8000 [AOTInductor] Add wrapper and kernel code to debug code logging (#153… · pytorch/pytorch@01cbf5a · GitHub
[go: up one dir, main page]

Skip to content

Commit 01cbf5a

Browse files
benjaminglass1pytorchmergebot
authored andcommitted
[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: #153181 Approved by: https://github.com/desertfire
1 parent 01bb249 commit 01cbf5a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

torch/_inductor/codecache.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
from .runtime import autotune_cache
9999
from .runtime.autotune_cache import AutotuneCacheBundler
100100
from .triton_bundler import TritonBundler
101+
from .virtualized import V
101102

102103

103104
if config.is_fbcode():
@@ -1604,6 +1605,12 @@ def compile(
16041605
specified_dir=specified_output_path,
16051606
)
16061607

1608+
# Log the AOTInductor wrapper and kernel code, if needed.
1609+
with tempfile.NamedTemporaryFile("w+") as t:
1610+
t.writelines((wrapper_code, "\n", kernel_code, "\n"))
1611+
t.flush()
1612+
V.debug.output_code(t.name, extension="cpp")
1613+
16071614
if config.aot_inductor.package:
16081615
generated_files.append(wrapper_path)
16091616
if not config.aot_inductor.package_cpp_only:

torch/_inductor/debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ def draw_orig_fx_graph(
559559
dot_graph_shape=config.trace.dot_graph_shape,
560560
)
561561

562-
def output_code(self, filename: str) -> None:
563-
shutil.copy(filename, self.filename("output_code.py"))
562+
def output_code(self, filename: str, extension: str = "py") -> None:
563+
shutil.copy(filename, self.filename(f"output_code.{extension}"))
564564

565565
def log_inductor_triton_kernel_to_post_grad_node_info(
566566
self, filename: str = "inductor_triton_kernel_to_post_grad_nodes.json"

0 commit comments

Comments
 (0)
0