Skip to content

[Inductor] Static CUDA launcher and AOTI can't load Triton kernels that need oversized shared memory #199308

Closed

Description

@mattteochen

🐛 Describe the bug

While tuning FP8/BF16 GEMMs with max-autotune on an sm_107 GPU, I noticed that configs whose Triton kernels use more shared memory than the per-block opt-in limit silently ran with num_stages=1 (much slower), and that AOTI-compiled models containing such kernels failed to launch.

The details below were drafted with Claude Code; I have reviewed and reproduced them.

On sm_107 a block can use more shared memory than
CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN, but only in the oversized
shared memory mode (CU_FUNC_ATTRIBUTE_SHARED_MEMORY_MODE =
CU_SHARED_MEMORY_MODE_ALLOW_OVERSIZED_SHARED_MEMORY, up to
CU_DEVICE_ATTRIBUTE_MAX_OVERSIZED_SHARED_MEMORY_PER_BLOCK). Triton compiles and
launches kernels against the larger limit, but Inductor's launchers only know the
opt-in limit:

  • Static CUDA launcher: the kernel fails to load with OutOfMemoryError, then
    compile_by_disabling_pipelining recompiles it with num_stages=1, so the run
    silently uses a much slower kernel. Default max-autotune configs are affected,
    e.g. bf16 mm (128, 128, 128, 4, 8).
  • AOTI / cpp_wrapper: the generated loadKernel sets
    CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, which can't exceed the opt-in
    limit, so launching the kernel fails with CUDA driver error: invalid argument.

Repro (AOTI, sm_107):

import torch, triton
import triton.language as tl

@triton.jit
def matmul_kernel(a_ptr, b_ptr, c_ptr, M, N, K,
                  BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr):
    offs_m = tl.program_id(0) * BLOCK_M + tl.arange(0, BLOCK_M)
    offs_n = tl.program_id(1) * BLOCK_N + tl.arange(0, BLOCK_N)
    offs_k = tl.arange(0, BLOCK_K)
    a_ptrs = a_ptr + offs_m[:, None] * K + offs_k[None, :]
    b_ptrs = b_ptr + offs_k[:, None] * N + offs_n[None, :]
    acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
    for _ in range(0, K, BLOCK_K):
        acc += tl.dot(tl.load(a_ptrs), tl.load(b_ptrs))
        a_ptrs += BLOCK_K
        b_ptrs += BLOCK_K * N
    tl.store(c_ptr + offs_m[:, None] * N + offs_n[None, :], acc.to(tl.bfloat16))

# 4 stages of 128x128 bf16 tiles: ~256 KiB of shared memory, above the opt-in limit
matmul = triton.autotune(
    configs=[triton.Config({"BLOCK_M": 128, "BLOCK_N": 128, "BLOCK_K": 128},
                           num_warps=8, num_stages=4)], key=[])(matmul_kernel)
M = N = K = 512

class Model(torch.nn.Module):
    def forward(self, a, b):
        c = torch.empty(M, N, device=a.device, dtype=torch.bfloat16)
        matmul[(M // 128, N // 128)](a, b, c, M, N, K)
        return c

a = torch.randn(M, K, device="cuda", dtype=torch.bfloat16)
b = torch.randn(K, N, device="cuda", dtype=torch.bfloat16)
ep = torch.export.export(Model(), (a, b), strict=True)
fn = torch._inductor.aoti_load_package(torch._inductor.aoti_compile_and_package(ep))
fn(a, b)  # RuntimeError: CUDA driver error: invalid argument

Error logs

RuntimeError: CUDA driver error: invalid argument                         # AOTI
OutOfMemoryError: out of resource: triton_tem_fused_mm_0 Required: 262160 Hardware limit:232448
  -> recompiled with num_stages=1                                          # static launcher

Versions

PyTorch version: 2.15.0a0+gite39c7e2
CUDA used to build PyTorch: 13.5
Triton: 3.8.0
OS: Ubuntu 24.04.5 LTS (aarch64)
GCC version: 13.3.0
Python version: 3.12.3
GPU: sm_107 (compute capability 10.7)

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo @avikchaudhuri @zhxchen17 @tugsbayasgalan @angelayi @ydwu4 @desertfire @yushangdi @iupaikov-amd @oulgen @davidberard98

Activity

  1. added
    triaged
    module: user triton
    on Oct 1, 2026
  2. added
    bot-triaged
    on Oct 1, 2026
  3. added a commit that references this issue on Nov 13, 2026
    4f89369
  4. added a commit that references this issue on Nov 13, 2026
    23aa27a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bot-triagedmodule: aotinductormodule: inductormodule: user tritononcall: exportoncall: pt2triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions