|
| 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