From a5c2a7ff84a92ec041edb4e329fb15e9cdee9057 Mon Sep 17 00:00:00 2001 From: Sarbojit Sarkar Date: Thu, 13 Aug 2020 13:56:19 -0400 Subject: [PATCH] Fix for HIP_VISIBLE_DEVICE [SWDEV-247751] Change-Id: Iff0ca6646f9d97b1ffa378c3cdc44159b6bf8ad0 [ROCm/clr commit: 8ac8384aea92e8762d0082a780bd8ec0e06d40fa] --- projects/clr/rocclr/device/rocm/rocdevice.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index 8b51d4080d..81a89f49b9 100755 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -455,11 +455,18 @@ bool Device::init() { if (ordinals[0] != '\0') { size_t end, pos = 0; std::vector valid_agents; + std::set valid_indexes; do { bool deviceIdValid = true; end = ordinals.find_first_of(',', pos); - int index = atoi(ordinals.substr(pos, end - pos).c_str()); - if (index < 0 || static_cast(index) >= gpu_agents_.size()) { + if (end == std::string::npos) { + end = ordinals.size(); + } + std::string strIndex = ordinals.substr(pos, end - pos); + int index = atoi(strIndex.c_str()); + if (index < 0 || + static_cast(index) >= gpu_agents_.size() || + strIndex != std::to_string(index)) { deviceIdValid = false; } @@ -468,10 +475,13 @@ bool Device::init() { // has to be discarded break; } else { - valid_agents.push_back(gpu_agents_[index]); + if (valid_indexes.find(index) == valid_indexes.end()) { + valid_agents.push_back(gpu_agents_[index]); + valid_indexes.insert(index); + } } pos = end + 1; - } while (end != std::string::npos); + } while (pos < ordinals.size()); gpu_agents_ = valid_agents; }