【发布时间】:2014-08-20 06:53:39
【问题描述】:
我一直无法理解何时使用 cl_float、cl_uchar 等 OpenCL API 数据类型,可在此处找到:
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 吗?如果在这种情况下不需要,那么什么时候应该使用 opencl 类型?
【问题讨论】: