-
Notifications
You must be signed in to change notification settings - Fork 549
add new function in xrt-smi to query the load on AIE array. #9983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -350,7 +350,8 @@ enum class key_type | |
|
|
||
| aie_read, | ||
| aie_write, | ||
| aie_coredump | ||
| aie_coredump, | ||
| aie_load | ||
| }; | ||
|
|
||
| struct pcie_vendor : request | ||
|
|
@@ -4316,6 +4317,30 @@ struct aie_coredump : request | |
| std::any | ||
| get(const device*, const std::any&) const override = 0; | ||
| }; | ||
|
|
||
| // AIE array hardware utilization, computed from two consecutive firmware | ||
| // activity-counter snapshots separated by sample_duration_ms milliseconds. | ||
| struct aie_load : request | ||
| { | ||
| struct result_type { | ||
| uint32_t load_percent; // 0-100, or UINT32_MAX if unavailable | ||
| uint64_t timestamp_ms; // FW uptime when second snapshot was taken | ||
| uint64_t activity_counters[8]; // raw counter values from second snapshot | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays] uint64_t activity_counters[8]; // raw counter values from second snapshot
^ |
||
| uint64_t operations_per_second; // total counter change across 8 counters per second | ||
| }; | ||
|
|
||
| struct args { | ||
| uint32_t sample_duration_ms = 0; // 0 = driver default (XRT_AIE_LOAD_SAMPLE_INTERVAL_MS) | ||
| }; | ||
|
|
||
| static const key_type key = key_type::aie_load; | ||
|
|
||
| virtual std::any | ||
| get(const device*) const override = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'virtual' is redundant since the function is already declared 'override' [cppcoreguidelines-explicit-virtual-functions] src/runtime_src/core/common/query_requests.h:4337: - virtual std::any
+ std::any |
||
|
|
||
| virtual std::any | ||
| get(const device*, const std::any&) const override = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'virtual' is redundant since the function is already declared 'override' [cppcoreguidelines-explicit-virtual-functions] src/runtime_src/core/common/query_requests.h:4340: - virtual std::any
+ std::any |
||
| }; | ||
| } // query | ||
|
|
||
| } // xrt_core | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||
| // Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. | ||||||
|
|
||||||
| #include "ReportAieLoad.h" | ||||||
|
|
||||||
| #include "core/common/query_requests.h" | ||||||
|
|
||||||
| #include <boost/format.hpp> | ||||||
| #include <limits> | ||||||
|
|
||||||
| void | ||||||
| ReportAieLoad::getPropertyTreeInternal(const xrt_core::device* dev, | ||||||
| boost::property_tree::ptree& pt) const | ||||||
| { | ||||||
| getPropertyTree20202(dev, pt); | ||||||
| } | ||||||
|
|
||||||
| void | ||||||
| ReportAieLoad::getPropertyTree20202(const xrt_core::device* dev, | ||||||
| boost::property_tree::ptree& pt) const | ||||||
| { | ||||||
| boost::property_tree::ptree node; | ||||||
|
|
||||||
| try { | ||||||
| const xrt_core::query::aie_load::args args{m_duration_ms}; | ||||||
| const auto data = xrt_core::device_query<xrt_core::query::aie_load>(dev, args); | ||||||
|
|
||||||
| const bool unavailable = (data.load_percent == std::numeric_limits<uint32_t>::max()); | ||||||
| node.put("load_percent", unavailable ? "N/A" : std::to_string(data.load_percent)); | ||||||
| node.put("timestamp_ms", data.timestamp_ms); | ||||||
| node.put("operations_per_second", data.operations_per_second); | ||||||
|
|
||||||
| boost::property_tree::ptree pt_counters; | ||||||
| for (size_t i = 0; i < 8; i++) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] for (size_t i = 0; i < 8; i++) {
^
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: use range-based for loop instead [modernize-loop-convert]
Suggested change
src/runtime_src/core/tools/common/reports/ReportAieLoad.cpp:35: - pt_counter.put("", data.activity_counters[i]);
+ pt_counter.put("", activity_counter); |
||||||
| boost::property_tree::ptree pt_counter; | ||||||
| pt_counter.put("", data.activity_counters[i]); | ||||||
| pt_counters.push_back({"", pt_counter}); | ||||||
| } | ||||||
| node.add_child("activity_counters", pt_counters); | ||||||
| } | ||||||
| catch (const xrt_core::query::exception& e) { | ||||||
| node.put("error", e.what()); | ||||||
| } | ||||||
|
|
||||||
| pt.add_child("aie_load", node); | ||||||
| } | ||||||
|
|
||||||
| void | ||||||
| ReportAieLoad::writeReport(const xrt_core::device* /*dev*/, | ||||||
| const boost::property_tree::ptree& pt, | ||||||
| const std::vector<std::string>& /*elementsFilter*/, | ||||||
| std::ostream& output) const | ||||||
| { | ||||||
| const auto& node = pt.get_child("aie_load"); | ||||||
|
|
||||||
| // If the query failed, report the error and return. | ||||||
| auto error = node.get_optional<std::string>("error"); | ||||||
| if (error) { | ||||||
| output << "AIE Load: " << *error << "\n\n"; | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| output << "AIE Load\n"; | ||||||
|
|
||||||
| const auto load = node.get<std::string>("load_percent"); | ||||||
| if (load == "N/A") | ||||||
| output << boost::format(" %-25s: N/A (AIE off, gated, or counters unavailable)\n") % "Utilization"; | ||||||
| else | ||||||
| output << boost::format(" %-25s: %s%%\n") % "Utilization" % load; | ||||||
|
|
||||||
| output << boost::format(" %-25s: %s ops/s\n") % "Operations/Second" | ||||||
| % node.get<std::string>("operations_per_second"); | ||||||
| output << boost::format(" %-25s: %s ms\n") % "FW Timestamp" | ||||||
| % node.get<std::string>("timestamp_ms"); | ||||||
|
|
||||||
| output << " Activity Counters:\n"; | ||||||
| int idx = 0; | ||||||
| for (const auto& [name, counter] : node.get_child("activity_counters")) | ||||||
| output << boost::format(" [%d]: %s\n") % idx++ % counter.get_value<std::string>(); | ||||||
|
|
||||||
| output << "\n"; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,28 @@ | ||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||
| // Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. | ||||||||
|
|
||||||||
| #ifndef __ReportAieLoad_h_ | ||||||||
| #define __ReportAieLoad_h_ | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: declaration uses identifier '_ReportAieLoad_h', which is a reserved identifier [bugprone-reserved-identifier]
Suggested change
|
||||||||
|
|
||||||||
| #include "tools/common/Report.h" | ||||||||
|
|
||||||||
| #include <cstdint> | ||||||||
|
|
||||||||
| class ReportAieLoad : public Report { | ||||||||
| public: | ||||||||
| ReportAieLoad() : Report("aie-load", "AIE array load utilization", true /*deviceRequired*/) {} | ||||||||
|
|
||||||||
| // Called by SubCmdExamine before produce_reports to forward --duration. | ||||||||
| void setDuration(uint32_t duration_ms) { m_duration_ms = duration_ms; } | ||||||||
|
|
||||||||
| public: | ||||||||
| virtual void getPropertyTreeInternal(const xrt_core::device* dev, boost::property_tree::ptree& pt) const; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [cppcoreguidelines-explicit-virtual-functions]
Suggested change
|
||||||||
| virtual void getPropertyTree20202(const xrt_core::device* dev, boost::property_tree::ptree& pt) const; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [cppcoreguidelines-explicit-virtual-functions]
Suggested change
|
||||||||
| virtual void writeReport(const xrt_core::device* dev, const boost::property_tree::ptree& pt, | ||||||||
| const std::vector<std::string>& elementsFilter, std::ostream& output) const; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [cppcoreguidelines-explicit-virtual-functions]
Suggested change
|
||||||||
|
|
||||||||
| private: | ||||||||
| uint32_t m_duration_ms = 0; // 0 = driver default (XRT_AIE_LOAD_SAMPLE_INTERVAL_MS) | ||||||||
| }; | ||||||||
|
|
||||||||
| #endif | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]