1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 07:13:02 +04:00

core(OpenCL): thread-local OpenCL execution context

This commit is contained in:
Alexander Alekhin
2020-08-11 18:13:52 +00:00
parent 0428dce27d
commit 2129c72bc0
12 changed files with 1719 additions and 252 deletions
+18 -4
View File
@@ -106,7 +106,7 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
CL_PREFERRED_DEVICES_FOR_VA_API_INTEL, 0, NULL, &numDevices);
if ((status != CL_SUCCESS) || !(numDevices > 0))
continue;
numDevices = 1; // initializeContextFromHandle() expects only 1 device
numDevices = 1; // OpenCV expects only 1 device
status = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(platforms[i], CL_VA_API_DISPLAY_INTEL, display,
CL_PREFERRED_DEVICES_FOR_VA_API_INTEL, numDevices, &device, NULL);
if (status != CL_SUCCESS)
@@ -135,9 +135,23 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
if (found >= 0)
{
contextInitialized = true;
Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device);
return ctx;
cl_platform_id platform = platforms[found];
std::string platformName = PlatformInfo(platform).name();
OpenCLExecutionContext clExecCtx;
try
{
clExecCtx = OpenCLExecutionContext::create(platformName, platform, context, device);
}
catch (...)
{
clReleaseDevice(device);
clReleaseContext(context);
throw;
}
clExecCtx.bind();
return const_cast<Context&>(clExecCtx.getContext());
}
}
# endif // HAVE_VA_INTEL && HAVE_OPENCL