This is an automated email from the ASF dual-hosted git repository.
tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git
The following commit(s) were added to refs/heads/main by this push:
new a3a901945 [FIX][CUDA] Allow oversized dynamic shared memory without a
cluster launch (#256)
a3a901945 is described below
commit a3a9019450eb034b057f66cd3657f1edc9ed0bcd
Author: Hongyi Jin <[email protected]>
AuthorDate: Sat Nov 21 23:22:50 2026 -0500
[FIX][CUDA] Allow oversized dynamic shared memory without a cluster launch
(#256)
## Motivation
When a kernel asks for more dynamic shared memory than the opt-in limit
without setting `shared_memory_mode`, `PrepareResources` picks the
oversized mode automatically, which is the intended convenience. It also
requires a cluster launch, so a plain launch such as
```python
T.cuda.LaunchConfig(grid=..., block=..., dynamic_smem_bytes=300 * 1024)
```
fails at run time with "oversized shared memory needs a cluster launch".
CUDA has no such requirement: the oversized mode is an ordinary launch
attribute (`cudaLaunchAttributeSharedMemoryMode`) and works for
non-cluster launches. Users today must either add `cluster=1` or spell
`shared_memory_mode="allow_oversized"` explicitly to get the same
launch.
## Changes
- Drop the cluster requirement before selecting the oversized mode.
- Regenerate `launch_source.h`.
## Testing
- New `test_oversized_dynamic_shared_memory_without_cluster` (sm_107
only) launches 300 KB of dynamic shared memory with neither a cluster
nor an explicit mode.
- On other GPUs that test is skipped, and the rest of
`test_cuda_launch.py` passes on an sm_103a GPU.
---
src/backend/cuda/launch/launch_config.h | 2 +-
src/backend/cuda/launch/launch_source.h | 2 +-
tests/python/tirx/test_cuda_launch.py | 28 ++++++++++++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/backend/cuda/launch/launch_config.h
b/src/backend/cuda/launch/launch_config.h
index eaeef2b56..46ccbbf8f 100644
--- a/src/backend/cuda/launch/launch_config.h
+++ b/src/backend/cuda/launch/launch_config.h
@@ -214,7 +214,7 @@ inline void PrepareResources(typename API::Kernel kernel,
int device, LaunchValu
size_t bytes = config->Int(Field::kDynamicSmemBytes);
if (bytes + state->static_bytes > state->optin_bytes) {
#if CUDA_VERSION >= 13040 && CUDART_VERSION >= 13040
- Require(config->Has(Option::kCluster), "oversized shared memory needs a
cluster launch");
+ // The oversized mode is a launch attribute; CUDA does not require a
cluster launch.
config->SetInt(Field::kSharedMemoryMode, 3);
#else
throw std::invalid_argument("CUDA oversized shared memory requires CUDA
13.4 or newer");
diff --git a/src/backend/cuda/launch/launch_source.h
b/src/backend/cuda/launch/launch_source.h
index df5125f8a..83fdb4063 100644
--- a/src/backend/cuda/launch/launch_source.h
+++ b/src/backend/cuda/launch/launch_source.h
@@ -885,7 +885,7 @@ inline void PrepareResources(typename API::Kernel kernel,
int device, LaunchValu
size_t bytes = config->Int(Field::kDynamicSmemBytes);
if (bytes + state->static_bytes > state->optin_bytes) {
#if CUDA_VERSION >= 13040 && CUDART_VERSION >= 13040
- Require(config->Has(Option::kCluster), "oversized shared memory needs a
cluster launch");
+ // The oversized mode is a launch attribute; CUDA does not require a
cluster launch.
config->SetInt(Field::kSharedMemoryMode, 3);
#else
throw std::invalid_argument("CUDA oversized shared memory requires CUDA
13.4 or newer");
diff --git a/tests/python/tirx/test_cuda_launch.py
b/tests/python/tirx/test_cuda_launch.py
index e92013b78..4cdff6602 100644
--- a/tests/python/tirx/test_cuda_launch.py
+++ b/tests/python/tirx/test_cuda_launch.py
@@ -322,6 +322,34 @@ def test_increasing_dynamic_shared_memory(host, tmp_path):
tvm_tirx.testing.run_with_gpu_lock(check)
[email protected]
[email protected](
+ not env.has_cuda_compute(10, 7, exact=True), reason="requires sm_107
oversized shared memory"
+)
[email protected](not env.has_nvcc_version(13, 4), reason="requires CUDA
13.4 or newer")
[email protected]("host", ["llvm", "cuda_host"])
+def test_oversized_dynamic_shared_memory_without_cluster(host, tmp_path):
+ """Above the opt-in limit the runtime selects the oversized mode; no
cluster is needed."""
+
+ @T.function
+ def shared(A: T.Tensor((1,), "int32"), n: T.int32, bytes_: T.int32):
+ T.device_entry(launch=T.cuda.LaunchConfig(grid=1, block=32,
dynamic_smem_bytes=bytes_))
+ scratch = T.alloc_tensor(ty_args=[T.Tensor((n,), "int32",
scope="shared.dyn")])
+ if T.cuda.thread_idx("x") == 0:
+ scratch[n - 1] = n
+ A[0] = scratch[n - 1]
+
+ module, _ = _compile(shared, host, tmp_path)
+
+ def check():
+ out = tvm_tirx.runtime.empty((1,), "int32", tvm_tirx.cuda(0))
+ n = 300 * 1024 // 4
+ module["shared"](out, n, n * 4)
+ assert out.numpy()[0] == n
+
+ tvm_tirx.testing.run_with_gpu_lock(check)
+
+
def test_static_shared_memory_override_cannot_shrink_allocation():
@T.function
def kernel():