Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the symbol parameter of cudaMemcpyFromSymbol()

Tags:

cuda

Below, I have included a self contained example that uses cudaMemcpyFromSymbol() to retrieve the result from a kernel. The example passes the symbol parameter (the second parameter in the call), as a regular variable. However, as I understand the CUDA documentation, passing the parameter as a string, that is:

cudaMemcpyFromSymbol(&out, "out_d", sizeof(out_d), 0, cudaMemcpyDeviceToHost);

(with quotes around the symbol name), should also work. That does not work for me.

When would the symbol name work and when would the symbol name as a string work?

#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;
}
like image 842
Roger Dahl Avatar asked Feb 10 '13 03:02

Roger Dahl


1 Answers

Passing the symbol name as a string parameter was deprecated in CUDA 4.2 and the syntax was eliminated in cuda 5.0. The reasons had to do with enabling of separate device code linker capability, which functionality appeared in CUDA 5. For the cuda 5 toolkit, this change is documented in the release notes:

  • The use of a character string to indicate a device symbol, which was possible with certain API functions, is no longer supported. Instead, the symbol should be used directly.
like image 79
Robert Crovella Avatar answered Sep 19 '22 20:09

Robert Crovella