Merge pull request #1060 from pengx17:2.4_setbinary_fix
This commit is contained in:
commit
087bab6ceb
@ -123,9 +123,6 @@ namespace cv
|
|||||||
codeCache.clear();
|
codeCache.clear();
|
||||||
cacheSize = 0;
|
cacheSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not to be exported to dynamic lib
|
|
||||||
void setBinaryDiskCacheImpl(int mode, String path, Info::Impl * impl);
|
|
||||||
struct Info::Impl
|
struct Info::Impl
|
||||||
{
|
{
|
||||||
cl_platform_id oclplatform;
|
cl_platform_id oclplatform;
|
||||||
@ -143,9 +140,6 @@ namespace cv
|
|||||||
char extra_options[512];
|
char extra_options[512];
|
||||||
int double_support;
|
int double_support;
|
||||||
int unified_memory; //1 means integrated GPU, otherwise this value is 0
|
int unified_memory; //1 means integrated GPU, otherwise this value is 0
|
||||||
bool enable_disk_cache;
|
|
||||||
bool update_disk_cache;
|
|
||||||
string binpath;
|
|
||||||
int refcounter;
|
int refcounter;
|
||||||
|
|
||||||
Impl();
|
Impl();
|
||||||
@ -173,6 +167,16 @@ namespace cv
|
|||||||
void releaseResources();
|
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()
|
Info::Impl::Impl()
|
||||||
:oclplatform(0),
|
:oclplatform(0),
|
||||||
oclcontext(0),
|
oclcontext(0),
|
||||||
@ -183,13 +187,9 @@ namespace cv
|
|||||||
maxComputeUnits(0),
|
maxComputeUnits(0),
|
||||||
double_support(0),
|
double_support(0),
|
||||||
unified_memory(0),
|
unified_memory(0),
|
||||||
enable_disk_cache(false),
|
|
||||||
update_disk_cache(false),
|
|
||||||
binpath("./"),
|
|
||||||
refcounter(1)
|
refcounter(1)
|
||||||
{
|
{
|
||||||
memset(extra_options, 0, 512);
|
memset(extra_options, 0, 512);
|
||||||
setBinaryDiskCacheImpl(CACHE_RELEASE, String("./"), this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Info::Impl::releaseResources()
|
void Info::Impl::releaseResources()
|
||||||
@ -505,29 +505,30 @@ namespace cv
|
|||||||
return openCLGetKernelFromSource(clCxt, source, kernelName, NULL);
|
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;
|
if(mode == CACHE_NONE)
|
||||||
impl->enable_disk_cache =
|
{
|
||||||
|
update_disk_cache = 0;
|
||||||
|
enable_disk_cache = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
update_disk_cache |= (mode & CACHE_UPDATE) == CACHE_UPDATE;
|
||||||
|
enable_disk_cache |=
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
(mode & CACHE_DEBUG) == CACHE_DEBUG;
|
(mode & CACHE_DEBUG) == CACHE_DEBUG;
|
||||||
#else
|
#else
|
||||||
(mode & CACHE_RELEASE) == CACHE_RELEASE;
|
(mode & CACHE_RELEASE) == CACHE_RELEASE;
|
||||||
#endif
|
#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)
|
void setBinpath(const char *path)
|
||||||
{
|
{
|
||||||
Context *clcxt = Context::getContext();
|
binpath = path;
|
||||||
clcxt->impl->binpath = path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int savetofile(const Context*, cl_program &program, const char *fileName)
|
int savetofile(const Context*, cl_program &program, const char *fileName)
|
||||||
@ -595,15 +596,15 @@ namespace cv
|
|||||||
strcat(all_build_options, build_options);
|
strcat(all_build_options, build_options);
|
||||||
if(all_build_options != NULL)
|
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
|
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;
|
FILE *fp = enable_disk_cache ? fopen(filename.c_str(), "rb") : NULL;
|
||||||
if(fp == NULL || clCxt->impl->update_disk_cache)
|
if(fp == NULL || update_disk_cache)
|
||||||
{
|
{
|
||||||
if(fp != NULL)
|
if(fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -612,7 +613,7 @@ namespace cv
|
|||||||
clCxt->impl->oclcontext, 1, source, NULL, &status);
|
clCxt->impl->oclcontext, 1, source, NULL, &status);
|
||||||
openCLVerifyCall(status);
|
openCLVerifyCall(status);
|
||||||
status = clBuildProgram(program, 1, &(clCxt->impl->devices[clCxt->impl->devnum]), all_build_options, NULL, NULL);
|
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());
|
savetofile(clCxt, program, filename.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user