Skip to content

Commit 8696423

Browse files
committed
ROCm: use native CMake HIP support (ggml-org#5966)
Only CMakeLists.txt.
1 parent 7c38079 commit 8696423

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

CMakeLists.txt

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,26 @@ if (LLAMA_VULKAN)
543543
endif()
544544

545545
if (LLAMA_HIPBLAS)
546-
list(APPEND CMAKE_PREFIX_PATH /opt/rocm)
547-
548-
if (NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang")
549-
message(WARNING "Only LLVM is supported for HIP, hint: CC=/opt/rocm/llvm/bin/clang")
546+
if ($ENV{ROCM_PATH})
547+
set(ROCM_PATH $ENV{ROCM_PATH})
548+
else()
549+
set(ROCM_PATH /opt/rocm)
550550
endif()
551+
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
551552

552-
if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
553-
message(WARNING "Only LLVM is supported for HIP, hint: CXX=/opt/rocm/llvm/bin/clang++")
554-
endif()
553+
string(REGEX MATCH "hipcc(\.bat)?$" CXX_IS_HIPCC "${CMAKE_CXX_COMPILER}")
555554

555+
if (CXX_IS_HIPCC AND UNIX)
556+
message(WARNING "Setting hipcc as the C++ compiler is legacy behavior."
557+
" Prefer setting the HIP compiler directly. See README for details.")
558+
else()
559+
# Forward AMDGPU_TARGETS to CMAKE_HIP_ARCHITECTURES.
560+
if (AMDGPU_TARGETS AND NOT CMAKE_HIP_ARCHITECTURES)
561+
set(CMAKE_HIP_ARCHITECTURES ${AMDGPU_ARGETS})
562+
endif()
563+
cmake_minimum_required(VERSION 3.21)
564+
enable_language(HIP)
565+
endif()
556566
find_package(hip REQUIRED)
557567
find_package(hipblas REQUIRED)
558568
find_package(rocblas REQUIRED)
@@ -586,13 +596,18 @@ if (LLAMA_HIPBLAS)
586596
add_compile_definitions(GGML_CUDA_MMV_Y=${LLAMA_CUDA_MMV_Y})
587597
add_compile_definitions(K_QUANTS_PER_ITERATION=${LLAMA_CUDA_KQUANTS_ITER})
588598

589-
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)
599+
if (CXX_IS_HIPCC)
600+
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)
601+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} hip::device)
602+
else()
603+
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP)
604+
endif()
590605

591606
if (LLAMA_STATIC)
592607
message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
593608
endif()
594609

595-
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} hip::device PUBLIC hip::host roc::rocblas roc::hipblas)
610+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} PUBLIC hip::host roc::rocblas roc::hipblas)
596611
endif()
597612

598613
if (LLAMA_SYCL)

0 commit comments

Comments
 (0)