char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
5a4d0feca
char/aliceai-t5-moe
1if ( NOT EXISTS $ ENV { ROCM_PATH }) 2if ( NOT EXISTS /opt/rocm) 3set ( ROCM_PATH /usr ) 4else () 5set ( ROCM_PATH /opt/rocm ) 6endif () 7else () 8set ( 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) 15set ( CMAKE_HIP_FLAGS_DEBUG "-g -O2" ) 16endif () 17 18# CMake on Windows doesn't support the HIP language yet 19if ( WIN32) 20set ( CXX_IS_HIPCC TRUE ) 21else () 22string ( REGEX MATCH "hipcc(\.bat)? $ " CXX_IS_HIPCC " ${ CMAKE_CXX_COMPILER } " ) 23endif () 24 25if ( CXX_IS_HIPCC) 26if ( LINUX) 27if ( NOT ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" ) 28message ( WARNING "Only LLVM is supported for HIP, hint: CXX=/opt/rocm/llvm/bin/clang++" ) 29endif () 30 31message ( WARNING "Setting hipcc as the C++ compiler is legacy behavior." 32" Prefer setting the HIP compiler directly. See README for details." ) 33endif () 34else () 35# Forward (AMD)GPU_TARGETS to CMAKE_HIP_ARCHITECTURES. 36if ( AMDGPU_TARGETSAND NOT GPU_TARGETS) 37set ( GPU_TARGETS ${ AMDGPU_TARGETS }) 38endif () 39if ( GPU_TARGETSAND NOT CMAKE_HIP_ARCHITECTURES) 40set ( CMAKE_HIP_ARCHITECTURES ${ GPU_TARGETS }) 41endif () 42cmake_minimum_required ( VERSION 3.21 ) 43enable_language ( HIP ) 44endif () 45 46find_package ( hip REQUIRED ) 47find_package ( hipblas REQUIRED ) 48find_package ( rocblas REQUIRED ) 49 50if ( GGML_HIP_RCCL) 51find_package ( rccl REQUIRED ) 52endif () 53 54if (${ hip_VERSION } VERSION_LESS 6.1) 55message ( 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) 83target_compile_definitions ( ggml PUBLIC GGML_USE_CUDA ) 84endif () 85 86add_compile_definitions ( GGML_USE_HIP ) 87 88if ( GGML_CUDA_FORCE_MMQ) 89add_compile_definitions ( GGML_CUDA_FORCE_MMQ ) 90endif () 91 92if ( GGML_CUDA_FORCE_CUBLAS) 93add_compile_definitions ( GGML_CUDA_FORCE_CUBLAS ) 94endif () 95 96if ( GGML_CUDA_NO_PEER_COPY) 97add_compile_definitions ( GGML_CUDA_NO_PEER_COPY ) 98endif () 99 100if ( GGML_HIP_GRAPHS) 101add_compile_definitions ( GGML_HIP_GRAPHS ) 102endif () 103 104if ( GGML_HIP_NO_VMM) 105add_compile_definitions ( GGML_HIP_NO_VMM ) 106endif () 107 108if ( NOT GGML_HIP_MMQ_MFMA) 109add_compile_definitions ( GGML_HIP_NO_MMQ_MFMA ) 110endif () 111 112if ( GGML_HIP_RCCL) 113add_compile_definitions ( GGML_USE_NCCL ) # RCCL has the same interface as NCCL. 114endif () 115 116if ( GGML_HIP_EXPORT_METRICS) 117set ( CMAKE_HIP_FLAGS " ${ CMAKE_HIP_FLAGS } -Rpass-analysis=kernel-resource-usage --save-temps" ) 118endif () 119 120if ( NOT GGML_CUDA_FA) 121add_compile_definitions ( GGML_CUDA_NO_FA ) 122endif () 123 124if ( CXX_IS_HIPCC) 125set_source_files_properties ( $ { GGML_SOURCES_ROCM } PROPERTIES LANGUAGE CXX ) 126if ( WIN32AND CMAKE_BUILD_TYPESTREQUAL "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. 129set_source_files_properties ( $ { GGML_SOURCES_ROCM } PROPERTIES COMPILE_FLAGS "-O2 -g" ) 130endif () 131target_link_libraries ( ggml-hip PRIVATE hip::device ) 132else () 133set_source_files_properties ( $ { GGML_SOURCES_ROCM } PROPERTIES LANGUAGE HIP ) 134endif () 135 136if ( GGML_STATIC) 137message ( FATAL_ERROR "Static linking not supported for HIP/ROCm" ) 138endif () 139 140if ( GGML_HIP_RCCL) 141target_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 )