From ae4aceb55e18af2bc718be1c15a37053aa9d6eb3 Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Sat, 9 May 2020 05:29:54 -0400 Subject: [PATCH] Make sure the list of HSA agents is valid If HIP_VISIBLE_DEVICES is active, then make sure the list of HSA agents contains the valid agents Change-Id: I584aad999a230ab7f88a0cfe20dcd0abe79c43a5 --- rocclr/device/rocm/rocdevice.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/rocclr/device/rocm/rocdevice.cpp b/rocclr/device/rocm/rocdevice.cpp index 5e50ddc80a..84600fb9a7 100644 --- a/rocclr/device/rocm/rocdevice.cpp +++ b/rocclr/device/rocm/rocdevice.cpp @@ -450,16 +450,12 @@ bool Device::init() { return false; } - std::unordered_map selectedDevices; - bool useDeviceList = false; - std::string ordinals = amd::IS_HIP ? ((HIP_VISIBLE_DEVICES[0] != '\0') ? HIP_VISIBLE_DEVICES : CUDA_VISIBLE_DEVICES) : GPU_DEVICE_ORDINAL; if (ordinals[0] != '\0') { - useDeviceList = true; - size_t end, pos = 0; + std::vector valid_agents; do { bool deviceIdValid = true; end = ordinals.find_first_of(',', pos); @@ -472,14 +468,14 @@ bool Device::init() { // Exit the loop as anything to the right of invalid deviceId // has to be discarded break; + } else { + valid_agents.push_back(gpu_agents_[index]); } - - selectedDevices[index] = deviceIdValid; pos = end + 1; } while (end != std::string::npos); + gpu_agents_ = valid_agents; } - size_t ordinal = 0; for (auto agent : gpu_agents_) { std::unique_ptr roc_device(new Device(agent)); @@ -600,9 +596,7 @@ bool Device::init() { } } - if (!useDeviceList || selectedDevices[ordinal++]) { - roc_device.release()->registerDevice(); - } + roc_device.release()->registerDevice(); } if (0 != Device::numDevices(CL_DEVICE_TYPE_GPU, false)) {