Blog posts
I have faced with two different types of errors. Here is the solutions
Error 1: cudaMemcpyToSymbol invalid argument
this is because of missing arguments;
use this;
__constant__ int x[100];
int x_h[100];
cudaStatus = cudaMemcpyToSymbol(x, x_h, sizeof(int) * 100, 0, cudaMemcpyHostToDevice);
instead of this;__constant__ int x[100];
int x_h[100];
cudaStatus = cudaMemcpyToSymbol(x, x_h, sizeof(int) * 100, cudaMemcpyHostToDevice);
Error 2: cudaMemcpyToSymbol invalid device symbol
This is a bit more surprising. Documentation says function definition as follows;
cudaError_t cudaMemcpyToSymbol ( const char * symbol,
const void * src,
size_t count,
size_t offset = 0,
enum cudaMemcpyKind kind = cudaMemcpyHostToDevice
)
But, when you are trying to copy just 1 variable instead of the error. You don't need address of the destination (Weird :))
Use this;
__constant__ int x;
int x_h;
int x_h[100];
cudaStatus = cudaMemcpyToSymbol(x, &x_h, sizeof(int), 0, cudaMemcpyHostToDevice);
instead of this;__constant__ int x[100];
int x_h[100];
cudaStatus = cudaMemcpyToSymbol(&x, &x_h, sizeof(int), 0, cudaMemcpyHostToDevice);
I hope this article be helpful for you
by zgrw on 2013-06-29 23:53:42