You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Kernel dispatch uses incorrect block_dim due to shared mutable state #1254
Kernel dispatch can use the wrong block_dim value when the same module is loaded on different devices (CPU vs CUDA), causing out-of-bounds shared memory access and runtime failures.
Module.options["block_dim"] is shared mutable state that gets permanently modified by each load() call. Several code paths don't explicitly pass block_dim to Module.load(), causing them to use stale values from previous launches:
Launch.__init__() (line 7060) - Used for command recording
get_module_identifier() (line 2648) - Used for module hash calculation
This creates a race condition where a module compiled for one block dimension can be loaded for execution with a different dimension.
The immediate bug was addressed in 9435922. But there's probably room for improvement. Copying the discussion on the code review here:
I'm not sure if I have the best solution here. Currently kernel execution on the CPU only supports block_dim=1 , and we enforce that in launch() and launch_tiled() but then have to pass it to other parts correctly, which is what this MR fixes.
I'll see if there's a more elegant solution by doing the override at a later point, like at load(). I also question whether we should really be altering the whole module's block_dim (which I believe should act as a default if not provided). It currently defines WP_TILE_BLOCK_DIM at the .cu level, but perhaps we should use blockDim instead?
Yeah I remember this being a messy issue, but we didn't have a better solution at the time. As you mention it defines WP_TILE_BLOCK_DIM, but that is used in several compile-time definitions so I don't think switching to blockDim would be feasible. There might be a better solution on the Python side.
Activity
c0d1f1ed commentedon Feb 24, 2026
The immediate bug was addressed in 9435922. But there's probably room for improvement. Copying the discussion on the code review here:
Merge branch 'ncapens/fix-block-dim-dispatch' into 'main'