From 367723544c2187a2a6cd5954ca37a8faf5335e5a Mon Sep 17 00:00:00 2001 From: Henri Vasserman Date: Sat, 22 Apr 2023 23:28:00 +0300 Subject: [PATCH] More build file changes --- CMakeLists.txt | 15 ++++++++++++--- Makefile | 21 ++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cea51078dcdd9..2c1958f6acfbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,16 +170,24 @@ if (LLAMA_CUBLAS) endif() if (LLAMA_HIPBLAS) + list(APPEND CMAKE_PREFIX_PATH /opt/rocm) + + if (NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang") + message(WARNING "Only LLVM is supported for HIP, hint: CC=/opt/rocm/llvm/bin/clang") + endif() + if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + message(WARNING "Only LLVM is supported for HIP, hint: CXX=/opt/rocm/llvm/bin/clang++") + endif() + find_package(hip) find_package(hipblas) if (${hipblas_FOUND} AND ${hip_FOUND}) message(STATUS "hipBLAS found") add_compile_definitions(GGML_USE_HIPBLAS) - enable_language(HIP) add_library(ggml-hip OBJECT ggml-cuda.cu ggml-cuda.h) - set_source_files_properties(ggml-cuda.cu PROPERTIES LANGUAGE HIP) - target_link_libraries(ggml-hip PRIVATE hip::device) + set_source_files_properties(ggml-cuda.cu PROPERTIES LANGUAGE CXX) + target_link_libraries(ggml-hip PUBLIC hip::device) if (LLAMA_STATIC) message(FATAL_ERROR "Static linking not supported for HIP/ROCm") @@ -188,6 +196,7 @@ if (LLAMA_HIPBLAS) else() message(WARNING "hipBLAS or HIP not found. Try setting CMAKE_PREFIX_PATH=/opt/rocm") endif() + endif() if (LLAMA_ALL_WARNINGS) diff --git a/Makefile b/Makefile index d27f716ec1fe1..5339d5765082c 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ ifndef UNAME_M UNAME_M := $(shell uname -m) endif -CCV := $(shell $(CC) --version | head -n 1) -CXXV := $(shell $(CXX) --version | head -n 1) +CCV = $(shell $(CC) --version | head -n 1) +CXXV = $(shell $(CXX) --version | head -n 1) # Mac OS + Arm can report x86_64 # ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789 @@ -108,14 +108,17 @@ ggml-cuda.o: ggml-cuda.cu ggml-cuda.h nvcc -arch=native -c -o $@ $< endif ifdef LLAMA_HIPBLAS - ROCM_PATH ?= /opt/rocm - LDFLAGS += -lhipblas -lamdhip64 -L$(ROCM_PATH)/lib -Wl,-rpath=$(ROCM_PATH)/lib - HIPCC ?= $(ROCM_PATH)/bin/hipcc - OBJS += ggml-cuda.o -ggml.o: CFLAGS += -DGGML_USE_HIPBLAS -D__HIP_PLATFORM_AMD__ -I$(ROCM_PATH)/include -ggml-cuda.o: CXXFLAGS += -march=native -D__HIP_PLATFORM_AMD__ -I$(ROCMPATH)/include + ROCM_PATH ?= /opt/rocm + CC := $(ROCM_PATH)/llvm/bin/clang + CXX := $(ROCM_PATH)/llvm/bin/clang++ + GPU_TARGETS!= $(ROCM_PATH)/llvm/bin/offload-arch + CFLAGS += -DGGML_USE_HIPBLAS $(shell $(ROCM_PATH)/bin/hipconfig -C) + CXXFLAGS += -DGGML_USE_HIPBLAS $(shell $(ROCM_PATH)/bin/hipconfig -C) + LDFLAGS += -L/opt/rocm/lib -lhipblas -lamdhip64 + OBJS += ggml-cuda.o +ggml-cuda.o: CXXFLAGS += $(addprefix --offload-arch=,$(GPU_TARGETS)) ggml-cuda.o: ggml-cuda.cu ggml-cuda.h - $(HIPCC) $(CXXFLAGS) -x hip $(HIPFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) -x hip -c -o $@ $< endif ifdef LLAMA_GPROF CFLAGS += -pg