summaryrefslogtreecommitdiff
path: root/opencl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2016-10-13 12:55:57 +0200
committerTomaž Vajngerl <quikee@gmail.com>2016-10-18 09:01:14 +0000
commit4eea4af8924e3b1bb00c22cf1f9d21fc4dec6e83 (patch)
tree73e6e3919eea8bedc18ba51f9141ae68d71f7708 /opencl
parent9a3b752756204307a0439c4e3534c094c6ee979d (diff)
tdf#103204 opencl: initialize command queue on demand
Change-Id: Ie3da1d6ec91e951b1ffc15abf376c7af57789e47 Reviewed-on: https://gerrit.libreoffice.org/29802 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'opencl')
-rw-r--r--opencl/source/openclwrapper.cxx81
1 files changed, 48 insertions, 33 deletions
diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx
index 43330a6bae31..3daa019cf37a 100644
--- a/opencl/source/openclwrapper.cxx
+++ b/opencl/source/openclwrapper.cxx
@@ -103,8 +103,54 @@ OString const & getCacheFolder()
}
+bool initializeCommandQueue(GPUEnv& aGpuEnv)
+{
+ OpenCLZone zone;
+
+ cl_int nState;
+ cl_command_queue command_queue[OPENCL_CMDQUEUE_SIZE];
+
+ for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
+ {
+ command_queue[i] = clCreateCommandQueue(aGpuEnv.mpContext, aGpuEnv.mpDevID, 0, &nState);
+ if (nState != CL_SUCCESS)
+ SAL_WARN("opencl", "clCreateCommandQueue failed: " << errorString(nState));
+
+ if (command_queue[i] == nullptr || 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] = nullptr;
+ }
+ }
+
+ clReleaseContext(aGpuEnv.mpContext);
+ SAL_WARN("opencl", "failed to set/switch opencl device");
+ return false;
+ }
+
+ SAL_INFO("opencl", "Created command queue " << command_queue[i] << " for context " << aGpuEnv.mpContext);
+ }
+
+ for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
+ {
+ aGpuEnv.mpCmdQueue[i] = command_queue[i];
+ }
+ aGpuEnv.mbCommandQueueInitialized = true;
+ return true;
+}
+
void setKernelEnv( KernelEnv *envInfo )
{
+ if (!gpuEnv.mbCommandQueueInitialized)
+ {
+ initializeCommandQueue(gpuEnv);
+ }
+
envInfo->mpkContext = gpuEnv.mpContext;
envInfo->mpkProgram = gpuEnv.mpArryPrograms[0];
@@ -265,8 +311,7 @@ bool initOpenCLAttr( OpenCLEnv * env )
gpuEnv.mnIsUserCreated = 1;
- for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
- gpuEnv.mpCmdQueue[i] = env->mpOclCmdQueue[i];
+ gpuEnv.mbCommandQueueInitialized = false;
gpuEnv.mnCmdQueuePos = 0; // default to 0.
@@ -776,7 +821,6 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
cl_context context;
cl_platform_id platformId;
- cl_command_queue command_queue[OPENCL_CMDQUEUE_SIZE];
{
OpenCLZone zone;
@@ -801,33 +845,6 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
}
SAL_INFO("opencl", "Created context " << context << " for platform " << platformId << ", device " << pDeviceId);
- for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
- {
- command_queue[i] = clCreateCommandQueue(
- context, pDeviceId, 0, &nState);
- if (nState != CL_SUCCESS)
- SAL_WARN("opencl", "clCreateCommandQueue failed: " << errorString(nState));
-
- if (command_queue[i] == nullptr || 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] = nullptr;
- }
- }
-
- clReleaseContext(context);
- SAL_WARN("opencl", "failed to set/switch opencl device");
- return false;
- }
-
- SAL_INFO("opencl", "Created command queue " << command_queue[i] << " for context " << context);
- }
-
OString sDeviceID = getDeviceInfoString(pDeviceId, CL_DEVICE_VENDOR) + " " + getDeviceInfoString(pDeviceId, CL_DRIVER_VERSION);
rOutSelectedDeviceVersionIDString = OStringToOUString(sDeviceID, RTL_TEXTENCODING_UTF8);
}
@@ -835,14 +852,12 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
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;
- for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
- env.mpOclCmdQueue[i] = command_queue[i];
-
initOpenCLAttr(&env);
return !initOpenCLRunEnv(0);