Skip to content

Commit

Permalink
Add support for zeDeviceGetP2PProperties
Browse files Browse the repository at this point in the history
Related-to: LOCI-2784

Signed-off-by: Jaime Arteaga <[email protected]>
  • Loading branch information
Jaime Arteaga authored and Compute-Runtime-Automation committed Feb 1, 2022
1 parent cfc9f38 commit 4aef992
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 14 deletions.
12 changes: 11 additions & 1 deletion level_zero/core/source/device/device_imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,17 @@ ze_result_t DeviceImp::getComputeProperties(ze_device_compute_properties_t *pCom

ze_result_t DeviceImp::getP2PProperties(ze_device_handle_t hPeerDevice,
ze_device_p2p_properties_t *pP2PProperties) {
pP2PProperties->flags = 0;

DeviceImp *peerDevice = static_cast<DeviceImp *>(Device::fromHandle(hPeerDevice));
if (this->getNEODevice()->getHardwareInfo().capabilityTable.p2pAccessSupported &&
peerDevice->getNEODevice()->getHardwareInfo().capabilityTable.p2pAccessSupported) {
pP2PProperties->flags = ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS;
if (this->getNEODevice()->getHardwareInfo().capabilityTable.p2pAtomicAccessSupported &&
peerDevice->getNEODevice()->getHardwareInfo().capabilityTable.p2pAtomicAccessSupported) {
pP2PProperties->flags |= ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS;
}
}

return ZE_RESULT_SUCCESS;
}

Expand Down
135 changes: 135 additions & 0 deletions level_zero/core/test/unit_tests/sources/device/test_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,141 @@ TEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerSu
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}

template <bool p2pAccessDevice0, bool p2pAtomicAccessDevice0, bool p2pAccessDevice1, bool p2pAtomicAccessDevice1>
struct MultipleDevicesP2PFixture : public ::testing::Test {
void SetUp() override {
NEO::MockCompilerEnableGuard mock(true);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);

std::vector<std::unique_ptr<NEO::Device>> devices;
NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);

NEO::HardwareInfo hardwareInfo = *NEO::defaultHwInfo;

hardwareInfo.capabilityTable.p2pAccessSupported = p2pAccessDevice0;
hardwareInfo.capabilityTable.p2pAtomicAccessSupported = p2pAtomicAccessDevice0;
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&hardwareInfo);

hardwareInfo.capabilityTable.p2pAccessSupported = p2pAccessDevice1;
hardwareInfo.capabilityTable.p2pAtomicAccessSupported = p2pAtomicAccessDevice1;
executionEnvironment->rootDeviceEnvironments[1]->setHwInfo(&hardwareInfo);

memoryManager = new ::testing::NiceMock<MockMemoryManagerMultiDevice>(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);

for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));

context = std::make_unique<ContextImp>(driverHandle.get());
EXPECT_NE(context, nullptr);
for (auto i = 0u; i < numRootDevices; i++) {
auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
}

DebugManagerStateRestore restorer;
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
MockMemoryManagerMultiDevice *memoryManager = nullptr;
std::unique_ptr<UltDeviceFactory> deviceFactory;
std::unique_ptr<ContextImp> context;

const uint32_t numRootDevices = 2u;
const uint32_t numSubDevices = 2u;
};

using MultipleDevicesP2PDevice0Access0Atomic0Device1Access0Atomic0Test = MultipleDevicesP2PFixture<0, 0, 0, 0>;
TEST_F(MultipleDevicesP2PDevice0Access0Atomic0Device1Access0Atomic0Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingNoAccessSupportThenNoSupportIsReturned) {
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];

ze_device_p2p_properties_t p2pProperties = {};
device0->getP2PProperties(device1, &p2pProperties);

EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
}

using MultipleDevicesP2PDevice0Access0Atomic0Device1Access1Atomic0Test = MultipleDevicesP2PFixture<0, 0, 1, 0>;
TEST_F(MultipleDevicesP2PDevice0Access0Atomic0Device1Access1Atomic0Test, WhenCallingGetP2PPropertiesWithOnlyOneDeviceHavingAccessSupportThenNoSupportIsReturned) {
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];

ze_device_p2p_properties_t p2pProperties = {};
device0->getP2PProperties(device1, &p2pProperties);

EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
}

using MultipleDevicesP2PDevice0Access1Atomic0Device1Access0Atomic0Test = MultipleDevicesP2PFixture<1, 0, 0, 0>;
TEST_F(MultipleDevicesP2PDevice0Access1Atomic0Device1Access0Atomic0Test, WhenCallingGetP2PPropertiesWithOnlyFirstDeviceHavingAccessSupportThenNoSupportIsReturned) {
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];

ze_device_p2p_properties_t p2pProperties = {};
device0->getP2PProperties(device1, &p2pProperties);

EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
}

using MultipleDevicesP2PDevice0Access1Atomic0Device1Access1Atomic0Test = MultipleDevicesP2PFixture<1, 0, 1, 0>;
TEST_F(MultipleDevicesP2PDevice0Access1Atomic0Device1Access1Atomic0Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingAccessSupportThenSupportIsReturned) {
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];

ze_device_p2p_properties_t p2pProperties = {};
device0->getP2PProperties(device1, &p2pProperties);

EXPECT_TRUE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
}

using MultipleDevicesP2PDevice0Access1Atomic0Device1Access1Atomic1Test = MultipleDevicesP2PFixture<1, 0, 1, 1>;
TEST_F(MultipleDevicesP2PDevice0Access1Atomic0Device1Access1Atomic1Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingAccessSupportAndOnlyOneWithAtomicThenSupportIsReturnedOnlyForAccess) {
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];

ze_device_p2p_properties_t p2pProperties = {};
device0->getP2PProperties(device1, &p2pProperties);

EXPECT_TRUE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
}

using MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic0Test = MultipleDevicesP2PFixture<1, 1, 1, 0>;
TEST_F(MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic0Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingAccessSupportAndOnlyFirstWithAtomicThenSupportIsReturnedOnlyForAccess) {
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];

ze_device_p2p_properties_t p2pProperties = {};
device0->getP2PProperties(device1, &p2pProperties);

EXPECT_TRUE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
EXPECT_FALSE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
}

using MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic1Test = MultipleDevicesP2PFixture<1, 1, 1, 1>;
TEST_F(MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic1Test, WhenCallingGetP2PPropertiesWithBothDevicesHavingAccessAndAtomicSupportThenSupportIsReturned) {
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];

ze_device_p2p_properties_t p2pProperties = {};
device0->getP2PProperties(device1, &p2pProperties);

EXPECT_TRUE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ACCESS);
EXPECT_TRUE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
}

TEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerReturnsTrue) {
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];
Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen11/hw_info_ehl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -80,6 +80,8 @@ const RuntimeCapabilityTable EHL::capabilityTable{
false, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
2 changes: 2 additions & 0 deletions shared/source/gen11/hw_info_icllp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const RuntimeCapabilityTable ICLLP::capabilityTable{
true, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen11/hw_info_lkf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -80,6 +80,8 @@ const RuntimeCapabilityTable LKF::capabilityTable{
false, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen12lp/hw_info_adlp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -78,6 +78,8 @@ const RuntimeCapabilityTable ADLP::capabilityTable{
true, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
true // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen12lp/hw_info_adls.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -78,6 +78,8 @@ const RuntimeCapabilityTable ADLS::capabilityTable{
true, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
true // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen12lp/hw_info_dg1.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -86,6 +86,8 @@ const RuntimeCapabilityTable DG1::capabilityTable{
true, // levelZeroSupported
false, // isIntegratedDevice
true, // supportsMediaBlock
true, // p2pAccessSupported
false, // p2pAtomicAccessSupported
true // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen12lp/hw_info_rkl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -78,6 +78,8 @@ const RuntimeCapabilityTable RKL::capabilityTable{
true, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
true // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen12lp/hw_info_tgllp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -82,6 +82,8 @@ const RuntimeCapabilityTable TGLLP::capabilityTable{
true, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
true // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen8/hw_info_bdw.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -85,6 +85,8 @@ const RuntimeCapabilityTable BDW::capabilityTable{
false, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
2 changes: 2 additions & 0 deletions shared/source/gen9/hw_info_bxt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const RuntimeCapabilityTable BXT::capabilityTable{
false, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
2 changes: 2 additions & 0 deletions shared/source/gen9/hw_info_cfl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const RuntimeCapabilityTable CFL::capabilityTable{
true, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/gen9/hw_info_glk.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -77,6 +77,8 @@ const RuntimeCapabilityTable GLK::capabilityTable{
false, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
2 changes: 2 additions & 0 deletions shared/source/gen9/hw_info_kbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const RuntimeCapabilityTable KBL::capabilityTable{
true, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
2 changes: 2 additions & 0 deletions shared/source/gen9/hw_info_skl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const RuntimeCapabilityTable SKL::capabilityTable{
true, // levelZeroSupported
true, // isIntegratedDevice
true, // supportsMediaBlock
false, // p2pAccessSupported
false, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/helpers/hw_info.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -65,6 +65,8 @@ struct RuntimeCapabilityTable {
bool levelZeroSupported;
bool isIntegratedDevice;
bool supportsMediaBlock;
bool p2pAccessSupported;
bool p2pAtomicAccessSupported;
bool fusedEuEnabled;
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/xe_hp_core/hw_info_xe_hp_sdv.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -82,6 +82,8 @@ const RuntimeCapabilityTable XE_HP_SDV::capabilityTable{
true, // levelZeroSupported
false, // isIntegratedDevice
true, // supportsMediaBlock
true, // p2pAccessSupported
false, // p2pAtomicAccessSupported
true // fusedEuEnabled
};

Expand Down
4 changes: 3 additions & 1 deletion shared/source/xe_hpc_core/hw_info_pvc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -90,6 +90,8 @@ const RuntimeCapabilityTable PVC::capabilityTable{
true, // levelZeroSupported
false, // isIntegratedDevice
false, // supportsMediaBlock
true, // p2pAccessSupported
true, // p2pAtomicAccessSupported
false // fusedEuEnabled
};

Expand Down
Loading

0 comments on commit 4aef992

Please sign in to comment.