Merge pull request #22855 from kallaballa:print_cl_status_on_fail

Print CL status code on error in opengl interop functions
pull/22866/head
Amir Hassan 2 years ago committed by GitHub
parent 6ca205a029
commit 3f371fe2dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      modules/core/src/opengl.cpp

@ -1638,14 +1638,14 @@ Context& initializeContextFromGL()
cl_uint numPlatforms;
cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get number of platforms");
CV_Error_(cv::Error::OpenCLInitError, "OpenCL: Can't get number of platforms: %d ", status);
if (numPlatforms == 0)
CV_Error(cv::Error::OpenCLInitError, "OpenCL: No available platforms");
std::vector<cl_platform_id> platforms(numPlatforms);
status = clGetPlatformIDs(numPlatforms, &platforms[0], NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get number of platforms");
CV_Error_(cv::Error::OpenCLInitError, "OpenCL: Can't get number of platforms: %d ", status);
// TODO Filter platforms by name from OPENCV_OPENCL_DEVICE
@ -1667,7 +1667,7 @@ Context& initializeContextFromGL()
status = clGetPlatformInfo(platforms[i], CL_PLATFORM_EXTENSIONS, extensionSize, (char*)extensionStr.data(), NULL);
}
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get platform extension string");
CV_Error_(cv::Error::OpenCLInitError, "OpenCL: Can't get platform extension string: %d ", status);
if (!strstr((const char*)extensionStr.data(), "cl_khr_gl_sharing"))
continue;
@ -1759,31 +1759,31 @@ void convertToGLTexture2D(InputArray src, Texture2D& texture)
cl_int status = 0;
cl_mem clImage = clCreateFromGLTexture(context, CL_MEM_WRITE_ONLY, gl::TEXTURE_2D, 0, texture.texId(), &status);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLTexture failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLTexture failed: %d ", status);
cl_mem clBuffer = (cl_mem)u.handle(ACCESS_READ);
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
status = clEnqueueAcquireGLObjects(q, 1, &clImage, 0, NULL, NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed: %d ", status);
size_t offset = 0; // TODO
size_t dst_origin[3] = {0, 0, 0};
size_t region[3] = { (size_t)u.cols, (size_t)u.rows, 1};
status = clEnqueueCopyBufferToImage(q, clBuffer, clImage, offset, dst_origin, region, 0, NULL, NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueCopyBufferToImage failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueCopyBufferToImage failed: %d ", status);
status = clEnqueueReleaseGLObjects(q, 1, &clImage, 0, NULL, NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed: %d ", status);
status = clFinish(q); // TODO Use events
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed: %d ", status);
status = clReleaseMemObject(clImage); // TODO RAII
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed: %d ", status);
#endif
}
@ -1821,31 +1821,31 @@ void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst)
cl_int status = 0;
cl_mem clImage = clCreateFromGLTexture(context, CL_MEM_READ_ONLY, gl::TEXTURE_2D, 0, texture.texId(), &status);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLTexture failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLTexture failed: %d ", status);
cl_mem clBuffer = (cl_mem)u.handle(ACCESS_READ);
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
status = clEnqueueAcquireGLObjects(q, 1, &clImage, 0, NULL, NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed: %d ", status);
size_t offset = 0; // TODO
size_t src_origin[3] = {0, 0, 0};
size_t region[3] = { (size_t)u.cols, (size_t)u.rows, 1};
status = clEnqueueCopyImageToBuffer(q, clImage, clBuffer, src_origin, region, offset, 0, NULL, NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueCopyImageToBuffer failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueCopyImageToBuffer failed: %d ", status);
status = clEnqueueReleaseGLObjects(q, 1, &clImage, 0, NULL, NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed: %d ", status);
status = clFinish(q); // TODO Use events
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed: : %d ", status);
status = clReleaseMemObject(clImage); // TODO RAII
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed: : %d ", status);
#endif
}
@ -1883,13 +1883,13 @@ UMat mapGLBuffer(const Buffer& buffer, AccessFlag accessFlags)
cl_int status = 0;
cl_mem clBuffer = clCreateFromGLBuffer(context, clAccessFlags, buffer.bufId(), &status);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLBuffer failed");
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLBuffer failed: %d ", status);
gl::Finish();
status = clEnqueueAcquireGLObjects(clQueue, 1, &clBuffer, 0, NULL, NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed");
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed: %d ", status);
size_t step = buffer.cols() * buffer.elemSize();
int rows = buffer.rows();
@ -1921,15 +1921,15 @@ void unmapGLBuffer(UMat& u)
cl_int status = clEnqueueReleaseGLObjects(clQueue, 1, &clBuffer, 0, NULL, NULL);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed: %d ", status);;
status = clFinish(clQueue);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed: %d ", status);;
status = clReleaseMemObject(clBuffer);
if (status != CL_SUCCESS)
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed");
CV_Error_(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed: %d ", status);;
#endif
}

Loading…
Cancel
Save