2

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

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mark Borgerding
  • 8,117
  • 4
  • 30
  • 51

1 Answers1

1

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
$
Robert Crovella
  • 143,785
  • 11
  • 213
  • 257