[Libreoffice-commits] core.git: Branch 'feature/fixes36' - include/opencl opencl/source
László Németh
laszlo.nemeth at collabora.com
Sat Oct 15 12:11:07 UTC 2016
include/opencl/openclwrapper.hxx | 1
opencl/source/openclwrapper.cxx | 81 +++++++++++++++------------------------
2 files changed, 33 insertions(+), 49 deletions(-)
New commits:
commit f606a33b57c24210876bd7665b9c8d7baac57a14
Author: László Németh <laszlo.nemeth at collabora.com>
Date: Sat Oct 15 14:04:42 2016 +0200
Revert "opencl: initialize command queue on demand"
This reverts commit 6d4d3db53242e2dc588b347f313d17f9966f283e.
diff --git a/include/opencl/openclwrapper.hxx b/include/opencl/openclwrapper.hxx
index 233412f..dae1192 100644
--- a/include/opencl/openclwrapper.hxx
+++ b/include/opencl/openclwrapper.hxx
@@ -42,7 +42,6 @@ struct OPENCL_DLLPUBLIC GPUEnv
cl_context mpContext;
cl_device_id mpDevID;
cl_command_queue mpCmdQueue[OPENCL_CMDQUEUE_SIZE];
- bool mbCommandQueueInitialized;
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;
diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx
index 5d40a54..d8d16c3 100644
--- a/opencl/source/openclwrapper.cxx
+++ b/opencl/source/openclwrapper.cxx
@@ -103,54 +103,8 @@ OString 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];
@@ -311,7 +265,8 @@ bool initOpenCLAttr( OpenCLEnv * env )
gpuEnv.mnIsUserCreated = 1;
- gpuEnv.mbCommandQueueInitialized = false;
+ for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i)
+ gpuEnv.mpCmdQueue[i] = env->mpOclCmdQueue[i];
gpuEnv.mnCmdQueuePos = 0; // default to 0.
@@ -810,6 +765,7 @@ 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;
@@ -834,6 +790,33 @@ 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);
}
@@ -841,12 +824,14 @@ 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);
More information about the Libreoffice-commits
mailing list