Skip to content

[FIX] Use the opt-in shared memory limit in GetKernelWithMaxDynamicSharedMemory - #973

Merged
tqchen merged 4 commits into
apache:mainfrom
0z5a:fix-cubin-max-dyn-smem-optin
Nov 10, 2026
Merged

tqchen merged 4 commits into
apache:mainfrom
0z5a:fix-cubin-max-dyn-smem-optin

Conversation

@0z5a

@0z5a 0z5a commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #971

GetKernelWithMaxDynamicSharedMemory(name, -1) should allow the maximum dynamic shared memory the device permits, minus the kernel's static shared memory. It computed that limit from device attribute 8 (MaxSharedMemoryPerBlock), the 48 KiB default per-block limit. The attribute it set was therefore what a kernel can already use without opting in, and launches with more than 48 KiB of dynamic shared memory still failed with invalid argument.

This change queries attribute 97 (cudaDevAttrMaxSharedMemoryPerBlockOptin / CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN) instead. An explicit dynamic_smem_max and launches up to 48 KiB behave as before.

The new test_cubin_launcher_max_dynamic_smem loads a kernel with 1 KiB of static shared memory through GetKernelWithMaxDynamicSharedMemory(name, -1). It checks that maxDynamicSharedSizeBytes == optin - static, then launches with that much dynamic shared memory and checks the result. On GH200 (aarch64, sm_90) and B300 (sm_103) it fails on main (maxDynamicSharedSizeBytes=48128, expected 231424) and passes with this change. The three existing CUBIN tests still pass on both.

The new test is behind the existing torch.version.cuda > (13, 0) gate, like the other CUBIN tests. To run it with a cu130 torch ("13.0"), the gate was relaxed locally; that change is not part of this PR.

0z5a and others added 4 commits November 9, 2026 12:57
…aredMemory

`GetKernelWithMaxDynamicSharedMemory(name, -1)` is documented to allow
the maximum available dynamic shared memory (device max minus the
kernel's static shared memory). It computed that from device attribute
8 (`MaxSharedMemoryPerBlock`), the 48 KiB default per-block limit, so the
attribute it set was what a kernel can already use without opting in,
and launches with more than 48 KiB of dynamic shared memory still failed
with an invalid-argument error.

Query attribute 97 (`MaxSharedMemoryPerBlockOptin` /
`CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN`) instead. An
explicit `dynamic_smem_max` is unchanged.

Signed-off-by: 0z5a <[email protected]>
Signed-off-by: tqchen <[email protected]>
@tqchen
tqchen merged commit 99a7edd into apache:main Nov 10, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetKernelWithMaxDynamicSharedMemory(name, -1) caps dynamic shared memory at 48 KiB instead of the opt-in limit

2 participants