From f397cba4146d8673e4d80d9696e636f35037d42e Mon Sep 17 00:00:00 2001 From: Divya Shikre Date: Wed, 7 Oct 2020 12:47:46 -0400 Subject: [PATCH] Adding gtest for gpu metrics read Signed-off-by: Divya Shikre Change-Id: I66edb15c8b7380f3427822b33e845202bfac7a2b --- .../functional/gpu_metrics_read.cc | 185 ++++++++++++++++++ .../functional/gpu_metrics_read.h | 73 +++++++ tests/rocm_smi_test/main.cc | 5 + 3 files changed, 263 insertions(+) create mode 100644 tests/rocm_smi_test/functional/gpu_metrics_read.cc create mode 100644 tests/rocm_smi_test/functional/gpu_metrics_read.h diff --git a/tests/rocm_smi_test/functional/gpu_metrics_read.cc b/tests/rocm_smi_test/functional/gpu_metrics_read.cc new file mode 100644 index 0000000000..7aae2451a8 --- /dev/null +++ b/tests/rocm_smi_test/functional/gpu_metrics_read.cc @@ -0,0 +1,185 @@ +/* + * ============================================================================= + * ROC Runtime Conformance Release License + * ============================================================================= + * The University of Illinois/NCSA + * Open Source License (NCSA) + * + * Copyright (c) 2020, Advanced Micro Devices, Inc. + * All rights reserved. + * + * Developed by: + * + * AMD Research and AMD ROC Software Development + * + * Advanced Micro Devices, Inc. + * + * www.amd.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal with 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: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimers. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimers in + * the documentation and/or other materials provided with the distribution. + * - Neither the names of , + * nor the names of its contributors may be used to endorse or promote + * products derived from this Software without specific prior written + * permission. + * + * 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 CONTRIBUTORS 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 WITH THE SOFTWARE. + * + */ + +#include +#include + +#include +#include +#include + +#include "gtest/gtest.h" +#include "rocm_smi/rocm_smi.h" +#include "rocm_smi_test/functional/gpu_metrics_read.h" +#include "rocm_smi_test/test_common.h" + + +TestGpuMetricsRead::TestGpuMetricsRead() : TestBase() { + set_title("RSMI GPU Metrics Read Test"); + set_description("The GPU Metrics tests verifies that the gpu metrics info can be read properly."); +} + +TestGpuMetricsRead::~TestGpuMetricsRead(void) { +} + +void TestGpuMetricsRead::SetUp(void) { + TestBase::SetUp(); + + return; +} + +void TestGpuMetricsRead::DisplayTestInfo(void) { + TestBase::DisplayTestInfo(); +} + +void TestGpuMetricsRead::DisplayResults(void) const { + TestBase::DisplayResults(); + return; +} + +void TestGpuMetricsRead::Close() { + // This will close handles opened within rsmitst utility calls and call + // rsmi_shut_down(), so it should be done after other hsa cleanup + TestBase::Close(); +} + + +void TestGpuMetricsRead::Run(void) { + rsmi_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(i); + + IF_VERB(STANDARD) { + std::cout << "\t**GPU METRICS:\n"; + } + rsmi_gpu_metrics_t smu; + err = rsmi_dev_gpu_metrics_info_get(i, &smu); + if (err != RSMI_STATUS_SUCCESS) { + if (err == RSMI_STATUS_NOT_SUPPORTED) { + IF_VERB(STANDARD) { + std::cout << "\t**" << + "Not supported on this machine" << std::endl; + return; + } + } else { + CHK_ERR_ASRT(err); + IF_VERB(STANDARD) { + std::cout << std::dec << "system_clock_counter=" + << smu.system_clock_counter << '\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 << 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 << "average_socket_power=" + << smu.average_socket_power << '\n'; + std::cout << std::dec << "energy_accumulator=" + << smu.energy_accumulator << '\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_dclk0_frequency=" + << smu.average_dclk0_frequency << '\n'; + std::cout << std::dec << "average_dclk1_frequency=" + << smu.average_dclk1_frequency << '\n'; + std::cout << std::dec << "current_gfxclk=" + << smu.current_gfxclk << '\n'; + std::cout << std::dec << "current_socclk=" + << smu.current_socclk << '\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_dclk0=" + << smu.current_dclk0 << '\n'; + std::cout << std::dec << "current_vclk1=" + << smu.current_vclk1 << '\n'; + std::cout << std::dec << "current_dclk1=" + << smu.current_dclk1 << '\n'; + std::cout << std::dec << "throttle_status=" + << smu.throttle_status << '\n'; + std::cout << std::dec << "current_fan_speed=" + << smu.current_fan_speed << '\n'; + std::cout << "pcie_link_width=" + << std::to_string(smu.pcie_link_width) << '\n'; + std::cout << "pcie_link_width=" + << std::to_string(smu.pcie_link_speed) << '\n'; + } + } + + // Verify api support checking functionality is working + err = rsmi_dev_gpu_metrics_info_get(i, nullptr); + ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS); + + } + } +} diff --git a/tests/rocm_smi_test/functional/gpu_metrics_read.h b/tests/rocm_smi_test/functional/gpu_metrics_read.h new file mode 100644 index 0000000000..a732a403a0 --- /dev/null +++ b/tests/rocm_smi_test/functional/gpu_metrics_read.h @@ -0,0 +1,73 @@ +/* + * ============================================================================= + * ROC Runtime Conformance Release License + * ============================================================================= + * The University of Illinois/NCSA + * Open Source License (NCSA) + * + * Copyright (c) 2020, Advanced Micro Devices, Inc. + * All rights reserved. + * + * Developed by: + * + * AMD Research and AMD ROC Software Development + * + * Advanced Micro Devices, Inc. + * + * www.amd.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal with 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: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimers. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimers in + * the documentation and/or other materials provided with the distribution. + * - Neither the names of , + * nor the names of its contributors may be used to endorse or promote + * products derived from this Software without specific prior written + * permission. + * + * 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 CONTRIBUTORS 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 WITH THE SOFTWARE. + * + */ +#ifndef TESTS_ROCM_SMI_TEST_FUNCTIONAL_GPU_METRICS_READ_H_ +#define TESTS_ROCM_SMI_TEST_FUNCTIONAL_GPU_METRICS_READ_H_ + +#include "rocm_smi_test/test_base.h" + +class TestGpuMetricsRead : public TestBase { + public: + TestGpuMetricsRead(); + + // @Brief: Destructor for test case of TestVOltRead + virtual ~TestGpuMetricsRead(); + + // @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_ROCM_SMI_TEST_FUNCTIONAL_GPU_METRICS_READ_H_ diff --git a/tests/rocm_smi_test/main.cc b/tests/rocm_smi_test/main.cc index 1502750ba3..3199b580fb 100755 --- a/tests/rocm_smi_test/main.cc +++ b/tests/rocm_smi_test/main.cc @@ -82,6 +82,7 @@ #include "functional/evt_notif_read_write.h" #include "functional/init_shutdown_refcount.h" #include "rocm_smi_test/functional/hw_topology_read.h" +#include "rocm_smi_test/functional/gpu_metrics_read.h" static RSMITstGlobals *sRSMIGlvalues = nullptr; @@ -228,6 +229,10 @@ TEST(rsmitstReadOnly, TestHWTopologyRead) { TestHWTopologyRead tst; RunGenericTest(&tst); } +TEST(rsmitstReadOnly, TestGpuMetricsRead) { + TestGpuMetricsRead tst; + RunGenericTest(&tst); +} TEST(rsmitstReadWrite, TestXGMIReadWrite) { TestXGMIReadWrite tst; RunGenericTest(&tst);