OpenCL中get_global_id与clEnqueueNDRangeKernel中维度数之间的关系是什么?

时间:2016-01-14 18:25:57

标签: opencl

例如,如果我有:

size_t local_dim[2]= [what should I place here?]
size_t global_dim[2]= [what should I place here?]

ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, 
                         NULL, global_dim, local_dim, 0, NULL, NULL)

或者:

ret = clEnqueueNDRangeKernel(command_queue, kernel, 2, 
                          NULL, global_dim, local_dim, 0, NULL, NULL)

当我在Cl Kernel函数中调用“get_global_id”函数时,如果我有2个维度而不是1,那么实践中有什么区别?如果我这样做:

int i = get_global_id(0);
int j = get_global_id(1);

只有两个维度例如,如果我有:

size_t local_dim[2]= [what should I place here?]
size_t global_dim[2]= [what should I place here?]

ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, 
                              NULL, global_dim, local_dim, 0, NULL, NULL)

或者:

ret = clEnqueueNDRangeKernel(command_queue, kernel, 2, 
                                 NULL, global_dim, local_dim, 0, NULL, NULL)

当我在Cl Kernel函数中调用“get_global_id”函数时,如果我在clEnqueueNDRangeKernel中有2个维度而不是1,那么实践中的区别是什么?如果我这样做:

int i = get_global_id(0);
int j = get_global_id(1);

只有两个维度,我会得到哪些值? 谢谢,抱歉这么乱,但我很困惑!

1 个答案:

答案 0 :(得分:3)

差异很明显。拥有多个维度并非“需要”,您可以始终拥有单个维度。但是,当您编写多维问题(图像滤镜,粒子模拟等等)时,使用多维度更加容易。

如果您设置了2维10x10,则将使用ID创建100个工作项:

Name: "{} Program Hours".format(programName)
Report Type: "Hour"
Filters
{ProgramID={}.format(programID),
EntryDate between 1/1/2016 and 12/13/2016,
JobRoleID={}.format(jobRoleID},}

Chart
Chart Type: "Gauge"
Color: Green Value = 100
Yellow Value = 200
Red Value = 300

如果您将1维设置为10x10,则OpenCL将忽略第二个参数,并使用ID创建10x1工作项:

int i = get_global_id(0); int j = get_global_id(1);  // 0,0
int i = get_global_id(0); int j = get_global_id(1);  // 0,1
...
int i = get_global_id(0); int j = get_global_id(1);  // 1,0
int i = get_global_id(0); int j = get_global_id(1);  // 1,1
...
int i = get_global_id(0); int j = get_global_id(1);  // 9,9

您仍然可以为任何维度调用int i = get_global_id(0); int j = get_global_id(1); // 0,0 int i = get_global_id(0); int j = get_global_id(1); // 1,0 ... int i = get_global_id(0); int j = get_global_id(1); // 9,0 ,但如果它不是维度0,则返回值将为0.