CMakeCUDAArchitecturesNative.cmake 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. function(cmake_cuda_architectures_native lang)
  4. # Run the test binary to detect the native architectures.
  5. execute_process(COMMAND "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin"
  6. RESULT_VARIABLE archs_result
  7. OUTPUT_VARIABLE archs_output
  8. ERROR_VARIABLE archs_output
  9. OUTPUT_STRIP_TRAILING_WHITESPACE
  10. )
  11. if(archs_result EQUAL 0)
  12. if("$ENV{CMAKE_CUDA_ARCHITECTURES_NATIVE_CLAMP}")
  13. # Undocumented hook used by CMake's CI.
  14. # Clamp native architecture to version range supported by this CUDA.
  15. list(GET CMAKE_${lang}_ARCHITECTURES_ALL 0 arch_min)
  16. list(GET CMAKE_${lang}_ARCHITECTURES_ALL -1 arch_max)
  17. set(CMAKE_CUDA_ARCHITECTURES_NATIVE "")
  18. foreach(arch IN LISTS archs_output)
  19. if(arch LESS arch_min)
  20. set(arch "${arch_min}")
  21. endif()
  22. if(arch GREATER arch_max)
  23. set(arch "${arch_max}")
  24. endif()
  25. list(APPEND CMAKE_CUDA_ARCHITECTURES_NATIVE ${arch})
  26. endforeach()
  27. unset(arch)
  28. unset(arch_min)
  29. unset(arch_max)
  30. else()
  31. set(CMAKE_CUDA_ARCHITECTURES_NATIVE "${archs_output}")
  32. endif()
  33. list(REMOVE_DUPLICATES CMAKE_CUDA_ARCHITECTURES_NATIVE)
  34. list(TRANSFORM CMAKE_CUDA_ARCHITECTURES_NATIVE APPEND "-real")
  35. else()
  36. if(NOT archs_result MATCHES "[0-9]+")
  37. set(archs_status " (${archs_result})")
  38. else()
  39. set(archs_status "")
  40. endif()
  41. string(REPLACE "\n" "\n " archs_output " ${archs_output}")
  42. message(CONFIGURE_LOG
  43. "Detecting the CUDA native architecture(s) failed with "
  44. "the following output${archs_status}:\n${archs_output}\n\n")
  45. endif()
  46. set(CMAKE_${lang}_ARCHITECTURES_NATIVE "${CMAKE_CUDA_ARCHITECTURES_NATIVE}" PARENT_SCOPE)
  47. endfunction()