SWDEV-342812- Add NPS support

Updates:
    * Added rsmi_dev_nps_mode_set and rsmi_dev_nps_mode_get
    * Added ability to set multiple SYSFS files in debug build
    * Added ability to see user's env variables set for debug build
    * Added tests for rsmi_dev_nps_mode_set and rsmi_dev_nps_mode_get
    * Added ability to restart AMD GPU driver, used in nps_mode_set
    * Updated ROCm_SMI_Manual.pdf to include new APIs
    * Added progress bar for long running python_smi_tools, used
      in setting nps_mode if runs longer than .1 seconds

Change-Id: I6d61bedd28d7cba6aff432ad2d127ba741b7d15a
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
This commit is contained in:
Charis Poag
2023-01-30 15:58:03 -06:00
parent ae10e842af
commit 9ef376cd61
19 changed files with 1198 additions and 87 deletions
+65 -1
View File
@@ -3,7 +3,7 @@
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2018, Advanced Micro Devices, Inc.
* Copyright (c) 2018-2023, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
@@ -51,6 +51,7 @@
#include <sstream>
#include <algorithm>
#include <vector>
#include <regex>
#include "rocm_smi/rocm_smi.h"
#include "rocm_smi/rocm_smi_utils.h"
@@ -234,5 +235,68 @@ rsmi_status_t ErrnoToRsmiStatus(int err) {
}
}
std::string leftTrim(const std::string &s) {
if (!s.empty()) {
return std::regex_replace(s, std::regex("^\\s+"), "");
}
return s;
}
std::string rightTrim(const std::string &s) {
if (!s.empty()) {
return std::regex_replace(s, std::regex("\\s+$"), "");
}
return s;
}
std::string removeNewLines(const std::string &s) {
if (!s.empty()) {
return std::regex_replace(s, std::regex("\n+"), "");
}
return s;
}
std::string trim(const std::string &s) {
if (!s.empty()) {
// remove new lines -> trim white space at ends
std::string noNewLines = removeNewLines(s);
return leftTrim(rightTrim(noNewLines));
}
return s;
}
// defaults to trim stdOut
std::pair<bool, std::string> executeCommand(std::string command, bool stdOut) {
char buffer[128];
std::string stdoutAndErr = "";
bool successfulRun = true;
command = "stdbuf -i0 -o0 -e0 " + command; // remove stdOut and err buffering
FILE *pipe = popen(command.c_str(), "r");
if (!pipe) {
stdoutAndErr = "[ERROR] popen failed to call " + command;
successfulRun = false;
} else {
//read until end of process
while (!feof(pipe)) {
// use buffer to read and add to stdoutAndErr
if (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
stdoutAndErr += buffer;
}
}
}
// any return code other than 0, is a failed execution
if (pclose(pipe) != 0) {
successfulRun = false;
}
if (stdOut) {
// remove leading and trailing spaces of output and new lines
stdoutAndErr = trim(stdoutAndErr);
}
return std::make_pair(successfulRun, stdoutAndErr);
}
} // namespace smi
} // namespace amd