Skip to content

feat(compile): surface AMDGPU kernel resource-usage info during compile#796

Closed
fsx950223 wants to merge 3 commits into
mainfrom
worktree-triton-style-occupancy-info
Closed

feat(compile): surface AMDGPU kernel resource-usage info during compile#796
fsx950223 wants to merge 3 commits into
mainfrom
worktree-triton-style-occupancy-info

Conversation

@fsx950223

Copy link
Copy Markdown
Contributor

Summary

  • Add flydsl.utils.kernel_info.parse_kernel_info() / get_occupancy(), which parse LLVM's AMDGPU AsmPrinter ; Kernel info: comment block (NumVgprs, NumSgprs, Occupancy, LDSByteSize, ScratchSize, ...) out of ISA text, similar to how Triton exposes kernel.n_regs/occupancy via its llc-based codegen.
  • Wire it into jit_function._dump_isa (the existing FLYDSL_DUMP_IR=1 ISA-dump path) so compiling any kernel now prints [flydsl.compile] kernel info: {...} alongside the .s dump.

Dependency

This requires the companion LLVM/MLIR patch ROCm/llvm-project#3177, which enables AsmVerbose for the ROCDL gpu-module-to-binary serialization path. Without it, FlyDSL's codegen only emits the .amdgpu_metadata YAML note (no Occupancy field), and parse_kernel_info returns an empty dict.

Test plan

  • pytest tests/unit/test_kernel_info.py -v -- 3/3 pass (pure parser tests, l0_backend_agnostic, no GPU/build required).
  • scripts/check_python_style.sh --include-local clean.
  • End-to-end: compiled pa_decode_ps_kernel via tests/kernels/test_pa.py's run_pa_decode_ps_test with FLYDSL_DUMP_IR=1 against a toolchain built with the companion LLVM patch; confirmed [flydsl.compile] kernel info: {..., 'Occupancy': '3', 'NumVgprs': '130', ...} is printed and matches the real register allocation.

🤖 Generated with Claude Code

Parse LLVM's "; Kernel info:" AsmPrinter comment block (NumVgprs,
NumSgprs, Occupancy, LDS/scratch usage) out of the ISA text FLYDSL_DUMP_IR
already dumps, and print it during compilation. Requires the companion
ROCDL AsmVerbose patch in llvm-project for the comment block to be
emitted; the parser degrades gracefully to an empty dict otherwise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 3, 2026 08:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a small utility to parse AMDGPU “; Kernel info:” resource-usage comments from generated ISA, and wires it into the existing ISA dump path so compile-time dumps can surface register/LDS/occupancy information.

Changes:

  • Add flydsl.utils.kernel_info.parse_kernel_info() to extract key/value pairs from LLVM’s AMDGPU AsmPrinter “Kernel info” comment block.
  • Print parsed kernel resource info from jit_function._dump_isa() when FLYDSL_DUMP_IR=1 produces ISA text.
  • Add unit tests for the parser and occupancy helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
python/flydsl/utils/kernel_info.py New parser for AMDGPU “Kernel info” block (currently missing get_occupancy implementation and has slightly misleading doc wording).
python/flydsl/compiler/jit_function.py Hooks the parser into the ISA-dump path and prints parsed info when available.
tests/unit/test_kernel_info.py Adds unit tests for parsing and occupancy extraction (currently imports get_occupancy which isn’t defined).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +19
This is only emitted when the target machine is built with ``AsmVerbose``
on. FlyDSL's ROCDL serializer (``mlir/lib/Target/LLVM/ROCDL/Target.cpp``,
``SerializeGPUModuleBase::getTargetOptions()``) enables it, so
``jit_function._dump_isa``'s ``.s`` output always carries this block.

Comment thread python/flydsl/utils/kernel_info.py
Comment on lines +43 to +50
info: Dict[str, str] = {}
for line in isa_text[block_start:block_end].splitlines()[1:]:
line = line.lstrip(";").strip()
if ":" not in line:
continue
key, _, value = line.partition(":")
info[key.strip()] = value.strip()
return info
The companion LLVM patch (ROCm/llvm-project#3177) now makes ROCDL's
AsmVerbose an opt-in via `-asm-verbose` in gpu-module-to-binary's `opts`
argument rather than always-on, so pass it explicitly from _dump_isa.

Also restores flydsl.utils.kernel_info.get_occupancy(), which was
dropped from the previous commit by an editing mishap despite still
being imported by tests/unit/test_kernel_info.py.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@fsx950223

Copy link
Copy Markdown
Contributor Author

Pushed a follow-up commit:

  • The companion LLVM patch (ROCm/llvm-project#3177) now makes AsmVerbose opt-in via -asm-verbose rather than always-on, so _dump_isa now passes that flag explicitly in gpu-module-to-binary's opts argument.
  • Also fixes flydsl.utils.kernel_info.get_occupancy(), which had been accidentally dropped from the previous commit despite still being imported by the tests -- re-verified pytest tests/unit/test_kernel_info.py (3/3 pass) and re-ran the end-to-end pa_decode_ps_kernel compile against a toolchain built from the updated LLVM patch; kernel info still surfaces correctly.

No callers need the Occupancy field on its own; parse_kernel_info()
already exposes it as part of the full dict. Also corrects a stale
docstring claim that AsmVerbose is unconditionally enabled -- it's
opt-in via -asm-verbose as of the companion LLVM patch.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@fsx950223

Copy link
Copy Markdown
Contributor Author

Superseded — cherry-picked onto #613 (see comment there) since both touch jit_function.py and the reviewer would otherwise need to reconcile two separate PRs.

@fsx950223 fsx950223 closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants