[Comgr][hotswap] Add code-object metadata parsing#2437
Conversation
81e6053 to
d1a05c9
Compare
2675e92 to
3831ee0
Compare
d1a05c9 to
8be9478
Compare
|
Thanks for putting this up. Two main pieces of feedback, both around the AGENT_CONVENTIONS "Comgr first, LLVM second, custom never" rule. The below is obv Claude's thoughts. But in general, we can beef up the existing Comgr metadata API implementations if we need to support Hotswap's needs. I think that could benefit both "sub-projects". Reuse existing Comgr metadata APIs
Switching to
The Comgr internal helpers take The one piece that's genuinely new is Reuse existing LLVM facilitiesA few hand-rolled bits that already exist in
Most of these collapse into the Comgr reuse above (the note iteration disappears entirely if you go through |
|
We really really really need to pull out common functionality that is shared between the transpiler and the translator into a singular module. We will have to suffer from a lot of code duplication later otherwise. |
3831ee0 to
9f6c2ed
Compare
8be9478 to
6ab4011
Compare
9f6c2ed to
ec69509
Compare
6ab4011 to
dd6bb68
Compare
ec69509 to
3b59a99
Compare
94e24d0 to
d6f97c5
Compare
d6f97c5 to
2b8bfde
Compare
|
For the new source files, should we use code-object-utils.cpp instead of code_object_utils.cpp? Not a defined convention and looks like we deviate from LLVM on this (which would use CodeObjectUtils.cpp). But probably best to follow existing practice |
3b59a99 to
91c4a7e
Compare
2b8bfde to
70e5099
Compare
91c4a7e to
cceb980
Compare
70e5099 to
73d63ce
Compare
cceb980 to
7b8ccf2
Compare
4314144 to
7fde156
Compare
Lands the minimal scaffolding
needed to build a `hotswap-transpiler` static library:
* `raiser.{hpp,cpp}` — `raiseToIR()` entry point. The implementation
creates an `llvm::Module` with a single `ret void` AMDGPU kernel
function for any input. ELF ingestion, MC disassembly and the
per-format raise handlers land in subsequent patches.
* `raise_failure.{hpp,cpp}` — structured failure values consumed by
`RaiseResult::failure`.
* `code_object_utils.h` — `KernelMeta` struct used in the
`raiseToIR` signature.
* Minimal `CMakeLists.txt` linking only `LLVMCore`, `LLVMSupport`,
`LLVMTargetParser`. The full library/include surface grows
incrementally as later patches need it.
* `tests/raiser_empty_module_test.cpp` (gtest) verifies the
scaffolding contract: an empty input produces a well-formed
module with one `AMDGPU_KERNEL` function whose body is `ret void`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds the AMDGPU code-object metadata extraction surface that the rest of
the raiser pipeline depends on:
* `extractTextSection`, `listKernelNames`, `extractKernelMeta`,
`findKernelSymbolOffset`, and `detectIsaFromElf` in
`hotswap/code_object_utils.{h,cpp}`.
* `KernelMeta` populated with both MsgPack-derived fields (kernarg/group/
private segment sizes, args) and the raw kernel-descriptor register
bytes (`compute_pgm_rsrc{1,2}`, `kernel_code_properties`,
`kernarg_preload`) read from `<name>.kd` in `.rodata`. Later layers
(`UserSgprLayout`, kernarg layout) consume these.
Reuses comgr's existing parsing infrastructure rather than duplicating
it. Two new `MemoryBufferRef`-friendly entry points are added to
`comgr-metadata.{h,cpp}` so hotswap can call them without going through
the `DataObject` / `DataMeta` ceremony of the public API:
* `metadata::walkElfMetadataIntoDoc(MemoryBufferRef, msgpack::Document&,
bool& EmitIntegerBooleans)` — walks PT_NOTE program headers and
SHT_NOTE sections, recognises `NT_AMD_HSA_METADATA` (YAML, name="AMD"),
`NT_AMDGPU_METADATA` (MsgPack, name="AMDGPU"), and the PAL note
(type 13). `getMetadataRoot(DataObject*, DataMeta*)` is reduced to a
thin wrapper around it.
* `metadata::getElfIsaNameFromBuffer(MemoryBufferRef, std::string&)` —
produces the canonical `amdgcn-amd-amdhsa--<gfx>:sramecc±:xnack±`
string. `getElfIsaName(DataObject*, std::string&)` delegates.
The existing internal templates (`mergeNoteRecords`, `processElfNote`,
`walkElfMetadata`, `getElfIsaNameFromElfHeader`) stay in
`comgr-metadata.cpp`'s anonymous namespace as the single source of
truth.
Includes a small focused gtest covering empty-input and malformed-ELF
guards on the public hotswap API.
No MC stack, no disassembler, no opcode canonicalisation yet — those
land in subsequent commits.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7fde156 to
2c6f5a2
Compare
Adds the ELF/MsgPack metadata parser that the rest of the raiser pipeline
depends on. Public surface is
extractTextSection,listKernelNames,extractKernelMeta,findKernelSymbolOffset, anddetectIsaFromElf.No MC stack, no disassembler, no opcode canonicalisation yet — those land
in subsequent commits. The kernel-descriptor fields on
KernelMeta(kernelcode properties, kernarg preload, compute_pgm_rsrc1/2) are populated here
so later layers (
UserSgprLayout, kernarg layout) have the metadata theyexpect; the raiser itself does not consume them yet.
Includes a small focused gtest covering the empty-input and malformed-ELF
guards on the public API.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com