diff --git a/level_zero/tools/source/sysman/power/power.cpp b/level_zero/tools/source/sysman/power/power.cpp index 0af2d31892..acc10fbf51 100644 --- a/level_zero/tools/source/sysman/power/power.cpp +++ b/level_zero/tools/source/sysman/power/power.cpp @@ -27,7 +27,12 @@ void PowerHandleContext::createHandle(ze_device_handle_t deviceHandle) { delete pPower; } } -ze_result_t PowerHandleContext::init(std::vector &deviceHandles) { +ze_result_t PowerHandleContext::init(std::vector &deviceHandles, ze_device_handle_t coreDevice) { + // Create Handle for device level power + if (deviceHandles.size() > 1) { + createHandle(coreDevice); + } + for (const auto &deviceHandle : deviceHandles) { createHandle(deviceHandle); } diff --git a/level_zero/tools/source/sysman/power/power.h b/level_zero/tools/source/sysman/power/power.h index b2c724918d..e3083df543 100644 --- a/level_zero/tools/source/sysman/power/power.h +++ b/level_zero/tools/source/sysman/power/power.h @@ -42,7 +42,7 @@ struct PowerHandleContext { PowerHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){}; ~PowerHandleContext(); - ze_result_t init(std::vector &deviceHandles); + ze_result_t init(std::vector &deviceHandles, ze_device_handle_t coreDevice); ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower); OsSysman *pOsSysman = nullptr; diff --git a/level_zero/tools/source/sysman/sysman_imp.cpp b/level_zero/tools/source/sysman/sysman_imp.cpp index 61ab9767d1..26733c6bbd 100644 --- a/level_zero/tools/source/sysman/sysman_imp.cpp +++ b/level_zero/tools/source/sysman/sysman_imp.cpp @@ -81,7 +81,7 @@ ze_result_t SysmanDeviceImp::init() { return result; } if (pPowerHandleContext) { - pPowerHandleContext->init(deviceHandles); + pPowerHandleContext->init(deviceHandles, hCoreDevice); } if (pFrequencyHandleContext) { pFrequencyHandleContext->init(deviceHandles); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h index 0706c85262..81fe32e632 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h @@ -390,7 +390,7 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture { pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt); } - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); } void TearDown() override { if (!sysmanUltsEnable) { @@ -462,7 +462,7 @@ class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture { pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt); } - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); } void TearDown() override { if (!sysmanUltsEnable) { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp index eae26a8b10..0e18b63e94 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp @@ -90,7 +90,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { zes_power_properties_t properties; @@ -114,7 +114,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { zes_power_properties_t properties; @@ -137,7 +137,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { zes_power_properties_t properties; @@ -387,7 +387,7 @@ TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsWhenPowerLimitsAreDisabledWh TEST_F(SysmanDevicePowerFixture, GivenScanDiectoriesFailAndPmtIsNotNullPointerThenPowerModuleIsSupported) { EXPECT_CALL(*pSysfsAccess.get(), scanDirEntries(_, _)) .WillRepeatedly(Return(ZE_RESULT_ERROR_NOT_AVAILABLE)); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; Device::fromHandle(device)->getProperties(&deviceProperties); PublicLinuxPowerImp *pPowerImp = new PublicLinuxPowerImp(pOsSysman, deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, deviceProperties.subdeviceId); @@ -402,7 +402,7 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); uint32_t count = 0; EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, powerHandleComponentCount); @@ -415,7 +415,7 @@ TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerD delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); uint32_t count = 0; EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, powerHandleComponentCount); @@ -432,7 +432,7 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); uint32_t count = 0; EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, powerHandleComponentCount); @@ -451,7 +451,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { @@ -469,7 +469,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto &deviceHandle : deviceHandles) { @@ -505,7 +505,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, nullptr); } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { @@ -521,7 +521,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyThre delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); zes_energy_threshold_t threshold; auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { @@ -536,7 +536,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerEnergyThre delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); double threshold = 0; auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { @@ -551,7 +551,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerLimitsThen delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { zes_power_sustained_limit_t sustained; @@ -568,7 +568,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerLimitsThen delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto handle : handles) { zes_power_sustained_limit_t sustained; @@ -585,7 +585,7 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe delete handle; } pSysmanDeviceImp->pPowerHandleContext->handleList.clear(); - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); auto handles = getPowerHandles(powerHandleComponentCount); for (auto &deviceHandle : deviceHandles) { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/power/windows/test_zes_sysman_power.cpp b/level_zero/tools/test/unit_tests/sources/sysman/power/windows/test_zes_sysman_power.cpp index ca2d0e826c..d73cea0484 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/power/windows/test_zes_sysman_power.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/power/windows/test_zes_sysman_power.cpp @@ -52,7 +52,7 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture { deviceHandles.resize(subDeviceCount, nullptr); Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); } - pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles); + pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle()); } void TearDown() override { if (!sysmanUltsEnable) {