include/opencl/openclwrapper.hxx | 10 +++++ opencl/source/openclwrapper.cxx | 66 ++++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 16 deletions(-)
New commits: commit e12fcd050a6647232df3003d0a5cca01e564ac22 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Wed Jan 7 16:24:06 2015 -0500 Set up foundation for supporting multiple OpenCL command queues per device. Change-Id: Ia63c8bd6552cdbc2b5eabadaa044b9f1eca5f664 diff --git a/include/opencl/openclwrapper.hxx b/include/opencl/openclwrapper.hxx index 412c00b..d869819 100644 --- a/include/opencl/openclwrapper.hxx +++ b/include/opencl/openclwrapper.hxx @@ -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 diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx index 09e7bc0..613e503 100644 --- a/opencl/source/openclwrapper.cxx +++ b/opencl/source/openclwrapper.cxx @@ -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: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits