Skip to content

Commit 4f48dab

Browse files
committed
Merge pull request opencv#18150 from alalek:ocl_async_cleanup_no_warning
2 parents 4372d75 + b3755e6 commit 4f48dab

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

modules/core/src/umatrix.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ UMatData::~UMatData()
8080
CV_Assert(mapcount == 0);
8181
data = origdata = 0;
8282
size = 0;
83+
bool isAsyncCleanup = !!(flags & UMatData::ASYNC_CLEANUP);
8384
flags = 0;
8485
handle = 0;
8586
userdata = 0;
@@ -106,7 +107,7 @@ UMatData::~UMatData()
106107
showWarn = true;
107108
if (zero_Ref && zero_URef) // oops, we need to free resources
108109
{
109-
showWarn = true;
110+
showWarn = !isAsyncCleanup;
110111
// simulate UMat::deallocate
111112
u->currAllocator->deallocate(u);
112113
}

modules/core/test/test_umat.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,30 @@ TEST(UMat, map_unmap_counting)
11541154
}
11551155

11561156

1157+
static void process_with_async_cleanup(Mat& frame)
1158+
{
1159+
UMat blurResult;
1160+
{
1161+
UMat umat_buffer = frame.getUMat(ACCESS_READ);
1162+
cv::blur(umat_buffer, blurResult, Size(3, 3)); // UMat doesn't support inplace, this call is not synchronized
1163+
}
1164+
Mat result;
1165+
blurResult.copyTo(result);
1166+
swap(result, frame);
1167+
// umat_buffer cleanup is done asynchronously, silence warning about original 'frame' cleanup here (through 'result')
1168+
// - release input 'frame' (as 'result')
1169+
// - release 'umat_buffer' asynchronously and silence warning about "parent" buffer (in debug builds)
1170+
}
1171+
TEST(UMat, async_cleanup_without_call_chain_warning)
1172+
{
1173+
Mat frame(Size(640, 480), CV_8UC1, Scalar::all(128));
1174+
for (int i = 0; i < 10; i++)
1175+
{
1176+
process_with_async_cleanup(frame);
1177+
}
1178+
}
1179+
1180+
11571181
///////////// oclCleanupCallback threadsafe check (#5062) /////////////////////
11581182

11591183
// Case 1: reuse of old src Mat in OCL pipe. Hard to catch!

0 commit comments

Comments
 (0)