I followed the example in 1.7.7 Allocating Shared Memory for OpenCL Kernels Targeting SoCs, but my code runs with outputing wrong values (When using without the CL_MEM_ALLOC_HOST_PTR - part it works)
Do you have a full hello world example for this task? Or do you might look trough my implementation if i´m doing something wrong:
... context, queue, programm already created
input : Mat img (Matrix from OpenCV which holds an grayscale value)
int size_cols = COLS + 6; int size_rows = ROWS + 6;
copyMakeBorder(img, img,3,3,3,3,BORDER_REFLECT_101 );
Mat output(img.rows, img.cols, CV_8UC1);
int pixels = img.rows* img.cols;
// Buffer
buffer_img_GAUSS = clCreateBuffer(context, CL_MEM_ALLOC_HOST_PTR, sizeof(uchar) * size_cols * size_rows,NULL,&status);
checkError(status, "clCreateBuffer");
uchar *src_ptr = (uchar *)clEnqueueMapBuffer(cmdQueue, buffer_img_GAUSS, CL_TRUE, CL_MAP_READ, 0, sizeof(uchar) * size_cols* size_rows, 0, NULL, NULL, &status);
checkError(status, "clEnqueueMapBuffer");
*src_ptr = *img.data; // data = pointer to the data of img
buffer_outputimg_GAUSS = clCreateBuffer(context,CL_MEM_WRITE_ONLY, sizeof(uchar) * size_cols * size_rows,NULL,&status);
//Kernel
kernel_gaussneu = clCreateKernel(program, "gaussneu", &status);
// Set Arguments
status = clSetKernelArg(kernel_gaussneu,0,sizeof(cl_mem),&buffer_img_GAUSS);
checkError(status, "clSetKernelArg");
status = clSetKernelArg(kernel_gaussneu,1,sizeof(cl_mem),&buffer_outputimg_GAUSS);
status = clSetKernelArg(kernel_gaussneu,2,sizeof(int), &pixels);
size_t sobelSize = 1;
// Run Kernel
clEnqueueUnmapMemObject(cmdQueue, buffer_img_GAUSS, src_ptr, 0, NULL, NULL);
status = clEnqueueNDRangeKernel(cmdQueue, kernel_gaussneu, 1, NULL, &sobelSize, &sobelSize, 0, NULL, NULL);
checkError(status, "clEnqueueNDRangeKernel");
clFinish(cmdQueue);
// Get output
status = clEnqueueReadBuffer(cmdQueue, buffer_outputimg_GAUSS, CL_FALSE, 0, sizeof(uchar) * output.cols * output.rows, output.data, 0, NULL, NULL);
checkError(status, "clEnqueueReadBuffer");
Thanks for the help