ocl: workaround for ProgramCache cleanup issue, use RAII to print kernel build error

This commit is contained in:
Alexander Alekhin 2013-10-21 19:15:11 +04:00
parent a54d36bde8
commit 9acca12d2d
2 changed files with 23 additions and 19 deletions

View File

@ -61,12 +61,16 @@ namespace cv { namespace ocl {
cv::Mutex ProgramCache::mutexFiles; cv::Mutex ProgramCache::mutexFiles;
cv::Mutex ProgramCache::mutexCache; cv::Mutex ProgramCache::mutexCache;
std::auto_ptr<ProgramCache> _programCache; ProgramCache* _programCache = NULL;
ProgramCache* ProgramCache::getProgramCache() ProgramCache* ProgramCache::getProgramCache()
{ {
if (NULL == _programCache.get()) if (NULL == _programCache)
_programCache.reset(new ProgramCache()); {
return _programCache.get(); cv::AutoLock lock(getInitializationMutex());
if (NULL == _programCache)
_programCache = new ProgramCache();
}
return _programCache;
} }
ProgramCache::ProgramCache() ProgramCache::ProgramCache()
@ -78,6 +82,12 @@ ProgramCache::ProgramCache()
ProgramCache::~ProgramCache() ProgramCache::~ProgramCache()
{ {
releaseProgram(); releaseProgram();
if (this == _programCache)
{
cv::AutoLock lock(getInitializationMutex());
if (this == _programCache)
_programCache = NULL;
}
} }
cl_program ProgramCache::progLookup(const string& srcsign) cl_program ProgramCache::progLookup(const string& srcsign)
@ -420,22 +430,17 @@ struct ProgramFileCache
{ {
if(status == CL_BUILD_PROGRAM_FAILURE) if(status == CL_BUILD_PROGRAM_FAILURE)
{ {
cl_int logStatus;
char *buildLog = NULL;
size_t buildLogSize = 0; 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), openCLSafeCall(clGetProgramBuildInfo(program, getClDeviceID(ctx),
CL_PROGRAM_BUILD_LOG, buildLogSize, buildLog, NULL)); CL_PROGRAM_BUILD_LOG, 0, NULL, &buildLogSize));
std::cout << "\nBUILD LOG: " << options << "\n"; std::vector<char> buildLog; buildLog.resize(buildLogSize);
std::cout << buildLog << endl; memset(&buildLog[0], 0, buildLogSize);
delete [] buildLog; 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); openCLVerifyCall(status);
} }

View File

@ -52,7 +52,6 @@ class ProgramCache
protected: protected:
ProgramCache(); ProgramCache();
~ProgramCache(); ~ProgramCache();
friend class std::auto_ptr<ProgramCache>;
public: public:
static ProgramCache *getProgramCache(); static ProgramCache *getProgramCache();