gpt4 book ai didi

c++ - OpenCL:clSetKernelArg 返回 CL_INVALID_ARG_SIZE

转载 作者:行者123 更新时间:2023-11-30 01:43:59 26 4
gpt4 key购买 nike

我是 OpenCL 的新手。我试图将 5 个参数传递给内核:一个输入缓冲区、一个输出缓冲区、一个整数和 2 个输入缓冲区大小的局部数组。

//Create input/output cl_mem objects
cl_mem inputBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY |
CL_MEM_COPY_HOST_PTR, inputVector.size(), (void *)inputVector.data(), NULL);
cl_mem outputBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
inputVector.size(), NULL, NULL);

//get iterator from command line
cl_uint iterations = (cl_uint) atoi(argv[3]);
//std::cout << "iterations: " << iterations << std::endl
//cout confirms I'm getting this correctly

//Set kernel arguments
bool argOK = (CL_SUCCESS == clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&inputBuffer));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&outputBuffer));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 2, sizeof(cl_uint), &iterations));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 3, sizeof(inputBuffer), NULL));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 4, sizeof(inputBuffer), NULL));
//Check for failure
if(!argOK) {
std::cerr << "Error: clSetKernelArg failed\n";
return SDK_FAILURE;
}

当我运行程序时,它会打印:

Error:  clSetKernelArg failed

我做了一些挖掘/调试,最终发现这一行:

argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 2, sizeof(cl_uint), &iterations));

是罪魁祸首。将其更改为:

argOK = argOK && (CL_INVALID_ARG_SIZE == clSetKernelArg(kernel, 2, sizeof(cl_uint), &iterations));

让程序成功继续。 因此,clSetKernelArg(kernel, 2, ...) 语句返回 CL_INVALID_ARG_SIZE。不过这很奇怪,因为看起来我为迭代变量传递了正确的大小。

这是我的内核供引用:

__kernel void do_the_thing (__global uchar* in, __global uchar* out,
__global uint * numIterations, __local uchar* arr1, __local uchar* arr2)
{
//Do stuff that I haven't written yet.

}

TL;DR:为什么 setKernelArg 调用返回 CL_INVALID_ARG_SIZE?

最佳答案

内核的第三个参数 (index = 2) 是缓冲区 (__global uint *) 而不是 cl_uint 标量。

将内核更改为:

__kernel void do_the_thing (__global uchar* in, __global uchar* out, uint numIterations, __local uchar* arr1, __local uchar* arr2)
{
//Do stuff that I haven't written yet.

}

关于c++ - OpenCL:clSetKernelArg 返回 CL_INVALID_ARG_SIZE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36946420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com