Search code examples
cudanvcc

How do I convert a __CUDACC_VER__ value into a MAJOR, MINOR, BUILD triplet?


When a newer (CUDA 9) version of nvcc encounters __CUDACC_VER__, it gives up and tells you something like:

/usr/local/cuda/include/crt/common_functions.h:64:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."

So, how do I convert uses of __CUDACC_VER__ into something that will work both for older and newer versions of NVCC?


Solution

  • Partial answer:

    For newer versions at least, the NVCC documentation tells us (on Page 3) what the formula is:

    __CUDACC_VER__ = 
         __CUDACC_VER_MAJOR__ * 10000 +
         __CUDACC_VER_MINOR__ * 100 +
         __CUDACC_VER_BUILD__
    

    thus, for example, checking for an nvcc from CUDA 7.5 or later means checking

    (__CUDACC_VER__ > 70500)
    

    and with the triplet of values you would write

    (__CUDACC_VER_MAJOR__ > 7) or ((__CUDACC_VER_MAJOR__ == 7) and (__CUDACC_VER_MINOR__ >= 5))
    

    instead.