okami.mom/strata

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

albedocmake: strata_kernels links strata_kernels_cpu (iq_kernels.cu reads the latent colscale table from expert_layout.cpp; strata-q36ref failed to link)a4af4df61

main
96.6 KiB1335 linesraw
1# cmake/strata_gpu_engine.cmake - the GPU engine shared by the CUDA and HIP builds.
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# the GPU engine of the CUDA and HIP builds (strata_core, strata_kernels, strata_prefill, strata_engine, strata, the Qwen3.6 engine and their tests): shared by both backends
7macro(strata_gpu_engine)
8if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)
9  add_library(strata_core STATIC src/core/device.cu src/core/pinned.cu src/platform/memory.cpp src/platform/io_priority.cpp src/core/graph.cpp src/core/weights.cpp
10                               src/core/layout.cpp)
11  target_include_directories(strata_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
12  # the DFlash2 drafter (src/core/dflash2.cpp, src/kernels/cuda/dflash2.cu) exists in the CUDA and HIP builds; the Metal and SYCL builds compile without it
13  target_compile_definitions(strata_core PUBLIC STRATA_HAVE_DFLASH2=1)
14  if(STRATA_ENABLE_CUDA AND STRATA_EXPERIMENTAL_SM60)
15    # the runtime device check (src/core/device.cu) admits the cards this build was made for (#236)
16    target_compile_definitions(strata_core PRIVATE STRATA_EXPERIMENTAL_SM60=1)
17  endif()
18  # The selected runtime is PUBLIC because graph.cpp is a HOST translation unit that calls cudaGraphLaunch and
19  # cudaEventQuery: the .cu sources get cudart through the CUDA language rules, a .cpp does not, and the
20  # linker error ("unresolved external symbol cudaGraphInstantiate") names the function rather than the cause.
21  target_link_libraries(strata_core PUBLIC strata_plan strata_warnings ${_strata_gpu_runtime_target})
22
23  add_executable(strata-device src/core/device_main.cpp)
24  target_link_libraries(strata-device PRIVATE strata_core)
25
26  add_executable(strata-load src/core/load_main.cpp)
27  target_link_libraries(strata-load PRIVATE strata_core strata_kernels)
28
29  add_executable(strata-concurrent src/core/concurrent_main.cpp)
30  target_include_directories(strata-concurrent PRIVATE ${_strata_gpu_include_directories})
31  target_link_libraries(strata-concurrent PRIVATE strata_core strata_kernels ${_strata_gpu_runtime_target})
32
33  add_executable(strata-overlap src/core/overlap_main.cpp)
34  # a .cpp that calls cudaMemcpyAsync itself needs the toolkit headers and cudart explicitly
35  target_include_directories(strata-overlap PRIVATE ${_strata_gpu_include_directories})
36  target_link_libraries(strata-overlap PRIVATE strata_core strata_kernels ${_strata_gpu_runtime_target})
37
38  # The load test needs the 34 GB artifact, so it is registered ONLY where that artifact exists.  A test that
39  # silently skips is a test that stops running; an absent registration is visible in the configure output.
40  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/pack/full/experts.bin)
41    add_test(NAME expert_arena_load
42             COMMAND strata-load --file ${CMAKE_CURRENT_SOURCE_DIR}/pack/full/experts.bin --layers 1)
43    set_tests_properties(expert_arena_load PROPERTIES PASS_REGULAR_EXPRESSION "per-layer checksums")
44  else()
45    message(STATUS "strata: pack/full/experts.bin absent - the expert arena load test is NOT registered")
46  endif()
47
48  # ---- strata_kernels (P2.S2) ----
49  # Naive first, each with a parity test against a reference that was itself validated against ggml.  The
50  # kernels link `strata_artifact` for the scalar dequantizers, because using the VALIDATED scalar path as the
51  # reference is the whole point - a kernel checked against another copy of itself proves nothing.
52  add_library(strata_kernels STATIC src/kernels/cuda/dequant_s2.cu src/kernels/cuda/s2_gemv.cu
53                          src/kernels/cuda/s_gemv.cu
54                          src/kernels/cuda/s_gemv_pair.cu
55                          src/kernels/cuda/s2_gemv_quads.cu
56                          src/kernels/cuda/s2_gemv_fast.cu
57                          src/kernels/cuda/router_top10.cu
58                          src/kernels/cuda/quantize_act.cu
59                          src/kernels/cuda/rope.cu
60                          src/kernels/cuda/sampler.cu
61                          src/kernels/cuda/s2_gemv_q8.cu
62    src/kernels/cuda/s2_expert_grouped.cu
63                          src/kernels/cuda/shared_expert.cu
64                          src/kernels/cuda/gr.cu
65                          src/kernels/cuda/gdn.cu
66                          src/kernels/cuda/qsa.cu
67                          src/kernels/cuda/elementwise.cu
68                          src/kernels/cuda/bf16_gemv.cu
69                          src/kernels/cuda/native_mmvq.cu
70                          src/kernels/cuda/native_bf16.cu
71                          src/kernels/cuda/native_gr_norm.cu
72                          src/kernels/cuda/native_moe.cu
73                          src/kernels/cuda/native_gdn.cu
74                          src/kernels/cuda/native_gr_postops.cu
75                          src/kernels/cuda/native_router.cu
76                          src/kernels/cuda/route_prior.cu
77                          src/kernels/cuda/native_gdn_preprocess.cu
78                          src/kernels/cuda/native_qsa.cu
79                          src/kernels/cuda/native_rope.cu
80                          src/kernels/cuda/native_ple_postops.cu
81                          src/kernels/cuda/native_flash_attn.cu
82                          src/kernels/cuda/native_qsa_indexer.cu
83                          src/kernels/cuda/native_qsa_score.cu
84                          src/kernels/cuda/ple.cu
85                          src/kernels/cuda/kv_q8.cu
86                          src/kernels/cuda/scr_move.cu
87                          src/kernels/cuda/kv_stream.cu
88                          src/kernels/cuda/kv_q4.cu
89                          src/kernels/cuda/fused_gr.cu
90                          src/kernels/cuda/cvec.cu
91                          src/kernels/cuda/qsa_decode_attn.cu
92                          src/kernels/cuda/qsa_prompt_attn.cu
93                          src/kernels/cuda/fused_gdn.cu
94                          src/kernels/cuda/dequant_bf16.cu
95                          src/kernels/cuda/qsa_select.cu
96                          src/kernels/cuda/qsa_pattn.cu
97                          src/kernels/cuda/verify_kernels.cu
98                          src/kernels/cuda/dflash2.cu
99                          src/kernels/cuda/iq_kernels.cu
100                          src/kernels/cuda/probe_q8gpu.cu
101                          src/kernels/cuda/latent.cu
102                          src/kernels/ngram.cpp
103                          src/ngram/ple_reader.cpp
104                          src/platform/direct_file.cpp)
105  # (strata_kernels_cpu: iq_kernels.cu reads the latent colscale table, lat_gu_colscale_host, kept in expert_layout.cpp)
106  target_link_libraries(strata_kernels PUBLIC strata_core strata_artifact strata_kernels_cpu)
107  # Exact gfx1100 prompt scorer (PR1825 method port): optional standalone test,
108  # also available where the published source omits tests/.
109  option(STRATA_PARITY_GFX1100_QSA_SCORES "Build the exact gfx1100 QSA score/ID check" OFF)
110  if(STRATA_ENABLE_HIP AND (STRATA_BUILD_TESTS OR STRATA_PARITY_GFX1100_QSA_SCORES))
111    set_source_files_properties(src/kernels/cuda/qsa_scores_gfx1100_test.cu
112                                src/kernels/qsa_scores_gfx1100_parity.cpp PROPERTIES LANGUAGE HIP)
113    add_executable(qsa_scores_gfx1100_parity src/kernels/qsa_scores_gfx1100_parity.cpp
114                                           src/kernels/cuda/qsa_scores_gfx1100_test.cu)
115    target_include_directories(qsa_scores_gfx1100_parity PRIVATE ${_strata_gpu_include_directories})
116    target_link_libraries(qsa_scores_gfx1100_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
117    enable_testing()
118    add_test(NAME qsa_scores_gfx1100_parity COMMAND qsa_scores_gfx1100_parity --full)
119    set_tests_properties(qsa_scores_gfx1100_parity PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 180
120      ENVIRONMENT "STRATA_SCORES_THREAD=1;STRATA_SCORES_THREAD_TRACE=1")
121  endif()
122  # perf-review D-1: the tensor-core prompt attention vs the FP32 kernel and FP64 (GPU, synthetic, no model); with
123  # the tests, or alone with -DSTRATA_PARITY_PROMPT_ATTN=ON.  CUDA only: HIP compiles the tensor-core kernel out.
124  if((STRATA_BUILD_TESTS OR STRATA_PARITY_PROMPT_ATTN) AND STRATA_ENABLE_CUDA)
125    add_executable(qsa_prompt_attn_parity src/kernels/qsa_prompt_attn_parity.cpp)
126    target_include_directories(qsa_prompt_attn_parity PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
127    target_link_libraries(qsa_prompt_attn_parity PRIVATE strata_kernels CUDA::cudart)
128  endif()
129  # PR #3943: STRATA_PATTN_SM60's score and value kernels against the decode kernels' output (the Daily's chunk kernel and
130  # the merge), bitwise, on random int8 K/V (GPU, synthetic, no model).  Only in the experimental sm_60 build; it skips
131  # (77) on a build without the kernels.
132  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA AND STRATA_EXPERIMENTAL_SM60)
133    add_executable(qsa_pattn_parity src/kernels/qsa_pattn_parity.cpp)
134    target_include_directories(qsa_pattn_parity PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
135    target_link_libraries(qsa_pattn_parity PRIVATE strata_kernels CUDA::cudart)
136    add_test(NAME qsa_pattn_parity COMMAND qsa_pattn_parity)
137    set_tests_properties(qsa_pattn_parity PROPERTIES SKIP_RETURN_CODE 77)
138  endif()
139  # PR #3820: STRATA_SELECT_LONG's multi-CTA top-k and shuffle-free decode scorer against qsa_block_topk and
140  # qsa_block_scores, bitwise, on random scores (GPU, synthetic, no model).  The switches force the new kernels on any
141  # card; the "n3" case fixes three CTAs a query.  Only in the experimental sm_60 build (skips with 77 otherwise).
142  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA AND STRATA_EXPERIMENTAL_SM60)
143    add_executable(qsa_select_long_parity src/kernels/qsa_select_long_parity.cpp)
144    target_include_directories(qsa_select_long_parity PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
145    target_link_libraries(qsa_select_long_parity PRIVATE strata_kernels CUDA::cudart)
146    add_test(NAME qsa_select_long_parity COMMAND qsa_select_long_parity)
147    add_test(NAME qsa_select_long_parity_n3 COMMAND qsa_select_long_parity)
148    set_tests_properties(qsa_select_long_parity qsa_select_long_parity_n3 PROPERTIES SKIP_RETURN_CODE 77)
149    set_tests_properties(qsa_select_long_parity PROPERTIES ENVIRONMENT "STRATA_SCORES_DX=1;STRATA_TOPK_MULTI=1")
150    set_tests_properties(qsa_select_long_parity_n3 PROPERTIES ENVIRONMENT "STRATA_SCORES_DX=1;STRATA_TOPK_MULTI=1;STRATA_TOPK_MULTI_N=3")
151  endif()
152  # PR #600: the Volta (sm_70) prompt attention's latency pipeline against the FP32 kernel it replaces.  Only in the
153  # experimental sm_60/sm_70 build, where prompt_attn_v70_kernel is compiled in.
154  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA AND STRATA_EXPERIMENTAL_SM60)
155    add_executable(qsa_prompt_attn_sm70_bench bench/qsa_prompt_attn_sm70_bench.cpp)
156    target_include_directories(qsa_prompt_attn_sm70_bench PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
157    target_link_libraries(qsa_prompt_attn_sm70_bench PRIVATE strata_kernels CUDA::cudart)
158  endif()
159  # #512: the top-k's active-block bound (Turing's dispatch, forced on any card by STRATA_TOPK_ACTIVE_ANY) against
160  # the capacity rule, selected ids bitwise
161  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA)
162    add_executable(qsa_topk_active_parity src/kernels/qsa_topk_active_parity.cpp)
163    target_include_directories(qsa_topk_active_parity PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
164    target_link_libraries(qsa_topk_active_parity PRIVATE strata_kernels CUDA::cudart)
165    add_test(NAME qsa_topk_active_parity COMMAND qsa_topk_active_parity)
166    set_tests_properties(qsa_topk_active_parity PROPERTIES SKIP_RETURN_CODE 77)
167    # STRATA_QSA_SLOTS: a batch window's scores, top-k and attention as one launch over rows of different slots
168    # against one call per row, bitwise (synthetic, no model)
169    add_executable(qsa_slots_parity src/kernels/qsa_slots_parity.cpp)
170    target_include_directories(qsa_slots_parity PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
171    target_link_libraries(qsa_slots_parity PRIVATE strata_kernels CUDA::cudart)
172    add_test(NAME qsa_slots_parity COMMAND qsa_slots_parity)
173    add_test(NAME qsa_slots_parity_lanecell COMMAND qsa_slots_parity)
174    set_tests_properties(qsa_slots_parity qsa_slots_parity_lanecell PROPERTIES SKIP_RETURN_CODE 77)
175    set_tests_properties(qsa_slots_parity_lanecell PROPERTIES ENVIRONMENT "STRATA_ATTN_LANECELL=1")
176    # fork: the Daily's decode attention (STRATA_ATTN_DAILY=1: PR #540's chunk kernel on every card and the bounded
177    # merge) against upstream's kernels, bitwise; the production entries checked with the variable off and on
178    add_executable(qsa_merge_daily_parity src/kernels/qsa_merge_daily_parity.cpp)
179    target_include_directories(qsa_merge_daily_parity PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
180    target_link_libraries(qsa_merge_daily_parity PRIVATE strata_kernels CUDA::cudart)
181    add_test(NAME qsa_merge_daily_parity_default COMMAND qsa_merge_daily_parity)
182    add_test(NAME qsa_merge_daily_parity_daily COMMAND qsa_merge_daily_parity)
183    set_tests_properties(qsa_merge_daily_parity_default PROPERTIES ENVIRONMENT "STRATA_ATTN_DAILY=0"
184                         SKIP_RETURN_CODE 77)
185    set_tests_properties(qsa_merge_daily_parity_daily PROPERTIES ENVIRONMENT "STRATA_ATTN_DAILY=1"
186                         SKIP_RETURN_CODE 77)
187    # the prompt path's block scores on the thread-per-head kernel (Turing) against the warp kernel, bitwise
188    add_executable(qsa_scores_parity src/kernels/qsa_scores_parity.cpp)
189    target_include_directories(qsa_scores_parity PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
190    target_link_libraries(qsa_scores_parity PRIVATE strata_kernels CUDA::cudart)
191    add_test(NAME qsa_scores_parity COMMAND qsa_scores_parity)
192    set_tests_properties(qsa_scores_parity PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT "STRATA_SCORES_THREAD=1")
193    # STRATA_SELECT_TWO_PASS: the two-pass prompt scores' selection against the tensor-core scorer's, ids and the
194    # scored-again blocks bitwise (sm_80+, synthetic, no model)
195    add_executable(qsa_two_pass_parity src/kernels/qsa_two_pass_parity.cpp)
196    target_include_directories(qsa_two_pass_parity PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
197    target_link_libraries(qsa_two_pass_parity PRIVATE strata_kernels CUDA::cudart)
198    add_test(NAME qsa_two_pass_parity COMMAND qsa_two_pass_parity)
199    set_tests_properties(qsa_two_pass_parity PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT "STRATA_SELECT_TWO_PASS=1")
200  endif()
201  # QSAROWS (docs/QSAROWS.md): what the T rows of a verification window cost in a QSA layer's decode kernels at a long
202  # context (block scores, top-k, attention over each row's selection, indexer append), row by row; GPU, synthetic, no
203  # model.  Not in the default build: `cmake --build <dir> --target qsa_rows_bench`.
204  if(STRATA_ENABLE_CUDA)
205    add_executable(qsa_rows_bench EXCLUDE_FROM_ALL src/kernels/qsa_rows_bench.cpp)
206    target_include_directories(qsa_rows_bench PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
207    target_link_libraries(qsa_rows_bench PRIVATE strata_kernels CUDA::cudart)
208  endif()
209  # the QSA selection (block scores on the warp kernel and the tensor-core one, top-k): a GPU bench with a
210  # scorer-vs-scorer comparison and an FP64 accuracy gate (synthetic, no model); the ctest runs a 32K context under a
211  # 262144-cell capacity (the top-k dispatch follows the capacity) and exits non-zero on a failed gate
212  if((STRATA_BUILD_TESTS OR STRATA_PARITY_PROMPT_ATTN) AND STRATA_ENABLE_HIP)
213    add_executable(qsa_select_bench src/kernels/qsa_select_bench.cpp)
214    set_source_files_properties(src/kernels/qsa_select_bench.cpp PROPERTIES LANGUAGE HIP)
215    target_link_libraries(qsa_select_bench PRIVATE strata_kernels strata_hip_runtime)
216    add_test(NAME qsa_select_bench COMMAND qsa_select_bench 32768 256 3 262144)
217    # the FP32 tiled scorer (STRATA_SELECT_SIMT=1) on HIP: FP64 gate and selections against the warp kernel at 131K
218    add_test(NAME qsa_select_bench_fp32_tiled COMMAND qsa_select_bench 131072 256 3 262144)
219    set_tests_properties(qsa_select_bench_fp32_tiled PROPERTIES ENVIRONMENT "STRATA_SELECT_SIMT=1")
220  endif()
221  # the same on CUDA: the tensor-core scorer (sm_80+) or the FP32 tiled one (below sm_80, and forced on any card by
222  # STRATA_QSA_WARP=1 in the second test) against the warp kernel and FP64, at 32K and 131K
223  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA)
224    add_executable(qsa_select_bench src/kernels/qsa_select_bench.cpp)
225    target_include_directories(qsa_select_bench PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
226    target_link_libraries(qsa_select_bench PRIVATE strata_kernels CUDA::cudart)
227    add_test(NAME qsa_select_bench COMMAND qsa_select_bench 32768 256 3 262144)
228    add_test(NAME qsa_select_bench_fp32_tiled COMMAND qsa_select_bench 131072 256 3 262144)
229    set_tests_properties(qsa_select_bench_fp32_tiled PROPERTIES ENVIRONMENT "STRATA_QSA_WARP=1;STRATA_SELECT_SIMT=1")
230  endif()
231  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA)   # the prompt attention on a recorded selection (STRATA_QSA_DUMP)
232    add_executable(pa_bench tests/cuda/pa_bench.cpp)
233    target_include_directories(pa_bench PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
234    target_link_libraries(pa_bench PRIVATE strata_kernels CUDA::cudart)
235  endif()
236  # plan v0.3 P6: llama.cpp's block layouts and codebook grids for the i-quant formats (MIT, third_party/ggml)
237  target_include_directories(strata_kernels PRIVATE third_party/ggml)
238  # Match the pinned llama.cpp CUDA arithmetic contract for this adapter only.
239  if(STRATA_ENABLE_CUDA)
240    set_source_files_properties(src/kernels/cuda/native_mmvq.cu src/kernels/cuda/native_bf16.cu
241      src/kernels/cuda/native_gr_norm.cu
242      src/kernels/cuda/native_moe.cu
243      src/kernels/cuda/native_gdn.cu
244      src/kernels/cuda/native_gr_postops.cu
245      src/kernels/cuda/native_router.cu
246      src/kernels/cuda/native_gdn_preprocess.cu
247      src/kernels/cuda/native_qsa.cu
248      src/kernels/cuda/native_rope.cu
249      src/kernels/cuda/native_ple_postops.cu
250      src/kernels/cuda/native_flash_attn.cu
251      src/kernels/cuda/native_qsa_indexer.cu
252      src/kernels/cuda/native_qsa_score.cu
253      PROPERTIES COMPILE_OPTIONS "$<IF:$<BOOL:${STRATA_HIP_GFX906}>,,--use_fast_math>")
254  elseif(STRATA_ENABLE_HIP)
255    # Keep Q8_K's multiply and magic-bias rounding as separate FP32 operations on HIP; contraction to an
256    # FMA changes tie results. The embedding gather also relies on separately rounded operations.
257    set_source_files_properties(src/kernels/cuda/elementwise.cu src/kernels/cuda/quantize_act.cu
258      PROPERTIES COMPILE_OPTIONS "-ffp-contract=off")
259  endif()
260
261  set(STRATA_ORACLE_SOURCE_DIR "" CACHE PATH "Pinned llama.cpp source for independent CUDA parity tests")
262  set(STRATA_ORACLE_BUILD_DIR "" CACHE PATH "Matching existing shared llama.cpp build")
263  # This oracle is a CUDA ggml build; do not pull CUDA libraries into a HIP build.
264  if(STRATA_ENABLE_CUDA AND STRATA_ORACLE_SOURCE_DIR AND STRATA_ORACLE_BUILD_DIR)
265    foreach(parity IN ITEMS native_mmvq native_bf16 native_shared native_gr_norm native_moe native_gdn native_gr_postops native_router native_gdn_preprocess native_gdn_pipeline native_qsa native_rope native_ple_postops native_flash_attn native_qsa_indexer native_qsa_score)
266    add_executable(${parity}_parity bench/micro/${parity}_parity.cpp)
267    target_include_directories(${parity}_parity PRIVATE
268      "${STRATA_ORACLE_SOURCE_DIR}/ggml/include" ${_strata_gpu_include_directories})
269    target_compile_definitions(${parity}_parity PRIVATE GGML_SHARED GGML_BACKEND_SHARED)
270    target_link_libraries(${parity}_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
271    foreach(component IN ITEMS ggml ggml-base ggml-cpu ggml-cuda)
272      string(REPLACE "-" "_" variable "STRATA_ORACLE_${component}")
273      find_library(${variable} NAMES ${component} PATHS
274        "${STRATA_ORACLE_BUILD_DIR}/ggml/src" "${STRATA_ORACLE_BUILD_DIR}/ggml/src/${component}"
275        "${STRATA_ORACLE_BUILD_DIR}/bin" NO_DEFAULT_PATH REQUIRED)
276      target_link_libraries(${parity}_parity PRIVATE "${${variable}}")
277    endforeach()
278    add_test(NAME ${parity}_parity COMMAND ${parity}_parity --selftest)
279    if(WIN32)
280      set_tests_properties(${parity}_parity PROPERTIES
281        ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${STRATA_ORACLE_BUILD_DIR}/bin")
282    endif()
283    endforeach()
284  endif()
285
286  # ---- strata_engine (P2.S5) -----------------------------------------------------
287  # The COMPOSED layer lives here and not in `strata_core`, because it calls kernels and `strata_kernels`
288  # already links `strata_core` - putting `gdn_layer` in core would make the two mutually dependent.  A third
289  # library is the honest shape of the dependency graph: core knows about devices and weights, kernels know
290  # about arithmetic, and this one knows the ORDER the arithmetic happens in.
291  add_library(strata_engine STATIC src/core/layer.cpp src/core/session.cpp src/core/expert_source.cpp src/core/remote_experts.cpp
292    src/core/remote_expert_opt.cu
293    src/core/expert_cache.cpp src/core/native_head.cpp src/core/native_dense.cpp src/core/verify.cpp src/core/mtp.cpp src/core/dflash2.cpp
294    src/core/conversation_snapshot.cpp src/core/conversation_state.cpp src/core/conversation_memory.cpp src/core/peer_experts.cpp
295    src/core/arch_defaults.cpp src/core/nv_defaults.cpp src/core/vmm.cpp src/core/conversation_file.cpp)
296  target_include_directories(strata_engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
297  target_link_libraries(strata_engine PUBLIC strata_core strata_kernels strata_kernels_cpu ${_strata_gpu_runtime_target})
298  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA AND NOT STRATA_HIP_GFX906)
299    add_executable(host_graph_launch_test tests/core/host_graph_launch_test.cu)
300    target_include_directories(host_graph_launch_test PRIVATE include)
301    target_link_libraries(host_graph_launch_test PRIVATE CUDA::cudart Threads::Threads)
302    add_test(NAME host_graph_launch_test COMMAND host_graph_launch_test)
303    set_tests_properties(host_graph_launch_test PROPERTIES TIMEOUT 30)
304  endif()
305  if(STRATA_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/exchange_storage_test.cpp")
306    add_executable(exchange_storage_test tests/core/exchange_storage_test.cpp)
307    target_include_directories(exchange_storage_test PRIVATE include)
308    target_link_libraries(exchange_storage_test PRIVATE Threads::Threads)
309    add_test(NAME exchange_storage_test COMMAND exchange_storage_test)
310    set_tests_properties(exchange_storage_test PROPERTIES TIMEOUT 60)
311  endif()
312
313  # available_host_bytes(): MemAvailable, cgroup limits and the operator's --memory-limit-mib cap on fixture directories
314  # - no GPU, no CUDA
315  if(STRATA_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/memory_guard_test.cpp")
316    add_executable(memory_guard_test tests/core/memory_guard_test.cpp src/core/conversation_memory.cpp)
317    target_include_directories(memory_guard_test PRIVATE include)
318    add_test(NAME memory_guard_test COMMAND memory_guard_test)
319    set_tests_properties(memory_guard_test PROPERTIES TIMEOUT 60)
320  endif()
321
322  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/file_expert_source_test.cpp")
323    enable_testing()
324    add_executable(file_expert_source_test tests/core/file_expert_source_test.cpp)
325    target_link_libraries(file_expert_source_test PRIVATE strata_engine)
326    add_test(NAME file_expert_source_test COMMAND file_expert_source_test)
327    set_tests_properties(file_expert_source_test PROPERTIES TIMEOUT 60)
328    add_executable(vmm_test tests/core/vmm_test.cpp)
329    target_link_libraries(vmm_test PRIVATE strata_engine)
330    add_test(NAME vmm_test COMMAND vmm_test)
331    set_tests_properties(vmm_test PROPERTIES TIMEOUT 60)
332    # the elastic K/V's pools when the expert cache cannot give them slots: they grow from new VRAM to a long prompt's
333    # cells and to the whole context, every mapped cell writable (GPU with virtual memory; skips with 77 without one)
334    add_executable(kv_grow_refused_test tests/core/kv_grow_refused_test.cpp)
335    target_link_libraries(kv_grow_refused_test PRIVATE strata_engine)
336    add_test(NAME kv_grow_refused_test COMMAND kv_grow_refused_test)
337    set_tests_properties(kv_grow_refused_test PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77)
338    # The resident RAM mode with a layer split: the copy keeps each stage's lend region, and the experts the
339    # prompt path borrows are served from RAM (the file source reads none of them).  The device calls are
340    # wrapped - conversation_transfer_test's pattern - and `pin = false` keeps the copy pageable, so this
341    # runs on a CPU-only PC.
342    if(NOT STRATA_ENABLE_HIP AND UNIX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
343      add_executable(split_lend_complement_test tests/core/split_lend_complement_test.cpp)
344      target_link_libraries(split_lend_complement_test PRIVATE strata_engine)
345      target_link_options(split_lend_complement_test PRIVATE
346        -Wl,--wrap=cudaMalloc -Wl,--wrap=cudaFree -Wl,--wrap=cudaMemset -Wl,--wrap=cudaMemcpy
347        -Wl,--wrap=cudaMemcpyAsync -Wl,--wrap=cudaStreamSynchronize -Wl,--wrap=cudaDeviceSynchronize
348        -Wl,--wrap=cudaGetLastError -Wl,--wrap=cudaGetDevice -Wl,--wrap=cudaSetDevice
349        -Wl,--wrap=cudaMemGetInfo -Wl,--wrap=cudaHostAlloc -Wl,--wrap=cudaFreeHost)
350      add_test(NAME split_lend_complement_test COMMAND split_lend_complement_test)
351      set_tests_properties(split_lend_complement_test PROPERTIES ENVIRONMENT "CUDA_VISIBLE_DEVICES=-1" TIMEOUT 120)
352    endif()
353  endif()
354  # #477: the learned expert profile (--expert-profile-save): its order and make_profile.py's file format (CPU only)
355  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/expert_profile_save_test.cpp")
356    enable_testing()
357    add_executable(expert_profile_save_test tests/core/expert_profile_save_test.cpp)
358    target_link_libraries(expert_profile_save_test PRIVATE strata_engine)
359    add_test(NAME expert_profile_save_test COMMAND expert_profile_save_test)
360    set_tests_properties(expert_profile_save_test PROPERTIES TIMEOUT 60)
361  endif()
362  # the profile header's version is enforced: a version other than 1 is refused by its number (CPU only)
363  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/expert_profile_version_test.cpp")
364    enable_testing()
365    add_executable(expert_profile_version_test tests/core/expert_profile_version_test.cpp)
366    target_link_libraries(expert_profile_version_test PRIVATE strata_engine)
367    add_test(NAME expert_profile_version_test COMMAND expert_profile_version_test)
368    set_tests_properties(expert_profile_version_test PROPERTIES TIMEOUT 60)
369  endif()
370  if(STRATA_BUILD_TESTS AND STRATA_NATIVE_EXPERTS)
371    # native_experts.txt v2-v4 (the real packs' copies and the per-role shard column) and the arena filled from
372    # synthetic GGUF shards at the real expert dimensions
373    add_executable(expert_layout_test tests/core/expert_layout_test.cpp)
374    target_link_libraries(expert_layout_test PRIVATE strata_engine)
375    add_test(NAME expert_layout_test COMMAND expert_layout_test ${CMAKE_CURRENT_SOURCE_DIR}/tests/data/native_experts)
376    set_tests_properties(expert_layout_test PROPERTIES TIMEOUT 60)
377    # #326: a native pack's BF16 (--compat-bf16) PLE key stays in the arena; a quantized key row loads as before
378    add_executable(native_dense_ple_key_test tests/core/native_dense_ple_key_test.cpp)
379    target_link_libraries(native_dense_ple_key_test PRIVATE strata_engine)
380    add_test(NAME native_dense_ple_key_test COMMAND native_dense_ple_key_test)
381    set_tests_properties(native_dense_ple_key_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
382    # a layer split prices a later stage's projections (with the Q8_0 hyper-connection rows) as `load` allocates them
383    add_executable(native_dense_price_test tests/core/native_dense_price_test.cpp)
384    target_link_libraries(native_dense_price_test PRIVATE strata_engine)
385    add_test(NAME native_dense_price_test COMMAND native_dense_price_test)
386    set_tests_properties(native_dense_price_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
387    # which GGUFs carry the hyper-connection projections as Q8_0 and the default rule STRATA_HC_Q8 follows from it (no device needed)
388    add_executable(native_dense_hc_default_test tests/core/native_dense_hc_default_test.cpp)
389    target_link_libraries(native_dense_hc_default_test PRIVATE strata_engine)
390    add_test(NAME native_dense_hc_default_test COMMAND native_dense_hc_default_test)
391    set_tests_properties(native_dense_hc_default_test PROPERTIES TIMEOUT 60)
392    # #369: per-layer admission on a sized (native pack) cache starts each layer in its own range
393    add_executable(expert_cache_per_layer_test tests/core/expert_cache_per_layer_test.cpp)
394    target_link_libraries(expert_cache_per_layer_test PRIVATE strata_engine)
395    add_test(NAME expert_cache_per_layer_test COMMAND expert_cache_per_layer_test)
396    set_tests_properties(expert_cache_per_layer_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
397    add_executable(expert_cache_segmented_test tests/core/expert_cache_segmented_test.cpp)
398    target_link_libraries(expert_cache_segmented_test PRIVATE strata_engine)
399    add_test(NAME expert_cache_segmented_test COMMAND expert_cache_segmented_test)
400    set_tests_properties(expert_cache_segmented_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
401    # #5708: a failed free-memory query is said with its error, not passed off as "0.00 GiB free" (no device: no GPU needed)
402    add_executable(device_free_error_test tests/core/device_free_error_test.cpp)
403    target_link_libraries(device_free_error_test PRIVATE strata_engine)
404    add_test(NAME device_free_error_test COMMAND device_free_error_test)
405    set_tests_properties(device_free_error_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60
406                         ENVIRONMENT "CUDA_VISIBLE_DEVICES=-1;HIP_VISIBLE_DEVICES=-1")
407    # STRATA_MMQ_DIRECT: slot_guard / slot_room / slot_tail on the uniform and the sized cache, and the default
408    # (no guard) sized layout unchanged
409    add_executable(expert_cache_slot_guard_test tests/core/expert_cache_slot_guard_test.cpp)
410    target_link_libraries(expert_cache_slot_guard_test PRIVATE strata_engine)
411    add_test(NAME expert_cache_slot_guard_test COMMAND expert_cache_slot_guard_test)
412    set_tests_properties(expert_cache_slot_guard_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
413  endif()
414  if(STRATA_BUILD_CONVERSATION_TESTS)
415    add_executable(conversation_snapshot_test src/core/conversation_snapshot_test.cpp)
416    target_link_libraries(conversation_snapshot_test PRIVATE strata_engine)
417    add_test(NAME conversation_snapshot_test COMMAND conversation_snapshot_test)
418    set_tests_properties(conversation_snapshot_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 120)
419    # the same test with a GDN state over 1 MiB and the opt-in background checkpoint copy (STRATA_CKPT_ASYNC=1), alone and with
420    # recent states kept in VRAM (STRATA_CKPT_VRAM_SLOTS): every checkpoint, capture and restore must give the same bytes
421    add_test(NAME conversation_snapshot_test_ckpt_async COMMAND conversation_snapshot_test)
422    set_tests_properties(conversation_snapshot_test_ckpt_async PROPERTIES
423      ENVIRONMENT "STRATA_TEST_BIG_GDN=1;STRATA_CKPT_ASYNC=1" SKIP_RETURN_CODE 77 TIMEOUT 300)
424    add_test(NAME conversation_snapshot_test_ckpt_vram_slots COMMAND conversation_snapshot_test)
425    set_tests_properties(conversation_snapshot_test_ckpt_vram_slots PROPERTIES
426      ENVIRONMENT "STRATA_TEST_BIG_GDN=1;STRATA_CKPT_ASYNC=1;STRATA_CKPT_VRAM_SLOTS=3" SKIP_RETURN_CODE 77 TIMEOUT 300)
427    add_executable(conversation_validation_test src/core/conversation_validation_test.cpp)
428    target_link_libraries(conversation_validation_test PRIVATE strata_engine)
429    add_test(NAME conversation_validation_test COMMAND conversation_validation_test)
430    set_tests_properties(conversation_validation_test PROPERTIES ENVIRONMENT "CUDA_VISIBLE_DEVICES=-1" TIMEOUT 120)
431    if(NOT STRATA_ENABLE_HIP AND UNIX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
432      add_executable(conversation_transfer_test src/core/conversation_validation_test.cpp)
433      target_compile_definitions(conversation_transfer_test PRIVATE CONVERSATION_TEST_TRANSFERS)
434      target_link_options(conversation_transfer_test PRIVATE
435        -Wl,--wrap=cudaMemcpy -Wl,--wrap=cudaMemcpyAsync -Wl,--wrap=cudaStreamSynchronize
436        -Wl,--wrap=cudaGetDevice -Wl,--wrap=cudaStreamCreateWithFlags
437        -Wl,--wrap=cudaDeviceSynchronize -Wl,--wrap=cudaGetLastError)
438      target_link_libraries(conversation_transfer_test PRIVATE strata_engine)
439      add_test(NAME conversation_transfer_test COMMAND conversation_transfer_test)
440      set_tests_properties(conversation_transfer_test PROPERTIES ENVIRONMENT "CUDA_VISIBLE_DEVICES=-1" TIMEOUT 120)
441    endif()
442  endif()
443
444  # `strata generate` (P2.S6).  The FIRST user-facing program: everything under it is a component, and this is
445  # what composes them into a token.  No tokenizer - the prompt arrives as ids - because Gate C1 compares logits
446  # against llama.cpp on the SAME ids and a tokenizer on one side of that comparison is a second variable.
447  # plan v0.3 P5: batched prompt processing (tensor-core GEMMs through cuBLAS).
448  add_library(strata_prefill STATIC src/prefill/gemm.cu src/prefill/kernels.cu src/prefill/prefill.cpp)
449  if(STRATA_ENABLE_HIP)
450    # #313: the RDNA3 WMMA GEMMs include hip_runtime.h: AMD builds only (a CUDA build never sees this file)
451    target_sources(strata_prefill PRIVATE src/prefill/wmma_gemm.cu)
452  endif()
453  target_include_directories(strata_prefill PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${_strata_gpu_include_directories})
454  target_link_libraries(strata_prefill PUBLIC strata_engine ${_strata_gpu_blas_target} ${_strata_gpu_runtime_target})
455  if(STRATA_ENABLE_CUDA)
456    # v100/gdn-chunk: the chunked Volta GDN prompt recurrence.  The dispatch (src/prefill/kernels.cu) is
457    # Volta-only (cc 7.0) and gated on STRATA_EXPERIMENTAL_SM60; the path itself stays opt-in (STRATA_GDN_CHUNK).
458    target_sources(strata_prefill PRIVATE src/prefill/gdn_chunk.cu)
459  endif()
460  if(STRATA_ENABLE_HIP AND STRATA_HIPBLASLT_AVAILABLE)
461    target_compile_definitions(strata_prefill PRIVATE STRATA_HIPBLASLT_AVAILABLE=1)
462    target_link_libraries(strata_prefill PRIVATE roc::hipblaslt)
463
464    add_executable(tune_hipblaslt tools/hip/tune_hipblaslt.cpp)
465    target_link_libraries(tune_hipblaslt PRIVATE hip::host roc::hipblas roc::hipblaslt)
466  endif()
467  if(STRATA_ENABLE_HIP AND STRATA_ROCBLAS_AVAILABLE)
468    # the prompt path's rocBLAS solution table (STRATA_ROCBLAS_TUNING; tools/hip/tune_rocblas makes one)
469    target_compile_definitions(strata_prefill PRIVATE STRATA_ROCBLAS_AVAILABLE=1)
470    target_link_libraries(strata_prefill PRIVATE roc::rocblas)
471
472    add_executable(tune_rocblas tools/hip/tune_rocblas.cpp)
473    target_link_libraries(tune_rocblas PRIVATE hip::host roc::rocblas)
474  endif()
475
476  # the prompt path's K/V append under KV streaming, both ways (the kernel's own stores to the host copy against the
477  # staging pool's DMA, core/kv_host_dma.hpp): host copies, a read-back on another stream and the VRAM slots byte-equal
478  # (GPU, synthetic, no model; skips with 77 without a GPU).  CUDA only: HIP keeps the kernel's stores by default.
479  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA)
480    add_executable(kv_host_dma_parity src/prefill/kv_host_dma_parity.cpp)
481    target_include_directories(kv_host_dma_parity PRIVATE ${_strata_gpu_include_directories})
482    target_link_libraries(kv_host_dma_parity PRIVATE strata_prefill strata_kernels ${_strata_gpu_runtime_target})
483    add_test(NAME kv_host_dma_parity COMMAND kv_host_dma_parity)
484    set_tests_properties(kv_host_dma_parity PROPERTIES SKIP_RETURN_CODE 77)
485  endif()
486
487  # DFlash2 drafter tools (not built by default: cmake --build <dir> --target dflash2_parity dflash2_gemm_bench dflash2_attn_bench): the drafter against
488  # the torch port on a synthetic case (needs the pack and a case file, tools/dflash2/mk_parity_case.py), and the timing of its Q8 GEMM and attention
489  add_executable(dflash2_parity EXCLUDE_FROM_ALL src/core/dflash2_parity.cpp)
490  target_include_directories(dflash2_parity PRIVATE ${_strata_gpu_include_directories})
491  target_link_libraries(dflash2_parity PRIVATE strata_engine strata_kernels ${_strata_gpu_runtime_target})
492  add_executable(dflash2_q4_parity EXCLUDE_FROM_ALL src/core/dflash2_q4_parity.cpp)
493  target_include_directories(dflash2_q4_parity PRIVATE ${_strata_gpu_include_directories})
494  target_link_libraries(dflash2_q4_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
495  add_executable(dflash2_ring_test EXCLUDE_FROM_ALL src/core/dflash2_ring_test.cpp)   # the drafter's ring log and rebuild against an uninterrupted update sequence
496  target_include_directories(dflash2_ring_test PRIVATE ${_strata_gpu_include_directories})
497  target_link_libraries(dflash2_ring_test PRIVATE strata_engine strata_kernels ${_strata_gpu_runtime_target})
498  add_executable(dflash2_gemm_bench EXCLUDE_FROM_ALL src/core/dflash2_gemm_bench.cpp)
499  target_include_directories(dflash2_gemm_bench PRIVATE ${_strata_gpu_include_directories})
500  target_link_libraries(dflash2_gemm_bench PRIVATE strata_kernels ${_strata_gpu_runtime_target})
501  add_executable(dflash2_launch_bench EXCLUDE_FROM_ALL src/core/dflash2_launch_bench.cu)
502  target_include_directories(dflash2_launch_bench PRIVATE ${_strata_gpu_include_directories})
503  target_link_libraries(dflash2_launch_bench PRIVATE ${_strata_gpu_runtime_target})
504  add_executable(dflash2_bw_bench EXCLUDE_FROM_ALL src/core/dflash2_bw_bench.cu)
505  target_include_directories(dflash2_bw_bench PRIVATE ${_strata_gpu_include_directories})
506  target_link_libraries(dflash2_bw_bench PRIVATE ${_strata_gpu_runtime_target})
507  add_executable(dflash2_small_bench EXCLUDE_FROM_ALL src/core/dflash2_small_bench.cpp)
508  target_include_directories(dflash2_small_bench PRIVATE ${_strata_gpu_include_directories})
509  target_link_libraries(dflash2_small_bench PRIVATE strata_kernels ${_strata_gpu_runtime_target})
510  add_executable(dflash2_attn_bench EXCLUDE_FROM_ALL src/core/dflash2_attn_bench.cpp)
511  target_include_directories(dflash2_attn_bench PRIVATE ${_strata_gpu_include_directories})
512  target_link_libraries(dflash2_attn_bench PRIVATE strata_kernels ${_strata_gpu_runtime_target})
513
514  add_executable(strata src/program/generate.cpp)
515  strata_utf8_manifest(strata)
516  target_include_directories(strata PRIVATE ${_strata_gpu_include_directories})
517  target_link_libraries(strata PRIVATE strata_engine strata_prefill strata_spec ${_strata_gpu_runtime_target})
518  if(WIN32 AND STRATA_ENABLE_HIP)
519    # 0.2.1.2: the ROCm math libraries live in <package>\rocm\bin, which is on PATH only when the launcher starts the engine; load them on first
520    # use (main() adds that folder to the DLL search first) so `strata.exe --version` works from the package folder.  amdhip64_7.dll and the
521    # C++ runtime sit beside the exe (tools/hip/package_windows.py) and stay normal imports.
522    target_link_libraries(strata PRIVATE delayimp)
523    target_link_options(strata PRIVATE "LINKER:/DELAYLOAD:hipblas.dll" "LINKER:/DELAYLOAD:libhipblaslt.dll" "LINKER:/DELAYLOAD:rocblas.dll")
524  endif()
525
526  # NEW-MODELS-PLAN.md T1: Qwen3.6-35B-A3B's reference path (one GPU, the model resident, plain kernels), checked
527  # against llama.cpp by tools/qwen35/; the engine itself does not run the family yet
528  add_executable(strata-q36ref src/qwen35/q36ref.cu)
529  target_include_directories(strata-q36ref PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${_strata_gpu_include_directories})
530  target_link_libraries(strata-q36ref PRIVATE strata_kernels strata_warnings ${_strata_gpu_runtime_target})
531  # the engine path for the same family (serve protocol, prompt chunks, decode graph): src/qwen35/q36_engine.cu, a
532  # library that `strata` switches to for a qwen35moe model (the family switch at the top of its main) and that
533  # strata-q36 wraps on its own.  Not on gfx906 (#3172, #3271): it calls cuBLAS entry points the wave64 compat layer does
534  # not map (cublasSgemm, cublasGemmStridedBatchedEx) and its kernels assume 32-lane warps; main() guards every use with
535  # STRATA_HAVE_QWEN35, so a gfx906 build links and runs the Qwen3.8 family, and `strata --families` says so
536  if(NOT STRATA_HIP_GFX906)
537  add_library(strata_qwen35 STATIC src/qwen35/q36_engine.cu)
538  target_include_directories(strata_qwen35 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_strata_gpu_include_directories})
539  target_link_libraries(strata_qwen35 PRIVATE strata_prefill strata_kernels strata_warnings ${_strata_gpu_runtime_target})
540  if(STRATA_NATIVE_EXPERTS)
541    # the hybrid mode (experts that do not all fit in VRAM): the CPU expert pool on ggml-cpu's arithmetic
542    target_link_libraries(strata_qwen35 PRIVATE strata_kernels_cpu)
543    target_compile_definitions(strata_qwen35 PRIVATE STRATA_Q36_CPU_POOL=1)
544  endif()
545  add_executable(strata-q36 src/qwen35/q36_main.cpp)
546  strata_utf8_manifest(strata-q36)
547  target_link_libraries(strata-q36 PRIVATE strata_qwen35 ${_strata_gpu_runtime_target})
548  target_link_libraries(strata PRIVATE strata_qwen35)
549  target_compile_definitions(strata PRIVATE STRATA_HAVE_QWEN35=1)
550  endif()
551
552  if(STRATA_ENABLE_HIP)
553    enable_testing()
554    set(_strata_hip_tests)
555    add_executable(hip_prefill_gemm tests/hip/prefill_gemm.cpp)
556    target_link_libraries(hip_prefill_gemm PRIVATE strata_prefill strata_hip_runtime)
557    add_test(NAME hip_prefill_gemm COMMAND hip_prefill_gemm)
558    list(APPEND _strata_hip_tests hip_prefill_gemm)
559    add_executable(hip_gemm_f16_io_parity tests/hip/gemm_f16_io_parity.cpp)
560    target_link_libraries(hip_gemm_f16_io_parity PRIVATE strata_prefill strata_hip_runtime)
561    add_test(NAME hip_gemm_f16_io_parity COMMAND hip_gemm_f16_io_parity)
562    list(APPEND _strata_hip_tests hip_gemm_f16_io_parity)
563    add_executable(hip_q2_zero tests/hip/q2_zero.cpp)
564    target_link_libraries(hip_q2_zero PRIVATE strata_kernels strata_hip_runtime)
565    add_test(NAME hip_q2_zero COMMAND hip_q2_zero)
566    list(APPEND _strata_hip_tests hip_q2_zero)
567    # the QSA layer's fused norm + rope (rms_rope_rows, STRATA_QSA_FUSE_NR) against split_q + rms_rows + rope, bit for bit over the
568    # whole output; and the gfx11 prompt GEMMs' full-output coverage (every element written, sampled rows against FP64).
569    # GPU, synthetic, no model; exit 77 without a gfx11 device.
570    add_executable(hip_qsa_nr_parity src/prefill/qsa_nr_parity.cu)
571    target_link_libraries(hip_qsa_nr_parity PRIVATE strata_prefill strata_hip_runtime)
572    add_test(NAME hip_qsa_nr_parity COMMAND hip_qsa_nr_parity)
573    set_tests_properties(hip_qsa_nr_parity PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 300)
574    list(APPEND _strata_hip_tests hip_qsa_nr_parity)
575    add_executable(hip_pf_cover_test src/prefill/pf_cover_test.cu)
576    target_include_directories(hip_pf_cover_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/prefill)
577    target_link_libraries(hip_pf_cover_test PRIVATE strata_prefill strata_hip_runtime)
578    add_test(NAME hip_pf_cover_test COMMAND hip_pf_cover_test)
579    set_tests_properties(hip_pf_cover_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 900)
580    list(APPEND _strata_hip_tests hip_pf_cover_test)
581    add_executable(hip_expert_cache_staging tests/hip/expert_cache_staging.cpp)
582    target_link_libraries(hip_expert_cache_staging PRIVATE strata_engine)
583    add_test(NAME hip_expert_cache_staging COMMAND hip_expert_cache_staging)
584    list(APPEND _strata_hip_tests hip_expert_cache_staging)
585    if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/hip/intrinsics.cpp")
586      add_executable(hip_intrinsics tests/hip/intrinsics.cpp)
587      target_link_libraries(hip_intrinsics PRIVATE strata_hip_runtime)
588      add_test(NAME hip_intrinsics COMMAND hip_intrinsics)
589      list(APPEND _strata_hip_tests hip_intrinsics)
590    endif()
591    if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/hip/handoff.cpp")
592      add_executable(hip_handoff tests/hip/handoff.cpp)
593      target_link_libraries(hip_handoff PRIVATE strata_kernels strata_hip_runtime)
594      add_test(NAME hip_handoff COMMAND hip_handoff)
595      list(APPEND _strata_hip_tests hip_handoff)
596    endif()
597    if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/hip/mapped_alias.cpp")
598      # #325: reports what a hipHostGetDevicePointer alias is on this stack (on Windows: the host pointer, and a
599      # D2D copy into it does not land - hip_handoff's timeout there). A diagnosis: exits 0 whenever it ran.
600      add_executable(hip_mapped_alias tests/hip/mapped_alias.cpp)
601      target_link_libraries(hip_mapped_alias PRIVATE strata_kernels strata_hip_runtime)
602      add_test(NAME hip_mapped_alias COMMAND hip_mapped_alias)
603      set_tests_properties(hip_mapped_alias PROPERTIES SKIP_RETURN_CODE 77)
604      list(APPEND _strata_hip_tests hip_mapped_alias)
605    endif()
606    if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/hip/native_qsa_score.cpp")
607      add_executable(hip_native_qsa_score tests/hip/native_qsa_score.cpp)
608      target_link_libraries(hip_native_qsa_score PRIVATE strata_kernels strata_hip_runtime)
609      add_test(NAME hip_native_qsa_score COMMAND hip_native_qsa_score)
610      list(APPEND _strata_hip_tests hip_native_qsa_score)
611    endif()
612    if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/hip/prefill_native_batch.cpp")
613      add_executable(hip_prefill_native_batch tests/hip/prefill_native_batch.cpp)
614      target_link_libraries(hip_prefill_native_batch PRIVATE strata_kernels strata_hip_runtime)
615      add_test(NAME hip_prefill_native_batch COMMAND hip_prefill_native_batch)
616      list(APPEND _strata_hip_tests hip_prefill_native_batch)
617    endif()
618    # Aurora: the prompt GDN recurrence's per-head kernel against the column-split + norm kernels, bitwise
619    add_executable(hip_gdn_rec_head tests/hip/gdn_rec_head.cpp)
620    target_link_libraries(hip_gdn_rec_head PRIVATE strata_prefill strata_hip_runtime)
621    add_test(NAME hip_gdn_rec_head COMMAND hip_gdn_rec_head)
622    list(APPEND _strata_hip_tests hip_gdn_rec_head)
623    # PR #5096: flag B stays behind queued copies (the same test as the CUDA build's flag_order_test; the HIP compat header maps the runtime calls)
624    set_source_files_properties(tests/core/flag_order_test.cu PROPERTIES LANGUAGE HIP)
625    add_executable(hip_flag_order_test tests/core/flag_order_test.cu)
626    target_include_directories(hip_flag_order_test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
627    target_link_libraries(hip_flag_order_test PRIVATE strata_hip_runtime Threads::Threads)
628    add_test(NAME hip_flag_order_test COMMAND hip_flag_order_test)
629    set_tests_properties(hip_flag_order_test PROPERTIES TIMEOUT 60)
630    list(APPEND _strata_hip_tests hip_flag_order_test)
631    add_executable(hip_gdn_chunked tests/hip/gdn_chunked.cpp)
632    target_link_libraries(hip_gdn_chunked PRIVATE strata_prefill strata_hip_runtime)
633    add_test(NAME hip_gdn_chunked COMMAND hip_gdn_chunked)
634    add_test(NAME hip_gdn_chunked_off COMMAND hip_gdn_chunked --off)
635    add_test(NAME hip_gdn_chunked_default COMMAND hip_gdn_chunked --default)
636    list(APPEND _strata_hip_tests hip_gdn_chunked hip_gdn_chunked_off hip_gdn_chunked_default)
637    # GDN prompt stage bench (gates + conv + recurrence, per-piece times and output/state hashes at 4K/16K/32K); a measurement
638    # tool, run by hand with the STRATA_GDN_* knobs under test - no add_test
639    add_executable(hip_gdn_stage_bench tests/hip/gdn_stage_bench.cpp)
640    target_link_libraries(hip_gdn_stage_bench PRIVATE strata_prefill strata_hip_runtime)
641    # #313: the RDNA3 / RDNA3.5 WMMA dense GEMMs (opt-in STRATA_WMMA_GEMM=1) against a reference
642    add_executable(hip_prefill_wmma_gemm_parity tests/hip/prefill_wmma_gemm_parity.cpp)
643    target_include_directories(hip_prefill_wmma_gemm_parity PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/prefill")
644    target_link_libraries(hip_prefill_wmma_gemm_parity PRIVATE strata_prefill strata_hip_runtime)
645    add_test(NAME hip_prefill_wmma_gemm_parity COMMAND hip_prefill_wmma_gemm_parity)
646    set_tests_properties(hip_prefill_wmma_gemm_parity PROPERTIES SKIP_RETURN_CODE 77)   # no matrix cores: skipped
647    list(APPEND _strata_hip_tests hip_prefill_wmma_gemm_parity)
648    # S (STRATA_HCD_EXACT): the exact HC down kernel against hipBLASLt solution 1176 / 1177 (needs STRATA_HIPBLASLT_TUNING; exit 77 else)
649    add_executable(hip_prefill_hcd_exact_parity tests/hip/prefill_hcd_exact_parity.cpp)
650    target_link_libraries(hip_prefill_hcd_exact_parity PRIVATE strata_prefill strata_hip_runtime)
651    add_test(NAME hip_prefill_hcd_exact_parity COMMAND hip_prefill_hcd_exact_parity)
652    set_tests_properties(hip_prefill_hcd_exact_parity PROPERTIES SKIP_RETURN_CODE 77)
653    list(APPEND _strata_hip_tests hip_prefill_hcd_exact_parity)
654    # the HC write-back kernel timed at the prompt path's shapes with an output checksum (not a ctest; STRATA_GRW_V picks a variant)
655    add_executable(hip_prefill_gr_write_bench tests/hip/prefill_gr_write_bench.cpp)
656    target_link_libraries(hip_prefill_gr_write_bench PRIVATE strata_prefill strata_hip_runtime)
657    # S6: the AMD fast router against the portable kernel, bitwise
658    add_executable(hip_router_fast tests/hip/router_fast.cpp)
659    target_link_libraries(hip_router_fast PRIVATE strata_kernels strata_hip_runtime)
660    add_test(NAME hip_router_fast COMMAND hip_router_fast)
661    list(APPEND _strata_hip_tests hip_router_fast)
662    # S6: the RDNA4 matrix-core prompt attention (STRATA_HIP_WMMA) against the FP32 kernel and FP64; skips off gfx12
663    # the prompt attention on a recorded selection (STRATA_QSA_DUMP), for A/B of kernel variants (STRATA_QSA_UNION=1)
664    add_executable(hip_pa_bench tests/cuda/pa_bench.cpp)
665    target_link_libraries(hip_pa_bench PRIVATE strata_kernels strata_hip_runtime)
666    add_executable(hip_prompt_attn_wmma src/kernels/qsa_prompt_attn_parity.cpp)
667    target_link_libraries(hip_prompt_attn_wmma PRIVATE strata_kernels strata_hip_runtime)
668    add_test(NAME hip_prompt_attn_wmma COMMAND hip_prompt_attn_wmma 32768 2048 3)
669    set_tests_properties(hip_prompt_attn_wmma PROPERTIES TIMEOUT 600 SKIP_RETURN_CODE 77)
670    list(APPEND _strata_hip_tests hip_prompt_attn_wmma)
671    if(STRATA_HIPBLASLT_AVAILABLE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/hip/prefill_hipblaslt_gemm.cpp")
672      add_executable(hip_prefill_hipblaslt_gemm tests/hip/prefill_hipblaslt_gemm.cpp)
673      target_include_directories(hip_prefill_hipblaslt_gemm PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/prefill")
674      target_link_libraries(hip_prefill_hipblaslt_gemm PRIVATE strata_prefill strata_hip_runtime roc::hipblaslt roc::hipblas)
675      add_test(NAME hip_prefill_hipblaslt_gemm COMMAND hip_prefill_hipblaslt_gemm)
676      set_tests_properties(hip_prefill_hipblaslt_gemm PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
677      list(APPEND _strata_hip_tests hip_prefill_hipblaslt_gemm)
678    endif()
679    if(STRATA_ROCBLAS_AVAILABLE)
680      # the rocBLAS solution table of the FP16-out prompt GEMMs (gfx103x): opt-in, skips without STRATA_ROCBLAS_TUNING
681      add_executable(hip_prefill_rocblas_gemm tests/hip/prefill_rocblas_gemm.cpp)
682      target_include_directories(hip_prefill_rocblas_gemm PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/prefill")
683      target_link_libraries(hip_prefill_rocblas_gemm PRIVATE strata_prefill strata_hip_runtime roc::rocblas roc::hipblas)
684      add_test(NAME hip_prefill_rocblas_gemm COMMAND hip_prefill_rocblas_gemm)
685      set_tests_properties(hip_prefill_rocblas_gemm PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
686      list(APPEND _strata_hip_tests hip_prefill_rocblas_gemm)
687    endif()
688    if(_strata_hip_tests)
689      set_tests_properties(${_strata_hip_tests} PROPERTIES TIMEOUT 60)
690    endif()
691    if(TARGET hip_prefill_native_batch)
692      set_tests_properties(hip_prefill_native_batch PROPERTIES TIMEOUT 120)
693    endif()
694    if(TARGET hip_prefill_hipblaslt_gemm)
695      set_tests_properties(hip_prefill_hipblaslt_gemm PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
696    endif()
697    if(TARGET hip_prefill_rocblas_gemm)
698      set_tests_properties(hip_prefill_rocblas_gemm PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
699    endif()
700  endif()
701
702  add_executable(dequant_s2_parity src/kernels/dequant_s2_parity.cpp)
703  # The tests are HOST C++ files that call cudaMalloc/cudaMemcpy themselves, so they need the toolkit headers
704  # and cudart explicitly: enabling the CUDA language gives those to .cu sources automatically, but a .cpp
705  # target is just a C++ target and gets neither.
706  target_include_directories(dequant_s2_parity PRIVATE ${_strata_gpu_include_directories})
707  target_link_libraries(dequant_s2_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
708  add_test(NAME dequant_s2_parity COMMAND dequant_s2_parity --selftest)
709
710  add_executable(s2_gemv_parity src/kernels/s2_gemv_parity.cpp)
711  target_include_directories(s2_gemv_parity PRIVATE ${_strata_gpu_include_directories})
712  target_link_libraries(s2_gemv_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
713  add_test(NAME s2_gemv_parity COMMAND s2_gemv_parity --selftest)
714
715  add_executable(iq_parity src/kernels/iq_parity.cpp)
716  target_include_directories(iq_parity PRIVATE ${_strata_gpu_include_directories})
717  target_link_libraries(iq_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
718  # TODO 24: the i-quant fixtures are generated, not shipped.  tools/iq_fixture.py needs python3 + numpy
719  # and the repository's vendored gguf-py (no pip installs); it writes deterministic fixtures into the
720  # BUILD directory (the source tree is not touched).  The CTest fixture makes generation-to-test order
721  # explicit even under parallel execution; a fixture-generation failure fails iq_parity with it.
722  find_package(Python3 COMPONENTS Interpreter QUIET)
723  # the generator needs an interpreter WITH numpy: probe the configured one, the setup's .venv, and the
724  # system python3; -DIQ_FIXTURE_PYTHON=... overrides the search outright.
725  set(_iq_python "")
726  set(_iq_candidates "")
727  if(IQ_FIXTURE_PYTHON)
728    list(APPEND _iq_candidates ${IQ_FIXTURE_PYTHON})
729  else()
730    if(Python3_Interpreter_FOUND)
731      list(APPEND _iq_candidates ${Python3_EXECUTABLE})
732    endif()
733    list(APPEND _iq_candidates "${CMAKE_CURRENT_SOURCE_DIR}/.venv/bin/python"
734                                "${CMAKE_CURRENT_SOURCE_DIR}/.venv/Scripts/python.exe"
735                                /usr/bin/python3
736                                python3)
737  endif()
738  foreach(_cand IN LISTS _iq_candidates)
739    if(_cand STREQUAL "")
740      continue()
741    endif()
742    execute_process(COMMAND ${_cand} -c "import numpy" OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE _iq_probe)
743    if(_iq_probe EQUAL 0)
744      set(_iq_python "${_cand}")
745      break()
746    endif()
747  endforeach()
748  if(NOT _iq_python STREQUAL "")
749    add_test(NAME iq_parity_fixtures
750             COMMAND ${_iq_python} ${CMAKE_CURRENT_SOURCE_DIR}/tools/iq_fixture.py
751                     --out ${CMAKE_CURRENT_BINARY_DIR}/iq_fixture)
752    # exit 3: numpy or the vendored gguf-py is missing (a trimmed third_party) - a skip, not a failure
753    set_tests_properties(iq_parity_fixtures PROPERTIES FIXTURES_SETUP iq_fixture_data SKIP_RETURN_CODE 3)
754    add_test(NAME iq_parity COMMAND iq_parity ${CMAKE_CURRENT_BINARY_DIR}/iq_fixture)
755    set_tests_properties(iq_parity PROPERTIES FIXTURES_REQUIRED iq_fixture_data SKIP_RETURN_CODE 3)
756  else()
757    message(STATUS "STRATA tests: no python3 with numpy was found (the configured interpreter and .venv "
758                   "were probed) - the iq_parity fixtures and its test are not registered; the fixtures "
759                   "need python3 with numpy and the repository's vendored gguf-py")
760  endif()
761  if(STRATA_ENABLE_CUDA)
762    # native_mmvq's multi_exact contract, bitwise: a T-column call against T single-column calls on the same Q8_1
763    # bytes, with the flag off as the negative control (synthetic, GPU, no model; the control assumes 32-lane warps)
764    add_executable(mmvq_multi_parity src/kernels/mmvq_multi_parity.cpp)
765    target_include_directories(mmvq_multi_parity PRIVATE ${_strata_gpu_include_directories})
766    target_link_libraries(mmvq_multi_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
767    add_test(NAME mmvq_multi_parity COMMAND mmvq_multi_parity)
768    if(STRATA_HIP_GFX906)   # the CUDA layout, where the negative control has power (the wave64 one is exact at every T)
769      add_test(NAME mmvq_multi_parity_cuda_layout COMMAND mmvq_multi_parity)
770      set_tests_properties(mmvq_multi_parity_cuda_layout PROPERTIES ENVIRONMENT "STRATA_MMVQ_WAVE=0")
771    endif()
772  endif()
773  if(STRATA_ENABLE_CUDA)
774    # fork F4: the 2-4 column dense projections from the interleaved q8_1 copy, bitwise vs native_mmvq (GPU, synthetic)
775    add_executable(mmvq_il_parity src/kernels/mmvq_il_parity.cpp)
776    target_include_directories(mmvq_il_parity PRIVATE ${_strata_gpu_include_directories})
777    target_link_libraries(mmvq_il_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
778    add_test(NAME mmvq_il_parity COMMAND mmvq_il_parity)
779    # sm_89's opt-in tables (#3453, STRATA_MMVQ_IL_89=1): the table check only (no case matches MMVQ_IL_ONLY)
780    add_test(NAME mmvq_il_parity_89table COMMAND mmvq_il_parity)
781    set_tests_properties(mmvq_il_parity_89table PROPERTIES ENVIRONMENT "STRATA_MMVQ_IL_89=1;MMVQ_IL_ONLY=no-such-case")
782    # the opt-in STRATA_MMVQ_IL_PF kernels (hoisted group loads, exact integer forms): every variant bit-checked against
783    # native_mmvq for every type, shape, T and rows choice
784    add_test(NAME mmvq_il_parity_pf COMMAND mmvq_il_parity --pf 0,2,3,4,5,6)
785    set_tests_properties(mmvq_il_parity_pf PROPERTIES TIMEOUT 900)
786    # the wide dequant kernels (a thread per 8 values; sm_61's default), bitwise vs the per-group ones (GPU, synthetic,
787    # no model; --bench adds old/new timings)
788    add_executable(dequant_wide_parity src/kernels/dequant_wide_parity.cpp)
789    target_include_directories(dequant_wide_parity PRIVATE ${_strata_gpu_include_directories})
790    target_link_libraries(dequant_wide_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
791    add_test(NAME dequant_wide_parity COMMAND dequant_wide_parity)
792  endif()
793  # programmatic dependent launch (pdl.hpp) in a captured verify-shaped chain: bitwise vs ordinary launches over
794  # replays with poisoned buffers, and only kernel-to-kernel programmatic edges (GPU, synthetic, no model; the edges
795  # are only made on sm_90+, elsewhere it checks that there are none).  NVIDIA only: PDL is a CUDA feature.
796  if(STRATA_ENABLE_CUDA AND NOT STRATA_HIP_GFX906)
797    add_executable(pdl_parity src/kernels/pdl_parity.cpp)
798    target_include_directories(pdl_parity PRIVATE ${_strata_gpu_include_directories})
799    target_link_libraries(pdl_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
800    add_test(NAME pdl_parity COMMAND pdl_parity)
801    # PDL is opt-in (STRATA_DF_PDL); the test checks the opted-in path, whose PDL capture forces programmatic launches
802    set_tests_properties(pdl_parity PROPERTIES ENVIRONMENT "STRATA_DF_PDL=1")
803  endif()
804  # the IQ kernels that decode a weight part once for every column/entry, bitwise vs the per-column ones
805  # (GPU, synthetic, no model; --bench adds old/new timings)
806  add_executable(iq_multi_parity src/kernels/iq_multi_parity.cpp)
807  target_include_directories(iq_multi_parity PRIVATE ${_strata_gpu_include_directories})
808  # strata_kernels_cpu: lat_gu_colscale_dev (iq_kernels.cu) reads the loaded layout's column scales
809  target_link_libraries(iq_multi_parity PRIVATE strata_kernels strata_kernels_cpu ${_strata_gpu_runtime_target})
810  add_test(NAME iq_multi_parity COMMAND iq_multi_parity)
811  # q3k_real_ref: CPU-official (ggml) vs GPU on a REAL v7_l1280_q3k expert (Q3_K gu / IQ4_NL dn)
812  add_executable(q3k_real_ref src/kernels/q3k_real_ref.cpp)
813  target_include_directories(q3k_real_ref PRIVATE ${_strata_gpu_include_directories})
814  target_link_libraries(q3k_real_ref PRIVATE strata_kernels strata_kernels_cpu ${_strata_gpu_runtime_target})
815  # the Gyro trellis decode kernels (TQ2_T / TQK6 / TQK7) on synthetic blocks: decode-once vs per-column bitwise, output
816  # checksums to compare two builds byte for byte, --bench for timings (GPU, no model)
817  add_executable(tq_pascal_bench src/kernels/tq_pascal_bench.cpp)
818  target_include_directories(tq_pascal_bench PRIVATE ${_strata_gpu_include_directories} ${CMAKE_CURRENT_SOURCE_DIR}/third_party/ggml)
819  target_link_libraries(tq_pascal_bench PRIVATE strata_kernels ${_strata_gpu_runtime_target})
820  add_test(NAME tq_pascal_bench COMMAND tq_pascal_bench)
821  set_tests_properties(iq_multi_parity PROPERTIES ENVIRONMENT "STRATA_KQ_SPLIT=1")   # the Q4_K / Q5_K / Q8_0 Split path against the old kernels
822  # the same Split path on the other routes it can meet: the generic multi kernels (no V2K) and the fused gate/up + SwiGLU kernel, and the sub-16-row
823  # gate/up route switched off (a K-quant row has 160 dots, not the 80 the sub-16 rows assume: STRATA_KQ_SPLIT=1 must stay bitwise on all of them)
824  add_test(NAME iq_multi_parity_kq_nov2k COMMAND iq_multi_parity)
825  set_tests_properties(iq_multi_parity_kq_nov2k PROPERTIES ENVIRONMENT "STRATA_KQ_SPLIT=1;STRATA_EXPERT_V2K=0")
826  add_test(NAME iq_multi_parity_kq_swiglu COMMAND iq_multi_parity)
827  set_tests_properties(iq_multi_parity_kq_swiglu PROPERTIES ENVIRONMENT "STRATA_KQ_SPLIT=1;STRATA_GU_SWIGLU=1")
828  add_test(NAME iq_multi_parity_kq_nosub16 COMMAND iq_multi_parity)
829  set_tests_properties(iq_multi_parity_kq_nosub16 PROPERTIES ENVIRONMENT "STRATA_KQ_SPLIT=1;STRATA_NO_SUB16_GU=1")
830  # the prompt path's DeltaNet recurrence: gdn_rec_kh_kernel against gdn_rec_cols_pipe_kernel, bitwise (GPU,
831  # synthetic, no model; --bench adds timings).  NVIDIA only: cp.async and the CUDA occupancy API (not on gfx906)
832  if(STRATA_ENABLE_CUDA AND NOT STRATA_HIP_GFX906)
833    # Independent pinned expert uploads: byte parity and stream/event ordering.
834    add_executable(dma_batch_parity tests/core/dma_batch_parity.cu)
835    target_include_directories(dma_batch_parity PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
836    target_link_libraries(dma_batch_parity PRIVATE ${_strata_gpu_runtime_target})
837    add_test(NAME dma_batch_parity COMMAND dma_batch_parity)
838    set_tests_properties(dma_batch_parity PROPERTIES TIMEOUT 120)
839    # PR #5096: flag B stays behind queued copies (delayed host-function copy, a consumer kernel, graph replay, every device)
840    add_executable(flag_order_test tests/core/flag_order_test.cu)
841    target_include_directories(flag_order_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
842    target_link_libraries(flag_order_test PRIVATE ${_strata_gpu_runtime_target} Threads::Threads)
843    add_test(NAME flag_order_test COMMAND flag_order_test)
844    set_tests_properties(flag_order_test PROPERTIES TIMEOUT 60)
845    if(WIN32)
846      add_test(NAME dma_batch_registered_parity COMMAND dma_batch_parity --registered)
847      set_tests_properties(dma_batch_registered_parity PROPERTIES TIMEOUT 120)
848    endif()
849    add_executable(gdn_rec_parity src/prefill/gdn_rec_parity.cu)
850    target_link_libraries(gdn_rec_parity PRIVATE ${_strata_gpu_runtime_target})
851    add_test(NAME gdn_rec_parity COMMAND gdn_rec_parity)
852    # STRATA_GDN_TC=1: the tensor-core helpers of the scan, each on one warp against a double-precision reference.  Any sm_80+
853    # card runs them; the scan itself needs 122 KB of shared memory a block (sm_80, sm_90), where gdn_rec_parity prints
854    # "not on this card" for the tc variant
855    add_test(NAME gdn_rec_parity_selftest_frag COMMAND gdn_rec_parity --selftest-frag)
856    set_tests_properties(gdn_rec_parity_selftest_frag PROPERTIES SKIP_RETURN_CODE 77)
857    # the production-linked GDN parity / benchmark harness (no kernel copies: it calls gdn_gates, gdn_conv and
858    # gdn_recurrence of strata_prefill through the GdnProbe of include/strata/prefill/gdn_probe.hpp, against an FP64
859    # oracle from tests/gdn/gdn_fixture.hpp).  Usage: docs/GDN_CONTRACT.md.  The smoke test is small and CPU-cheap.
860    execute_process(COMMAND git -C ${CMAKE_CURRENT_SOURCE_DIR} rev-parse --short=9 HEAD OUTPUT_VARIABLE _gdn_sha
861                    OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
862    if(NOT _gdn_sha)
863      set(_gdn_sha unknown)
864    endif()
865    add_executable(gdn_harness src/prefill/gdn_harness.cu)
866    target_include_directories(gdn_harness PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests/gdn)
867    target_compile_definitions(gdn_harness PRIVATE GDN_HARNESS_SHA="${_gdn_sha}")
868    target_link_libraries(gdn_harness PRIVATE strata_prefill)
869    add_test(NAME gdn_harness_smoke COMMAND gdn_harness --T 400 --chunk 160 --cuts 37 --paths auto,keyhead,pipe --ref-heads 0,17)
870    set_tests_properties(gdn_harness_smoke PROPERTIES TIMEOUT 300)
871    # the prompt path's BF16 products against cuBLAS's own BF16 GEMM, within fp32 rounding (sm_7x runs them on the
872    # FP16 tensor cores; GPU, synthetic, no model; --bench adds timings)
873    add_executable(gemm_bf16_parity src/prefill/gemm_bf16_parity.cu)
874    target_link_libraries(gemm_bf16_parity PRIVATE strata_prefill )
875    add_test(NAME gemm_bf16_parity COMMAND gemm_bf16_parity)
876    # STRATA_DEQUANT_SIDE: Gemm::native with the dense dequant on a side stream (two scratches) against the serial form,
877    # bitwise (GPU, synthetic, no model; 77 without a device)
878    add_executable(gemm_dequant_side_parity src/prefill/gemm_dequant_side_parity.cu)
879    target_link_libraries(gemm_dequant_side_parity PRIVATE strata_prefill )
880    add_test(NAME gemm_dequant_side_parity COMMAND gemm_dequant_side_parity)
881    set_tests_properties(gemm_dequant_side_parity PROPERTIES SKIP_RETURN_CODE 77)
882    add_executable(gemm_w16_parity src/prefill/gemm_w16_parity.cu)
883    target_link_libraries(gemm_w16_parity PRIVATE strata_prefill )
884    add_test(NAME gemm_w16_parity COMMAND gemm_w16_parity)
885    set_tests_properties(gemm_w16_parity PROPERTIES SKIP_RETURN_CODE 77)
886    # Pascal, opt-in STRATA_DENSE_F32=1: the dense projections' FP16 GEMMs as cublasSgemm on FP32 copies, bitwise vs
887    # the cuBLAS FP16 call over a sweep of chunk sizes (GPU, synthetic, no model; --full sweeps every size, --bench
888    # adds timings).  Not a ctest: whether the two agree is a property of the cuBLAS build, which this checks.
889    add_executable(gemm_f32_parity src/prefill/gemm_f32_parity.cu)
890    target_link_libraries(gemm_f32_parity PRIVATE strata_prefill )
891    # the hyper-connection read's fused up projection + mix (gr_upmix, STRATA_HC_UPMIX) against cuBLAS + gr_mix_r,
892    # bitwise where cuBLAS sums K in the same order, else within FP32 rounding and as close to FP64 (GPU, synthetic,
893    # no model; --bench adds timings)
894    add_executable(gr_upmix_parity src/prefill/gr_upmix_parity.cu)
895    target_link_libraries(gr_upmix_parity PRIVATE strata_prefill )
896    add_test(NAME gr_upmix_parity COMMAND gr_upmix_parity)
897    set_tests_properties(gr_upmix_parity PROPERTIES SKIP_RETURN_CODE 77)
898    # the two kernels of the layer-major prompt path (STRATA_PREFILL_LAYER_MAJOR=1, #3976): moe_shared_init and
899    # moe_scatter_add against a host reference, bitwise for the scatter (GPU, synthetic, no model)
900    add_executable(lm_kernels_parity src/prefill/lm_kernels_parity.cu)
901    target_link_libraries(lm_kernels_parity PRIVATE strata_prefill )
902    add_test(NAME lm_kernels_parity COMMAND lm_kernels_parity)
903    set_tests_properties(lm_kernels_parity PROPERTIES SKIP_RETURN_CODE 77)
904    # hc_q8_to_bf16 on the stream it is given: the layer-major prompt walk expanded a STRATA_HC_REQ8
905    # hyper-connection projection on the default stream while its GEMMs read another.  Synthetic, no model.
906    add_executable(hc_q8_stream_test tests/cuda/hc_q8_stream_test.cu)
907    target_link_libraries(hc_q8_stream_test PRIVATE strata_prefill )
908    add_test(NAME hc_q8_stream COMMAND hc_q8_stream_test)
909    set_tests_properties(hc_q8_stream PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 300)
910  endif()
911  # native_expert_grouped's group stride and fused SwiGLU + q8_1, bitwise vs the launches before them (GPU, synthetic,
912  # no model; --bench adds v1/new timings of a window's 48 calls in a graph)
913  add_executable(native_grouped_parity src/kernels/native_grouped_parity.cpp)
914  target_include_directories(native_grouped_parity PRIVATE ${_strata_gpu_include_directories})
915  target_link_libraries(native_grouped_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
916  add_test(NAME native_grouped_parity COMMAND native_grouped_parity)
917  # native_expert_i8 (our own int8 dot-product tile kernels, research, off by default) against native_expert_grouped (GPU, synthetic, no model)
918  add_executable(native_i8_parity src/kernels/native_i8_parity.cpp)
919  target_include_directories(native_i8_parity PRIVATE ${_strata_gpu_include_directories})
920  target_link_libraries(native_i8_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
921  add_test(NAME native_i8_parity COMMAND native_i8_parity)
922  set_tests_properties(native_i8_parity PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 300)
923  add_executable(mmvf_rows_parity src/kernels/mmvf_rows_parity.cpp)
924  target_include_directories(mmvf_rows_parity PRIVATE ${_strata_gpu_include_directories})
925  target_link_libraries(mmvf_rows_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
926  add_test(NAME mmvf_rows_parity COMMAND mmvf_rows_parity)
927  set_tests_properties(mmvf_rows_parity PROPERTIES ENVIRONMENT "STRATA_MMVF_ROWS=1" TIMEOUT 120)
928  if(STRATA_HIP_GFX906)
929    add_test(NAME native_grouped_fused_parity COMMAND native_grouped_parity)
930    set_tests_properties(native_grouped_fused_parity PROPERTIES
931      ENVIRONMENT "STRATA_HIP_SWIGLU_FUSED=1;STRATA_EXP_MODE=7" TIMEOUT 120)
932    add_executable(gfx906_gdn_rec_head tests/hip/gdn_rec_head.cpp)
933    target_include_directories(gfx906_gdn_rec_head PRIVATE ${_strata_gpu_include_directories})
934    target_link_libraries(gfx906_gdn_rec_head PRIVATE strata_prefill ${_strata_gpu_runtime_target})
935    add_test(NAME gfx906_gdn_rec_head COMMAND gfx906_gdn_rec_head)
936    set_tests_properties(gfx906_gdn_rec_head PROPERTIES TIMEOUT 120)
937  endif()
938  if(STRATA_ENABLE_CUDA)
939    # the Volta prompt experts (gemm_iq_f16_grouped, STRATA_PF_WMMA) against a double reference; skipped below sm_70
940    add_executable(pf_wmma_parity src/kernels/pf_wmma_parity.cpp)
941    target_include_directories(pf_wmma_parity PRIVATE ${_strata_gpu_include_directories})
942    target_link_libraries(pf_wmma_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
943    add_test(NAME pf_wmma_parity COMMAND pf_wmma_parity)
944    set_tests_properties(pf_wmma_parity PROPERTIES SKIP_RETURN_CODE 77)
945  endif()
946  add_executable(shared_expert_parity src/kernels/shared_expert_parity.cpp)
947  target_include_directories(shared_expert_parity PRIVATE ${_strata_gpu_include_directories})
948  target_link_libraries(shared_expert_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
949  add_test(NAME shared_expert_parity COMMAND shared_expert_parity --selftest)
950  # the split / batched verify-window kernels (from eddoursul's fork), bitwise vs the kernels they replace
951  if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)
952    add_executable(verify_parity src/kernels/verify_parity.cpp)
953    target_include_directories(verify_parity PRIVATE ${_strata_gpu_include_directories})
954    target_link_libraries(verify_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
955    add_test(NAME verify_parity COMMAND verify_parity --selftest)
956  endif()
957  # BW-DENSE: the v3 read's weight-prefetch variants against the plain v3 read, bit for bit, and their cold-weight time
958  add_executable(gr_v3_screen src/kernels/gr_v3_screen.cpp)
959  target_include_directories(gr_v3_screen PRIVATE ${_strata_gpu_include_directories})
960  target_link_libraries(gr_v3_screen PRIVATE strata_kernels ${_strata_gpu_runtime_target})
961  add_executable(mmvf_unr_hash src/kernels/mmvf_unr_hash.cpp)
962  target_include_directories(mmvf_unr_hash PRIVATE ${_strata_gpu_include_directories})
963  target_link_libraries(mmvf_unr_hash PRIVATE strata_kernels ${_strata_gpu_runtime_target})
964  add_executable(fused_gr_bench src/kernels/fused_gr_bench.cpp)
965  target_include_directories(fused_gr_bench PRIVATE ${_strata_gpu_include_directories})
966  target_link_libraries(fused_gr_bench PRIVATE strata_kernels ${_strata_gpu_runtime_target})
967  add_executable(router_chain_bench src/kernels/router_chain_bench.cpp)
968  target_include_directories(router_chain_bench PRIVATE ${_strata_gpu_include_directories})
969  target_link_libraries(router_chain_bench PRIVATE strata_kernels ${_strata_gpu_runtime_target})
970  # B6: the dense projections' time per verify row at the model's shapes, default vs STRATA_B6_MMVQ_ROWS, bitwise
971  if(STRATA_ENABLE_CUDA)
972    add_executable(b6_mmvq_bench src/kernels/b6_mmvq_bench.cpp)
973    target_include_directories(b6_mmvq_bench PRIVATE ${_strata_gpu_include_directories})
974    target_link_libraries(b6_mmvq_bench PRIVATE strata_kernels ${_strata_gpu_runtime_target})
975  endif()
976  add_executable(gr_parity src/kernels/gr_parity.cpp)
977  target_include_directories(gr_parity PRIVATE ${_strata_gpu_include_directories})
978  target_link_libraries(gr_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
979  add_test(NAME gr_parity COMMAND gr_parity --selftest)
980
981  add_executable(gdn_parity src/kernels/gdn_parity.cpp)
982  target_include_directories(gdn_parity PRIVATE ${_strata_gpu_include_directories})
983  target_link_libraries(gdn_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
984  add_test(NAME gdn_parity COMMAND gdn_parity --selftest)
985  # #3948: the same checks through the 4-blocks-a-head GDN step (the default on gfx1151), whose output-norm kernel writes the
986  # STRATA_QFUSE q8_1 image on its own
987  add_test(NAME gdn_parity_split COMMAND gdn_parity --selftest)
988  set_tests_properties(gdn_parity_split PROPERTIES ENVIRONMENT "STRATA_GDN_SPLIT=1")
989
990  # v100/gdn-chunk: the chunked GDN prompt recurrence vs the token recurrence and a host reference (GPU,
991  # synthetic, no model).  The chunked path changes the summation order - FP32-level, not bit-exact - so the
992  # test asserts measured error bounds, and --selftest pins them.
993  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA)
994    add_executable(gdn_chunk_parity src/kernels/gdn_chunk_parity.cpp)
995    target_include_directories(gdn_chunk_parity PRIVATE ${_strata_gpu_include_directories})
996    target_link_libraries(gdn_chunk_parity PRIVATE strata_prefill ${_strata_gpu_runtime_target})
997    add_test(NAME gdn_chunk_parity COMMAND gdn_chunk_parity --selftest)
998    set_tests_properties(gdn_chunk_parity PROPERTIES SKIP_RETURN_CODE 77)
999
1000    # v100/gdn-chunk: the micro benchmark (CUDA events, real GDN shapes): chunked vs recurrent prompt path.
1001    add_executable(gdn_chunk_bench bench/gdn_chunk_bench.cpp)
1002    target_include_directories(gdn_chunk_bench PRIVATE ${_strata_gpu_include_directories})
1003    target_link_libraries(gdn_chunk_bench PRIVATE strata_prefill ${_strata_gpu_runtime_target})
1004  endif()
1005
1006  add_executable(s2_gemv_q8_parity src/kernels/s2_gemv_q8_parity.cpp)
1007  target_include_directories(s2_gemv_q8_parity PRIVATE ${_strata_gpu_include_directories})
1008  target_link_libraries(s2_gemv_q8_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1009  add_test(NAME s2_gemv_q8_parity COMMAND s2_gemv_q8_parity --selftest)
1010
1011  add_executable(sampler_parity src/kernels/sampler_parity.cpp)
1012  target_include_directories(sampler_parity PRIVATE ${_strata_gpu_include_directories})
1013  target_link_libraries(sampler_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1014  add_test(NAME sampler_parity COMMAND sampler_parity --selftest)
1015  set_tests_properties(sampler_parity PROPERTIES ENVIRONMENT "STRATA_OLD_SAMPLER=0;STRATA_SAMPLER_ONE_BLOCK=0")
1016  # the GPU verifier of probabilistic draft acceptance against the host reference (STRATA_SPEC_PROB)
1017  add_executable(spec_verify_parity src/kernels/spec_verify_parity.cpp)
1018  target_include_directories(spec_verify_parity PRIVATE ${_strata_gpu_include_directories})
1019  target_link_libraries(spec_verify_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1020  add_test(NAME spec_verify_parity COMMAND spec_verify_parity)
1021  set_tests_properties(spec_verify_parity PROPERTIES ENVIRONMENT "STRATA_OLD_SAMPLER=0;STRATA_SAMPLER_ONE_BLOCK=0")
1022  # the explicit mu / NULL verifier of the gated proposal (STRATA_SPEC_PROB=1, pick gate) against a CPU oracle
1023  add_executable(spec_proposal_parity src/kernels/spec_proposal_parity.cpp)
1024  target_include_directories(spec_proposal_parity PRIVATE ${_strata_gpu_include_directories})
1025  target_link_libraries(spec_proposal_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1026  add_test(NAME spec_proposal_parity COMMAND spec_proposal_parity)
1027  set_tests_properties(spec_proposal_parity PROPERTIES ENVIRONMENT "STRATA_OLD_SAMPLER=0;STRATA_SAMPLER_ONE_BLOCK=0" TIMEOUT 120)
1028  # the same fixtures on the other two sampled paths: the one-block kernel and the 0.1.20 kernel
1029  add_test(NAME sampler_parity_one_block COMMAND sampler_parity --selftest)
1030  set_tests_properties(sampler_parity_one_block PROPERTIES ENVIRONMENT "STRATA_OLD_SAMPLER=0;STRATA_SAMPLER_ONE_BLOCK=1")
1031  add_test(NAME sampler_parity_old COMMAND sampler_parity --selftest)
1032  set_tests_properties(sampler_parity_old PROPERTIES ENVIRONMENT "STRATA_OLD_SAMPLER=1;STRATA_SAMPLER_ONE_BLOCK=0")
1033  # S19: the decode QSA top-k and the greedy argmax on thread-block clusters (sm_90+) vs the one-CTA kernels, bitwise,
1034  # captured in a graph too (GPU, synthetic, no model; skips below sm_90); --bench: per-call times
1035  if(STRATA_ENABLE_CUDA)
1036    add_executable(decode_cluster_parity src/kernels/decode_cluster_parity.cpp)
1037    target_include_directories(decode_cluster_parity PRIVATE ${_strata_gpu_include_directories})
1038    target_link_libraries(decode_cluster_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1039    add_test(NAME decode_cluster_parity COMMAND decode_cluster_parity --selftest)
1040  endif()
1041
1042  add_executable(rope_parity src/kernels/rope_parity.cpp)
1043  target_include_directories(rope_parity PRIVATE ${_strata_gpu_include_directories})
1044  target_link_libraries(rope_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1045  add_test(NAME rope_parity COMMAND rope_parity --selftest)
1046
1047  add_executable(quantize_act_parity src/kernels/quantize_act_parity.cpp)
1048  target_include_directories(quantize_act_parity PRIVATE ${_strata_gpu_include_directories})
1049  target_link_libraries(quantize_act_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1050  add_test(NAME quantize_act_parity COMMAND quantize_act_parity --selftest)
1051
1052  # the verify window's routing in one multi-column BF16 projection + one top-k, bitwise the per-token calls
1053  add_executable(route_window_parity src/kernels/route_window_parity.cpp)
1054  target_include_directories(route_window_parity PRIVATE ${_strata_gpu_include_directories})
1055  target_link_libraries(route_window_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1056  add_test(NAME route_window_parity COMMAND route_window_parity)
1057
1058  # STRATA_ROUTE_RESIDENT's swap: the warp-per-token kernel against a scalar reference of the same semantics,
1059  # bitwise on the ids, the weights and the four counters (GPU, synthetic, no model)
1060  add_executable(route_resident_parity src/kernels/route_resident_parity.cu)
1061  target_include_directories(route_resident_parity PRIVATE ${_strata_gpu_include_directories})
1062  target_link_libraries(route_resident_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1063  add_test(NAME route_resident_parity COMMAND route_resident_parity)
1064  set_tests_properties(route_resident_parity PROPERTIES TIMEOUT 120)
1065
1066  add_executable(router_top10_parity src/kernels/router_top10_parity.cpp)
1067  target_include_directories(router_top10_parity PRIVATE ${_strata_gpu_include_directories})
1068  target_link_libraries(router_top10_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1069  add_test(NAME router_top10_parity COMMAND router_top10_parity --selftest)
1070  # #783 PR-c: the multi-token router and the k = 10 float4 combine, bitwise against the single-token contracts
1071  add_executable(native_multi_parity src/kernels/native_multi_parity.cpp)
1072  target_include_directories(native_multi_parity PRIVATE ${_strata_gpu_include_directories})
1073  target_link_libraries(native_multi_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1074  add_test(NAME native_multi_parity COMMAND native_multi_parity)
1075  # #783 PR-d: the batched K/V append (INT8, Q4_0, the hybrid fold) against the per-cell appends, memcmp
1076  add_executable(kv_steps_parity src/kernels/kv_steps_parity.cpp)
1077  target_include_directories(kv_steps_parity PRIVATE ${_strata_gpu_include_directories})
1078  target_link_libraries(kv_steps_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1079  add_test(NAME kv_steps_parity COMMAND kv_steps_parity)
1080  # #783 PR-e: the device-built expert plan (parallel grouping + prefix scan) against a host replay of its contract
1081  add_executable(resident_plan_parity src/kernels/resident_plan_parity.cpp)
1082  target_include_directories(resident_plan_parity PRIVATE ${_strata_gpu_include_directories})
1083  target_link_libraries(resident_plan_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1084  add_test(NAME resident_plan_parity COMMAND resident_plan_parity)
1085  # #783 PR-g: the multi-token hyper-connection read/write (exact-T projections under them) against the single-token calls
1086  add_executable(gr_multi_parity src/kernels/gr_multi_parity.cpp)
1087  target_include_directories(gr_multi_parity PRIVATE ${_strata_gpu_include_directories})
1088  target_link_libraries(gr_multi_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1089  add_test(NAME gr_multi_parity COMMAND gr_multi_parity)
1090  # STRATA_HC_PERSIST=1: the persistent hyper-connection read against the default multi read (bounded, two runs bitwise),
1091  # and with the variable unset it never runs (a skip where the card cannot hold its 80 blocks, and on CUDA)
1092  add_executable(hc_persist_parity src/kernels/hc_persist_parity.cpp)
1093  target_include_directories(hc_persist_parity PRIVATE ${_strata_gpu_include_directories})
1094  target_link_libraries(hc_persist_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1095  add_test(NAME hc_persist_parity COMMAND hc_persist_parity)
1096  add_test(NAME hc_persist_default_off COMMAND hc_persist_parity --off)
1097  if(STRATA_HIP_GFX906)
1098    # the S6 router (STRATA_HIP_ROUTER_FAST=1 on gfx906) against the portable kernel, bitwise, on wave64
1099    add_executable(hip_router_fast tests/hip/router_fast.cpp)
1100    target_include_directories(hip_router_fast PRIVATE ${_strata_gpu_include_directories})
1101    target_link_libraries(hip_router_fast PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1102  endif()
1103
1104  add_executable(s_gemv_parity src/kernels/s_gemv_parity.cpp)
1105  target_include_directories(s_gemv_parity PRIVATE ${_strata_gpu_include_directories})
1106  target_link_libraries(s_gemv_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1107  add_test(NAME s_gemv_parity COMMAND s_gemv_parity --selftest)
1108
1109  add_executable(elementwise_parity src/kernels/elementwise_parity.cpp)
1110  target_include_directories(elementwise_parity PRIVATE ${_strata_gpu_include_directories})
1111  target_link_libraries(elementwise_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1112  add_test(NAME elementwise_parity COMMAND elementwise_parity --selftest)
1113
1114  add_executable(bf16_gemv_parity src/kernels/bf16_gemv_parity.cpp)
1115  target_include_directories(bf16_gemv_parity PRIVATE ${_strata_gpu_include_directories})
1116  target_link_libraries(bf16_gemv_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1117  add_test(NAME bf16_gemv_parity COMMAND bf16_gemv_parity --selftest)
1118
1119  # the V100 fusion work: every fused kernel against its unfused pipeline, bitwise, and the before/after
1120  # CUDA-event timings at decode shapes (`--bench`).  It is a .cu because it carries the unfused reference
1121  # kernels it compares against.
1122  if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA)
1123    add_executable(fusions_parity bench/micro/fusions_parity.cu)
1124    target_include_directories(fusions_parity PRIVATE ${_strata_gpu_include_directories})
1125    target_link_libraries(fusions_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1126    add_test(NAME fusions_parity COMMAND fusions_parity)
1127  endif()
1128
1129  add_executable(s_gemv_q8k_parity src/kernels/s_gemv_q8k_parity.cpp)
1130  target_include_directories(s_gemv_q8k_parity PRIVATE ${_strata_gpu_include_directories})
1131  target_link_libraries(s_gemv_q8k_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1132  add_test(NAME s_gemv_q8k_parity COMMAND s_gemv_q8k_parity --selftest)
1133
1134  add_executable(qsa_parity src/kernels/qsa_parity.cpp)
1135  target_include_directories(qsa_parity PRIVATE ${_strata_gpu_include_directories})
1136  target_link_libraries(qsa_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1137  add_test(NAME qsa_parity COMMAND qsa_parity --selftest)
1138
1139  # the QSA top-k the engine dispatches against the original kernel: identical ids on both sides of the register
1140  # kernel's reach, with tied and with equal scores (synthetic, no model)
1141  add_executable(qsa_topk_parity src/kernels/qsa_topk_parity.cpp)
1142  target_include_directories(qsa_topk_parity PRIVATE ${_strata_gpu_include_directories})
1143  target_link_libraries(qsa_topk_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1144  add_test(NAME qsa_topk_parity COMMAND qsa_topk_parity --selftest)
1145  # the register kernel from the smallest prompt batch (the line gfx1151 moves to 4096 blocks): same ids at every case
1146  add_test(NAME qsa_topk_parity_reg_always COMMAND qsa_topk_parity --selftest)
1147  set_tests_properties(qsa_topk_parity_reg_always PROPERTIES ENVIRONMENT "STRATA_TOPK_REG_MIN_BLOCKS=0")
1148
1149  # ---- P2.S4: the PLE n-gram hash, the IQ4_NL table read, and the PLE block ----
1150  # `ngram.cpp` is host-only but lives in `strata_kernels` because `ple.cu` shares its geometry constants, and
1151  # splitting them across two libraries would only add a layer.
1152  #
1153  # The pack, the original GGUF and the ggml capture are all REQUIRED inputs: this test's oracles are real
1154  # artifacts, so the working directory is pinned to the source tree and a missing input is a hard error
1155  # INSIDE the test.  A test that passes by finding nothing to compare is the failure mode this project keeps
1156  # re-learning.
1157  add_executable(ple_parity src/kernels/ple_parity.cpp)
1158  target_include_directories(ple_parity PRIVATE ${_strata_gpu_include_directories})
1159  target_link_libraries(ple_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1160  set(STRATA_PLE_FIXTURE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bench/micro" CACHE PATH
1161      "Directory containing required ple_in.bin and ple_out.bin parity fixtures")
1162  add_test(NAME ple_parity COMMAND ple_parity --selftest
1163    --in "${STRATA_PLE_FIXTURE_DIR}/ple_in.bin" --out "${STRATA_PLE_FIXTURE_DIR}/ple_out.bin"
1164    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1165  # STRATA_PLE_COMPACT: the raw IQ4_NL rows dequantized on the device against the host decode, bit for bit (synthetic, no model)
1166  add_executable(ple_iq4nl_dequant_test src/kernels/ple_iq4nl_dequant_test.cpp)
1167  target_include_directories(ple_iq4nl_dequant_test PRIVATE ${_strata_gpu_include_directories})
1168  target_link_libraries(ple_iq4nl_dequant_test PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1169  add_test(NAME ple_iq4nl_dequant_test COMMAND ple_iq4nl_dequant_test)
1170  set_tests_properties(ple_iq4nl_dequant_test PROPERTIES SKIP_RETURN_CODE 77)
1171
1172  # Plan v0.3 P7: INT8 KV storage vs a host reference and vs the FP16 path (GPU, synthetic, no model).
1173  add_executable(kv_q8_parity src/kernels/kv_q8_parity.cpp)
1174  target_include_directories(kv_q8_parity PRIVATE ${_strata_gpu_include_directories})
1175  target_link_libraries(kv_q8_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1176  add_test(NAME kv_q8_parity COMMAND kv_q8_parity)
1177
1178  # KV streaming (docs/kv-streaming-design.md): streamed vs resident attention, bitwise (GPU, synthetic, no model).
1179  add_executable(kv_stream_parity src/kernels/kv_stream_parity.cpp)
1180  target_include_directories(kv_stream_parity PRIVATE ${_strata_gpu_include_directories})
1181  target_link_libraries(kv_stream_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1182  add_test(NAME kv_stream_parity COMMAND kv_stream_parity)
1183
1184  # #2403: the verify window's KV calls on a streamed layer and on a ring (steps appends with the host copy, batched
1185  # resolve + attention, plain launches and graph replays), q4_0 / int8 / K8V4 (GPU, synthetic, no model).
1186  add_executable(kv_window_parity src/kernels/kv_window_parity.cpp)
1187  target_include_directories(kv_window_parity PRIVATE ${_strata_gpu_include_directories})
1188  target_link_libraries(kv_window_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1189  add_test(NAME kv_window_parity COMMAND kv_window_parity)
1190
1191  # PR #120: the hybrid K8V4 KV (INT8 K + rotated Q4_0 V) vs host references (GPU, synthetic, no model).
1192  add_executable(kv_hybrid_parity src/kernels/kv_hybrid_parity.cpp)
1193  target_include_directories(kv_hybrid_parity PRIVATE ${_strata_gpu_include_directories})
1194  target_link_libraries(kv_hybrid_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1195  add_test(NAME kv_hybrid_parity COMMAND kv_hybrid_parity)
1196  # PR #21: Q4_0 KV with Walsh-Hadamard rotation vs a host reference (GPU, synthetic, no model).
1197  add_executable(kv_q4_parity src/kernels/kv_q4_parity.cpp)
1198  target_include_directories(kv_q4_parity PRIVATE ${_strata_gpu_include_directories})
1199  target_link_libraries(kv_q4_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1200  add_test(NAME kv_q4_parity COMMAND kv_q4_parity)
1201  # the verify window's one-launch forms (hyper-connection write, PLE post-ops with the commit's
1202  # history snapshots) vs the per-token launches they replace, bitwise (GPU, synthetic, no model)
1203  add_executable(verify_batch_parity src/kernels/verify_batch_parity.cpp)
1204  target_include_directories(verify_batch_parity PRIVATE ${_strata_gpu_include_directories})
1205  target_link_libraries(verify_batch_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1206  add_test(NAME verify_batch_parity COMMAND verify_batch_parity)
1207  # #2234: the batch window's one-launch-for-all-rows kernels vs the per-row launches, bitwise (GPU, synthetic)
1208  add_executable(batch_rows_parity src/kernels/batch_rows_parity.cpp)
1209  target_include_directories(batch_rows_parity PRIVATE ${_strata_gpu_include_directories})
1210  target_link_libraries(batch_rows_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1211  add_test(NAME batch_rows_parity COMMAND batch_rows_parity)
1212  add_executable(cvec_parity src/kernels/cvec_parity.cpp)
1213  target_include_directories(cvec_parity PRIVATE ${_strata_gpu_include_directories})
1214  target_link_libraries(cvec_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1215  add_test(NAME cvec_parity COMMAND cvec_parity)
1216
1217  # The rewritten per-hit and grouped expert kernels vs the previous ones, bitwise (GPU, synthetic, no model).
1218  # `--bench` adds previous/new timings on engine-like shapes.
1219  add_executable(s2_expert_grouped_parity src/kernels/s2_expert_grouped_parity.cpp)
1220  target_include_directories(s2_expert_grouped_parity PRIVATE ${_strata_gpu_include_directories})
1221  target_link_libraries(s2_expert_grouped_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1222  add_test(NAME s2_expert_grouped_parity COMMAND s2_expert_grouped_parity --selftest)
1223
1224  # Plan v0.3 P3: native MMVQ for 1..8 tokens (bitwise selftest + --bench timing); synthetic data, no model.
1225  if(STRATA_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/bench/micro/native_mmvq_multi.cpp")
1226    add_executable(native_mmvq_multi bench/micro/native_mmvq_multi.cpp)
1227    target_include_directories(native_mmvq_multi PRIVATE ${_strata_gpu_include_directories})
1228    target_link_libraries(native_mmvq_multi PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1229    add_test(NAME native_mmvq_multi COMMAND native_mmvq_multi --selftest)
1230  endif()
1231
1232  # Plan v0.3 P0.1: working-set lock of a host region (CPU only).
1233  add_executable(platform_memory_test src/platform/memory_test.cpp)
1234  target_link_libraries(platform_memory_test PRIVATE strata_core ${_strata_gpu_runtime_target})
1235  add_test(NAME platform_memory_test COMMAND platform_memory_test)
1236  set_tests_properties(platform_memory_test PROPERTIES SKIP_RETURN_CODE 77)   # the system refused to lock the region (small memory-lock limit): skipped, with the reason printed
1237
1238  # The pinned-memory headroom (pin_budget.hpp) against a simulated ceiling; skips without a GPU.
1239  add_executable(pin_budget_test src/core/pin_budget_test.cpp)
1240  target_link_libraries(pin_budget_test PRIVATE strata_core ${_strata_gpu_runtime_target})
1241  add_test(NAME pin_budget_test COMMAND pin_budget_test)
1242
1243  # #3431: the expert arena's registered ranges keep their GPU aliases clear of the process's own memory (Windows HIP; else skips)
1244  add_executable(pinned_alias_test src/core/pinned_alias_test.cpp)
1245  target_link_libraries(pinned_alias_test PRIVATE strata_core ${_strata_gpu_runtime_target})
1246  add_test(NAME pinned_alias_test COMMAND pinned_alias_test)
1247  set_tests_properties(pinned_alias_test PROPERTIES SKIP_RETURN_CODE 77)
1248
1249  # #3350 / #3470: the conversation copy streams and events are pooled across short-lived threads (needs a device, else skips)
1250  add_executable(conversation_copy_streams_test src/core/conversation_copy_streams_test.cpp)
1251  target_include_directories(conversation_copy_streams_test PRIVATE include)
1252  target_link_libraries(conversation_copy_streams_test PRIVATE strata_core ${_strata_gpu_runtime_target})
1253  add_test(NAME conversation_copy_streams_test COMMAND conversation_copy_streams_test)
1254  set_tests_properties(conversation_copy_streams_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 120)
1255
1256  if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1257    add_executable(pinned_shared_test src/core/pinned_shared_test.cpp)
1258    target_link_libraries(pinned_shared_test PRIVATE strata_core ${_strata_gpu_runtime_target})
1259    add_test(NAME pinned_shared_test COMMAND pinned_shared_test)
1260  endif()
1261  if(WIN32)   # the replicas' shared expert arena as a named section (src/core/pinned.cu): two arenas, a child process, the last handle
1262    add_executable(pinned_shared_win_test src/core/pinned_shared_win_test.cpp)
1263    target_include_directories(pinned_shared_win_test PRIVATE include)
1264    target_link_libraries(pinned_shared_win_test PRIVATE strata_core ${_strata_gpu_runtime_target})
1265    add_test(NAME pinned_shared_win_test COMMAND pinned_shared_win_test)
1266    set_tests_properties(pinned_shared_win_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 180)
1267  endif()
1268
1269  # Plan v0.3 P2: the n-gram table read straight from the SSD. The selftest needs only the CPU and a temp file.
1270  add_executable(ple_reader_test src/ngram/ple_reader_test.cpp)
1271  target_include_directories(ple_reader_test PRIVATE ${_strata_gpu_include_directories})
1272  target_link_libraries(ple_reader_test PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1273  add_test(NAME ple_reader_selftest COMMAND ple_reader_test --selftest)
1274
1275  # #3602: the same reader under load - several clients, a tiny row cache, one in-flight slot, injected delays, rows on
1276  # every page phase, late-writer checks, the reader after a failed read. CPU and a temp file only; 77 = no direct reads here.
1277  add_executable(ple_reader_stress_test src/ngram/ple_reader_stress_test.cpp)
1278  target_include_directories(ple_reader_stress_test PRIVATE ${_strata_gpu_include_directories})
1279  target_link_libraries(ple_reader_stress_test PRIVATE strata_kernels ${_strata_gpu_runtime_target})
1280  add_test(NAME ple_reader_stress COMMAND ple_reader_stress_test)
1281  set_tests_properties(ple_reader_stress PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 300)
1282
1283  # 0.2.7: the PLE residency rule (table + expert arena + headroom); header-only, needs nothing
1284  add_executable(ple_residency_test src/core/ple_residency_test.cpp)
1285  target_include_directories(ple_residency_test PRIVATE include)
1286  add_test(NAME ple_residency_test COMMAND ple_residency_test)
1287
1288  # #4474: the automatic expert cache's slot rule (the late allocation priced); header-only, needs nothing
1289  add_executable(auto_cache_test src/core/auto_cache_test.cpp)
1290  target_include_directories(auto_cache_test PRIVATE include)
1291  add_test(NAME auto_cache_test COMMAND auto_cache_test)
1292
1293  # 0.2.7 (#3911): the qwen35 host sampler's penalties on a short (draft-vocab) logit row; header-only, CPU
1294  add_executable(qwen35_sampling_test src/qwen35/sampling_test.cpp)
1295  target_include_directories(qwen35_sampling_test PRIVATE include)
1296  add_test(NAME qwen35_sampling_test COMMAND qwen35_sampling_test)
1297
1298  # The GPU test runs ON THE TARGET PC. `--selftest` allocates
1299  # and writes real VRAM, so a machine without a device fails this test rather than skipping it silently -
1300  # which is correct: an engine that targets one GPU should not report a pass for having no GPU.
1301  if(STRATA_ENABLE_CUDA)
1302    add_test(NAME cuda_device_selftest COMMAND strata-device --selftest)
1303  else()
1304    add_test(NAME hip_device_selftest COMMAND strata-device --selftest)
1305  endif()
1306
1307  # ---- P2.S5: the GraphRegistry --------------------------------------------------
1308  # A .cu because the test needs real kernels to capture; it links `strata_core` and not `strata_kernels`,
1309  # because what it exercises is the capture machinery and not any kernel in it.
1310  if(STRATA_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/bench/micro/graph_registry_test.cu")
1311    add_executable(graph_registry_test bench/micro/graph_registry_test.cu)
1312    target_include_directories(graph_registry_test PRIVATE ${_strata_gpu_include_directories})
1313    target_link_libraries(graph_registry_test PRIVATE strata_core ${_strata_gpu_runtime_target})
1314    add_test(NAME graph_registry_test COMMAND graph_registry_test)
1315  endif()
1316
1317  # ---- P2.S5's GATE: is a device<->pinned-memory handoff graph-capturable? --------------------
1318  # The doorbell protocol puts the D2H of `x_f` and the miss list INSIDE G[l] - that is the whole overlap.  The
1319  # phase doc says to verify this "before building on it", and this project has already lost two rounds to
1320  # building first (a memory-only spin that DEADLOCKS on Windows, and a `cudaEventRecord` inside a capture that
1321  # is SILENTLY DROPPED).  It links only cudart: it is about the capture machinery, not about any kernel.
1322  if(STRATA_ENABLE_CUDA AND STRATA_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/bench/micro/pinned_capture.cu")
1323    add_executable(pinned_capture bench/micro/pinned_capture.cu)
1324    target_include_directories(pinned_capture PRIVATE ${_strata_gpu_include_directories})
1325    target_link_libraries(pinned_capture PRIVATE ${_strata_gpu_runtime_target})
1326    add_test(NAME pinned_capture COMMAND pinned_capture)
1327  endif()
1328
1329  # Tells tests/CMakeLists.txt to add the CUDA-dependent Catch2 target.  It cannot be declared there
1330  # unconditionally: tests/ is added at the end of this file, but the flag has to be known before it runs.
1331  if(STRATA_ENABLE_CUDA)
1332    set(STRATA_CUDA_TESTS ON)
1333  endif()
1334endif()
1335endmacro()