From 9acca12d2dcd01435161e3281fc269e65697cb76 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 21 Oct 2013 19:15:11 +0400 Subject: [PATCH] ocl: workaround for ProgramCache cleanup issue, use RAII to print kernel build error --- modules/ocl/src/cl_programcache.cpp | 41 ++++++++++++++++------------- modules/ocl/src/cl_programcache.hpp | 1 - 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/ocl/src/cl_programcache.cpp b/modules/ocl/src/cl_programcache.cpp index 76a115fd7..cc49ec193 100644 --- a/modules/ocl/src/cl_programcache.cpp +++ b/modules/ocl/src/cl_programcache.cpp @@ -61,12 +61,16 @@ namespace cv { namespace ocl { cv::Mutex ProgramCache::mutexFiles; cv::Mutex ProgramCache::mutexCache; -std::auto_ptr _programCache; +ProgramCache* _programCache = NULL; ProgramCache* ProgramCache::getProgramCache() { - if (NULL == _programCache.get()) - _programCache.reset(new ProgramCache()); - return _programCache.get(); + if (NULL == _programCache) + { + cv::AutoLock lock(getInitializationMutex()); + if (NULL == _programCache) + _programCache = new ProgramCache(); + } + return _programCache; } ProgramCache::ProgramCache() @@ -78,6 +82,12 @@ ProgramCache::ProgramCache() ProgramCache::~ProgramCache() { releaseProgram(); + if (this == _programCache) + { + cv::AutoLock lock(getInitializationMutex()); + if (this == _programCache) + _programCache = NULL; + } } cl_program ProgramCache::progLookup(const string& srcsign) @@ -420,22 +430,17 @@ struct ProgramFileCache { if(status == CL_BUILD_PROGRAM_FAILURE) { - cl_int logStatus; - char *buildLog = NULL; size_t buildLogSize = 0; - logStatus = clGetProgramBuildInfo(program, - getClDeviceID(ctx), CL_PROGRAM_BUILD_LOG, buildLogSize, - buildLog, &buildLogSize); - if(logStatus != CL_SUCCESS) - std::cout << "Failed to build the program and get the build info." << endl; - buildLog = new char[buildLogSize]; - CV_DbgAssert(!!buildLog); - memset(buildLog, 0, buildLogSize); openCLSafeCall(clGetProgramBuildInfo(program, getClDeviceID(ctx), - CL_PROGRAM_BUILD_LOG, buildLogSize, buildLog, NULL)); - std::cout << "\nBUILD LOG: " << options << "\n"; - std::cout << buildLog << endl; - delete [] buildLog; + CL_PROGRAM_BUILD_LOG, 0, NULL, &buildLogSize)); + std::vector buildLog; buildLog.resize(buildLogSize); + memset(&buildLog[0], 0, buildLogSize); + openCLSafeCall(clGetProgramBuildInfo(program, getClDeviceID(ctx), + CL_PROGRAM_BUILD_LOG, buildLogSize, &buildLog[0], NULL)); + std::cout << std::endl << "BUILD LOG: " + << (source->name ? source->name : "dynamic program") << ": " + << options << "\n"; + std::cout << &buildLog[0] << endl; } openCLVerifyCall(status); } diff --git a/modules/ocl/src/cl_programcache.hpp b/modules/ocl/src/cl_programcache.hpp index ea2ab400c..d94de21d9 100644 --- a/modules/ocl/src/cl_programcache.hpp +++ b/modules/ocl/src/cl_programcache.hpp @@ -52,7 +52,6 @@ class ProgramCache protected: ProgramCache(); ~ProgramCache(); - friend class std::auto_ptr; public: static ProgramCache *getProgramCache();