From 142568072a57a8f60aab7d11ec8fe22fa0678ecd Mon Sep 17 00:00:00 2001 From: dylanyunlon Date: Sat, 1 Aug 2026 01:29:47 +0800 Subject: [PATCH] fix(common.cuh): add threads >= 32 floor in scale_mem_bound Defensive guard: if SMEM cap computes max_threads_by_smem < 32 (or rounds to 0), floor at 32 (one warp). Prevents launching 0 threads which is undefined behavior. --- muh/include/muh/tuning/common.cuh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/muh/include/muh/tuning/common.cuh b/muh/include/muh/tuning/common.cuh index e319b575..6f6b6b3a 100644 --- a/muh/include/muh/tuning/common.cuh +++ b/muh/include/muh/tuning/common.cuh @@ -167,6 +167,13 @@ constexpr scaling_result scale_mem_bound( int threads = nominal_4B_threads < max_threads_by_smem ? nominal_4B_threads : max_threads_by_smem; + // Step 4: floor at one warp (32 threads) + // Defensive: if SMEM is so tight that max_threads_by_smem rounds to 0 + // (e.g. target_type_size=49152 and items=1 → raw=1 → round_up(1,32)=32, + // but if items were large enough to make raw=0 → round_up(0,32)=0), + // ensure we never launch 0 threads. + if (threads < 32) threads = 32; + return {items, threads}; // items-first, matching CCCL scaling_result }