ccudagpgpu

Pass the data from CPU to GPU without explicitly passing it as a parameter


Is it possible to pass the data from CPU to GPU without explicitly passing it as a parameter?

I don't want to pass it as a parameter primarily for syntax sugar reasons - I have about 20 constant parameters I need to pass, and also because I successively invoke two kernels with (almost) same parameters.

I want something along the lines of

__constant__ int* blah;

__global__ myKernel(...){
    ... i want to use blah inside ...
}

int main(){
    ...
    cudaMalloc(...allocate blah...)
    cudaMemcpy(copy my array from CPU to blah)

}

Solution

  • cudaMemcpyToSymbol seems to be the function you're looking for. It works similarly to cudaMemcpy, but with an additional 'offset' argument which looks like it'll make it easier to copy across 2D arrays.

    (I'm hesitant to provide code, since I'm unable to test it - but see this thread and this post for reference.)