1

I have a cuda project containing the following files

Header File:

 Declarations.h

Main File:

 main.cpp:
    #include "Declarations.h"

And Kernel File:

Kernel.cu:
    #include "Declarations.h"

In main.cpp, I have float K1[3*3] which I want to copy to GPU constant memory. To do so, I declared __constant__ float K1_d[3*3];in Declarations.h and In main.cpp I did

checkCudaErrors( cudaMemcpyToSymbol(&K1_d, &K1, 9*sizeof(float)) );

When running the code I got the following error: CUDA error at c:\users\xxx\test.cpp:241 code=13(cudaErrorInvalidSymbol) "cudaMemcpyToSymbol(&K1, &K1_inv, 9*sizeof(float))"

I tried to copy one variable, for example, I declared in the header file

__constant__ float N;

And did:checkCudaErrors( cudaMemcpyToSymbol(&N, &K1_inv[0], sizeof(float)) );

I got the same error message of the macro chechCudaErrors.

How to transer variables to constant memory in CUDA?`

einpoklum
  • 118,144
  • 57
  • 340
  • 684
Didon
  • 383
  • 2
  • 4
  • 13
  • There are many questions like this and two options. The duplicate linked answer suggests the simplest option - modify your code so that the `__constant__` declaration and the `cudaMemcpyToSymbol` usage are in the same file (compilation/translation unit). You can also work with separate compilation and linking and use of `extern` to avoid this (such as discussed [here](http://stackoverflow.com/questions/18213988/cuda-constant-memory-symbols) ). You will find other questions and answers about that if you search here on SO. – Robert Crovella Apr 23 '15 at 15:01

0 Answers0