Skip to content

Commit 4aef992

Browse files
Jaime ArteagaCompute-Runtime-Automation
Jaime Arteaga
authored andcommitted
Add support for zeDeviceGetP2PProperties
Related-to: LOCI-2784 Signed-off-by: Jaime Arteaga <[email protected]>
1 parent cfc9f38 commit 4aef992

20 files changed

+195
-14
lines changed

level_zero/core/source/device/device_imp.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,17 @@ ze_result_t DeviceImp::getComputeProperties(ze_device_compute_properties_t *pCom
303303

304304
ze_result_t DeviceImp::getP2PProperties(ze_device_handle_t hPeerDevice,
305305
ze_device_p2p_properties_t *pP2PProperties) {
306-
pP2PProperties->flags = 0;
306+
307+
DeviceImp *peerDevice = static_cast<DeviceImp *>(Device::fromHandle(hPeerDevice));
308+
if (this->getNEODevice()->getHardwareInfo().capabilityTable.p2pAccessSupported &&
309+
peerDevice->getNEODevice()->getHardwareInfo().capabilityTable.p2pAccessSupported) {
310+
pP2PProperties->flags = ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS;
311+
if (this->getNEODevice()->getHardwareInfo().capabilityTable.p2pAtomicAccessSupported &&
312+
peerDevice->getNEODevice()->getHardwareInfo().capabilityTable.p2pAtomicAccessSupported) {
313+
pP2PProperties->flags |= ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS;
314+
}
315+
}
316+
307317
return ZE_RESULT_SUCCESS;
308318
}
309319

level_zero/core/test/unit_tests/sources/device/test_device.cpp

+135
Original file line numberDiff line numberDiff line change
@@ -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+
18071942
TEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerReturnsTrue) {
18081943
L0::Device *device0 = driverHandle->devices[0];
18091944
L0::Device *device1 = driverHandle->devices[1];

shared/source/gen11/hw_info_ehl.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 Intel Corporation
2+
* Copyright (C) 2019-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -80,6 +80,8 @@ const RuntimeCapabilityTable EHL::capabilityTable{
8080
false, // levelZeroSupported
8181
true, // isIntegratedDevice
8282
true, // supportsMediaBlock
83+
false, // p2pAccessSupported
84+
false, // p2pAtomicAccessSupported
8385
false // fusedEuEnabled
8486
};
8587

shared/source/gen11/hw_info_icllp.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const RuntimeCapabilityTable ICLLP::capabilityTable{
8181
true, // levelZeroSupported
8282
true, // isIntegratedDevice
8383
true, // supportsMediaBlock
84+
false, // p2pAccessSupported
85+
false, // p2pAtomicAccessSupported
8486
false // fusedEuEnabled
8587
};
8688

shared/source/gen11/hw_info_lkf.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 Intel Corporation
2+
* Copyright (C) 2019-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -80,6 +80,8 @@ const RuntimeCapabilityTable LKF::capabilityTable{
8080
false, // levelZeroSupported
8181
true, // isIntegratedDevice
8282
true, // supportsMediaBlock
83+
false, // p2pAccessSupported
84+
false, // p2pAtomicAccessSupported
8385
false // fusedEuEnabled
8486
};
8587

shared/source/gen12lp/hw_info_adlp.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 Intel Corporation
2+
* Copyright (C) 2021-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -78,6 +78,8 @@ const RuntimeCapabilityTable ADLP::capabilityTable{
7878
true, // levelZeroSupported
7979
true, // isIntegratedDevice
8080
true, // supportsMediaBlock
81+
false, // p2pAccessSupported
82+
false, // p2pAtomicAccessSupported
8183
true // fusedEuEnabled
8284
};
8385

shared/source/gen12lp/hw_info_adls.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -78,6 +78,8 @@ const RuntimeCapabilityTable ADLS::capabilityTable{
7878
true, // levelZeroSupported
7979
true, // isIntegratedDevice
8080
true, // supportsMediaBlock
81+
false, // p2pAccessSupported
82+
false, // p2pAtomicAccessSupported
8183
true // fusedEuEnabled
8284
};
8385

shared/source/gen12lp/hw_info_dg1.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -86,6 +86,8 @@ const RuntimeCapabilityTable DG1::capabilityTable{
8686
true, // levelZeroSupported
8787
false, // isIntegratedDevice
8888
true, // supportsMediaBlock
89+
true, // p2pAccessSupported
90+
false, // p2pAtomicAccessSupported
8991
true // fusedEuEnabled
9092
};
9193

shared/source/gen12lp/hw_info_rkl.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -78,6 +78,8 @@ const RuntimeCapabilityTable RKL::capabilityTable{
7878
true, // levelZeroSupported
7979
true, // isIntegratedDevice
8080
true, // supportsMediaBlock
81+
false, // p2pAccessSupported
82+
false, // p2pAtomicAccessSupported
8183
true // fusedEuEnabled
8284
};
8385

shared/source/gen12lp/hw_info_tgllp.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 Intel Corporation
2+
* Copyright (C) 2019-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -82,6 +82,8 @@ const RuntimeCapabilityTable TGLLP::capabilityTable{
8282
true, // levelZeroSupported
8383
true, // isIntegratedDevice
8484
true, // supportsMediaBlock
85+
false, // p2pAccessSupported
86+
false, // p2pAtomicAccessSupported
8587
true // fusedEuEnabled
8688
};
8789

shared/source/gen8/hw_info_bdw.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -85,6 +85,8 @@ const RuntimeCapabilityTable BDW::capabilityTable{
8585
false, // levelZeroSupported
8686
true, // isIntegratedDevice
8787
true, // supportsMediaBlock
88+
false, // p2pAccessSupported
89+
false, // p2pAtomicAccessSupported
8890
false // fusedEuEnabled
8991
};
9092

shared/source/gen9/hw_info_bxt.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ const RuntimeCapabilityTable BXT::capabilityTable{
8282
false, // levelZeroSupported
8383
true, // isIntegratedDevice
8484
true, // supportsMediaBlock
85+
false, // p2pAccessSupported
86+
false, // p2pAtomicAccessSupported
8587
false // fusedEuEnabled
8688
};
8789

shared/source/gen9/hw_info_cfl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ const RuntimeCapabilityTable CFL::capabilityTable{
7777
true, // levelZeroSupported
7878
true, // isIntegratedDevice
7979
true, // supportsMediaBlock
80+
false, // p2pAccessSupported
81+
false, // p2pAtomicAccessSupported
8082
false // fusedEuEnabled
8183
};
8284

shared/source/gen9/hw_info_glk.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -77,6 +77,8 @@ const RuntimeCapabilityTable GLK::capabilityTable{
7777
false, // levelZeroSupported
7878
true, // isIntegratedDevice
7979
true, // supportsMediaBlock
80+
false, // p2pAccessSupported
81+
false, // p2pAtomicAccessSupported
8082
false // fusedEuEnabled
8183
};
8284

shared/source/gen9/hw_info_kbl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ const RuntimeCapabilityTable KBL::capabilityTable{
7777
true, // levelZeroSupported
7878
true, // isIntegratedDevice
7979
true, // supportsMediaBlock
80+
false, // p2pAccessSupported
81+
false, // p2pAtomicAccessSupported
8082
false // fusedEuEnabled
8183
};
8284

shared/source/gen9/hw_info_skl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const RuntimeCapabilityTable SKL::capabilityTable{
8585
true, // levelZeroSupported
8686
true, // isIntegratedDevice
8787
true, // supportsMediaBlock
88+
false, // p2pAccessSupported
89+
false, // p2pAtomicAccessSupported
8890
false // fusedEuEnabled
8991
};
9092

shared/source/helpers/hw_info.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -65,6 +65,8 @@ struct RuntimeCapabilityTable {
6565
bool levelZeroSupported;
6666
bool isIntegratedDevice;
6767
bool supportsMediaBlock;
68+
bool p2pAccessSupported;
69+
bool p2pAtomicAccessSupported;
6870
bool fusedEuEnabled;
6971
};
7072

shared/source/xe_hp_core/hw_info_xe_hp_sdv.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 Intel Corporation
2+
* Copyright (C) 2021-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -82,6 +82,8 @@ const RuntimeCapabilityTable XE_HP_SDV::capabilityTable{
8282
true, // levelZeroSupported
8383
false, // isIntegratedDevice
8484
true, // supportsMediaBlock
85+
true, // p2pAccessSupported
86+
false, // p2pAtomicAccessSupported
8587
true // fusedEuEnabled
8688
};
8789

shared/source/xe_hpc_core/hw_info_pvc.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 Intel Corporation
2+
* Copyright (C) 2021-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -90,6 +90,8 @@ const RuntimeCapabilityTable PVC::capabilityTable{
9090
true, // levelZeroSupported
9191
false, // isIntegratedDevice
9292
false, // supportsMediaBlock
93+
true, // p2pAccessSupported
94+
true, // p2pAtomicAccessSupported
9395
false // fusedEuEnabled
9496
};
9597

0 commit comments

Comments
 (0)