nvcc.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright Benjamin Worpitz 2018
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BOOST_PREDEF_COMPILER_NVCC_H
  8. #define BOOST_PREDEF_COMPILER_NVCC_H
  9. #include <boost/predef/version_number.h>
  10. #include <boost/predef/make.h>
  11. /* tag::reference[]
  12. = `BOOST_COMP_NVCC`
  13. https://en.wikipedia.org/wiki/NVIDIA_CUDA_Compiler[NVCC] compiler.
  14. Version number available as major, minor, and patch beginning with version 7.5.
  15. [options="header"]
  16. |===
  17. | {predef_symbol} | {predef_version}
  18. | `+__NVCC__+` | {predef_detection}
  19. | `+__CUDACC_VER_MAJOR__+`, `+__CUDACC_VER_MINOR__+`, `+__CUDACC_VER_BUILD__+` | V.R.P
  20. |===
  21. */ // end::reference[]
  22. #define BOOST_COMP_NVCC BOOST_VERSION_NUMBER_NOT_AVAILABLE
  23. #if defined(__NVCC__)
  24. # if !defined(__CUDACC_VER_MAJOR__) || !defined(__CUDACC_VER_MINOR__) || !defined(__CUDACC_VER_BUILD__)
  25. # define BOOST_COMP_NVCC_DETECTION BOOST_VERSION_NUMBER_AVAILABLE
  26. # else
  27. # define BOOST_COMP_NVCC_DETECTION BOOST_VERSION_NUMBER(__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, __CUDACC_VER_BUILD__)
  28. # endif
  29. #endif
  30. #ifdef BOOST_COMP_NVCC_DETECTION
  31. /*
  32. Always define BOOST_COMP_NVCC instead of BOOST_COMP_NVCC_EMULATED
  33. The nvcc compilation process is somewhat special as can be read here:
  34. https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#cuda-compilation-trajectory
  35. The nvcc compiler precompiles the input two times. Once for the device code
  36. being compiled by the cicc device compiler and once for the host code
  37. compiled by the real host compiler. NVCC uses gcc/clang/msvc/...
  38. depending on the host compiler being set on the command line.
  39. Predef (as a preprocessor only lib) detects the one doing the preprocessing
  40. as compiler and expects it to be the one doing the real compilation.
  41. This is not true for NVCC which is only doing the preprocessing and which
  42. is using another compiler for parts of its work. So for NVCC it should be
  43. allowed to set BOOST_COMP_NVCC additionally to the already detected host
  44. compiler because both is true: It is gcc/clang/... compiling the code, but it
  45. is also NVCC doing the preprocessing and adding some other quirks you may
  46. want to detect.
  47. This behavior is similar to what boost config is doing in `select_compiler_config.hpp`.
  48. There the NVCC detection is not handled as a real compiler (part of the
  49. #if-#elif) but as additional option before the real compiler.
  50. */
  51. # undef BOOST_COMP_NVCC
  52. # define BOOST_COMP_NVCC BOOST_COMP_NVCC_DETECTION
  53. # define BOOST_COMP_NVCC_AVAILABLE
  54. # include <boost/predef/detail/comp_detected.h>
  55. #endif
  56. #define BOOST_COMP_NVCC_NAME "NVCC"
  57. #endif
  58. #include <boost/predef/detail/test.h>
  59. BOOST_PREDEF_DECLARE_TEST(BOOST_COMP_NVCC,BOOST_COMP_NVCC_NAME)