Skip to content

Commit 32ccf30

Browse files
Add support for pci_ext_properties_t
Added API definition in ze_device.cpp, and added function declaration of getPciProperties() in device.h and device_imp.cpp Initially returns -1 for all values of ze_pci_speed_ext_t for now, simply because we do not have function to retrieve the information of the PCI speed. Related-To: LOCI-2669 Signed-off-by: Young Jin Yoon <[email protected]>
1 parent ade43e2 commit 32ccf30

File tree

8 files changed

+94
-9
lines changed

8 files changed

+94
-9
lines changed

level_zero/api/core/ze_core_loader.cpp

Lines changed: 2 additions & 1 deletion
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
*
@@ -224,6 +224,7 @@ zeGetDeviceProcAddrTable(
224224
pDdiTable->pfnGetGlobalTimestamps = zeDeviceGetGlobalTimestamps;
225225
pDdiTable->pfnReserveCacheExt = zeDeviceReserveCacheExt;
226226
pDdiTable->pfnSetCacheAdviceExt = zeDeviceSetCacheAdviceExt;
227+
pDdiTable->pfnPciGetPropertiesExt = zeDevicePciGetPropertiesExt;
227228
driver_ddiTable.core_ddiTable.Device = *pDdiTable;
228229
if (driver_ddiTable.enableTracing) {
229230
pDdiTable->pfnGet = zeDeviceGet_Tracing;

level_zero/api/core/ze_device.cpp

Lines changed: 8 additions & 1 deletion
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
*
@@ -139,3 +139,10 @@ zeDeviceSetCacheAdviceExt(
139139
ze_cache_ext_region_t cacheRegion) {
140140
return L0::Device::fromHandle(hDevice)->setCacheAdvice(ptr, regionSize, cacheRegion);
141141
}
142+
143+
ZE_APIEXPORT ze_result_t ZE_APICALL
144+
zeDevicePciGetPropertiesExt(
145+
ze_device_handle_t hDevice,
146+
ze_pci_ext_properties_t *pPciProperties) {
147+
return L0::Device::fromHandle(hDevice)->getPciProperties(pPciProperties);
148+
}

level_zero/core/source/device/device.h

Lines changed: 2 additions & 1 deletion
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
*
@@ -70,6 +70,7 @@ struct Device : _ze_device_handle_t {
7070
virtual ze_result_t getP2PProperties(ze_device_handle_t hPeerDevice,
7171
ze_device_p2p_properties_t *pP2PProperties) = 0;
7272
virtual ze_result_t getKernelProperties(ze_device_module_properties_t *pKernelProperties) = 0;
73+
virtual ze_result_t getPciProperties(ze_pci_ext_properties_t *pPciProperties) = 0;
7374
virtual ze_result_t getMemoryProperties(uint32_t *pCount, ze_device_memory_properties_t *pMemProperties) = 0;
7475
virtual ze_result_t getMemoryAccessProperties(ze_device_memory_access_properties_t *pMemAccessProperties) = 0;
7576
virtual ze_result_t getProperties(ze_device_properties_t *pDeviceProperties) = 0;

level_zero/core/source/device/device_imp.cpp

Lines changed: 24 additions & 1 deletion
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
*
@@ -307,6 +307,26 @@ ze_result_t DeviceImp::getP2PProperties(ze_device_handle_t hPeerDevice,
307307
return ZE_RESULT_SUCCESS;
308308
}
309309

310+
ze_result_t DeviceImp::getPciProperties(ze_pci_ext_properties_t *pPciProperties) {
311+
if (!driverInfo) {
312+
return ZE_RESULT_ERROR_UNINITIALIZED;
313+
}
314+
auto pciBusInfo = driverInfo->getPciBusInfo();
315+
auto isPciValid = [&](auto pci) -> bool {
316+
return (pci.pciDomain != NEO::PhysicalDevicePciBusInfo::InvalidValue &&
317+
pci.pciBus != NEO::PhysicalDevicePciBusInfo::InvalidValue &&
318+
pci.pciDevice != NEO::PhysicalDevicePciBusInfo::InvalidValue &&
319+
pci.pciFunction != NEO::PhysicalDevicePciBusInfo::InvalidValue);
320+
};
321+
if (!isPciValid(pciBusInfo)) {
322+
return ZE_RESULT_ERROR_UNINITIALIZED;
323+
}
324+
pPciProperties->address = {pciBusInfo.pciDomain, pciBusInfo.pciBus,
325+
pciBusInfo.pciDevice, pciBusInfo.pciFunction};
326+
pPciProperties->maxSpeed = {-1, -1, -1};
327+
return ZE_RESULT_SUCCESS;
328+
}
329+
310330
ze_result_t DeviceImp::getMemoryProperties(uint32_t *pCount, ze_device_memory_properties_t *pMemProperties) {
311331
if (*pCount == 0) {
312332
*pCount = 1;
@@ -787,6 +807,9 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool
787807
device->cacheReservation = CacheReservation::create(*device);
788808
device->maxNumHwThreads = NEO::HwHelper::getMaxThreadsForVfe(neoDevice->getHardwareInfo());
789809

810+
auto osInterface = neoDevice->getRootDeviceEnvironment().osInterface.get();
811+
device->driverInfo.reset(NEO::DriverInfo::create(&neoDevice->getHardwareInfo(), osInterface));
812+
790813
auto debugSurfaceSize = NEO::SipKernel::maxDbgSurfaceSize;
791814
std::vector<char> stateSaveAreaHeader;
792815

level_zero/core/source/device/device_imp.h

Lines changed: 3 additions & 1 deletion
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
*
@@ -45,6 +45,7 @@ struct DeviceImp : public Device {
4545
ze_result_t getP2PProperties(ze_device_handle_t hPeerDevice,
4646
ze_device_p2p_properties_t *pP2PProperties) override;
4747
ze_result_t getKernelProperties(ze_device_module_properties_t *pKernelProperties) override;
48+
ze_result_t getPciProperties(ze_pci_ext_properties_t *pPciProperties) override;
4849
ze_result_t getMemoryProperties(uint32_t *pCount, ze_device_memory_properties_t *pMemProperties) override;
4950
ze_result_t getMemoryAccessProperties(ze_device_memory_access_properties_t *pMemAccessProperties) override;
5051
ze_result_t getProperties(ze_device_properties_t *pDeviceProperties) override;
@@ -119,6 +120,7 @@ struct DeviceImp : public Device {
119120
NEO::SpinLock peerAllocationsMutex;
120121
std::map<NEO::SvmAllocationData *, NEO::MemAdviseFlags> memAdviseSharedAllocations;
121122
std::unique_ptr<NEO::AllocationsList> allocationsForReuse;
123+
std::unique_ptr<NEO::DriverInfo> driverInfo;
122124
void createSysmanHandle(bool isSubDevice);
123125

124126
protected:

level_zero/core/source/driver/driver_handle_imp.h

Lines changed: 3 additions & 2 deletions
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
*
@@ -87,7 +87,8 @@ struct DriverHandleImp : public DriverHandle {
8787
{ZE_RELAXED_ALLOCATION_LIMITS_EXP_NAME, ZE_RELAXED_ALLOCATION_LIMITS_EXP_VERSION_CURRENT},
8888
{ZE_MODULE_PROGRAM_EXP_NAME, ZE_MODULE_PROGRAM_EXP_VERSION_CURRENT},
8989
{ZE_KERNEL_SCHEDULING_HINTS_EXP_NAME, ZE_SCHEDULING_HINTS_EXP_VERSION_CURRENT},
90-
{ZE_GLOBAL_OFFSET_EXP_NAME, ZE_GLOBAL_OFFSET_EXP_VERSION_CURRENT}};
90+
{ZE_GLOBAL_OFFSET_EXP_NAME, ZE_GLOBAL_OFFSET_EXP_VERSION_CURRENT},
91+
{ZE_PCI_PROPERTIES_EXT_NAME, ZE_PCI_PROPERTIES_EXT_VERSION_CURRENT}};
9192

9293
uint64_t uuidTimestamp = 0u;
9394

level_zero/core/test/unit_tests/mocks/mock_device.h

Lines changed: 2 additions & 1 deletion
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
*
@@ -40,6 +40,7 @@ struct Mock<Device> : public Device {
4040
ADDMETHOD_NOBASE(getComputeProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_compute_properties_t * pComputeProperties));
4141
ADDMETHOD_NOBASE(getP2PProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_handle_t hPeerDevice, ze_device_p2p_properties_t *pP2PProperties));
4242
ADDMETHOD_NOBASE(getKernelProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_module_properties_t * pKernelProperties));
43+
ADDMETHOD_NOBASE(getPciProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_pci_ext_properties_t * pPciProperties));
4344
ADDMETHOD_NOBASE(getMemoryProperties, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCount, ze_device_memory_properties_t *pMemProperties));
4445
ADDMETHOD_NOBASE(getMemoryAccessProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_memory_access_properties_t * pMemAccessProperties));
4546
ADDMETHOD_NOBASE(getProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_properties_t * pDeviceProperties));

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

Lines changed: 50 additions & 1 deletion
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
*
@@ -15,6 +15,7 @@
1515
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1616
#include "shared/test/common/mocks/mock_compilers.h"
1717
#include "shared/test/common/mocks/mock_device.h"
18+
#include "shared/test/common/mocks/mock_driver_info.h"
1819
#include "shared/test/common/mocks/mock_memory_manager.h"
1920
#include "shared/test/common/mocks/mock_sip.h"
2021
#include "shared/test/common/mocks/ult_device_factory.h"
@@ -947,6 +948,54 @@ TEST_F(DeviceTest, givenCallToDevicePropertiesThenTimestampValidBitsAreCorrectly
947948
EXPECT_EQ(32u, deviceProps.kernelTimestampValidBits);
948949
}
949950

951+
TEST_F(DeviceTest, givenNullDriverInfowhenPciPropertiesIsCalledThenUninitializedErrorIsReturned) {
952+
auto deviceImp = static_cast<L0::DeviceImp *>(device);
953+
ze_pci_ext_properties_t pciProperties = {};
954+
955+
deviceImp->driverInfo.reset(nullptr);
956+
ze_result_t res = device->getPciProperties(&pciProperties);
957+
958+
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, res);
959+
}
960+
961+
TEST_F(DeviceTest, givenValidPciExtPropertiesWhenPciPropertiesIsCalledThenSuccessIsReturned) {
962+
963+
auto deviceImp = static_cast<L0::DeviceImp *>(device);
964+
const NEO::PhysicalDevicePciBusInfo pciBusInfo(0, 1, 2, 3);
965+
NEO::DriverInfoMock *driverInfo = new DriverInfoMock();
966+
ze_pci_ext_properties_t pciProperties = {};
967+
968+
driverInfo->setPciBusInfo(pciBusInfo);
969+
deviceImp->driverInfo.reset(driverInfo);
970+
ze_result_t res = device->getPciProperties(&pciProperties);
971+
972+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
973+
EXPECT_EQ(pciBusInfo.pciDomain, pciProperties.address.domain);
974+
EXPECT_EQ(pciBusInfo.pciBus, pciProperties.address.bus);
975+
EXPECT_EQ(pciBusInfo.pciDevice, pciProperties.address.device);
976+
EXPECT_EQ(pciBusInfo.pciFunction, pciProperties.address.function);
977+
}
978+
979+
TEST_F(DeviceTest, givenInvalidPciBusInfoWhenPciPropertiesIsCalledThenUninitializedErrorIsReturned) {
980+
constexpr uint32_t INVALID = NEO::PhysicalDevicePciBusInfo::InvalidValue;
981+
auto deviceImp = static_cast<L0::DeviceImp *>(device);
982+
ze_pci_ext_properties_t pciProperties = {};
983+
std::vector<NEO::PhysicalDevicePciBusInfo> pciBusInfos;
984+
985+
pciBusInfos.push_back(NEO::PhysicalDevicePciBusInfo(0, 1, 2, INVALID));
986+
pciBusInfos.push_back(NEO::PhysicalDevicePciBusInfo(0, 1, INVALID, 3));
987+
pciBusInfos.push_back(NEO::PhysicalDevicePciBusInfo(0, INVALID, 2, 3));
988+
pciBusInfos.push_back(NEO::PhysicalDevicePciBusInfo(INVALID, 1, 2, 3));
989+
990+
for (auto pciBusInfo : pciBusInfos) {
991+
NEO::DriverInfoMock *driverInfo = new DriverInfoMock();
992+
driverInfo->setPciBusInfo(pciBusInfo);
993+
deviceImp->driverInfo.reset(driverInfo);
994+
995+
ze_result_t res = device->getPciProperties(&pciProperties);
996+
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, res);
997+
}
998+
}
950999
TEST_F(DeviceTest, whenGetExternalMemoryPropertiesIsCalledThenSuccessIsReturnedAndNoPropertiesAreReturned) {
9511000
ze_device_external_memory_properties_t externalMemoryProperties;
9521001

0 commit comments

Comments
 (0)