How to read values from memories?

Hi all,

I have two .cu files–alg.cu and alg_kernel.cu. How can I retrieve the value of vars from kernel? Do I need to pass them through parameters of the kernel function?

alg.cu

int maxI,gMaxI,a,b,c;

...

maxI=1;

....

CUDA_SAFE_CALL(cudaMalloc((void**)&gMaxI,sizeof(int)));

CUDA_SAFE_CALL(cudaMemcpy(gMaxI,maxI,sizeof(maxI),cudaMemcpyHostToDevice));

myKernel<<<dimGrid,dimBlock>>>(a,b,c);

alg_kernel.cu

__global__ void myKernel(int a, int b, int c){

                 ...

                 //Can I directly get gMaxI value here?

                 int d = gMaxI;

                 ...

}

Appreciate.

single values you can just pass to the kernel. Allocating memory on the device and cudamemcopy-ing data from host to that memory is only necessary for arrays.

Yap, understand. But I am still wondering if it is doable? And BTW, does it has __constant__in CUDA 1.1? I always get errors when I try to use it.

You can do this

myKernel<<<dimGrid,dimBlock>>>(a,b,c, maxI);

global void myKernel(int a, int b, int c, int maxI){

int d = maxI;

--------------------------------------------- or this

constant int maxI;

int dummy = 1;
CUDA_SAFE_CALL( cudaMemcpyToSymbol(maxI, &dummy, 1 * sizeof(int))

myKernel<<<dimGrid,dimBlock>>>(a,b,c);

global_ void myKernel(int a, int b, int c){

int d = maxI;

Yes, that’s exactly what I have tried. But I got an error: Error 1 fatal error C1057: unexpected end of file in macro expansion c:\Program Files\NVIDIA Corporation\NVIDIA CUDA SDK\projects\SM2D\SW2D.cu 173.

Hmmmm…any idea whaz wrong with it?? :[

not without knowing what is at line 173 of SW2D.cu