cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

uforob
Journeyman III

cl_uint to size_t

I would like to create an application using a number of work-items equal to number of compute_units (i already have an application with number of items equals to number of the cells of the grid but i would like to confront this new implementation on CPU).

I'm having troubles because the number of compute units is of type cl_uint and the global worl size is obviously size_t, I tried normal assignment and various explicit casting but the result of a printf of global work size variable is always 0.

I'm using pure C, not C++, on GNU/Linux. I'm sure the error is that because assigning a number (e.g. 😎 to the global work size variable the printf and all computation are correct

Thank you.

0 Likes
6 Replies
nou
Exemplar

there should be no problem with assign cl_uint to size_t as both are unsigned 32-bit integers. (on 64-bit system size_t is 64 bit so it got converted)

don't you have just problem with printing size_t as you are on 64 bit platform? printf just takes first half of size_t variable which is just 0.

0 Likes
uforob
Journeyman III

The platform i'm trying now is  64-bit but I don't think the problem is that.: if i assign 8 to global_work_size of type size_t the printf is correct (even bacause casting to int is needed at compile time) and also calculations are correct, when I try with number of compte units printf is 0 and also calculations are uncorrect.

I can't simply assign the number of cores bacause thr program have to run on machines with varying number of cores.

0 Likes

you should post some code.

0 Likes
uforob
Journeyman III

I solved using directly size_t type for the number of the compute units.

The code runs correctly also using sizeof(cl_uint) in clGetDeviceInfo (but with compute_units of type size_t) but if I try to use type cl_uint for compute_units the code doesn't work correctly.

The code doesn't workcorrectly with compute_units of type cl_uint and sizeof(size_t), too.

size_t compute_units; size_t global_work_size; clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(name), &name, NULL); printf("The name of the current device is: %s\n", name); clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(size_t), &compute_units, NULL); printf("Number of compute units: %d\n", (int)compute_units); global_work_size = compute_units; printf("Global work size is %d\n", (int)global_work_size);

0 Likes

one thing. you under utilize GPU with this approach. each compute unit can run 64 or more workitems in work group. look at CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE

0 Likes
uforob
Journeyman III

I know that, as I said in the first message I've also a version that uses one work-item for each cell of a grid, this version is thought specifically for CPU.

0 Likes