Skip to content

Commit 22ee417

Browse files
authored
[SYCL][UR][L0 v2] Remove duplicate devices when creating a context (#19509)
V2 stores device handles in a vector of size `Platform->getNumDevices()`. If there are more devices than that, we may have out-of-range acces.
1 parent 6e6d612 commit 22ee417

File tree

1 file changed

+9
-1
lines changed
  • unified-runtime/source/adapters/level_zero/v2

1 file changed

+9
-1
lines changed

unified-runtime/source/adapters/level_zero/v2/context.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ populateP2PDevices(size_t maxDevices,
4444
return p2pDevices;
4545
}
4646

47+
static std::vector<ur_device_handle_t>
48+
uniqueDevices(uint32_t numDevices, const ur_device_handle_t *phDevices) {
49+
std::vector<ur_device_handle_t> devices(phDevices, phDevices + numDevices);
50+
std::sort(devices.begin(), devices.end());
51+
devices.erase(std::unique(devices.begin(), devices.end()), devices.end());
52+
return devices;
53+
}
54+
4755
ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext,
4856
uint32_t numDevices,
4957
const ur_device_handle_t *phDevices,
5058
bool ownZeContext)
5159
: hContext(hContext, ownZeContext),
52-
hDevices(phDevices, phDevices + numDevices),
60+
hDevices(uniqueDevices(numDevices, phDevices)),
5361
commandListCache(hContext,
5462
{phDevices[0]->Platform->ZeCopyOffloadExtensionSupported,
5563
phDevices[0]->Platform->ZeMutableCmdListExt.Supported}),

0 commit comments

Comments
 (0)