Skip to content

Commit 7cee465

Browse files
Fixes #447
DPCLTDeviceMgr_GetDevices should not rely of the cached unordered map of root sycl devices to sycl contexts. Because unordered map can change the ordering. Changed implementation to iterate over device::get_devices instead. Confirmation of the fix: ``` In [1]: import dpctl In [2]: d0 = dpctl.SyclDevice("gpu:0") In [3]: d0.filter_string Out[3]: 'opencl:gpu:0' In [4]: [i for i, di in enumerate(dpctl.get_devices(dpctl.backend_type.all, dpctl.device_type.gpu)) if di == d0] Out[4]: [0] In [5]: d0 == dpctl.SyclDevice(d0.filter_string) Out[5]: True In [6]: d1 = dpctl.SyclDevice("gpu:1") In [7]: d1.filter_string Out[7]: 'level_zero:gpu:0' In [8]: [i for i, di in enumerate(dpctl.get_devices(dpctl.backend_type.all, dpctl.device_type.gpu)) if di == d1] Out[8]: [1] In [9]: d1 == dpctl.SyclDevice(d1.filter_string) Out[9]: True ```
1 parent 49373f8 commit 7cee465

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

dpctl-capi/source/dpctl_sycl_device_manager.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,18 @@ DPCTLDeviceMgr_GetDevices(int device_identifier)
146146
} catch (std::bad_alloc const &ba) {
147147
return nullptr;
148148
}
149-
auto &cache = DeviceCacheBuilder::getDeviceCache();
149+
const auto &root_devices = device::get_devices();
150+
default_selector mRanker;
150151

151-
for (const auto &entry : cache) {
152+
for (const auto &root_device : root_devices) {
153+
if (mRanker(root_device) < 0)
154+
continue;
152155
auto Bty(DPCTL_SyclBackendToDPCTLBackendType(
153-
entry.first.get_platform().get_backend()));
156+
root_device.get_platform().get_backend()));
154157
auto Dty(DPCTL_SyclDeviceTypeToDPCTLDeviceType(
155-
entry.first.get_info<info::device::device_type>()));
158+
root_device.get_info<info::device::device_type>()));
156159
if ((device_identifier & Bty) && (device_identifier & Dty)) {
157-
Devices->emplace_back(wrap(new device(entry.first)));
160+
Devices->emplace_back(wrap(new device(root_device)));
158161
}
159162
}
160163
// the wrap function is defined inside dpctl_vector_templ.cpp

0 commit comments

Comments
 (0)