提交 087bab6c 编写于 作者: R Roman Donchenko 提交者: OpenCV Buildbot

Merge pull request #1060 from pengx17:2.4_setbinary_fix

......@@ -123,9 +123,6 @@ namespace cv
codeCache.clear();
cacheSize = 0;
}
// not to be exported to dynamic lib
void setBinaryDiskCacheImpl(int mode, String path, Info::Impl * impl);
struct Info::Impl
{
cl_platform_id oclplatform;
......@@ -143,9 +140,6 @@ namespace cv
char extra_options[512];
int double_support;
int unified_memory; //1 means integrated GPU, otherwise this value is 0
bool enable_disk_cache;
bool update_disk_cache;
string binpath;
int refcounter;
Impl();
......@@ -173,6 +167,16 @@ namespace cv
void releaseResources();
};
// global variables to hold binary cache properties
static int enable_disk_cache =
#ifdef _DEBUG
false;
#else
true;
#endif
static int update_disk_cache = false;
static String binpath = "";
Info::Impl::Impl()
:oclplatform(0),
oclcontext(0),
......@@ -183,13 +187,9 @@ namespace cv
maxComputeUnits(0),
double_support(0),
unified_memory(0),
enable_disk_cache(false),
update_disk_cache(false),
binpath("./"),
refcounter(1)
{
memset(extra_options, 0, 512);
setBinaryDiskCacheImpl(CACHE_RELEASE, String("./"), this);
}
void Info::Impl::releaseResources()
......@@ -505,29 +505,30 @@ namespace cv
return openCLGetKernelFromSource(clCxt, source, kernelName, NULL);
}
void setBinaryDiskCacheImpl(int mode, String path, Info::Impl * impl)
void setBinaryDiskCache(int mode, String path)
{
impl->update_disk_cache = (mode & CACHE_UPDATE) == CACHE_UPDATE;
impl->enable_disk_cache =
if(mode == CACHE_NONE)
{
update_disk_cache = 0;
enable_disk_cache = 0;
return;
}
update_disk_cache |= (mode & CACHE_UPDATE) == CACHE_UPDATE;
enable_disk_cache |=
#ifdef _DEBUG
(mode & CACHE_DEBUG) == CACHE_DEBUG;
#else
(mode & CACHE_RELEASE) == CACHE_RELEASE;
#endif
if(impl->enable_disk_cache && !path.empty())
if(enable_disk_cache && !path.empty())
{
impl->binpath = path;
binpath = path;
}
}
void setBinaryDiskCache(int mode, cv::String path)
{
setBinaryDiskCacheImpl(mode, path, Context::getContext()->impl);
}
void setBinpath(const char *path)
{
Context *clcxt = Context::getContext();
clcxt->impl->binpath = path;
binpath = path;
}
int savetofile(const Context*, cl_program &program, const char *fileName)
......@@ -595,15 +596,15 @@ namespace cv
strcat(all_build_options, build_options);
if(all_build_options != NULL)
{
filename = clCxt->impl->binpath + kernelName + "_" + clCxt->impl->devName[clCxt->impl->devnum] + all_build_options + ".clb";
filename = binpath + kernelName + "_" + clCxt->impl->devName[clCxt->impl->devnum] + all_build_options + ".clb";
}
else
{
filename = clCxt->impl->binpath + kernelName + "_" + clCxt->impl->devName[clCxt->impl->devnum] + ".clb";
filename = binpath + kernelName + "_" + clCxt->impl->devName[clCxt->impl->devnum] + ".clb";
}
FILE *fp = clCxt->impl->enable_disk_cache ? fopen(filename.c_str(), "rb") : NULL;
if(fp == NULL || clCxt->impl->update_disk_cache)
FILE *fp = enable_disk_cache ? fopen(filename.c_str(), "rb") : NULL;
if(fp == NULL || update_disk_cache)
{
if(fp != NULL)
fclose(fp);
......@@ -612,7 +613,7 @@ namespace cv
clCxt->impl->oclcontext, 1, source, NULL, &status);
openCLVerifyCall(status);
status = clBuildProgram(program, 1, &(clCxt->impl->devices[clCxt->impl->devnum]), all_build_options, NULL, NULL);
if(status == CL_SUCCESS && clCxt->impl->enable_disk_cache)
if(status == CL_SUCCESS && enable_disk_cache)
savetofile(clCxt, program, filename.c_str());
}
else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册