Skip to content

Commit d9b8283

Browse files
committed
Fix tileiras SIGSEGV with occupancy=2 by retrying without occupancy hint
Signed-off-by: yanght24 <yanght24@gmail.com>
1 parent 9c3ee3c commit d9b8283

4 files changed

Lines changed: 95 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Work around a `tileiras` SIGSEGV triggered by `occupancy=2` on some fused tile kernels by retrying compilation without the occupancy hint.

src/cuda/tile/_compile.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import warnings
88
import contextlib
9-
from dataclasses import dataclass
9+
from dataclasses import dataclass, replace
1010
import datetime
1111
import functools
1212
from functools import cache
@@ -607,6 +607,29 @@ def compile_tile(ann_func: AnnotatedFunction | FunctionType,
607607
timeout_sec=context.config.compiler_timeout_sec,
608608
remarks_output_file=remarks_file)
609609
except TileCompilerError as e:
610+
if (isinstance(e, TileCompilerExecutionError)
611+
and getattr(e, "return_code", None) == -11
612+
and compiler_options.occupancy is not None):
613+
fallback_options = replace(compiler_options, occupancy=None)
614+
warnings.warn(
615+
"tileiras terminated with SIGSEGV while processing the requested "
616+
f"occupancy hint {compiler_options.occupancy!r}; retrying without an "
617+
"occupancy hint.",
618+
UserWarning,
619+
stacklevel=3,
620+
)
621+
return compile_tile(
622+
ann_func,
623+
signatures,
624+
sm_arch=sm_arch,
625+
compiler_options=fallback_options,
626+
context=context,
627+
bytecode_version=bytecode_version,
628+
return_final_ir=return_final_ir,
629+
return_bytecode=return_bytecode,
630+
return_cubin=return_cubin,
631+
)
632+
610633
if context.config.enable_crash_dump:
611634
anonymized_bytecode = _get_bytecode(ir_keeper, compiler_options,
612635
anonymize_debug_info=True)

src/cuda/tile/_exception.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def __init__(self,
269269
stderr: str,
270270
compiler_flags: str,
271271
compiler_version: Optional[str]):
272+
self.return_code = return_code
272273
message, loc = _parse_tileir_stderr(stderr)
273274
if loc is None:
274275
loc = _unknown_loc
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
from pathlib import Path
6+
7+
import cuda.tile as ct
8+
from cuda.tile._bytecode.version import BytecodeVersion
9+
from cuda.tile._cext import TileContext
10+
from cuda.tile._compile import compile_tile
11+
from cuda.tile._context import TileContextConfig
12+
from cuda.tile._exception import TileCompilerExecutionError
13+
from cuda.tile.compilation import ArrayConstraint, CallingConvention, KernelSignature
14+
15+
16+
def test_sigsegv_with_occupancy_falls_back_to_auto(monkeypatch, tmp_path):
17+
@ct.kernel(occupancy=2)
18+
def kernel(x, y):
19+
t = ct.load(x, (0,), shape=(32,))
20+
ct.store(y, (0,), tile=t)
21+
22+
constraint = ArrayConstraint(
23+
ct.float32,
24+
1,
25+
index_dtype=ct.int32,
26+
stride_lower_bound_incl=0,
27+
alias_groups=(),
28+
may_alias_internally=False,
29+
stride_constant=(1,),
30+
base_addr_divisible_by=16,
31+
)
32+
sig = KernelSignature(
33+
parameters=[constraint, constraint],
34+
calling_convention=CallingConvention.cutile_python_v1(),
35+
)
36+
37+
seen = []
38+
39+
def fake_compile_cubin(fname_bytecode, compiler_options, sm_arch, timeout_sec,
40+
remarks_output_file=None):
41+
seen.append(compiler_options.occupancy)
42+
if compiler_options.occupancy is not None:
43+
raise TileCompilerExecutionError(-11, "", "--gpu-name sm_120 -O2 --lineinfo",
44+
"13.3")
45+
cubin_path = Path(fname_bytecode).with_suffix(".cubin")
46+
cubin_path.write_bytes(b"FAKE_CUBIN")
47+
return cubin_path
48+
49+
monkeypatch.setattr("cuda.tile._compile.compile_cubin", fake_compile_cubin)
50+
context = TileContext(config=TileContextConfig(
51+
temp_dir=str(tmp_path),
52+
compiler_timeout_sec=None,
53+
enable_crash_dump=False,
54+
cache_dir=None,
55+
cache_size_limit=0,
56+
))
57+
58+
result = compile_tile(
59+
kernel._annotated_function,
60+
[sig],
61+
sm_arch="sm_120",
62+
compiler_options=kernel._compiler_options,
63+
context=context,
64+
bytecode_version=BytecodeVersion.V_13_3,
65+
return_cubin=True,
66+
)
67+
68+
assert result.cubin == b"FAKE_CUBIN"
69+
assert seen == [2, None]

0 commit comments

Comments
 (0)