From 90963b95adb184704206cbd69694115353ce4f98 Mon Sep 17 00:00:00 2001 From: Mayank Raghuwanshi Date: Tue, 11 Jan 2022 11:10:46 +0530 Subject: [PATCH] Update mechanism for getting subdeviceId and onSubdevice for memory Earlier sysman memory module was using logical subdeviceId exposed by core to retrieve memory telmetry data, replace the logical subdeviceId with actual subdeviceId for collecting telemetry data. Related-To: LOCI-2828 Signed-off-by: Mayank Raghuwanshi --- .../tools/source/sysman/linux/pmt/pmt.cpp | 14 ++--- .../tools/source/sysman/memory/memory_imp.cpp | 13 +++-- .../tools/source/sysman/memory/memory_imp.h | 3 +- level_zero/tools/source/sysman/sysman_imp.cpp | 16 +++++- level_zero/tools/source/sysman/sysman_imp.h | 3 +- .../sources/sysman/mocks/CMakeLists.txt | 4 +- .../sysman/mocks/mock_sysman_device_info.h | 53 +++++++++++++++++++ .../sysman/mocks/test_sysman_device_info.cpp | 44 +++++++++++++++ 8 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 level_zero/tools/test/unit_tests/sources/sysman/mocks/mock_sysman_device_info.h create mode 100644 level_zero/tools/test/unit_tests/sources/sysman/mocks/test_sysman_device_info.cpp diff --git a/level_zero/tools/source/sysman/linux/pmt/pmt.cpp b/level_zero/tools/source/sysman/linux/pmt/pmt.cpp index df78afadee..9060048d84 100644 --- a/level_zero/tools/source/sysman/linux/pmt/pmt.cpp +++ b/level_zero/tools/source/sysman/linux/pmt/pmt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Intel Corporation + * Copyright (C) 2021-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,6 +9,8 @@ #include "shared/source/debug_settings/debug_settings_manager.h" +#include "level_zero/tools/source/sysman/sysman_imp.h" + #include #include #include @@ -184,12 +186,12 @@ void PlatformMonitoringTech::create(const std::vector &devic std::map &mapOfSubDeviceIdToPmtObject) { if (ZE_RESULT_SUCCESS == PlatformMonitoringTech::enumerateRootTelemIndex(pFsAccess, rootPciPathOfGpuDevice)) { for (const auto &deviceHandle : deviceHandles) { - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); - auto pPmt = new PlatformMonitoringTech(pFsAccess, deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, - deviceProperties.subdeviceId); + uint32_t subdeviceId = 0; + ze_bool_t onSubdevice = false; + SysmanDeviceImp::getSysmanDeviceInfo(deviceHandle, subdeviceId, onSubdevice); + auto pPmt = new PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId); UNRECOVERABLE_IF(nullptr == pPmt); - PlatformMonitoringTech::doInitPmtObject(pFsAccess, deviceProperties.subdeviceId, pPmt, + PlatformMonitoringTech::doInitPmtObject(pFsAccess, subdeviceId, pPmt, rootPciPathOfGpuDevice, mapOfSubDeviceIdToPmtObject); } } diff --git a/level_zero/tools/source/sysman/memory/memory_imp.cpp b/level_zero/tools/source/sysman/memory/memory_imp.cpp index 45caf93a4b..b8ee68b919 100644 --- a/level_zero/tools/source/sysman/memory/memory_imp.cpp +++ b/level_zero/tools/source/sysman/memory/memory_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #include "level_zero/tools/source/sysman/memory/memory_imp.h" +#include "level_zero/tools/source/sysman/sysman_imp.h" + namespace L0 { ze_result_t MemoryImp::memoryGetBandwidth(zes_mem_bandwidth_t *pBandwidth) { @@ -29,10 +31,11 @@ void MemoryImp::init() { } } -MemoryImp::MemoryImp(OsSysman *pOsSysman, ze_device_handle_t handle) : deviceHandle(handle) { - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); - pOsMemory = OsMemory::create(pOsSysman, deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, deviceProperties.subdeviceId); +MemoryImp::MemoryImp(OsSysman *pOsSysman, ze_device_handle_t handle) { + uint32_t subdeviceId = 0; + ze_bool_t onSubdevice = false; + SysmanDeviceImp::getSysmanDeviceInfo(handle, subdeviceId, onSubdevice); + pOsMemory = OsMemory::create(pOsSysman, onSubdevice, subdeviceId); init(); } diff --git a/level_zero/tools/source/sysman/memory/memory_imp.h b/level_zero/tools/source/sysman/memory/memory_imp.h index 7d2308cb1c..05fd8f8d9a 100644 --- a/level_zero/tools/source/sysman/memory/memory_imp.h +++ b/level_zero/tools/source/sysman/memory/memory_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,7 +29,6 @@ class MemoryImp : public Memory, NEO::NonCopyableOrMovableClass { private: zes_mem_properties_t memoryProperties = {}; - ze_device_handle_t deviceHandle = nullptr; }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/sysman_imp.cpp b/level_zero/tools/source/sysman/sysman_imp.cpp index 7c71c14a63..b33999bb1a 100644 --- a/level_zero/tools/source/sysman/sysman_imp.cpp +++ b/level_zero/tools/source/sysman/sysman_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -72,6 +72,20 @@ void SysmanDeviceImp::updateSubDeviceHandlesLocally() { } } +void SysmanDeviceImp::getSysmanDeviceInfo(zes_device_handle_t hDevice, uint32_t &subdeviceId, ze_bool_t &onSubdevice) { + NEO::Device *neoDevice = Device::fromHandle(hDevice)->getNEODevice(); + onSubdevice = static_cast(false); + if (NEO::HwHelper::getSubDevicesCount(&neoDevice->getHardwareInfo()) > 1) { + onSubdevice = static_cast(true); + } + if (!neoDevice->isSubDevice()) { // To get physical device or subdeviceIndex Index in case when the device does not support tile architecture is single tile device + UNRECOVERABLE_IF(neoDevice->getDeviceBitfield().count() != 1) // or the device is single tile device or AFFINITY_MASK only exposes single tile + subdeviceId = Math::log2(static_cast(neoDevice->getDeviceBitfield().to_ulong())); + } else { + subdeviceId = static_cast(neoDevice)->getSubDeviceIndex(); + } +} + ze_result_t SysmanDeviceImp::init() { // We received a device handle. Check for subdevices in this device updateSubDeviceHandlesLocally(); diff --git a/level_zero/tools/source/sysman/sysman_imp.h b/level_zero/tools/source/sysman/sysman_imp.h index 827f2afc57..e5deb35f49 100644 --- a/level_zero/tools/source/sysman/sysman_imp.h +++ b/level_zero/tools/source/sysman/sysman_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -67,6 +67,7 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass { ze_result_t firmwareGet(uint32_t *pCount, zes_firmware_handle_t *phFirmware) override; ze_result_t deviceEventRegister(zes_event_type_flags_t events) override; bool deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) override; + static void getSysmanDeviceInfo(zes_device_handle_t hDevice, uint32_t &subdeviceId, ze_bool_t &onSubdevice); void updateSubDeviceHandlesLocally(); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/mocks/CMakeLists.txt b/level_zero/tools/test/unit_tests/sources/sysman/mocks/CMakeLists.txt index 3889306068..08263c7706 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/mocks/CMakeLists.txt +++ b/level_zero/tools/test/unit_tests/sources/sysman/mocks/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2021 Intel Corporation +# Copyright (C) 2021-2022 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -8,4 +8,6 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/mock_sysman_env_vars.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_sysman_device_info.h + ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_device_info.cpp ) diff --git a/level_zero/tools/test/unit_tests/sources/sysman/mocks/mock_sysman_device_info.h b/level_zero/tools/test/unit_tests/sources/sysman/mocks/mock_sysman_device_info.h new file mode 100644 index 0000000000..73ad7b3d04 --- /dev/null +++ b/level_zero/tools/test/unit_tests/sources/sysman/mocks/mock_sysman_device_info.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/common/mocks/ult_device_factory.h" +#include "shared/test/common/test_macros/test.h" + +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/tools/source/sysman/sysman_imp.h" + +#include "mock_sysman_env_vars.h" + +using namespace NEO; +using ::testing::_; + +namespace L0 { +namespace ult { + +class SysmanMultiDeviceInfoFixture : public ::testing::Test { + public: + void SetUp() { + if (!sysmanUltsEnable) { + GTEST_SKIP(); + } + hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.gtSystemInfo.MultiTileArchInfo.IsValid = 1; + hwInfo.gtSystemInfo.MultiTileArchInfo.TileCount = numSubDevices; + hwInfo.gtSystemInfo.MultiTileArchInfo.Tile0 = 1; + hwInfo.gtSystemInfo.MultiTileArchInfo.Tile1 = 1; + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(&hwInfo, 0u); + neoDevice = NEO::MockDevice::createWithExecutionEnvironment(&hwInfo, executionEnvironment, 0u); + + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique>(); + driverHandle->initialize(std::move(devices)); + device = driverHandle->devices[0]; + } + void TearDown() {} + NEO::MockDevice *neoDevice = nullptr; + L0::Device *device = nullptr; + std::unique_ptr> driverHandle; + NEO::HardwareInfo hwInfo; + + const uint32_t numRootDevices = 1u; + const uint32_t numSubDevices = 2u; +}; + +} // namespace ult +} // namespace L0 \ No newline at end of file diff --git a/level_zero/tools/test/unit_tests/sources/sysman/mocks/test_sysman_device_info.cpp b/level_zero/tools/test/unit_tests/sources/sysman/mocks/test_sysman_device_info.cpp new file mode 100644 index 0000000000..5c0ad9f3ba --- /dev/null +++ b/level_zero/tools/test/unit_tests/sources/sysman/mocks/test_sysman_device_info.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/tools/test/unit_tests/sources/sysman/mocks/mock_sysman_device_info.h" + +namespace L0 { +namespace ult { + +TEST_F(SysmanMultiDeviceInfoFixture, GivenDeviceWithMultipleTilesWhenOnlyTileOneIsEnabledThenGetSysmanDeviceInfoReturnsExpectedValues) { + neoDevice->deviceBitfield.reset(); + neoDevice->deviceBitfield.set(1); + uint32_t subdeviceId = 0; + ze_bool_t onSubdevice = false; + SysmanDeviceImp::getSysmanDeviceInfo(device->toHandle(), subdeviceId, onSubdevice); + EXPECT_EQ(subdeviceId, 1u); + EXPECT_TRUE(onSubdevice); +} + +TEST_F(SysmanMultiDeviceInfoFixture, GivenDeviceWithMultipleTilesEnabledThenGetSysmanDeviceInfoReturnsExpectedValues) { + uint32_t subDeviceCount = 0; + std::vector deviceHandles; + Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); + if (subDeviceCount == 0) { + deviceHandles.resize(1, device->toHandle()); + } else { + deviceHandles.resize(subDeviceCount, nullptr); + Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); + } + for (auto &device : deviceHandles) { + NEO::Device *neoDevice = Device::fromHandle(device)->getNEODevice(); + uint32_t subdeviceId = 0; + ze_bool_t onSubdevice = false; + SysmanDeviceImp::getSysmanDeviceInfo(device, subdeviceId, onSubdevice); + EXPECT_EQ(subdeviceId, static_cast(neoDevice)->getSubDeviceIndex()); + EXPECT_TRUE(onSubdevice); + } +} + +} // namespace ult +} // namespace L0 \ No newline at end of file