ocl: fixes for OpenCL multiple contexts support

pull/18258/head
Alexander Alekhin 4 years ago
parent 2129c72bc0
commit 8711653530
  1. 9
      modules/core/src/ocl.cpp
  2. 2
      modules/core/src/opengl.cpp
  3. 7
      modules/core/src/system.cpp
  4. 2
      samples/sycl/CMakeLists.txt

@ -2316,8 +2316,9 @@ struct Context::Impl
typedef std::deque<Context::Impl*> container_t;
static container_t& getGlobalContainer()
{
static container_t g_contexts;
return g_contexts;
// never delete this container (Impl lifetime is greater due to TLS storage)
static container_t* g_contexts = new container_t();
return *g_contexts;
}
protected:
@ -2356,7 +2357,7 @@ protected:
{
cv::AutoLock lock(cv::getInitializationMutex());
auto& container = getGlobalContainer();
CV_Assert((size_t)contextId < container.size());
CV_CheckLT((size_t)contextId, container.size(), "");
container[contextId] = NULL;
}
}
@ -2839,7 +2840,7 @@ bool Context::create()
if (!haveOpenCL())
return false;
p = Impl::findOrCreateContext(std::string());
if (p->handle)
if (p && p->handle)
return true;
release();
return false;

@ -1692,7 +1692,7 @@ Context& initializeContextFromGL()
cl_platform_id platform = platforms[found];
std::string platformName = PlatformInfo(platform).name();
OpenCLExecutionContext clExecCtx = OpenCLExecutionContext::create(platformName, platform, context, deviceID);
OpenCLExecutionContext clExecCtx = OpenCLExecutionContext::create(platformName, platform, context, device);
clReleaseDevice(device);
clReleaseContext(context);
clExecCtx.bind();

@ -1416,7 +1416,10 @@ static TlsAbstraction* getTlsAbstraction()
#ifdef WINRT
static __declspec( thread ) void* tlsData = NULL; // using C++11 thread attribute for local thread data
TlsAbstraction::TlsAbstraction() {}
TlsAbstraction::~TlsAbstraction() {}
TlsAbstraction::~TlsAbstraction()
{
cv::__termination = true; // DllMain is missing in static builds
}
void* TlsAbstraction::getData_() const
{
return tlsData;
@ -1440,6 +1443,7 @@ TlsAbstraction::TlsAbstraction()
}
TlsAbstraction::~TlsAbstraction()
{
cv::__termination = true; // DllMain is missing in static builds
#ifndef CV_USE_FLS
TlsFree(tlsKey);
#else // CV_USE_FLS
@ -1472,6 +1476,7 @@ TlsAbstraction::TlsAbstraction()
}
TlsAbstraction::~TlsAbstraction()
{
cv::__termination = true; // DllMain is missing in static builds
if (pthread_key_delete(tlsKey) != 0)
{
// Don't use logging here

@ -2,7 +2,7 @@ if(OPENCV_SKIP_SAMPLES_SYCL)
return()
endif()
ocv_install_example_src(opencl *.cpp *.hpp CMakeLists.txt)
ocv_install_example_src(sycl *.cpp *.hpp CMakeLists.txt)
set(OPENCV_SYCL_SAMPLES_REQUIRED_DEPS
opencv_core

Loading…
Cancel
Save