Repository navigation
Link GPU device code to the conceptual stmt in the html output (simplified alternative to #9691) - #9713
Draft
mcourteaux wants to merge 1 commit into
Draft
Link GPU device code to the conceptual stmt in the html output (simplified alternative to #9691)#9713mcourteaux wants to merge 1 commit into
mcourteaux wants to merge 1 commit into
Conversation
mcourteaux
force-pushed
the
mcourteaux/gpu-debug-symbols-alt
branch
from
November 22, 2026 18:52
af257b6 to
5729392
Compare
The conceptual_stmt_html output links the device code of GPU kernels to the conceptual stmt it was made from, for CUDA and for the APIs with C-like source (OpenCL, Metal, D3D12, WebGPU), in the same way as the assembly: by line of IR, and within a line by IR node. Lowering prints the conceptual stmt with its source map before the GPU loops are offloaded, and each device code generator says where in it each line of its output came from. The Module keeps that per device code buffer, for the html. - The C-like code generators note where print_stmt() and print_expr() print each Stmt and Expr. The line that assigns the value of an Expr is left to that Expr, after the lines of its operands. - PTX is compiled with line tables that point into the conceptual stmt. The .loc directives are read, for their line and column, and taken out of the device code again. - A Stmt that was rewritten since the conceptual stmt was printed is found by the first node within it that was printed (StmtSourceMap::find_within). The device code itself is unchanged. CodeGen_LLVM::init_debug_info() takes the source to point into; compile() prints one itself if it has to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011FRemhS639vq75urwV44oe
mcourteaux
force-pushed
the
mcourteaux/gpu-debug-symbols-alt
branch
from
November 22, 2026 19:37
5729392 to
a3cb0ae
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## mcourteaux/llvm-debug-symbols-alt #9713 +/- ##
=====================================================================
+ Coverage 73.62% 73.84% +0.22%
=====================================================================
Files 266 266
Lines 83009 83146 +137
Branches 20589 20631 +42
=====================================================================
+ Hits 61113 61397 +284
+ Misses 15399 15292 -107
+ Partials 6497 6457 -40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #9712, which is stacked on #9711 and #9710. Draft: this is a simplified alternative to #9691, for comparing the two side by side.
What this does
The
conceptual_stmt_htmloutput links the device code of GPU kernels to the conceptual stmt it was made from, for CUDA (PTX) and for the APIs whose device code is C-like source (OpenCL, Metal, D3D12, WebGPU), in the same way as #9712 links the assembly: by line of IR, and within a line by IR node. Hover IR to see its device code, double-click to keep it shown and go there, and the same from device code to its IR.The device code itself is unchanged, and has no line information in it. Device code that isn't text to read, like SPIR-V, is not linked.
How it works
Lowering prints the conceptual stmt with its source map before the GPU loops are offloaded, and each device code generator says where in it each line of its output came from: the line, and the IR node (
CodeGen_GPU_Dev::source_lines). The Module keeps that per device code buffer, for the html.CodeGen_C::print_stmt()andprint_expr()note where they print each Stmt and Expr, and where that is in the conceptual stmt. A shared helper turns that into a position per line of source. The line that assigns the value of an Expr is left to that Expr, after the lines of its operands..locdirectives, for their line and column, and takes them out again.StmtSourceMap::find_within). Bind let names in a scope in CodeGen_C instead of substituting #9710 makes sureCodeGen_Citself no longer rebuilds what it prints.What is different from #9691
gpu_debug_symbolstarget feature: no.locin the PTX of the pipeline, and no#linedirectives in C-like source. This is for the html only.remember_replaced), and no set of all the nodes of the conceptual stmt.Output and performance
The C source of four pipelines on CUDA, OpenCL, Metal, D3D12 and WebGPU targets, with the device code embedded in it, is the same as on main apart from the operand order that #9710 describes. That includes the PTX after its line information is taken out.
Lowering time of the generators in
apps/, withtools/benchmark_apps_generators.py(-e stmt, wall clock, mean of 3 runs), main against #9712 and this PR. With a GPU target, lowering includes compiling the kernels to device code. Two of the 72 generators fail to build or run on all three, and are left out.host-cudahost-openclThe time of the lowering passes themselves hardly moves (1.007x). The extra time is outside of them, which is where printing the conceptual stmt and keeping track of where the device code came from are. No single generator moves beyond the noise.
Screenshots
Taken with headless Chrome, of a small pipeline with a kernel that computes one Func at the tiles of another, with rainbow parentheses on.
OpenCL: the first
+of the sum of three loads double-clicked in the conceptual stmt. The lines of OpenCL C of that sum have the color of the operator each was generated for, and the rest of the statement is marked faintly. The bar is in front of the line of the+itself:CUDA: the same operator, with the PTX made from it:
OpenCL in the classic dark color scheme:
Tests
correctness_debug_symbolschecks, for CUDA and OpenCL, that the device code has no line information in it, and that the html links lines of device code to lines of the conceptual stmt that have IR on them. For OpenCL it also checks that the call ofsinin the source is linked to the Stmt that calls it. It also checks that the device code is linked to several IR nodes. For the kernel of the screenshots, 62 of the 88 lines of OpenCL C are linked to 56 nodes, and 97 of the 212 lines of PTX to 41 nodes; the others are declarations, labels and the like.The linking for Metal, D3D12 and WebGPU shares the code of OpenCL, but has no test of its own.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FRemhS639vq75urwV44oe