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;
...
}
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.
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.