From 0e83e7d56e60e05de5f6ccbb95aee498c7a739dc Mon Sep 17 00:00:00 2001 From: Nikita Shulga <2453524+malfet@users.noreply.github.com> Date: Sat, 8 Feb 2025 23:40:23 +0000 Subject: [PATCH] [EZ] Add logic to build Metal shader with debug info (#146768) By appending `-frecord-sources -gline-tables-only` to the compilation command Helpful when debugging shaders compiled into libtorch Test plan: Run `python ../tools/build_with_debinfo.py ../aten/src/ATen/native/mps/kernels/UpSample.metal ../aten/src/ATen/native/mps/operations/UpSample.mm` And then run following to capture shader and check that it contains debug info ```python import torch import os os.environ["MTL_CAPTURE_ENABLED"]="1" inp = torch.rand(size=(6, 3, 10, 20), device="mps", dtype=torch.float32) with torch.mps.profiler.metal_capture("bilinear2d"): out = torch.nn.functional.interpolate(x, scale_factor=(1.7,0.9), mode="bilinear") ``` image Pull Request resolved: https://github.com/pytorch/pytorch/pull/146768 Approved by: https://github.com/dcci --- tools/build_with_debinfo.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/build_with_debinfo.py b/tools/build_with_debinfo.py index 26c054bf2a0..0c9553b963e 100755 --- a/tools/build_with_debinfo.py +++ b/tools/build_with_debinfo.py @@ -78,6 +78,9 @@ def create_build_plan() -> list[tuple[str, str]]: if line.startswith(": &&") and line.endswith("&& :"): line = line[4:-4] line = line.replace("-O2", "-g").replace("-O3", "-g") + # Build Metal shaders with debug infomation + if "xcrun metal " in line and "-frecord-sources" not in line: + line += " -frecord-sources -gline-tables-only" try: name = line.split("-o ", 1)[1].split(" ")[0] rc.append((name, line))