Search code examples
cudac-preprocessornvcccufft

How can I tell if cuda code is being compiled with relocatable device code?


In order to use CUFFT callbacks, one of the restrictions is that the code must be compiled with relocatable relocatable device code.

When this condition is not met, bad things happen; silent failures, wrong answers, etc.

I've got my current build working, but I'd like to make this code more robust against mis-compilation in future projects.

Is there any way to detect this inside the compilation unit? e.g. preprocessor flags


Solution

  • The macro to use to detect when -rdc=true is specified is:

    __CUDACC_RDC__
    

    published here

    As a simple test case, you could do:

    $ cat t1.cu
    #ifndef __CUDACC_RDC__
    #error THIS CODE REQUIRES CUDA RELOCATABLE DEVICE CODE COMPILATION
    #endif
    
    int main(){}
    $ nvcc -c t1.cu
    t1.cu:2:2: error: #error THIS CODE REQUIRES CUDA RELOCATABLE DEVICE CODE COMPILATION
     #error THIS CODE REQUIRES CUDA RELOCATABLE DEVICE CODE COMPILATION
      ^
    $ nvcc -rdc=true -c t1.cu
    $