@@ -1804,6 +1804,141 @@ TEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerSu
18041804 EXPECT_EQ (ZE_RESULT_SUCCESS, res);
18051805}
18061806
1807+ template <bool p2pAccessDevice0, bool p2pAtomicAccessDevice0, bool p2pAccessDevice1, bool p2pAtomicAccessDevice1>
1808+ struct MultipleDevicesP2PFixture : public ::testing::Test {
1809+ void SetUp () override {
1810+ NEO::MockCompilerEnableGuard mock (true );
1811+ VariableBackup<bool > mockDeviceFlagBackup (&MockDevice::createSingleDevice, false );
1812+
1813+ std::vector<std::unique_ptr<NEO::Device>> devices;
1814+ NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment ();
1815+ executionEnvironment->prepareRootDeviceEnvironments (numRootDevices);
1816+
1817+ NEO::HardwareInfo hardwareInfo = *NEO::defaultHwInfo;
1818+
1819+ hardwareInfo.capabilityTable .p2pAccessSupported = p2pAccessDevice0;
1820+ hardwareInfo.capabilityTable .p2pAtomicAccessSupported = p2pAtomicAccessDevice0;
1821+ executionEnvironment->rootDeviceEnvironments [0 ]->setHwInfo (&hardwareInfo);
1822+
1823+ hardwareInfo.capabilityTable .p2pAccessSupported = p2pAccessDevice1;
1824+ hardwareInfo.capabilityTable .p2pAtomicAccessSupported = p2pAtomicAccessDevice1;
1825+ executionEnvironment->rootDeviceEnvironments [1 ]->setHwInfo (&hardwareInfo);
1826+
1827+ memoryManager = new ::testing::NiceMock<MockMemoryManagerMultiDevice>(*executionEnvironment);
1828+ executionEnvironment->memoryManager .reset (memoryManager);
1829+ deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
1830+
1831+ for (auto i = 0u ; i < executionEnvironment->rootDeviceEnvironments .size (); i++) {
1832+ devices.push_back (std::unique_ptr<NEO::Device>(deviceFactory->rootDevices [i]));
1833+ }
1834+ driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
1835+ driverHandle->initialize (std::move (devices));
1836+
1837+ context = std::make_unique<ContextImp>(driverHandle.get ());
1838+ EXPECT_NE (context, nullptr );
1839+ for (auto i = 0u ; i < numRootDevices; i++) {
1840+ auto device = driverHandle->devices [i];
1841+ context->getDevices ().insert (std::make_pair (device->toHandle (), device));
1842+ auto neoDevice = device->getNEODevice ();
1843+ context->rootDeviceIndices .insert (neoDevice->getRootDeviceIndex ());
1844+ context->deviceBitfields .insert ({neoDevice->getRootDeviceIndex (), neoDevice->getDeviceBitfield ()});
1845+ }
1846+ }
1847+
1848+ DebugManagerStateRestore restorer;
1849+ std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
1850+ MockMemoryManagerMultiDevice *memoryManager = nullptr ;
1851+ std::unique_ptr<UltDeviceFactory> deviceFactory;
1852+ std::unique_ptr<ContextImp> context;
1853+
1854+ const uint32_t numRootDevices = 2u ;
1855+ const uint32_t numSubDevices = 2u ;
1856+ };
1857+
1858+ using MultipleDevicesP2PDevice0Access0Atomic0Device1Access0Atomic0Test = MultipleDevicesP2PFixture<0 , 0 , 0 , 0 >;
1859+ TEST_F (MultipleDevicesP2PDevice0Access0Atomic0Device1Access0Atomic0Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingNoAccessSupportThenNoSupportIsReturned) {
1860+ L0::Device *device0 = driverHandle->devices [0 ];
1861+ L0::Device *device1 = driverHandle->devices [1 ];
1862+
1863+ ze_device_p2p_properties_t p2pProperties = {};
1864+ device0->getP2PProperties (device1, &p2pProperties);
1865+
1866+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
1867+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
1868+ }
1869+
1870+ using MultipleDevicesP2PDevice0Access0Atomic0Device1Access1Atomic0Test = MultipleDevicesP2PFixture<0 , 0 , 1 , 0 >;
1871+ TEST_F (MultipleDevicesP2PDevice0Access0Atomic0Device1Access1Atomic0Test, WhenCallingGetP2PPropertiesWithOnlyOneDeviceHavingAccessSupportThenNoSupportIsReturned) {
1872+ L0::Device *device0 = driverHandle->devices [0 ];
1873+ L0::Device *device1 = driverHandle->devices [1 ];
1874+
1875+ ze_device_p2p_properties_t p2pProperties = {};
1876+ device0->getP2PProperties (device1, &p2pProperties);
1877+
1878+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
1879+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
1880+ }
1881+
1882+ using MultipleDevicesP2PDevice0Access1Atomic0Device1Access0Atomic0Test = MultipleDevicesP2PFixture<1 , 0 , 0 , 0 >;
1883+ TEST_F (MultipleDevicesP2PDevice0Access1Atomic0Device1Access0Atomic0Test, WhenCallingGetP2PPropertiesWithOnlyFirstDeviceHavingAccessSupportThenNoSupportIsReturned) {
1884+ L0::Device *device0 = driverHandle->devices [0 ];
1885+ L0::Device *device1 = driverHandle->devices [1 ];
1886+
1887+ ze_device_p2p_properties_t p2pProperties = {};
1888+ device0->getP2PProperties (device1, &p2pProperties);
1889+
1890+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
1891+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
1892+ }
1893+
1894+ using MultipleDevicesP2PDevice0Access1Atomic0Device1Access1Atomic0Test = MultipleDevicesP2PFixture<1 , 0 , 1 , 0 >;
1895+ TEST_F (MultipleDevicesP2PDevice0Access1Atomic0Device1Access1Atomic0Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingAccessSupportThenSupportIsReturned) {
1896+ L0::Device *device0 = driverHandle->devices [0 ];
1897+ L0::Device *device1 = driverHandle->devices [1 ];
1898+
1899+ ze_device_p2p_properties_t p2pProperties = {};
1900+ device0->getP2PProperties (device1, &p2pProperties);
1901+
1902+ EXPECT_TRUE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
1903+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
1904+ }
1905+
1906+ using MultipleDevicesP2PDevice0Access1Atomic0Device1Access1Atomic1Test = MultipleDevicesP2PFixture<1 , 0 , 1 , 1 >;
1907+ TEST_F (MultipleDevicesP2PDevice0Access1Atomic0Device1Access1Atomic1Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingAccessSupportAndOnlyOneWithAtomicThenSupportIsReturnedOnlyForAccess) {
1908+ L0::Device *device0 = driverHandle->devices [0 ];
1909+ L0::Device *device1 = driverHandle->devices [1 ];
1910+
1911+ ze_device_p2p_properties_t p2pProperties = {};
1912+ device0->getP2PProperties (device1, &p2pProperties);
1913+
1914+ EXPECT_TRUE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
1915+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
1916+ }
1917+
1918+ using MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic0Test = MultipleDevicesP2PFixture<1 , 1 , 1 , 0 >;
1919+ TEST_F (MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic0Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingAccessSupportAndOnlyFirstWithAtomicThenSupportIsReturnedOnlyForAccess) {
1920+ L0::Device *device0 = driverHandle->devices [0 ];
1921+ L0::Device *device1 = driverHandle->devices [1 ];
1922+
1923+ ze_device_p2p_properties_t p2pProperties = {};
1924+ device0->getP2PProperties (device1, &p2pProperties);
1925+
1926+ EXPECT_TRUE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
1927+ EXPECT_FALSE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
1928+ }
1929+
1930+ using MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic1Test = MultipleDevicesP2PFixture<1 , 1 , 1 , 1 >;
1931+ TEST_F (MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic1Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingAccessAndAtomicSupportThenSupportIsReturned) {
1932+ L0::Device *device0 = driverHandle->devices [0 ];
1933+ L0::Device *device1 = driverHandle->devices [1 ];
1934+
1935+ ze_device_p2p_properties_t p2pProperties = {};
1936+ device0->getP2PProperties (device1, &p2pProperties);
1937+
1938+ EXPECT_TRUE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
1939+ EXPECT_TRUE (p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
1940+ }
1941+
18071942TEST_F (MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerReturnsTrue) {
18081943 L0::Device *device0 = driverHandle->devices [0 ];
18091944 L0::Device *device1 = driverHandle->devices [1 ];
0 commit comments