Skip to content

Commit 8711653

Browse files
committed
ocl: fixes for OpenCL multiple contexts support
1 parent 2129c72 commit 8711653

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

Diff for: modules/core/src/ocl.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,9 @@ struct Context::Impl
23162316
typedef std::deque<Context::Impl*> container_t;
23172317
static container_t& getGlobalContainer()
23182318
{
2319-
static container_t g_contexts;
2320-
return g_contexts;
2319+
// never delete this container (Impl lifetime is greater due to TLS storage)
2320+
static container_t* g_contexts = new container_t();
2321+
return *g_contexts;
23212322
}
23222323

23232324
protected:
@@ -2356,7 +2357,7 @@ struct Context::Impl
23562357
{
23572358
cv::AutoLock lock(cv::getInitializationMutex());
23582359
auto& container = getGlobalContainer();
2359-
CV_Assert((size_t)contextId < container.size());
2360+
CV_CheckLT((size_t)contextId, container.size(), "");
23602361
container[contextId] = NULL;
23612362
}
23622363
}
@@ -2839,7 +2840,7 @@ bool Context::create()
28392840
if (!haveOpenCL())
28402841
return false;
28412842
p = Impl::findOrCreateContext(std::string());
2842-
if (p->handle)
2843+
if (p && p->handle)
28432844
return true;
28442845
release();
28452846
return false;

Diff for: modules/core/src/opengl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ Context& initializeContextFromGL()
16921692
cl_platform_id platform = platforms[found];
16931693
std::string platformName = PlatformInfo(platform).name();
16941694

1695-
OpenCLExecutionContext clExecCtx = OpenCLExecutionContext::create(platformName, platform, context, deviceID);
1695+
OpenCLExecutionContext clExecCtx = OpenCLExecutionContext::create(platformName, platform, context, device);
16961696
clReleaseDevice(device);
16971697
clReleaseContext(context);
16981698
clExecCtx.bind();

Diff for: modules/core/src/system.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,10 @@ static TlsAbstraction* getTlsAbstraction()
14161416
#ifdef WINRT
14171417
static __declspec( thread ) void* tlsData = NULL; // using C++11 thread attribute for local thread data
14181418
TlsAbstraction::TlsAbstraction() {}
1419-
TlsAbstraction::~TlsAbstraction() {}
1419+
TlsAbstraction::~TlsAbstraction()
1420+
{
1421+
cv::__termination = true; // DllMain is missing in static builds
1422+
}
14201423
void* TlsAbstraction::getData_() const
14211424
{
14221425
return tlsData;
@@ -1440,6 +1443,7 @@ TlsAbstraction::TlsAbstraction()
14401443
}
14411444
TlsAbstraction::~TlsAbstraction()
14421445
{
1446+
cv::__termination = true; // DllMain is missing in static builds
14431447
#ifndef CV_USE_FLS
14441448
TlsFree(tlsKey);
14451449
#else // CV_USE_FLS
@@ -1472,6 +1476,7 @@ TlsAbstraction::TlsAbstraction()
14721476
}
14731477
TlsAbstraction::~TlsAbstraction()
14741478
{
1479+
cv::__termination = true; // DllMain is missing in static builds
14751480
if (pthread_key_delete(tlsKey) != 0)
14761481
{
14771482
// Don't use logging here

Diff for: samples/sycl/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ if(OPENCV_SKIP_SAMPLES_SYCL)
22
return()
33
endif()
44

5-
ocv_install_example_src(opencl *.cpp *.hpp CMakeLists.txt)
5+
ocv_install_example_src(sycl *.cpp *.hpp CMakeLists.txt)
66

77
set(OPENCV_SYCL_SAMPLES_REQUIRED_DEPS
88
opencv_core

0 commit comments

Comments
 (0)