From d9b8283e7c089566eccc8d1f46de0aa4f7f1cd3c Mon Sep 17 00:00:00 2001 From: yanght24 Date: Fri, 21 Aug 2026 23:58:28 +0800 Subject: [PATCH] Fix tileiras SIGSEGV with occupancy=2 by retrying without occupancy hint Signed-off-by: yanght24 --- changelog.d/fix-occupancy-sigsegv-fallback.md | 1 + src/cuda/tile/_compile.py | 25 ++++++- src/cuda/tile/_exception.py | 1 + test/test_compiler_sigsegv_fallback.py | 69 +++++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 changelog.d/fix-occupancy-sigsegv-fallback.md create mode 100644 test/test_compiler_sigsegv_fallback.py diff --git a/changelog.d/fix-occupancy-sigsegv-fallback.md b/changelog.d/fix-occupancy-sigsegv-fallback.md new file mode 100644 index 00000000..48ccf9d6 --- /dev/null +++ b/changelog.d/fix-occupancy-sigsegv-fallback.md @@ -0,0 +1 @@ +Work around a `tileiras` SIGSEGV triggered by `occupancy=2` on some fused tile kernels by retrying compilation without the occupancy hint. diff --git a/src/cuda/tile/_compile.py b/src/cuda/tile/_compile.py index 5b091689..09dedaa5 100644 --- a/src/cuda/tile/_compile.py +++ b/src/cuda/tile/_compile.py @@ -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 @@ -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) diff --git a/src/cuda/tile/_exception.py b/src/cuda/tile/_exception.py index e67bd575..fe636193 100644 --- a/src/cuda/tile/_exception.py +++ b/src/cuda/tile/_exception.py @@ -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 diff --git a/test/test_compiler_sigsegv_fallback.py b/test/test_compiler_sigsegv_fallback.py new file mode 100644 index 00000000..41f8a243 --- /dev/null +++ b/test/test_compiler_sigsegv_fallback.py @@ -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]