0

The function cudaMemcpyFromSymbol is templated and takes a __device__ variable. We can't give the address of the source, so I don't see how we can pass __device__ variables dynamically (as argument). Maybe with references?

__device__ float d_f;

void test1()
{
    float h_f;
    cudaMemcpyFromSymbol(&h_f, d_f, sizeof(float)); // Ok
}

void test2(float d_arg_f)
{
    float h_f;
    cudaMemcpyFromSymbol(&h_f, d_arg_f, sizeof(float)); // Not ok
}

void test3(float& d_arg_f)
{
    float h_f;
    cudaMemcpyFromSymbol(&h_f, d_arg_f, sizeof(float)); // Is it ok?
}

int main()
{
    test1();
    test2(d_f);
    test3(d_f);
}

EDIT: removed the first question which did actually not compile.

rafoo
  • 1,506
  • 10
  • 17
  • Does this answer your question? [Understanding the symbol parameter of cudaMemcpyFromSymbol()](https://stackoverflow.com/questions/14794319/understanding-the-symbol-parameter-of-cudamemcpyfromsymbol) – wohlstad Apr 05 '22 at 07:36
  • 2
    Perhaps this also answers your question: https://stackoverflow.com/questions/26075972/cudamemcpyfromsymbol-on-a-device-variable – Ander Biguri Apr 05 '22 at 08:43
  • 2
    I would say your question is basically a duplicate of the one Ander Biguri found. `cudaMemcpyFromSymbol` [requires](https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__MEMORY.html#group__CUDART__MEMORY_1g17ce3365ef7b6687a7d16c5b29de1f82) that the second argument be a device symbol. In `test1` you are using it correctly. In `test2` and `test3`, `d_arg_f` is not a device symbol (nor is it a device symbol address, nor does it contain a device symbol address). – Robert Crovella Apr 05 '22 at 14:09
  • `test2()` works correctly in test – rafoo Apr 07 '22 at 00:05

0 Answers0