diff --git a/profile/plugin/aie_dtrace/CMakeLists.txt b/profile/plugin/aie_dtrace/CMakeLists.txt index 8d150fd2..c31b6b63 100644 --- a/profile/plugin/aie_dtrace/CMakeLists.txt +++ b/profile/plugin/aie_dtrace/CMakeLists.txt @@ -1,63 +1,27 @@ # SPDX-License-Identifier: Apache-2.0 -# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. -# -# Link this plugin with the same AIE profile *object sources* as -# xdp_aie_profile_plugin_xdna (see plugin/aie_profile/CMakeLists.txt, XDP_VE2_BUILD), -# except: -# - no aie_profile_plugin*, aie_profile_cb*, writer/aie_profile/* -# - no ve2/aie_profile* (replaced by aie_dtrace/ve2/*) -# -# If load fails with "undefined symbol" from AieProfileMetadata / parser / elf, -# add the missing .cpp here or in AIE_DTRACE_PROFILE_CORE_SOURCES below. -# ELF serialization for aiebu CT: ve2/elf_helper.cpp (same role as aie_profile/ve2/elf_helper.cpp). +# Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved # +# Standalone AIE dtrace plugin for VE2/XDNA. Handles bandwidth metric sets only; +# no dependency on aie_profile sources. if (XDP_VE2_BUILD_CMAKE STREQUAL "yes") - set(XDP_PROFILE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") - file(GLOB AIE_DTRACE_PLUGIN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" ) - file(GLOB AIE_DTRACE_UTIL_FILES - "${CMAKE_CURRENT_SOURCE_DIR}/util/*.h" - "${CMAKE_CURRENT_SOURCE_DIR}/util/*.cpp" + set(AIE_DTRACE_UTIL_FILES + "${CMAKE_CURRENT_SOURCE_DIR}/util/aie_dtrace_util.h" + "${CMAKE_CURRENT_SOURCE_DIR}/util/aie_dtrace_util.cpp" ) file(GLOB AIE_DTRACE_IMPL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ve2/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/ve2/*.cpp" ) - # Explicit .cpp from aie_profile tree required by metadata + CT/ELF (not covered by util/config globs). - set(AIE_DTRACE_PROFILE_CORE_SOURCES - "${XDP_PROFILE_ROOT}/plugin/aie_profile/aie_profile_metadata.cpp" - "${XDP_PROFILE_ROOT}/plugin/aie_profile/aie_profile_metadata_json.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/ve2/elf_helper.cpp" - ) - - file(GLOB AIE_PROFILE_UTIL_FILES - "${XDP_PROFILE_ROOT}/plugin/aie_base/*" - "${XDP_PROFILE_ROOT}/plugin/aie_base/generations/*" - "${XDP_PROFILE_ROOT}/plugin/aie_profile/util/aie_profile_util.h" - "${XDP_PROFILE_ROOT}/plugin/aie_profile/util/aie_profile_util.cpp" - ) - file(GLOB AIE_PROFILE_CONFIG_FILES - "${XDP_PROFILE_ROOT}/plugin/aie_profile/util/aie_profile_config.h" - "${XDP_PROFILE_ROOT}/plugin/aie_profile/util/aie_profile_config.cpp" - ) - file(GLOB AIE_JSON_PARSER_FILES - "${XDP_PROFILE_ROOT}/database/parser/*.h" - "${XDP_PROFILE_ROOT}/database/parser/*.cpp" - ) - add_library(xdp_aie_dtrace_plugin_xdna SHARED ${AIE_DTRACE_PLUGIN_FILES} ${AIE_DTRACE_IMPL_FILES} ${AIE_DTRACE_UTIL_FILES} - ${AIE_DTRACE_PROFILE_CORE_SOURCES} - ${AIE_PROFILE_UTIL_FILES} - ${AIE_PROFILE_CONFIG_FILES} - ${AIE_JSON_PARSER_FILES} ) add_dependencies(xdp_aie_dtrace_plugin_xdna xdp_core xrt_coreutil) target_link_libraries(xdp_aie_dtrace_plugin_xdna PRIVATE xdp_core xrt_coreutil aie_codegen aiebu_library_objects) diff --git a/profile/plugin/aie_dtrace/aie_dtrace_cb.cpp b/profile/plugin/aie_dtrace/aie_dtrace_cb.cpp index b8d41698..127e8b05 100644 --- a/profile/plugin/aie_dtrace/aie_dtrace_cb.cpp +++ b/profile/plugin/aie_dtrace/aie_dtrace_cb.cpp @@ -1,18 +1,6 @@ -/** - * Copyright (C) 2022-2023 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. - */ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved + #define XDP_PLUGIN_SOURCE #include "aie_dtrace_cb.h" diff --git a/profile/plugin/aie_dtrace/aie_dtrace_cb.h b/profile/plugin/aie_dtrace/aie_dtrace_cb.h index fe80840d..1d4579dc 100644 --- a/profile/plugin/aie_dtrace/aie_dtrace_cb.h +++ b/profile/plugin/aie_dtrace/aie_dtrace_cb.h @@ -1,18 +1,5 @@ -/** - * Copyright (C) 2023-2025 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. - */ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #ifndef XDP_PLUGIN_AIE_DTRACE_CB_H #define XDP_PLUGIN_AIE_DTRACE_CB_H diff --git a/profile/plugin/aie_dtrace/aie_dtrace_impl.h b/profile/plugin/aie_dtrace/aie_dtrace_impl.h new file mode 100644 index 00000000..7c505be7 --- /dev/null +++ b/profile/plugin/aie_dtrace/aie_dtrace_impl.h @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved + +#ifndef AIE_DTRACE_IMPL_H +#define AIE_DTRACE_IMPL_H + +#include +#include + +#include "xdp/profile/plugin/aie_dtrace/aie_dtrace_metadata.h" +#include "xdp/profile/plugin/vp_base/vp_base_plugin.h" + +namespace xdp { + + // AIE profile configurations can be done in different ways depending + // on the platform. For example, platforms like the VCK5000 or + // discovery platform, where the host code runs on the x86 and the AIE + // is not directly accessible, will require configuration be done via + // PS kernel. + class AieDtraceImpl + { + + protected: + VPDatabase* db = nullptr; + std::shared_ptr metadata; + uint64_t deviceID; + + public: + AieDtraceImpl(VPDatabase* database, std::shared_ptr metadata, uint64_t id) + : db(database), + metadata(metadata), + deviceID(id) + {} + + AieDtraceImpl() = delete; + virtual ~AieDtraceImpl() {}; + + virtual void updateDevice() = 0; + + virtual void startPoll(const uint64_t /*id*/) {} + virtual void continuePoll(const uint64_t /*id*/) {} + virtual void poll(const uint64_t /*id*/) {} + virtual void endPoll() {} + virtual void freeResources() {} + + virtual void generateCTForRun(void* /*run_impl_ptr*/, void* /*hwctx*/, uint32_t /*run_uid*/, + const std::string& /*kernel_name*/, + void* /*elf_handle*/) {} + + uint64_t getDeviceID() { return deviceID; } + }; + +} // namespace xdp + +#endif diff --git a/profile/plugin/aie_dtrace/aie_dtrace_metadata.cpp b/profile/plugin/aie_dtrace/aie_dtrace_metadata.cpp new file mode 100644 index 00000000..3d86fbab --- /dev/null +++ b/profile/plugin/aie_dtrace/aie_dtrace_metadata.cpp @@ -0,0 +1,355 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved + +#define XDP_PLUGIN_SOURCE + +#include "xdp/profile/plugin/aie_dtrace/aie_dtrace_metadata.h" + +#include +#include +#include + +#include + +#include "core/common/config_reader.h" +#include "core/common/message.h" +#include "xdp/profile/database/database.h" +#include "xdp/profile/database/static_info/aie_util.h" +#include "xdp/profile/plugin/vp_base/profiling_runtime_config.h" + +namespace xdp { + using severity_level = xrt_core::message::severity_level; + + static const std::set& bandwidthMetricSets() + { + static const std::set metrics = { + "ddr_bandwidth", "read_bandwidth", "write_bandwidth", + "peak_read_bandwidth", "peak_write_bandwidth", "off"}; + return metrics; + } + + AieDtraceMetadata::AieDtraceMetadata(uint64_t deviceID, void* handle) + : deviceID(deviceID) + , handle(handle) + { + xrt_core::message::send(severity_level::info, "XRT", "Parsing AIE dtrace metadata."); + VPDatabase* db = VPDatabase::Instance(); + + metadataReader = (db->getStaticInfo()).getAIEmetadataReader(deviceID); + if (!metadataReader) + return; + + checkDtraceSettings(); + configMetrics.resize(NUM_MODULES); + clockFreqMhz = (db->getStaticInfo()).getClockRateMHz(deviceID, false); + + const bool usingBlob = profiling_runtime_config::has_control_instrumentation(); + const auto& ci = profiling_runtime_config::control_instrumentation(); + + if (usingBlob) { + if (ci.aie_tile.has_value() && !ci.aie_tile->empty()) { + xrt_core::message::send(severity_level::info, "XRT", + "AIE dtrace: core tile metric '" + *ci.aie_tile + + "' from profiling_runtime_config will be supported in a follow-up."); + } + if (ci.mem_tile.has_value() && !ci.mem_tile->empty()) { + xrt_core::message::send(severity_level::info, "XRT", + "AIE dtrace: mem tile metric '" + *ci.mem_tile + + "' from profiling_runtime_config will be supported in a follow-up."); + } + } + + std::vector metricsSettings; + if (usingBlob && ci.interface_tile.has_value() && !ci.interface_tile->empty()) { + xrt_core::message::send(severity_level::info, "XRT", + "AIE dtrace: using interface_tile metric '" + *ci.interface_tile + + "' from Debug.profiling_runtime_config."); + metricsSettings = getSettingsVector("all:" + *ci.interface_tile); + } + else { + const std::string tileBased = + xrt_core::config::get_aie_dtrace_settings_tile_based_interface_tile_metrics(); + if (!tileBased.empty()) + metricsSettings = getSettingsVector(tileBased); + else + metricsSettings = getSettingsVector("all:peak_read_bandwidth"); + } + + getConfigMetricsForInterfaceTiles(SHIM_MODULE_IDX, metricsSettings); + + xrt_core::message::send(severity_level::info, "XRT", "Finished parsing AIE dtrace metadata."); + } + + void AieDtraceMetadata::checkDtraceSettings() + { + using boost::property_tree::ptree; + const std::set validSettings { + "tile_based_interface_tile_metrics", + "configure_aie_hardware", + "config_one_partition", + }; + + auto tree = xrt_core::config::detail::get_ptree_value("AIE_dtrace_settings"); + if (auto val = tree.get_optional("config_one_partition")) + configOnePartition = *val; + + for (ptree::iterator pos = tree.begin(); pos != tree.end(); pos++) { + if (validSettings.find(pos->first) == validSettings.end()) { + std::stringstream msg; + msg << "The setting AIE_dtrace_settings." << pos->first << " is not recognized. " + << "Please check the spelling and compare to supported list:"; + for (auto it = validSettings.cbegin(); it != validSettings.cend(); it++) + msg << ((it == validSettings.cbegin()) ? " " : ", ") << *it; + xrt_core::message::send(severity_level::warning, "XRT", msg.str()); + } + } + } + + std::vector + AieDtraceMetadata::getSettingsVector(std::string settingsString) + { + if (settingsString.empty()) + return {}; + std::vector settingsVector; + boost::replace_all(settingsString, " ", ""); + boost::split(settingsVector, settingsString, boost::is_any_of(";")); + return settingsVector; + } + + bool AieDtraceMetadata::isBandwidthMetricSet(const std::string& metricSet) const + { + return bandwidthMetricSets().count(metricSet) > 0; + } + + void AieDtraceMetadata::getConfigMetricsForInterfaceTiles(int moduleIdx, + const std::vector& metricsSettings) + { + if (metricsSettings.empty()) + return; + + std::vector> metrics(metricsSettings.size()); + + // Pass 1: all:[:[:]] + for (size_t i = 0; i < metricsSettings.size(); ++i) { + boost::split(metrics[i], metricsSettings[i], boost::is_any_of(":")); + + if (metrics[i][0].compare("all") != 0) + continue; + if (metrics[i].size() < 2 || !isBandwidthMetricSet(metrics[i][1])) + continue; + + bool foundChannels = false; + uint8_t channelId0 = 0; + uint8_t channelId1 = 1; + if (metrics[i].size() > 2) { + try { + foundChannels = true; + channelId0 = aie::convertStringToUint8(metrics[i][2]); + channelId1 = (metrics[i].size() < 4) ? channelId0 : aie::convertStringToUint8(metrics[i][3]); + } + catch (std::invalid_argument const&) { + foundChannels = false; + xrt_core::message::send(severity_level::warning, "XRT", + "Channel ID specification in tile_based_interface_tile_metrics " + "is not an integer and hence ignored."); + } + } + + std::vector tiles; + if (foundChannels) + tiles = metadataReader->getInterfaceTiles("all", "all", metrics[i][1], channelId0); + else + tiles = metadataReader->getInterfaceTiles("all", "all", metrics[i][1]); + + for (auto& t : tiles) { + auto tileItr = std::find_if(configMetrics[moduleIdx].begin(), + configMetrics[moduleIdx].end(), compareTileByLocMap(t)); + + if (tileItr == configMetrics[moduleIdx].end()) { + configMetrics[moduleIdx][t] = metrics[i][1]; + configChannel0[t] = channelId0; + configChannel1[t] = channelId1; + } + else { + xrt_core::message::send(severity_level::warning, "XRT", + "Tile " + std::to_string(t.col) + "," + std::to_string(t.row) + + " is already configured with metric set " + configMetrics[moduleIdx][t] + + ". Ignoring setting for set " + metrics[i][1] + "."); + } + } + } + + // Pass 2: ::[:[:]] + for (size_t i = 0; i < metricsSettings.size(); ++i) { + if ((metrics[i][0].compare("all") == 0) || (metrics[i].size() < 3)) + continue; + + uint8_t maxCol = 0; + try { + maxCol = aie::convertStringToUint8(metrics[i][1]); + } + catch (std::invalid_argument const&) { + continue; + } + + if (!isBandwidthMetricSet(metrics[i][2])) + continue; + + uint8_t minCol = 0; + try { + minCol = aie::convertStringToUint8(metrics[i][0]); + } + catch (std::invalid_argument const&) { + xrt_core::message::send(severity_level::warning, "XRT", + "Minimum column specification in tile_based_interface_tile_metrics " + "is not an integer and hence skipped."); + continue; + } + + bool foundChannels = false; + uint8_t channelId0 = 0; + uint8_t channelId1 = 1; + if (metrics[i].size() > 3) { + try { + foundChannels = true; + channelId0 = aie::convertStringToUint8(metrics[i][3]); + channelId1 = (metrics[i].size() == 4) ? channelId0 : aie::convertStringToUint8(metrics[i][4]); + } + catch (std::invalid_argument const&) { + foundChannels = false; + xrt_core::message::send(severity_level::warning, "XRT", + "Channel ID specification in tile_based_interface_tile_metrics " + "is not an integer and hence ignored."); + } + } + + int16_t channelNum = foundChannels ? channelId0 : -1; + auto tiles = metadataReader->getInterfaceTiles("all", "all", metrics[i][2], + channelNum, true, minCol, maxCol); + + for (auto& t : tiles) { + configMetrics[moduleIdx][t] = metrics[i][2]; + configChannel0[t] = channelId0; + configChannel1[t] = channelId1; + } + } + + // Pass 3: :[:[:]] + for (size_t i = 0; i < metricsSettings.size(); ++i) { + bool isRangeSpecification = false; + if (metrics[i].size() >= 3) { + try { + (void)aie::convertStringToUint8(metrics[i][0]); + (void)aie::convertStringToUint8(metrics[i][1]); + isRangeSpecification = true; + } + catch (std::invalid_argument const&) { + isRangeSpecification = false; + } + } + + if (isRangeSpecification || (metrics[i].size() == 4) || (metrics[i].size() < 2) + || (metrics[i][0].compare("all") == 0)) + continue; + if (!isBandwidthMetricSet(metrics[i][1])) + continue; + + uint8_t col = 0; + try { + col = aie::convertStringToUint8(metrics[i][1]); + xrt_core::message::send(severity_level::warning, "XRT", + "tile_based_interface_tile_metrics: invalid format. Ignored: " + + metricsSettings[i]); + continue; + } + catch (std::invalid_argument const&) { + try { + col = aie::convertStringToUint8(metrics[i][0]); + } + catch (std::invalid_argument const&) { + xrt_core::message::send(severity_level::warning, "XRT", + "Column specification in tile_based_interface_tile_metrics " + "is not an integer and hence skipped."); + continue; + } + + bool foundChannels = false; + uint8_t channelId0 = 0; + uint8_t channelId1 = 1; + if (metrics[i].size() > 2) { + try { + foundChannels = true; + channelId0 = aie::convertStringToUint8(metrics[i][2]); + channelId1 = (metrics[i].size() == 3) ? channelId0 : aie::convertStringToUint8(metrics[i][3]); + } + catch (std::invalid_argument const&) { + foundChannels = false; + xrt_core::message::send(severity_level::warning, "XRT", + "Channel ID specification in tile_based_interface_tile_metrics " + "is not an integer and hence ignored."); + } + } + + int16_t channelNum = foundChannels ? channelId0 : -1; + auto tiles = metadataReader->getInterfaceTiles("all", "all", metrics[i][1], + channelNum, true, col, col); + + for (auto& t : tiles) { + configMetrics[moduleIdx][t] = metrics[i][1]; + configChannel0[t] = channelId0; + configChannel1[t] = channelId1; + } + } + } + + const std::string defaultSet = "peak_read_bandwidth"; + bool showWarning = true; + std::vector offTiles; + const auto& metricVec = bandwidthMetricSets(); + + for (auto& tileMetric : configMetrics[moduleIdx]) { + if (tileMetric.second.empty() || tileMetric.second.compare("off") == 0) { + offTiles.push_back(tileMetric.first); + continue; + } + + if (metricVec.count(tileMetric.second) == 0) { + if (showWarning) { + std::string msg = "Unable to find interface_tile metric set " + tileMetric.second + + ". Using default of " + defaultSet + ". "; + xrt_core::message::send(severity_level::warning, "XRT", msg); + showWarning = false; + } + tileMetric.second = defaultSet; + } + } + + for (auto& t : offTiles) + configMetrics[moduleIdx].erase(t); + } + + std::vector> + AieDtraceMetadata::getConfigMetricsVec(int module) + { + if (module < 0 || module >= static_cast(configMetrics.size())) + return {}; + return {configMetrics[module].begin(), configMetrics[module].end()}; + } + + aie::driver_config + AieDtraceMetadata::getAIEConfigMetadata() + { + return metadataReader->getDriverConfig(); + } + + std::unique_ptr + AieDtraceMetadata::createAIEProfileConfig() + { + std::map emptyBytes; + std::map emptyLatency; + return std::make_unique( + configMetrics, configChannel0, configChannel1, + metadataReader->getAIETileRowOffset(), emptyBytes, emptyLatency); + } + +} // namespace xdp diff --git a/profile/plugin/aie_dtrace/aie_dtrace_metadata.h b/profile/plugin/aie_dtrace/aie_dtrace_metadata.h new file mode 100644 index 00000000..0b4c4103 --- /dev/null +++ b/profile/plugin/aie_dtrace/aie_dtrace_metadata.h @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved + +#ifndef AIE_DTRACE_METADATA_H +#define AIE_DTRACE_METADATA_H + +#include +#include +#include +#include +#include + +#include "xdp/profile/database/static_info/aie_constructs.h" +#include "xdp/profile/database/static_info/filetypes/base_filetype_impl.h" + +namespace xdp { + +class AieDtraceMetadata { + private: + static constexpr int SHIM_MODULE_IDX = static_cast(module_type::shim); + static constexpr int NUM_MODULES = static_cast(module_type::num_types); + + uint64_t deviceID = 0; + double clockFreqMhz = 0.0; + void* handle = nullptr; + bool configOnePartition = false; + + std::vector> configMetrics; + std::map configChannel0; + std::map configChannel1; + + const aie::BaseFiletypeImpl* metadataReader = nullptr; + + void checkDtraceSettings(); + void getConfigMetricsForInterfaceTiles(int moduleIdx, + const std::vector& metricsSettings); + bool isBandwidthMetricSet(const std::string& metricSet) const; + + public: + AieDtraceMetadata(uint64_t deviceID, void* handle); + + uint64_t getDeviceID() { return deviceID; } + void* getHandle() { return handle; } + + bool isConfigured() const { + return SHIM_MODULE_IDX < static_cast(configMetrics.size()) + && !configMetrics[SHIM_MODULE_IDX].empty(); + } + + bool isConfigOnePartition() const { return configOnePartition; } + + bool aieMetadataEmpty() { return metadataReader == nullptr; } + + std::vector getSettingsVector(std::string settingsString); + + std::vector> getConfigMetricsVec(int module); + + int getHardwareGen() const { + return metadataReader == nullptr ? 0 : metadataReader->getHardwareGeneration(); + } + + double getClockFreqMhz() { return clockFreqMhz; } + + std::vector getPartitionOverlayStartCols() const { + return metadataReader->getPartitionOverlayStartCols(); + } + + aie::driver_config getAIEConfigMetadata(); + + std::unique_ptr createAIEProfileConfig(); +}; + +} // namespace xdp + +#endif diff --git a/profile/plugin/aie_dtrace/aie_dtrace_plugin.cpp b/profile/plugin/aie_dtrace/aie_dtrace_plugin.cpp index 095de1e0..0b7f4faa 100644 --- a/profile/plugin/aie_dtrace/aie_dtrace_plugin.cpp +++ b/profile/plugin/aie_dtrace/aie_dtrace_plugin.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #define XDP_PLUGIN_SOURCE @@ -74,13 +74,15 @@ namespace xdp { if (!((db->getStaticInfo()).continueXDPConfig(hw_context_flow))) return; - if ((xrt_core::config::get_aie_profile_settings_config_one_partition()) && - (configuredOnePartition)) { - xrt_core::message::send( - severity_level::warning, "XRT", - "AIE dtrace: a previous partition was already configured; skipping " - "(config_one_partition=true)."); - return; + { + auto tree = xrt_core::config::detail::get_ptree_value("AIE_dtrace_settings"); + if (tree.get_optional("config_one_partition").value_or(false) && configuredOnePartition) { + xrt_core::message::send( + severity_level::warning, "XRT", + "AIE dtrace: a previous partition was already configured; skipping " + "(config_one_partition=true)."); + return; + } } if (hw_context_flow) { @@ -130,19 +132,17 @@ namespace xdp { return; #endif - auto metadata = - std::make_shared(deviceID, handle, aie_dtrace_ini_metadata_tag{}); + auto metadata = std::make_shared(deviceID, handle); if (metadata->aieMetadataEmpty()) { xrt_core::message::send(severity_level::debug, "XRT", "AIE dtrace: no AIE metadata for this xclbin; skipping."); return; } - if ((xrt_core::config::get_aie_profile_settings_config_one_partition()) && - (metadata->isConfigured())) + if (metadata->isConfigOnePartition() && metadata->isConfigured()) configuredOnePartition = true; - std::unique_ptr implementation; + std::unique_ptr implementation; #if defined(XDP_VE2_BUILD) implementation = std::make_unique(db, metadata, deviceID); #else @@ -151,11 +151,6 @@ namespace xdp { return; #endif - if (!(db->getStaticInfo()).isAIECounterRead(deviceID)) { - implementation->updateDevice(); - (db->getStaticInfo()).setIsAIECounterRead(deviceID, true); - } - (db->getStaticInfo()).saveProfileConfig(metadata->createAIEProfileConfig(), deviceID); handleToAIEDtraceImpl[handle] = std::move(implementation); diff --git a/profile/plugin/aie_dtrace/aie_dtrace_plugin.h b/profile/plugin/aie_dtrace/aie_dtrace_plugin.h index c74c4ecf..b57e07af 100644 --- a/profile/plugin/aie_dtrace/aie_dtrace_plugin.h +++ b/profile/plugin/aie_dtrace/aie_dtrace_plugin.h @@ -1,11 +1,11 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #ifndef XDP_AIE_DTRACE_PLUGIN_DOT_H #define XDP_AIE_DTRACE_PLUGIN_DOT_H -#include "xdp/profile/plugin/aie_profile/aie_profile_impl.h" -#include "xdp/profile/plugin/aie_profile/aie_profile_metadata.h" +#include "xdp/profile/plugin/aie_dtrace/aie_dtrace_impl.h" +#include "xdp/profile/plugin/aie_dtrace/aie_dtrace_metadata.h" #include "xdp/profile/plugin/vp_base/vp_base_plugin.h" namespace xdp { @@ -41,7 +41,7 @@ namespace xdp { static bool live; static bool configuredOnePartition; - std::map> handleToAIEDtraceImpl; + std::map> handleToAIEDtraceImpl; }; } // namespace xdp diff --git a/profile/plugin/aie_dtrace/util/aie_dtrace_util.cpp b/profile/plugin/aie_dtrace/util/aie_dtrace_util.cpp index 6959f9e4..93352107 100644 --- a/profile/plugin/aie_dtrace/util/aie_dtrace_util.cpp +++ b/profile/plugin/aie_dtrace/util/aie_dtrace_util.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #define XDP_PLUGIN_SOURCE diff --git a/profile/plugin/aie_dtrace/util/aie_dtrace_util.h b/profile/plugin/aie_dtrace/util/aie_dtrace_util.h index b3a6b92f..2a49a334 100644 --- a/profile/plugin/aie_dtrace/util/aie_dtrace_util.h +++ b/profile/plugin/aie_dtrace/util/aie_dtrace_util.h @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #ifndef AIE_DTRACE_UTIL_DOT_H #define AIE_DTRACE_UTIL_DOT_H diff --git a/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.cpp b/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.cpp index 8d061b4f..dd6553cd 100644 --- a/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.cpp +++ b/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.cpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #define XDP_PLUGIN_SOURCE #include "xdp/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.h" -#include "xdp/profile/plugin/aie_profile/aie_profile_metadata.h" +#include "xdp/profile/plugin/aie_dtrace/aie_dtrace_metadata.h" #include "xdp/profile/database/database.h" #include "xdp/profile/database/static_info/aie_constructs.h" #include "xdp/profile/database/static_info/aie_util.h" @@ -83,7 +83,7 @@ using severity_level = xrt_core::message::severity_level; namespace fs = std::filesystem; AieDtraceCTWriter::AieDtraceCTWriter(VPDatabase* database, - std::shared_ptr metadata, + std::shared_ptr metadata, uint64_t deviceId, uint8_t startCol) : db(database) diff --git a/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.h b/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.h index f8455996..d3e52770 100644 --- a/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.h +++ b/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.h @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #ifndef AIE_DTRACE_CT_WRITER_H #define AIE_DTRACE_CT_WRITER_H @@ -18,7 +18,7 @@ namespace xdp { // Forward declarations class VPDatabase; -class AieProfileMetadata; +class AieDtraceMetadata; struct AIECounter; /** @@ -106,14 +106,14 @@ class AieDtraceCTWriter { /** * @brief Constructor * @param database Pointer to the VPDatabase for accessing counter configuration - * @param metadata Pointer to AieProfileMetadata for AIE configuration info + * @param metadata Pointer to AieDtraceMetadata for AIE configuration info * @param deviceId The device ID for which to generate the CT file * @param startCol Absolute start column of the hw_context partition; added to * relative counter columns so the CT file contains absolute * hardware addresses regardless of where XRT placed the partition */ AieDtraceCTWriter(VPDatabase* database, - std::shared_ptr metadata, + std::shared_ptr metadata, uint64_t deviceId, uint8_t startCol); @@ -297,7 +297,7 @@ class AieDtraceCTWriter { private: VPDatabase* db; - std::shared_ptr metadata; + std::shared_ptr metadata; uint64_t deviceId; // AIE configuration values diff --git a/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.cpp b/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.cpp index 67f284d6..786e1d2b 100644 --- a/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.cpp +++ b/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.cpp @@ -1,181 +1,38 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved -#define XDP_PLUGIN_SOURCE +#define XDP_PLUGIN_SOURCE #include "xdp/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.h" #include "xdp/profile/plugin/aie_dtrace/ve2/aie_dtrace_ct_writer.h" -#include "xdp/profile/plugin/aie_profile/aie_profile_defs.h" -#include "xdp/profile/plugin/aie_profile/aie_profile_metadata.h" -#include "xdp/profile/plugin/aie_profile/util/aie_profile_util.h" -#include "xdp/profile/plugin/aie_profile/util/aie_profile_config.h" -#include "xdp/profile/plugin/aie_base/aie_base_util.h" -#include "xdp/profile/plugin/aie_base/aie_nop_util.h" - -#include "xdp/profile/database/database.h" -#include "xdp/profile/device/utility.h" -#include "xdp/profile/database/static_info/aie_util.h" -#include "xdp/profile/database/static_info/aie_constructs.h" -#include "xdp/profile/database/static_info/pl_constructs.h" - -#include -#include -#include -#include -#include +#include "xdp/profile/plugin/aie_dtrace/ve2/elf_helper.h" -#include "core/common/message.h" -#include "core/common/time.h" -#include "core/common/config_reader.h" +#include "core/common/api/hw_context_int.h" #include "core/common/api/kernel_int.h" - -#include -#include -#include +#include "core/common/config_reader.h" +#include "core/common/message.h" #include "core/common/shim/hwctx_handle.h" -#include "core/common/api/hw_context_int.h" -#include "xdp/profile/plugin/aie_dtrace/ve2/elf_helper.h" -#include "shim_ve2/xdna_hwctx.h" -namespace { - static void* fetchAieDevInst(void* devHandle) - { - xrt::hw_context context = xrt_core::hw_context_int::create_hw_context_from_implementation(devHandle); - auto hwctx_hdl = static_cast(context); - auto hwctx_obj = dynamic_cast(hwctx_hdl); - auto aieArray = hwctx_obj->get_aie_array(); - return aieArray->get_dev() ; - } - - static void* allocateAieDevice(void* devHandle) - { - auto aieDevInst = static_cast(fetchAieDevInst(devHandle)) ; - if (!aieDevInst) - return nullptr; - return new xaiefal::XAieDev(aieDevInst, false) ; - } +#include "xdp/profile/database/static_info/aie_util.h" - static void deallocateAieDevice(void* aieDevice) - { - auto object = static_cast(aieDevice) ; - if (object != nullptr) - delete object ; - } -} // end anonymous namespace +#include +#include +#include namespace xdp { - using tile_type = xdp::tile_type; - using module_type = xdp::module_type; using severity_level = xrt_core::message::severity_level; - AieDtrace_VE2Impl::AieDtrace_VE2Impl(VPDatabase* database, std::shared_ptr metadata, uint64_t deviceID) - : AieProfileImpl(database, metadata, deviceID) - { - auto hwGen = metadata->getHardwareGen(); - - coreStartEvents = aie::profile::getCoreEventSets(hwGen); - coreEndEvents = coreStartEvents; - - memoryStartEvents = aie::profile::getMemoryEventSets(hwGen); - memoryEndEvents = memoryStartEvents; - - shimStartEvents = aie::profile::getInterfaceTileEventSets(hwGen); - for (const auto& kv : aie::dtrace::getBandwidthInterfaceTileEventSets(hwGen)) - shimStartEvents[kv.first] = kv.second; - shimEndEvents = shimStartEvents; - shimEndEvents[METRIC_BYTE_COUNT] = {XAIE_EVENT_PORT_RUNNING_0_PL, XAIE_EVENT_PERF_CNT_0_PL}; + static constexpr int SHIM_MODULE_IDX = static_cast(module_type::shim); - memTileStartEvents = aie::profile::getMemoryTileEventSets(hwGen); - memTileEndEvents = memTileStartEvents; - - microcontrollerEvents = aie::profile::getMicrocontrollerEventSets(hwGen); - } + AieDtrace_VE2Impl::AieDtrace_VE2Impl(VPDatabase* database, + std::shared_ptr metadata, + uint64_t deviceID) + : AieDtraceImpl(database, metadata, deviceID) + {} - AieDtrace_VE2Impl::~AieDtrace_VE2Impl() + void AieDtrace_VE2Impl::updateDevice() { - // Hw context destructor / plugin teardown: do not read counters or offload samples to the - // dynamic database. Only stop/release FAL resources; join if a poll thread existed. - if (thread && thread->joinable()) { - threadCtrl = false; - thread->join(); - } - releaseConfiguredHwResourcesNoRead(); - } - - bool AieDtrace_VE2Impl::checkAieDevice(const uint64_t deviceId, void* handle) - { - aieDevInst = static_cast(db->getStaticInfo().getAieDevInst(fetchAieDevInst, handle, deviceId)) ; - aieDevice = static_cast(db->getStaticInfo().getAieDevice(allocateAieDevice, deallocateAieDevice, handle, deviceId)) ; - if (!aieDevInst || !aieDevice) { - xrt_core::message::send(severity_level::warning, "XRT", - "Unable to get AIE device. There will be no AIE profiling."); - return false; - } - return true; - } - - void AieDtrace_VE2Impl::updateDevice() { - - if(!checkAieDevice(deviceID, metadata->getHandle())) - return; - - // CT file handles all hardware configuration via write_reg commands in begin block. - // No need to submit nop.elf or call setMetricsSettings here. - // The code below is preserved for potential fallback flow in the future. - return; - - bool runtimeCounters = setMetricsSettings(deviceID, metadata->getHandle()); - - if (!runtimeCounters) { - void* h = metadata->getHandle(); - std::shared_ptr device = xrt_core::get_userpf_device(h); - if (!device) - device = xdp::util::convertToCoreDevice(h, true); - if (!device) { - xrt_core::message::send(severity_level::warning, "XRT", - "AIE dtrace: could not resolve core device for xclbin profile counters."); - (db->getStaticInfo()).setIsAIECounterRead(deviceID, true); - return; - } - auto counters = xrt_core::edge::aie::get_profile_counters(device.get()); - - if (counters.empty()) { - xrt_core::message::send(severity_level::warning, "XRT", - "AIE dtrace: no counters found. Specify " - "AIE_dtrace_settings.tile_based_interface_tile_metrics or " - "graph_based_interface_tile_metrics (same style as AIE_profile_settings)."); - (db->getStaticInfo()).setIsAIECounterRead(deviceID,true); - return; - } - else { - XAie_DevInst* aieDevInst = - static_cast(db->getStaticInfo().getAieDevInst(fetchAieDevInst, metadata->getHandle())); - - if (!aieDevInst) { - xrt_core::message::send(severity_level::warning, "XRT", - "Failed to get AIE device instance for profile counters."); - return; - } - - xrt_core::message::send(severity_level::debug, "XRT", "Processing " + std::to_string(counters.size()) + " counters"); - for (auto& counter : counters) { - std::stringstream msg; - msg << "Adding counter " << counter.id << " at (" - << +counter.column << "," << +counter.row << ") module: " << counter.module; - xrt_core::message::send(severity_level::debug, "XRT", msg.str()); - - // For pre-configured counters from xclbin metadata, the hardware is already configured - // Payload is used for reporting metadata (channel/stream IDs), set to 0 for these counters - // as we don't have full tile information (stream_ids, is_master_vec) to safely compute it - uint64_t payload = 0; - - (db->getStaticInfo()).addAIECounter(deviceID, counter.id, counter.column, - counter.row, counter.counterNumber, counter.startEvent, counter.endEvent, - counter.resetEvent, payload, counter.clockFreqMhz, counter.module, counter.name); - } - xrt_core::message::send(severity_level::debug, "XRT", "Finished processing counters"); - } - } + // Bandwidth CT generation configures hardware via write_reg in the begin block. } void AieDtrace_VE2Impl::computeOpLocations(void* elf_handle, const std::string& kernel_name) @@ -232,63 +89,43 @@ namespace xdp { auto ctx = xrt_core::hw_context_int::create_hw_context_from_implementation(hwctx); auto slotIdx = static_cast(ctx)->get_slotidx(); - std::string filename = "aie_profile_ctx_" + std::to_string(slotIdx) + std::string filename = "aie_dtrace_ctx_" + std::to_string(slotIdx) + "_run_" + std::to_string(run_uid) + ".ct"; std::string outputPath = (std::filesystem::current_path() / filename).string(); computeOpLocations(elf_handle, kernel_name); + auto it = m_op_locations_cache.find(kernel_name); + if (it == m_op_locations_cache.end() || it->second.empty()) { + xrt_core::message::send(severity_level::debug, "XRT", + "AIE dtrace: No op_locations for kernel '" + kernel_name + "'; skipping CT generation."); + return; + } + boost::property_tree::ptree aiePartitionPt = xdp::aie::getAIEPartitionInfo(hwctx); uint8_t partitionStartCol = aiePartitionPt.empty() ? 0 : static_cast(aiePartitionPt.back().second.get("start_col")); AieDtraceCTWriter ctWriter(db, metadata, deviceID, partitionStartCol); - // Get the metric set for interface tiles (module index 2 = shim) - std::string bandwidthMetricSet = "ddr_bandwidth"; - auto shimConfigMetrics = metadata->getConfigMetricsVec(2); + std::string bandwidthMetricSet = "peak_read_bandwidth"; + auto shimConfigMetrics = metadata->getConfigMetricsVec(SHIM_MODULE_IDX); if (!shimConfigMetrics.empty()) { bandwidthMetricSet = shimConfigMetrics.front().second; xrt_core::message::send(severity_level::info, "XRT", "AIE dtrace: Using metric set '" + bandwidthMetricSet + "' from configuration"); } else { xrt_core::message::send(severity_level::info, "XRT", - "AIE dtrace: No interface tile metrics configured, using default 'ddr_bandwidth'"); - } - - bool generated = false; - auto it = m_op_locations_cache.find(kernel_name); - - if (it != m_op_locations_cache.end() && !it->second.empty()) { - generated = ctWriter.generateBandwidthCT(outputPath, hwctx, it->second, bandwidthMetricSet); - if (generated) { - xrt_core::message::send(severity_level::debug, "XRT", - "AIE dtrace: Bandwidth CT generated (self-contained) for kernel '" - + kernel_name + "' with metric set '" + bandwidthMetricSet + "'"); - } + "AIE dtrace: No interface tile metrics configured, using default 'peak_read_bandwidth'"); } - if (!generated && it != m_op_locations_cache.end() && !it->second.empty()) { - if (db->getStaticInfo().getNumAIECounter(deviceID) > 0) { - generated = ctWriter.generate(outputPath, it->second); - if (generated) - xrt_core::message::send(severity_level::debug, "XRT", - "AIE dtrace: CT generated using aiebu API (get_op_locations) for kernel '" - + kernel_name + "'"); - } - } - - if (!generated && db->getStaticInfo().getNumAIECounter(deviceID) > 0) { - generated = ctWriter.generate(outputPath); - if (generated) - xrt_core::message::send(severity_level::debug, "XRT", - "AIE dtrace: CT generated using CSV file (aie_profile_timestamps.csv) for kernel '" - + kernel_name + "'"); - } - - if (!generated) + if (!ctWriter.generateBandwidthCT(outputPath, hwctx, it->second, bandwidthMetricSet)) return; + xrt_core::message::send(severity_level::debug, "XRT", + "AIE dtrace: Bandwidth CT generated for kernel '" + kernel_name + + "' with metric set '" + bandwidthMetricSet + "'"); + auto* run_impl = static_cast(run_impl_ptr); try { xrt_core::kernel_int::set_dtrace_control_file(run_impl, outputPath); @@ -304,461 +141,4 @@ namespace xdp { } } - // Get reportable payload specific for this tile and/or counter - uint64_t - AieDtrace_VE2Impl::getCounterPayload(XAie_DevInst* aieDevInst, - const tile_type& tile, - const module_type type, - uint8_t column, - uint8_t row, - uint16_t startEvent, - const std::string metricSet, - const uint8_t channel, - uint8_t logicalPortIndex) - { - // 1. Profile API specific values - if (aie::profile::profileAPIMetricSet(metricSet)) - return getAdfProfileAPIPayload(tile, metricSet); - - // 2. Channel/stream IDs for interface tiles - if (type == module_type::shim) { - // NOTE: value = ((isMaster) << 8) & (isChannel << 7) & (channel/stream ID) - // portnum = physical stream-switch port (0-7) from event; stream_ids/is_master_vec - // are indexed by logical port (size = number of configured ports). When portnum is - // out of range (e.g. physical ports 4-7 when only 4 logical ports), use - // logicalPortIndex. - auto portnum = xdp::aie::getPortNumberFromEvent(static_cast(startEvent)); - uint8_t streamPortId = (portnum >= tile.stream_ids.size()) ? - 0 : static_cast(tile.stream_ids.at(portnum)); - uint8_t idToReport = (tile.subtype == io_type::GMIO) ? channel : streamPortId; - uint8_t isChannel = (tile.subtype == io_type::GMIO) ? 1 : 0; - uint8_t isMaster = aie::isInputSet(type, metricSet) ? 0 : 1; - if ((type == module_type::shim) && ((metricSet == "ddr_bandwidth") || (metricSet == "read_bandwidth") || - (metricSet == "write_bandwidth") || (metricSet == "peak_read_bandwidth") || - (metricSet == "peak_write_bandwidth"))) { - uint8_t idx = (portnum < tile.is_master_vec.size()) ? portnum - : (logicalPortIndex < tile.is_master_vec.size()) ? logicalPortIndex : 0; - isMaster = tile.is_master_vec.at(idx); - } - - return ((isMaster << PAYLOAD_IS_MASTER_SHIFT) - | (isChannel << PAYLOAD_IS_CHANNEL_SHIFT) | idToReport); - } - - // 3. Channel IDs for memory tiles - if (type == module_type::mem_tile) { - // NOTE: value = ((isMaster) << 8) & (isChannel << 7) & (channel ID) - uint8_t isChannel = 1; - uint8_t isMaster = aie::isInputSet(type, metricSet) ? 1 : 0; - return ((isMaster << PAYLOAD_IS_MASTER_SHIFT) - | (isChannel << PAYLOAD_IS_CHANNEL_SHIFT) | channel); - } - - // 4. DMA BD sizes for AIE tiles - // NOTE: value = ((max BD size) << 16) & ((isMaster) << 8) & (isChannel << 7) & (channel ID) - uint8_t isChannel = 1; - uint8_t isMaster = aie::isInputSet(type, metricSet) ? 1 : 0; - uint32_t payloadValue = ((isMaster << PAYLOAD_IS_MASTER_SHIFT) - | (isChannel << PAYLOAD_IS_CHANNEL_SHIFT) | channel); - - if ((metadata->getHardwareGen() != 1) - || ((startEvent != XAIE_EVENT_DMA_S2MM_0_FINISHED_BD_MEM) - && (startEvent != XAIE_EVENT_DMA_S2MM_1_FINISHED_BD_MEM) - && (startEvent != XAIE_EVENT_DMA_MM2S_0_FINISHED_BD_MEM) - && (startEvent != XAIE_EVENT_DMA_MM2S_1_FINISHED_BD_MEM))) - return payloadValue; - - // Get average BD size for throughput calculations (AIE1 only) - constexpr int NUM_BDS = 8; - constexpr uint32_t BYTES_PER_WORD = 4; - constexpr uint32_t ACTUAL_OFFSET = 1; - uint64_t offsets[NUM_BDS] = {XAIEGBL_MEM_DMABD0CTRL, XAIEGBL_MEM_DMABD1CTRL, - XAIEGBL_MEM_DMABD2CTRL, XAIEGBL_MEM_DMABD3CTRL, - XAIEGBL_MEM_DMABD4CTRL, XAIEGBL_MEM_DMABD5CTRL, - XAIEGBL_MEM_DMABD6CTRL, XAIEGBL_MEM_DMABD7CTRL}; - uint32_t lsbs[NUM_BDS] = {XAIEGBL_MEM_DMABD0CTRL_LEN_LSB, XAIEGBL_MEM_DMABD1CTRL_LEN_LSB, - XAIEGBL_MEM_DMABD2CTRL_LEN_LSB, XAIEGBL_MEM_DMABD3CTRL_LEN_LSB, - XAIEGBL_MEM_DMABD4CTRL_LEN_LSB, XAIEGBL_MEM_DMABD5CTRL_LEN_LSB, - XAIEGBL_MEM_DMABD6CTRL_LEN_LSB, XAIEGBL_MEM_DMABD7CTRL_LEN_LSB}; - uint32_t masks[NUM_BDS] = {XAIEGBL_MEM_DMABD0CTRL_LEN_MASK, XAIEGBL_MEM_DMABD1CTRL_LEN_MASK, - XAIEGBL_MEM_DMABD2CTRL_LEN_MASK, XAIEGBL_MEM_DMABD3CTRL_LEN_MASK, - XAIEGBL_MEM_DMABD4CTRL_LEN_MASK, XAIEGBL_MEM_DMABD5CTRL_LEN_MASK, - XAIEGBL_MEM_DMABD6CTRL_LEN_MASK, XAIEGBL_MEM_DMABD7CTRL_LEN_MASK}; - uint32_t valids[NUM_BDS] = {XAIEGBL_MEM_DMABD0CTRL_VALBD_MASK, XAIEGBL_MEM_DMABD1CTRL_VALBD_MASK, - XAIEGBL_MEM_DMABD2CTRL_VALBD_MASK, XAIEGBL_MEM_DMABD3CTRL_VALBD_MASK, - XAIEGBL_MEM_DMABD4CTRL_VALBD_MASK, XAIEGBL_MEM_DMABD5CTRL_VALBD_MASK, - XAIEGBL_MEM_DMABD6CTRL_VALBD_MASK, XAIEGBL_MEM_DMABD7CTRL_VALBD_MASK}; - - uint32_t maxBDSize = 0; - auto tileOffset = XAie_GetTileAddr(aieDevInst, row, column); - for (int bd = 0; bd < NUM_BDS; ++bd) { - uint32_t regValue = 0; - XAie_Read32(aieDevInst, tileOffset + offsets[bd], ®Value); - - if (regValue & valids[bd]) { - uint32_t bdBytes = BYTES_PER_WORD * (((regValue >> lsbs[bd]) & masks[bd]) + ACTUAL_OFFSET); - maxBDSize = std::max(bdBytes, maxBDSize); - } - } - - payloadValue |= (maxBDSize << PAYLOAD_BD_SIZE_SHIFT); - return payloadValue; - } - - uint64_t - AieDtrace_VE2Impl::getAdfProfileAPIPayload(const tile_type& tile, const std::string metricSet) - { - if (metricSet == METRIC_LATENCY) - return metadata->getIntfLatencyPayload(tile); - - return 0; - } - - void AieDtrace_VE2Impl::printTileModStats(xaiefal::XAieDev* aieDevice, - const tile_type& tile, XAie_ModuleType mod) - { - auto col = tile.col; - auto row = tile.row; - auto loc = XAie_TileLoc(col, row); - std::string moduleName = (mod == XAIE_CORE_MOD) ? "aie" - : ((mod == XAIE_MEM_MOD) ? "aie_memory" - : "interface_tile"); - const std::string groups[3] = { - XAIEDEV_DEFAULT_GROUP_GENERIC, - XAIEDEV_DEFAULT_GROUP_STATIC, - XAIEDEV_DEFAULT_GROUP_AVAIL - }; - - std::stringstream msg; - msg << "Resource usage stats for Tile : (" << +col << "," << +row - << ") Module : " << moduleName << std::endl; - for (auto&g : groups) { - auto stats = aieDevice->getRscStat(g); - auto pc = stats.getNumRsc(loc, mod, xaiefal::XAIE_PERFCOUNT); - auto ts = stats.getNumRsc(loc, mod, xaiefal::XAIE_TRACEEVENT); - auto bc = stats.getNumRsc(loc, mod, xaiefal::XAIE_BROADCAST); - msg << "Resource Group : " << std::left << std::setw(10) << g << " " - << "Performance Counters : " << pc << " " - << "Trace Slots : " << ts << " " - << "Broadcast Channels : " << bc << " " - << std::endl; - } - - xrt_core::message::send(severity_level::info, "XRT", msg.str()); - } - - // Set metrics for all specified AIE counters on this device with configs given in AIE_profile_settings - bool - AieDtrace_VE2Impl::setMetricsSettings(const uint64_t deviceId, void* handle) - { - int counterId = 0; - bool runtimeCounters = false; - - auto stats = aieDevice->getRscStat(XAIEDEV_DEFAULT_GROUP_AVAIL); - auto hwGen = metadata->getHardwareGen(); - auto configChannel0 = metadata->getConfigChannel0(); - auto configChannel1 = metadata->getConfigChannel1(); - uint8_t startColShift = metadata->getPartitionOverlayStartCols().front(); - aie::displayColShiftInfo(startColShift); - - for (int module = 0; module < metadata->getNumModules(); ++module) { - auto configMetrics = metadata->getConfigMetricsVec(module); - if (configMetrics.empty()) - continue; - - int numTileCounters[metadata->getNumCountersMod(module)+1] = {0}; - XAie_ModuleType mod = aie::profile::getFalModuleType(module); - - // Iterate over tiles and metrics to configure all desired counters - for (auto& tileMetric : configMetrics) { - auto& metricSet = tileMetric.second; - auto tile = tileMetric.first; - auto col = tile.col + startColShift; - auto row = tile.row; - auto subtype = tile.subtype; - auto type = aie::getModuleType(row, metadata->getAIETileRowOffset()); - if ((mod == XAIE_MEM_MOD) && (type == module_type::core)) - type = module_type::dma; - - // Catch microcontroller event sets for MDM - if (module == static_cast(module_type::uc)) { - // Configure - auto events = microcontrollerEvents[metricSet]; - aie::profile::configMDMCounters(aieDevInst, hwGen, col, row, events); - // Record - tile_type recordTile; - recordTile.col = col; - recordTile.row = row; - microcontrollerTileEvents[recordTile] = events; - runtimeCounters = true; - continue; - } - - // Ignore invalid types and inactive modules - // NOTE: Inactive core modules are configured when utilizing - // stream switch monitor ports to profile DMA channels - if (!aie::profile::isValidType(type, mod)) - continue; - if ((type == module_type::dma) && !tile.active_memory) - continue; - if ((type == module_type::core) && !tile.active_core) { - if (metadata->getPairModuleIndex(metricSet, type) < 0) - continue; - } - - // Skip interface tiles with empty stream_ids for throughput metrics - if ((type == module_type::shim) && - ((metricSet == "read_bandwidth") || (metricSet == "write_bandwidth") || - (metricSet == "ddr_bandwidth") || (metricSet == "peak_read_bandwidth") || - (metricSet == "peak_write_bandwidth")) && - tile.stream_ids.empty()) { - std::stringstream msg; - msg << "Skipping " << metricSet << " configuration for tile (" << +col << "," << +row - << ") - stream_ids is empty"; - xrt_core::message::send(severity_level::warning, "XRT", msg.str()); - continue; - } - - auto loc = XAie_TileLoc(col, row); - auto& xaieTile = aieDevice->tile(col, row); - auto xaieModule = (mod == XAIE_CORE_MOD) ? xaieTile.core() - : ((mod == XAIE_MEM_MOD) ? xaieTile.mem() - : xaieTile.pl()); - - auto startEvents = (type == module_type::core) ? coreStartEvents[metricSet] - : ((type == module_type::dma) ? memoryStartEvents[metricSet] - : ((type == module_type::shim) ? shimStartEvents[metricSet] - : memTileStartEvents[metricSet])); - auto endEvents = (type == module_type::core) ? coreEndEvents[metricSet] - : ((type == module_type::dma) ? memoryEndEvents[metricSet] - : ((type == module_type::shim) ? shimEndEvents[metricSet] - : memTileEndEvents[metricSet])); - std::vector resetEvents = {}; - - int numCounters = 0; - auto numFreeCtr = stats.getNumRsc(loc, mod, xaiefal::XAIE_PERFCOUNT); - - if (aie::isDebugVerbosity() && ((metricSet == "ddr_bandwidth") || (metricSet == "read_bandwidth") || - (metricSet == "write_bandwidth") || (metricSet == "peak_read_bandwidth") || - (metricSet == "peak_write_bandwidth"))) { - std::stringstream msg; - msg << metricSet << " **** counter reservation: tile (" << +col << "," << +row - << ") startEvents.size()=" << startEvents.size() - << " hardware_counters=" << numFreeCtr - << " tile.stream_ids.size()=" << tile.stream_ids.size(); - xrt_core::message::send(severity_level::debug, "XRT", msg.str()); - } - - numFreeCtr = (startEvents.size() < numFreeCtr) ? startEvents.size() : numFreeCtr; - if ((type == module_type::shim) && ((metricSet == "ddr_bandwidth") || (metricSet == "read_bandwidth") || - (metricSet == "write_bandwidth") || (metricSet == "peak_read_bandwidth") || - (metricSet == "peak_write_bandwidth"))) { - numFreeCtr = tile.stream_ids.size(); - } - - int numFreeCtrSS = numFreeCtr; - if (aie::profile::profileAPIMetricSet(metricSet)) { - if (numFreeCtr < 2) { - continue; - } - // We need to monitor single stream switch monitor port - // numFreeCtrSS = 1 ; - } - - // Specify Sel0/Sel1 for memory tile events 21-44 - auto iter0 = configChannel0.find(tile); - auto iter1 = configChannel1.find(tile); - uint8_t channel0 = (iter0 == configChannel0.end()) ? 0 : iter0->second; - uint8_t channel1 = (iter1 == configChannel1.end()) ? 1 : iter1->second; - - // Modify events as needed - aie::profile::modifyEvents(type, subtype, channel0, startEvents, metadata->getHardwareGen()); - endEvents = startEvents; - - // TBD : Placeholder to configure AIE core with required profile counters. - aie::profile::configEventSelections(aieDevInst, loc, type, metricSet, channel0); - // TBD : Placeholder to configure shim tile with required profile counters. - - aie::profile::configStreamSwitchPorts(tileMetric.first, xaieTile, loc, type, - numFreeCtrSS, metricSet, channel0, channel1, startEvents, endEvents, streamPorts); - - // Identify the profiling API metric sets and configure graph events - if (metadata->getUseGraphIterator() && !graphItrBroadcastConfigDone) { - XAie_Events bcEvent = XAIE_EVENT_NONE_CORE; - bool status = aie::profile::configGraphIteratorAndBroadcast(aieDevInst, aieDevice, - metadata, xaieModule, loc, mod, type, metricSet, bcEvent, bcResourcesBytesTx); - if (status) { - graphIteratorBrodcastChannelEvent = bcEvent; - graphItrBroadcastConfigDone = true; - } - } - - if (aie::profile::profileAPIMetricSet(metricSet)) { - // Re-use the existing port running event for both the counters - startEvents[startEvents.size()-1] = startEvents[0]; - - // Use start events as End events for profile counters if threshold is not provided - endEvents[endEvents.size()-1] = endEvents[0]; - - // Use the set values broadcast events for the reset of counter - resetEvents = {XAIE_EVENT_NONE_CORE, XAIE_EVENT_NONE_CORE}; - if (type == module_type::shim) { - if (metadata->getUseGraphIterator()) - resetEvents = {graphIteratorBrodcastChannelEvent, graphIteratorBrodcastChannelEvent}; - else - resetEvents = {XAIE_EVENT_NONE_CORE, XAIE_EVENT_USER_EVENT_1_PL}; - } - } - - uint32_t threshold = 0; - // Request and configure all available counters for this tile - for (int i=0; i < numFreeCtr; ++i) { - auto startEvent = startEvents.at(i); - auto endEvent = endEvents.at(i); - auto resetEvent = XAIE_EVENT_NONE_CORE; - auto portnum = xdp::aie::getPortNumberFromEvent(startEvent); - // For metric sets with 4 ports (like ddr_bandwidth), use modulo for channel mapping - uint8_t channelNum = portnum % 2; - uint8_t channel = (channelNum == 0) ? channel0 : channel1; - - // Configure group event before reserving and starting counter - aie::profile::configGroupEvents(aieDevInst, loc, mod, type, metricSet, startEvent, channel); - - // Configure the profile counters for profile APIs metric sets. - std::shared_ptr perfCounter = nullptr; - if (aie::profile::profileAPIMetricSet(metricSet)) { - resetEvent = resetEvents.at(i); - threshold = metadata->getUserSpecifiedThreshold(tileMetric.first, tileMetric.second); - threshold = aie::profile::convertToBeats(tileMetric.second, threshold, metadata->getHardwareGen()); - - if (i==0 && threshold>0) - endEvent = XAIE_EVENT_PERF_CNT_1_PL; - - if (i==1 && threshold == 0) - continue; - - XAie_Events retCounterEvent = XAIE_EVENT_NONE_CORE; - perfCounter = aie::profile::configProfileAPICounters(aieDevInst, aieDevice, metadata, xaieModule, - mod, type, metricSet, startEvent, endEvent, resetEvent, i, perfCounters.size(), - threshold, retCounterEvent, tile, bcResourcesLatency, adfAPIResourceInfoMap, adfAPIBroadcastEventsMap); - } - else { - // Request counter from resource manager - perfCounter = xaieModule.perfCounter(); - auto ret = perfCounter->initialize(mod, startEvent, mod, endEvent); - if (ret != XAIE_OK) break; - ret = perfCounter->reserve(); - if (ret != XAIE_OK) break; - - // Start the counter - ret = perfCounter->start(); - if (ret != XAIE_OK) break; - } - if (!perfCounter) - continue; - perfCounters.push_back(perfCounter); - - // Generate user_event_1 for byte count metric set after configuration - if ((metricSet == METRIC_BYTE_COUNT) && (i == 1) && !graphItrBroadcastConfigDone) { - XAie_LocType tileloc = XAie_TileLoc(tile.col, tile.row); - //Note: For BYTE_COUNT metric, user_event_1 is used twice as eventA & eventB to - // to transition the FSM from Idle->State0->State1. - // eventC = Port Running and eventD = stop event (counter event). - XAie_EventGenerate(aieDevInst, tileloc, mod, XAIE_EVENT_USER_EVENT_1_PL); - XAie_EventGenerate(aieDevInst, tileloc, mod, XAIE_EVENT_USER_EVENT_1_PL); - } - - // Convert enums to physical event IDs for reporting purposes - auto physicalEventIds = aie::profile::getEventPhysicalId(aieDevInst, loc, mod, type, metricSet, - startEvent, endEvent); - uint16_t phyStartEvent = physicalEventIds.first; - uint16_t phyEndEvent = physicalEventIds.second; - - // Get payload for reporting purposes - uint64_t payload = getCounterPayload(aieDevInst, tileMetric.first, type, col, row, - startEvent, metricSet, channel, static_cast(i)); - // Store counter info in database - std::string counterName = "AIE Counter " + std::to_string(counterId); - (db->getStaticInfo()).addAIECounter(deviceId, counterId, col, row, i, - phyStartEvent, phyEndEvent, resetEvent, payload, metadata->getClockFreqMhz(), - metadata->getModuleName(module), counterName, (tile.stream_ids.empty() ? 0 : tile.stream_ids[0])); - counterId++; - numCounters++; - } // numFreeCtr - - std::stringstream msg; - msg << "Reserved " << numCounters << " counters for profiling AIE tile (" << +col - << "," << +row << ") using metric set " << metricSet << "."; - xrt_core::message::send(severity_level::debug, "XRT", msg.str()); - numTileCounters[numCounters]++; - } // configMetrics - - // Report counters reserved per tile - { - std::stringstream msg; - msg << "AIE profile counters reserved in " << metadata->getModuleName(module) << " - "; - for (int n=0; n <= metadata->getNumCountersMod(module); ++n) { - if (numTileCounters[n] == 0) - continue; - msg << n << ": " << numTileCounters[n] << " tiles, "; - (db->getStaticInfo()).addAIECounterResources(deviceId, n, numTileCounters[n], module); - } - xrt_core::message::send(severity_level::info, "XRT", msg.str().substr(0, msg.str().size()-2)); - } - - runtimeCounters = true; - } // modules - - return runtimeCounters; - } - - // Dtrace does not run a profiling poll loop or offload samples; bandwidth is consumed via dtrace. - void AieDtrace_VE2Impl::startPoll(const uint64_t /*id*/) {} - - void AieDtrace_VE2Impl::continuePoll(const uint64_t /*id*/) {} - - void AieDtrace_VE2Impl::poll(const uint64_t /*id*/) {} - - void AieDtrace_VE2Impl::endPoll() - { - // Hw context destructor calls endAIEDtracePoll -> endPollforDevice; avoid reads/offload here. - // Resource release happens in ~AieDtrace_VE2Impl when the implementation is destroyed. - } - - void AieDtrace_VE2Impl::freeResources() - { - releaseConfiguredHwResourcesNoRead(); - } - - void AieDtrace_VE2Impl::releaseConfiguredHwResourcesNoRead() - { - for (auto& c : perfCounters) { - if (c) { - c->stop(); - c->release(); - } - } - - for (auto& c : streamPorts) { - if (c) { - c->stop(); - c->release(); - } - } - - for (auto& bc : bcResourcesBytesTx) { - if (bc) { - bc->stop(); - bc->release(); - } - } - - for (auto& bc : bcResourcesLatency) { - if (bc) { - bc->stop(); - bc->release(); - } - } - } - - } +} diff --git a/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.h b/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.h index e73f2af7..3fa6926a 100644 --- a/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.h +++ b/profile/plugin/aie_dtrace/ve2/aie_dtrace_ve2.h @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #ifndef AIE_DTRACE_VE2_H #define AIE_DTRACE_VE2_H @@ -11,8 +11,7 @@ #include "aiebu/aiebu_assembler.h" #include "core/edge/common/aie_parser.h" -#include "xdp/profile/plugin/aie_profile/aie_profile_impl.h" -#include "xdp/profile/plugin/aie_profile/util/aie_profile_util.h" +#include "xdp/profile/plugin/aie_dtrace/aie_dtrace_impl.h" #include "xdp/profile/plugin/aie_dtrace/util/aie_dtrace_util.h" #include "xaiefal/xaiefal.hpp" @@ -22,113 +21,24 @@ extern "C" { } namespace xdp { - using tile_type = xdp::tile_type; - - class AieDtrace_VE2Impl : public AieProfileImpl{ - public: - // AieDtrace_VE2Impl(VPDatabase* database, std::shared_ptr metadata) - // : AieProfileImpl(database, metadata){} - AieDtrace_VE2Impl(VPDatabase* database, std::shared_ptr metadata, uint64_t deviceID); - - ~AieDtrace_VE2Impl() override; - void updateDevice(); + class AieDtrace_VE2Impl : public AieDtraceImpl { + public: + AieDtrace_VE2Impl(VPDatabase* database, std::shared_ptr metadata, uint64_t deviceID); + ~AieDtrace_VE2Impl() override = default; - void startPoll(const uint64_t id) override; - void continuePoll(const uint64_t id) override; - void poll(const uint64_t id) override; - void endPoll() override; + void updateDevice() override; - void freeResources(); void generateCTForRun(void* run_impl_ptr, void* hwctx, uint32_t run_uid, const std::string& kernel_name, void* elf_handle) override; - bool checkAieDevice(const uint64_t deviceId, void* handle); - - bool setMetricsSettings(const uint64_t deviceId, void* handle); - void printTileModStats(xaiefal::XAieDev* aieDevice, - const tile_type& tile, - const XAie_ModuleType mod); - - uint64_t getCounterPayload(XAie_DevInst* aieDevInst, - const tile_type& tile, - const module_type type, - uint8_t column, - uint8_t row, - uint16_t startEvent, - const std::string metricSet, - const uint8_t channel, - uint8_t logicalPortIndex = 0); - uint64_t getAdfProfileAPIPayload(const tile_type& tile, const std::string metricSet); private: - std::pair - getEventPhysicalId(XAie_LocType& tileLoc, - XAie_ModuleType& xaieModType, module_type xdpModType, - const std::string& metricSet, - XAie_Events startEvent, XAie_Events endEvent); - - std::pair - setupBroadcastChannel(const tile_type& currTileLoc); - - inline std::shared_ptr - startCounter(std::shared_ptr& pc, - XAie_Events counterEvent, XAie_Events& retCounterEvent) - { - if (!pc) - return nullptr; - - auto ret = pc->start(); - if (ret != XAIE_OK) - return nullptr; - - // Return the known counter event - retCounterEvent = counterEvent; - return pc; - } - - std::pair - getShimBroadcastChannel(const tile_type& srcTile); - - // Stop/release configured FAL objects only (no counter read / sample offload). - void releaseConfiguredHwResourcesNoRead(); - - XAie_DevInst* aieDevInst = nullptr; - xaiefal::XAieDev* aieDevice = nullptr; - - std::map> coreStartEvents; - std::map> coreEndEvents; - std::map> memoryStartEvents; - std::map> memoryEndEvents; - std::map> shimStartEvents; - std::map> shimEndEvents; - std::map> memTileStartEvents; - std::map> memTileEndEvents; - std::map> microcontrollerEvents; - std::map> microcontrollerTileEvents; - std::vector> perfCounters; - std::vector> streamPorts; - - bool graphItrBroadcastConfigDone = false; - // Graph Iterator broadcast channel event - // This event is used to reset/configure the counters in interface tiles - XAie_Events graphIteratorBrodcastChannelEvent = XAIE_EVENT_NONE_CORE; - - // This event is asserted in another interface tile - XAie_Events latencyUserBrodcastChannelEvent = XAIE_EVENT_NONE_CORE; - - std::map> adfAPIResourceInfoMap; - - // This stores the map of location of tile and configured broadcast channel event - std::map> adfAPIBroadcastEventsMap; - - std::vector> bcResourcesBytesTx; - std::vector> bcResourcesLatency; + void computeOpLocations(void* elf_handle, const std::string& kernel_name); std::map> m_op_locations_cache; - - void computeOpLocations(void* elf_handle, const std::string& kernel_name); }; -} + +} #endif diff --git a/profile/plugin/aie_dtrace/ve2/elf_helper.cpp b/profile/plugin/aie_dtrace/ve2/elf_helper.cpp index d7dff094..1e09d110 100644 --- a/profile/plugin/aie_dtrace/ve2/elf_helper.cpp +++ b/profile/plugin/aie_dtrace/ve2/elf_helper.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved // IMPORTANT: elf_int.h (which includes ELFIO) must be included before any // system headers that pull in , to avoid macro/constexpr conflicts diff --git a/profile/plugin/aie_dtrace/ve2/elf_helper.h b/profile/plugin/aie_dtrace/ve2/elf_helper.h index a93ce035..20f4d053 100644 --- a/profile/plugin/aie_dtrace/ve2/elf_helper.h +++ b/profile/plugin/aie_dtrace/ve2/elf_helper.h @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved +// Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved #ifndef XDP_AIE_DTRACE_VE2_ELF_HELPER_H #define XDP_AIE_DTRACE_VE2_ELF_HELPER_H diff --git a/profile/plugin/aie_profile/aie_profile_metadata.cpp b/profile/plugin/aie_profile/aie_profile_metadata.cpp index ded2d669..f578a613 100644 --- a/profile/plugin/aie_profile/aie_profile_metadata.cpp +++ b/profile/plugin/aie_profile/aie_profile_metadata.cpp @@ -173,119 +173,6 @@ namespace xdp { "XRT", "Finished Parsing AIE Profile Metadata using xrt.ini settings."); } - AieProfileMetadata::AieProfileMetadata(uint64_t deviceID, void* handle, - aie_dtrace_ini_metadata_tag) - : deviceID(deviceID) - , handle(handle) - , m_dtraceBandwidthMode(true) - { - xrt_core::message::send(severity_level::info, - "XRT", "Parsing AIE dtrace metadata."); - VPDatabase* db = VPDatabase::Instance(); - - metadataReader = (db->getStaticInfo()).getAIEmetadataReader(deviceID); - if (!metadataReader) { - return; - } - - auto compilerOptions = metadataReader->getAIECompilerOptions(); - - checkDtraceSettings(); - - configMetrics.resize(NUM_MODULES); - - clockFreqMhz = (db->getStaticInfo()).getClockRateMHz(deviceID, false); - - // Polling interval and the "start" control always come from xrt.ini. - pollingInterval = xrt_core::config::get_aie_dtrace_settings_interval_us(); - - setProfileStartControl(compilerOptions.graph_iterator_event, false, nullptr); - - // Metric-set source precedence: - // 1. If Debug.profiling_runtime_config carries a control_instrumentation - // section, it wins. Only interface_tile is wired today; aie_tile and - // mem_tile entries are logged for a follow-up. - // 2. Otherwise fall back to the legacy AIE_dtrace_settings.* xrt.ini - // options. - const bool usingBlob = profiling_runtime_config::has_control_instrumentation(); - const auto& ci = profiling_runtime_config::control_instrumentation(); - - if (usingBlob) { - xrt_core::message::send(severity_level::info, "XRT", - "AIE dtrace: using control_instrumentation from " - "Debug.profiling_runtime_config; AIE_dtrace_settings.* will be ignored " - "for metric sets."); - - if (ci.aie_tile.has_value() && !ci.aie_tile->empty()) { - xrt_core::message::send(severity_level::info, "XRT", - "AIE dtrace: core tile metric '" + *ci.aie_tile - + "' from profiling_runtime_config will be supported in a follow-up."); - } - if (ci.mem_tile.has_value() && !ci.mem_tile->empty()) { - xrt_core::message::send(severity_level::info, "XRT", - "AIE dtrace: mem tile metric '" + *ci.mem_tile - + "' from profiling_runtime_config will be supported in a follow-up."); - } - } - - for (int module = 0; module < NUM_MODULES; ++module) { - if (moduleTypes[module] != module_type::shim) - continue; - - std::vector metricsSettings; - std::vector graphMetricsSettings; - - if (usingBlob) { - if (ci.interface_tile.has_value() && !ci.interface_tile->empty()) { - // Blob carries a bare metric name (e.g. "ddr_bandwidth"). Synthesize - // an "all:" tile-based selection so the existing parser - // applies it to every interface tile. - metricsSettings = getSettingsVector("all:" + *ci.interface_tile); - } - // If interface_tile is unset/empty in the blob, the blob wins and - // leaves shim tiles unconfigured (no xrt.ini fallback for this knob). - } - else { - metricsSettings = - getSettingsVector(xrt_core::config::get_aie_dtrace_settings_tile_based_interface_tile_metrics()); - graphMetricsSettings = - getSettingsVector(xrt_core::config::get_aie_dtrace_settings_graph_based_interface_tile_metrics()); - } - - getConfigMetricsForInterfaceTiles(module, metricsSettings, graphMetricsSettings); - } - - xrt_core::message::send(severity_level::info, - "XRT", "Finished parsing AIE dtrace metadata."); - } - - void AieProfileMetadata::checkDtraceSettings() - { - using boost::property_tree::ptree; - // configure_aie_hardware: accepted for xrt.ini compatibility; dtrace VE2 always programs like AIE profile. - const std::set validSettings { - "interval_us", - "tile_based_interface_tile_metrics", - "graph_based_interface_tile_metrics", - "configure_aie_hardware", - }; - - auto tree = xrt_core::config::detail::get_ptree_value("AIE_dtrace_settings"); - - for (ptree::iterator pos = tree.begin(); pos != tree.end(); pos++) { - if (validSettings.find(pos->first) == validSettings.end()) { - std::stringstream msg; - msg << "The setting AIE_dtrace_settings." << pos->first << " is not recognized. " - << "Please check the spelling and compare to supported list:"; - - for (auto it = validSettings.cbegin(); it != validSettings.cend(); it++) - msg << ((it == validSettings.cbegin()) ? " " : ", ") << *it; - - xrt_core::message::send(severity_level::warning, "XRT", msg.str()); - } - } - } - void AieProfileMetadata::processPluginJsonSetting(const PluginJsonSetting& config, MetricsCollectionManager& manager) { @@ -1328,15 +1215,6 @@ namespace xdp { bool showWarning = true; std::vector offTiles; auto metricVec = metricStrings.at(module_type::shim); - if (m_dtraceBandwidthMode) { - static const char* dtraceMetrics[] = - {"ddr_bandwidth", "read_bandwidth", "write_bandwidth", - "peak_read_bandwidth", "peak_write_bandwidth"}; - for (const char* m : dtraceMetrics) { - if (std::find(metricVec.begin(), metricVec.end(), m) == metricVec.end()) - metricVec.push_back(m); - } - } for (auto& tileMetric : configMetrics[moduleIdx]) { // Save list of "off" tiles diff --git a/profile/plugin/aie_profile/aie_profile_metadata.h b/profile/plugin/aie_profile/aie_profile_metadata.h index f4521e03..54e01411 100644 --- a/profile/plugin/aie_profile/aie_profile_metadata.h +++ b/profile/plugin/aie_profile/aie_profile_metadata.h @@ -38,9 +38,6 @@ namespace xdp { // Forwadr declarations of XDP constructs struct LatencyConfig; -// Tag type: construct metadata from [AIE_dtrace_settings] only (bandwidth metrics for dtrace). -struct aie_dtrace_ini_metadata_tag {}; - constexpr unsigned int NUM_CORE_COUNTERS = 4; constexpr unsigned int NUM_MEMORY_COUNTERS = 2; #if defined(XDP_VE2_BUILD) || defined(XDP_VE2_ZOCL_BUILD) @@ -128,15 +125,8 @@ class AieProfileMetadata { const aie::BaseFiletypeImpl* metadataReader = nullptr; - bool m_dtraceBandwidthMode = false; - - void checkDtraceSettings(); - public: AieProfileMetadata(uint64_t deviceID, void* handle); - AieProfileMetadata(uint64_t deviceID, void* handle, aie_dtrace_ini_metadata_tag); - - bool isDtraceBandwidthMode() const { return m_dtraceBandwidthMode; } uint64_t getDeviceID() {return deviceID;} void* getHandle() {return handle;}