SWDEV-327563 - Win:setenv/unsetenv build failure. develop to staging (#2795)

* SWDEV-327563 - Win:setenv/unsetenv build failure. develop to staging

* SWDEV-327563 - Win:setenv/unsetenv build failure2. develop to staging

* SWDEV-327563 - Win:setenv/unsetenv build failure. develop to staging

Linux build failure
This commit is contained in:
agunashe
2022-07-12 09:24:32 -07:00
committed by GitHub
parent 646eaa43ea
commit 1ffff2acbb
+30 -9
View File
@@ -22,6 +22,27 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <iostream>
#include <stdlib.h>
bool UNSETENV(std::string var) {
int result = -1;
#ifdef __unix__
result = unsetenv(var.c_str());
#else
result = _putenv((var + '=').c_str());
#endif
return (result == 0) ? true: false;
}
bool SETENV(std::string var, std::string value, int overwrite) {
int result = -1;
#ifdef __unix__
result = setenv(var.c_str(), value.c_str(), overwrite);
#else
result = _putenv((var + '=' + value).c_str());
#endif
return (result == 0) ? true: false;
}
// Expects 1 command line arg, which is the Device Visible String
int main(int argc, char** argv) {
@@ -37,18 +58,18 @@ int main(int argc, char** argv) {
// disable visible_devices env from shell
#ifdef __HIP_PLATFORM_NVCC__
unsetenv("CUDA_VISIBLE_DEVICES");
setenv("CUDA_VISIBLE_DEVICES", argv[1], 1);
UNSETENV("CUDA_VISIBLE_DEVICES");
SETENV("CUDA_VISIBLE_DEVICES", argv[1], 1);
auto init_res = hipInit(0);
if (hipSuccess != init_res) {
std::cerr << "CUDA INIT API returned : " << hipGetErrorString(init_res) << std::endl;
return -1;
}
#else
unsetenv("ROCR_VISIBLE_DEVICES");
unsetenv("HIP_VISIBLE_DEVICES");
setenv("ROCR_VISIBLE_DEVICES", argv[1], 1);
setenv("HIP_VISIBLE_DEVICES", argv[1], 1);
UNSETENV("ROCR_VISIBLE_DEVICES");
UNSETENV("HIP_VISIBLE_DEVICES");
SETENV("ROCR_VISIBLE_DEVICES", argv[1], 1);
SETENV("HIP_VISIBLE_DEVICES", argv[1], 1);
#endif
int count = 0;
@@ -59,10 +80,10 @@ int main(int argc, char** argv) {
}
#ifdef __HIP_PLATFORM_NVCC__
unsetenv("CUDA_VISIBLE_DEVICES");
UNSETENV("CUDA_VISIBLE_DEVICES");
#else
unsetenv("ROCR_VISIBLE_DEVICES");
unsetenv("HIP_VISIBLE_DEVICES");
UNSETENV("ROCR_VISIBLE_DEVICES");
UNSETENV("HIP_VISIBLE_DEVICES");
#endif
return count;
}