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.4 kB

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