From b5799c4dbe60247593226ea3c19a893abc8595f2 Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Thu, 20 Oct 2022 19:00:37 +0000 Subject: [PATCH] SWDEV-363536 - HIP_VISIBLE_DEVICES= should disable the device Setting HIP_VISIBLE_DEVICES= should be treated as invalid device which makes all the devices invisible to the app. This matches the CUDA behavior Change-Id: I937ac4c0b7dacff776cdbe692d4576c81b86ee2d --- rocclr/utils/flags.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rocclr/utils/flags.cpp b/rocclr/utils/flags.cpp index 4606d2c6b4..3897f4d0e4 100644 --- a/rocclr/utils/flags.cpp +++ b/rocclr/utils/flags.cpp @@ -110,12 +110,16 @@ bool Flag::init() { // For all environment variables: std::string var = str; size_t pos = var.find('='); - if ((pos == std::string::npos) || ((pos + 1) >= var.size())) { + if ((pos == std::string::npos) || ((pos + 1) > var.size())) { continue; } std::string name = var.substr(0, pos); - vars.insert(std::make_pair(name, &str[pos + 1])); + if ((pos + 1) == var.size()) { + vars.insert(std::make_pair(name, " ")); + } else { + vars.insert(std::make_pair(name, &str[pos + 1])); + } } #else // !_WIN32 #ifdef __APPLE__ @@ -128,12 +132,16 @@ bool Flag::init() { for (const char** p = const_cast(environ); *p != NULL; ++p) { std::string var = *p; size_t pos = var.find('='); - if ((pos == std::string::npos) || ((pos + 1) >= var.size())) { + if ((pos == std::string::npos) || ((pos + 1) > var.size())) { continue; } std::string name = var.substr(0, pos); - vars.insert(std::make_pair(name, &(*p)[pos + 1])); + if ((pos + 1) == var.size()) { + vars.insert(std::make_pair(name, " ")); + } else { + vars.insert(std::make_pair(name, &(*p)[pos + 1])); + } } #endif // !_WIN32