Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the relation in OpenCL between get_global_id and the number of dimensions in clEnqueueNDRangeKernel?

Tags:

opencl

For example, if I have :

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)

Or:

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

What's the difference in practice if I have 2 dimensions instead of 1 when i call "get_global_id" function in Cl Kernel function? And if I do:

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

with only two dimensions in For example, if I have :

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)

Or:

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

What's the difference in practice if I have 2 dimensions in clEnqueueNDRangeKernel instead of 1 when i call "get_global_id" function in Cl Kernel function? And if I do:

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

with only two dimensions, which values would I get? Thanks and sorry for such a mess, but I'm very confused!

like image 832
Melvin Avatar asked Jan 20 '26 05:01

Melvin


1 Answers

The difference is obvious. It is not "needed" to have multiple dimensions, you can always have a single dimension. However, it is incredible easier to work with multiple dimension when you are writing a multidimensional problem (Image filters, particle simulations, etc...).

If you set a 2 dimensional 10x10, then 100 work items will be created with ids:

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

While if you set a 1 dimension of 10x10, OpenCL will ignore the second argument and just create 10x1 work items with ids:

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

You can still call get_global_id() for any dimension, however if it is not the dimension 0, the return value will be 0.

like image 157
DarkZeros Avatar answered Jan 22 '26 19:01

DarkZeros