Skip to content

Commit

Permalink
More build file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SlyEcho committed Apr 22, 2023
1 parent d3e1984 commit 3677235
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3677235

Please sign in to comment.