[AOTInductor] Add wrapper and kernel code to debug code logging (#153181)

This is a simple PR to make the AOTInductor wrapper and kernel code get output by `TORCH_COMPILE_DEBUG=1`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/153181
Approved by: https://github.com/desertfire
This commit is contained in:
Benjamin Glass 2025-05-10 15:31:18 +00:00 committed by PyTorch MergeBot
parent 01bb249978
commit 01cbf5a30a
2 changed files with 9 additions and 2 deletions

View File

@ -98,6 +98,7 @@ from .remote_cache import create_cache
from .runtime import autotune_cache
from .runtime.autotune_cache import AutotuneCacheBundler
from .triton_bundler import TritonBundler
from .virtualized import V
if config.is_fbcode():
@ -1604,6 +1605,12 @@ class AotCodeCompiler:
specified_dir=specified_output_path,
)
# Log the AOTInductor wrapper and kernel code, if needed.
with tempfile.NamedTemporaryFile("w+") as t:
t.writelines((wrapper_code, "\n", kernel_code, "\n"))
t.flush()
V.debug.output_code(t.name, extension="cpp")
if config.aot_inductor.package:
generated_files.append(wrapper_path)
if not config.aot_inductor.package_cpp_only:

View File

@ -559,8 +559,8 @@ class DebugFormatter:
dot_graph_shape=config.trace.dot_graph_shape,
)
def output_code(self, filename: str) -> None:
shutil.copy(filename, self.filename("output_code.py"))
def output_code(self, filename: str, extension: str = "py") -> None:
shutil.copy(filename, self.filename(f"output_code.{extension}"))
def log_inductor_triton_kernel_to_post_grad_node_info(
self, filename: str = "inductor_triton_kernel_to_post_grad_nodes.json"