Show more info in stderr when rsmi_init() fails

Some rsmi apps fail without much explanation when
rsmi_init() fails. This patch hopes to provide some clues to
the reason for the failure.

Change-Id: Id51308dc327b9871d537dd3e709b677db4ef10bc


[ROCm/rocm_smi_lib commit: 6377e0258d]
Этот коммит содержится в:
Chris Freehill
2020-12-09 16:41:26 -06:00
коммит произвёл Kent Russell
родитель aef625bfd3
Коммит df789612b6
4 изменённых файлов: 42 добавлений и 2 удалений
+1
Просмотреть файл
@@ -435,6 +435,7 @@ rsmi_init(uint64_t flags) {
smi.Initialize(flags);
} catch(...) {
smi.Cleanup();
std::cerr << "rsmi_init() failed" << std::endl;
throw amd::smi::rsmi_exception(RSMI_STATUS_INIT_ERROR, __FUNCTION__);
}
}
+12 -1
Просмотреть файл
@@ -177,7 +177,14 @@ int DiscoverIOLinks(std::map<std::pair<uint32_t, uint32_t>,
links->clear();
auto kfd_node_dir = opendir(kKFDNodesPathRoot);
assert(kfd_node_dir != nullptr);
if (kfd_node_dir == nullptr) {
std::string err_msg = "Failed to open KFD nodes directory ";
err_msg += kKFDNodesPathRoot;
err_msg += ".";
perror(err_msg.c_str());
return 1;
}
auto dentry_kfd = readdir(kfd_node_dir);
while (dentry_kfd != nullptr) {
@@ -222,6 +229,10 @@ int DiscoverIOLinks(std::map<std::pair<uint32_t, uint32_t>,
}
if (closedir(io_link_dir)) {
std::string err_msg = "Failed to close KFD nodes directory ";
err_msg += kKFDNodesPathRoot;
err_msg += ".";
perror(err_msg.c_str());
return 1;
}
+8
Просмотреть файл
@@ -559,12 +559,16 @@ int DiscoverKFDNodes(std::map<uint64_t, std::shared_ptr<KFDNode>> *nodes) {
node->get_property_value(kKFDNodePropLOCATION_IDStr,
&kfd_gpu_node_bus_fn);
if (ret != 0) {
std:: cerr << "Failed to open properties file for kfd node " <<
node->node_index() << "." << std::endl;
closedir(kfd_node_dir);
return ret;
}
ret =
node->get_property_value(kKFDNodePropDOMAINStr, &kfd_gpu_node_domain);
if (ret != 0) {
std::cerr << "Failed to get \"domain\" properity from properties "
"files for kfd node " << node->node_index() << "." << std::endl;
closedir(kfd_node_dir);
return ret;
}
@@ -577,6 +581,10 @@ int DiscoverKFDNodes(std::map<uint64_t, std::shared_ptr<KFDNode>> *nodes) {
}
if (closedir(kfd_node_dir)) {
std::string err_str = "Failed to close KFD node directory ";
err_str += kKFDNodesPathRoot;
err_str += ".";
perror(err_str.c_str());
return 1;
}
return 0;
+21 -1
Просмотреть файл
@@ -56,6 +56,7 @@
#include <functional>
#include <cerrno>
#include <unordered_map>
#include <iostream>
#include "rocm_smi/rocm_smi.h"
#include "rocm_smi/rocm_smi_device.h"
@@ -230,6 +231,7 @@ static uint32_t GetMonitorDevices(const std::shared_ptr<amd::smi::Device> &d,
if (d->monitor() != nullptr) {
// Calculate BDFID and set for this device
if (ConstructBDFID(d->path(), &bdfid) != 0) {
std::cerr << "Failed to construct BDFID." << std::endl;
return 1;
}
d->set_bdfid(bdfid);
@@ -458,6 +460,7 @@ static bool isAMDGPU(std::string dev_path) {
uint32_t RocmSMI::DiscoverAmdgpuDevices(void) {
uint32_t ret = 0;
std::string err_msg;
// If this gets called more than once, clear previous findings.
devices_.clear();
@@ -471,6 +474,10 @@ uint32_t RocmSMI::DiscoverAmdgpuDevices(void) {
auto drm_dir = opendir(kPathDRMRoot);
if (drm_dir == nullptr) {
err_msg = "Failed to open drm root directory ";
err_msg += kPathDRMRoot;
err_msg += ".";
perror(err_msg.c_str());
return 1;
}
@@ -492,6 +499,10 @@ uint32_t RocmSMI::DiscoverAmdgpuDevices(void) {
}
if (closedir(drm_dir)) {
err_msg = "Failed to close drm root directory ";
err_msg += kPathDRMRoot;
err_msg += ".";
perror(err_msg.c_str());
return 1;
}
return 0;
@@ -504,6 +515,7 @@ uint32_t RocmSMI::DiscoverAMDMonitors(void) {
std::string mon_name;
std::string tmp;
std::string err_msg;
while (dentry != nullptr) {
if (dentry->d_name[0] == '.') {
@@ -521,7 +533,11 @@ uint32_t RocmSMI::DiscoverAMDMonitors(void) {
fs.open(tmp);
if (!fs.is_open()) {
return 1;
err_msg = "Failed to open monitor file ";
err_msg += tmp;
err_msg += ".";
perror(err_msg.c_str());
return 1;
}
std::string mon_type;
fs >> mon_type;
@@ -539,6 +555,10 @@ uint32_t RocmSMI::DiscoverAMDMonitors(void) {
}
if (closedir(mon_dir)) {
err_msg = "Failed to close monitor directory ";
err_msg += kPathHWMonRoot;
err_msg += ".";
perror(err_msg.c_str());
return 1;
}
return 0;