Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/adapters/level_zero/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ struct ur_context_handle_t_ : _ur_object {
l0_command_list_cache_info>>>
ZeCopyCommandListCache;

std::unordered_map<ur_device_handle_t, std::list<ur_device_handle_t>>
P2PDeviceCache;

// Store USM pool for USM shared and device allocations. There is 1 memory
// pool per each pair of (context, device) per each memory type.
std::unordered_map<ze_device_handle_t, umf::pool_unique_handle_t>
Expand Down
29 changes: 20 additions & 9 deletions source/adapters/level_zero/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,26 @@ static ur_result_t USMAllocationMakeResident(
} else {
Devices.push_back(Device);
if (ForceResidency == USMAllocationForceResidencyType::P2PDevices) {
ze_bool_t P2P;
for (const auto &D : Context->Devices) {
if (D == Device)
continue;
// TODO: Cache P2P devices for a context
ZE2UR_CALL(zeDeviceCanAccessPeer,
(D->ZeDevice, Device->ZeDevice, &P2P));
if (P2P)
Devices.push_back(D);
// Check if the P2P devices are already cached
auto it = Context->P2PDeviceCache.find(Device);
if (it != Context->P2PDeviceCache.end()) {
// Use cached P2P devices
Devices.insert(Devices.end(), it->second.begin(), it->second.end());
} else {
// Query for P2P devices and update the cache
std::list<ur_device_handle_t> P2PDevices;
ze_bool_t P2P;
for (const auto &D : Context->Devices) {
if (D == Device)
continue;
ZE2UR_CALL(zeDeviceCanAccessPeer,
(D->ZeDevice, Device->ZeDevice, &P2P));
if (P2P)
P2PDevices.push_back(D);
}
// Update the cache
Context->P2PDeviceCache[Device] = P2PDevices;
Devices.insert(Devices.end(), P2PDevices.begin(), P2PDevices.end());
}
}
}
Expand Down