From 9f37923767300e50b24d82c76501de4e747ebd3d Mon Sep 17 00:00:00 2001 From: Divya Shikre Date: Thu, 3 Dec 2020 13:01:15 -0500 Subject: [PATCH] Fix for inconsistent GPU indexing between rocm-smi and rbt/hip. Signed-off-by: Divya Shikre Change-Id: I0d966c91bfe0f0d51859ff098d15011a3e4e8b29 [ROCm/rocm_smi_lib commit: 47ca37aef75ac57ecd1214a8ab6dac7be65302fb] --- projects/rocm-smi-lib/src/rocm_smi_main.cc | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/projects/rocm-smi-lib/src/rocm_smi_main.cc b/projects/rocm-smi-lib/src/rocm_smi_main.cc index 9aa4ced9f5..3822a65f4b 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_main.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_main.cc @@ -461,6 +461,7 @@ static bool isAMDGPU(std::string dev_path) { uint32_t RocmSMI::DiscoverAmdgpuDevices(void) { uint32_t ret = 0; std::string err_msg; + uint32_t count = 0; // If this gets called more than once, clear previous findings. devices_.clear(); @@ -486,18 +487,26 @@ uint32_t RocmSMI::DiscoverAmdgpuDevices(void) { while (dentry != nullptr) { if (memcmp(dentry->d_name, kDeviceNamePrefix, strlen(kDeviceNamePrefix)) == 0) { - std::string vend_str_path = kPathDRMRoot; - vend_str_path += "/"; - vend_str_path += dentry->d_name; - - if (isAMDGPU(vend_str_path) || - (init_options_ & RSMI_INIT_FLAG_ALL_GPUS)) { - AddToDeviceList(dentry->d_name); - } + if ((strcmp(dentry->d_name, ".") == 0) || + (strcmp(dentry->d_name, "..") == 0)) + continue; + count++; } dentry = readdir(drm_dir); } + for (uint32_t node_id = 0; node_id < count; node_id++) { + std::string path = kPathDRMRoot; + path += "/card"; + path += std::to_string(node_id); + if (isAMDGPU(path) || + (init_options_ & RSMI_INIT_FLAG_ALL_GPUS)) { + std::string d_name = "card"; + d_name += std::to_string(node_id); + AddToDeviceList(d_name); + } + } + if (closedir(drm_dir)) { err_msg = "Failed to close drm root directory "; err_msg += kPathDRMRoot;