Fix HIP_VISIBLE_DEVICES order (#1184)

* Fix HIP_VISIBLE_DEVICES order

* Fix device IDs mismatch

* Fix review comments- loop order and device range check

* Handle incomplete VISIBLE device env variable

* Revert "Handle incomplete VISIBLE device env variable"


[ROCm/hip commit: 1dcf618d20]
This commit is contained in:
Rahul Garg
2019-07-17 20:18:04 -07:00
committed by Maneesh Gupta
parent 774f778352
commit 7629cdd2cf
+15 -11
View File
@@ -1399,7 +1399,7 @@ void ihipInit() {
// Make sure the hip visible devices are within the deviceCnt range // Make sure the hip visible devices are within the deviceCnt range
for (int i = 0; i < g_hip_visible_devices.size(); i++) { for (int i = 0; i < g_hip_visible_devices.size(); i++) {
if (g_hip_visible_devices[i] >= deviceCnt) { if ((g_hip_visible_devices[i] >= deviceCnt) ||(g_hip_visible_devices[i] < 0)){
// Make sure any DeviceID after invalid DeviceID will be erased. // Make sure any DeviceID after invalid DeviceID will be erased.
g_hip_visible_devices.resize(i); g_hip_visible_devices.resize(i);
break; break;
@@ -1415,17 +1415,21 @@ void ihipInit() {
g_deviceArray = new ihipDevice_t*[deviceCnt]; g_deviceArray = new ihipDevice_t*[deviceCnt];
g_deviceCnt = 0; g_deviceCnt = 0;
for (int i = 0; i < accs.size(); i++) {
// check if the device id is included in the HIP_VISIBLE_DEVICES env variable if(g_visible_device) {
if (!accs[i].get_is_emulated()) { for (int i = 0; i < g_hip_visible_devices.size(); i++) {
if (std::find(g_hip_visible_devices.begin(), g_hip_visible_devices.end(), (i - 1)) == int devIndex = g_hip_visible_devices[i];
g_hip_visible_devices.end() && if (!accs[devIndex+1].get_is_emulated()) {
g_visible_device) { g_deviceArray[g_deviceCnt] = new ihipDevice_t(g_deviceCnt, deviceCnt, accs[devIndex+1]);
// If device is not in visible devices list, ignore g_deviceCnt++;
continue; }
}
}else {
for (int i = 0; i < accs.size(); i++) {
if (!accs[i].get_is_emulated()) {
g_deviceArray[g_deviceCnt] = new ihipDevice_t(g_deviceCnt, deviceCnt, accs[i]);
g_deviceCnt++;
} }
g_deviceArray[g_deviceCnt] = new ihipDevice_t(g_deviceCnt, deviceCnt, accs[i]);
g_deviceCnt++;
} }
} }