get_global_id is undefined

Hi All,

Sorry for this (stupid) question. I’m new to OpenCL programming.

I’ve downloaded the CUDA SDK v5 and I’m trying to write my first applications.

I trying to use the function get_global_id but I got a message saying that it is undefined. I was not able to find this function in any include file.

Can someone please tell me what happened with this function?

Thanks a lot!

get_global_id() is a built-in of OpenCL C, so it is only defined inside of kernels. Are you trying to use it in host code? please post a minimal buildable example showing the problem.

Hi Bilog!

First of all, thank you very much for your help!

The code is very simple:


__kernel
	void array_add(__global const double *a1, __global const double *a2, __global double *ar)
{
    int id = get_global_id(0);
    ar[id] = a1[id] + a2[id];
}

I’ve tried to change “__kernel” to “global”, since “__kernel” is also not recognized but I had no success.

Actually I just wanted to use OpenCL instead of using CUDA. I’m using the CUDA SDK due to my GPU (NVIDIA GeForce GT630M). But it seems that there are some OpenCL types/functions in the CUDA SDK. But I was not able to find the function get_global_id (or “__kernel”).

Can you help me with this?

Again, thanks a lot!

Hi Bilog,

Not sure but now I think I understood my problem. Again, sorry for my ignorance.

The kernel code will not be compiled within the .cu file, right?

Should I create a separate file containing the kernel code and then load in the .cu file using the function clCreateKernel?

Is there any way to debug this code?

Thank you!

OpenCL source files usually end in “.cl” (.cu is used by CUDA). But no, .cl files contain the source code.

To get a kernel first create a cl_program object with clCreateProgramWithSource(), next build the program with clBuildProgram(), and then create the kernel object with clCreateKernel().