mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
ocl: fixes for OpenCL multiple contexts support
This commit is contained in:
parent
2129c72bc0
commit
8711653530
@ -2316,8 +2316,9 @@ struct Context::Impl
|
|||||||
typedef std::deque<Context::Impl*> container_t;
|
typedef std::deque<Context::Impl*> container_t;
|
||||||
static container_t& getGlobalContainer()
|
static container_t& getGlobalContainer()
|
||||||
{
|
{
|
||||||
static container_t g_contexts;
|
// never delete this container (Impl lifetime is greater due to TLS storage)
|
||||||
return g_contexts;
|
static container_t* g_contexts = new container_t();
|
||||||
|
return *g_contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -2356,7 +2357,7 @@ protected:
|
|||||||
{
|
{
|
||||||
cv::AutoLock lock(cv::getInitializationMutex());
|
cv::AutoLock lock(cv::getInitializationMutex());
|
||||||
auto& container = getGlobalContainer();
|
auto& container = getGlobalContainer();
|
||||||
CV_Assert((size_t)contextId < container.size());
|
CV_CheckLT((size_t)contextId, container.size(), "");
|
||||||
container[contextId] = NULL;
|
container[contextId] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2839,7 +2840,7 @@ bool Context::create()
|
|||||||
if (!haveOpenCL())
|
if (!haveOpenCL())
|
||||||
return false;
|
return false;
|
||||||
p = Impl::findOrCreateContext(std::string());
|
p = Impl::findOrCreateContext(std::string());
|
||||||
if (p->handle)
|
if (p && p->handle)
|
||||||
return true;
|
return true;
|
||||||
release();
|
release();
|
||||||
return false;
|
return false;
|
||||||
|
@ -1692,7 +1692,7 @@ Context& initializeContextFromGL()
|
|||||||
cl_platform_id platform = platforms[found];
|
cl_platform_id platform = platforms[found];
|
||||||
std::string platformName = PlatformInfo(platform).name();
|
std::string platformName = PlatformInfo(platform).name();
|
||||||
|
|
||||||
OpenCLExecutionContext clExecCtx = OpenCLExecutionContext::create(platformName, platform, context, deviceID);
|
OpenCLExecutionContext clExecCtx = OpenCLExecutionContext::create(platformName, platform, context, device);
|
||||||
clReleaseDevice(device);
|
clReleaseDevice(device);
|
||||||
clReleaseContext(context);
|
clReleaseContext(context);
|
||||||
clExecCtx.bind();
|
clExecCtx.bind();
|
||||||
|
@ -1416,7 +1416,10 @@ static TlsAbstraction* getTlsAbstraction()
|
|||||||
#ifdef WINRT
|
#ifdef WINRT
|
||||||
static __declspec( thread ) void* tlsData = NULL; // using C++11 thread attribute for local thread data
|
static __declspec( thread ) void* tlsData = NULL; // using C++11 thread attribute for local thread data
|
||||||
TlsAbstraction::TlsAbstraction() {}
|
TlsAbstraction::TlsAbstraction() {}
|
||||||
TlsAbstraction::~TlsAbstraction() {}
|
TlsAbstraction::~TlsAbstraction()
|
||||||
|
{
|
||||||
|
cv::__termination = true; // DllMain is missing in static builds
|
||||||
|
}
|
||||||
void* TlsAbstraction::getData_() const
|
void* TlsAbstraction::getData_() const
|
||||||
{
|
{
|
||||||
return tlsData;
|
return tlsData;
|
||||||
@ -1440,6 +1443,7 @@ TlsAbstraction::TlsAbstraction()
|
|||||||
}
|
}
|
||||||
TlsAbstraction::~TlsAbstraction()
|
TlsAbstraction::~TlsAbstraction()
|
||||||
{
|
{
|
||||||
|
cv::__termination = true; // DllMain is missing in static builds
|
||||||
#ifndef CV_USE_FLS
|
#ifndef CV_USE_FLS
|
||||||
TlsFree(tlsKey);
|
TlsFree(tlsKey);
|
||||||
#else // CV_USE_FLS
|
#else // CV_USE_FLS
|
||||||
@ -1472,6 +1476,7 @@ TlsAbstraction::TlsAbstraction()
|
|||||||
}
|
}
|
||||||
TlsAbstraction::~TlsAbstraction()
|
TlsAbstraction::~TlsAbstraction()
|
||||||
{
|
{
|
||||||
|
cv::__termination = true; // DllMain is missing in static builds
|
||||||
if (pthread_key_delete(tlsKey) != 0)
|
if (pthread_key_delete(tlsKey) != 0)
|
||||||
{
|
{
|
||||||
// Don't use logging here
|
// Don't use logging here
|
||||||
|
@ -2,7 +2,7 @@ if(OPENCV_SKIP_SAMPLES_SYCL)
|
|||||||
return()
|
return()
|
||||||
endif()
|
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
|
set(OPENCV_SYCL_SAMPLES_REQUIRED_DEPS
|
||||||
opencv_core
|
opencv_core
|
||||||
|
Loading…
Reference in New Issue
Block a user