Set up foundation for supporting multiple OpenCL command queues per device.
Change-Id: Ia63c8bd6552cdbc2b5eabadaa044b9f1eca5f664
This commit is contained in:
parent
37947afccd
commit
e12fcd050a
2 changed files with 60 additions and 16 deletions
|
@ -33,6 +33,7 @@ if( status != CL_SUCCESS ) \
|
|||
}
|
||||
|
||||
#define MAX_CLFILE_NUM 50
|
||||
#define OPENCL_CMDQUEUE_SIZE 1 // number of command queues per OpenCL device.
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
@ -53,9 +54,10 @@ struct GPUEnv
|
|||
cl_context mpContext;
|
||||
cl_device_id *mpArryDevsID;
|
||||
cl_device_id mpDevID;
|
||||
cl_command_queue mpCmdQueue;
|
||||
cl_command_queue mpCmdQueue[OPENCL_CMDQUEUE_SIZE];
|
||||
cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
|
||||
int mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper
|
||||
int mnCmdQueuePos;
|
||||
bool mnKhrFp64Flag;
|
||||
bool mnAmdFp64Flag;
|
||||
};
|
||||
|
@ -79,6 +81,12 @@ OPENCL_DLLPUBLIC bool switchOpenCLDevice(const OUString* pDeviceId, bool bAutoSe
|
|||
|
||||
OPENCL_DLLPUBLIC void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId);
|
||||
|
||||
/**
|
||||
* Set the current command queue position in case of multiple command queues
|
||||
* for a given device.
|
||||
*/
|
||||
OPENCL_DLLPUBLIC void setOpenCLCmdQueuePosition( int nPos );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -89,8 +89,10 @@ OString maCacheFolder = getCacheFolder();
|
|||
void setKernelEnv( KernelEnv *envInfo )
|
||||
{
|
||||
envInfo->mpkContext = gpuEnv.mpContext;
|
||||
envInfo->mpkCmdQueue = gpuEnv.mpCmdQueue;
|
||||
envInfo->mpkProgram = gpuEnv.mpArryPrograms[0];
|
||||
|
||||
assert(gpuEnv.mnCmdQueuePos < OPENCL_CMDQUEUE_SIZE);
|
||||
envInfo->mpkCmdQueue = gpuEnv.mpCmdQueue[gpuEnv.mnCmdQueuePos];
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -259,7 +261,7 @@ struct OpenCLEnv
|
|||
cl_platform_id mpOclPlatformID;
|
||||
cl_context mpOclContext;
|
||||
cl_device_id mpOclDevsID;
|
||||
cl_command_queue mpOclCmdQueue;
|
||||
cl_command_queue mpOclCmdQueue[OPENCL_CMDQUEUE_SIZE];
|
||||
};
|
||||
|
||||
bool initOpenCLAttr( OpenCLEnv * env )
|
||||
|
@ -270,10 +272,14 @@ bool initOpenCLAttr( OpenCLEnv * env )
|
|||
gpuEnv.mpContext = env->mpOclContext;
|
||||
gpuEnv.mpPlatformID = env->mpOclPlatformID;
|
||||
gpuEnv.mpDevID = env->mpOclDevsID;
|
||||
gpuEnv.mpCmdQueue = env->mpOclCmdQueue;
|
||||
|
||||
gpuEnv.mnIsUserCreated = 1;
|
||||
|
||||
for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
|
||||
gpuEnv.mpCmdQueue[i] = env->mpOclCmdQueue[i];
|
||||
|
||||
gpuEnv.mnCmdQueuePos = 0; // default to 0.
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -284,11 +290,16 @@ void releaseOpenCLEnv( GPUEnv *gpuInfo )
|
|||
return;
|
||||
}
|
||||
|
||||
if ( gpuEnv.mpCmdQueue )
|
||||
for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
|
||||
{
|
||||
clReleaseCommandQueue( gpuEnv.mpCmdQueue );
|
||||
gpuEnv.mpCmdQueue = NULL;
|
||||
if (gpuEnv.mpCmdQueue[i])
|
||||
{
|
||||
clReleaseCommandQueue(gpuEnv.mpCmdQueue[i]);
|
||||
gpuEnv.mpCmdQueue[i] = NULL;
|
||||
}
|
||||
}
|
||||
gpuEnv.mnCmdQueuePos = 0;
|
||||
|
||||
if ( gpuEnv.mpContext )
|
||||
{
|
||||
clReleaseContext( gpuEnv.mpContext );
|
||||
|
@ -761,25 +772,41 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
|
|||
return false;
|
||||
}
|
||||
|
||||
cl_command_queue command_queue = clCreateCommandQueue(
|
||||
cl_command_queue command_queue[OPENCL_CMDQUEUE_SIZE];
|
||||
for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
|
||||
{
|
||||
command_queue[i] = clCreateCommandQueue(
|
||||
context, pDeviceId, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &nState);
|
||||
|
||||
if(command_queue == NULL || nState != CL_SUCCESS)
|
||||
{
|
||||
if(command_queue != NULL)
|
||||
clReleaseCommandQueue(command_queue);
|
||||
if (command_queue[i] == NULL || nState != CL_SUCCESS)
|
||||
{
|
||||
// Release all command queues created so far.
|
||||
for (int j = 0; j <= i; ++j)
|
||||
{
|
||||
if (command_queue[j])
|
||||
{
|
||||
clReleaseCommandQueue(command_queue[j]);
|
||||
command_queue[j] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
clReleaseContext(context);
|
||||
SAL_WARN("opencl", "failed to set/switch opencl device");
|
||||
return false;
|
||||
clReleaseContext(context);
|
||||
SAL_WARN("opencl", "failed to set/switch opencl device");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
setOpenCLCmdQueuePosition(0); // Call this just to avoid the method being deleted from unused function deleter.
|
||||
|
||||
releaseOpenCLEnv(&gpuEnv);
|
||||
OpenCLEnv env;
|
||||
env.mpOclPlatformID = platformId;
|
||||
env.mpOclContext = context;
|
||||
env.mpOclDevsID = pDeviceId;
|
||||
env.mpOclCmdQueue = command_queue;
|
||||
|
||||
for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
|
||||
env.mpOclCmdQueue[i] = command_queue[i];
|
||||
|
||||
initOpenCLAttr(&env);
|
||||
|
||||
// why do we need this at all?
|
||||
|
@ -804,6 +831,15 @@ void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId)
|
|||
findDeviceInfoFromDeviceId(id, rDeviceId, rPlatformId);
|
||||
}
|
||||
|
||||
void setOpenCLCmdQueuePosition( int nPos )
|
||||
{
|
||||
if (nPos < 0 || nPos >= OPENCL_CMDQUEUE_SIZE)
|
||||
// Out of range. Ignore this.
|
||||
return;
|
||||
|
||||
gpuEnv.mnCmdQueuePos = nPos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
Loading…
Reference in a new issue