From 1d72c83e042d8115d3bc4b4b7cad4c0d265dc19b Mon Sep 17 00:00:00 2001 From: Ishita Ghosh Date: Sun, 11 Aug 2024 12:35:23 -0700 Subject: [PATCH] AIE Halt Plugin to set Debug Halt on AIE Cores used by current Hw Context, using transaction Signed-off-by: Ishita Ghosh --- .../profile/plugin/aie_halt/CMakeLists.txt | 41 +++++ .../profile/plugin/aie_halt/aie_halt_cb.cpp | 52 +++++++ .../xdp/profile/plugin/aie_halt/aie_halt_cb.h | 28 ++++ .../profile/plugin/aie_halt/aie_halt_impl.h | 51 +++++++ .../plugin/aie_halt/aie_halt_plugin.cpp | 122 +++++++++++++++ .../profile/plugin/aie_halt/aie_halt_plugin.h | 54 +++++++ .../plugin/aie_halt/clientDev/aie_halt.cpp | 140 ++++++++++++++++++ .../plugin/aie_halt/clientDev/aie_halt.h | 39 +++++ 8 files changed, 527 insertions(+) create mode 100644 src/runtime_src/xdp/profile/plugin/aie_halt/CMakeLists.txt create mode 100644 src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_cb.cpp create mode 100644 src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_cb.h create mode 100644 src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_impl.h create mode 100644 src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.cpp create mode 100644 src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.h create mode 100644 src/runtime_src/xdp/profile/plugin/aie_halt/clientDev/aie_halt.cpp create mode 100644 src/runtime_src/xdp/profile/plugin/aie_halt/clientDev/aie_halt.h diff --git a/src/runtime_src/xdp/profile/plugin/aie_halt/CMakeLists.txt b/src/runtime_src/xdp/profile/plugin/aie_halt/CMakeLists.txt new file mode 100644 index 00000000000..2cf47389583 --- /dev/null +++ b/src/runtime_src/xdp/profile/plugin/aie_halt/CMakeLists.txt @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +# + +# ======================================================================= +# This builds the AIE Halt Plugin to add Debug Halts for all AIE Cores at +# the start. It is currently built on Client Windows Only. +# ========================================================================= + +if (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes") + set(IMPL_DIR "${PROFILE_DIR}/plugin/aie_halt/clientDev") +endif() + + +file(GLOB XDP_AIE_HALT_PLUGIN_FILES + "${PROFILE_DIR}/plugin/aie_halt/*.h" + "${PROFILE_DIR}/plugin/aie_halt/*.cpp" + "${IMPL_DIR}/*.h" + "${IMPL_DIR}/*.cpp" +) + +file(GLOB XDP_DEVICE_COMMON_FILES + "${PROFILE_DIR}/device/common/*.h" + "${PROFILE_DIR}/device/common/*.cpp" +) + +if (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes") + add_library(xdp_aie_halt_plugin MODULE ${XDP_AIE_HALT_PLUGIN_FILES} ${XDP_DEVICE_COMMON_FILES}) + add_dependencies(xdp_aie_halt_plugin xdp_core xrt_coreutil) + target_link_libraries(xdp_aie_halt_plugin PRIVATE xdp_core xrt_coreutil xaiengine) + target_compile_definitions(xdp_aie_halt_plugin PRIVATE XDP_CLIENT_BUILD=1 -DXAIE_FEATURE_MSVC) + target_include_directories(xdp_aie_halt_plugin PRIVATE ${AIERT_DIR}/include) + set_target_properties(xdp_aie_halt_plugin PROPERTIES VERSION ${XRT_VERSION_STRING} SOVERSION ${XRT_SOVERSION}) + + install (TARGETS xdp_aie_halt_plugin + LIBRARY DESTINATION ${XDP_PLUGIN_INSTALL_DIR} + ) + +# Else, on edge-aarch64 don't build at all + +endif() \ No newline at end of file diff --git a/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_cb.cpp b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_cb.cpp new file mode 100644 index 00000000000..c002d0e52cb --- /dev/null +++ b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_cb.cpp @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may + * not use this file except in compliance with the License. A copy of the + * License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#define XDP_PLUGIN_SOURCE + +#include "xdp/profile/plugin/aie_halt/aie_halt_cb.h" +#include "xdp/profile/plugin/aie_halt/aie_halt_plugin.h" + +namespace xdp { + + static AIEHaltPlugin aieHaltPluginInstance; + + static void updateDeviceAIEHalt(void* hwCtxImpl) + { + if (AIEHaltPlugin::alive()) { + aieHaltPluginInstance.updateDevice(hwCtxImpl); + } + } + + static void finishflushDeviceAIEHalt(void* hwCtxImpl) + { + if (AIEHaltPlugin::alive()) { + aieHaltPluginInstance.finishflushDevice(hwCtxImpl); + } + } + +} // end namespace xdp + +extern "C" +void updateDeviceAIEHalt(void* hwCtxImpl) +{ + xdp::updateDeviceAIEHalt(hwCtxImpl); +} + +extern "C" +void finishflushDeviceAIEHalt(void* hwCtxImpl) +{ + xdp::finishflushDeviceAIEHalt(hwCtxImpl); +} \ No newline at end of file diff --git a/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_cb.h b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_cb.h new file mode 100644 index 00000000000..8e5e93eb127 --- /dev/null +++ b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_cb.h @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may + * not use this file except in compliance with the License. A copy of the + * License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#ifndef XDP_PLUGIN_AIE_HALT_CB_H +#define XDP_PLUGIN_AIE_HALT_CB_H + +#include "xdp/config.h" + +extern "C" { + + XDP_PLUGIN_EXPORT void updateDeviceAIEHalt(void* hwCtxImpl); + XDP_PLUGIN_EXPORT void finishflushDeviceAIEHalt(void* hwCtxImpl); + +} +#endif diff --git a/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_impl.h b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_impl.h new file mode 100644 index 00000000000..0fe62be2092 --- /dev/null +++ b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_impl.h @@ -0,0 +1,51 @@ +/** + * Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may + * not use this file except in compliance with the License. A copy of the + * License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#ifndef XDP_PLUGIN_AIE_HALT_IMPL_H +#define XDP_PLUGIN_AIE_HALT_IMPL_H + +#include "core/include/xrt/xrt_hw_context.h" + +namespace xdp { + + class VPDatabase; + + class AIEHaltImpl + { + protected : + VPDatabase* db = nullptr; + xrt::hw_context mHwContext; + + public: + AIEHaltImpl(VPDatabase* dB) + : db(dB) + {} + + AIEHaltImpl() = delete; + + virtual ~AIEHaltImpl() {} + + virtual void updateDevice(void*) = 0; + virtual void finishflushDevice(void*) = 0; + + void setHwContext(xrt::hw_context ctx) + { + mHwContext = std::move(ctx); + } + }; + +} +#endif \ No newline at end of file diff --git a/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.cpp b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.cpp new file mode 100644 index 00000000000..056abe8f158 --- /dev/null +++ b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.cpp @@ -0,0 +1,122 @@ +/** + * Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may + * not use this file except in compliance with the License. A copy of the + * License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#define XDP_PLUGIN_SOURCE + +#include +#include + +#include "core/common/device.h" +#include "core/common/message.h" +#include "core/common/api/hw_context_int.h" + +#include "xdp/profile/plugin/aie_halt/aie_halt_plugin.h" +#include "xdp/profile/plugin/vp_base/info.h" +#include "xdp/profile/plugin/vp_base/utility.h" + +#ifdef XDP_CLIENT_BUILD +#include "xdp/profile/plugin/aie_halt/clientDev/aie_halt.h" +#endif + +namespace xdp { + + bool AIEHaltPlugin::live = false; + + AIEHaltPlugin::AIEHaltPlugin() + : XDPPlugin() + { + AIEHaltPlugin::live = true; + + db->registerPlugin(this); + db->registerInfo(info::aie_halt); + } + + AIEHaltPlugin::~AIEHaltPlugin() + { + if (VPDatabase::alive()) { + try { + writeAll(false); + } + catch (...) { + } + db->unregisterPlugin(this); + } + + AIEHaltPlugin::live = false; + } + + bool AIEHaltPlugin::alive() + { + return AIEHaltPlugin::live; + } + + void AIEHaltPlugin::updateDevice(void* hwCtxImpl) + { +#ifdef XDP_CLIENT_BUILD + if (mHwCtxImpl) { + // For client device flow, only 1 device and xclbin is supported now. + return; + } + mHwCtxImpl = hwCtxImpl; + + 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); + + // Only one device for Client Device flow + uint64_t deviceId = db->addDevice("win_device"); + (db->getStaticInfo()).updateDeviceClient(deviceId, coreDevice); + (db->getStaticInfo()).setDeviceName(deviceId, "win_device"); + + DeviceDataEntry.valid = true; + DeviceDataEntry.implementation = std::make_unique(db); + DeviceDataEntry.implementation->setHwContext(hwContext); + DeviceDataEntry.implementation->updateDevice(mHwCtxImpl); +#endif + } + + void AIEHaltPlugin::finishflushDevice(void* hwCtxImpl) + { +#ifdef XDP_CLIENT_BUILD + if (!mHwCtxImpl || !DeviceDataEntry.valid) { + return; + } + + if (hwCtxImpl != mHwCtxImpl) { + xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", + "New Hw Context Impl passed in AIE Halt Plugin."); + return; + } + + DeviceDataEntry.valid = false; + DeviceDataEntry.implementation->finishflushDevice(mHwCtxImpl); +#endif + } + + void AIEHaltPlugin::writeAll(bool /*openNewFiles*/) + { +#ifdef XDP_CLIENT_BUILD + + if (!mHwCtxImpl || !DeviceDataEntry.valid) { + return; + } + + // For client device flow, only 1 device and xclbin is supported now. + DeviceDataEntry.valid = false; + DeviceDataEntry.implementation->finishflushDevice(mHwCtxImpl); +#endif + } + +} \ No newline at end of file diff --git a/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.h b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.h new file mode 100644 index 00000000000..7bada08536f --- /dev/null +++ b/src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.h @@ -0,0 +1,54 @@ +/** + * Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may + * not use this file except in compliance with the License. A copy of the + * License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#ifndef XDP_AIE_HALT_PLUGIN_H +#define XDP_AIE_HALT_PLUGIN_H + +#include "xdp/profile/plugin/aie_halt/aie_halt_impl.h" +#include "xdp/profile/plugin/vp_base/vp_base_plugin.h" + + +namespace xdp { + + class AIEHaltPlugin : public XDPPlugin + { + public: + + AIEHaltPlugin(); + ~AIEHaltPlugin(); + + void updateDevice(void* hwCtxImpl); + void finishflushDevice(void* hwCtxImpl); + + void writeAll(bool); + + static bool alive(); + + private: + static bool live; + + struct DeviceData { + bool valid; + std::unique_ptr implementation; + } DeviceDataEntry; + + void* mHwCtxImpl = nullptr; + + }; + +} // end namespace xdp + +#endif diff --git a/src/runtime_src/xdp/profile/plugin/aie_halt/clientDev/aie_halt.cpp b/src/runtime_src/xdp/profile/plugin/aie_halt/clientDev/aie_halt.cpp new file mode 100644 index 00000000000..9df5980516e --- /dev/null +++ b/src/runtime_src/xdp/profile/plugin/aie_halt/clientDev/aie_halt.cpp @@ -0,0 +1,140 @@ +/** + * Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may + * not use this file except in compliance with the License. A copy of the + * License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#define XDP_PLUGIN_SOURCE + +#include +#include + +#include "core/common/device.h" +#include "core/common/message.h" +#include "core/common/api/hw_context_int.h" + +#include "xdp/profile/database/database.h" +#include "xdp/profile/database/static_info/aie_util.h" +#include "xdp/profile/database/static_info/aie_constructs.h" +#include "xdp/profile/device/common/client_transaction.h" +#include "xdp/profile/plugin/aie_halt/clientDev/aie_halt.h" +#include "xdp/profile/plugin/vp_base/utility.h" + +#include "core/common/api/xclbin_int.h" +#include "core/include/xclbin.h" + +extern "C" { + #include + #include +} + +#ifdef _WIN32 +# pragma warning ( disable : 4244 ) +#endif + +namespace xdp { + + + AIEHaltClientDevImpl::AIEHaltClientDevImpl(VPDatabase*dB) + : AIEHaltImpl(dB) + { + } + + void AIEHaltClientDevImpl::updateDevice(void* hwCtxImpl) + { + xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", + "In AIEHaltClientDevImpl::updateDevice"); + + std::unique_ptr txnHandler + = std::make_unique(mHwContext, "AIE Halt"); + + if (!txnHandler->initializeKernel("XDP_KERNEL")) + return; + + boost::property_tree::ptree aieMetadata; + try { + auto device = xrt_core::hw_context_int::get_core_device(mHwContext); + xrt::xclbin xrtXclbin = device.get()->get_xclbin(device.get()->get_xclbin_uuid()); + auto data = xrt_core::xclbin_int::get_axlf_section(xrtXclbin, AIE_METADATA); + + if (!data.first || !data.second) { + xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", "Empty AIE Metadata in xclbin"); + return; + } + + std::stringstream ss; + ss.write(data.first,data.second); + + boost::property_tree::read_json(ss, aieMetadata); + } catch (const std::exception& e) { + std::string msg("AIE Metadata could not be read/processed from xclbin: "); + msg += e.what(); + xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", msg); + return; + } + + xdp::aie::driver_config meta_config = xdp::aie::getDriverConfig(aieMetadata, "aie_metadata.driver_config"); + + XAie_Config cfg { + meta_config.hw_gen, + meta_config.base_address, + meta_config.column_shift, + meta_config.row_shift, + meta_config.num_rows, + meta_config.num_columns, + meta_config.shim_row, + meta_config.mem_row_start, + meta_config.mem_num_rows, + meta_config.aie_tile_row_start, + meta_config.aie_tile_num_rows, + {0} + }; + + XAie_DevInst aieDevInst = {0}; + auto RC = XAie_CfgInitialize(&aieDevInst, &cfg); + if (RC != XAIE_OK) { + xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", "AIE Driver Initialization Failed."); + return; + } + + uint64_t startCol = 0, numCols = 0; + + boost::property_tree::ptree aiePartitionPt = xdp::aie::getAIEPartitionInfoClient(hwCtxImpl); + for (const auto& e : aiePartitionPt) { + startCol = e.second.get("start_col"); + numCols = e.second.get("num_cols"); + // Currently, assuming only one Hw Context is alive at a time + break; + } + + std::stringstream msg; + msg << " Adding CoreDebugHalts starting column " << startCol << " for " << numCols << " columns." << std::endl; + xrt_core::message::send(xrt_core::message::severity_level::info, "XRT", msg.str()); + + XAie_StartTransaction(&aieDevInst, XAIE_TRANSACTION_DISABLE_AUTO_FLUSH); + for (uint8_t c = static_cast(startCol) ; c < (static_cast(startCol + numCols)) ; c++ ) { + for (uint8_t r = 2; r < 6 ; r++) { + XAie_CoreDebugHalt(&aieDevInst, XAie_TileLoc(c, r)); + } + } + + uint8_t* txnBin = XAie_ExportSerializedTransaction(&aieDevInst, 1, 0); + if (!txnHandler->submitTransaction(txnBin)) + return; + XAie_ClearTransaction(&aieDevInst); + } + + void AIEHaltClientDevImpl::finishflushDevice(void* /*hwCtxImpl*/) + { + } +} \ No newline at end of file diff --git a/src/runtime_src/xdp/profile/plugin/aie_halt/clientDev/aie_halt.h b/src/runtime_src/xdp/profile/plugin/aie_halt/clientDev/aie_halt.h new file mode 100644 index 00000000000..60fe7839287 --- /dev/null +++ b/src/runtime_src/xdp/profile/plugin/aie_halt/clientDev/aie_halt.h @@ -0,0 +1,39 @@ +/** + * Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may + * not use this file except in compliance with the License. A copy of the + * License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#ifndef XDP_PLUGIN_AIE_HALT_CLIENTDEV_IMPL_H +#define XDP_PLUGIN_AIE_HALT_CLIENTDEV_IMPL_H + +#include "xdp/config.h" +#include "xdp/profile/plugin/aie_halt/aie_halt_impl.h" + +namespace xdp { + + class AIEHaltClientDevImpl : public AIEHaltImpl + { + + public : + AIEHaltClientDevImpl(VPDatabase* dB); + + ~AIEHaltClientDevImpl() = default; + + virtual void updateDevice(void* hwCtxImpl); + virtual void finishflushDevice(void* hwCtxImpl); + }; + +} + +#endif \ No newline at end of file