Refactor OpenCL initialization and allow to use ocl module witout explicit setup
This commit is contained in:
@@ -94,15 +94,15 @@ namespace cv
|
||||
for(size_t i = 0; i < args.size(); i ++)
|
||||
openCLSafeCall(clSetKernelArg(kernel, i, args[i].first, args[i].second));
|
||||
|
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 3, NULL, globalThreads,
|
||||
openCLSafeCall(clEnqueueNDRangeKernel((cl_command_queue)clCxt->oclCommandQueue(), kernel, 3, NULL, globalThreads,
|
||||
localThreads, 0, NULL, NULL));
|
||||
|
||||
switch(finish_mode)
|
||||
{
|
||||
case CLFINISH:
|
||||
clFinish(clCxt->impl->clCmdQueue);
|
||||
clFinish((cl_command_queue)clCxt->oclCommandQueue());
|
||||
case CLFLUSH:
|
||||
clFlush(clCxt->impl->clCmdQueue);
|
||||
clFlush((cl_command_queue)clCxt->oclCommandQueue());
|
||||
break;
|
||||
case DISABLE:
|
||||
default:
|
||||
@@ -126,7 +126,7 @@ namespace cv
|
||||
openCLExecuteKernel_2(clCxt, source, kernelName, globalThreads, localThreads, args, channels, depth,
|
||||
build_options, finish_mode);
|
||||
}
|
||||
|
||||
|
||||
cl_mem bindTexture(const oclMat &mat)
|
||||
{
|
||||
cl_mem texture;
|
||||
@@ -177,7 +177,7 @@ namespace cv
|
||||
desc.buffer = NULL;
|
||||
desc.num_mip_levels = 0;
|
||||
desc.num_samples = 0;
|
||||
texture = clCreateImage(mat.clCxt->impl->clContext, CL_MEM_READ_WRITE, &format, &desc, NULL, &err);
|
||||
texture = clCreateImage((cl_context)mat.clCxt->oclContext(), CL_MEM_READ_WRITE, &format, &desc, NULL, &err);
|
||||
#else
|
||||
texture = clCreateImage2D(
|
||||
mat.clCxt->impl->clContext,
|
||||
@@ -195,10 +195,10 @@ namespace cv
|
||||
cl_mem devData;
|
||||
if (mat.cols * mat.elemSize() != mat.step)
|
||||
{
|
||||
devData = clCreateBuffer(mat.clCxt->impl->clContext, CL_MEM_READ_ONLY, mat.cols * mat.rows
|
||||
devData = clCreateBuffer((cl_context)mat.clCxt->oclContext(), CL_MEM_READ_ONLY, mat.cols * mat.rows
|
||||
* mat.elemSize(), NULL, NULL);
|
||||
const size_t regin[3] = {mat.cols * mat.elemSize(), mat.rows, 1};
|
||||
clEnqueueCopyBufferRect(mat.clCxt->impl->clCmdQueue, (cl_mem)mat.data, devData, origin, origin,
|
||||
clEnqueueCopyBufferRect((cl_command_queue)mat.clCxt->oclCommandQueue(), (cl_mem)mat.data, devData, origin, origin,
|
||||
regin, mat.step, 0, mat.cols * mat.elemSize(), 0, 0, NULL, NULL);
|
||||
}
|
||||
else
|
||||
@@ -206,10 +206,10 @@ namespace cv
|
||||
devData = (cl_mem)mat.data;
|
||||
}
|
||||
|
||||
clEnqueueCopyBufferToImage(mat.clCxt->impl->clCmdQueue, devData, texture, 0, origin, region, 0, NULL, 0);
|
||||
clEnqueueCopyBufferToImage((cl_command_queue)mat.clCxt->oclCommandQueue(), devData, texture, 0, origin, region, 0, NULL, 0);
|
||||
if ((mat.cols * mat.elemSize() != mat.step))
|
||||
{
|
||||
clFinish(mat.clCxt->impl->clCmdQueue);
|
||||
clFinish((cl_command_queue)mat.clCxt->oclCommandQueue());
|
||||
clReleaseMemObject(devData);
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ namespace cv
|
||||
}
|
||||
|
||||
bool support_image2d(Context *clCxt)
|
||||
{return false;
|
||||
{
|
||||
static const char * _kernel_string = "__kernel void test_func(image2d_t img) {}";
|
||||
static bool _isTested = false;
|
||||
static bool _support = false;
|
||||
@@ -234,7 +234,7 @@ namespace cv
|
||||
try
|
||||
{
|
||||
cv::ocl::openCLGetKernelFromSource(clCxt, &_kernel_string, "test_func");
|
||||
_support = true;
|
||||
//_support = true;
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
|
Reference in New Issue
Block a user