Skip to content

Commit d91c467

Browse files
committed
ROCm: use native CMake HIP support
CMake has become the recommended way to add HIP code into a project (see [here](https://rocm.docs.amd.com/en/docs-6.0.0/conceptual/cmake-packages.html#using-hip-in-cmake)). Most importantly, this separation of HIP compiler and the C/C++ compiler also allows user to choose a different compiler if desired, compared to the current situation where everything must be built with ROCm's clang. Makefile is unchanged. Signed-off-by: Gavin Zhao <[email protected]>
1 parent d5a410e commit d91c467

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

.devops/nix/package.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,13 @@ effectiveStdenv.mkDerivation (
179179
)
180180
]
181181
++ optionals useRocm [
182-
(cmakeFeature "CMAKE_C_COMPILER" "hipcc")
183-
(cmakeFeature "CMAKE_CXX_COMPILER" "hipcc")
182+
(cmakeFeature "CMAKE_HIP_COMPILER" "${rocmPackages.llvm.clang}/bin/clang")
184183

185184
# Build all targets supported by rocBLAS. When updating search for TARGET_LIST_ROCM
186185
# in https://github.com/ROCmSoftwarePlatform/rocBLAS/blob/develop/CMakeLists.txt
187186
# and select the line that matches the current nixpkgs version of rocBLAS.
188187
# Should likely use `rocmPackages.clr.gpuTargets`.
189-
"-DAMDGPU_TARGETS=gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx940;gfx941;gfx942;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102"
188+
(cmakeFeature "CMAKE_HIP_ARCHITECTURES" "gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx940;gfx941;gfx942;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102")
190189
]
191190
++ optionals useMetalKit [ (lib.cmakeFeature "CMAKE_C_FLAGS" "-D__ARM_FEATURE_DOTPROD=1") ]
192191
++ optionals useBlas [ (lib.cmakeFeature "LLAMA_BLAS_VENDOR" "OpenBLAS") ];

CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,15 @@ if (LLAMA_CLBLAST)
398398
endif()
399399

400400
if (LLAMA_HIPBLAS)
401-
list(APPEND CMAKE_PREFIX_PATH /opt/rocm)
402-
403-
if (NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang")
404-
message(WARNING "Only LLVM is supported for HIP, hint: CC=/opt/rocm/llvm/bin/clang")
405-
endif()
406-
if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
407-
message(WARNING "Only LLVM is supported for HIP, hint: CXX=/opt/rocm/llvm/bin/clang++")
401+
if ($ENV{ROCM_PATH})
402+
set(ROCM_PATH $ENV{ROCM_PATH})
403+
else()
404+
set(ROCM_PATH /opt/rocm)
408405
endif()
409406

407+
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
408+
409+
enable_language(HIP)
410410
find_package(hip)
411411
find_package(hipblas)
412412
find_package(rocblas)
@@ -430,8 +430,8 @@ if (LLAMA_HIPBLAS)
430430
target_compile_definitions(ggml-rocm PRIVATE GGML_CUDA_DMMV_X=${LLAMA_CUDA_DMMV_X})
431431
target_compile_definitions(ggml-rocm PRIVATE GGML_CUDA_MMV_Y=${LLAMA_CUDA_MMV_Y})
432432
target_compile_definitions(ggml-rocm PRIVATE K_QUANTS_PER_ITERATION=${LLAMA_CUDA_KQUANTS_ITER})
433-
set_source_files_properties(ggml-cuda.cu PROPERTIES LANGUAGE CXX)
434-
target_link_libraries(ggml-rocm PRIVATE hip::device PUBLIC hip::host roc::rocblas roc::hipblas)
433+
set_source_files_properties(ggml-cuda.cu PROPERTIES LANGUAGE HIP)
434+
target_link_libraries(ggml-rocm PUBLIC hip::host roc::rocblas roc::hipblas)
435435

436436
if (LLAMA_STATIC)
437437
message(FATAL_ERROR "Static linking not supported for HIP/ROCm")

0 commit comments

Comments
 (0)