@@ -746,9 +746,9 @@ ur_platform_handle_t_::getDeviceFromNativeHandle(ze_device_handle_t ZeDevice) {
746746 std::shared_lock<ur_shared_mutex> Lock (URDevicesCacheMutex);
747747 auto it = std::find_if (URDevicesCache.begin (), URDevicesCache.end (),
748748 [&](std::unique_ptr<ur_device_handle_t_> &D) {
749- return D. get () ->ZeDevice == ZeDevice &&
750- (D. get () ->RootDevice == nullptr ||
751- D. get () ->RootDevice ->RootDevice == nullptr );
749+ return D->ZeDevice == ZeDevice &&
750+ (D->RootDevice == nullptr ||
751+ D->RootDevice ->RootDevice == nullptr );
752752 });
753753 if (it != URDevicesCache.end ()) {
754754 return (*it).get ();
@@ -914,6 +914,44 @@ ur_result_t ur_platform_handle_t_::populateDeviceCacheIfNeeded() {
914914 ZeDeviceSynchronizeSupported = Supported;
915915 }
916916
917+ for (auto &dev : URDevicesCache) {
918+ dev->peers = std::vector<ur_device_handle_t_::PeerStatus>(
919+ URDevicesCache.size (), ur_device_handle_t_::PeerStatus::NO_CONNECTION );
920+
921+ for (size_t peerId = 0 ; peerId < URDevicesCache.size (); ++peerId) {
922+ if (peerId == dev->Id .value ())
923+ continue ;
924+
925+ ZeStruct<ze_device_p2p_properties_t > p2pProperties;
926+ ZE2UR_CALL_THROWS (
927+ zeDeviceGetP2PProperties,
928+ (dev->ZeDevice , URDevicesCache[peerId]->ZeDevice , &p2pProperties));
929+ if (!(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS )) {
930+ UR_LOG (INFO ,
931+ " p2p access to memory of dev:{} from dev:{} not possible due to "
932+ " lack of p2p property" ,
933+ peerId, dev->Id .value ());
934+ continue ;
935+ }
936+
937+ ze_bool_t p2p;
938+ ZE2UR_CALL_THROWS (
939+ zeDeviceCanAccessPeer,
940+ (dev->ZeDevice , URDevicesCache[peerId]->ZeDevice , &p2p));
941+ if (!p2p) {
942+ UR_LOG (INFO ,
943+ " p2p access to memory of dev:{} from dev:{} not possible due to "
944+ " no connection" ,
945+ peerId, dev->Id .value ());
946+ continue ;
947+ }
948+
949+ UR_LOG (INFO , " p2p access to memory of dev:{} from dev:{} can be enabled" ,
950+ peerId, dev->Id .value ());
951+ dev->peers [peerId] = ur_device_handle_t_::PeerStatus::DISABLED ;
952+ }
953+ }
954+
917955 return UR_RESULT_SUCCESS ;
918956}
919957
0 commit comments