6 Replies Latest reply on Jan 7, 2012 1:47 PM by uforob

    cl_uint to size_t

    uforob

      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. 8) to the global work size variable the printf and all computation are correct

      Thank you.

        • cl_uint to size_t
          nou

          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.

            • cl_uint to size_t
              uforob

              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.

                • cl_uint to size_t
                  nou

                  you should post some code.

                    • cl_uint to size_t
                      uforob

                      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);