1
votes

The skeleton of the code is

a_kernel.cu

__constant__ unsigned char carray[256];

a.cu

#include <a_kernel.cu>
...
unsigned char h_carray[256];
...
cudaMemcpyToSymbol("carray", h_carray, 256);

The system configuration is
Windows7 64bit
CUDA toolkit 3.1, SDK 3.1
GeForce GTX 460
rules file in SDK 3.1

I've got invalid device symbol error string at cudaMemcpyToSymbol.
Any help would be appreciated. :)

2

2 Answers

0
votes

It would help if you could post some code to reproduce the problem, perhaps you could do this on the CUDA forums. Having said that, __constant__ variables have static (i.e. translation unit) scope. The simplest structure to follow would be as follows. Note that it may also be worth checking out CUDA 3.2.

host_code.cpp:

#include "cuda_funcs.h"

...
{
  unsigned char h_carray[256];
  cudaMemcpyToSymbol("carray", h_carray, 256);
  processOnGpu(...);
}
...

cuda_funcs.h:

void processOnGpu(...);

cuda_funcs.cu:

__constant__ unsigned char carray[256];

__global__ void kernel(...)
{
  ...
}

void processOnGpu(...)
{
  ...
  kernel<<<...>>>(...);
  ...
}
0
votes

Checkout the document in the cuda manual

You need to include the kind or direction of the memory copy. Maybe default is "cudaDevicetoHost".

cudaMemcpyToSymbol("carray", h_carray, 256, 0, cudaHostToDevice);