[AMDGPU] comgr: Hotswap dispatcher vtable + .def registry, fix Windows support#2491
Open
xintin wants to merge 2 commits into
Open
[AMDGPU] comgr: Hotswap dispatcher vtable + .def registry, fix Windows support#2491xintin wants to merge 2 commits into
xintin wants to merge 2 commits into
Conversation
Signed-off-by: xintin <gaurav.verma@amd.com>
Signed-off-by: xintin <gaurav.verma@amd.com>
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.
Requires: to run CI in order to test the fix.
Summary
Replaces the
LLVM_ATTRIBUTE_WEAK+#if !defined(_MSC_VER)patch dispatch pattern with a function-pointer vtable driven by a centralcomgr-hotswap-patches.defregistry.Addresses issue #2479: on Windows,
LLVM_ATTRIBUTE_WEAKexpands to nothing under MSVC, so the no-op stubs incomgr-hotswap-b0a0.cppbecame regular definitions and either (a) collided with the strong overrides asLNK2005duplicate symbols, or (b) silently won every dispatch when the patch.cppfiles were guarded out with#if !defined(_MSC_VER), disabling hotswap entirely while still reporting build success.The new dispatch contract is:
one slot on
HotswapPatchVTableper patch family;one alpha-ordered line in
comgr-hotswap-patches.defper merged patch; oneregister*Patch(HotswapPatchVTable&)exported from eachcomgr-hotswap-patch-*.cpp;installHotswapPatches()walks the.defto bind every slot;retargetCodeObjectB0A0drives the install once viastd::call_once;a missing registrar is a libamd_comgr / HotswapMCTests link error, not a silent feature disable.
applyWmmaSplitPatchesandapplyScratchPatcheskeep nullptr defaults because no patch file ships them yet.The dispatcher treats nullptr as a no-op slot, preserving the previous "weak stub returns 0" behaviour until those families land their first strong override.
Changes
HOTSWAP_PATCH(Name)line per merged patch (InPlace,Trampoline,Vop3px2Src2,WmmaHazard).HotswapPatchVTable,getHotswapPatchVTable(),installHotswapPatches(). Forward-declare everyregister*Patchfrom the same.defso internal.h is the single prototype source for both libamd_comgr and the unit tests. Remove the per-passapplyXxxexternal declarations -- impls are now file-local in their patch.cpp.apply*stubs and the forward-declaration block. Add the singleton accessor and the.def-driveninstallHotswapPatches. Route the dispatcher through the vtable via a smallrunPerInstPasshelper that treats nullptr slots as 0-return. Install once per process fromretargetCodeObjectB0A0understd::call_once. Liveness / DWARF stubs that still have no strong override anywhere in tree keep theLLVM_ATTRIBUTE_WEAKpattern -- they migrate the same way the first time a real implementation lands.#if !defined(_MSC_VER)guard and its explanatory comment. Rename the dispatcher entry pointapplyXxxto a file-staticapplyXxxImpl. Add a file-scoperegisterXxxPatch(HotswapPatchVTable&)that binds the impl into the vtable. Test-facing helpers (classifyWmmaNops,patchScaleSrc2) now compile unconditionally, fixing theLNK2019failures inHotswapMCTestson MSVC.Tests
Link errors catch
.defentries without matchingregister*Patchdefinitions. The tests cover the runtime binding behavior the linker cannot validate.TEST(HotswapPatchVTable, ...)blocks.RegisterInPlaceBindsOnlyInPlaceSlot-- canonical worked example that pins the "binds only its own slot" invariant for one installer. Wrong-slot bugs in the other threeregister*Patchfunctions are caught transitively by the install end-to-end test below.InstallBindsRegisteredAndLeavesUnregisteredNull-- end-to-end install: defaults null, every.defentry gets bound, slots without a.defentry (wmma-split,scratch) stay null. Pins the dispatcher's no-op contract for unimplemented pass families.ProcessSingletonIdentityAndInstallPersists--getHotswapPatchVTable()is a real Meyers singleton and bindings persist on it; theretargetCodeObjectB0A0install path understd::call_oncerelies on this.comgr-hotswap-b0a0.cpp,comgr-hotswap-patch-inplace.cpp, andcomgr-hotswap-patch-trampoline.cppintoHotswapMCTests(the other two patch sources were already there) soinstallHotswapPatchesand everyregister*Patchresolve at link time. Apatches.defline without a matching definition produces aHotswapMCTestslink error, which is itself a regression guard for the new contract.Follow-up (deferred)
ds_2addr_stride64per #2379, need a one-line.defadd and aregister*Patchshim when they rebase.LLVM_ATTRIBUTE_WEAKliveness / DWARF stubs (buildCfg,computeLiveness,getInstRegDefUse,getBranchImm,verifyPatchCorrectness,addTrampolineSymbols,patchDebug*) onto the same.defcontract the first time any of them grows a real implement.