From 141022fcc122e2d065bf2b07fcb6347f12df5878 Mon Sep 17 00:00:00 2001 From: richard-byron Date: Tue, 8 Sep 2026 11:29:37 -0700 Subject: [PATCH 1/3] Deferrs halt plugin config until run_start for full ELF --- profile/plugin/aie_halt/aie_halt_cb.cpp | 15 ++++ profile/plugin/aie_halt/aie_halt_cb.h | 5 ++ profile/plugin/aie_halt/aie_halt_plugin.cpp | 82 +++++++++++++++------ profile/plugin/aie_halt/aie_halt_plugin.h | 9 ++- 4 files changed, 87 insertions(+), 24 deletions(-) diff --git a/profile/plugin/aie_halt/aie_halt_cb.cpp b/profile/plugin/aie_halt/aie_halt_cb.cpp index c002d0e5..b1d2a7c4 100644 --- a/profile/plugin/aie_halt/aie_halt_cb.cpp +++ b/profile/plugin/aie_halt/aie_halt_cb.cpp @@ -37,6 +37,14 @@ namespace xdp { } } + static void aieHaltRunStart(void* run_impl_ptr, void* hwctx, + uint32_t run_uid, const char* kernel_name) + { + if (AIEHaltPlugin::alive()) + aieHaltPluginInstance.runStartHook(run_impl_ptr, hwctx, run_uid, + kernel_name ? kernel_name : ""); + } + } // end namespace xdp extern "C" @@ -49,4 +57,11 @@ extern "C" void finishflushDeviceAIEHalt(void* hwCtxImpl) { xdp::finishflushDeviceAIEHalt(hwCtxImpl); +} + +extern "C" +void aieHaltRunStart(void* run_impl_ptr, void* hwctx, uint32_t run_uid, + const char* kernel_name) +{ + xdp::aieHaltRunStart(run_impl_ptr, hwctx, run_uid, kernel_name); } \ No newline at end of file diff --git a/profile/plugin/aie_halt/aie_halt_cb.h b/profile/plugin/aie_halt/aie_halt_cb.h index 8e5e93eb..6809fa72 100644 --- a/profile/plugin/aie_halt/aie_halt_cb.h +++ b/profile/plugin/aie_halt/aie_halt_cb.h @@ -19,10 +19,15 @@ #include "xdp/config.h" +#include + extern "C" { XDP_PLUGIN_EXPORT void updateDeviceAIEHalt(void* hwCtxImpl); XDP_PLUGIN_EXPORT void finishflushDeviceAIEHalt(void* hwCtxImpl); + XDP_PLUGIN_EXPORT void aieHaltRunStart(void* run_impl_ptr, void* hwctx, + uint32_t run_uid, + const char* kernel_name); } #endif diff --git a/profile/plugin/aie_halt/aie_halt_plugin.cpp b/profile/plugin/aie_halt/aie_halt_plugin.cpp index 17552971..08bd9e04 100644 --- a/profile/plugin/aie_halt/aie_halt_plugin.cpp +++ b/profile/plugin/aie_halt/aie_halt_plugin.cpp @@ -64,55 +64,74 @@ namespace xdp { // Only 1 device and xclbin is supported now. return; } + mHwCtxImpl = hwCtxImpl; -#if defined(XDP_VE2_BUILD) - const std::string deviceName = "ve2_device"; -#else - const std::string deviceName = "win_device"; -#endif - - xrt::hw_context hwContext = xrt_core::hw_context_int::create_hw_context_from_implementation(hwCtxImpl); - std::shared_ptr coreDevice = xrt_core::hw_context_int::get_core_device(hwContext); - - xrt_core::message::send(xrt_core::message::severity_level::info, "XRT", "Identify flow type"); + xrt::hw_context hwContext = xrt_core::hw_context_int::create_hw_context_from_implementation(mHwCtxImpl); + // Full ELF flow carries AIE metadata in an xrt::elf (no xclbin). bool isFullELFFlow = false; try { isFullELFFlow = xrt_core::hw_context_int::get_elf_flow(hwContext); } catch (const std::exception& e) { std::stringstream msg; - msg << e.what() << " AIE Halt cannot be enabled before complete configuration." << std::endl; + msg << e.what() << " AIE Halt cannot be enabled before complete configuration, plugin configuration deferred."; xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", msg.str()); + mDeferredConfiguration = true; return; } - uint64_t deviceId = 0; if (isFullELFFlow) { - /* For Full ELF flow, AIE metadata is carried in an xrt::elf registered - * with the HWCtx instead of an xclbin. - */ - xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", "In Full ELF flow"); + // updateDevice can be called by hw_context::add_config() while it holds + // the hw-context mutex. Defer all APIs which reacquire that mutex until + // the first user run is constructed. + mDeferredConfiguration = true; + xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", + "Deferring AIE Halt full-ELF configuration until the first user run."); + return; + } + + mDeferredConfiguration = false; + configureDevice(); +#endif + } - deviceId = (db->getStaticInfo()).getHwCtxImplUidElf(hwCtxImpl); + void AIEHaltPlugin::configureDevice() + { +#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD) +#if defined(XDP_VE2_BUILD) + const std::string deviceName = "ve2_device"; +#else + const std::string deviceName = "win_device"; +#endif + + xrt::hw_context hwContext = xrt_core::hw_context_int::create_hw_context_from_implementation(mHwCtxImpl); + std::shared_ptr coreDevice = xrt_core::hw_context_int::get_core_device(hwContext); + + uint64_t deviceId = 0; + if (mDeferredConfiguration) { + xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", + "Applying deferred configuration for AIE Halt."); + deviceId = (db->getStaticInfo()).getHwCtxImplUidElf(mHwCtxImpl); auto elfMap = xrt_core::hw_context_int::get_elf_map(hwContext); if (elfMap.empty()) { xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", - "AIE Halt ELF flow: hw_context has no registered ELFs. Skipping ELF flow."); + "AIE Halt ELF flow: hw_context has no registered ELFs, halt cannot be configured."); return; } auto elf = util::getAieMetadataElf(elfMap); - if (!elf) + if (!elf) { + xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", + "Metadata not found in ELF map, halt cannot be configured."); return; + } (db->getStaticInfo()).updateDeviceFromCoreDeviceElf(deviceId, coreDevice, std::move(*elf)); } else { - // xclbin flow : only one device for the Client/VE2 device flow + // Only one device for the Client/VE2 device flow deviceId = db->addDevice(deviceName); (db->getStaticInfo()).updateDeviceFromCoreDevice(deviceId, coreDevice, false); } (db->getStaticInfo()).setDeviceName(deviceId, deviceName); - mHwCtxImpl = hwCtxImpl; - DeviceDataEntry.valid = true; #if defined(XDP_VE2_BUILD) DeviceDataEntry.implementation = std::make_unique(db); @@ -124,6 +143,23 @@ namespace xdp { #endif } + void AIEHaltPlugin::runStartImpl(void* /*run_impl_ptr*/, void* hwCtxImpl, + uint32_t /*run_uid*/, + const std::string& /*kernel_name*/) + { +#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD) + if (mDeferredConfiguration) { + if (hwCtxImpl != mHwCtxImpl) { + xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", + "New Hw Context Impl passed in AIE Halt Plugin runStartImpl, aborting configuration."); + } else { + configureDevice(); + } + mDeferredConfiguration = false; + } +#endif + } + void AIEHaltPlugin::finishflushDevice(void* hwCtxImpl) { #if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD) @@ -133,7 +169,7 @@ namespace xdp { if (hwCtxImpl != mHwCtxImpl) { xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", - "New Hw Context Impl passed in AIE Halt Plugin."); + "New Hw Context Impl passed in AIE Halt Plugin finishflushDevice."); return; } diff --git a/profile/plugin/aie_halt/aie_halt_plugin.h b/profile/plugin/aie_halt/aie_halt_plugin.h index 7bada085..6d0b2919 100644 --- a/profile/plugin/aie_halt/aie_halt_plugin.h +++ b/profile/plugin/aie_halt/aie_halt_plugin.h @@ -37,7 +37,14 @@ namespace xdp { static bool alive(); + protected: + void runStartImpl(void* run_impl_ptr, void* hwCtxImpl, + uint32_t run_uid, + const std::string& kernel_name) override; + private: + void configureDevice(); + static bool live; struct DeviceData { @@ -46,7 +53,7 @@ namespace xdp { } DeviceDataEntry; void* mHwCtxImpl = nullptr; - + bool mDeferredConfiguration = false; }; } // end namespace xdp From 58b4a75966c29828f35d5adea679ec7c8a9b6ca0 Mon Sep 17 00:00:00 2001 From: richard-byron Date: Tue, 8 Sep 2026 14:03:51 -0700 Subject: [PATCH 2/3] Remove unused parameters from hooks where possible --- profile/plugin/aie_halt/aie_halt_cb.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/profile/plugin/aie_halt/aie_halt_cb.cpp b/profile/plugin/aie_halt/aie_halt_cb.cpp index b1d2a7c4..86f551d9 100644 --- a/profile/plugin/aie_halt/aie_halt_cb.cpp +++ b/profile/plugin/aie_halt/aie_halt_cb.cpp @@ -37,12 +37,10 @@ namespace xdp { } } - static void aieHaltRunStart(void* run_impl_ptr, void* hwctx, - uint32_t run_uid, const char* kernel_name) + static void aieHaltRunStart(void* hwctx, const char* kernel_name) { if (AIEHaltPlugin::alive()) - aieHaltPluginInstance.runStartHook(run_impl_ptr, hwctx, run_uid, - kernel_name ? kernel_name : ""); + aieHaltPluginInstance.runStartHook(nullptr, hwctx, 0, kernel_name ? kernel_name : ""); } } // end namespace xdp @@ -60,8 +58,7 @@ void finishflushDeviceAIEHalt(void* hwCtxImpl) } extern "C" -void aieHaltRunStart(void* run_impl_ptr, void* hwctx, uint32_t run_uid, - const char* kernel_name) +void aieHaltRunStart(void* hwctx, const char* kernel_name) { - xdp::aieHaltRunStart(run_impl_ptr, hwctx, run_uid, kernel_name); + xdp::aieHaltRunStart(hwctx, kernel_name); } \ No newline at end of file From 34309f7c68cf90f4719bbbd84ecd7bcc158d42be Mon Sep 17 00:00:00 2001 From: richard-byron Date: Tue, 8 Sep 2026 16:23:18 -0700 Subject: [PATCH 3/3] Missing header from last commit --- profile/plugin/aie_halt/aie_halt_cb.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/profile/plugin/aie_halt/aie_halt_cb.h b/profile/plugin/aie_halt/aie_halt_cb.h index 6809fa72..ef64bf90 100644 --- a/profile/plugin/aie_halt/aie_halt_cb.h +++ b/profile/plugin/aie_halt/aie_halt_cb.h @@ -25,9 +25,7 @@ extern "C" { XDP_PLUGIN_EXPORT void updateDeviceAIEHalt(void* hwCtxImpl); XDP_PLUGIN_EXPORT void finishflushDeviceAIEHalt(void* hwCtxImpl); - XDP_PLUGIN_EXPORT void aieHaltRunStart(void* run_impl_ptr, void* hwctx, - uint32_t run_uid, - const char* kernel_name); + XDP_PLUGIN_EXPORT void aieHaltRunStart(void* hwctx, const char* kernel_name); } #endif