Error 13 from cudaMemcpyToSymbol in bicubicTexture, which is one of CUDA SDK samples

I add three lines in bicubicTexture.cpp.
An array with constant memory space specifier is declared as global variable.

__constant__ int a[2];

And here is the main

main(int argc, char **argv)
    int la[2] = { 0,1 };
    cudaMemcpyToSymbol(a, la, 2 * sizeof(int));

Then I get an error.

getLastCudaError() CUDA error : kernel failed : (13) invalid device symbol.

Why this happens and how can I solve this problem? Thanks.

  1. You should not add:

    __constant__ int a[2];

    to bicubicTexture.cpp

    A .cpp file generally cannot contain cuda-specific syntax such as __constant__. Yes, it happens to compile, but this is almost certainly not what you want.

  2. It’s unlikely that this is what you want to do anyway. Presumably you would want to access the variable a in kernel code. But there is no kernel code in bicubicTexture.cpp

My suggestion would be to add this kind of stuff to Yes, there doesn’t happen to be a main function in there, but you should use one of the existing functions there to do this, or add a new wrapper function there that you call from main, that populates the __constant__ variable.

Another reason for this suggestion is that although it is possible to define the __constant__ variable in another module, you will need to introduce cross-module device code linking. I wouldn’t add that complexity unless I needed to for some other reason.


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.