Skip to content

[MLIR][ROCDL] Enable AsmVerbose when serializing to textual ISA#3177

Closed
fsx950223 wants to merge 2 commits into
amd-stagingfrom
flydsl-rocdl-asmverbose
Closed

[MLIR][ROCDL] Enable AsmVerbose when serializing to textual ISA#3177
fsx950223 wants to merge 2 commits into
amd-stagingfrom
flydsl-rocdl-asmverbose

Conversation

@fsx950223

Copy link
Copy Markdown

Summary

  • gpu-module-to-binary's ROCDL serialization path (SerializeGPUModuleBase / ModuleToObject::getOrCreateTargetMachine) builds its llvm::TargetMachine with a default-constructed TargetOptions, so AsmVerbose is off.
  • As a result, the AMDGPU AsmPrinter's per-kernel ; Kernel info: comment block (register usage, occupancy, LDS/scratch size) never appears in textual ISA output produced via this path -- only the .amdgpu_metadata YAML note survives, which has no Occupancy field (LLVM only computes/prints occupancy inside the verbose comment).
  • Adds a virtual ModuleToObject::getTargetOptions() hook (default {}, so NVVM and any other target keep current behavior) and overrides it in ROCDL's SerializeGPUModuleBase to set MCOptions.AsmVerbose = true.
  • AsmVerbose only affects the textual MCAsmStreamer path, not binary/object emission, so this is a no-op for format=binary/fatbin -- verified compiled binaries are unaffected, only format=isa/assembly output gains the comment block.

Motivation

Downstream (FlyDSL) wants to surface per-kernel occupancy/register info during compilation the same way Triton's llc-based codegen does. Without this, the only kernel info source is the incomplete .amdgpu_metadata note.

Test plan

  • Incremental ninja build of MLIRTargetLLVM/MLIRROCDLTarget succeeds with no warnings/errors (built and installed into a downstream FlyDSL toolchain).
  • Downstream: recompiled a real GPU kernel (pa_decode_ps_kernel) via gpu-module-to-binary{format=isa} and confirmed the ISA text now contains ; Kernel info: ... ; Occupancy: N, matching the AsmPrinter's actual register allocation (NumVgprs, NumSgprs, etc.).
  • clang-format --dry-run --Werror clean on all 4 changed files.
  • Full LLVM/MLIR test suite not re-run in this environment (only the affected libraries were rebuilt incrementally).

🤖 Generated with Claude Code

gpu-module-to-binary's ROCDL path builds its LLVM TargetMachine with a
default-constructed TargetOptions, so AsmVerbose is off and the AMDGPU
AsmPrinter's per-kernel "Kernel info" comment block (register usage,
occupancy, LDS/scratch size) never appears in emitted ISA text -- only
the .amdgpu_metadata YAML note, which lacks an Occupancy field since
LLVM only computes/prints that inside the verbose comment.

Add a virtual ModuleToObject::getTargetOptions() hook (default: {},
matching prior behavior for NVVM and other targets) and override it in
ROCDL's SerializeGPUModuleBase to set MCOptions.AsmVerbose = true. This
only affects textual assembly output (MCAsmStreamer), not binary/ELF
emission, so it is a no-op for `format=binary`/`fatbin`.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
fsx950223 added a commit to ROCm/FlyDSL that referenced this pull request Jul 3, 2026
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>
Only set MCOptions.AsmVerbose when the caller passes `-asm-verbose` in
gpu-module-to-binary's `opts` command line options, rather than
unconditionally enabling it for every ROCDL serialization. Callers that
don't need the AsmPrinter's per-kernel "Kernel info" comments keep the
prior (default off) behavior and output.

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

Copy link
Copy Markdown
Author

Updated: AsmVerbose is now opt-in via -asm-verbose in gpu-module-to-binary's opts argument (SerializeGPUModuleBase tokenizes the command line options and only sets MCOptions.AsmVerbose when the flag is present), rather than unconditionally enabled for every ROCDL serialization. Callers that don't pass -asm-verbose keep the prior default-off behavior/output byte-for-byte.

fsx950223 added a commit to ROCm/FlyDSL that referenced this pull request Jul 3, 2026
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>
@lamb-j

lamb-j commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Should be filed upstream https://github.com/llvm/llvm-project

@lamb-j lamb-j closed this Jul 5, 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