okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6ca60e9a0
main
1# cmake -DLLAMA=<llama.cpp dir> -DOUT=<scratch dir> -P cmake/ggml_tq_overlay_test.cmake 2# The trellis MMQ overlay on a pinned llama.cpp: it generates, every copied header is the pinned one except the patched 3# ones, and the patched ones only gain lines (TQ routing, three externs, config copies of IQ2_XS's). 4# a -P script has no cmake_minimum_required, so CMake 3.x applies the OLD CMP0057 and IN_LIST below is not an operator (#3412) 5cmake_policy ( SET CMP0057 NEW ) 6get_filename_component ( CMAKE_SOURCE_DIR " ${ CMAKE_CURRENT_LIST_DIR } /.." ABSOLUTE ) 7include ( $ { CMAKE_CURRENT_LIST_DIR } /strata_ggml_tq_overlay.cmake ) 8file ( REMOVE_RECURSE " ${ OUT } " ) 9strata_ggml_tq_overlay ( " ${ LLAMA } " " ${ OUT } " ) 10if ( NOT STRATA_TQ_OVERLAY_OK) 11message ( FATAL_ERROR "overlay did not generate on ${ LLAMA } " ) 12endif () 13set ( CU " ${ LLAMA } /ggml/src/ggml-cuda" ) 14file ( GLOB _cuh " ${ CU } /*.cuh" " ${ CU } /*.h" ) 15set ( _patched mmq.cuh mmq-load-tiles.cuh ) 16foreach ( _f IN LISTS _cuh) 17get_filename_component ( _n " ${ _f } " NAME ) 18if ( _nMATCHES "^mmq-config-" OR _nIN_LIST _patched) 19continue () 20endif () 21file ( READ " ${ _f } " _a ) 22file ( READ " ${ OUT } / ${ _n } " _b ) 23if ( NOT _aSTREQUAL _b) 24message ( FATAL_ERROR " ${ _n } differs from the pinned file but is not meant to" ) 25endif () 26endforeach () 27file ( READ " ${ OUT } /mmq.cuh" _m ) 28foreach ( _pat"case GGML_TYPE_TQ2_T: return MMQ_DP4A_TXS_Q8_0_16;" "ggml_cuda_mmq_load_tiles_tq<type, J, fallback>,\n ggml_cuda_mmq_vec_dot_q8_0_16_q8_1_dp4a" 29"extern DECL_MMQ_CASE(GGML_TYPE_TQK7);" "extern DECL_MMQ_CASE(GGML_TYPE_TQP5);" "extern DECL_MMQ_CASE(GGML_TYPE_TQP7);" 30"case GGML_TYPE_TQP6: return MMQ_DP4A_TXS_Q8_0_16;" ) 31string ( FIND " ${ _m } " " ${ _pat } " _p ) 32if ( _pLESS 0 ) 33message ( FATAL_ERROR "mmq.cuh lacks: ${ _pat } " ) 34endif () 35endforeach () 36file ( READ " ${ OUT } /include/ggml.h" _g ) 37string ( FIND " ${ _g } " "GGML_TYPE_TQK7 = 146," _p ) 38if ( _pLESS 0 ) 39message ( FATAL_ERROR "ggml.h lacks the trellis enumerators" ) 40endif () 41string ( FIND " ${ _g } " "GGML_TYPE_TQP7 = 149," _p ) # Gyro-L's pair trellis 42if ( _pLESS 0 ) 43message ( FATAL_ERROR "ggml.h lacks the pair-trellis enumerators" ) 44endif () 45foreach ( _t tqp5 tqp6 tqp7) 46if ( NOT EXISTS " ${ OUT } /template-instances/mmq-instance- ${ _t } .cu" ) 47message ( FATAL_ERROR "the overlay has no MMQ instance for ${ _t } " ) 48endif () 49endforeach () 50foreach ( _c IN ITEMS ampere rdna4) 51file ( READ " ${ CU } /mmq-config- ${ _c } .cuh" _o ) 52file ( READ " ${ OUT } /mmq-config- ${ _c } .cuh" _n2 ) 53string ( REGEX MATCHALL "CASE[(]GGML_TYPE_IQ2_XS," _x " ${ _o } " ) 54string ( REGEX MATCHALL "CASE[(]GGML_TYPE_TQK6," _y " ${ _n2 } " ) 55list ( LENGTH _x _lx ) 56list ( LENGTH _y _ly ) 57if ( NOT _lxEQUAL _lyOR _lxEQUAL 0 ) 58message ( FATAL_ERROR "mmq-config- ${ _c } .cuh: ${ _lx } IQ2_XS cases, ${ _ly } TQK6 cases" ) 59endif () 60endforeach () 61# #3217: the generated callbacks and the loader follow the helper signatures of the ggml-cuda they patch: with the precision argument 62# (llama.cpp b11xxx and newer: prec_src1) they carry it, on the pinned commit (no such argument) they do not 63file ( READ " ${ CU } /mmq.cuh" _src ) 64file ( READ " ${ OUT } /tq-mmq-tiles.cuh" _tiles ) 65string ( FIND " ${ _src } " "ggml_cuda_mmq_get_nthreads(ggml_type type, int J, bool fallback, ggml_prec prec_src1)" _with_prec ) 66if ( _with_precLESS 0 ) 67string ( FIND " ${ _m } " "ggml_cuda_mmq_write_back_mma<type, J, fallback, prec_src1>);\n case GGML_TYPE_IQ3_XXS" _bad ) 68string ( FIND " ${ _tiles } " "GGML_PREC_Q8" _bad2 ) 69if ( NOT _bad2LESS 0 ) 70message ( FATAL_ERROR "the loader passes a precision argument the pinned ggml-cuda does not take" ) 71endif () 72string ( FIND " ${ _m } " "ggml_cuda_mmq_load_tiles_tq<type, J, fallback>,\n ggml_cuda_mmq_vec_dot_q8_0_16_q8_1_dp4a<type, J, fallback>,\n ggml_cuda_mmq_write_back_dp4a<type, J, fallback>);" _ok ) 73else () 74string ( FIND " ${ _m } " "ggml_cuda_mmq_load_tiles_tq<type, J, fallback>,\n ggml_cuda_mmq_vec_dot_q8_0_16_q8_1_dp4a<type, J, fallback>,\n ggml_cuda_mmq_write_back_dp4a<type, J, fallback, prec_src1>);" _ok ) 75string ( FIND " ${ _tiles } " "ggml_cuda_mmq_get_sram_stride(type, J, fallback, GGML_PREC_Q8)" _loader_ok ) 76if ( _loader_okLESS 0 ) 77message ( FATAL_ERROR "the loader does not pass GGML_PREC_Q8 to ggml_cuda_mmq_get_sram_stride" ) 78endif () 79endif () 80if ( _okLESS 0 ) 81message ( FATAL_ERROR "the generated DP4A callback does not match this ggml-cuda's signatures" ) 82endif () 83message ( STATUS "ggml_tq_overlay_test: ok" )