我一直无法理解何时使用 OpenCL API 数据类型,如 cl_float、cl_uchar 等,可以在此处找到:
http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/scalarDataTypes.html
我见过的涉及将缓冲区复制到设备的示例如下所示:
float data[DATA_SIZE]; // original data set given to device
//Create the input and output arrays in device memory for our calculation
input = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * count, NULL,
// Write our data set into the input array in device memory
err = clEnqueueWriteBuffer(commands, input, CL_TRUE, 0, sizeof(float) * count, data, 0, NULL, NULL);
if (err != CL_SUCCESS)
{
printf("Error: Failed to write to source array!\n");
exit(1);
}
此代码直接取自此处提供的 Apple 代码示例:https://developer.apple.com/library/mac/samplecode/OpenCL_Hello_World_Example/Listings/ReadMe_txt.html
您会注意到在上面的代码中,浮点数组被复制到设备。为什么这不需要是 cl_floats 数组?内存是直接复制的吧?如果您的主机浮动和设备浮动大小不同,会发生什么情况?
您能解释一下为什么不需要使用 cl_float 吗?如果在这种情况下没有必要,那么当should使用opencl类型?