From d3427d5d0f9d8df526d3887bcfa09abf84d51507 Mon Sep 17 00:00:00 2001 From: Vinod Pangul <146476973+vipangul@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:56:22 -0700 Subject: [PATCH] Correct Freq store & fetch (#8434) --- .../profile/database/static_info/aie_util.cpp | 12 +++++++++++ .../profile/database/static_info/aie_util.h | 12 +++++++---- .../filetypes/aie_control_config_filetype.cpp | 6 ++++++ .../filetypes/aie_control_config_filetype.h | 2 ++ .../filetypes/base_filetype_impl.h | 1 + .../profile/database/static_info_database.cpp | 21 ++++++++++++++----- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/runtime_src/xdp/profile/database/static_info/aie_util.cpp b/src/runtime_src/xdp/profile/database/static_info/aie_util.cpp index 49bb68e3084..700a6a5116a 100755 --- a/src/runtime_src/xdp/profile/database/static_info/aie_util.cpp +++ b/src/runtime_src/xdp/profile/database/static_info/aie_util.cpp @@ -133,6 +133,18 @@ namespace xdp::aie { return *hwGen; } + // On Edge devices, AIE clock frequency shouldn't change once execution has started. + // On Client devices, this static information from metadata may not be correct. + double getAIEClockFreqMHz(const boost::property_tree::ptree& aie_meta, + const std::string& root) + { + static std::optional clockFreqMHz; + if (!clockFreqMHz.has_value()) { + clockFreqMHz = aie_meta.get_child(root).get_value(); + } + return *clockFreqMHz; + } + /**************************************************************************** * Get metadata required to configure driver ***************************************************************************/ diff --git a/src/runtime_src/xdp/profile/database/static_info/aie_util.h b/src/runtime_src/xdp/profile/database/static_info/aie_util.h index 8b2fe4bd8b2..cd206b95791 100755 --- a/src/runtime_src/xdp/profile/database/static_info/aie_util.h +++ b/src/runtime_src/xdp/profile/database/static_info/aie_util.h @@ -53,22 +53,26 @@ namespace xdp::aie { XDP_CORE_EXPORT int getHardwareGeneration(const boost::property_tree::ptree& aie_meta, - const std::string& root); + const std::string& root); + + XDP_CORE_EXPORT + double getAIEClockFreqMHz(const boost::property_tree::ptree& aie_meta, + const std::string& root); XDP_CORE_EXPORT xdp::aie::driver_config getDriverConfig(const boost::property_tree::ptree& aie_meta, - const std::string& root); + const std::string& root); XDP_CORE_EXPORT uint8_t getAIETileRowOffset(const boost::property_tree::ptree& aie_meta, - const std::string& location); + const std::string& location); XDP_CORE_EXPORT std::vector getValidGraphs(const boost::property_tree::ptree& aie_meta, - const std::string& root); + const std::string& root); XDP_CORE_EXPORT bool isInfoVerbosity(); diff --git a/src/runtime_src/xdp/profile/database/static_info/filetypes/aie_control_config_filetype.cpp b/src/runtime_src/xdp/profile/database/static_info/filetypes/aie_control_config_filetype.cpp index 5239dacaccc..152a46f8aab 100644 --- a/src/runtime_src/xdp/profile/database/static_info/filetypes/aie_control_config_filetype.cpp +++ b/src/runtime_src/xdp/profile/database/static_info/filetypes/aie_control_config_filetype.cpp @@ -49,6 +49,12 @@ AIEControlConfigFiletype::getHardwareGeneration() const return xdp::aie::getHardwareGeneration(aie_meta, "aie_metadata.driver_config.hw_gen"); } +double +AIEControlConfigFiletype::getAIEClockFreqMHz() const +{ + return xdp::aie::getAIEClockFreqMHz(aie_meta, "aie_metadata.DeviceData.AIEFrequency"); +} + aiecompiler_options AIEControlConfigFiletype::getAIECompilerOptions() const { diff --git a/src/runtime_src/xdp/profile/database/static_info/filetypes/aie_control_config_filetype.h b/src/runtime_src/xdp/profile/database/static_info/filetypes/aie_control_config_filetype.h index 15d385c0544..920a3c9058f 100644 --- a/src/runtime_src/xdp/profile/database/static_info/filetypes/aie_control_config_filetype.h +++ b/src/runtime_src/xdp/profile/database/static_info/filetypes/aie_control_config_filetype.h @@ -35,6 +35,8 @@ class AIEControlConfigFiletype : public xdp::aie::BaseFiletypeImpl { int getHardwareGeneration() const override; + double getAIEClockFreqMHz() const override; + aiecompiler_options getAIECompilerOptions() const override; diff --git a/src/runtime_src/xdp/profile/database/static_info/filetypes/base_filetype_impl.h b/src/runtime_src/xdp/profile/database/static_info/filetypes/base_filetype_impl.h index bf7fe118ec9..1945195b28b 100644 --- a/src/runtime_src/xdp/profile/database/static_info/filetypes/base_filetype_impl.h +++ b/src/runtime_src/xdp/profile/database/static_info/filetypes/base_filetype_impl.h @@ -36,6 +36,7 @@ class BaseFiletypeImpl { getDriverConfig() const = 0; virtual int getHardwareGeneration() const = 0; + virtual double getAIEClockFreqMHz() const = 0; virtual aiecompiler_options getAIECompilerOptions() const = 0; diff --git a/src/runtime_src/xdp/profile/database/static_info_database.cpp b/src/runtime_src/xdp/profile/database/static_info_database.cpp index 2eec1b4aabd..b8f9d34c0c5 100644 --- a/src/runtime_src/xdp/profile/database/static_info_database.cpp +++ b/src/runtime_src/xdp/profile/database/static_info_database.cpp @@ -1470,7 +1470,16 @@ namespace xdp { if (nullptr == device) return; - auto xclbin_slot_info = xrt_core::device_query(device.get()); + std::vector xclbin_slot_info; + try { + xclbin_slot_info = xrt_core::device_query(device.get()); + } + catch (const std::exception& e) { + std::stringstream msg; + msg << "Exception occured while retrieving loaded xclbin info: " << e.what(); + xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", msg.str()); + } + if (xclbin_slot_info.empty()) return; xrt::uuid new_xclbin_uuid = xrt::uuid(xclbin_slot_info.back().uuid); @@ -2330,7 +2339,6 @@ namespace xdp { if (readAIEdata) { readAIEMetadata(xrtXclbin, clientBuild); setAIEGeneration(deviceId, xrtXclbin); - setAIEClockRateMHz(deviceId, xrtXclbin); } /* Configure AMs if context monitoring is supported @@ -2346,6 +2354,10 @@ namespace xdp { } devInfo->createConfig(currentXclbin); + + // Following functions require configInfo to be created first. + if (readAIEdata) + setAIEClockRateMHz(deviceId, xrtXclbin); initializeProfileMonitors(devInfo, xrtXclbin); devInfo->isReady = true; @@ -2436,7 +2448,7 @@ namespace xdp { return; try { - auto hwGen = aieMetadata.get_child("aie_metadata.driver_config.hw_gen").get_value(); + auto hwGen = metadataReader->getHardwareGeneration(); deviceInfo[deviceId]->setAIEGeneration(hwGen); } catch(...) { return; @@ -2460,8 +2472,7 @@ namespace xdp { return; try { - auto dev_node = aieMetadata.get_child("aie_metadata.DeviceData"); - xclbin->aie.clockRateAIEMHz = dev_node.get("AIEFrequency"); + xclbin->aie.clockRateAIEMHz = metadataReader->getAIEClockFreqMHz(); xrt_core::message::send(xrt_core::message::severity_level::info, "XRT", "read clockRateAIEMHz: " + std::to_string(xclbin->aie.clockRateAIEMHz)); } catch(...) {