Skip to content

Commit d55a561

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

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
@@ -533,16 +533,26 @@ if (LLAMA_VULKAN)
533533
endif()
534534

535535
if (LLAMA_HIPBLAS)
536-
list(APPEND CMAKE_PREFIX_PATH /opt/rocm)
537-
538-
if (NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang")
539-
message(WARNING "Only LLVM is supported for HIP, hint: CC=/opt/rocm/llvm/bin/clang")
536+
if ($ENV{ROCM_PATH})
537+
set(ROCM_PATH $ENV{ROCM_PATH})
538+
else()
539+
set(ROCM_PATH /opt/rocm)
540540
endif()
541+
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
541542

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

545+
if (CXX_IS_HIPCC AND UNIX)
546+
message(WARNING "Setting hipcc as the C++ compiler is legacy behavior."
547+
" Prefer setting the HIP compiler directly. See README for details.")
548+
else()
549+
# Forward AMDGPU_TARGETS to CMAKE_HIP_ARCHITECTURES.
550+
if (AMDGPU_TARGETS AND NOT CMAKE_HIP_ARCHITECTURES)
551+
set(CMAKE_HIP_ARCHITECTURES ${AMDGPU_ARGETS})
552+
endif()
553+
cmake_minimum_required(VERSION 3.21)
554+
enable_language(HIP)
555+
endif()
546556
find_package(hip REQUIRED)
547557
find_package(hipblas REQUIRED)
548558
find_package(rocblas REQUIRED)
@@ -576,13 +586,18 @@ if (LLAMA_HIPBLAS)
576586
add_compile_definitions(GGML_CUDA_MMV_Y=${LLAMA_CUDA_MMV_Y})
577587
add_compile_definitions(K_QUANTS_PER_ITERATION=${LLAMA_CUDA_KQUANTS_ITER})
578588

579-
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)
589+
if (CXX_IS_HIPCC)
590+
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)
591+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} hip::device)
592+
else()
593+
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP)
594+
endif()
580595

581596
if (LLAMA_STATIC)
582597
message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
583598
endif()
584599

585-
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} hip::device PUBLIC hip::host roc::rocblas roc::hipblas)
600+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} PUBLIC hip::host roc::rocblas roc::hipblas)
586601
endif()
587602

588603
if (LLAMA_SYCL)

0 commit comments

Comments
 (0)