我想将输入图像写入缓冲区并在主机程序的while循环中执行内核文件(而不是在内核文件中)。我确实在 while 循环之外设置了 OpenCL 的东西(上下文、设备、缓冲区、命令队列等),将图像写入我在循环中创建的缓冲区,然后运行内核。它可以在我的桌面上运行,但是当我在 i.mx6 板上执行它时,它会在第二个 while 循环中返回分段错误错误。代码如下。
while (count < 10)
{
unsigned char* input = (unsigned char*)inImg.data;
start = clock();
unsigned char* output = (unsigned char*)malloc(width * height * sizeof(unsigned char));
size_t localWorkSize[2] = { WGX, WGY };
size_t globalWorkSize[2] = { RoundUp(WGX, width), RoundUp(WGY, height) };
cl_mem cl_inImg = clCreateBuffer(context, CL_MEM_READ_ONLY, width * height * sizeof(unsigned char) * inImg.channels(), NULL, &ret);
/*error check*/
cl_mem cl_outImg = clCreateBuffer(context, CL_MEM_WRITE_ONLY, width * height * sizeof(unsigned char) * inImg.channels(), NULL, &ret);
/*error check*/
int filterSize = 5;
int paddingSize = (int)(filterSize / 2) * 2;
int localWidth = WGX + paddingSize;
int localHeight = WGY + paddingSize;
size_t localMemSize = (localWidth * localHeight * sizeof(unsigned char) * inImg.channels());
clEnqueueWriteBuffer(queue, cl_inImg, CL_TRUE, 0, width * height * sizeof(unsigned char) * inImg.channels(), input, 0, NULL, NULL);
cl_int errNum = 0;
errNum = clSetKernelArg(kernel, 0, sizeof(cl_mem), &cl_inImg);
errNum |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &cl_outImg);
errNum |= clSetKernelArg(kernel, 2, localMemSize, NULL);
errNum |= clSetKernelArg(kernel, 3, sizeof(int), &filterSize);
errNum |= clSetKernelArg(kernel, 4, sizeof(int), &localWidth);
errNum |= clSetKernelArg(kernel, 5, sizeof(int), &localHeight);
errNum |= clSetKernelArg(kernel, 6, sizeof(int), &width);
errNum |= clSetKernelArg(kernel, 7, sizeof(int), &height);
/*error check*/
errNum = clEnqueueNDRangeKernel(queue, kernel, 2, NULL,
globalWorkSize, localWorkSize,
0, NULL, NULL);
/*error check*/
clFinish(queue);
errNum = clEnqueueReadBuffer(queue, cl_outImg,
CL_TRUE, 0, width * height * sizeof(unsigned char) * inImg.channels(), output, 0, NULL, NULL);
/*error check*/
}
我找不到我做错的地方,因为它在我的电脑上正常工作。我应该如何解决这个问题?