okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fd19246dc
main
1# cmake/strata_ggml.cmake - where the engine's ggml comes from: the tree vendored in third_party/strata-ggml (default, no download), or -DSTRATA_GGML_DIR=<llama.cpp>. 2# 3# Every block below is a macro: it runs in the scope of the caller (CMakeLists.txt calls it where the block used to be), so variables, targets and 4# their order are those of the single-file CMakeLists.txt it was cut from (cleanup 5.4; the build graph is identical). 5 6# which ggml tree the engine builds from: the vendored third_party/strata-ggml, or the -DSTRATA_GGML_DIR override (repo_root: the checkout) 7macro ( strata_ggml_resolve repo_root ) 8set ( STRATA_GGML_DIR "" CACHE PATH "llama.cpp checkout to take ggml from instead of the vendored third_party/strata-ggml (empty: the vendored tree)" ) 9if ( STRATA_GGML_DIR) 10set ( _strata_ggml_root " ${ STRATA_GGML_DIR } " ) 11else () 12get_filename_component ( _strata_ggml_root " ${ repo_root } /third_party/strata-ggml" ABSOLUTE ) # (normalised: sycl/ and metal/ pass <repo>/sycl/..) 13endif () 14endmacro () 15 16# the root project's ggml-base / ggml-cpu: the forced GGML_* options per build kind (portable, ISA floor, native) and the subproject 17macro ( strata_ggml_configure_root ) 18set ( BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE ) 19set ( GGML_STATIC ON CACHE BOOL "" FORCE ) 20set ( GGML_CUDA OFF CACHE BOOL "" FORCE ) 21set ( GGML_OPENMP OFF CACHE BOOL "" FORCE ) 22set ( GGML_BACKEND_DL OFF CACHE BOOL "" FORCE ) 23set ( GGML_BUILD_TESTS OFF CACHE BOOL "" FORCE ) 24set ( GGML_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE ) 25if ( STRATA_PORTABLEAND NOT STRATA_CPU_X86) 26# arm64 (DGX Spark: Cortex-X925 + A725): ggml-cpu for any Armv8.2 CPU with dot product, FP16 and int8 matmul instead of the build 27# host's, so the engine built here does not depend on which core the compiler ran on. Without it GGML_NATIVE OFF would leave 28# ggml-cpu at plain armv8-a, and a native pack's CPU experts would lose the NEON dot products. 29set ( GGML_NATIVE OFF CACHE BOOL "" FORCE ) 30set ( STRATA_ARM64_ARCH "armv8.2-a+dotprod+fp16+i8mm" CACHE STRING "arm64: ggml-cpu's -march for a STRATA_PORTABLE build" ) 31set ( GGML_CPU_ARM_ARCH " ${ STRATA_ARM64_ARCH } " CACHE STRING "" FORCE ) 32elseif ( STRATA_PORTABLE) 33set ( GGML_NATIVE OFF CACHE BOOL "" FORCE ) 34foreach ( _f GGML_AVX GGML_AVX2 GGML_FMA GGML_F16C GGML_BMI2) 35set ( $ { _f } ON CACHE BOOL "" FORCE ) 36endforeach () 37elseif ( STRATA_ISA_FLOOR) 38# the experimental older-CPU build (STRATA_ISA_FLOOR above): one ggml-cpu for the floor, ggml's "sandybridge" 39# feature set (SSE4.2 + AVX) or SSE4.2 alone - not the build host's, which may be newer than the PC it runs on. 40# From the Strata_Dirigo fork (rwkeyes). ggml's defaults turn the rest on when GGML_NATIVE is off: all off here. 41set ( GGML_NATIVE OFF CACHE BOOL "" FORCE ) 42set ( GGML_CPU_ALL_VARIANTS OFF CACHE BOOL "" FORCE ) 43set ( GGML_SSE42 ON CACHE BOOL "" FORCE ) 44if ( STRATA_ISA_FLOORSTREQUAL "avx" ) 45set ( GGML_AVX ON CACHE BOOL "" FORCE ) 46else () 47set ( GGML_AVX OFF CACHE BOOL "" FORCE ) 48endif () 49foreach ( _f GGML_AVX2 GGML_FMA GGML_F16C GGML_BMI2 GGML_AVX_VNNI GGML_AVX512 GGML_AVX512_VBMI GGML_AVX512_VNNI 50 GGML_AVX512_BF16 GGML_AMX_TILE GGML_AMX_INT8 GGML_AMX_BF16) 51set ( $ { _f } OFF CACHE BOOL "" FORCE ) 52endforeach () 53else () 54set ( GGML_NATIVE ON CACHE BOOL "" FORCE ) 55endif () 56add_subdirectory ( $ { _strata_ggml_root } /ggml ${ CMAKE_BINARY_DIR } /ggml EXCLUDE_FROM_ALL ) 57endmacro () 58 59# the MMQ instances to build and where the trellis (Gyro) variants come from: the vendored ggml-cuda-tq folder, a fork's ggml, or the overlay of a STRATA_GGML_DIR llama.cpp 60macro ( strata_ggml_mmq_types ) 61set ( _strata_mmq_types q2_0 q3_k iq2_xxs iq2_xs iq2_s iq3_xxs iq3_s iq4_nl iq4_xs q8_0 ) # q3_k: the v7l1280 q3k latent pack 62# APR: the agention llama.cpp fork has MMQ instances for its trellis expert types (f62fdead0); any other ggml 63# tree leaves them to the FP16 prompt path 64if ( STRATA_GGML_DIRAND EXISTS " ${ STRATA_GGML_DIR } /ggml/src/ggml-cuda/template-instances/mmq-instance-tqk6.cu" ) 65list ( APPEND _strata_mmq_types tq2_t tqk6 tqk7 ) 66# Gyro-L's pair trellis (types 147-149): the same fork's ggml has their MMQ instances 67if ( EXISTS " ${ STRATA_GGML_DIR } /ggml/src/ggml-cuda/template-instances/mmq-instance-tqp5.cu" ) 68list ( APPEND _strata_mmq_types tqp5 tqp6 tqp7 ) 69set ( _strata_mmq_tqp ON ) # moe_mmq.cu names GGML_TYPE_TQP5-7 only where the ggml has them (STRATA_MMQ_TQP) 70endif () 71set ( _strata_mmq_tq ON ) 72elseif ( STRATA_MMQ_TQ_OVERLAYAND ( STRATA_ENABLE_CUDAOR STRATA_ENABLE_HIP)) 73if ( NOT STRATA_GGML_DIR) 74# the vendored ggml: what the overlay would write is plain files in third_party/strata-ggml/ggml/src/ggml-cuda-tq (patched copies of ggml.h, 75# mmq.cuh, mmq-load-tiles.cuh, mmq-config-*.cuh and quantize.cu, tq.cuh, the tile loader and the trellis instances; UPSTREAM.md), used exactly as 76# the overlay dir was: first on strata_mmq's include path, its instances and quantize.cu compiled from there. Every other file of ggml-cuda is untouched. 77set ( _strata_tq_overlay_dir " ${ _strata_ggml_root } /ggml/src/ggml-cuda-tq" ) 78set ( _strata_mmq_tq ON ) 79set ( _strata_mmq_tqp ON ) 80set ( _strata_mmq_tq_overlay ON ) 81message ( STATUS "trellis MMQ (Gyro prompts): vendored ${ _strata_tq_overlay_dir } " ) 82else () 83# an upstream llama.cpp: the trellis MMQ instances come from an overlay of the pinned ggml-cuda headers written at 84# configure time (cmake/strata_ggml_tq_overlay.cmake); off with a message if the llama.cpp tree is not the pinned one 85set ( _strata_tq_llama " ${ _strata_ggml_root } " ) 86include ( $ { CMAKE_CURRENT_SOURCE_DIR } /cmake/strata_ggml_tq_overlay.cmake ) 87set ( _strata_tq_overlay_dir " ${ CMAKE_BINARY_DIR } /ggml-tq-overlay" ) 88strata_ggml_tq_overlay ( " ${ _strata_tq_llama } " " ${ _strata_tq_overlay_dir } " ) 89if ( STRATA_TQ_OVERLAY_OK) 90configure_file ( third_party/ggml/ggml-common-tq.h " ${ _strata_tq_overlay_dir } /ggml-common-tq.h" COPYONLY ) 91configure_file ( src/kernels/cuda/tq_lut_i8.cuh " ${ _strata_tq_overlay_dir } /tq_lut_i8.cuh" COPYONLY ) 92set ( _strata_mmq_tq ON ) 93set ( _strata_mmq_tqp ON ) # the overlay adds the pair-trellis enumerators and instances 94set ( _strata_mmq_tq_overlay ON ) 95message ( STATUS "trellis MMQ (Gyro prompts): overlay on the pinned ggml-cuda in ${ _strata_tq_overlay_dir } " ) 96if ( STRATA_BUILD_TESTS) 97add_test ( NAME ggml_tq_overlay COMMAND ${ CMAKE_COMMAND } -DLLAMA= ${ _strata_tq_llama } 98-DOUT= ${ CMAKE_BINARY_DIR } /ggml-tq-overlay-test -P ${ CMAKE_CURRENT_SOURCE_DIR } /cmake/ggml_tq_overlay_test.cmake ) 99endif () 100endif () 101endif () 102endif () 103endmacro ()