Skip to content

Commit ce37749

Browse files
author
Diptorup Deb
committed
Correct the logic to return device count.
We were not handling the cases where a device identifier does not provide a backend or a device type. Changed the logic to count all devices of a given type if no backend is specified. Similarly, all devices in a backend are counted if no device type is provided.
1 parent 711f868 commit ce37749

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

dpctl-capi/source/dpctl_sycl_device_manager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ size_t DPCTLDeviceMgr_GetNumDevices(int device_identifier)
224224
{
225225
size_t nDevices = 0;
226226
auto &cache = DeviceCacheBuilder::getDeviceCache();
227+
228+
// If the identifier is 0 (UNKNOWN_DEVICE) return 0.
229+
if (!device_identifier)
230+
return 0;
231+
232+
// Check if the device identifier has a backend specified. If not, then
233+
// make sure we match with all backends. The lower 6 bits are for the
234+
// device types, so we blank out those bits to check if any of the
235+
// higher bits reserved for the backend types was non-zero.
236+
if (!((device_identifier & DPCTL_ALL_BACKENDS) >> 6))
237+
device_identifier |= DPCTL_ALL_BACKENDS;
238+
239+
// Check if a device type was specified. If not, set device type to ALL.
240+
if (!(device_identifier & ~DPCTL_ALL_BACKENDS))
241+
device_identifier |= DPCTL_ALL;
242+
227243
for (const auto &entry : cache) {
228244
auto Bty(DPCTL_SyclBackendToDPCTLBackendType(
229245
entry.first.get_platform().get_backend()));

0 commit comments

Comments
 (0)