Skip to content

Commit

Permalink
Merge pull request #27 from cfreehill/master
Browse files Browse the repository at this point in the history
Use system tables for gpu names instead of internal table
  • Loading branch information
cfreehill authored Mar 11, 2019
2 parents e9e54bc + 58d5ff7 commit 9144cad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi_monitor.cc")
set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi.cc")
set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi_power_mon.cc")
set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi_utils.cc")
set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi_dev_names.cc")

set(SMI_INC_LIST "${INC_DIR}/rocm_smi_device.h")
set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_main.h")
Expand All @@ -122,7 +121,6 @@ set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_power_mon.h")
set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_utils.h")
set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_common.h")
set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_exception.h")
set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_dev_names.h")

set(SMI_EXAMPLE_EXE "rocm_smi_ex")

Expand Down
56 changes: 53 additions & 3 deletions src/rocm_smi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@
#include <cstdint>
#include <unordered_map>
#include <map>
#include <fstream>
#include <iostream>

#include "rocm_smi/rocm_smi.h"
#include "rocm_smi/rocm_smi_main.h"
#include "rocm_smi/rocm_smi_device.h"
#include "rocm_smi/rocm_smi_utils.h"
#include "rocm_smi/rocm_smi_exception.h"
#include "rocm_smi/rocm_smi_dev_names.h"

#include "rocm_smi/rocm_smi64Config.h"

Expand Down Expand Up @@ -949,7 +950,56 @@ rsmi_dev_gpu_clk_freq_set(uint32_t dv_ind,

CATCH
}

static std::vector<std::string> pci_name_files = {
"/usr/share/misc/pci.ids",
"/usr/share/hwdata/pci.ids",
"/usr/share/pci.ids",
"/var/lib/pciutils/pci.ids"
};

// Parse pci.ids files. Comment lines have # in first column. Otherwise,
// Syntax:
// vendor vendor_name
// device device_name <-- single tab
// subvendor subdevice subsystem_name <-- two tabs
static std::string get_dev_name_from_id(uint64_t id) {
std::string ln;
std::string token1;
std::string description;

for (auto fl : pci_name_files) {
std::ifstream id_file_strm(fl);

while (std::getline(id_file_strm, ln)) {
std::istringstream ln_str(ln);
// parse line
if (ln_str.peek() == '#') {
continue;
}

if (ln[0] == '\t') {
if (ln[1] == '\t') {
if (ln[2] == '\t') {
// This is a subvendor line
}
} else { // ln[1] != '\t'
// This is a device line
ln_str >> token1;
if (std::stoul(token1, nullptr, 16) == id) {
int64_t pos = ln_str.tellg();

pos = ln.find_first_not_of("\t ", pos);
description = ln.substr(pos);
return description;
}
}
} else { // ln[0] != '\t'
// This is a vendor line
}
}
}
return description;
}
rsmi_status_t
rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len) {
TRY
Expand All @@ -967,7 +1017,7 @@ rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len) {
return ret;
}

val_str = get_dev_id_name_map(id);
val_str = get_dev_name_from_id(id);

if (val_str.size() == 0) {
ret = get_dev_mon_value_str(amd::smi::kMonName, dv_ind, -1, &val_str);
Expand Down

0 comments on commit 9144cad

Please sign in to comment.