Skip to content

Commit 603fa03

Browse files
committed
Merge pull request opencv#9441 from wzw-intel:delete_program
2 parents 8a094a5 + da3da84 commit 603fa03

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
@@ -1380,6 +1380,23 @@ struct Context::Impl
13801380
return prog;
13811381
}
13821382

1383+
void unloadProg(Program& prog)
1384+
{
1385+
cv::AutoLock lock(program_cache_mutex);
1386+
for (CacheList::iterator i = cacheList.begin(); i != cacheList.end(); ++i)
1387+
{
1388+
phash_t::iterator it = phash.find(*i);
1389+
if (it != phash.end())
1390+
{
1391+
if (it->second.ptr() == prog.ptr())
1392+
{
1393+
phash.erase(*i);
1394+
cacheList.erase(i);
1395+
return;
1396+
}
1397+
}
1398+
}
1399+
}
13831400

13841401
IMPLEMENT_REFCOUNTABLE();
13851402

@@ -1643,7 +1660,11 @@ Program Context::getProg(const ProgramSource& prog,
16431660
return p ? p->getProg(prog, buildopts, errmsg) : Program();
16441661
}
16451662

1646-
1663+
void Context::unloadProg(Program& prog)
1664+
{
1665+
if (p)
1666+
p->unloadProg(prog);
1667+
}
16471668

16481669
#ifdef HAVE_OPENCL_SVM
16491670
bool Context::useSVM() const

0 commit comments

Comments
 (0)