okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
74d12d663
main
1# cmake/backends/cuda.cmake - the NVIDIA (CUDA) parts of the root project: toolchain setup, llama.cpp's MMQ kernels (strata_mmq, strata_kq), the spill guard. 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# CUDA: runtime library, architectures (enable_language), the architecture checks, the gpu target variables 7macro ( strata_cuda_toolchain ) 8# #585: CMake links CUDA code with the STATIC runtime by default, and the targets below also link CUDA::cudart (the 9# DLL's import library). MSVC with a CUDA 12.x toolkit - the experimental Pascal/Volta build - then fails with 10# LNK1169 (every cudart symbol defined twice); GNU ld lets it pass. That build links the shared runtime alone. The 11# ready-made engine (CUDA 13, no STRATA_EXPERIMENTAL_SM60) is unchanged; -DCMAKE_CUDA_RUNTIME_LIBRARY overrides. 12if ( MSVCAND STRATA_EXPERIMENTAL_SM60AND NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY) 13set ( CMAKE_CUDA_RUNTIME_LIBRARY Shared ) 14endif () 15# #4023: the default below has to be set BEFORE enable_language(CUDA): since CMake 3.18 that call fills an unset 16# CMAKE_CUDA_ARCHITECTURES with nvcc's own default (sm_75 for CUDA 13), so a test after it never saw "undefined" and 17# a build with no option was an sm_75 build. -DCMAKE_CUDA_ARCHITECTURES and the CUDAARCHS environment variable win. 18set ( _strata_cuda_arch_defaulted OFF ) 19if ( NOT DEFINED CMAKE_CUDA_ARCHITECTURESAND NOT DEFINED ENV{CUDAARCHS}) 20set ( CMAKE_CUDA_ARCHITECTURES 120 CACHE STRING "CUDA architectures" ) 21set ( _strata_cuda_arch_defaulted ON ) 22endif () 23enable_language ( CUDA ) 24# `enable_language(CUDA)` gives the .cu compile rules but NOT the imported targets, so `CUDA::cudart` has to 25# be brought in explicitly for the host-side tests that call cudaMalloc themselves. 26find_package ( CUDAToolkit REQUIRED ) 27option ( STRATA_EXPERIMENTAL_SM60 "community build for GPUs below compute capability 7.5: Pascal sm_60, Volta sm_70 (#236)" OFF ) 28if ( _strata_cuda_arch_defaulted) 29# a recommendation, not a refusal: the release engine is built for 75;86;89;120, a hand build names its card 30message ( WARNING "Strata: CMAKE_CUDA_ARCHITECTURES was not set, so this build is for ${ CMAKE_CUDA_ARCHITECTURES } only (sm_120 = RTX 50). For another " 31"card pass it: -DCMAKE_CUDA_ARCHITECTURES=native (the GPUs in this PC), 75 (RTX 20), 86 (RTX 30), " 32"89 (RTX 40), or a list like \"86;120\"." ) 33endif () 34set ( _strata_cuda_below75 OFF ) # an architecture below sm_75 in the list (only with STRATA_EXPERIMENTAL_SM60): tests of sm_75+ device code are not built 35foreach ( _a IN LISTS CMAKE_CUDA_ARCHITECTURES) 36string ( REGEX REPLACE "-.* $ " "" _base " ${ _a } " ) # 120-real / 120-virtual are still 120 37if ( _baseMATCHES "^[0-9]+ $ " AND _baseLESS 75) 38set ( _strata_cuda_below75 ON ) 39endif () 40# Turing port: developed and measured on sm_120 (RTX 50); the tf32 mma in the QSA scorer has a 41# portable fp32-FMA fallback, so RTX 20 (75), 30 (86), RTX 40 (89) and RTX 50 (120) build too. 42# Pre-sm_75 is refused. 43if ( _baseSTREQUAL "native" OR _baseSTREQUAL "all" OR _baseSTREQUAL "all-major" ) 44continue () 45endif () 46# STRATA_EXPERIMENTAL_SM60: a Pascal (sm_60, GP100-class) or Volta (sm_70, V100 / Titan V, #236) build. 47# These sit below every architecture the kernels were written for, so two intrinsics are replaced below 48# their arch - `__dp4a` (6.1+) and `__nanosleep` (7.0+) - in include/strata/kernels/dp4a.hpp, which is 49# bit-exact for the first and merely a shorter pause for the second (sm_70 has both). Community-tested, 50# not in the ready-made engine; RTX 20/30/40/50 cards must use the release engine instead. It needs a CUDA 51# 12.x toolkit: CUDA 13 dropped sm_60 and sm_70 (nvcc fails CMake's compiler test with "compute_70"). 52if ( _baseLESS 75AND NOT STRATA_EXPERIMENTAL_SM60) 53message ( FATAL_ERROR 54"Strata needs an NVIDIA GPU of compute capability 7.5 or newer (RTX 20 / 30 / 40 / 50 series), but " 55"CMAKE_CUDA_ARCHITECTURES is ' ${ CMAKE_CUDA_ARCHITECTURES } '. (A Pascal sm_60 or Volta sm_70 build is " 56"-DSTRATA_EXPERIMENTAL_SM60=ON; upstream does not support it.)" ) 57endif () 58if ( _baseLESS 52) 59message ( FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES ' ${ CMAKE_CUDA_ARCHITECTURES } ': even the experimental build " 60"needs compute capability 5.2 (sm_52, Maxwell) or newer" ) 61endif () 62# Maxwell (sm_52, #3218): one reporter built and ran this on two Quadro M6000 (CUDA 12.x, Qwen3.8-Flash-Next 63# IQ1, about 22 t/s). It has no native half-precision arithmetic, so it is slower per byte than Pascal; only 64# this opt-in build gets the floor. Warn, do not refuse. 65if ( _baseLESS 60) 66message ( WARNING "Building for sm_ ${ _base } (Maxwell): community-tested on one reporter's Quadro M6000 only, " 67"no native half-precision arithmetic, CUDA 12.x toolkit required (docs/OLDER_GPUS.md)." ) 68endif () 69# #220 / #224: RTX 50 engines built with CUDA 12.8 crashed in the prompt path on Linux (13.0 and newer did not) 70if ( _baseGREATER_EQUAL 120AND CMAKE_CUDA_COMPILER_VERSIONVERSION_LESS 13.0) 71message ( WARNING "Building for sm_ ${ _base } (RTX 50) with CUDA ${ CMAKE_CUDA_COMPILER_VERSION } : engines built with " 72"CUDA 12.8 crashed on long prompts on these cards (issues #220, #224). Use CUDA 13.0 or newer." ) 73endif () 74endforeach () 75if ( STRATA_EXPERIMENTAL_SM60) 76# every target sees it: the Pascal / Volta code paths (the Volta prompt attention, PR #600) are compiled into this 77# build only, so the ready-made engine (sm_75+) keeps exactly the code it had 78add_compile_definitions ( STRATA_EXPERIMENTAL_SM60=1 ) 79endif () 80message ( STATUS "Strata: CUDA enabled, arch ${ CMAKE_CUDA_ARCHITECTURES } " ) 81set ( _strata_gpu_runtime_target CUDA::cudart ) 82set ( _strata_gpu_blas_target CUDA::cublas ) 83set ( _strata_gpu_include_directories ${ CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES }) 84endmacro () 85 86# strata_pf_own (Strata's own prompt kernels) with strata_mmq's include directories (in their order, the trellis overlay's 87# first), definitions and options: the same command line for the files that left strata_mmq (CUDA and HIP) 88macro ( strata_pf_own_mirror ) 89foreach ( _strata_p INCLUDE_DIRECTORIES COMPILE_DEFINITIONS COMPILE_OPTIONS) 90get_target_property ( _strata_v strata_mmq ${ _strata_p }) 91if ( _strata_v) 92set_property ( TARGET strata_pf_own PROPERTY ${ _strata_p } " ${ _strata_v } " ) 93endif () 94endforeach () 95target_include_directories ( strata_pf_own INTERFACE ${ CMAKE_CURRENT_SOURCE_DIR } /include ) 96endmacro () 97 98# strata_mmq, strata_mmq_w4a4 and libstrata_kq: llama.cpp's MMQ kernels for the prompt path (CUDA), and their tests 99macro ( strata_cuda_mmq ) 100# prompt-speed plan step 2b: llama.cpp's MMQ kernels (ggml-cuda, MIT) for the prompt path's experts, compiled 101# from the same checkout as ggml above - only mmq.cuh's instances for the packs' types and the quantizer, with 102# the few host symbols of ggml-cuda.cu they use in src/prefill/ggml_cuda_host.cu 103set ( _strata_gg ${ _strata_ggml_root } /ggml ) 104set ( _strata_mmq ${ _strata_gg } /src/ggml-cuda ) 105set ( _strata_quantize_cu ${ _strata_mmq } /quantize.cu ) # the overlay's copy when the trellis overlay is on: it includes mmq.cuh 106if ( _strata_mmq_tq_overlay) 107set ( _strata_quantize_cu ${ _strata_tq_overlay_dir } /quantize.cu ) 108endif () 109# #136: the Q2_0 pack's prompt experts on Strata's own int8 kernels (moe_fused.cu, opt-in STRATA_PF_FUSED=1; CUDA 110# only: the HIP branch below keeps MMQ, and an sm_75 device or an sm_75-only build reports them unavailable) 111add_library ( strata_mmq STATIC src/prefill/moe_mmq.cu src/prefill/moe_iq4_w4a8.cu 112src/prefill/mmq_nvfp4_w4a8.cu 113src/prefill/ggml_cuda_host.cu ${ _strata_quantize_cu }) 114# M1 of the q3k latent A stage: the down half (IQ4_NL, K = 640) on moe_fused.cu's latent kernel structure 115target_sources ( strata_mmq PRIVATE src/prefill/lat_q3k_down.cu ) 116# M2a of the q3k latent A stage: the gate/up half (Q3_K, K = 640 features of gate and up) 117target_sources ( strata_mmq PRIVATE src/prefill/lat_q3k_gu.cu ) 118# M2b of the q3k latent A stage: SwiGLU + the q8_1 of H 119target_sources ( strata_mmq PRIVATE src/prefill/lat_q3k_swiglu.cu ) 120# M3 of the q3k latent A stage: the whole stage in one call (two launches, the down is lat_q3k_down's) 121target_sources ( strata_mmq PRIVATE src/prefill/lat_q3k_fused.cu ) 122# The latent Q3_K variant uses the same flags as the other MMQ sources. 123target_sources ( strata_mmq PRIVATE src/prefill/moe_fused_q3k.cu ) 124# P4-SPLIT: Strata's own prompt kernels (the fused int8 experts) are a library of their own, strata_pf_own, so that a 125# build without llama.cpp's MMQ keeps them. With MMQ they are compiled with strata_mmq's command line (strata_pf_own_mirror 126# below) and strata_mmq hands them on (PUBLIC): every target that links strata_mmq gets the same objects as before. 127add_library ( strata_pf_own STATIC src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu src/prefill/moe_helpers.cu 128src/prefill/moe_fused_iq_q36.cu ) # (the same kernels again for Qwen3.6's expert shape, for src/qwen35/q36_engine.cu) 129if ( STRATA_EXPERIMENTAL_SM60AND NOT STRATA_HIP_GFX906) 130# GP100 (sm_60): a resident layer's experts weight-stationary, one launch per product (moe_ws.hpp; opt-in at 131# run time, STRATA_MMQ_WS=1, and only where every visible GPU is cc 6.0) 132target_sources ( strata_mmq PRIVATE src/prefill/moe_ws.cu src/prefill/moe_ws_gu_iq2.cu src/prefill/moe_ws_gu_iq3.cu 133src/prefill/moe_ws_down.cu ) 134endif () 135# q8_0: the drafter's matrices (E-9); STRATA_ORCA_Q4KS_MMQ adds q5_0 (#296, in _strata_mmq_types), and 136# STRATA_MMQ_KQUANTS q4_k q5_k q5_1 q6_k, the experts of Unsloth's UD-Q4/Q5/Q6_K_XL (docs/QUANTS.md; the dispatch 137# follows eddoursul/Strata 7706c1b). MODEL-UPDATE Phase 1: on CUDA they are a library of their own, strata_kq 138# (below), loaded only for a model with these experts: the engine loads every kernel of its own binary at start 139# (CUDA_MODULE_LOADING=EAGER), and these four took ~3.8 MB of VRAM (3 expert slots of IQ3_XXS on a P100) from every 140# model. gfx906 (HIP: code objects load on first use) keeps them in strata_mmq. 141set ( _strata_mmq_cuda_types ${ _strata_mmq_types }) 142set ( _strata_kq_types q4_k q5_k q5_1 q6_k ) 143set ( _strata_kq_dso OFF ) 144if ( STRATA_MMQ_KQUANTSAND STRATA_HIP_GFX906) 145list ( APPEND _strata_mmq_cuda_types ${ _strata_kq_types }) 146elseif ( STRATA_MMQ_KQUANTS) 147set ( _strata_kq_dso ON ) 148endif () 149foreach ( _t IN LISTS _strata_mmq_cuda_types) 150target_sources ( strata_mmq PRIVATE ${ _strata_mmq } /template-instances/mmq-instance- ${ _t } .cu ) 151endforeach () 152if ( _strata_mmq_tq_overlay) 153foreach ( _t tq2_t tqk6 tqk7 tqp5 tqp6 tqp7) 154target_sources ( strata_mmq PRIVATE ${ _strata_tq_overlay_dir } /template-instances/mmq-instance- ${ _t } .cu ) 155endforeach () 156# first on the include path: the patched mmq.cuh / ggml.h shadow the pinned ones for this target only 157target_include_directories ( strata_mmq BEFORE PRIVATE ${ _strata_tq_overlay_dir } ${ _strata_tq_overlay_dir } /include ) 158endif () 159# NVFP4: W4A8 (default) in mmq_nvfp4_w4a8.cu with the plain architectures; the opt-in W4A4 needs RTX 50's FP4 MMA, 160# which exists only in the arch-specific target, so its one unit alone is built with 12x -> 12xa (the default 161# binary is unchanged and runs on sm_121; a card without that image falls back to W4A8 at run time) 162set ( _strata_w4a4_archs ${ CMAKE_CUDA_ARCHITECTURES }) 163# `native` is first replaced by the detected architectures (e.g. 120-real), so the 12x -> 12xa rewrite below applies 164# to it too: with plain sm_120 ptxas refuses the FP4 MMA of this one unit (#4023) 165if ( "native" IN_LIST _strata_w4a4_archsAND CMAKE_CUDA_ARCHITECTURES_NATIVE) 166list ( REMOVE_ITEM _strata_w4a4_archs native ) 167list ( APPEND _strata_w4a4_archs ${ CMAKE_CUDA_ARCHITECTURES_NATIVE }) 168endif () 169# (two steps: CMake before 3.29 rejects a \2 whose optional group did not match, "120" alone) 170list ( TRANSFORM _strata_w4a4_archs REPLACE "^(12[0-9]) $ " "\\1a" ) 171list ( TRANSFORM _strata_w4a4_archs REPLACE "^(12[0-9])-(real|virtual) $ " "\\1a-\\2" ) 172add_library ( strata_mmq_w4a4 STATIC src/prefill/mmq_nvfp4_w4a4.cu ) 173set_target_properties ( strata_mmq_w4a4 PROPERTIES CUDA_ARCHITECTURES " ${ _strata_w4a4_archs } " ) 174target_include_directories ( strata_mmq_w4a4 PRIVATE ${ _strata_gg } /include ${ _strata_gg } /src ${ _strata_mmq }) 175target_compile_options ( strata_mmq_w4a4 PRIVATE $ < $ <COMPILE_LANGUAGE:CUDA>:--extended-lambda -use_fast_math> ) 176if ( MSVC) 177target_compile_options ( strata_mmq_w4a4 PRIVATE $ < $ <COMPILE_LANGUAGE:CUDA>:-Xcompiler=/bigobj> ) 178endif () 179target_link_libraries ( strata_mmq_w4a4 PUBLIC ggml-base ${ _strata_gpu_runtime_target }) 180target_link_libraries ( strata_mmq PRIVATE strata_mmq_w4a4 ) 181# STRATA_MMQ_TAB: the pointer-table copy of MMQ's scheduler mirrors mmq.cuh from mul_mat_q_process_tile through 182# mul_mat_q_case (struct mmq_args included). A fingerprint of that text instead of a compile probe: nothing is 183# compiled at configure time, and a llama.cpp tree with another scheduler turns the feature off instead of 184# failing the build. _strata_mmq_tab_known: the hashes moe_mmq_tab.cuh was verified against (3cf03257, the 185# pinned commit, which is also what third_party/strata-ggml holds). 186set ( _strata_mmq_tab_on OFF ) 187if ( STRATA_MMQ_TABAND NOT STRATA_HIP_GFX906) # gfx906 compiles no .cu from here (its HIP glob): no tab at all 188if ( NOT STRATA_GGML_DIR) 189# the vendored third_party/strata-ggml is the tree moe_mmq_tab.cuh was verified against (its mmq.cuh is the pinned file, unedited), and 190# tools/check_vendored.py keeps its bytes: no fingerprint of mmq.cuh is needed 191set ( _strata_mmq_tab_on ON ) 192else () # a -DSTRATA_GGML_DIR checkout: only the verified scheduler is accepted 193set ( _strata_mmq_tab_known 36e4dc716c504470ec09cc0852d29a6ac5eace257f6e5e72db3805ca4f043eb0 ) 194set ( _strata_mmq_tab_hash "" ) 195if ( EXISTS ${ _strata_mmq } /mmq.cuh) 196file ( READ ${ _strata_mmq } /mmq.cuh _strata_mmq_src ) 197string ( REPLACE "\r\n" "\n" _strata_mmq_src " ${ _strata_mmq_src } " ) 198string ( FIND " ${ _strata_mmq_src } " "static __device__ __forceinline__ void mul_mat_q_process_tile" _strata_tab_a ) 199string ( FIND " ${ _strata_mmq_src } " "#define DECL_MMQ_CASE" _strata_tab_b ) 200if ( _strata_tab_aGREATER -1AND _strata_tab_bGREATER _strata_tab_a) 201math ( EXPR _strata_tab_len " ${ _strata_tab_b } - ${ _strata_tab_a } " ) 202string ( SUBSTRING " ${ _strata_mmq_src } " ${ _strata_tab_a } ${ _strata_tab_len } _strata_tab_region ) 203string ( SHA256 _strata_mmq_tab_hash " ${ _strata_tab_region } " ) 204endif () 205unset ( _strata_mmq_src ) 206unset ( _strata_tab_region ) 207endif () 208if ( _strata_mmq_tab_hashAND _strata_mmq_tab_hashIN_LIST _strata_mmq_tab_known) 209set ( _strata_mmq_tab_on ON ) 210else () 211message ( STATUS "STRATA_MMQ_TAB off: mmq.cuh differs from the mirrored scheduler ( ${ _strata_mmq_tab_hash } )" ) 212endif () 213endif () 214endif () 215if ( _strata_mmq_tab_on) 216set ( _strata_tab_cuh ${ CMAKE_CURRENT_SOURCE_DIR } /src/prefill/moe_mmq_tab.cuh ) 217# the native packs' nine types, the ones prefill_mmq_tab_test checks bit for bit; the optional Q5_0 / K-quant 218# instances (STRATA_ORCA_Q4KS_MMQ, STRATA_MMQ_KQUANTS) get no pointer table and keep the gather 219set ( _strata_mmq_tab_types q2_0 iq2_xxs iq2_xs iq2_s iq3_xxs iq3_s iq4_nl iq4_xs q8_0 ) 220foreach ( _t IN LISTS _strata_mmq_tab_types) 221string ( TOUPPER ${ _t } _strata_tab_T ) 222configure_file ( src/prefill/mmq_tab_instance.cu.in ${ CMAKE_BINARY_DIR } /mmq_tab/mmq-tab- ${ _t } .cu @ONLY ) 223target_sources ( strata_mmq PRIVATE ${ CMAKE_BINARY_DIR } /mmq_tab/mmq-tab- ${ _t } .cu ) 224endforeach () 225target_compile_definitions ( strata_mmq PRIVATE STRATA_MMQ_TAB=1 ) 226message ( STATUS "STRATA_MMQ_TAB on: pointer-table MMQ for ${ _strata_mmq_tab_types } " ) 227endif () 228target_include_directories ( strata_mmq PRIVATE ${ _strata_gg } /include ${ _strata_gg } /src ${ _strata_mmq } 229PUBLIC ${ CMAKE_CURRENT_SOURCE_DIR } /include ) 230target_compile_options ( strata_mmq PRIVATE $ < $ <COMPILE_LANGUAGE:CUDA>:--extended-lambda -use_fast_math> ) 231if ( MSVC) 232target_compile_options ( strata_mmq PRIVATE $ < $ <COMPILE_LANGUAGE:CUDA>:-Xcompiler=/bigobj> ) 233endif () 234# GGML's CUDA error reporting calls cuGetErrorString from the driver API. 235target_link_libraries ( strata_mmq PUBLIC ggml-base ${ _strata_gpu_runtime_target }) 236if ( TARGET CUDA::cuda_driver) # not in the HIP (gfx906) build, whose CUDA::cudart is a stand-in 237target_link_libraries ( strata_mmq PUBLIC CUDA::cuda_driver ) 238endif () 239if ( STRATA_MMQ_KQUANTS) 240target_compile_definitions ( strata_mmq PRIVATE STRATA_MMQ_KQUANTS=1 ) 241endif () 242if ( _strata_kq_dso) 243# strata_kq: the K-quant MMQ instances with their own copy of ggml_cuda_host.cu's symbols and the static CUDA 244# runtime, next to the engine (libstrata_kq.so / strata_kq.dll); moe_mmq.cu opens it when a model asks for one 245# of these formats (STRATA_MMQ_KQ=1). Without the file the engine runs them on the FP16 prompt path, as before. 246target_compile_definitions ( strata_mmq PRIVATE STRATA_KQ_DSO=1 ) 247target_sources ( strata_mmq PRIVATE src/prefill/mmq_kq_loader.cpp ) 248if ( NOT WIN32) 249target_link_libraries ( strata_mmq PUBLIC ${ CMAKE_DL_LIBS }) 250endif () 251add_library ( strata_kq SHARED src/prefill/mmq_kq_lib.cu src/prefill/ggml_cuda_host.cu ) 252foreach ( _t IN LISTS _strata_kq_types) 253target_sources ( strata_kq PRIVATE ${ _strata_mmq } /template-instances/mmq-instance- ${ _t } .cu ) 254endforeach () 255target_include_directories ( strata_kq PRIVATE ${ _strata_gg } /include ${ _strata_gg } /src ${ _strata_mmq } 256${ CMAKE_CURRENT_SOURCE_DIR } /include ) 257target_compile_options ( strata_kq PRIVATE $ < $ <COMPILE_LANGUAGE:CUDA>:--extended-lambda -use_fast_math> ) 258if ( MSVC) 259target_compile_options ( strata_kq PRIVATE $ < $ <COMPILE_LANGUAGE:CUDA>:-Xcompiler=/bigobj> ) 260endif () 261set_target_properties ( strata_kq PROPERTIES CUDA_RUNTIME_LIBRARY Static POSITION_INDEPENDENT_CODE ON 262CXX_VISIBILITY_PRESET hidden CUDA_VISIBILITY_PRESET hidden ) 263# ggml-base is static: position-independent so a shared library can hold it (the same code otherwise) 264set_target_properties ( ggml-base PROPERTIES POSITION_INDEPENDENT_CODE ON ) 265target_link_libraries ( strata_kq PRIVATE ggml-base ) 266if ( TARGET CUDA::cuda_driver) 267target_link_libraries ( strata_kq PRIVATE CUDA::cuda_driver ) 268endif () 269add_dependencies ( strata_mmq strata_kq ) 270endif () 271if ( STRATA_ORCA_Q4KS_MMQ) 272target_compile_definitions ( strata_mmq PRIVATE STRATA_ORCA_Q4KS_MMQ=1 ) 273endif () 274if ( _strata_mmq_tq) 275target_compile_definitions ( strata_mmq PRIVATE STRATA_MMQ_TQ=1 ) 276endif () 277if ( _strata_mmq_tqp) 278target_compile_definitions ( strata_mmq PRIVATE STRATA_MMQ_TQP=1 ) 279endif () 280strata_pf_own_mirror () 281target_link_libraries ( strata_pf_own PUBLIC strata_quant ggml-base ${ _strata_gpu_runtime_target }) 282if ( TARGET CUDA::cuda_driver) 283target_link_libraries ( strata_pf_own PUBLIC CUDA::cuda_driver ) 284endif () 285target_link_libraries ( strata_mmq PUBLIC strata_pf_own ) 286target_link_libraries ( strata_prefill PUBLIC strata_mmq ) 287target_compile_definitions ( strata_prefill PUBLIC STRATA_PREFILL_MMQ=1 STRATA_PREFILL_FUSED=1 ) 288if ( STRATA_EXPERIMENTAL_SM60AND NOT STRATA_HIP_GFX906) 289# the weight-stationary experts (moe_ws.hpp) are in strata_mmq: the prompt path may take them (STRATA_MMQ_WS=1) 290target_compile_definitions ( strata_prefill PUBLIC STRATA_PREFILL_WS=1 ) 291endif () 292set ( _strata_pf_tests_lib strata_mmq ) 293endmacro () 294 295# P4-SPLIT, STRATA_MMQ=OFF (the default): Strata's own prompt kernels without llama.cpp's MMQ (strata_pf_own alone, with mmq_absent.cpp for the MMQ half 296# of moe_mmq.hpp); the same sources and options as strata_cuda_mmq gives them, the ggml-base headers only 297macro ( strata_cuda_pf_own ) 298set ( _strata_gg ${ _strata_ggml_root } /ggml ) 299add_library ( strata_pf_own STATIC src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu src/prefill/moe_helpers.cu 300src/prefill/moe_fused_iq_q36.cu src/prefill/mmq_absent.cpp ) 301target_include_directories ( strata_pf_own PRIVATE ${ _strata_gg } /include ${ _strata_gg } /src PUBLIC ${ CMAKE_CURRENT_SOURCE_DIR } /include ) 302target_compile_options ( strata_pf_own PRIVATE $ < $ <COMPILE_LANGUAGE:CUDA>:--extended-lambda -use_fast_math> ) 303if ( MSVC) 304target_compile_options ( strata_pf_own PRIVATE $ < $ <COMPILE_LANGUAGE:CUDA>:-Xcompiler=/bigobj> ) 305endif () 306target_link_libraries ( strata_pf_own PUBLIC strata_quant ggml-base ${ _strata_gpu_runtime_target }) 307if ( TARGET CUDA::cuda_driver) 308target_link_libraries ( strata_pf_own PUBLIC CUDA::cuda_driver ) 309endif () 310if ( STRATA_HIP_GFX906) # (strata_hip_gfx906_sources adds these two to strata_pf_own only with MMQ) 311target_sources ( strata_pf_own PRIVATE src/prefill/moe_f16_kq.cu ) 312target_sources ( strata_pf_own PRIVATE src/prefill/moe_p1a.cu ) 313target_compile_definitions ( strata_pf_own PRIVATE GGML_USE_HIP ) 314endif () 315target_link_libraries ( strata_prefill PUBLIC strata_pf_own ) 316target_compile_definitions ( strata_prefill PUBLIC STRATA_PREFILL_FUSED=1 ) 317set ( _strata_pf_tests_lib strata_pf_own ) 318message ( STATUS "Strata: no llama.cpp MMQ prompt kernels (STRATA_MMQ=OFF): Strata's own prompt kernels and the FP16 path" ) 319endmacro () 320 321# the prompt kernels' tests: the fused experts' (linked to ${_strata_pf_tests_lib}) and, with MMQ, MMQ's own 322macro ( strata_cuda_prompt_tests ) 323if ( STRATA_BUILD_TESTSAND NOT STRATA_MMQ) 324# P4-SPLIT: the engine and Strata's prompt library hold none of llama.cpp's MMQ (names in the bytes, nm, cuobjdump; tools/check_no_mmq.py) 325find_package ( Python3 QUIET COMPONENTS Interpreter ) 326if ( Python3_Interpreter_FOUND) 327add_test ( NAME no_mmq_symbols COMMAND ${ Python3_EXECUTABLE } ${ CMAKE_CURRENT_SOURCE_DIR } /tools/check_no_mmq.py 328--cuobjdump ${ CUDAToolkit_BIN_DIR } /cuobjdump ${ CMAKE_EXECUTABLE_SUFFIX } $ <TARGET_FILE:strata> $ <TARGET_FILE:strata_pf_own> ) 329set_tests_properties ( no_mmq_symbols PROPERTIES TIMEOUT 900 ) 330endif () 331endif () 332if ( STRATA_BUILD_TESTS) 333# the fused prompt kernels' weight decode (moe_fused_iq.cu's load_unit / convert, compiled as the library compiles them) against 334# stored digests: the same file on CUDA and HIP (exit 77 without a card). Those device functions exist only for sm_75 and newer 335# (moe_fused_iq.cu's __CUDA_ARCH__ >= 750 sections), so a list with an older architecture (STRATA_EXPERIMENTAL_SM60) does not build it 336if ( _strata_cuda_below75) 337message ( STATUS "Strata: prefill_decode_golden not built: ${ CMAKE_CUDA_ARCHITECTURES } has an architecture below sm_75" ) 338else () 339add_executable ( prefill_decode_golden tests/cuda/prefill_decode_golden.cu ) 340target_include_directories ( prefill_decode_golden PRIVATE $ <TARGET_PROPERTY:strata_pf_own,INCLUDE_DIRECTORIES> ) 341target_compile_definitions ( prefill_decode_golden PRIVATE $ <TARGET_PROPERTY:strata_pf_own,COMPILE_DEFINITIONS> ) 342target_compile_options ( prefill_decode_golden PRIVATE $ <TARGET_PROPERTY:strata_pf_own,COMPILE_OPTIONS> ) 343target_link_libraries ( prefill_decode_golden PRIVATE ggml-base ${ _strata_gpu_runtime_target }) 344add_test ( NAME prefill_decode_golden COMMAND prefill_decode_golden ${ CMAKE_CURRENT_SOURCE_DIR } /tests/cuda/prefill_decode_golden.txt ) 345set_tests_properties ( prefill_decode_golden PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 120 ) 346endif () 347# #136: the fused int8 experts against a double-precision reference and the MMQ path (exit 77 below sm_80) 348add_executable ( prefill_fused_moe_test tests/cuda/prefill_fused_moe_test.cpp ) 349target_link_libraries ( prefill_fused_moe_test PRIVATE ${ _strata_pf_tests_lib } ggml-base ${ _strata_gpu_runtime_target }) 350add_test ( NAME prefill_fused_moe_test COMMAND prefill_fused_moe_test ) 351set_tests_properties ( prefill_fused_moe_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 300 ) 352# #136: the same for the native packs' formats (IQ2_XXS IQ2_XS IQ2_S IQ3_XXS IQ3_S IQ4_XS, down Q2_0 IQ4_NL) 353add_executable ( prefill_fused_iq_test tests/cuda/prefill_fused_iq_test.cpp ) 354target_link_libraries ( prefill_fused_iq_test PRIVATE ${ _strata_pf_tests_lib } ggml-base ${ _strata_gpu_runtime_target }) 355add_test ( NAME prefill_fused_iq_test COMMAND prefill_fused_iq_test ) 356set_tests_properties ( prefill_fused_iq_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ) 357# one prompt layer of experts timed on every path the engine can take (MMQ where it is built, the dequantize + FP16 GEMM path with and without 358# the few-row experts, the grouped kernels, the fused kernels where the card has them), hash and error of each against a CPU reference; runs on 359# any card (77 only without one). The ctest entry is a small smoke run; the grid is `prefill_expert_paths_bench` itself (see its source's head) 360add_executable ( prefill_expert_paths_bench tests/cuda/prefill_expert_paths_bench.cpp ) 361target_link_libraries ( prefill_expert_paths_bench PRIVATE strata_prefill ${ _strata_pf_tests_lib } $ <TARGET_NAME_IF_EXISTS:strata_quant> ggml-base ${ _strata_gpu_runtime_target }) 362add_test ( NAME prefill_expert_paths_bench COMMAND prefill_expert_paths_bench --quick ) 363set_tests_properties ( prefill_expert_paths_bench PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ) 364# P4-SMALL: the fused experts for one gathered group (the layer-major walk's entry) against the layer's fused path (bits) and MMQ in the walk 365# (P4-INT: MMQ builds only: the test returns 1 where mmq::built() is false, it has no no-MMQ rule yet) 366if ( STRATA_MMQ) 367add_executable ( prefill_fused_group_test tests/cuda/prefill_fused_group_test.cpp ) 368target_link_libraries ( prefill_fused_group_test PRIVATE ${ _strata_pf_tests_lib } ggml-base ${ _strata_gpu_runtime_target }) 369add_test ( NAME prefill_fused_group_test COMMAND prefill_fused_group_test ) 370set_tests_properties ( prefill_fused_group_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ) 371endif () 372# the same kernels at Qwen3.6's expert shape (n_embd 2048, n_ff 512: the copy moe_fused_iq_q36.cu compiles): UD-Q6_K_XL's and the 373# Q8_0 file's pairs against the reference, the int8 model and MMQ (77 below sm_80) 374add_executable ( prefill_fused_q36_test tests/cuda/prefill_fused_q36_test.cpp ) 375target_link_libraries ( prefill_fused_q36_test PRIVATE ${ _strata_pf_tests_lib } ggml-base ${ _strata_gpu_runtime_target }) 376add_test ( NAME prefill_fused_q36_test COMMAND prefill_fused_q36_test ) 377set_tests_properties ( prefill_fused_q36_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 900 ) 378# a launch whose expert blobs are not in device memory takes the unstaged kernel instead of ending the process (a staged K-quant down: timing part only, one layer of 2,048 tokens) 379add_test ( NAME prefill_fused_q36_test_hostblobs COMMAND prefill_fused_q36_test "--only=Q4_K / Q5_K" --no-ref --chunks=2048 --host-blobs=1 --expect-fallback ) 380set_tests_properties ( prefill_fused_q36_test_hostblobs PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ) 381# the opt-in STRATA_PF_FUSED_Q2N=1 on its own (the test leaves STRATA_PF_FUSED unset): the native Q2_0 pack's Q2_0 / Q2_0 382# layers on sm_80+ (77 below sm_80 and without a card) 383add_test ( NAME prefill_fused_iq_test_q2n COMMAND prefill_fused_iq_test "--only=Q2_0 / Q2_0" --unset-pf-fused ) 384set_tests_properties ( prefill_fused_iq_test_q2n PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_Q2N=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 385# the Turing set (STRATA_PF_FUSED_SM75=1): the canonical Q2_0 pair and the i-quant pairs with kernels on sm_75, against the reference and the int8 model with the edge shapes. 386# 77 on any card that is not a compute capability 7.5 one and does not emulate it (STRATA_EMULATE_CC=75 on a bigger card, with a build whose device code has PTX for sm_75) 387add_test ( NAME prefill_fused_iq_test_sm75 COMMAND prefill_fused_iq_test --turing --edge --no-timing ) 388set_tests_properties ( prefill_fused_iq_test_sm75 PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_SM75=1" SKIP_RETURN_CODE 77 TIMEOUT 900 ) 389# the opt-in STRATA_PF_FUSED_NT=256 kernels (256 threads, two blocks a multiprocessor, two-pass weight loads) against the 390# same references; the batches of the test reach them through the Batch overload of experts_native (77 below sm_80) 391add_test ( NAME prefill_fused_iq_test_nt256 COMMAND prefill_fused_iq_test ) 392set_tests_properties ( prefill_fused_iq_test_nt256 PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_NT=256" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 393# the opt-in STRATA_PF_FUSED_F16=1 (f16 mma, rounding level) and STRATA_PF_FUSED_WS=1 (warp-specialized, the same F16 products; 394# about 101 KB of shared memory at its defaults, more than an sm_86 / sm_89 / sm_120 card's 99 KB, so it is set up on 395# sm_80 and sm_90 cards and the test skips (77) elsewhere) 396add_test ( NAME prefill_fused_iq_test_f16 COMMAND prefill_fused_iq_test ) 397set_tests_properties ( prefill_fused_iq_test_f16 PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_F16=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 398add_test ( NAME prefill_fused_iq_test_ws COMMAND prefill_fused_iq_test ) 399set_tests_properties ( prefill_fused_iq_test_ws PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_WS=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 400# the opt-in STRATA_PF_FUSED_Q50=1 (phase 4 step 1): UD-IQ4_XS v31's Q5_0 down layers on the native kernels, against the reference 401# (this build has no Q5_0 MMQ), with the tails and tile boundaries the test adds for every Q5_0 pair (77 below sm_80) 402add_test ( NAME prefill_fused_iq_test_q50 COMMAND prefill_fused_iq_test "--only=Q5_0" --no-timing ) 403set_tests_properties ( prefill_fused_iq_test_q50 PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_Q50=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 404# a launch whose expert blobs are not in device memory takes the unstaged kernel instead of ending the process (timing part only: one layer of 2,048 tokens, S20_NOMMQ because MMQ does not read host blobs) 405add_test ( NAME prefill_fused_iq_test_hostblobs COMMAND prefill_fused_iq_test "--only=IQ3_S / IQ4_NL" --no-ref --chunks=2048 --host-blobs=1 --expect-fallback ) 406set_tests_properties ( prefill_fused_iq_test_hostblobs PROPERTIES ENVIRONMENT "S20_NOMMQ=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 407# the opt-in STRATA_PF_FUSED_KQ=1 (phase 4): UD-Q4_K_XL's Q4_K / Q5_K gate/up with Q5_1 / Q8_0 down on the native kernels, against the 408# reference and the int8 model at every shape (--edge), MMQ's K-quant library alongside (STRATA_MMQ_KQ=1; 77 below sm_80) 409add_test ( NAME prefill_fused_iq_test_kq COMMAND prefill_fused_iq_test "--only=K / Q" --edge --no-timing ) 410set_tests_properties ( prefill_fused_iq_test_kq PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_KQ=1;STRATA_MMQ_KQ=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 411# the weight-staging kernels of UD-Q4_K_XL's pairs (Q5_1 and Q8_0 downs) against the unstaged kernel: the same experts and routing run with device blobs (staged) 412# and host-mapped blobs (the unstaged fallback), every output bit equal (tails, a tile boundary and a 2,048-token chunk; 77 below sm_80) 413add_test ( NAME prefill_fused_iq_test_kqbits COMMAND prefill_fused_iq_test "--only=K / Q" --bits-staged ) 414set_tests_properties ( prefill_fused_iq_test_kqbits PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_KQ=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 415# the opt-in STRATA_PF_FUSED_Q8D=1 (phase 4): the pinned UD-IQ4_XS's IQ3_S / Q8_0 and IQ4_XS / Q8_0 layers on the native kernels, against the 416# reference, the int8 model and MMQ at every shape (--edge; 77 below sm_80) 417add_test ( NAME prefill_fused_iq_test_q8d COMMAND prefill_fused_iq_test "--only=S / Q8_0" --edge --no-timing ) 418set_tests_properties ( prefill_fused_iq_test_q8d PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_Q8D=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 419# the opt-in STRATA_PF_FUSED_Q8GU=1 (phase 4): the Q8_0 set's Q8_0 / Q8_0 layers on the native kernels, against the reference, the int8 420# model and MMQ at every shape (--edge; 77 below sm_80) 421add_test ( NAME prefill_fused_iq_test_q8gu COMMAND prefill_fused_iq_test "--only=Q8_0 / Q8_0" --edge --no-timing ) 422set_tests_properties ( prefill_fused_iq_test_q8gu PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_Q8GU=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 423# the opt-in STRATA_PF_FUSED_Q6K=1 (phase 4): UD-Q6_K_XL's Q6_K gate/up with a Q8_0 down on the native kernels, against the reference, the 424# int8 model and MMQ's K-quant library (STRATA_MMQ_KQ=1) at every shape (--edge; 77 below sm_80) 425add_test ( NAME prefill_fused_iq_test_q6k COMMAND prefill_fused_iq_test "--only=Q6_K + Q8_0" --edge --no-timing ) 426set_tests_properties ( prefill_fused_iq_test_q6k PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_Q6K=1;STRATA_MMQ_KQ=1" SKIP_RETURN_CODE 77 TIMEOUT 600 ) 427# the opt-in STRATA_PF_FUSED_TQ=1 (phase 4): Gyro-S's TQK6 / TQK7 and Gyro-M's TQ2_T / TQ2_T layers on the native kernels, against a reference 428# from the format definition (fp16 codebook), the int8 model (the int8 codebook) and the overlay's trellis MMQ at every shape (--edge; 77 below sm_80) 429add_test ( NAME prefill_fused_iq_test_tq COMMAND prefill_fused_iq_test "--only=+ T" --edge --no-timing ) 430set_tests_properties ( prefill_fused_iq_test_tq PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_TQ=1" SKIP_RETURN_CODE 77 TIMEOUT 900 ) 431# the same pairs as Hadamard-folded experts (the Gyro packs' form): the gate/up input and H rotated per 128 values with random signs; the 432# fused path's H rotation (set_down_rotation) against the host-side rotation of the reference and MMQ with its H rotated on the device 433add_test ( NAME prefill_fused_iq_test_tqh COMMAND prefill_fused_iq_test "--only=+ T" --folded --edge --no-timing ) 434set_tests_properties ( prefill_fused_iq_test_tqh PROPERTIES ENVIRONMENT "STRATA_PF_FUSED_TQ=1" SKIP_RETURN_CODE 77 TIMEOUT 900 ) 435# NVFP4 / NVFP4 (ModelOpt packs) on the native kernels: weights decoded from the 36-byte blocks, the blob's tail scales on the FP32 products; edge shapes too 436add_test ( NAME prefill_fused_iq_test_nvfp4 COMMAND prefill_fused_iq_test "--only=NVFP4" --edge ) 437set_tests_properties ( prefill_fused_iq_test_nvfp4 PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 900 ) 438endif () 439if ( STRATA_BUILD_TESTSAND STRATA_MMQ) # (P4-SPLIT: MMQ's own tests, below too) 440# the MoE input quantized per token and scattered to its rows (mmq::quantize_scatter) against the per-row 441# gather: the same q8_1 bytes for every MMQ layout (--bench: both at 2K, 8K and 32K tokens) 442# the Unsloth v3.1 sets' expert formats through MMQ (Q5_0 down only in a STRATA_ORCA_Q4KS_MMQ build), and --bench 443add_executable ( prefill_mmq_v31_test tests/cuda/prefill_mmq_v31_test.cpp ) 444target_link_libraries ( prefill_mmq_v31_test PRIVATE strata_mmq strata_kernels ggml-base ${ _strata_gpu_blas_target } ${ _strata_gpu_runtime_target }) 445add_test ( NAME prefill_mmq_v31_test COMMAND prefill_mmq_v31_test ) 446set_tests_properties ( prefill_mmq_v31_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 300 ) 447add_executable ( prefill_mmq_scatter_test tests/cuda/prefill_mmq_scatter_test.cpp ) 448target_link_libraries ( prefill_mmq_scatter_test PRIVATE strata_mmq ggml-base ${ _strata_gpu_runtime_target }) 449add_test ( NAME prefill_mmq_scatter_test COMMAND prefill_mmq_scatter_test ) 450set_tests_properties ( prefill_mmq_scatter_test PROPERTIES TIMEOUT 120 ) 451if ( STRATA_EXPERIMENTAL_SM60) 452# mmq::swiglu_quant: swiglu + the down product's q8_1 rows in one kernel against the two, byte for byte 453add_executable ( prefill_swiglu_quant_test tests/cuda/prefill_swiglu_quant_test.cpp ) 454target_link_libraries ( prefill_swiglu_quant_test PRIVATE strata_mmq ggml-base ${ _strata_gpu_runtime_target }) 455add_test ( NAME prefill_swiglu_quant_test COMMAND prefill_swiglu_quant_test ) 456set_tests_properties ( prefill_swiglu_quant_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 120 ) 457# the weight-stationary experts (STRATA_MMQ_WS) against the per-group MMQ, byte for byte, on random experts; the 458# verdict is given on a compute capability 6.0 card only (77 elsewhere) 459add_executable ( prefill_ws_parity_test tests/cuda/prefill_ws_parity_test.cpp ) 460target_link_libraries ( prefill_ws_parity_test PRIVATE strata_mmq ggml-base ${ _strata_gpu_runtime_target }) 461add_test ( NAME prefill_ws_parity_test COMMAND prefill_ws_parity_test ) 462set_tests_properties ( prefill_ws_parity_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ) 463endif () 464endif () 465if ( STRATA_BUILD_TESTSAND STRATA_MMQAND NOT STRATA_HIP_GFX906) 466# STRATA_IQ4_W4A8: the IQ4 W4A8 expert kernel against MMQ, bit for bit, on the group buffers and (with 467# STRATA_MMQ_TAB) the pointer table (exit 77 without a card or off sm_80..sm_88; gfx906: a stub, no test) 468add_executable ( prefill_iq4_w4a8_test tests/cuda/prefill_iq4_w4a8_test.cu ) 469target_link_libraries ( prefill_iq4_w4a8_test PRIVATE strata_mmq ggml-base ${ _strata_gpu_runtime_target }) 470add_test ( NAME prefill_iq4_w4a8_test COMMAND prefill_iq4_w4a8_test ) 471set_tests_properties ( prefill_iq4_w4a8_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 300 ) 472endif () 473if ( STRATA_BUILD_TESTSAND _strata_mmq_tab_on) 474# STRATA_MMQ_DIRECT: the pointer-table MMQ bit for bit against the gathered MMQ (exit 77 below sm_80) 475add_executable ( prefill_mmq_tab_test tests/cuda/prefill_mmq_tab_test.cu ) 476target_link_libraries ( prefill_mmq_tab_test PRIVATE strata_mmq ggml-base ${ _strata_gpu_runtime_target }) 477add_test ( NAME prefill_mmq_tab_test COMMAND prefill_mmq_tab_test ) 478set_tests_properties ( prefill_mmq_tab_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ) 479endif () 480if ( STRATA_BUILD_TESTSAND STRATA_MMQAND STRATA_MMQ_KQUANTS) 481# the UD-Q4_K_XL expert formats through MMQ against ggml's dequantized weights (synthetic, a few seconds) 482add_executable ( prefill_mmq_kquant_test tests/cuda/prefill_mmq_kquant_test.cpp ) 483target_link_libraries ( prefill_mmq_kquant_test PRIVATE strata_mmq ggml-base ${ _strata_gpu_runtime_target }) 484add_test ( NAME prefill_mmq_kquant_test COMMAND prefill_mmq_kquant_test ) 485# the K-quant MMQ runs when STRATA_MMQ_KQ=1 (the engine's default on NVIDIA 8.0+ and Linux gfx12; see the option above), and on CUDA it is strata_kq next to the test 486set_tests_properties ( prefill_mmq_kquant_test PROPERTIES TIMEOUT 120 ENVIRONMENT STRATA_MMQ_KQ=1 ) 487endif () 488# the NVFP4 expert products (w4a8 / w4a4, STRATA_PREFILL_NVFP4) against a double-precision reference 489if ( STRATA_MMQAND CMAKE_SYSTEM_PROCESSORMATCHES "^(x86_64|AMD64|amd64|i[3-6]86) $ " ) # its FP16 rounding helper is the x86 F16C intrinsics: not built on aarch64 490add_executable ( mmq_nvfp4_parity src/prefill/mmq_nvfp4_parity.cpp ) 491target_link_libraries ( mmq_nvfp4_parity PRIVATE strata_mmq ggml-base CUDA::cudart ) 492if ( NOT MSVC) # GCC/Clang need the target flag 493target_compile_options ( mmq_nvfp4_parity PRIVATE $ < $ <COMPILE_LANGUAGE:CXX>:-mf16c> ) 494endif () 495endif () 496# the routed-expert products (MMQ) timed at the prompt path's shapes (16 experts a launch) 497if ( STRATA_MMQ) 498add_executable ( lat_mmq_bench src/prefill/lat_mmq_bench.cpp ) 499# latent D projections on partial tiles and identical rows 500add_executable ( latent_dense_tail_test src/prefill/latent_dense_tail_test.cpp ) 501target_link_libraries ( latent_dense_tail_test PRIVATE strata_mmq strata_kernels ggml-base CUDA::cudart ) 502target_include_directories ( latent_dense_tail_test PRIVATE include ) 503# one q3k expert through the verified MMQ products: the target the fused Q3_K dot must match 504add_executable ( lat_fused_q3k_test src/prefill/lat_fused_q3k_test.cpp ) 505target_link_libraries ( lat_fused_q3k_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 506target_include_directories ( lat_fused_q3k_test PRIVATE include ) 507# M1 of the q3k latent A stage: the down half against native_expert_grouped's own down (one unit test) 508add_executable ( lat_q3k_down_test src/prefill/lat_q3k_down_test.cpp ) 509target_link_libraries ( lat_q3k_down_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 510target_include_directories ( lat_q3k_down_test PRIVATE include ) 511# M2a: the Q3_K gate/up half against a double-precision host dequantization (+ the per-super-block decode gate) 512add_executable ( lat_q3k_gu_test src/prefill/lat_q3k_gu_test.cpp ) 513target_link_libraries ( lat_q3k_gu_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 514target_include_directories ( lat_q3k_gu_test PRIVATE include ) 515# M2b: SwiGLU + q8_1 of H against the engine's own quantizer rule on the host 516add_executable ( lat_q3k_swiglu_test src/prefill/lat_q3k_swiglu_test.cpp ) 517target_link_libraries ( lat_q3k_swiglu_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 518target_include_directories ( lat_q3k_swiglu_test PRIVATE include ) 519# M2c step 1: the gu half on the down half's four shapes (mine vs native gate/up only) 520add_executable ( lat_q3k_gu_shape_test src/prefill/lat_q3k_gu_shape_test.cpp ) 521target_link_libraries ( lat_q3k_gu_shape_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 522target_include_directories ( lat_q3k_gu_shape_test PRIVATE include ) 523# M3: the fused A stage against the serial chain (memcmp) and against native's whole step, four shapes 524add_executable ( lat_q3k_fused_test src/prefill/lat_q3k_fused_test.cpp ) 525add_executable ( lat_cache_test src/prefill/lat_cache_test.cpp ) 526target_link_libraries ( lat_cache_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 527target_include_directories ( lat_cache_test PRIVATE include ) 528target_link_libraries ( lat_q3k_fused_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 529target_include_directories ( lat_q3k_fused_test PRIVATE include ) 530# M3b: explicit per-group counts (nullptr = the old starts-derived path), scrambled starts, fused == serial 531add_executable ( lat_q3k_counts_test src/prefill/lat_q3k_counts_test.cpp ) 532target_link_libraries ( lat_q3k_counts_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 533target_include_directories ( lat_q3k_counts_test PRIVATE include ) 534# M4's unit gate: ent_tok / ent_dst (native_expert_grouped's two entry maps) 535add_executable ( lat_q3k_maps_test src/prefill/lat_q3k_maps_test.cpp ) 536target_link_libraries ( lat_q3k_maps_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 537target_include_directories ( lat_q3k_maps_test PRIVATE include ) 538# the engine's real A-stage shape (512 groups, 42450 entries, shared xl rows, non-monotonic off[]) 539add_executable ( lat_q3k_engine_shape_test src/prefill/lat_q3k_engine_shape_test.cpp ) 540target_link_libraries ( lat_q3k_engine_shape_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 541target_include_directories ( lat_q3k_engine_shape_test PRIVATE include ) 542# L2a of the q3k acceptance sheet: one batch of kMaxBatch experts vs one launch a launch, same inputs 543add_executable ( lat_q3k_batch_self_test src/prefill/lat_q3k_batch_self_test.cpp ) 544target_link_libraries ( lat_q3k_batch_self_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 545target_include_directories ( lat_q3k_batch_self_test PRIVATE include ) 546# one group with thousands of rows (the engine's per-expert walk: the blockIdx.z fill is active) 547add_executable ( lat_q3k_onegroup_test src/prefill/lat_q3k_onegroup_test.cpp ) 548target_link_libraries ( lat_q3k_onegroup_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 549target_include_directories ( lat_q3k_onegroup_test PRIVATE include ) 550# the v5 kernel with the q3k decode, against the frozen chain (memcmp, two shapes) 551add_executable ( lat_q3k_fusedv5_test src/prefill/lat_q3k_fusedv5_test.cpp ) 552target_link_libraries ( lat_q3k_fusedv5_test PRIVATE strata_mmq strata_kernels strata_kernels_cpu ggml-base CUDA::cudart ) 553target_include_directories ( lat_q3k_fusedv5_test PRIVATE include ) 554# the latent A stage's per-layer row tables (host only, no CUDA) 555add_executable ( lat_tables_test src/prefill/lat_tables_test.cpp ) 556target_include_directories ( lat_tables_test PRIVATE include ) 557target_link_libraries ( lat_mmq_bench PRIVATE strata_mmq ggml-base CUDA::cudart ) 558add_executable ( mmq_expert_bench src/prefill/mmq_expert_bench.cpp ) 559target_link_libraries ( mmq_expert_bench PRIVATE strata_mmq ggml-base CUDA::cudart ) 560endif () 561endmacro () 562 563# the CUDA local-memory spill check of the kernel libraries (cuobjdump) 564macro ( strata_cuda_spill_guard ) 565if ( STRATA_ENABLE_CUDAAND STRATA_BUILD_TESTSAND NOT STRATA_ENABLE_HIPAND NOT STRATA_HIP_GFX906) 566find_package ( Python3 QUIET COMPONENTS Interpreter ) 567if ( Python3_Interpreter_FOUND) 568set ( _strata_spill_libs ) 569foreach ( _t strata_kernels strata_core strata_engine strata_prefill strata_qwen35 strata_mmq strata_pf_own strata_mmq_w4a4 strata_kq) 570if ( TARGET ${ _t }) 571list ( APPEND _strata_spill_libs $ <TARGET_FILE: ${ _t } > ) 572endif () 573endforeach () 574add_test ( NAME cuda_spill_guard COMMAND ${ Python3_EXECUTABLE } ${ CMAKE_CURRENT_SOURCE_DIR } /tools/check_cuda_spills.py 575--cuobjdump ${ CUDAToolkit_BIN_DIR } /cuobjdump ${ CMAKE_EXECUTABLE_SUFFIX } ${ _strata_spill_libs }) 576set_tests_properties ( cuda_spill_guard PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ) 577if ( NOT WIN32) # its stand-in demanglers are sh scripts 578add_test ( NAME check_cuda_spills_unit COMMAND ${ Python3_EXECUTABLE } -m unittest tools.test_check_cuda_spills 579WORKING_DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR }) 580endif () 581else () 582message ( STATUS "strata: no python3 - the cuda_spill_guard test is NOT registered" ) 583endif () 584endif () 585endmacro ()