0

I'm trying to modify my C++ program using CUDA 6.0 on Win7 to accept parameters from the command line and then copy them to constant memory. I get a invalid device symbol error and I don't understand why.

EDIT : I did see the solution at Invalid device symbol when copying to CUDA constant memory, but the difference is that my device constants are variables, not arrays. I tried duplicating the solution in there, but I get an error in intellisense (or whatever it is) stating that "argument of type int is incompatible with parameter of type const void*".

__device__ __constant__ int nc;

int main(int argc, char** argv)
{
    int hnc =2;  //Default value if no args passed in.

    if (argc > 1)
        hnc = strtod(argv[1], NULL);

    cudaMemcpyToSymbol(&nc, &hnc, sizeof(int));

    return 0;
}

Originally, I wanted to use a struct so that I can easily change the default model run parameters, but I got the same error.

struct modelParameters  //Contains other parameters, but reduced for readability.
{
    modelParameters() : nc(2) {}
    int nc;                             //Nucleus Size

} knowles;

__device__ __constant__ int nc;

int main(int argc, char** argv)
{
    int hnc = knowles.nc;    //Default value if no args passed in.

    if (argc > 1)
        hnc = strtod(argv[1], NULL);

    cudaMemcpyToSymbol(&nc, &hnc, sizeof(int));

    return 0;
}
Community
  • 1
  • 1
  • I don't understand what you are complaining about in your edit. The code in your first example is *exactly* the same as the code in the duplicate question with *exactly* the same mistake, and the solution is *exactly* as written in the answer. Where is there any ambiguity or difference? – talonmies Sep 04 '14 at 10:54
  • I was dumb and didn't just try building it. Visual studio was telling me the error I listed in the edit above, so I guess I need to just learn to ignore those errors and continue mission. For my edification, is there a reason that the symbols shouldn't be declared as "__device__ __constant__ int nc"? – Hair of Slytherin Sep 04 '14 at 19:04

0 Answers0