Skip to content

Commit da3da84

Browse files
committed
ocl: Add a function to unload a run-time cached program
This function is the counterpart of "Context::getProg". With this function, users have chance to unload a program from global run-time cached programs, and save resource.
1 parent f670a99 commit da3da84

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

modules/core/include/opencv2/core/ocl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class CV_EXPORTS Context
248248
const Device& device(size_t idx) const;
249249
Program getProg(const ProgramSource& prog,
250250
const String& buildopt, String& errmsg);
251+
void unloadProg(Program& prog);
251252

252253
static Context& getDefault(bool initialize = true);
253254
void* ptr() const;

modules/core/src/ocl.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,23 @@ struct Context::Impl
13971397
return prog;
13981398
}
13991399

1400+
void unloadProg(Program& prog)
1401+
{
1402+
cv::AutoLock lock(program_cache_mutex);
1403+
for (CacheList::iterator i = cacheList.begin(); i != cacheList.end(); ++i)
1404+
{
1405+
phash_t::iterator it = phash.find(*i);
1406+
if (it != phash.end())
1407+
{
1408+
if (it->second.ptr() == prog.ptr())
1409+
{
1410+
phash.erase(*i);
1411+
cacheList.erase(i);
1412+
return;
1413+
}
1414+
}
1415+
}
1416+
}
14001417

14011418
IMPLEMENT_REFCOUNTABLE();
14021419

@@ -1660,7 +1677,11 @@ Program Context::getProg(const ProgramSource& prog,
16601677
return p ? p->getProg(prog, buildopts, errmsg) : Program();
16611678
}
16621679

1663-
1680+
void Context::unloadProg(Program& prog)
1681+
{
1682+
if (p)
1683+
p->unloadProg(prog);
1684+
}
16641685

16651686
#ifdef HAVE_OPENCL_SVM
16661687
bool Context::useSVM() const

0 commit comments

Comments
 (0)