Skip to content

Commit

Permalink
Build file changes
Browse files Browse the repository at this point in the history
Now HIP Clang is not required, the CMake scripts will configure the
needed compiler, which can be system clang++. Also other code can
still use GCC, but CMake will force the clang to link.
  • Loading branch information
SlyEcho committed Apr 20, 2023
1 parent 54a63c1 commit 0e005f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
24 changes: 10 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,27 +170,23 @@ if (LLAMA_CUBLAS)
endif()

if (LLAMA_HIPBLAS)
cmake_minimum_required(VERSION 3.21)

find_package(hip)
find_package(hipblas)

if (hipblas_FOUND)
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(LLAMA_HIPBLAS_PLATFORM "AMD" CACHE STRING "hip device type" FORCE)
set_property(CACHE LLAMA_HIPBLAS_PLATFORM PROPERTY STRINGS "AMD" "NVIDIA")

add_compile_definitions(GGML_USE_HIPBLAS "__HIP_PLATFORM_${LLAMA_HIPBLAS_PLATFORM}__")

add_library(ggml-hip OBJECT ggml-cuda.cu)
set_source_files_properties(ggml-cuda.cu PROPERTIES LANGUAGE CXX)
target_link_libraries(ggml-hip hip::device)

if (LLAMA_STATIC)
message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
endif()
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} hip::host roc::hipblas ggml-hip)

else()
message(WARNING "hipBLAS not found")
message(WARNING "hipBLAS or HIP not found. Try setting CMAKE_PREFIX_PATH=/opt/rocm")
endif()
endif()

Expand Down
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,12 @@ ggml-cuda.o: ggml-cuda.cu ggml-cuda.h
nvcc -arch=native -c -o $@ $<
endif
ifdef LLAMA_HIPBLAS
ROCMPATH?= /opt/rocm
CFLAGS += -DGGML_USE_HIPBLAS -D__HIP_PLATFORM_AMD__ -I$(ROCMPATH)/include
CXXFLAGS+= -D__HIP_PLATFORM_AMD__ -I$(ROCMPATH)/include
HIPFLAGS?= -amdgpu-early-inline-all=true -amdgpu-function-calls=false -march=native
LDFLAGS += -lhipblas -lamdhip64 -L$(ROCMPATH)/lib
HIPCC ?= $(ROCMPATH)/bin/hipcc
OBJS += ggml-cuda.o
ROCM_PATH ?= /opt/rocm
LDFLAGS += -lhipblas -lamdhip64 -L$(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
ggml-cuda.o: ggml-cuda.cu ggml-cuda.h
$(HIPCC) $(CXXFLAGS) -x hip $(HIPFLAGS) -c -o $@ $<
endif
Expand Down

0 comments on commit 0e005f7

Please sign in to comment.