Skip to content

Commit 221615d

Browse files
Jay Gublinxt
authored andcommitted
Add cli for inspecting compilation cache with tileiras remarks
Signed-off-by: Jay Gu <jagu@.nvidia.com>
1 parent bd670a9 commit 221615d

13 files changed

Lines changed: 777 additions & 161 deletions

File tree

changelog.d/cache-log-cli.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Add a commandline interface for inspecting compilation history: ``cutile-cache log``.
2+
Compilation cache now includes metadata such as mangled kernel names,
3+
compiler versions, compilation dates, durations, and `tileiras` compiler
4+
remarks available starting 13.4.

docs/source/debugging.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,18 @@ Set ``CUDA_TILE_CACHE_SIZE`` to configure the maximum
5757
disk cache size in bytes. Oldest entries are evicted
5858
when the cache exceeds this limit. Defaults to
5959
2 GB (2147483648).
60+
61+
62+
Inspecting the Compilation Cache
63+
--------------------------------
64+
65+
Use the ``cutile-cache log`` command to page through cached compilations in
66+
most-recently-accessed order. Each entry shows the kernel's mangled name,
67+
compiler version, compilation date and duration, CUBIN size, and optimization
68+
remarks::
69+
70+
cutile-cache log
71+
72+
Compilation remarks are captured in YAML format when using ``tileiras`` 13.4
73+
or newer. Entries produced by earlier cuTile Python or compiler versions remain
74+
readable but may show metadata as unavailable.

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,24 @@ dependencies = [
3939
]
4040

4141
[project.optional-dependencies]
42-
tileiras = [ "cuda-toolkit[tileiras,nvcc,nvvm]>=13.2,<13.4" ]
42+
tileiras = [ "cuda-toolkit[tileiras,nvcc,nvvm]>=13.2,<13.5" ]
4343

4444
[project.urls]
4545
Homepage = "https://github.com/nvidia/cutile-python"
4646
Repository = "https://github.com/nvidia/cutile-python"
4747
documentation = "https://docs.nvidia.com/cuda/cutile-python"
4848
"Bug Tracker" = "https://github.com/nvidia/cutile-python/issues"
4949

50+
[project.scripts]
51+
cutile-cache = "cutile_cache._cli:main"
52+
5053
[tool.setuptools.dynamic]
5154
version = {file = "src/cuda/tile/VERSION"}
5255

5356
[tool.setuptools.packages.find]
5457
where = ["src"]
5558
include = [
59+
"cutile_cache",
5660
"cuda",
5761
"cuda.tile",
5862
"cuda.tile.compilation",

src/cuda/tile/_cache.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

src/cuda/tile/_compile.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import sys
1919
import tempfile
2020
import threading
21+
import time
2122
import traceback
2223
from types import FunctionType
2324
from typing import Optional, Sequence
@@ -63,7 +64,7 @@
6364
from cuda.tile._passes.dce import dead_code_elimination_pass
6465
from cuda.tile._passes.propagate_divby import add_divby_pass
6566
from cuda.tile._passes.token_order import token_order_pass
66-
from cuda.tile._cache import cache_key, cache_lookup, cache_store, evict_lru
67+
from cutile_cache._cache import MetadataV1, cache_key, cache_lookup, cache_store, evict_lru
6768
from cuda.tile._ir2bytecode import generate_bytecode_for_kernel
6869
from cuda.tile._version import __version__ as cutile_version
6970
import cuda.tile._bytecode as bc
@@ -547,9 +548,15 @@ def compile_tile(ann_func: AnnotatedFunction | FunctionType,
547548
f.write(bytecode_buf)
548549
f.flush()
549550

551+
capture_remarks = (cache_dir is not None
552+
and key is not None
553+
and _tileiras_supports_remarks(context.config.temp_dir))
554+
remarks_file = Path(f.name).with_suffix(".remarks.yaml") if capture_remarks else None
555+
compilation_start = time.perf_counter()
550556
try:
551557
cubin_file = compile_cubin(f.name, compiler_options, sm_arch,
552-
timeout_sec=context.config.compiler_timeout_sec)
558+
timeout_sec=context.config.compiler_timeout_sec,
559+
remarks_output_file=remarks_file)
553560
except TileCompilerError as e:
554561
if context.config.enable_crash_dump:
555562
anonymized_bytecode = _get_bytecode(ir_keeper, compiler_options,
@@ -560,10 +567,25 @@ def compile_tile(ann_func: AnnotatedFunction | FunctionType,
560567
e.compiler_flags, e.compiler_version)
561568

562569
raise e
570+
compilation_time = time.perf_counter() - compilation_start
563571
ret.cubin = Path(cubin_file).read_bytes()
564572

565573
if cache_dir is not None and key is not None:
566-
cache_store(cache_dir, key, ret.cubin)
574+
remarks = ""
575+
if capture_remarks:
576+
try:
577+
remarks = remarks_file.read_text(encoding="utf-8", errors="replace")
578+
except OSError:
579+
logger.debug("failed to read compilation remarks from %s",
580+
remarks_file, exc_info=True)
581+
metadata = MetadataV1(
582+
kernel_names=[signature.symbol or "" for signature in signatures],
583+
compiler_version=compiler_ver.strip() if compiler_ver else None,
584+
compilation_timestamp=time.time(),
585+
compilation_time_seconds=compilation_time,
586+
remarks=remarks,
587+
)
588+
cache_store(cache_dir, key, ret.cubin, metadata.to_dict())
567589
evict_lru(cache_dir, context.config.cache_size_limit)
568590

569591
return ret
@@ -752,6 +774,13 @@ def _get_max_supported_bytecode_version(temp_dir: str, allow_dev: bool = False)
752774
return BytecodeVersion.V_13_1
753775

754776

777+
def _tileiras_supports_remarks(temp_dir: str) -> bool:
778+
max_supported_version = _get_max_supported_bytecode_version(
779+
temp_dir, allow_dev=dev_features_enabled()
780+
)
781+
return max_supported_version >= BytecodeVersion.V_13_4
782+
783+
755784
def _find_compiler_in_default_cuda_toolkit_paths() -> tuple[str, str] | None:
756785
binary_name = "tileiras.exe" if is_windows() else "tileiras"
757786
for toolkit_path in _get_default_cuda_toolkit_paths():
@@ -812,7 +841,8 @@ def compile_cubin(
812841
fname_bytecode: str,
813842
compiler_options: CompilerOptions,
814843
sm_arch: str,
815-
timeout_sec: Optional[float]) -> Path:
844+
timeout_sec: Optional[float],
845+
remarks_output_file: str | os.PathLike | None = None) -> Path:
816846
binary = _find_compiler_bin()
817847
fname_cubin = Path(fname_bytecode).with_suffix(".cubin")
818848
effective_opt, use_device_debug = _tileiras_effective_opt_and_device_debug(
@@ -830,6 +860,12 @@ def compile_cubin(
830860
flags.append("--device-debug")
831861
else:
832862
flags.append("--lineinfo")
863+
if remarks_output_file is not None:
864+
flags.extend([
865+
"--remark-format=yaml",
866+
"--remarks=all",
867+
f"--remarks-output-file={remarks_output_file}",
868+
])
833869

834870
binary.run(args, flags, timeout_sec)
835871
return fname_cubin

src/cuda/tile/_context.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
from contextlib import contextmanager
77
import os
88
import shutil
9-
import sys
109
import tempfile
1110
from dataclasses import dataclass
1211
from typing import Optional
1312

13+
from cutile_cache._env import get_cache_dir_from_env
14+
1415

1516
@dataclass
1617
class TileContextConfig:
@@ -88,19 +89,6 @@ def get_enable_crash_dump_from_env() -> bool:
8889
return env in ("1", "true", "yes", "on")
8990

9091

91-
def get_cache_dir_from_env() -> Optional[str]:
92-
home_cache = os.path.join(os.path.expanduser("~"), ".cache")
93-
if sys.platform == "win32":
94-
base = os.environ.get("LOCALAPPDATA", home_cache)
95-
else:
96-
base = os.environ.get("XDG_CACHE_HOME", home_cache)
97-
default = os.path.join(base, "cutile-python")
98-
env = os.environ.get("CUDA_TILE_CACHE_DIR", default)
99-
if env.strip().lower() in ("0", "off", "none", ""):
100-
return None
101-
return env
102-
103-
10492
def get_cache_size_limit_from_env() -> int:
10593
return int(os.environ.get("CUDA_TILE_CACHE_SIZE", 1 << 31)) # 2GB
10694

src/cutile_cache/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""Lightweight support for inspecting the cuTile compilation cache."""

0 commit comments

Comments
 (0)