[SWDEV-535159] Add support for GPU partition metrics (#490)

[SWDEV-535159] Add support for GPU partition metrics

Changes include:
  - Internal logic to smart-switch between gpu_metrics/xcp_metrics files
  - [WIP] Initial plumbing for new partition metric API

Change-Id: I4340fb1b48bac0117d80d5d486b9e871430d5cd8
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Add amdsmi_get_gpu_partition_metrics_info() + minor cleanup

Change-Id: I5d60604f18baddbd03852dc90e88aa0b8107d50e
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Fix partition metric logic + update logging/tests

Change-Id: I9e89b19ead17694c54e224f8e13ff8ee3eb2e22a
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Adjust amd-smi metric/monitor/default to show (some) partition information

Change-Id: I2e8d2745876a19bdaec3c039daa97345c9f701b5
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Add C++ tests

Change-Id: Ib9eb0b57a6d7a280992e05a4c6eba632826952ef
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Remove modification of energy counter, not needed

Change-Id: I5c48eaaae248ee6dc79abba609d837ec35d78022
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

[CLI] amd-smi metric: cleaned up N/A'd multi-valued to show just N/A

Changes:
1. amd-smi metric: cleaned up N/A'd multi-valued to show just N/A
ex.
JPEG_ACTIVITY: [N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A]

Now just shows: N/A

2. [Python Unit Test] Changed testname TestAmdSmiPythonBDF(unittest.TestCase) ->
 AmdSmiPythonUnitTest

Test name was confusing.

Change-Id: Ieb3b036f30002fd22362508eb9fc5d443df395ae
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Log cleanup

Change-Id: I1b1a95f1844d35bec7a7bd8cb996f87e4914c069
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Add amd-smi partition-metrics CLI + general cleanup

Change-Id: Ia91488e6cb3a4d62b4087afbddfe0b3bb9378fdc
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

[1.3 metrics] Remove forwards compatibility for partition metrics

Change-Id: Iab928983e6f6f1587bc9307f6f3fa2b2696ca6f7
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Fixed violation output not showing % + general cleanup

Change-Id: Icac1b0a55b18c7628b07109ae0c377d17e0825f1
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

Clean up amdsmi_get_gpu_partition_metrics_info & amd-smi partition-metric outputs

Change-Id: I6427028b980874641e9ffb3b5d88ad493dbf9cf4
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Fix metrics not found + extra logging/formatting

Change-Id: I841a27bb2c305e97ec7579a13ac915e5be497c3a
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Update license to current default

Change-Id: I0de9b8a2d5dbbeab4491097f0354ba17b0d30866
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Cleanup for review

Change-Id: I96ed25c3f2b8968eea1af24c5e5860c2b4e74e6e
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Moderize updated/new interal APIs.

Change-Id: I3c48a250eeb703709b14cb5ffa68268d8321626c
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Remove extra logging in dynamic metrics

Change-Id: Idb97547bcbe143d6fa1cb5cb278ffe4da615ce14
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Remove amd-smi partition-metric command

Change-Id: Ib83c17e5cd7e0da3798198943bddd46c296b411c
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Move new CLI updates to another PR + minor fixes

Change-Id: I3b1163eec12f9b5f7d95ee33de08e168cec1b1fe
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Allow dynamic metrics to work for gpu/xcp metrics 1.9+/1.1+

Updated some logging as well.

Change-Id: I2ed9f5a5ef8afb1520508820ca6153525f0644b4
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Allow dyn gpu/xcp metric v1.9+/v1.1+

Added tests for quick check

Change-Id: I576d6f6582a55afb08e5ac57791ce95e2fa184a2
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Update tests for larger subset of version checks

Change-Id: I3cdf4f8bb4fc6161f4c76566939f90545d0f362a
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

* Fix XCP metrics in gpu/partition metric pre-v1.9/v1.1 (dynamic)

Change-Id: I4dabc1ed6bef6b86c8e7f92bf9cb5992f3966fe2
Signed-off-by: Charis Poag <Charis.Poag@amd.com>

---------

Signed-off-by: Charis Poag <Charis.Poag@amd.com>
This commit is contained in:
Poag, Charis
2025-10-20 14:43:40 -05:00
committed by GitHub
parent b2b0815b37
commit 01b4fe6614
22 changed files with 2235 additions and 815 deletions
+5
View File
@@ -52,6 +52,11 @@ include_directories(${TEST} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${ROCM_INC_DIR}/..)
add_executable(${TEST} ${tstSources} ${functionalSources})
target_link_libraries(${TEST} ${AMD_SMI} GTest::gtest_main c stdc++ pthread)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9")
target_link_libraries(${TEST} stdc++fs)
endif()
# Install tests
install(
TARGETS ${TEST}
@@ -0,0 +1,203 @@
/*
* Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <amd_smi_test/test_base.h>
#include <gtest/gtest.h>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <vector>
#include "rocm_smi/rocm_smi_gpu_metrics.h"
namespace amd::smi {
// Forward declarations of internal helpers we exercise in this unit-test.
AMDGpuMetricVersionFlags_t translate_header_to_flag_version(
const AMDGpuMetricsHeader_v1_t& metrics_header, bool is_partition_metrics,
const std::string& file_path);
GpuMetricsBasePtr amdgpu_metrics_factory(AMDGpuMetricVersionFlags_t gpu_metric_version,
bool is_partition_metrics, const std::string& file_path);
} // namespace amd::smi
namespace {
// Version helper checker
auto GetExpectedMetricVersionFlag(uint16_t major, uint16_t minor, bool is_partition_metrics)
-> amd::smi::AMDGpuMetricVersionFlags_t {
using Flag = amd::smi::AMDGpuMetricVersionFlags_t;
if (is_partition_metrics) {
if (major == 1) {
if (minor == 0) {
return Flag::kGpuXcpMetricV10;
} else if (minor >= 1) {
return Flag::kGpuXcpMetricDynV11Plus;
} else {
return Flag::kGpuMetricNone;
}
}
} else { // GPU metrics
if (major == 1) {
switch (minor) {
case 0: return Flag::kGpuMetricNone;
case 1: return Flag::kGpuMetricV11;
case 2: return Flag::kGpuMetricV12;
case 3: return Flag::kGpuMetricV13;
case 4: return Flag::kGpuMetricV14;
case 5: return Flag::kGpuMetricV15;
case 6: return Flag::kGpuMetricV16;
case 7: return Flag::kGpuMetricV17;
case 8: return Flag::kGpuMetricV18;
default: return Flag::kGpuMetricDynV19Plus;
}
}
}
return Flag::kGpuMetricNone;
}
// pass a header we want to test against
auto BuildFakeMetricsBlob(amd::smi::AMDGpuMetricsHeader_v1_t new_header) -> std::vector<uint8_t> {
if (new_header.m_structure_size < sizeof(new_header)) {
throw std::runtime_error("Header size too small");
}
amd::smi::AMDGpuMetricsHeader_v1_t header{};
header.m_structure_size = static_cast<uint16_t>(sizeof(header));
header.m_format_revision = new_header.m_format_revision;
header.m_content_revision = new_header.m_content_revision;
const uint8_t* begin = reinterpret_cast<const uint8_t*>(&header);
return std::vector<uint8_t>(begin, begin + sizeof(header));
}
auto WriteBlobToTempFile(const std::vector<uint8_t>& blob,
const std::string& filename = "amdsmi_fake_metrics.bin")
-> std::filesystem::path {
auto temp_dir = std::filesystem::temp_directory_path();
auto file_path = temp_dir / filename;
std::ofstream stream(file_path, std::ios::binary | std::ios::trunc);
stream.write(reinterpret_cast<const char*>(blob.data()),
static_cast<std::streamsize>(blob.size()));
stream.close();
return file_path;
}
} // namespace
TEST(AmdSmiDynamicMetricTest, GPUMetricDynamicVersionSupported) {
const bool is_partition_metrics = false;
for (auto ver : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}) {
std::string test_detail = "[GPUMetric";
if (ver >= 9) {
test_detail += "Dynamic] ";
} else {
test_detail += "] ";
}
std::cout << test_detail << "Checking version 1." << ver << std::endl;
SCOPED_TRACE(testing::Message() << "Subtest for minor version: 1." << ver);
const auto blob = BuildFakeMetricsBlob(amd::smi::AMDGpuMetricsHeader_v1_t{
.m_structure_size = sizeof(amd::smi::AMDGpuMetricsHeader_v1_t),
.m_format_revision = 1,
.m_content_revision = static_cast<uint16_t>(ver), // Known minor versions
});
const auto fake_path =
WriteBlobToTempFile(blob, "amdsmi_fake_gpu_metrics_v1" + std::to_string(ver) + ".bin");
ASSERT_FALSE(blob.empty());
ASSERT_TRUE(std::filesystem::exists(fake_path));
const auto* header = reinterpret_cast<const amd::smi::AMDGpuMetricsHeader_v1_t*>(blob.data());
const auto flag = amd::smi::translate_header_to_flag_version(*header, is_partition_metrics,
fake_path.string());
EXPECT_EQ(flag, GetExpectedMetricVersionFlag(1, ver, is_partition_metrics))
<< "Version 1." << ver << " should be treated as supported";
auto gpu_metrics_ptr =
amd::smi::amdgpu_metrics_factory(flag, is_partition_metrics, fake_path.string());
if (ver != 0) {
EXPECT_NE(gpu_metrics_ptr, nullptr)
<< "Factory must create metrics object for supported version";
} else {
EXPECT_EQ(gpu_metrics_ptr, nullptr)
<< "Factory must not create metrics object for unsupported versions";
}
if (gpu_metrics_ptr) {
std::cout << test_detail << "Created valid object for version 1." << ver << std::endl;
} else {
std::cout << test_detail << "Unsupported Metric Version"
<< " | Failed to create valid object for version 1." << ver << std::endl;
}
std::filesystem::remove(fake_path);
}
}
TEST(AmdSmiDynamicMetricTest, XCPMetricDynamicVersionSupported) {
const bool is_partition_metrics = true;
for (auto ver : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}) {
std::string test_detail = "[XCPMetric";
if (ver >= 1) {
test_detail += "Dynamic] ";
} else {
test_detail += "] ";
}
std::cout << test_detail << "Checking version 1." << ver << std::endl;
SCOPED_TRACE(testing::Message() << "Subtest for minor version: 1." << ver);
const auto blob = BuildFakeMetricsBlob(amd::smi::AMDGpuMetricsHeader_v1_t{
.m_structure_size = sizeof(amd::smi::AMDGpuMetricsHeader_v1_t),
.m_format_revision = 1,
.m_content_revision = static_cast<uint16_t>(ver), // Known minor versions
});
const auto fake_path =
WriteBlobToTempFile(blob, "amdsmi_fake_xcp_metrics_v1" + std::to_string(ver) + ".bin");
ASSERT_FALSE(blob.empty());
ASSERT_TRUE(std::filesystem::exists(fake_path));
const auto* header = reinterpret_cast<const amd::smi::AMDGpuMetricsHeader_v1_t*>(blob.data());
const auto flag = amd::smi::translate_header_to_flag_version(*header, is_partition_metrics,
fake_path.string());
EXPECT_EQ(flag, GetExpectedMetricVersionFlag(1, ver, is_partition_metrics))
<< "Version 1." << ver << " should be treated as supported";
auto xcp_metrics_ptr =
amd::smi::amdgpu_metrics_factory(flag, is_partition_metrics, fake_path.string());
EXPECT_NE(xcp_metrics_ptr, nullptr)
<< "Factory must create metrics object for supported version";
if (xcp_metrics_ptr) {
std::cout << test_detail << "Created valid object for version 1." << ver << std::endl;
} else {
std::cout << test_detail << "Failed to create valid object for version 1." << ver
<< std::endl;
}
std::filesystem::remove(fake_path);
}
}
@@ -0,0 +1,426 @@
/*
* Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <cstdint>
#include <iostream>
#include <iterator>
#include <string>
#include <map>
#include <gtest/gtest.h>
#include "amd_smi/amdsmi.h"
#include "gpu_partition_metrics_read.h"
#include "../test_common.h"
#include "rocm_smi/rocm_smi_utils.h"
#include "amd_smi/impl/amd_smi_utils.h"
TestGpuPartitionMetricsRead::TestGpuPartitionMetricsRead() : TestBase() {
set_title("AMDSMI GPU Partition (XCP) Metrics Read Test");
set_description("The GPU Partition (XCP) Metrics tests verifies that "
"the gpu metrics info can be read properly.");
}
TestGpuPartitionMetricsRead::~TestGpuPartitionMetricsRead(void) {
}
void TestGpuPartitionMetricsRead::SetUp(void) {
TestBase::SetUp();
return;
}
void TestGpuPartitionMetricsRead::DisplayTestInfo(void) {
TestBase::DisplayTestInfo();
}
void TestGpuPartitionMetricsRead::DisplayResults(void) const {
TestBase::DisplayResults();
return;
}
void TestGpuPartitionMetricsRead::Close() {
// This will close handles opened within amdsmitst utility calls and call
// amdsmi_shut_down(), so it should be done after other hsa cleanup
TestBase::Close();
}
void TestGpuPartitionMetricsRead::Run(void) {
amdsmi_status_t err;
TestBase::Run();
if (setup_failed_) {
std::cout << "** SetUp Failed for this test. Skipping.**" << std::endl;
return;
}
for (uint32_t i = 0; i < num_monitor_devs(); ++i) {
PrintDeviceHeader(processor_handles_[i]);
std::cout << "Device #" << std::to_string(i) << "\n";
IF_VERB(STANDARD) {
std::cout << "\n\n";
std::cout << "\t**GPU PARTITION METRICS: Using static struct (Backwards Compatibility):\n";
}
amdsmi_gpu_metrics_t smu = {};
err = amdsmi_get_gpu_partition_metrics_info(processor_handles_[i], &smu);
const char *status_string;
amdsmi_status_code_to_string(err, &status_string);
std::cout << "\t\t** amdsmi_get_gpu_partition_metrics_info(): " << status_string
<< "\n";
if (err != AMDSMI_STATUS_SUCCESS) {
if (err == AMDSMI_STATUS_NOT_SUPPORTED) {
IF_VERB(STANDARD) {
std::cout << "\t**" <<
"Not supported on this machine" << std::endl;
continue;
}
}
CHK_ERR_ASRT(err); // Anything else should be a failure
// (ie, we are not handling the metrics right/etc..)
} else {
IF_VERB(STANDARD) {
std::cout << "METRIC TABLE HEADER:\n";
std::cout << "structure_size=" << std::dec
<< static_cast<uint16_t>(smu.common_header.structure_size) << "\n";
std::cout << "format_revision=" << std::dec
<< static_cast<uint16_t>(smu.common_header.format_revision) << "\n";
std::cout << "content_revision=" << std::dec
<< static_cast<uint16_t>(smu.common_header.content_revision) << "\n";
std::cout << "\n";
std::cout << "TIME STAMPS (ns):\n";
std::cout << std::dec << "system_clock_counter=" << smu.system_clock_counter << "\n";
std::cout << "firmware_timestamp (10ns resolution)=" << std::dec << smu.firmware_timestamp
<< "\n";
std::cout << "\n";
std::cout << "TEMPERATURES (C):\n";
std::cout << std::dec << "temperature_edge= " << smu.temperature_edge << "\n";
std::cout << std::dec << "temperature_hotspot= " << smu.temperature_hotspot << "\n";
std::cout << std::dec << "temperature_mem= " << smu.temperature_mem << "\n";
std::cout << std::dec << "temperature_vrgfx= " << smu.temperature_vrgfx << "\n";
std::cout << std::dec << "temperature_vrsoc= " << smu.temperature_vrsoc << "\n";
std::cout << std::dec << "temperature_vrmem= " << smu.temperature_vrmem << "\n";
std::cout << "temperature_hbm = [";
std::copy(std::begin(smu.temperature_hbm),
std::end(smu.temperature_hbm),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << "\n";
std::cout << "UTILIZATION (%):\n";
std::cout << std::dec << "average_gfx_activity=" << smu.average_gfx_activity << "\n";
std::cout << std::dec << "average_umc_activity=" << smu.average_umc_activity << "\n";
std::cout << std::dec << "average_mm_activity=" << smu.average_mm_activity << "\n";
std::cout << std::dec << "vcn_activity= [";
std::copy(std::begin(smu.vcn_activity),
std::end(smu.vcn_activity),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << "\n";
std::cout << std::dec << "jpeg_activity= [";
std::copy(std::begin(smu.jpeg_activity),
std::end(smu.jpeg_activity),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << "\n";
std::cout << "POWER (W)/ENERGY (15.259uJ per 1ns):\n";
std::cout << std::dec << "average_socket_power=" << smu.average_socket_power << "\n";
std::cout << std::dec << "current_socket_power=" << smu.current_socket_power << "\n";
std::cout << std::dec << "energy_accumulator=" << smu.energy_accumulator << "\n";
std::cout << "\n";
std::cout << "AVG CLOCKS (MHz):\n";
std::cout << std::dec << "average_gfxclk_frequency=" << smu.average_gfxclk_frequency
<< "\n";
std::cout << std::dec << "average_gfxclk_frequency=" << smu.average_gfxclk_frequency
<< "\n";
std::cout << std::dec << "average_uclk_frequency=" << smu.average_uclk_frequency << "\n";
std::cout << std::dec << "average_vclk0_frequency=" << smu.average_vclk0_frequency
<< "\n";
std::cout << std::dec << "average_dclk0_frequency=" << smu.average_dclk0_frequency
<< "\n";
std::cout << std::dec << "average_vclk1_frequency=" << smu.average_vclk1_frequency
<< "\n";
std::cout << std::dec << "average_dclk1_frequency=" << smu.average_dclk1_frequency
<< "\n";
std::cout << "\n";
std::cout << "CURRENT CLOCKS (MHz):\n";
std::cout << std::dec << "current_gfxclk=" << smu.current_gfxclk << "\n";
std::cout << std::dec << "current_gfxclks= [";
std::copy(std::begin(smu.current_gfxclks),
std::end(smu.current_gfxclks),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << std::dec << "current_socclk=" << smu.current_socclk << "\n";
std::cout << std::dec << "current_socclks= [";
std::copy(std::begin(smu.current_socclks),
std::end(smu.current_socclks),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << std::dec << "current_uclk=" << smu.current_uclk << "\n";
std::cout << std::dec << "current_vclk0=" << smu.current_vclk0 << "\n";
std::cout << std::dec << "current_vclk0s= [";
std::copy(std::begin(smu.current_vclk0s),
std::end(smu.current_vclk0s),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << std::dec << "current_dclk0=" << smu.current_dclk0 << "\n";
std::cout << std::dec << "current_dclk0s= [";
std::copy(std::begin(smu.current_dclk0s),
std::end(smu.current_dclk0s),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << std::dec << "current_vclk1=" << smu.current_vclk1 << "\n";
std::cout << std::dec << "current_dclk1=" << smu.current_dclk1 << "\n";
std::cout << "\n";
std::cout << "TROTTLE STATUS:\n";
std::cout << std::dec << "throttle_status=" << smu.throttle_status << "\n";
std::cout << "\n";
std::cout << "FAN SPEED:\n";
std::cout << std::dec << "current_fan_speed=" << smu.current_fan_speed << "\n";
std::cout << "\n";
std::cout << "LINK WIDTH (number of lanes) /SPEED (0.1 GT/s):\n";
std::cout << "pcie_link_width=" << smu.pcie_link_width << "\n";
std::cout << "pcie_link_speed=" << smu.pcie_link_speed << "\n";
std::cout << "xgmi_link_width=" << smu.xgmi_link_width << "\n";
std::cout << "xgmi_link_speed=" << smu.xgmi_link_speed << "\n";
std::cout << "\n";
std::cout << "Utilization Accumulated(%):\n";
std::cout << "gfx_activity_acc=" << std::dec << smu.gfx_activity_acc << "\n";
std::cout << "mem_activity_acc=" << std::dec << smu.mem_activity_acc << "\n";
std::cout << "\n";
std::cout << "XGMI ACCUMULATED DATA TRANSFER SIZE (KB):\n";
std::cout << std::dec << "xgmi_read_data_acc= [";
std::copy(std::begin(smu.xgmi_read_data_acc),
std::end(smu.xgmi_read_data_acc),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << std::dec << "xgmi_write_data_acc= [";
std::copy(std::begin(smu.xgmi_write_data_acc),
std::end(smu.xgmi_write_data_acc),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
std::cout << std::dec << "xgmi_link_status= [";
std::copy(std::begin(smu.xgmi_link_status),
std::end(smu.xgmi_link_status),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << std::dec << "]\n";
// Voltage (mV)
std::cout << "voltage_soc = " << std::dec << smu.voltage_soc << "\n";
std::cout << "voltage_gfx = " << std::dec << smu.voltage_gfx << "\n";
std::cout << "voltage_mem = " << std::dec << smu.voltage_mem << "\n";
std::cout << "indep_throttle_status = " << std::dec << smu.indep_throttle_status << "\n";
// Clock Lock Status. Each bit corresponds to clock instance
std::cout << "gfxclk_lock_status (in hex) = " << std::hex
<< smu.gfxclk_lock_status << std::dec <<"\n";
// Bandwidth (GB/sec)
std::cout << "pcie_bandwidth_acc=" << std::dec << smu.pcie_bandwidth_acc << "\n";
std::cout << "pcie_bandwidth_inst=" << std::dec << smu.pcie_bandwidth_inst << "\n";
// VRAM max bandwidth at max memory clock (GB/sec)
std::cout << "vram_max_bandwidth=" << std::dec << smu.vram_max_bandwidth << "\n";
// Counts
std::cout << "pcie_l0_to_recov_count_acc= " << std::dec << smu.pcie_l0_to_recov_count_acc
<< "\n";
std::cout << "pcie_replay_count_acc= " << std::dec << smu.pcie_replay_count_acc << "\n";
std::cout << "pcie_replay_rover_count_acc= " << std::dec
<< smu.pcie_replay_rover_count_acc << "\n";
std::cout << "pcie_nak_sent_count_acc= " << std::dec << smu.pcie_nak_sent_count_acc
<< "\n";
std::cout << "pcie_nak_rcvd_count_acc= " << std::dec << smu.pcie_nak_rcvd_count_acc
<< "\n";
// Accumulation cycle counter
// Accumulated throttler residencies
std::cout << "\n";
std::cout << "RESIDENCY ACCUMULATION / COUNTER:\n";
std::cout << "accumulation_counter = " << std::dec << smu.accumulation_counter << "\n";
std::cout << "prochot_residency_acc = " << std::dec << smu.prochot_residency_acc << "\n";
std::cout << "ppt_residency_acc = " << std::dec << smu.ppt_residency_acc << "\n";
std::cout << "socket_thm_residency_acc = " << std::dec << smu.socket_thm_residency_acc
<< "\n";
std::cout << "vr_thm_residency_acc = " << std::dec << smu.vr_thm_residency_acc
<< "\n";
std::cout << "hbm_thm_residency_acc = " << std::dec << smu.hbm_thm_residency_acc << "\n";
// Number of current partitions
std::cout << "num_partition = " << std::dec << smu.num_partition << "\n";
// PCIE other end recovery counter
std::cout << "pcie_lc_perf_other_end_recovery = "
<< std::dec << smu.pcie_lc_perf_other_end_recovery << "\n";
std::cout << std::dec << "xcp_stats.gfx_busy_inst = \n";
auto xcp = 0;
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.gfx_busy_inst),
std::end(row.gfx_busy_inst),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
xcp = 0;
std::cout << std::dec << "xcp_stats.jpeg_busy = \n";
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.jpeg_busy),
std::end(row.jpeg_busy),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
xcp = 0;
std::cout << std::dec << "xcp_stats.vcn_busy = \n";
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.vcn_busy),
std::end(row.vcn_busy),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
xcp = 0;
std::cout << std::dec << "xcp_stats.gfx_busy_acc = \n";
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.gfx_busy_acc),
std::end(row.gfx_busy_acc),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
xcp = 0;
std::cout << std::dec << "xcp_stats.gfx_below_host_limit_acc = \n";
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.gfx_below_host_limit_acc),
std::end(row.gfx_below_host_limit_acc),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
// new for gpu metrics v1.8
xcp = 0;
std::cout << std::dec << "xcp_stats.gfx_below_host_limit_ppt_acc = \n";
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.gfx_below_host_limit_ppt_acc),
std::end(row.gfx_below_host_limit_ppt_acc),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
xcp = 0;
std::cout << std::dec << "xcp_stats.gfx_below_host_limit_thm_acc = \n";
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.gfx_below_host_limit_thm_acc),
std::end(row.gfx_below_host_limit_thm_acc),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
xcp = 0;
std::cout << std::dec << "xcp_stats.gfx_low_utilization_acc = \n";
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.gfx_low_utilization_acc),
std::end(row.gfx_low_utilization_acc),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
xcp = 0;
std::cout << std::dec << "xcp_stats.gfx_below_host_limit_total_acc = \n";
for (auto& row : smu.xcp_stats) {
std::cout << "XCP[" << xcp << "] = " << "[ ";
std::copy(std::begin(row.gfx_below_host_limit_total_acc),
std::end(row.gfx_below_host_limit_total_acc),
amd::smi::make_ostream_joiner(&std::cout, ", "));
std::cout << " ]\n";
xcp++;
}
std::cout << "\n\n";
std::cout << "\t ** -> Checking metrics with constant changes ** " << "\n";
constexpr uint16_t kMAX_ITER_TEST = 10;
amdsmi_gpu_metrics_t gpu_xcp_metrics_check = {};
for (auto idx = uint16_t(1); idx <= kMAX_ITER_TEST; ++idx) {
amdsmi_get_gpu_metrics_info(processor_handles_[i], &gpu_xcp_metrics_check);
std::cout << "\t\t -> firmware_timestamp [" << idx << "/" << kMAX_ITER_TEST << "]: "
<< gpu_xcp_metrics_check.firmware_timestamp << "\n";
}
std::cout << "\n";
for (auto idx = uint16_t(1); idx <= kMAX_ITER_TEST; ++idx) {
amdsmi_get_gpu_partition_metrics_info(processor_handles_[i], &gpu_xcp_metrics_check);
std::cout << "\t\t -> system_clock_counter [" << idx << "/" << kMAX_ITER_TEST << "]: "
<< gpu_xcp_metrics_check.system_clock_counter << "\n";
}
std::cout << "\n";
std::cout << " ** Note: Values MAX'ed out "
<< "(UINTX MAX are unsupported for the version in question) ** " << "\n\n";
}
}
// Verify api support checking functionality is working
err = amdsmi_get_gpu_partition_metrics_info(processor_handles_[i], nullptr);
if (err !=AMDSMI_STATUS_INVAL) {
DISPLAY_AMDSMI_ERR(err);
}
amdsmi_status_code_to_string(err, &status_string);
std::cout << "\t\t** amdsmi_get_gpu_partition_metrics_info(nullptr check): " << status_string << "\n";
ASSERT_EQ(err, AMDSMI_STATUS_INVAL);
}
}
@@ -0,0 +1,51 @@
/*
* Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef TESTS_AMD_SMI_TEST_FUNCTIONAL_GPU_PARTITION_METRICS_READ_H_
#define TESTS_AMD_SMI_TEST_FUNCTIONAL_GPU_PARTITION_METRICS_READ_H_
#include "../test_base.h"
class TestGpuPartitionMetricsRead : public TestBase {
public:
TestGpuPartitionMetricsRead();
// @Brief: Destructor for test case of TestGpuPartitionMetricsRead
virtual ~TestGpuPartitionMetricsRead();
// @Brief: Setup the environment for measurement
virtual void SetUp();
// @Brief: Core measurement execution
virtual void Run();
// @Brief: Clean up and retrive the resource
virtual void Close();
// @Brief: Display results
virtual void DisplayResults() const;
// @Brief: Display information about what this test does
virtual void DisplayTestInfo(void);
};
#endif // TESTS_AMD_SMI_TEST_FUNCTIONAL_GPU_PARTITION_METRICS_READ_H_
+5
View File
@@ -37,6 +37,7 @@
#include "functional/process_info_read.h"
#include "functional/gpu_busy_read.h"
#include "functional/gpu_metrics_read.h"
#include "functional/gpu_partition_metrics_read.h"
#include "functional/err_cnt_read.h"
#include "functional/power_read.h"
#include "functional/power_read_write.h"
@@ -224,6 +225,10 @@ TEST(amdsmitstReadOnly, TestGpuMetricsRead) {
TestGpuMetricsRead tst;
RunGenericTest(&tst);
}
TEST(amdsmitstReadOnly, TestGpuPartitionMetricsRead) {
TestGpuPartitionMetricsRead tst;
RunGenericTest(&tst);
}
TEST(amdsmitstReadOnly, TestMetricsCounterRead) {
TestMetricsCounterRead tst;
RunGenericTest(&tst);
+17 -1
View File
@@ -282,7 +282,23 @@ void TestBase::PrintDeviceHeader(amdsmi_processor_handle dv_ind) {
}
}
std::cout << std::setbase(10);
amdsmi_kfd_info_t kfd_info;
err = amdsmi_get_gpu_kfd_info(dv_ind, &kfd_info);
if (err == AMDSMI_STATUS_NOT_SUPPORTED) {
IF_VERB(STANDARD) {
std::cout << "\t**KFD info: " << smi_amdgpu_get_status_string(err, false) << std::endl;
}
ASSERT_EQ(err, AMDSMI_STATUS_NOT_SUPPORTED);
} else {
CHK_ERR_ASRT(err)
IF_VERB(STANDARD) {
std::cout << "\t**KFD info: " << std::endl;
std::cout << "\t\t**GPU ID: " << std::dec << kfd_info.kfd_id << std::endl;
std::cout << "\t\t**Node ID: " << std::dec << kfd_info.node_id << std::endl;
std::cout << "\t\t**Partition ID: "
<< std::dec << kfd_info.current_partition_id << std::endl;
}
}
}
void TestBase::Run(void) {
std::string label;
+15 -2
View File
@@ -1581,8 +1581,6 @@ class TestAmdSmiPython(unittest.TestCase):
def test_get_gpu_metrics_info(self):
self._print_func_name('')
if self.TODO_SKIP_FAIL:
self.skipTest("Skipping test_get_gpu_metrics_info as it fails (MI350X, AMDSMI_STATUS_UNEXPECTED_DATA).")
for i, gpu in enumerate(self.processors):
msg = f'gpu({i}):'
try:
@@ -1595,6 +1593,19 @@ class TestAmdSmiPython(unittest.TestCase):
raise self.raise_exception
return
def test_get_gpu_partition_metrics_info(self):
self._print_func_name('')
for i, gpu in enumerate(self.processors):
try:
msg = f'gpu({i}): '
ret = amdsmi.amdsmi_get_gpu_partition_metrics_info(gpu)
self._print(msg, ret)
except amdsmi.AmdSmiLibraryException as e:
if self._check_ret(msg, e, self.PASS):
self.raise_exception = e
if self.raise_exception:
raise self.raise_exception
def test_get_gpu_od_volt_curve_regions(self):
self._print_func_name('')
num_region = 10
@@ -3110,6 +3121,8 @@ class TestAmdSmiPython(unittest.TestCase):
def test_set_gpu_perf_level(self):
self._print_func_name('')
if self.TODO_SKIP_NOT_COMPLETE:
self.skipTest("Skipping test_set_gpu_perf_level as it is not complete.")
dev_perf_level_current = self.dev_perf_levels[0][1]
for i, gpu in enumerate(self.processors):
msg = f'gpu({i}):'