@@ -15,24 +15,108 @@ find_package(HIP REQUIRED)
15
15
message (STATUS "HIP version: ${HIP_VERSION_STRING} " )
16
16
message (STATUS "HIP platform: ${HIP_PLATFORM} " )
17
17
18
- if ("${HIP_PLATFORM} " STREQUAL "hcc" OR "${HIP_PLATFORM} " STREQUAL "amd" )
19
- set (HIP_RUNTIME_DEFINE "__HIP_PLATFORM_HCC__" )
20
- elseif ("${HIP_PLATFORM} " STREQUAL "nvcc" )
21
- set (HIP_RUNTIME_DEFINE "__HIP_PLATFORM_NVCC__" )
18
+ set (HIP_RUNTIME_INCLUDE_DIRS "${HIP_ROOT_DIR} /include" )
19
+ if (${HIP_PLATFORM} STREQUAL "hcc" )
20
+ set (HIP_RUNTIME_DEFINES "-D__HIP_PLATFORM_HCC__" )
21
+ find_library (HIP_RUNTIME_LIBRARIES NAMES hip_hcc libhip_hcc
22
+ PATHS ${HIP_ROOT_DIR} /lib
23
+ NO_DEFAULT_PATH
24
+ NO_CMAKE_ENVIRONMENT_PATH
25
+ NO_CMAKE_PATH
26
+ NO_SYSTEM_ENVIRONMENT_PATH
27
+ NO_CMAKE_SYSTEM_PATH)
28
+ set (HIP_RUNTIME_LIBRARIES "${HIP_ROOT_DIR} /lib/libhip_hcc.so" )
29
+ elseif (${HIP_PLATFORM} STREQUAL "clang" OR ${HIP_PLATFORM} STREQUAL "amd" )
30
+ set (HIP_RUNTIME_DEFINES "-D__HIP_PLATFORM_HCC__;-D__HIP_ROCclr__;-D__HIP_PLATFORM_AMD__" )
31
+ find_library (HIP_RUNTIME_LIBRARIES NAMES amdhip64 libamdhip64
32
+ PATHS ${HIP_ROOT_DIR} /lib
33
+ NO_DEFAULT_PATH
34
+ NO_CMAKE_ENVIRONMENT_PATH
35
+ NO_CMAKE_PATH
36
+ NO_SYSTEM_ENVIRONMENT_PATH
37
+ NO_CMAKE_SYSTEM_PATH)
38
+ elseif (${HIP_PLATFORM} STREQUAL "nvcc" OR ${HIP_PLATFORM} STREQUAL "nvidia" )
39
+ set (HIP_RUNTIME_DEFINES "-D__HIP_PLATFORM_NVCC__;-D__HIP_PLATFORM_NVIDIA__" )
40
+ if (${CMAKE_VERSION} VERSION_LESS "3.17.0" )
41
+ find_package (CUDA)
42
+ find_library (HIP_RUNTIME_LIBRARIES NAMES cudart libcudart
43
+ PATHS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}
44
+ NO_DEFAULT_PATH
45
+ NO_CMAKE_ENVIRONMENT_PATH
46
+ NO_CMAKE_PATH
47
+ NO_SYSTEM_ENVIRONMENT_PATH
48
+ NO_CMAKE_SYSTEM_PATH)
49
+ set (HIP_RUNTIME_INCLUDE_DIRS "${HIP_RUNTIME_INCLUDE_DIRS} ;${CUDA_INCLUDE_DIRS} " )
50
+ else ()
51
+ find_package (CUDAToolkit)
52
+ find_library (HIP_RUNTIME_LIBRARIES NAMES cudart libcudart
53
+ PATHS ${CUDAToolkit_LIBRARY_DIR}
54
+ NO_DEFAULT_PATH
55
+ NO_CMAKE_ENVIRONMENT_PATH
56
+ NO_CMAKE_PATH
57
+ NO_SYSTEM_ENVIRONMENT_PATH
58
+ NO_CMAKE_SYSTEM_PATH)
59
+ set (HIP_RUNTIME_INCLUDE_DIRS "${HIP_RUNTIME_INCLUDE_DIRS} ;${CUDAToolkit_INCLUDE_DIR} " )
60
+ endif ()
22
61
endif ()
62
+
23
63
if ( IS_DIRECTORY "${HIP_ROOT_DIR} /hcc/include" ) # this path only exists on older rocm installs
24
- set (HIP_RUNTIME_INCLUDE_DIRS "${HIP_ROOT_DIR} /include;${HIP_ROOT_DIR} /hcc/include" CACHE STRING "" )
64
+ set (HIP_RUNTIME_INCLUDE_DIRS "${HIP_ROOT_DIR} /include;${HIP_ROOT_DIR} /hcc/include" CACHE STRING "" )
25
65
else ()
26
- set (HIP_RUNTIME_INCLUDE_DIRS "${HIP_ROOT_DIR} /include" CACHE STRING "" )
66
+ set (HIP_RUNTIME_INCLUDE_DIRS "${HIP_ROOT_DIR} /include" CACHE STRING "" )
27
67
endif ()
28
- set (HIP_RUNTIME_COMPILE_FLAGS "${HIP_RUNTIME_COMPILE_FLAGS} ;-D${HIP_RUNTIME_DEFINE} ;-Wno-unused-parameter" )
68
+ set (HIP_RUNTIME_COMPILE_FLAGS "${HIP_RUNTIME_COMPILE_FLAGS} ;-Wno-unused-parameter" )
69
+
70
+ set (_hip_compile_flags " " )
71
+ if (ENABLE_CLANG_HIP)
72
+ if (NOT (${HIP_PLATFORM} STREQUAL "clang" ))
73
+ message (FATAL_ERROR "ENABLE_CLANG_HIP requires HIP_PLATFORM=clang" )
74
+ endif ()
75
+ set (_hip_compile_flags -x;hip)
76
+ # Using clang HIP, we need to construct a few CPP defines and compiler flags
77
+ foreach (_arch ${BLT_CLANG_HIP_ARCH} )
78
+ string (TOUPPER ${_arch} _UPARCH)
79
+ string (TOLOWER ${_arch} _lowarch)
80
+ list (APPEND _hip_compile_flags "--offload-arch=${_lowarch} " )
81
+ set (_hip_compile_defines "${HIP_RUNTIME_DEFINES} ;-D__HIP_ARCH_${_UPARCH} __=1" )
82
+ endforeach (_arch)
83
+
84
+ # We need to pass rocm path as well, for certain bitcode libraries.
85
+ # First see if we were given it, then see if it exists in the environment.
86
+ # If not, don't try to guess but print a warning and hope the compiler knows where it is.
87
+ if (NOT ROCM_PATH)
88
+ find_path (ROCM_PATH
89
+ bin/rocminfo
90
+ ENV ROCM_DIR
91
+ ENV ROCM_PATH
92
+ ${HIP_ROOT_DIR} /../
93
+ ${ROCM_ROOT_DIR}
94
+ /opt/rocm)
95
+ endif ()
96
+
97
+ if (DEFINED ROCM_PATH)
98
+ list (APPEND _hip_compile_flags "--rocm-path=${ROCM_PATH} " )
99
+ else ()
100
+ message (WARN "ROCM_PATH not set or found! This is typically required for Clang HIP Compilation" )
101
+ endif ()
102
+
103
+ message (STATUS "Clang HIP Enabled. Clang flags for HIP compilation: ${_hip_compile_flags} " )
104
+ message (STATUS "Defines for HIP compilation: ${_hip_compile_defines} " )
105
+
106
+ blt_import_library(NAME hip
107
+ DEFINES ${_hip_compile_defines}
108
+ COMPILE_FLAGS ${_hip_compile_flags}
109
+ DEPENDS_ON ${HIP_RUNTIME_LIBRARIES} )
110
+ else ()
29
111
30
112
# depend on 'hip', if you need to use hip
31
113
# headers, link to hip libs, and need to run your source
32
114
# through a hip compiler (hipcc)
33
115
# This is currently used only as an indicator for blt_add_hip* -- FindHIP/hipcc will handle resolution
34
116
# of all required HIP-related includes/libraries/flags.
35
- blt_import_library(NAME hip)
117
+ blt_import_library(NAME hip)
118
+ endif ()
119
+
36
120
37
121
# depend on 'hip_runtime', if you only need to use hip
38
122
# headers or link to hip libs, but don't need to run your source
@@ -41,5 +125,6 @@ blt_import_library(NAME hip_runtime
41
125
INCLUDES ${HIP_RUNTIME_INCLUDE_DIRS}
42
126
DEFINES ${HIP_RUNTIME_DEFINES}
43
127
COMPILE_FLAGS ${HIP_RUNTIME_COMPILE_FLAGS}
128
+ DEPENDS_ON ${HIP_RUNTIME_LIBRARIES}
44
129
TREAT_INCLUDES_AS_SYSTEM ON
45
130
EXPORTABLE ${BLT_EXPORT_THIRDPARTY} )
0 commit comments