1818import sys
1919import tempfile
2020import threading
21+ import time
2122import traceback
2223from types import FunctionType
2324from typing import Optional , Sequence
6364from cuda .tile ._passes .dce import dead_code_elimination_pass
6465from cuda .tile ._passes .propagate_divby import add_divby_pass
6566from 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
6768from cuda .tile ._ir2bytecode import generate_bytecode_for_kernel
6869from cuda .tile ._version import __version__ as cutile_version
6970import 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+
755784def _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
0 commit comments