Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9dda5de

Browse files
committed
Merge branch 'jg/doc-debug' into 'main'
Add debug section to doc See merge request dl/tileir/cutile-python!46
2 parents 148330b + 710169e commit 9dda5de

File tree

8 files changed

+62
-37
lines changed

8 files changed

+62
-37
lines changed

docs/source/debugging.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
..
3+
.. SPDX-License-Identifier: Apache-2.0
4+
5+
.. currentmodule:: cuda.tile
6+
7+
Debugging
8+
=========
9+
10+
Exception Types
11+
---------------
12+
13+
.. autoclass:: TileSyntaxError()
14+
.. autoclass:: TileTypeError()
15+
.. autoclass:: TileValueError()
16+
.. autoclass:: TileCompilerExecutionError()
17+
.. autoclass:: TileCompilerTimeoutError()
18+
19+
20+
Environment Variables
21+
---------------------
22+
23+
The following environment variables are useful when
24+
the above exceptions are encountered during kernel
25+
development.
26+
27+
Set ``CUDA_TILE_ENABLE_CRASH_DUMP=1`` to enable dumping
28+
an archive including the TileIR bytecode
29+
for submitting a bug report on :class:`TileCompilerExecutionError`
30+
or class:`TileCompilerTimeoutError`.
31+
32+
Set ``CUDA_TILE_COMPILER_TIMEOUT_SEC`` to limit the
33+
time the TileIR compiler `tileiras` can take.
34+
35+
Set ``CUDA_TILE_LOGS=CUTILEIR`` to print cuTile python
36+
IR during compilation to stderr. This is usefule when
37+
debugging :class:`TileTypeError`.
38+
39+
Set ``CUDA_TILE_TEMP_DIR`` to configure the directory
40+
for storing temporary files.

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ latest hardware features without having to rewrite your code.
4444
interoperability
4545
performance
4646
operations
47+
debugging

src/cuda/tile/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
)
4141

4242
from cuda.tile._exception import (
43-
TileCompilerError,
43+
TileCompilerExecutionError,
44+
TileCompilerTimeoutError,
4445
TileInternalError,
4546
TileSyntaxError,
4647
TileTypeError,
@@ -169,7 +170,8 @@
169170
"uint32",
170171
"uint64",
171172

172-
"TileCompilerError",
173+
"TileCompilerExecutionError",
174+
"TileCompilerTimeoutError",
173175
"TileInternalError",
174176
"TileSyntaxError",
175177
"TileTypeError",

src/cuda/tile/_compile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ def wrapper(*args, **kwargs):
6969
return wrapper
7070

7171

72-
def _get_final_ir(pyfunc, args) -> ir.Function:
72+
def _get_final_ir(pyfunc, args, tile_context) -> ir.Function:
7373
ir_ctx = ir.IRContext()
7474
func_ir: ir.Function = get_function_ir(pyfunc, ir_ctx, call_site=None)
7575
ir_args = func_ir.bind_arguments(args, get_constant_annotations(pyfunc))
76-
func_ir = infer_types_pass(func_ir, ir_args, pyfunc)
76+
func_ir = infer_types_pass(func_ir, ir_args, pyfunc, tile_context)
7777
dead_code_elimination_pass(func_ir)
7878

7979
if not CUDA_TILE_TESTING_DISABLE_TOKEN_ORDER:
@@ -145,7 +145,7 @@ def compile_tile(pyfunc,
145145
args,
146146
compiler_options: CompilerOptions,
147147
context: TileContext = default_tile_context) -> TileLibrary:
148-
func_ir = _get_final_ir(pyfunc, args)
148+
func_ir = _get_final_ir(pyfunc, args, context)
149149

150150
if 'CUTILEIR' in context.config.log_keys:
151151
code = (f"==== CuTile IR for {func_ir.qualname}==== \n\n"

src/cuda/tile/_debug.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,14 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import logging
65
import os
76

8-
# Comma separated string for selective debug logging
9-
# values are case in-sensitive
10-
CUDA_TILE_LOG_KEYS = {"CUTILEIR", "TILEIR"}
117

12-
13-
def parse_cuda_tile_logs_env():
14-
env = os.environ.get('CUDA_TILE_LOGS', "")
15-
ret = []
16-
for x in env.split(","):
17-
x = x.upper().strip()
18-
if len(x) == 0:
19-
continue
20-
if x not in CUDA_TILE_LOG_KEYS:
21-
raise RuntimeError(f"Unexpected value {x} in CUDA_TILE_LOGS, "
22-
f"supported values are {CUDA_TILE_LOG_KEYS}")
23-
ret.append(x)
24-
return ret
25-
26-
27-
CUDA_TILE_LOGS = parse_cuda_tile_logs_env()
8+
# Internal environment variables for debugging
289

2910
CUDA_TILE_DUMP_TILEIR = os.environ.get('CUDA_TILE_DUMP_TILEIR', None)
3011
CUDA_TILE_DUMP_BYTECODE = os.environ.get('CUDA_TILE_DUMP_BYTECODE', None)
31-
CUDA_TILE_TEMP_DIR = os.environ.get('CUDA_TILE_TEMP_DIR', None)
32-
33-
3412
CUDA_TILE_TESTING_DISABLE_DIV = (
3513
os.environ.get("CUDA_TILE_TESTING_DISABLE_DIV", "0") == "1")
36-
37-
3814
CUDA_TILE_TESTING_DISABLE_TOKEN_ORDER = (
3915
os.environ.get("CUDA_TILE_TESTING_DISABLE_TOKEN_ORDER", "0") == "1")
40-
41-
42-
logger = logging.getLogger(__name__)

src/cuda/tile/_exception.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ def __str__(self):
9494

9595

9696
class TileSyntaxError(TileError):
97+
"""Exception when a python syntax not supported by cuTile is encountered."""
9798
pass
9899

99100

100101
class TileTypeError(TileError):
102+
"""Exception when an unexpected type or |data type| is encountered."""
101103
pass
102104

103105

104106
class TileValueError(TileError):
107+
"""Exception when an unexpected python value is encountered."""
105108
pass
106109

107110

@@ -167,6 +170,7 @@ def __init__(self,
167170

168171

169172
class TileCompilerExecutionError(TileCompilerError):
173+
"""Exception when ``tileiras`` compiler throws an error."""
170174
def __init__(self,
171175
return_code: int,
172176
stderr: str,
@@ -180,6 +184,7 @@ def __init__(self,
180184

181185

182186
class TileCompilerTimeoutError(TileCompilerError):
187+
"""Exception when ``tileiras`` compiler timeout limit is exceeded."""
183188
def __init__(self,
184189
message: str,
185190
compiler_flags: str,

src/cuda/tile/_passes/typeinfer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
from types import FunctionType
1212
from typing import Tuple, Any, Optional, Sequence, Callable
1313

14-
from cuda.tile._debug import CUDA_TILE_LOGS
1514
from cuda.tile._exception import (
1615
TileTypeError,
1716
TileInternalError,
1817
ConstantNotFoundError, TileSyntaxError, Loc, TileError
1918
)
19+
from cuda.tile._cext import TileContext
2020
from cuda.tile._ir import ir
2121
from cuda.tile._ir.ir import Operation, Function, Block, Var, Argument, IRContext, TypedOperation
2222
from cuda.tile._ir.op_impl import op_implementations
@@ -359,12 +359,15 @@ def infer_types_in_func(context: TypingContext,
359359
return dataclasses.replace(func, parameters=tuple(new_params))
360360

361361

362-
def infer_types_pass(func: Function, args: Tuple[Argument, ...], pyfunc: FunctionType) -> Function:
362+
def infer_types_pass(func: Function,
363+
args: Tuple[Argument, ...],
364+
pyfunc: FunctionType,
365+
tile_context: TileContext) -> Function:
363366
context = TypingContext(func.root_block.ctx)
364367
try:
365368
return infer_types_in_func(context, func, args)
366369
except Exception as e:
367-
if 'CUTILEIR' in CUDA_TILE_LOGS:
370+
if 'CUTILEIR' in tile_context.config.log_keys:
368371
highlight_loc = e.loc if hasattr(e, 'loc') else None
369372
code = (f"====Partial CuTile IR for {func}==== \n\n"
370373
f"{func.to_string(highlight_loc=highlight_loc)}\n\n")

test/test_dce.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
from cuda.tile._ir.ops import Loop, Continue, Break
99
from cuda.tile._ir import ir
1010
from cuda.tile._compile import _get_final_ir
11+
from cuda.tile._cext import default_tile_context
1112

1213

1314
def get_ir(func) -> ir.Function:
1415
x = torch.zeros(10, device="cuda")
15-
ir = _get_final_ir(func, (x,))
16+
ir = _get_final_ir(func, (x,), default_tile_context)
1617
print(ir)
1718
return ir
1819

0 commit comments

Comments
 (0)