diff --git a/rocrtst/common/base_rocr.cc b/rocrtst/common/base_rocr.cc index 4c95e4cf85..5682ed0689 100755 --- a/rocrtst/common/base_rocr.cc +++ b/rocrtst/common/base_rocr.cc @@ -64,6 +64,7 @@ BaseRocR::BaseRocR(void) { orig_hsa_enable_interrupt_ = GetEnv("HSA_ENABLE_INTERRUPT"); set_kernel_file_name(""); set_verbosity(0); + set_monitor_verbosity(0); set_title("unset_title"); } diff --git a/rocrtst/common/base_rocr.h b/rocrtst/common/base_rocr.h index 121c5318df..cdaf43a34b 100755 --- a/rocrtst/common/base_rocr.h +++ b/rocrtst/common/base_rocr.h @@ -214,6 +214,13 @@ class BaseRocR { return verbosity_; } + void set_monitor_verbosity(uint32_t m) { + monitor_verbosity_ = m; + } + uint32_t monitor_verbosity(void) const { + return monitor_verbosity_; + } + protected: void set_requires_profile(int32_t reqd_prof) { requires_profile_ = reqd_prof; @@ -270,6 +277,8 @@ class BaseRocR { uint32_t verbosity_; ///< How much additional output to produce + uint32_t monitor_verbosity_; ///< How much additional output to produce + PerfTimer hsa_timer_; ///< Timer to be used for timing parts of test }; diff --git a/rocrtst/suites/performance/main.cc b/rocrtst/suites/performance/main.cc index 36bab14d5a..93a0219177 100755 --- a/rocrtst/suites/performance/main.cc +++ b/rocrtst/suites/performance/main.cc @@ -43,6 +43,10 @@ * */ +#include +#include +#include + #include "gtest/gtest.h" #include "suites/performance/dispatch_time.h" #include "suites/performance/memory_async_copy.h" @@ -50,15 +54,35 @@ #include "suites/performance/main.h" #include "suites/test_common/test_common.h" -static uint32_t sRocrTstOptVerbosity = 1; -static uint32_t sRocrTestOptIterations = 0; +#include "common/rocm_smi/rocm_smi.h" + + +static RocrTstGlobals *sRocrtstGlvalues = nullptr; + +static bool GetMonitorDevices(const std::shared_ptr &d, + void *p) { + std::string val_str; + + assert(p != nullptr); + + std::vector> *device_list = + reinterpret_cast> *>(p); + + if (d->monitor() != nullptr) { + device_list->push_back(d); + } + return false; +} + static void RunTest(TestBase *test) { - test->set_verbosity(sRocrTstOptVerbosity); + assert(sRocrtstGlvalues != nullptr); + + test->set_verbosity(sRocrtstGlvalues->verbosity); + test->set_monitor_verbosity(sRocrtstGlvalues->monitor_verbosity); + test->set_num_iteration(sRocrtstGlvalues->num_iterations); + test->set_monitor_devices(&sRocrtstGlvalues->monitor_devices); - if (sRocrTestOptIterations) { - test->set_num_iteration(sRocrTestOptIterations); - } test->DisplayTestInfo(); test->SetUp(); test->Run(); @@ -79,6 +103,10 @@ static void RunTest(TestBase *test) { TEST(rocrtst, Test_Example) { TestExample tst; + + rocrtst::smi::RocmSMI hw; + hw.DiscoverDevices(); + RunTest(&tst); } @@ -117,11 +145,22 @@ TEST(rocrtst, Perf_Dispatch_Time_Multi_Interrupt) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - RocrtstOptions opts(&sRocrTstOptVerbosity, &sRocrTestOptIterations); + RocrTstGlobals settings; - if (ProcessCmdline(&opts, argc, argv)) { + settings.verbosity = 1; + settings.monitor_verbosity = 1; + settings.num_iterations = 0; + + if (ProcessCmdline(&settings, argc, argv)) { return 1; } + rocrtst::smi::RocmSMI hw; + hw.DiscoverDevices(); + hw.IterateSMIDevices( + GetMonitorDevices, reinterpret_cast(&settings.monitor_devices)); + + sRocrtstGlvalues = &settings; + return RUN_ALL_TESTS(); } diff --git a/rocrtst/suites/performance/main.h b/rocrtst/suites/performance/main.h new file mode 100755 index 0000000000..d7d4425f84 --- /dev/null +++ b/rocrtst/suites/performance/main.h @@ -0,0 +1,49 @@ +/* + * ============================================================================= + * ROC Runtime Conformance Release License + * ============================================================================= + * The University of Illinois/NCSA + * Open Source License (NCSA) + * + * Copyright (c) 2017, 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 ROCRTST_SUITES_PERFORMANCE_MAIN_H_ +#define ROCRTST_SUITES_PERFORMANCE_MAIN_H_ + +#endif // ROCRTST_SUITES_PERFORMANCE_MAIN_H_ + diff --git a/rocrtst/suites/test_common/test_base.cc b/rocrtst/suites/test_common/test_base.cc index d7fa7883bf..cc3ea12829 100755 --- a/rocrtst/suites/test_common/test_base.cc +++ b/rocrtst/suites/test_common/test_base.cc @@ -46,6 +46,7 @@ #include #include "suites/test_common/test_base.h" +#include "suites/test_common/test_common.h" #include "common/base_rocr_utils.h" #include "gtest/gtest.h" @@ -101,6 +102,11 @@ void TestBase::Close(void) { MakeHeaderStr(kCloseLabel, &label); printf("\n\t%s\n", label.c_str()); + + if (monitor_verbosity() > 0) { + DumpMonitorInfo(this); + } + err = rocrtst::CommonCleanUp(this); ASSERT_EQ(err, HSA_STATUS_SUCCESS); } diff --git a/rocrtst/suites/test_common/test_base.h b/rocrtst/suites/test_common/test_base.h index 9141fbf66a..269d8d6a37 100755 --- a/rocrtst/suites/test_common/test_base.h +++ b/rocrtst/suites/test_common/test_base.h @@ -46,11 +46,14 @@ #define ROCRTST_SUITES_TEST_COMMON_TEST_BASE_H_ #include +#include +#include + #include "common/base_rocr.h" +#include "common/rocm_smi/rocm_smi.h" class TestBase : public rocrtst::BaseRocR { public: - TestBase(void); virtual ~TestBase(void); @@ -77,8 +80,18 @@ class TestBase : public rocrtst::BaseRocR { void set_description(std::string d); + void set_monitor_devices( + std::vector> *m) { + monitor_devices_ = m; + } + std::vector> * + monitor_devices(void) const { + return monitor_devices_; + } + private: std::string description_; + std::vector> *monitor_devices_; }; #endif // ROCRTST_SUITES_TEST_COMMON_TEST_BASE_H_ diff --git a/rocrtst/suites/test_common/test_common.cc b/rocrtst/suites/test_common/test_common.cc index 8ae52d026b..64f1f56f74 100755 --- a/rocrtst/suites/test_common/test_common.cc +++ b/rocrtst/suites/test_common/test_common.cc @@ -45,34 +45,26 @@ #include #include -#include #include +#include +#include + +#include "suites/test_common/test_base.h" #include "suites/test_common/test_common.h" -RocrtstOptions::RocrtstOptions(uint32_t *verb, uint32_t *iter) { - assert(verb != nullptr); - assert(iter != nullptr); - - verbosity_ = verb; - iterations_ = iter; -} - -RocrtstOptions::~RocrtstOptions() { -} static const struct option long_options[] = { {"iterations", required_argument, nullptr, 'i'}, - {"verbose", no_argument, nullptr, 'v'}, + {"verbose", required_argument, nullptr, 'v'}, + {"monitor_verbose", required_argument, nullptr, 'm'}, {nullptr, 0, nullptr, 0} }; -static const char* short_options = "i:v:r"; +static const char* short_options = "i:v:m:r"; static void PrintHelp(void) { std::cout << -// "Required Arguments:\n" -// "--kernel, -k \n" "Optional RocRTst Arguments:\n" "--iterations, -i ; override default, " "which varies for each test\n" @@ -83,10 +75,16 @@ static void PrintHelp(void) { " 1 -- intermediate; show intermediate values such as intermediate " "perf. data\n" " 2 -- progress; show progress displays\n" - " >= 3 -- more debug output\n"; + " >= 3 -- more debug output\n" + "--monitor_verbosity, -m \n" + " Monitor Verbosity levels:\n" + " 0 -- don't read or print out any GPU monitor information;\n" + " 1 -- print out all available monitor information before the first " + "test and after each test\n" + " >= 2 -- print out even more monitor information (test specific)\n"; } -uint32_t ProcessCmdline(RocrtstOptions* test, int arg_cnt, char** arg_list) { +uint32_t ProcessCmdline(RocrTstGlobals* test, int arg_cnt, char** arg_list) { int a; int ind = -1; @@ -101,11 +99,15 @@ uint32_t ProcessCmdline(RocrtstOptions* test, int arg_cnt, char** arg_list) { switch (a) { case 'i': - *test->iterations_ = std::stoi(optarg); + test->num_iterations = std::stoi(optarg); break; case 'v': - *test->verbosity_ = std::stoi(optarg); + test->verbosity = std::stoi(optarg); + break; + + case 'm': + test->monitor_verbosity = std::stoi(optarg); break; case 'r': @@ -119,3 +121,87 @@ uint32_t ProcessCmdline(RocrtstOptions* test, int arg_cnt, char** arg_list) { } return 0; } + +void DumpMonitorInfo(const TestBase *test) { + int ret = 0; + uint32_t value; + uint32_t value2; + std::string val_str; + std::vector val_vec; + + assert(test != nullptr); + assert(test->monitor_devices() != nullptr && + "Make sure to call test->set_monitor_devices()"); + auto print_attr_label = + [&](std::string attrib) -> bool { + std::cout << "\t** " << attrib; + if (ret == -1) { + std::cout << "not available" << std::endl; + return false; + } + return true; + }; + + auto delim = "\t***********************************"; + + std::cout << "\t***** Hardware monitor values *****" << std::endl; + std::cout << delim << std::endl; + std::cout.setf(std::ios::dec, std::ios::basefield); + for (auto dev : *test->monitor_devices()) { + auto print_vector = + [&](rocrtst::smi::DevInfoTypes type, std::string label) { + ret = dev->readDevInfo(type, &val_vec); + if (print_attr_label(label)) { + for (auto vs : val_vec) { + std::cout << "\t** " << vs << std::endl; + } + val_vec.clear(); + } + }; + auto print_val_str = + [&](rocrtst::smi::DevInfoTypes type, std::string label) { + ret = dev->readDevInfo(type, &val_str); + + std::cout << "\t** " << label; + if (ret == -1) { + std::cout << "not available"; + } else { + std::cout << val_str; + } + std::cout << std:: endl; + }; + + print_val_str(rocrtst::smi::kDevDevID, "Device ID: "); + print_val_str(rocrtst::smi::kDevPerfLevel, "Performance Level: "); + print_val_str(rocrtst::smi::kDevOverDriveLevel, "OverDrive Level: "); + print_vector(rocrtst::smi::kDevGPUMClk, + "Supported GPU Memory clock frequencies:\n"); + print_vector(rocrtst::smi::kDevGPUSClk, + "Supported GPU clock frequencies:\n"); + + if (dev->monitor() != nullptr) { + ret = dev->monitor()->readMonitor(rocrtst::smi::kMonName, &val_str); + if (print_attr_label("Monitor name: ")) { + std::cout << val_str << std::endl; + } + + ret = dev->monitor()->readMonitor(rocrtst::smi::kMonTemp, &value); + if (print_attr_label("Temperature: ")) { + std::cout << static_cast(value)/1000.0 << "C" << std::endl; + } + + std::cout.setf(std::ios::dec, std::ios::basefield); + + ret = dev->monitor()->readMonitor(rocrtst::smi::kMonMaxFanSpeed, &value); + if (ret == 0) { + ret = dev->monitor()->readMonitor(rocrtst::smi::kMonFanSpeed, &value2); + } + if (print_attr_label("Current Fan Speed: ")) { + std::cout << value2/static_cast(value) * 100 << "% (" << + value2 << "/" << value << ")" << std::endl; + } + } + std::cout << "\t=======" << std::endl; + } + std::cout << delim << std::endl; +} diff --git a/rocrtst/suites/test_common/test_common.h b/rocrtst/suites/test_common/test_common.h index c40329bce2..bb825ed400 100755 --- a/rocrtst/suites/test_common/test_common.h +++ b/rocrtst/suites/test_common/test_common.h @@ -46,16 +46,20 @@ #ifndef ROCRTST_SUITES_TEST_COMMON_TEST_COMMON_H_ #define ROCRTST_SUITES_TEST_COMMON_TEST_COMMON_H_ -class RocrtstOptions { - public: - RocrtstOptions(uint32_t *verb, uint32_t *iter); +#include +#include - ~RocrtstOptions(void); +#include "common/rocm_smi/rocm_smi.h" - uint32_t *verbosity_; - uint32_t *iterations_; +struct RocrTstGlobals { + uint32_t verbosity; + uint32_t monitor_verbosity; + uint32_t num_iterations; + std::vector> monitor_devices; }; -uint32_t ProcessCmdline(RocrtstOptions* test, int arg_cnt, char** arg_list); +uint32_t ProcessCmdline(RocrTstGlobals* test, int arg_cnt, char** arg_list); + +void DumpMonitorInfo(const TestBase *test); #endif // ROCRTST_SUITES_TEST_COMMON_TEST_COMMON_H_