You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rocm.cmake 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. if(NOT DEFINED HIP_PATH)
  2. if(NOT DEFINED ENV{HIP_PATH})
  3. set(HIP_PATH
  4. "/opt/rocm/hip"
  5. CACHE PATH "Path to which HIP has been installed")
  6. else()
  7. set(HIP_PATH
  8. $ENV{HIP_PATH}
  9. CACHE PATH "Path to which HIP has been installed")
  10. endif()
  11. endif()
  12. set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})
  13. find_package(HIP QUIET)
  14. if(HIP_FOUND)
  15. message(STATUS "Found HIP: " ${HIP_VERSION})
  16. else()
  17. message(
  18. FATAL_ERROR
  19. "Could not find HIP. Ensure that HIP is either installed in /opt/rocm/hip or the variable HIP_PATH is set to point to the right location."
  20. )
  21. endif()
  22. if(${HIP_VERSION} VERSION_LESS 3.0)
  23. message(FATAL_ERROR "ROCM version needed 3. Please update ROCM.")
  24. endif()
  25. macro(hipconfig_get_option variable option)
  26. if(NOT DEFINED ${variable})
  27. execute_process(COMMAND ${HIP_HIPCONFIG_EXECUTABLE} ${option}
  28. OUTPUT_VARIABLE ${variable})
  29. endif()
  30. endmacro()
  31. hipconfig_get_option(HIP_COMPILER "--compiler")
  32. hipconfig_get_option(HIP_CPP_CONFIG "--cpp_config")
  33. separate_arguments(HIP_CPP_CONFIG)
  34. foreach(hip_config_item ${HIP_CPP_CONFIG})
  35. foreach(macro_name "__HIP_PLATFORM_HCC__" "__HIP_ROCclr__")
  36. if(${hip_config_item} STREQUAL "-D${macro_name}=")
  37. set(HIP_CPP_DEFINE "${HIP_CPP_DEFINE}#define ${macro_name}\n")
  38. set(HIP_CPP_UNDEFINE
  39. "${HIP_CPP_UNDEFINE}\
  40. #ifdef ${macro_name}\n#undef ${macro_name}\n\
  41. #else\n#error\n\
  42. #endif\n")
  43. elseif(${hip_config_item} STREQUAL "-D${macro_name}")
  44. set(HIP_CPP_DEFINE "${HIP_CPP_DEFINE}#define ${macro_name} 1\n")
  45. set(HIP_CPP_UNDEFINE
  46. "${HIP_CPP_UNDEFINE}\
  47. #ifdef ${macro_name}\n#undef ${macro_name}\n\
  48. #else\n#error\n\
  49. #endif\n")
  50. endif()
  51. endforeach()
  52. endforeach()
  53. message(STATUS "Using HIP compiler ${HIP_COMPILER}")
  54. if(${HIP_COMPILER} STREQUAL "hcc")
  55. set(MGE_ROCM_LIBS hip_hcc)
  56. message(
  57. WARNING "hcc is not well supported, please modify link.txt to link with hipcc")
  58. elseif(${HIP_COMPILER} STREQUAL "clang")
  59. set(MGE_ROCM_LIBS amdhip64)
  60. endif()
  61. list(APPEND MGE_ROCM_LIBS amdocl64 MIOpen rocblas rocrand)
  62. set(HIP_INCLUDE_DIR ${HIP_ROOT_DIR}/../include)
  63. set(HIP_LIBRARY_DIR ${HIP_ROOT_DIR}/../lib)
  64. function(find_rocm_library name dirname include library)
  65. find_path(
  66. ${name}_LIBRARY_DIR
  67. NAMES ${library}
  68. HINTS "${${name}_ROOT_DIR}" "${HIP_ROOT_DIR}/../${dirname}"
  69. PATH_SUFFIXES lib lib/x86_64
  70. DOC "Path to ${name} library directory")
  71. if(${${name}_LIBRARY_DIR} MATCHES "NOTFOUND$")
  72. message(FATAL_ERROR "Can not find ${name} library")
  73. endif()
  74. find_path(
  75. ${name}_INCLUDE_DIR
  76. NAMES ${include}
  77. HINTS "${${name}_ROOT_DIR}" "${HIP_ROOT_DIR}/../${dirname}"
  78. PATH_SUFFIXES include
  79. DOC "Path to ${name} include directory")
  80. if(${name}_INCLUDE_DIR MATCHES "NOTFOUND$")
  81. message(FATAL_ERROR "Can not find ${name} include")
  82. endif()
  83. message(DEBUG "Found lib ${${name}_LIBRARY_DIR}, include ${${name}_INCLUDE_DIR}")
  84. endfunction()
  85. find_rocm_library(MIOPEN miopen miopen libMIOpen.so)
  86. find_rocm_library(ROCBLAS rocblas rocblas.h librocblas.so)
  87. find_rocm_library(ROCRAND rocrand rocrand.h librocrand.so)
  88. find_rocm_library(AMDOCL opencl CL libamdocl64.so)