okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

waveringanaedge0-strata: add the engine for Edge0 145B and Edge0 120Bfd19246dc

main
6.5 KiB103 linesraw
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)
10  set(_strata_ggml_root "${STRATA_GGML_DIR}")
11else()
12  get_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)
18  set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
19  set(GGML_STATIC ON CACHE BOOL "" FORCE)
20  set(GGML_CUDA OFF CACHE BOOL "" FORCE)
21  set(GGML_OPENMP OFF CACHE BOOL "" FORCE)
22  set(GGML_BACKEND_DL OFF CACHE BOOL "" FORCE)
23  set(GGML_BUILD_TESTS OFF CACHE BOOL "" FORCE)
24  set(GGML_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
25  if(STRATA_PORTABLE AND 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.
29    set(GGML_NATIVE OFF CACHE BOOL "" FORCE)
30    set(STRATA_ARM64_ARCH "armv8.2-a+dotprod+fp16+i8mm" CACHE STRING "arm64: ggml-cpu's -march for a STRATA_PORTABLE build")
31    set(GGML_CPU_ARM_ARCH "${STRATA_ARM64_ARCH}" CACHE STRING "" FORCE)
32  elseif(STRATA_PORTABLE)
33    set(GGML_NATIVE OFF CACHE BOOL "" FORCE)
34    foreach(_f GGML_AVX GGML_AVX2 GGML_FMA GGML_F16C GGML_BMI2)
35      set(${_f} ON CACHE BOOL "" FORCE)
36    endforeach()
37  elseif(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.
41    set(GGML_NATIVE OFF CACHE BOOL "" FORCE)
42    set(GGML_CPU_ALL_VARIANTS OFF CACHE BOOL "" FORCE)
43    set(GGML_SSE42 ON CACHE BOOL "" FORCE)
44    if(STRATA_ISA_FLOOR STREQUAL "avx")
45      set(GGML_AVX ON CACHE BOOL "" FORCE)
46    else()
47      set(GGML_AVX OFF CACHE BOOL "" FORCE)
48    endif()
49    foreach(_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)
51      set(${_f} OFF CACHE BOOL "" FORCE)
52    endforeach()
53  else()
54    set(GGML_NATIVE ON CACHE BOOL "" FORCE)
55  endif()
56  add_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)
61  set(_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
64  if(STRATA_GGML_DIR AND EXISTS "${STRATA_GGML_DIR}/ggml/src/ggml-cuda/template-instances/mmq-instance-tqk6.cu")
65    list(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
67    if(EXISTS "${STRATA_GGML_DIR}/ggml/src/ggml-cuda/template-instances/mmq-instance-tqp5.cu")
68      list(APPEND _strata_mmq_types tqp5 tqp6 tqp7)
69      set(_strata_mmq_tqp ON)   # moe_mmq.cu names GGML_TYPE_TQP5-7 only where the ggml has them (STRATA_MMQ_TQP)
70    endif()
71    set(_strata_mmq_tq ON)
72  elseif(STRATA_MMQ_TQ_OVERLAY AND (STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP))
73    if(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.
77      set(_strata_tq_overlay_dir "${_strata_ggml_root}/ggml/src/ggml-cuda-tq")
78      set(_strata_mmq_tq ON)
79      set(_strata_mmq_tqp ON)
80      set(_strata_mmq_tq_overlay ON)
81      message(STATUS "trellis MMQ (Gyro prompts): vendored ${_strata_tq_overlay_dir}")
82    else()
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
85      set(_strata_tq_llama "${_strata_ggml_root}")
86      include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/strata_ggml_tq_overlay.cmake)
87      set(_strata_tq_overlay_dir "${CMAKE_BINARY_DIR}/ggml-tq-overlay")
88      strata_ggml_tq_overlay("${_strata_tq_llama}" "${_strata_tq_overlay_dir}")
89      if(STRATA_TQ_OVERLAY_OK)
90        configure_file(third_party/ggml/ggml-common-tq.h "${_strata_tq_overlay_dir}/ggml-common-tq.h" COPYONLY)
91        configure_file(src/kernels/cuda/tq_lut_i8.cuh "${_strata_tq_overlay_dir}/tq_lut_i8.cuh" COPYONLY)
92        set(_strata_mmq_tq ON)
93        set(_strata_mmq_tqp ON)   # the overlay adds the pair-trellis enumerators and instances
94        set(_strata_mmq_tq_overlay ON)
95        message(STATUS "trellis MMQ (Gyro prompts): overlay on the pinned ggml-cuda in ${_strata_tq_overlay_dir}")
96        if(STRATA_BUILD_TESTS)
97          add_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)
99        endif()
100      endif()
101    endif()
102  endif()
103endmacro()