perf(test): gate benchmark loops and share GPU backend in test_deepseek4_unit

Merged
DU
3d ago
+268-244

Based on main (d552394eb). Reduces test_deepseek4_unit GPU runtime without removing any test cases or assertions.

What

  • Cause:
    • In main run 43754866765, test_deepseek4_unit took 21.3 s on R9700 (gfx1201) and 10.3 s on Strix Halo (gfx1151).
    • Four GPU test functions (test_ds4_flash_attention_streaming_topk_gpu, test_ds4_indexer_score_m32_gpu across 30 cases, test_ds4_indexer_score_packed_small_gpu across 4 cases, and test_ds4_topk_block_radix_gpu across 10 widths) ran unguarded measure_us microbenchmark loops (~8,355 unasserted GPU graph launches) during every default ctest run, whereas test_ds4_flash_attention_segmented_kv_gpu and test_ds4_flash_attention_sparse_value_skip_gpu already gate timing on bool benchmark.
    • Single-device GPU tests called ggml_backend_cuda_init(0) and ggml_backend_free() 31 separate times inside the same process.
  • Fix (server/test/unit/test_deepseek4_unit.cpp):
    • Gate the measure_us timing loops in those four functions behind bool benchmark = false, preserving every functional check and assertion in default runs, and pass benchmark = true from the --bench-streaming-attn, --bench-indexer, and --bench-topk CLI flags.
    • Reuse a single shared device-0 GPU backend (get_shared_gpu_backend(), released by SharedGpuBackendGuard on main() exit) across single-device GPU tests. Multi-device test_hc_scratch_per_device and test_cuda_graph_rebuild_generation_guard keep their own dedicated backend instances.

Tests

  • Verified syntax and warnings locally with g++ -std=c++17 -fsyntax-only -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -DLUCE_BACKEND_CUDA=1 -DGGML_USE_CUDA and validated the commit message with .github/ci/check_commit_messages.py.
  • Full GPU execution and timing delta will be verified by the dgx-gb10 (CUDA) and lucebox3 (ROCm R9700 + Strix Halo) CI jobs.

Known limits, not addressed here

  • Scoped solely to server/test/unit/test_deepseek4_unit.cpp; other unit test binaries are unchanged.