@@ -1044,6 +1044,76 @@ TEST(UMat, map_unmap_counting)
10441044}
10451045
10461046
1047+ // /////////// oclCleanupCallback threadsafe check (#5062) /////////////////////
1048+
1049+ // Case 1: reuse of old src Mat in OCL pipe. Hard to catch!
1050+ OCL_TEST (UMat, DISABLED_OCL_ThreadSafe_CleanupCallback_1_VeryLongTest)
1051+ {
1052+ if (!cv::ocl::useOpenCL ())
1053+ {
1054+ std::cout << " OpenCL is not enabled. Skip test" << std::endl;
1055+ return ;
1056+ }
1057+ for (int j = 0 ; j < 100 ; j++)
1058+ {
1059+ const Size srcSize (320 , 240 );
1060+ const int type = CV_8UC1;
1061+ const int dtype = CV_16UC1;
1062+
1063+ Mat src (srcSize, type);
1064+ Mat dst_ref (srcSize, dtype);
1065+
1066+ // Generate reference data as additional check
1067+ OCL_OFF (src.convertTo (dst_ref, dtype));
1068+ cv::ocl::setUseOpenCL (true ); // restore OpenCL state
1069+
1070+ UMat dst (srcSize, dtype);
1071+
1072+ // Use multiple iterations to increase chance of data race catching
1073+ for (int k = 0 ; k < 10000 ; k++)
1074+ {
1075+ UMat tmpUMat = src.getUMat (ACCESS_RW);
1076+ tmpUMat.convertTo (dst, dtype);
1077+ ::cv::ocl::finish (); // force kernel to complete to start cleanup sooner
1078+ }
1079+
1080+ EXPECT_MAT_NEAR (dst_ref, dst, 1 );
1081+ printf (" .\n " ); fflush (stdout);
1082+ }
1083+ }
1084+
1085+ // Case 2: concurent deallocation of UMatData between UMat and Mat deallocators. Hard to catch!
1086+ OCL_TEST (UMat, DISABLED_OCL_ThreadSafe_CleanupCallback_2_VeryLongTest)
1087+ {
1088+ if (!cv::ocl::useOpenCL ())
1089+ {
1090+ std::cout << " OpenCL is not enabled. Skip test" << std::endl;
1091+ return ;
1092+ }
1093+ for (int j = 0 ; j < 100 ; j++)
1094+ {
1095+ const Size srcSize (320 , 240 );
1096+ const int type = CV_8UC1;
1097+ const int dtype = CV_16UC1;
1098+
1099+ // This test is only relevant for OCL
1100+ UMat dst (srcSize, dtype);
1101+
1102+ // Use multiple iterations to increase chance of data race catching
1103+ for (int k = 0 ; k < 10000 ; k++)
1104+ {
1105+ Mat src (srcSize, type); // Declare src inside loop now to catch its destruction on stack
1106+ {
1107+ UMat tmpUMat = src.getUMat (ACCESS_RW);
1108+ tmpUMat.convertTo (dst, dtype);
1109+ }
1110+ ::cv::ocl::finish (); // force kernel to complete to start cleanup sooner
1111+ }
1112+ printf (" .\n " ); fflush (stdout);
1113+ }
1114+ }
1115+
1116+
10471117
10481118TEST (UMat, DISABLED_Test_same_behaviour_read_and_read)
10491119{
0 commit comments