Below I have included a standalone example that uses cudaMemcpyFromSymbol() to extract the result from the kernel. The example passes the character parameter (the second parameter in the call) as a regular variable. However, since I understand the CUDA documentation, passing the parameter as a string, i.e.:
cudaMemcpyFromSymbol(&out, "out_d", sizeof(out_d), 0, cudaMemcpyDeviceToHost);
(with quotes around the character name) should also work. This does not work for me.
When will the symbol name work and when will the symbol name be displayed as a string?
#include "cuda_runtime.h" #include <stdio.h> __device__ int out_d; __global__ void test() { out_d = 123; } int main() { test<<<1,1>>>(); int out; cudaMemcpyFromSymbol(&out, out_d, sizeof(out_d), 0, cudaMemcpyDeviceToHost); printf("%d\n", out); return 0; }
source share