Can someone tell me how to pass a variable of data type integer to the kernel??? It is already in my MEX file. Thanks
if it is just one value (no array):
my_kernel<<<>>>(int_variable);
Hello thanks again.
How about if it is an array?
the you will have to cudamalloc the appropriate amount of memory and cudamemcpy the data to the gpu. You then pass the pointer that was returned by cudamalloc to the kernel like
other_kernel<<<…>>>(int *device_pointer);
int N=... //number of elements in the array
float *myArray=...; //some array at your cpu
float *device_array; //will become our array on the gpu
cudaMalloc((void**)&device_array,sizeof(float)*N); //allocate memory on gpu, address to this memory is now in device_array
cudaMemcpy(device_array,myArray,sizeof(float)*N,cudaMemcpyHostToDevice); //copy contents of myArray (cpu) to device_array (gpu)
someKernel<<<...>>>(device_array);
cudaMemcpy(myArray,device_array,sizeof(float)*N,cudaMemcpyDeviceToHost); //copy contents of device_array (gpu) back to myArray (cpu)
for more information read the programming guide and/or reference manual.
[edit]
if you want int instead of float, just replace float with int ;-)