Skip to content

Commit 6cc3473

Browse files
[SYCL][HIP] Add CMake cache variables to allow build of DPC++ toolchain with non-standard ROCm installation (#8791)
Fix #8790 Re-adds CMake cache variables `SYCL_BUILD_PI_HIP_INCLUDE_DIR` and `SYCL_BUILD_PI_HIP_HSA_INCLUDE_DIR`. Also adds CMake cache variable `SYCL_BUILD_PI_HIP_LIB_DIR`. Added checks for above variables. The changes maintain the current simplified behavior from #6406 while allowing for the user to override paths if necessary.
1 parent 3e3b33a commit 6cc3473

File tree

1 file changed

+75
-6
lines changed

1 file changed

+75
-6
lines changed

sycl/plugins/hip/CMakeLists.txt

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,82 @@ message(STATUS "Including the PI API HIP backend for ${SYCL_BUILD_PI_HIP_PLATFOR
77
# Set default ROCm installation directory
88
set(SYCL_BUILD_PI_HIP_ROCM_DIR "/opt/rocm" CACHE STRING "ROCm installation dir")
99

10-
if(NOT EXISTS "${SYCL_BUILD_PI_HIP_ROCM_DIR}")
11-
message(FATAL_ERROR "Couldn't find ROCm installation in '${SYCL_BUILD_PI_HIP_ROCM_DIR}',"
12-
" please set SYCL_BUILD_PI_HIP_ROCM_DIR to the path of the ROCm installation.")
10+
# Set HIP include and lib dirs
11+
set(SYCL_BUILD_PI_HIP_INCLUDE_DIR "" CACHE STRING "Override HIP include dir path (set to \"\" for default behavior)")
12+
set(SYCL_BUILD_PI_HIP_HSA_INCLUDE_DIR "" CACHE STRING "Override HSA include dir path (set to \"\" for default behavior)")
13+
14+
if("${SYCL_BUILD_PI_HIP_INCLUDE_DIR}" STREQUAL "")
15+
set(PI_HIP_INCLUDE_DIR "${SYCL_BUILD_PI_HIP_ROCM_DIR}/hip/include")
16+
else()
17+
set(PI_HIP_INCLUDE_DIR "${SYCL_BUILD_PI_HIP_INCLUDE_DIR}")
18+
endif()
19+
20+
if("${SYCL_BUILD_PI_HIP_HSA_INCLUDE_DIR}" STREQUAL "")
21+
set(PI_HIP_HSA_INCLUDE_DIR "${SYCL_BUILD_PI_HIP_ROCM_DIR}/hsa/include")
22+
else()
23+
set(PI_HIP_HSA_INCLUDE_DIR "${SYCL_BUILD_PI_HIP_INCLUDE_DIR}")
24+
endif()
25+
26+
# Set HIP lib dir
27+
set(SYCL_BUILD_PI_HIP_LIB_DIR "" CACHE STRING "Override HIP lib dir path (set to \"\" for default behavior)")
28+
if("${SYCL_BUILD_PI_HIP_LIB_DIR}" STREQUAL "")
29+
set(PI_HIP_LIB_DIR "${SYCL_BUILD_PI_HIP_ROCM_DIR}/hip/lib")
30+
else()
31+
set(PI_HIP_LIB_DIR "${SYCL_BUILD_PI_HIP_LIB_DIR}")
32+
endif()
33+
34+
# Mark override options for advanced usage
35+
mark_as_advanced(SYCL_BUILD_PI_HIP_INCLUDE_DIR SYCL_BUILD_PI_HIP_HSA_INCLUDE_DIR SYCL_BUILD_PI_HIP_LIB_DIR)
36+
37+
# Check if ROCm install paths exists
38+
# N.B. Doesn't check if all override options are set: HSA and HIP include (and HIP lib for AMD platform)
39+
if(("${SYCL_BUILD_PI_HIP_INCLUDE_DIR}" STREQUAL "") OR
40+
("${SYCL_BUILD_PI_HIP_HSA_INCLUDE_DIR}" STREQUAL "") OR
41+
(("${SYCL_BUILD_PI_HIP_LIB_DIR}" STREQUAL "") AND ("${SYCL_BUILD_PI_HIP_PLATFORM}" STREQUAL "AMD")))
42+
43+
if(NOT EXISTS "${SYCL_BUILD_PI_HIP_ROCM_DIR}")
44+
message(FATAL_ERROR "Couldn't find ROCm installation in '${SYCL_BUILD_PI_HIP_ROCM_DIR}',"
45+
" please set SYCL_BUILD_PI_HIP_ROCM_DIR to the path of the ROCm installation.")
46+
endif()
47+
endif()
48+
49+
# Check if HIP include path exists
50+
if(NOT EXISTS "${PI_HIP_INCLUDE_DIR}")
51+
if("${SYCL_BUILD_PI_HIP_INCLUDE_DIR}" STREQUAL "")
52+
message(FATAL_ERROR "Couldn't find the HIP include directory at '${PI_HIP_INCLUDE_DIR}',"
53+
" please check ROCm installation and possibly set SYCL_BUILD_PI_HIP_INCLUDE_DIR to the path of the HIP include directory for non-standard install paths.")
54+
else()
55+
message(FATAL_ERROR "Couldn't find the HIP include directory at '${PI_HIP_INCLUDE_DIR}',"
56+
" please set SYCL_BUILD_PI_HIP_INCLUDE_DIR to the path of the HIP include directory from the ROCm installation.")
57+
endif()
58+
endif()
59+
60+
# Check if HSA include path exists
61+
if(NOT EXISTS "${PI_HIP_HSA_INCLUDE_DIR}")
62+
if("${SYCL_BUILD_PI_HIP_HSA_INCLUDE_DIR}" STREQUAL "")
63+
message(FATAL_ERROR "Couldn't find the HSA include directory at '${PI_HIP_HSA_INCLUDE_DIR}',"
64+
" please check ROCm installation and possibly set SYCL_BUILD_PI_HIP_HSA_INCLUDE_DIR to the path of the HSA include directory for non-standard install paths.")
65+
else()
66+
message(FATAL_ERROR "Couldn't find the HSA include directory at '${PI_HIP_HSA_INCLUDE_DIR}',"
67+
" please set SYCL_BUILD_PI_HIP_HSA_INCLUDE_DIR to the path of the HSA include directory from the ROCm installation.")
68+
endif()
69+
endif()
70+
71+
# Check if HIP library path exists (AMD platform only)
72+
if("${SYCL_BUILD_PI_HIP_PLATFORM}" STREQUAL "AMD")
73+
if(NOT EXISTS "${PI_HIP_LIB_DIR}")
74+
if("${SYCL_BUILD_PI_HIP_LIB_DIR}" STREQUAL "")
75+
message(FATAL_ERROR "Couldn't find the HIP library directory at '${PI_HIP_LIB_DIR}',"
76+
" please check ROCm installation and possibly set SYCL_BUILD_PI_HIP_LIB_DIR to the path of the HIP library directory for non-standard install paths.")
77+
else()
78+
message(FATAL_ERROR "Couldn't find the HIP library directory at '${PI_HIP_LIB_DIR}',"
79+
" please set SYCL_BUILD_PI_HIP_LIB_DIR to the path of the HIP library directory from the ROCm installation.")
80+
endif()
81+
endif()
1382
endif()
1483

15-
# Set HIP include dirs
16-
set(HIP_HEADERS "${SYCL_BUILD_PI_HIP_ROCM_DIR}/hip/include;${SYCL_BUILD_PI_HIP_ROCM_DIR}/hsa/include")
84+
# Set includes used in added library (rocmdrv)
85+
set(HIP_HEADERS "${PI_HIP_INCLUDE_DIR};${PI_HIP_HSA_INCLUDE_DIR}")
1786

1887
# Create pi_hip library
1988
add_sycl_plugin(hip
@@ -35,7 +104,7 @@ if("${SYCL_BUILD_PI_HIP_PLATFORM}" STREQUAL "AMD")
35104

36105
set_target_properties(
37106
rocmdrv PROPERTIES
38-
IMPORTED_LOCATION "${SYCL_BUILD_PI_HIP_ROCM_DIR}/hip/lib/libamdhip64.so"
107+
IMPORTED_LOCATION "${PI_HIP_LIB_DIR}/libamdhip64.so"
39108
INTERFACE_INCLUDE_DIRECTORIES "${HIP_HEADERS}"
40109
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${HIP_HEADERS}"
41110
)

0 commit comments

Comments
 (0)