From 6037aee3b51e188dd4f910de1cdd1ce654e4e238 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Fri, 2 Oct 2026 22:05:43 +0200 Subject: [PATCH] fused_gr: STRATA_GR_DOWN_MAX4 read once (#443 follow-up) The switch was read with getenv on every launch_multi call, which runs per layer when decode is not captured in a graph. It is now read once, like the engine's other STRATA_* switches. --- src/kernels/cuda/fused_gr.cu | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cu index 6fd60aa6..c9d1b80d 100644 --- a/src/kernels/cuda/fused_gr.cu +++ b/src/kernels/cuda/fused_gr.cu @@ -779,10 +779,11 @@ void launch_multi(const GrMulti& m, int variant, cudaStream_t st, unsigned long for (int k = 0; k < ct; ++k) c.a[k] = m.a[c0 + k]; } const size_t smem = (size_t) ct * per_tok; - // Only bound per-thread token storage; retain the chosen tile, block - // size, accumulation order and upstream plain/split/staged path. - const char* max4_env = std::getenv("STRATA_GR_DOWN_MAX4"); - const bool max4 = ct <= 4 && max4_env && std::atoi(max4_env) != 0; + // #443, opt-in STRATA_GR_DOWN_MAX4=1: launches of up to 4 tokens hold 4 tokens' sums per thread instead of + // kFusedGrMaxT - the same tile, block size, accumulation order and plain/split/staged path, so the same bits + // (read once: this runs per layer when decode is not captured) + static const bool max4_on = [] { const char* v = std::getenv("STRATA_GR_DOWN_MAX4"); return v && std::atoi(v) != 0; }(); + const bool max4 = max4_on && ct <= 4; if (staged) { if (max4) gr_down_staged_kernel<4><<>>(c); else gr_down_staged_kernel<><<>>(c);