From 32ccf30c61976849b16313528ba28eff2a1ef273 Mon Sep 17 00:00:00 2001 From: Young Jin Yoon Date: Tue, 21 Dec 2021 08:55:09 +0000 Subject: [PATCH] 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 --- level_zero/api/core/ze_core_loader.cpp | 3 +- level_zero/api/core/ze_device.cpp | 9 +++- level_zero/core/source/device/device.h | 3 +- level_zero/core/source/device/device_imp.cpp | 25 ++++++++- level_zero/core/source/device/device_imp.h | 4 +- .../core/source/driver/driver_handle_imp.h | 5 +- .../core/test/unit_tests/mocks/mock_device.h | 3 +- .../unit_tests/sources/device/test_device.cpp | 51 ++++++++++++++++++- 8 files changed, 94 insertions(+), 9 deletions(-) diff --git a/level_zero/api/core/ze_core_loader.cpp b/level_zero/api/core/ze_core_loader.cpp index 83dccdd003..a9353a1012 100644 --- a/level_zero/api/core/ze_core_loader.cpp +++ b/level_zero/api/core/ze_core_loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -224,6 +224,7 @@ zeGetDeviceProcAddrTable( pDdiTable->pfnGetGlobalTimestamps = zeDeviceGetGlobalTimestamps; pDdiTable->pfnReserveCacheExt = zeDeviceReserveCacheExt; pDdiTable->pfnSetCacheAdviceExt = zeDeviceSetCacheAdviceExt; + pDdiTable->pfnPciGetPropertiesExt = zeDevicePciGetPropertiesExt; driver_ddiTable.core_ddiTable.Device = *pDdiTable; if (driver_ddiTable.enableTracing) { pDdiTable->pfnGet = zeDeviceGet_Tracing; diff --git a/level_zero/api/core/ze_device.cpp b/level_zero/api/core/ze_device.cpp index cfc3476af2..1d1aaaa0d2 100644 --- a/level_zero/api/core/ze_device.cpp +++ b/level_zero/api/core/ze_device.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -139,3 +139,10 @@ zeDeviceSetCacheAdviceExt( ze_cache_ext_region_t cacheRegion) { return L0::Device::fromHandle(hDevice)->setCacheAdvice(ptr, regionSize, cacheRegion); } + +ZE_APIEXPORT ze_result_t ZE_APICALL +zeDevicePciGetPropertiesExt( + ze_device_handle_t hDevice, + ze_pci_ext_properties_t *pPciProperties) { + return L0::Device::fromHandle(hDevice)->getPciProperties(pPciProperties); +} diff --git a/level_zero/core/source/device/device.h b/level_zero/core/source/device/device.h index 7814bd8ee7..56f61c1f51 100644 --- a/level_zero/core/source/device/device.h +++ b/level_zero/core/source/device/device.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -70,6 +70,7 @@ struct Device : _ze_device_handle_t { virtual ze_result_t getP2PProperties(ze_device_handle_t hPeerDevice, ze_device_p2p_properties_t *pP2PProperties) = 0; virtual ze_result_t getKernelProperties(ze_device_module_properties_t *pKernelProperties) = 0; + virtual ze_result_t getPciProperties(ze_pci_ext_properties_t *pPciProperties) = 0; virtual ze_result_t getMemoryProperties(uint32_t *pCount, ze_device_memory_properties_t *pMemProperties) = 0; virtual ze_result_t getMemoryAccessProperties(ze_device_memory_access_properties_t *pMemAccessProperties) = 0; virtual ze_result_t getProperties(ze_device_properties_t *pDeviceProperties) = 0; diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index eb2817c89e..e98d57740d 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -307,6 +307,26 @@ ze_result_t DeviceImp::getP2PProperties(ze_device_handle_t hPeerDevice, return ZE_RESULT_SUCCESS; } +ze_result_t DeviceImp::getPciProperties(ze_pci_ext_properties_t *pPciProperties) { + if (!driverInfo) { + return ZE_RESULT_ERROR_UNINITIALIZED; + } + auto pciBusInfo = driverInfo->getPciBusInfo(); + auto isPciValid = [&](auto pci) -> bool { + return (pci.pciDomain != NEO::PhysicalDevicePciBusInfo::InvalidValue && + pci.pciBus != NEO::PhysicalDevicePciBusInfo::InvalidValue && + pci.pciDevice != NEO::PhysicalDevicePciBusInfo::InvalidValue && + pci.pciFunction != NEO::PhysicalDevicePciBusInfo::InvalidValue); + }; + if (!isPciValid(pciBusInfo)) { + return ZE_RESULT_ERROR_UNINITIALIZED; + } + pPciProperties->address = {pciBusInfo.pciDomain, pciBusInfo.pciBus, + pciBusInfo.pciDevice, pciBusInfo.pciFunction}; + pPciProperties->maxSpeed = {-1, -1, -1}; + return ZE_RESULT_SUCCESS; +} + ze_result_t DeviceImp::getMemoryProperties(uint32_t *pCount, ze_device_memory_properties_t *pMemProperties) { if (*pCount == 0) { *pCount = 1; @@ -787,6 +807,9 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool device->cacheReservation = CacheReservation::create(*device); device->maxNumHwThreads = NEO::HwHelper::getMaxThreadsForVfe(neoDevice->getHardwareInfo()); + auto osInterface = neoDevice->getRootDeviceEnvironment().osInterface.get(); + device->driverInfo.reset(NEO::DriverInfo::create(&neoDevice->getHardwareInfo(), osInterface)); + auto debugSurfaceSize = NEO::SipKernel::maxDbgSurfaceSize; std::vector stateSaveAreaHeader; diff --git a/level_zero/core/source/device/device_imp.h b/level_zero/core/source/device/device_imp.h index 1e3f5eb36e..4aa5355c44 100644 --- a/level_zero/core/source/device/device_imp.h +++ b/level_zero/core/source/device/device_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -45,6 +45,7 @@ struct DeviceImp : public Device { ze_result_t getP2PProperties(ze_device_handle_t hPeerDevice, ze_device_p2p_properties_t *pP2PProperties) override; ze_result_t getKernelProperties(ze_device_module_properties_t *pKernelProperties) override; + ze_result_t getPciProperties(ze_pci_ext_properties_t *pPciProperties) override; ze_result_t getMemoryProperties(uint32_t *pCount, ze_device_memory_properties_t *pMemProperties) override; ze_result_t getMemoryAccessProperties(ze_device_memory_access_properties_t *pMemAccessProperties) override; ze_result_t getProperties(ze_device_properties_t *pDeviceProperties) override; @@ -119,6 +120,7 @@ struct DeviceImp : public Device { NEO::SpinLock peerAllocationsMutex; std::map memAdviseSharedAllocations; std::unique_ptr allocationsForReuse; + std::unique_ptr driverInfo; void createSysmanHandle(bool isSubDevice); protected: diff --git a/level_zero/core/source/driver/driver_handle_imp.h b/level_zero/core/source/driver/driver_handle_imp.h index d43cecf503..3e93bcef38 100644 --- a/level_zero/core/source/driver/driver_handle_imp.h +++ b/level_zero/core/source/driver/driver_handle_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -87,7 +87,8 @@ struct DriverHandleImp : public DriverHandle { {ZE_RELAXED_ALLOCATION_LIMITS_EXP_NAME, ZE_RELAXED_ALLOCATION_LIMITS_EXP_VERSION_CURRENT}, {ZE_MODULE_PROGRAM_EXP_NAME, ZE_MODULE_PROGRAM_EXP_VERSION_CURRENT}, {ZE_KERNEL_SCHEDULING_HINTS_EXP_NAME, ZE_SCHEDULING_HINTS_EXP_VERSION_CURRENT}, - {ZE_GLOBAL_OFFSET_EXP_NAME, ZE_GLOBAL_OFFSET_EXP_VERSION_CURRENT}}; + {ZE_GLOBAL_OFFSET_EXP_NAME, ZE_GLOBAL_OFFSET_EXP_VERSION_CURRENT}, + {ZE_PCI_PROPERTIES_EXT_NAME, ZE_PCI_PROPERTIES_EXT_VERSION_CURRENT}}; uint64_t uuidTimestamp = 0u; diff --git a/level_zero/core/test/unit_tests/mocks/mock_device.h b/level_zero/core/test/unit_tests/mocks/mock_device.h index 6a9191ee8d..2a34ca923d 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_device.h +++ b/level_zero/core/test/unit_tests/mocks/mock_device.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -40,6 +40,7 @@ struct Mock : public Device { ADDMETHOD_NOBASE(getComputeProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_compute_properties_t * pComputeProperties)); ADDMETHOD_NOBASE(getP2PProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_handle_t hPeerDevice, ze_device_p2p_properties_t *pP2PProperties)); ADDMETHOD_NOBASE(getKernelProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_module_properties_t * pKernelProperties)); + ADDMETHOD_NOBASE(getPciProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_pci_ext_properties_t * pPciProperties)); ADDMETHOD_NOBASE(getMemoryProperties, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCount, ze_device_memory_properties_t *pMemProperties)); ADDMETHOD_NOBASE(getMemoryAccessProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_memory_access_properties_t * pMemAccessProperties)); ADDMETHOD_NOBASE(getProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_properties_t * pDeviceProperties)); diff --git a/level_zero/core/test/unit_tests/sources/device/test_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_device.cpp index 28e5c382ea..50126597d5 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_device.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -15,6 +15,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_compilers.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_driver_info.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_sip.h" #include "shared/test/common/mocks/ult_device_factory.h" @@ -947,6 +948,54 @@ TEST_F(DeviceTest, givenCallToDevicePropertiesThenTimestampValidBitsAreCorrectly EXPECT_EQ(32u, deviceProps.kernelTimestampValidBits); } +TEST_F(DeviceTest, givenNullDriverInfowhenPciPropertiesIsCalledThenUninitializedErrorIsReturned) { + auto deviceImp = static_cast(device); + ze_pci_ext_properties_t pciProperties = {}; + + deviceImp->driverInfo.reset(nullptr); + ze_result_t res = device->getPciProperties(&pciProperties); + + EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, res); +} + +TEST_F(DeviceTest, givenValidPciExtPropertiesWhenPciPropertiesIsCalledThenSuccessIsReturned) { + + auto deviceImp = static_cast(device); + const NEO::PhysicalDevicePciBusInfo pciBusInfo(0, 1, 2, 3); + NEO::DriverInfoMock *driverInfo = new DriverInfoMock(); + ze_pci_ext_properties_t pciProperties = {}; + + driverInfo->setPciBusInfo(pciBusInfo); + deviceImp->driverInfo.reset(driverInfo); + ze_result_t res = device->getPciProperties(&pciProperties); + + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_EQ(pciBusInfo.pciDomain, pciProperties.address.domain); + EXPECT_EQ(pciBusInfo.pciBus, pciProperties.address.bus); + EXPECT_EQ(pciBusInfo.pciDevice, pciProperties.address.device); + EXPECT_EQ(pciBusInfo.pciFunction, pciProperties.address.function); +} + +TEST_F(DeviceTest, givenInvalidPciBusInfoWhenPciPropertiesIsCalledThenUninitializedErrorIsReturned) { + constexpr uint32_t INVALID = NEO::PhysicalDevicePciBusInfo::InvalidValue; + auto deviceImp = static_cast(device); + ze_pci_ext_properties_t pciProperties = {}; + std::vector pciBusInfos; + + pciBusInfos.push_back(NEO::PhysicalDevicePciBusInfo(0, 1, 2, INVALID)); + pciBusInfos.push_back(NEO::PhysicalDevicePciBusInfo(0, 1, INVALID, 3)); + pciBusInfos.push_back(NEO::PhysicalDevicePciBusInfo(0, INVALID, 2, 3)); + pciBusInfos.push_back(NEO::PhysicalDevicePciBusInfo(INVALID, 1, 2, 3)); + + for (auto pciBusInfo : pciBusInfos) { + NEO::DriverInfoMock *driverInfo = new DriverInfoMock(); + driverInfo->setPciBusInfo(pciBusInfo); + deviceImp->driverInfo.reset(driverInfo); + + ze_result_t res = device->getPciProperties(&pciProperties); + EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, res); + } +} TEST_F(DeviceTest, whenGetExternalMemoryPropertiesIsCalledThenSuccessIsReturnedAndNoPropertiesAreReturned) { ze_device_external_memory_properties_t externalMemoryProperties;