ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-hip / CMakeLists.txt
| 1 | if (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() |
| 7 | else() |
| 8 | set(ROCM_PATH $ENV{ROCM_PATH}) |
| 9 | endif() |
| 10 | |
| 11 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}) |
| 12 | list(APPEND CMAKE_PREFIX_PATH "${ROCM_PATH}/lib64/cmake") |
| 13 | |
| 14 | if (NOT DEFINED CMAKE_HIP_FLAGS_DEBUG) |
| 15 | set(CMAKE_HIP_FLAGS_DEBUG "-g -Xarch_device -O2 -Xarch_host -O0") |
| 16 | endif() |
| 17 | |
| 18 | # CMake on Windows doesn't support the HIP language yet |
| 19 | if (WIN32) |
| 20 | set(CXX_IS_HIPCC TRUE) |
| 21 | else() |
| 22 | string(REGEX MATCH "hipcc(\.bat)?$" CXX_IS_HIPCC "${CMAKE_CXX_COMPILER}") |
| 23 | endif() |
| 24 | |
| 25 | if (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() |
| 34 | else() |
| 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) |
| 44 | endif() |
| 45 | |
| 46 | find_package(hip REQUIRED) |
| 47 | find_package(hipblas REQUIRED) |
| 48 | find_package(rocblas REQUIRED) |
| 49 | |
| 50 | if (GGML_HIP_RCCL) |
| 51 | find_package(rccl REQUIRED) |
| 52 | endif() |
| 53 | |
| 54 | if (${hip_VERSION} VERSION_LESS 6.1) |
| 55 | message(FATAL_ERROR "At least ROCM/HIP V6.1 is required") |
| 56 | endif() |
| 57 | |
| 58 | message(STATUS "HIP and hipBLAS found") |
| 59 | |
| 60 | file(GLOB GGML_HEADERS_ROCM "../ggml-cuda/*.cuh") |
| 61 | list(APPEND GGML_HEADERS_ROCM "../../include/ggml-cuda.h") |
| 62 | |
| 63 | file(GLOB GGML_SOURCES_ROCM "../ggml-cuda/*.cu") |
| 64 | file(GLOB SRCS "../ggml-cuda/template-instances/fattn-tile*.cu") |
| 65 | list(APPEND GGML_SOURCES_ROCM ${SRCS}) |
| 66 | file(GLOB SRCS "../ggml-cuda/template-instances/fattn-mma*.cu") |
| 67 | list(APPEND GGML_SOURCES_ROCM ${SRCS}) |
| 68 | file(GLOB SRCS "../ggml-cuda/template-instances/mmq*.cu") |
| 69 | list(APPEND GGML_SOURCES_ROCM ${SRCS}) |
| 70 | file(GLOB SRCS "../ggml-cuda/template-instances/mmf*.cu") |
| 71 | list(APPEND GGML_SOURCES_ROCM ${SRCS}) |
| 72 | |
| 73 | ggml_cuda_fattn_vec_instances(${CMAKE_CURRENT_SOURCE_DIR}/../ggml-cuda SRCS) |
| 74 | list(APPEND GGML_SOURCES_ROCM ${SRCS}) |
| 75 | |
| 76 | ggml_add_backend_library(ggml-hip |
| 77 | ${GGML_HEADERS_ROCM} |
| 78 | ${GGML_SOURCES_ROCM} |
| 79 | ) |
| 80 | |
| 81 | # TODO: do not use CUDA definitions for HIP |
| 82 | if (NOT GGML_BACKEND_DL) |
| 83 | target_compile_definitions(ggml PUBLIC GGML_USE_CUDA) |
| 84 | endif() |
| 85 | |
| 86 | add_compile_definitions(GGML_USE_HIP) |
| 87 | |
| 88 | if (GGML_CUDA_FORCE_MMQ) |
| 89 | add_compile_definitions(GGML_CUDA_FORCE_MMQ) |
| 90 | endif() |
| 91 | |
| 92 | if (GGML_CUDA_FORCE_CUBLAS) |
| 93 | add_compile_definitions(GGML_CUDA_FORCE_CUBLAS) |
| 94 | endif() |
| 95 | |
| 96 | if (GGML_CUDA_NO_PEER_COPY) |
| 97 | add_compile_definitions(GGML_CUDA_NO_PEER_COPY) |
| 98 | endif() |
| 99 | |
| 100 | if (GGML_HIP_GRAPHS) |
| 101 | add_compile_definitions(GGML_HIP_GRAPHS) |
| 102 | endif() |
| 103 | |
| 104 | if (GGML_HIP_NO_VMM) |
| 105 | add_compile_definitions(GGML_HIP_NO_VMM) |
| 106 | endif() |
| 107 | |
| 108 | if (NOT GGML_HIP_MMQ_MFMA) |
| 109 | add_compile_definitions(GGML_HIP_NO_MMQ_MFMA) |
| 110 | endif() |
| 111 | |
| 112 | if (GGML_HIP_RCCL) |
| 113 | add_compile_definitions(GGML_USE_NCCL) # RCCL has the same interface as NCCL. |
| 114 | endif() |
| 115 | |
| 116 | if (GGML_HIP_EXPORT_METRICS) |
| 117 | set(CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS} -Rpass-analysis=kernel-resource-usage --save-temps") |
| 118 | endif() |
| 119 | |
| 120 | if (NOT GGML_CUDA_FA) |
| 121 | add_compile_definitions(GGML_CUDA_NO_FA) |
| 122 | endif() |
| 123 | |
| 124 | if (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) |
| 132 | else() |
| 133 | set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP) |
| 134 | endif() |
| 135 | |
| 136 | if (GGML_STATIC) |
| 137 | message(FATAL_ERROR "Static linking not supported for HIP/ROCm") |
| 138 | endif() |
| 139 | |
| 140 | if (GGML_HIP_RCCL) |
| 141 | target_link_libraries(ggml-hip PRIVATE ggml-base roc::rccl) |
| 142 | endif() |
| 143 | |
| 144 | target_link_libraries(ggml-hip PRIVATE ggml-base hip::host roc::rocblas roc::hipblas) |