Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fix-occupancy-sigsegv-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Work around a `tileiras` SIGSEGV triggered by `occupancy=2` on some fused tile kernels by retrying compilation without the occupancy hint.
25 changes: 24 additions & 1 deletion src/cuda/tile/_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import warnings
import contextlib
from dataclasses import dataclass
from dataclasses import dataclass, replace
import datetime
import functools
from functools import cache
Expand Down Expand Up @@ -607,6 +607,29 @@ def compile_tile(ann_func: AnnotatedFunction | FunctionType,
timeout_sec=context.config.compiler_timeout_sec,
remarks_output_file=remarks_file)
except TileCompilerError as e:
if (isinstance(e, TileCompilerExecutionError)
and getattr(e, "return_code", None) == -11
and compiler_options.occupancy is not None):
fallback_options = replace(compiler_options, occupancy=None)
warnings.warn(
"tileiras terminated with SIGSEGV while processing the requested "
f"occupancy hint {compiler_options.occupancy!r}; retrying without an "
"occupancy hint.",
UserWarning,
stacklevel=3,
)
return compile_tile(
ann_func,
signatures,
sm_arch=sm_arch,
compiler_options=fallback_options,
context=context,
bytecode_version=bytecode_version,
return_final_ir=return_final_ir,
return_bytecode=return_bytecode,
return_cubin=return_cubin,
)

if context.config.enable_crash_dump:
anonymized_bytecode = _get_bytecode(ir_keeper, compiler_options,
anonymize_debug_info=True)
Expand Down
1 change: 1 addition & 0 deletions src/cuda/tile/_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def __init__(self,
stderr: str,
compiler_flags: str,
compiler_version: Optional[str]):
self.return_code = return_code
message, loc = _parse_tileir_stderr(stderr)
if loc is None:
loc = _unknown_loc
Expand Down
69 changes: 69 additions & 0 deletions test/test_compiler_sigsegv_fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0

from pathlib import Path

import cuda.tile as ct
from cuda.tile._bytecode.version import BytecodeVersion
from cuda.tile._cext import TileContext
from cuda.tile._compile import compile_tile
from cuda.tile._context import TileContextConfig
from cuda.tile._exception import TileCompilerExecutionError
from cuda.tile.compilation import ArrayConstraint, CallingConvention, KernelSignature


def test_sigsegv_with_occupancy_falls_back_to_auto(monkeypatch, tmp_path):
@ct.kernel(occupancy=2)
def kernel(x, y):
t = ct.load(x, (0,), shape=(32,))
ct.store(y, (0,), tile=t)

constraint = ArrayConstraint(
ct.float32,
1,
index_dtype=ct.int32,
stride_lower_bound_incl=0,
alias_groups=(),
may_alias_internally=False,
stride_constant=(1,),
base_addr_divisible_by=16,
)
sig = KernelSignature(
parameters=[constraint, constraint],
calling_convention=CallingConvention.cutile_python_v1(),
)

seen = []

def fake_compile_cubin(fname_bytecode, compiler_options, sm_arch, timeout_sec,
remarks_output_file=None):
seen.append(compiler_options.occupancy)
if compiler_options.occupancy is not None:
raise TileCompilerExecutionError(-11, "", "--gpu-name sm_120 -O2 --lineinfo",
"13.3")
cubin_path = Path(fname_bytecode).with_suffix(".cubin")
cubin_path.write_bytes(b"FAKE_CUBIN")
return cubin_path

monkeypatch.setattr("cuda.tile._compile.compile_cubin", fake_compile_cubin)
context = TileContext(config=TileContextConfig(
temp_dir=str(tmp_path),
compiler_timeout_sec=None,
enable_crash_dump=False,
cache_dir=None,
cache_size_limit=0,
))

result = compile_tile(
kernel._annotated_function,
[sig],
sm_arch="sm_120",
compiler_options=kernel._compiler_options,
context=context,
bytecode_version=BytecodeVersion.V_13_3,
return_cubin=True,
)

assert result.cubin == b"FAKE_CUBIN"
assert seen == [2, None]