|
|
|
@ -2755,7 +2755,7 @@ KernelArg KernelArg::Constant(const Mat& m) |
|
|
|
|
struct Kernel::Impl |
|
|
|
|
{ |
|
|
|
|
Impl(const char* kname, const Program& prog) : |
|
|
|
|
refcount(1), handle(NULL), isInProgress(false), nu(0) |
|
|
|
|
refcount(1), handle(NULL), isInProgress(false), isAsyncRun(false), nu(0) |
|
|
|
|
{ |
|
|
|
|
cl_program ph = (cl_program)prog.ptr(); |
|
|
|
|
cl_int retval = 0; |
|
|
|
@ -2832,6 +2832,7 @@ struct Kernel::Impl |
|
|
|
|
enum { MAX_ARRS = 16 }; |
|
|
|
|
UMatData* u[MAX_ARRS]; |
|
|
|
|
bool isInProgress; |
|
|
|
|
bool isAsyncRun; // true if kernel was scheduled in async mode
|
|
|
|
|
int nu; |
|
|
|
|
std::list<Image2D> images; |
|
|
|
|
bool haveTempDstUMats; |
|
|
|
@ -3111,13 +3112,45 @@ bool Kernel::run(int dims, size_t _globalsize[], size_t _localsize[], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool isRaiseErrorOnReuseAsyncKernel() |
|
|
|
|
{ |
|
|
|
|
static bool initialized = false; |
|
|
|
|
static bool value = false; |
|
|
|
|
if (!initialized) |
|
|
|
|
{ |
|
|
|
|
value = cv::utils::getConfigurationParameterBool("OPENCV_OPENCL_RAISE_ERROR_REUSE_ASYNC_KERNEL", false); |
|
|
|
|
initialized = true; |
|
|
|
|
} |
|
|
|
|
return value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Kernel::Impl::run(int dims, size_t globalsize[], size_t localsize[], |
|
|
|
|
bool sync, int64* timeNS, const Queue& q) |
|
|
|
|
{ |
|
|
|
|
CV_INSTRUMENT_REGION_OPENCL_RUN(name.c_str()); |
|
|
|
|
|
|
|
|
|
if (!handle || isInProgress) |
|
|
|
|
if (!handle) |
|
|
|
|
{ |
|
|
|
|
CV_LOG_ERROR(NULL, "OpenCL kernel has zero handle: " << name); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isAsyncRun) |
|
|
|
|
{ |
|
|
|
|
CV_LOG_ERROR(NULL, "OpenCL kernel can't be reused in async mode: " << name); |
|
|
|
|
if (isRaiseErrorOnReuseAsyncKernel()) |
|
|
|
|
CV_Assert(0); |
|
|
|
|
return false; // OpenCV 5.0: raise error
|
|
|
|
|
} |
|
|
|
|
isAsyncRun = !sync; |
|
|
|
|
|
|
|
|
|
if (isInProgress) |
|
|
|
|
{ |
|
|
|
|
CV_LOG_ERROR(NULL, "Previous OpenCL kernel launch is not finished: " << name); |
|
|
|
|
if (isRaiseErrorOnReuseAsyncKernel()) |
|
|
|
|
CV_Assert(0); |
|
|
|
|
return false; // OpenCV 5.0: raise error
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cl_command_queue qq = getQueue(q); |
|
|
|
|
if (haveTempDstUMats) |
|
|
|
|