interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-hip / CMakeLists.txt

144 lines · 4309 bytes Raw Blame History
1if (NOT EXISTS $ENV{ROCM_PATH})
2 if (NOT EXISTS /opt/rocm)
3 set(ROCM_PATH /usr)
4 else()
5 set(ROCM_PATH /opt/rocm)
6 endif()
7else()
8 set(ROCM_PATH $ENV{ROCM_PATH})
9endif()
10
11list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
12list(APPEND CMAKE_PREFIX_PATH "${ROCM_PATH}/lib64/cmake")
13
14if (NOT DEFINED CMAKE_HIP_FLAGS_DEBUG)
15 set(CMAKE_HIP_FLAGS_DEBUG "-g -Xarch_device -O2 -Xarch_host -O0")
16endif()
17
18# CMake on Windows doesn't support the HIP language yet
19if (WIN32)
20 set(CXX_IS_HIPCC TRUE)
21else()
22 string(REGEX MATCH "hipcc(\.bat)?$" CXX_IS_HIPCC "${CMAKE_CXX_COMPILER}")
23endif()
24
25if (CXX_IS_HIPCC)
26 if (LINUX)
27 if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
28 message(WARNING "Only LLVM is supported for HIP, hint: CXX=/opt/rocm/llvm/bin/clang++")
29 endif()
30
31 message(WARNING "Setting hipcc as the C++ compiler is legacy behavior."
32 " Prefer setting the HIP compiler directly. See README for details.")
33 endif()
34else()
35 # Forward (AMD)GPU_TARGETS to CMAKE_HIP_ARCHITECTURES.
36 if(AMDGPU_TARGETS AND NOT GPU_TARGETS)
37 set(GPU_TARGETS ${AMDGPU_TARGETS})
38 endif()
39 if(GPU_TARGETS AND NOT CMAKE_HIP_ARCHITECTURES)
40 set(CMAKE_HIP_ARCHITECTURES ${GPU_TARGETS})
41 endif()
42 cmake_minimum_required(VERSION 3.21)
43 enable_language(HIP)
44endif()
45
46find_package(hip REQUIRED)
47find_package(hipblas REQUIRED)
48find_package(rocblas REQUIRED)
49
50if (GGML_HIP_RCCL)
51 find_package(rccl REQUIRED)
52endif()
53
54if (${hip_VERSION} VERSION_LESS 6.1)
55 message(FATAL_ERROR "At least ROCM/HIP V6.1 is required")
56endif()
57
58message(STATUS "HIP and hipBLAS found")
59
60file(GLOB GGML_HEADERS_ROCM "../ggml-cuda/*.cuh")
61list(APPEND GGML_HEADERS_ROCM "../../include/ggml-cuda.h")
62
63file(GLOB GGML_SOURCES_ROCM "../ggml-cuda/*.cu")
64file(GLOB SRCS "../ggml-cuda/template-instances/fattn-tile*.cu")
65list(APPEND GGML_SOURCES_ROCM ${SRCS})
66file(GLOB SRCS "../ggml-cuda/template-instances/fattn-mma*.cu")
67list(APPEND GGML_SOURCES_ROCM ${SRCS})
68file(GLOB SRCS "../ggml-cuda/template-instances/mmq*.cu")
69list(APPEND GGML_SOURCES_ROCM ${SRCS})
70file(GLOB SRCS "../ggml-cuda/template-instances/mmf*.cu")
71list(APPEND GGML_SOURCES_ROCM ${SRCS})
72
73ggml_cuda_fattn_vec_instances(${CMAKE_CURRENT_SOURCE_DIR}/../ggml-cuda SRCS)
74list(APPEND GGML_SOURCES_ROCM ${SRCS})
75
76ggml_add_backend_library(ggml-hip
77 ${GGML_HEADERS_ROCM}
78 ${GGML_SOURCES_ROCM}
79 )
80
81# TODO: do not use CUDA definitions for HIP
82if (NOT GGML_BACKEND_DL)
83 target_compile_definitions(ggml PUBLIC GGML_USE_CUDA)
84endif()
85
86add_compile_definitions(GGML_USE_HIP)
87
88if (GGML_CUDA_FORCE_MMQ)
89 add_compile_definitions(GGML_CUDA_FORCE_MMQ)
90endif()
91
92if (GGML_CUDA_FORCE_CUBLAS)
93 add_compile_definitions(GGML_CUDA_FORCE_CUBLAS)
94endif()
95
96if (GGML_CUDA_NO_PEER_COPY)
97 add_compile_definitions(GGML_CUDA_NO_PEER_COPY)
98endif()
99
100if (GGML_HIP_GRAPHS)
101 add_compile_definitions(GGML_HIP_GRAPHS)
102endif()
103
104if (GGML_HIP_NO_VMM)
105 add_compile_definitions(GGML_HIP_NO_VMM)
106endif()
107
108if (NOT GGML_HIP_MMQ_MFMA)
109 add_compile_definitions(GGML_HIP_NO_MMQ_MFMA)
110endif()
111
112if (GGML_HIP_RCCL)
113 add_compile_definitions(GGML_USE_NCCL) # RCCL has the same interface as NCCL.
114endif()
115
116if (GGML_HIP_EXPORT_METRICS)
117 set(CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS} -Rpass-analysis=kernel-resource-usage --save-temps")
118endif()
119
120if (NOT GGML_CUDA_FA)
121 add_compile_definitions(GGML_CUDA_NO_FA)
122endif()
123
124if (CXX_IS_HIPCC)
125 set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)
126 if (WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
127 # CMake on Windows doesn't support the HIP language yet.
128 # Therefore we workaround debug build's failure on HIP backend this way.
129 set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES COMPILE_FLAGS "-O2 -g")
130 endif()
131 target_link_libraries(ggml-hip PRIVATE hip::device)
132else()
133 set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP)
134endif()
135
136if (GGML_STATIC)
137 message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
138endif()
139
140if (GGML_HIP_RCCL)
141 target_link_libraries(ggml-hip PRIVATE ggml-base roc::rccl)
142endif()
143
144target_link_libraries(ggml-hip PRIVATE ggml-base hip::host roc::rocblas roc::hipblas)