Skip to content

[BUG]: tileiras crashes (SIGSEGV in libnvvm) compiling a ct.load inside if j == 0: of a loop that follows another loop #147

Backlog

Description

@lifang535

Version

1.8.1 (pip); same with main 6b44cea (source build, which reports 9.9.99)

Version

13.5 (tileiras 13.5.37 from the nvidia-cuda-tileiras wheel); same with 13.4.92, 13.3.36 and 13.2.86

Which installation method(s) does this occur on?

Pip, Source

Describe the bug.

tileiras dies with SIGSEGV on this kernel for sm_80, sm_89, sm_90 and sm_120 at opt_level 1, 2 and 3 (opt_level=0 compiles). For sm_100 the float32 kernel compiles, but the int8 and int32 ones crash as well.

@ct.kernel
def load_in_if(Y, OUT, N):
    x = ct.zeros((256,), ct.float32)
    for i in range(N):
        x = ct.load(Y, (0,), (256,))
    for j in range(N):
        if j == 0:
            x = x + ct.load(Y, (0,), (256,))
    ct.store(OUT, (0,), x)

From controls/variants.py in the attachment.zip (sm_89): tiles of 256 and more elements crash, whatever the rank and the element type. It compiles with the load moved out of the if, without the first loop, with constant trip counts, with a while loop, with if j > 0 or if N == 3, with an else branch that updates x, and with 128 or fewer elements. If the loaded tile is broadcast ((1, 1, 4) onto (8, 8, 4)), it crashes at opt_level=0 too.

The crash is inside libnvvm. A signal handler preloaded into tileiras 13.5.37 gives these first frames:

libnvvm.so.4+0x176aaed  +0x25f4292  +0x25f54b0  +0x25f7dd8  +0x186f405  +0x1f7c1ed  +0x186b0d5  +0x17e9281 ...

With tileiras 13.4.92 and 13.3.36 it is inside libnvvm as well (crash_stack_*.log). The kernels are only compiled (export_kernel), so no GPU is needed.

#96 and #97 are also SIGSEGVs of tileiras, but with 13.5.37 both crash in tileiras itself (first frame tileiras+0x44b6963), so this looks like a different bug. NVIDIA/cuda-tile#29 (LoopSplit) compares the induction variable with a loop-carried value; here it is compared with a constant.

Minimum reproducible example

import importlib.metadata as md
import io
import sys

import cuda.tile as ct
from cuda.tile.compilation import ArrayConstraint, CallingConvention, KernelSignature, ScalarConstraint, export_kernel


@ct.kernel
def load_in_if(Y, OUT, N):           # the failing kernel
    x = ct.zeros((256,), ct.float32)
    for i in range(N):
        x = ct.load(Y, (0,), (256,))
    for j in range(N):
        if j == 0:
            x = x + ct.load(Y, (0,), (256,))
    ct.store(OUT, (0,), x)


@ct.kernel
def load_before_if(Y, OUT, N):       # control: the same kernel with the load moved out of the if
    x = ct.zeros((256,), ct.float32)
    for i in range(N):
        x = ct.load(Y, (0,), (256,))
    for j in range(N):
        y = ct.load(Y, (0,), (256,))
        if j == 0:
            x = x + y
    ct.store(OUT, (0,), x)


@ct.kernel
def no_first_loop(Y, OUT, N):        # control: only the second loop
    x = ct.zeros((256,), ct.float32)
    for j in range(N):
        if j == 0:
            x = x + ct.load(Y, (0,), (256,))
    ct.store(OUT, (0,), x)


ARR = ArrayConstraint(ct.float32, 1, index_dtype=ct.int32, stride_lower_bound_incl=0, alias_groups=(),
                      may_alias_internally=False, base_addr_divisible_by=16)
SIGNATURE = KernelSignature([ARR, ARR, ScalarConstraint(ct.int32)], CallingConvention.cutile_python_v2())
ARCHS = sys.argv[1:] or ["sm_80", "sm_89", "sm_90", "sm_120"]


def build(kernel, name, arch, opt_level):     # compile only, nothing is launched
    export_kernel(kernel.replace_hints(opt_level=opt_level), [SIGNATURE], io.BytesIO(), gpu_code=arch, output_format="cubin")
    print(f"{name:15s} {arch} opt_level={opt_level}: compiled", flush=True)


print("nvidia-cuda-tileiras", md.version("nvidia-cuda-tileiras"))
for arch in ARCHS:
    build(load_before_if, "load_before_if", arch, 3)
    build(no_first_loop, "no_first_loop", arch, 3)
    build(load_in_if, "load_in_if", arch, 0)
    if arch != ARCHS[-1]:
        try:
            build(load_in_if, "load_in_if", arch, 3)
        except ct.TileCompilerExecutionError as e:
            print(f"{'load_in_if':15s} {arch} opt_level=3: {type(e).__name__}: {str(e).splitlines()[0]}", flush=True)
build(load_in_if, "load_in_if", ARCHS[-1], 3)

Relevant log output

$ python repro.py      # cuda-tile 1.8.1 (pip) + nvidia-cuda-tileiras 13.5.37
nvidia-cuda-tileiras 13.5.37
load_before_if  sm_80 opt_level=3: compiled
no_first_loop   sm_80 opt_level=3: compiled
load_in_if      sm_80 opt_level=0: compiled
load_in_if      sm_80 opt_level=3: CompilerExecutionError: Return code -11
load_before_if  sm_89 opt_level=3: compiled
no_first_loop   sm_89 opt_level=3: compiled
load_in_if      sm_89 opt_level=0: compiled
load_in_if      sm_89 opt_level=3: CompilerExecutionError: Return code -11
load_before_if  sm_90 opt_level=3: compiled
no_first_loop   sm_90 opt_level=3: compiled
load_in_if      sm_90 opt_level=0: compiled
load_in_if      sm_90 opt_level=3: CompilerExecutionError: Return code -11
load_before_if  sm_120 opt_level=3: compiled
no_first_loop   sm_120 opt_level=3: compiled
load_in_if      sm_120 opt_level=0: compiled
Traceback (most recent call last):
  ...
subprocess.CalledProcessError: Command '['.../lib/python3.11/site-packages/nvidia/cu13/bin/tileiras', '<tmpdir>/load_in_ifykc3wrn6.bytecode', '-o', '<tmpdir>/load_in_ifykc3wrn6.cubin', '--gpu-name', 'sm_120', '-O3', ...]' died with <Signals.SIGSEGV: 11>.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "repro.py", line 62, in <module>
    build(load_in_if, "load_in_if", ARCHS[-1], 3)
  File "repro.py", line 48, in build
    export_kernel(kernel.replace_hints(opt_level=opt_level), [SIGNATURE], io.BytesIO(), gpu_code=arch, output_format="cubin")
  ...
cuda.tile._exception.CompilerExecutionError: Return code -11
Unknown location

Full env printout

Summary instead of the full print_env.sh output:
OS: Ubuntu 22.04.4 LTS, x86_64
Python 3.11.18
cuda-tile 1.8.1 (pip) and cutile-python main 6b44ceae (source build); nvidia-cuda-tileiras / nvidia-nvvm / nvidia-cuda-nvcc 13.5.37 (pip); other tileiras versions as described
Compile only (export_kernel with an explicit gpu_code); no GPU of these architectures was used

Other/Misc.

  • Versions: main 6b44cea and 1.8.1 with tileiras 13.5.37, 1.8.1 with 13.4.92 and 13.3.36 (sm_80, sm_89, sm_90 and sm_120 crash in all of them), 1.8.1 with 13.2.86 (sm_80 and sm_89 crash; it has no sm_90 target). So it is not a regression of 13.5.
  • attachment.zip: repro.py, controls/variants.py (30 kernels, run for sm_89 and sm_100), their outputs, and the crash stacks of three tileiras versions.

Contributing Guidelines

  • I agree to follow cuTile Python's contributing guidelines
  • I have searched the open bugs and have found no duplicates for this bug report

Activity

  1. added
    status: needs-triage
    on Nov 26, 2026
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

    bugstatus: needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions