From 286f973d0cb0e2086ce49bbe5f55d283cb66b08c Mon Sep 17 00:00:00 2001 From: Bellekallu Rajkiran Date: Tue, 30 Sep 2025 17:27:06 +0000 Subject: [PATCH] feature(sysman): Add support for Memory properties & state for iGPU's in Linux Related-To: NEO-14198, NEO-15464 Signed-off-by: Bellekallu Rajkiran --- .../api/memory/linux/sysman_os_memory_imp.cpp | 17 +- .../api/memory/linux/sysman_os_memory_imp.h | 5 +- .../sysman_product_helper_hw.inl | 3 +- .../sources/memory/linux/mock_memory.h | 9 +- .../memory/linux/test_sysman_memory.cpp | 43 ++- .../sysman/memory/linux/os_memory_imp.cpp | 71 +++- .../sources/sysman/memory/linux/mock_memory.h | 28 +- .../memory/linux/test_sysman_memory.cpp | 320 ++++++++++-------- .../common/test_macros/test_checks_shared.cpp | 4 + .../common/test_macros/test_checks_shared.h | 11 + 10 files changed, 335 insertions(+), 176 deletions(-) diff --git a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.cpp b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.cpp index f9fb05ef1e..a17c661074 100644 --- a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.cpp +++ b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.cpp @@ -40,7 +40,8 @@ ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { if (pLinuxSysmanImp->getHardwareInfo().capabilityTable.isIntegratedDevice) { const std::string memFreeKey = "MemFree"; const std::string memAvailableKey = "MemAvailable"; - auto memInfoValues = readMemInfoValues(&pLinuxSysmanImp->getFsAccess(), {memFreeKey, memAvailableKey}); + std::unordered_set keys{memFreeKey, memAvailableKey}; + auto memInfoValues = readMemInfoValues(&pLinuxSysmanImp->getFsAccess(), keys); if (memInfoValues.find(memFreeKey) != memInfoValues.end() && memInfoValues.find(memAvailableKey) != memInfoValues.end()) { pState->free = memInfoValues[memFreeKey] * 1024; pState->size = memInfoValues[memAvailableKey] * 1024; @@ -77,25 +78,21 @@ ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { return status; } -std::map LinuxMemoryImp::readMemInfoValues(FsAccessInterface *pFsAccess, const std::vector &keys) { - std::map result = {}; +std::unordered_map LinuxMemoryImp::readMemInfoValues(FsAccessInterface *pFsAccess, const std::unordered_set &keys) { + std::unordered_map result; const std::string memInfoFile = "/proc/meminfo"; - std::vector memInfo{}; + std::vector memInfo; if (pFsAccess->read(memInfoFile, memInfo) == ZE_RESULT_SUCCESS) { for (const auto &line : memInfo) { std::istringstream lineStream(line); - std::string label = ""; - std::string unit = ""; + std::string label, unit; uint64_t value = 0; - lineStream >> label >> value >> unit; - if (!label.empty() && label.back() == ':') { label.pop_back(); } - - if (std::find(keys.begin(), keys.end(), label) != keys.end()) { + if (keys.count(label)) { result[label] = value; if (result.size() == keys.size()) { break; diff --git a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h index 0bc7761bfe..8238a4ef07 100644 --- a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h +++ b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h @@ -10,8 +10,9 @@ #include "level_zero/sysman/source/api/memory/sysman_os_memory.h" -#include #include +#include +#include #include namespace NEO { @@ -31,7 +32,7 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableAndNonMovableClass { ze_result_t getProperties(zes_mem_properties_t *pProperties) override; ze_result_t getBandwidth(zes_mem_bandwidth_t *pBandwidth) override; ze_result_t getState(zes_mem_state_t *pState) override; - static std::map readMemInfoValues(FsAccessInterface *pFsAccess, const std::vector &keys); + static std::unordered_map readMemInfoValues(FsAccessInterface *pFsAccess, const std::unordered_set &keys); bool isMemoryModuleSupported() override; LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId); LinuxMemoryImp() = default; diff --git a/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.inl b/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.inl index 2679f9e27c..1dbfe5ddfa 100644 --- a/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.inl +++ b/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.inl @@ -111,7 +111,8 @@ ze_result_t SysmanProductHelperHw::getMemoryProperties(zes_mem_prope pProperties->type = ZES_MEM_TYPE_FORCE_UINT32; const std::string memTotalKey = "MemTotal"; - auto memInfoValues = LinuxMemoryImp::readMemInfoValues(&pLinuxSysmanImp->getFsAccess(), {memTotalKey}); + std::unordered_set keys{memTotalKey}; + auto memInfoValues = LinuxMemoryImp::readMemInfoValues(&pLinuxSysmanImp->getFsAccess(), keys); if (memInfoValues.find(memTotalKey) != memInfoValues.end()) { pProperties->physicalSize = memInfoValues[memTotalKey] * 1024; } diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h b/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h index 71eb92e438..c7e0cb89fd 100644 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h +++ b/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h @@ -172,14 +172,11 @@ struct MockMemorySysFsAccessInterface : public L0::Sysman::SysFsAccessInterface }; struct MockMemoryFsAccessInterface : public L0::Sysman::FsAccessInterface { - bool mockMemInfoIncorrectValue = false; + std::vector customMemInfo; ze_result_t read(std::string file, std::vector &val) override { if (file == "/proc/meminfo") { - if (mockMemInfoIncorrectValue) { - val.push_back("Buffers: 158772 kB"); - val.push_back("Cached: 11744244 kB"); - val.push_back("SwapCached: 1376 kB"); - val.push_back("Active: 6777644 kB"); + if (!customMemInfo.empty()) { + val = customMemInfo; } else { val.push_back("MemTotal: 16384 kB"); val.push_back("MemFree: 4096 kB"); diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory.cpp b/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory.cpp index 5136b20723..3a92dbc2be 100644 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory.cpp +++ b/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory.cpp @@ -6,6 +6,7 @@ */ #include "shared/test/common/mocks/linux/mock_ioctl_helper.h" +#include "shared/test/common/test_macros/test_checks_shared.h" #include "level_zero/sysman/source/device/sysman_device_imp.h" #include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h" @@ -685,9 +686,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSys } TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndIoctlReturnedErrorThenApiReturnsError) { - if (defaultHwInfo->capabilityTable.isIntegratedDevice) { - GTEST_SKIP() << "This test is not applicable for integrated devices"; - } + REQUIRE_DISCRETE_DEVICE_OR_SKIP(*defaultHwInfo); auto ioctlHelper = static_cast(pDrm->ioctlHelper.get()); ioctlHelper->returnEmptyMemoryInfo = true; ioctlHelper->mockErrorNumber = EBUSY; @@ -705,9 +704,7 @@ TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSysman } TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndDeviceIsNotAvailableThenDeviceLostErrorIsReturned) { - if (defaultHwInfo->capabilityTable.isIntegratedDevice) { - GTEST_SKIP() << "This test is not applicable for integrated devices"; - } + REQUIRE_DISCRETE_DEVICE_OR_SKIP(*defaultHwInfo); auto ioctlHelper = static_cast(pDrm->ioctlHelper.get()); ioctlHelper->returnEmptyMemoryInfo = true; ioctlHelper->mockErrorNumber = ENODEV; @@ -901,10 +898,36 @@ HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMe } TEST_F(SysmanMultiDeviceMemoryFixture, GivenMemFreeAndMemAvailableMissingInMemInfoWhenCallingGetStateThenFreeAndSizeValuesAreZero) { - if (!defaultHwInfo->capabilityTable.isIntegratedDevice) { - GTEST_SKIP() << "This test is only applicable for integrated devices."; - } - pFsAccess->mockMemInfoIncorrectValue = true; + REQUIRE_INTEGRATED_DEVICE_OR_SKIP(*defaultHwInfo); + pFsAccess->customMemInfo = { + "Buffers: 158772 kB", + "Cached: 11744244 kB"}; + auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount()); + zes_mem_state_t state = {}; + ze_result_t result = zesMemoryGetState(handles[0], &state); + + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); + EXPECT_EQ(state.free, 0u); + EXPECT_EQ(state.size, 0u); +} + +TEST_F(SysmanMultiDeviceMemoryFixture, GivenMemInfoWithoutColonSeparatorWhenCallingGetStateThenFreeAndSizeValuesAreZero) { + REQUIRE_INTEGRATED_DEVICE_OR_SKIP(*defaultHwInfo); + pFsAccess->customMemInfo = { + "Buffers 158772 kB", + "Cached 11744244 kB"}; + auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount()); + zes_mem_state_t state = {}; + ze_result_t result = zesMemoryGetState(handles[0], &state); + + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); + EXPECT_EQ(state.free, 0u); + EXPECT_EQ(state.size, 0u); +} + +TEST_F(SysmanMultiDeviceMemoryFixture, GivenMemInfoIsEmptyWhenCallingGetStateThenFreeAndSizeValuesAreZero) { + REQUIRE_INTEGRATED_DEVICE_OR_SKIP(*defaultHwInfo); + pFsAccess->customMemInfo = {""}; auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount()); zes_mem_state_t state = {}; ze_result_t result = zesMemoryGetState(handles[0], &state); diff --git a/level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp b/level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp index 6c4f68b5e7..628258dd64 100644 --- a/level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp +++ b/level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp @@ -9,6 +9,8 @@ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/device/device.h" +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/memory_manager/memory_banks.h" #include "shared/source/os_interface/linux/ioctl_helper.h" @@ -22,6 +24,8 @@ #include "neo_igfxfmid.h" +#include + namespace L0 { const std::string LinuxMemoryImp::deviceMemoryHealth("device_memory_health"); @@ -38,6 +42,31 @@ void LinuxMemoryImp::init() { } } +static std::unordered_map readMemInfoValues(FsAccess &fsAccess, const std::unordered_set &keys) { + std::unordered_map result; + const std::string memInfoFile = "/proc/meminfo"; + std::vector memInfo; + + if (fsAccess.read(memInfoFile, memInfo) == ZE_RESULT_SUCCESS) { + for (const auto &line : memInfo) { + std::istringstream lineStream(line); + std::string label, unit; + uint64_t value = 0; + lineStream >> label >> value >> unit; + if (!label.empty() && label.back() == ':') { + label.pop_back(); + } + if (keys.count(label)) { + result[label] = value; + if (result.size() == keys.size()) { + break; + } + } + } + } + return result; +} + LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) { pLinuxSysmanImp = static_cast(pOsSysman); pDrm = &pLinuxSysmanImp->getDrm(); @@ -48,10 +77,33 @@ LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint3 } bool LinuxMemoryImp::isMemoryModuleSupported() { - return pDevice->getDriverHandle()->getMemoryManager()->isLocalMemorySupported(pDevice->getRootDeviceIndex()); + auto &gfxCoreHelper = pDevice->getNEODevice()->getRootDeviceEnvironment().getHelper(); + auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); + if (hwInfo.capabilityTable.isIntegratedDevice) { + return true; + } + return gfxCoreHelper.getEnableLocalMemory(hwInfo); } ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) { + auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); + pProperties->physicalSize = 0; + if (hwInfo.capabilityTable.isIntegratedDevice) { + const std::string memTotalKey = "MemTotal"; + std::unordered_set keys{memTotalKey}; + auto memInfoValues = readMemInfoValues(pLinuxSysmanImp->getFsAccess(), keys); + if (memInfoValues.find(memTotalKey) != memInfoValues.end()) { + pProperties->physicalSize = memInfoValues[memTotalKey] * 1024; + } + pProperties->type = ZES_MEM_TYPE_DDR; + pProperties->numChannels = -1; + pProperties->location = ZES_MEM_LOC_SYSTEM; + pProperties->onSubdevice = isSubdevice; + pProperties->subdeviceId = subdeviceId; + pProperties->busWidth = -1; + return ZE_RESULT_SUCCESS; + } + pProperties->type = ZES_MEM_TYPE_DDR; pProperties->numChannels = -1; if (pDrm->querySystemInfo()) { @@ -81,7 +133,6 @@ ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) { pProperties->subdeviceId = subdeviceId; pProperties->busWidth = memoryBusWidth; // Hardcode - pProperties->physicalSize = 0; if (isSubdevice) { std::string memval; ze_result_t result = pSysfsAccess->read(physicalSizeFile, memval); @@ -348,6 +399,22 @@ ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) { ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { ze_result_t status = ZE_RESULT_SUCCESS; pState->health = ZES_MEM_HEALTH_UNKNOWN; + auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); + if (hwInfo.capabilityTable.isIntegratedDevice) { + const std::string memFreeKey = "MemFree"; + const std::string memAvailableKey = "MemAvailable"; + std::unordered_set keys{memFreeKey, memAvailableKey}; + auto memInfoValues = readMemInfoValues(pLinuxSysmanImp->getFsAccess(), keys); + if (memInfoValues.find(memFreeKey) != memInfoValues.end() && memInfoValues.find(memAvailableKey) != memInfoValues.end()) { + pState->free = memInfoValues[memFreeKey] * 1024; + pState->size = memInfoValues[memAvailableKey] * 1024; + } else { + pState->free = 0; + pState->size = 0; + status = ZE_RESULT_ERROR_UNKNOWN; + } + return status; + } FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); auto productFamily = SysmanDeviceImp::getProductFamily(pDevice); if ((pFwInterface != nullptr) && (IGFX_PVC == productFamily)) { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h index 8a6d53dc1b..fe3ceb26c5 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h @@ -11,7 +11,6 @@ #include "shared/source/os_interface/linux/memory_info.h" #include "shared/source/os_interface/linux/system_info.h" -#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h" #include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" #include "level_zero/tools/source/sysman/memory/linux/os_memory_imp.h" #include "level_zero/tools/source/sysman/memory/memory_imp.h" @@ -78,6 +77,10 @@ constexpr uint64_t mockDisplayVc1ReadVal = 10u; constexpr uint64_t numberMcChannels = 16; constexpr uint64_t transactionSize = 32; +constexpr uint64_t mockIntegratedDeviceAvailableMemory = 8192 * 1024; +constexpr uint64_t mockIntegratedDeviceFreeMemory = 4096 * 1024; +constexpr uint64_t mockIntegratedDevicePhysicalSize = 16384 * 1024; + namespace L0 { namespace ult { uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e; @@ -201,10 +204,6 @@ struct MockMemorySysfsAccess : public SysfsAccess { } }; -struct MockMemoryManagerSysman : public MemoryManagerMock { - MockMemoryManagerSysman(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast(executionEnvironment)) {} -}; - struct MockMemoryNeoDrm : public Drm { using Drm::ioctlHelper; const int mockFd = 33; @@ -221,6 +220,10 @@ struct MockMemoryNeoDrm : public Drm { return {}; } + void resetSystemInfo() { + systemInfo.reset(nullptr); + } + bool querySystemInfo() override { bool returnValue = true; if (!mockQuerySystemInfoReturnValue.empty()) { @@ -228,6 +231,7 @@ struct MockMemoryNeoDrm : public Drm { if (isRepeated != true) { mockQuerySystemInfoReturnValue.erase(mockQuerySystemInfoReturnValue.begin()); } + resetSystemInfo(); return returnValue; } @@ -469,6 +473,20 @@ struct MockMemoryFsAccess : public FsAccess { return ZE_RESULT_ERROR_NOT_AVAILABLE; } + std::vector customMemInfo; + ze_result_t read(std::string file, std::vector &val) override { + if (file == "/proc/meminfo") { + if (!customMemInfo.empty()) { + val = customMemInfo; + } else { + val.push_back("MemTotal: 16384 kB"); + val.push_back("MemFree: 4096 kB"); + val.push_back("MemAvailable: 8192 kB"); + } + } + return ZE_RESULT_SUCCESS; + } + MockMemoryFsAccess() = default; }; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp index ce0c45f5a6..f875b97fbf 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp @@ -7,6 +7,7 @@ #include "shared/source/os_interface/driver_info.h" #include "shared/test/common/mocks/linux/mock_ioctl_helper.h" +#include "shared/test/common/test_macros/test_checks_shared.h" #include "level_zero/tools/source/sysman/linux/pmt/pmt_xml_offsets.h" #include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h" @@ -56,17 +57,13 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { if (!sysmanUltsEnable) { GTEST_SKIP(); } + debugManager.flags.EnableLocalMemory.set(1); SysmanDeviceFixture::SetUp(); pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess; pSysfsAccess = std::make_unique(); pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get(); - pMemoryManagerOld = device->getDriverHandle()->getMemoryManager(); - pMemoryManager = new MockMemoryManagerSysman(*neoDevice->getExecutionEnvironment()); - pMemoryManager->localMemorySupported[0] = false; - device->getDriverHandle()->setMemoryManager(pMemoryManager); - pDrm = new MockMemoryNeoDrm(const_cast(neoDevice->getRootDeviceEnvironment())); pSysmanDevice = device->getSysmanHandle(); @@ -112,7 +109,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { } pLinuxSysmanImp->releasePmtObject(); pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject = pmtMapOriginal; - device->getDriverHandle()->setMemoryManager(pMemoryManagerOld); pLinuxSysmanImp->pFsAccess = pFsAccessOriginal; pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld; pLinuxSysmanImp->pDrm = pOriginalDrm; @@ -120,15 +116,11 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { delete pDrm; pDrm = nullptr; } - if (pMemoryManager != nullptr) { - delete pMemoryManager; - pMemoryManager = nullptr; - } SysmanDeviceFixture::TearDown(); } void setLocalSupportedAndReinit(bool supported) { - pMemoryManager->localMemorySupported[0] = supported; + debugManager.flags.EnableLocalMemory.set(supported); pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); uint32_t subDeviceCount = 0; @@ -149,9 +141,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); return handles; } - - MockMemoryManagerSysman *pMemoryManager = nullptr; - MemoryManager *pMemoryManagerOld; }; TEST_F(SysmanDeviceMemoryFixture, GivenWhenGettingMemoryPropertiesThenSuccessIsReturned) { @@ -161,16 +150,12 @@ TEST_F(SysmanDeviceMemoryFixture, GivenWhenGettingMemoryPropertiesThenSuccessIsR } TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - setLocalSupportedAndReinit(true); - uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); } TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - setLocalSupportedAndReinit(true); - uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); @@ -181,8 +166,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemor } TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidHandlesIsReturned) { - setLocalSupportedAndReinit(true); - uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); @@ -194,43 +177,43 @@ TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryMo } } -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturned) { - setLocalSupportedAndReinit(false); +TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturnedForDiscretePlatforms) { + if (!defaultHwInfo->capabilityTable.isIntegratedDevice) { + setLocalSupportedAndReinit(false); + } uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(count, 1u); + } else { + EXPECT_EQ(count, 0u); + } } -TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturned) { - setLocalSupportedAndReinit(false); +TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturnedForDiscretePlatforms) { + if (!defaultHwInfo->capabilityTable.isIntegratedDevice) { + setLocalSupportedAndReinit(false); + } uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(count, 1u); + } else { + EXPECT_EQ(count, 0u); + } count = count + 1; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); -} - -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidHandlesAreReturned) { - setLocalSupportedAndReinit(false); - - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); - - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - for (auto handle : handles) { - EXPECT_NE(handle, nullptr); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(count, 1u); + } else { + EXPECT_EQ(count, 0u); } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { - setLocalSupportedAndReinit(true); - +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetPropertiesWithLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { @@ -240,21 +223,28 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo ze_result_t result = zesMemoryGetProperties(handle, &properties); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.location, ZES_MEM_LOC_SYSTEM); + EXPECT_EQ(properties.type, ZES_MEM_TYPE_DDR); + EXPECT_EQ(properties.physicalSize, mockIntegratedDevicePhysicalSize); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.busWidth, -1); + } else { + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM); + EXPECT_EQ(properties.physicalSize, 0u); + EXPECT_EQ(properties.numChannels, numMemoryChannels); + EXPECT_EQ(properties.busWidth, memoryBusWidth); + } EXPECT_FALSE(properties.onSubdevice); EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesAndQuerySystemInfoFailsThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknown) { +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetPropertiesAndQuerySystemInfoFailsThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknownForDiscretePlatforms) { pDrm->mockQuerySystemInfoReturnValue.push_back(false); setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { @@ -264,22 +254,30 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo ze_result_t result = zesMemoryGetProperties(handle, &properties); EXPECT_EQ(result, ZE_RESULT_SUCCESS); + + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.location, ZES_MEM_LOC_SYSTEM); + EXPECT_EQ(properties.physicalSize, mockIntegratedDevicePhysicalSize); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.busWidth, -1); + } else { + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.physicalSize, 0u); + EXPECT_EQ(properties.busWidth, memoryBusWidth); + } EXPECT_EQ(properties.type, ZES_MEM_TYPE_DDR); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_EQ(properties.numChannels, -1); EXPECT_FALSE(properties.onSubdevice); EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.busWidth, memoryBusWidth); } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesAndQuerySystemInfoSucceedsButMemSysInfoIsNullThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknown) { +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetPropertiesAndQuerySystemInfoSucceedsButMemSysInfoIsNullThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknownForDiscretePlatforms) { + pDrm->mockQuerySystemInfoReturnValue.push_back(true); setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { ASSERT_NE(nullptr, handle); zes_mem_properties_t properties; @@ -287,20 +285,26 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo ze_result_t result = zesMemoryGetProperties(handle, &properties); EXPECT_EQ(result, ZE_RESULT_SUCCESS); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.location, ZES_MEM_LOC_SYSTEM); + EXPECT_EQ(properties.physicalSize, mockIntegratedDevicePhysicalSize); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.busWidth, -1); + } else { + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.physicalSize, 0u); + EXPECT_EQ(properties.busWidth, memoryBusWidth); + } EXPECT_EQ(properties.type, ZES_MEM_TYPE_DDR); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_EQ(properties.numChannels, -1); EXPECT_FALSE(properties.onSubdevice); EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.busWidth, memoryBusWidth); } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithHBMLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetPropertiesWithHBMLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2); setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { @@ -310,20 +314,26 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo ze_result_t result = zesMemoryGetProperties(handle, &properties); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.location, ZES_MEM_LOC_SYSTEM); + EXPECT_EQ(properties.physicalSize, mockIntegratedDevicePhysicalSize); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.busWidth, -1); + } else { + EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM); + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_EQ(properties.physicalSize, 0u); + EXPECT_EQ(properties.numChannels, numMemoryChannels); + EXPECT_EQ(properties.busWidth, memoryBusWidth); + } EXPECT_FALSE(properties.onSubdevice); EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLPDDR4LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetPropertiesWithLPDDR4LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::lpddr4); setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { @@ -333,20 +343,26 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo ze_result_t result = zesMemoryGetProperties(handle, &properties); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_LPDDR4); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.location, ZES_MEM_LOC_SYSTEM); + EXPECT_EQ(properties.physicalSize, mockIntegratedDevicePhysicalSize); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.busWidth, -1); + } else { + EXPECT_EQ(properties.type, ZES_MEM_TYPE_LPDDR4); + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_EQ(properties.physicalSize, 0u); + EXPECT_EQ(properties.numChannels, numMemoryChannels); + EXPECT_EQ(properties.busWidth, memoryBusWidth); + } EXPECT_FALSE(properties.onSubdevice); EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLPDDR5LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetPropertiesWithLPDDR5LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::lpddr5); setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { @@ -356,20 +372,26 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo ze_result_t result = zesMemoryGetProperties(handle, &properties); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_LPDDR5); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.location, ZES_MEM_LOC_SYSTEM); + EXPECT_EQ(properties.physicalSize, mockIntegratedDevicePhysicalSize); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.busWidth, -1); + } else { + EXPECT_EQ(properties.type, ZES_MEM_TYPE_LPDDR5); + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_EQ(properties.physicalSize, 0u); + EXPECT_EQ(properties.numChannels, numMemoryChannels); + EXPECT_EQ(properties.busWidth, memoryBusWidth); + } EXPECT_FALSE(properties.onSubdevice); EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithDDRLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetPropertiesWithDDRLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::gddr6); setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { @@ -379,19 +401,24 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo ze_result_t result = zesMemoryGetProperties(handle, &properties); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_DDR); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + if (defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.location, ZES_MEM_LOC_SYSTEM); + EXPECT_EQ(properties.physicalSize, mockIntegratedDevicePhysicalSize); + EXPECT_EQ(properties.numChannels, -1); + EXPECT_EQ(properties.busWidth, -1); + } else { + EXPECT_EQ(properties.type, ZES_MEM_TYPE_DDR); + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_EQ(properties.physicalSize, 0u); + EXPECT_EQ(properties.numChannels, numMemoryChannels); + EXPECT_EQ(properties.busWidth, memoryBusWidth); + } EXPECT_FALSE(properties.onSubdevice); EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); } } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { @@ -407,8 +434,8 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryG } } -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - setLocalSupportedAndReinit(true); +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { + REQUIRE_DISCRETE_DEVICE_OR_SKIP(*defaultHwInfo); auto handles = getMemoryHandles(memoryHandleComponentCount); @@ -425,8 +452,8 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanM } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateAndIoctlReturnedErrorThenApiReturnsError) { - setLocalSupportedAndReinit(true); +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndIoctlReturnedErrorThenApiReturnsError) { + REQUIRE_DISCRETE_DEVICE_OR_SKIP(*defaultHwInfo); auto ioctlHelper = static_cast(pDrm->ioctlHelper.get()); ioctlHelper->returnEmptyMemoryInfo = true; @@ -443,8 +470,8 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateAndDeviceIsNotAvailableThenDeviceLostErrorIsReturned) { - setLocalSupportedAndReinit(true); +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndDeviceIsNotAvailableThenDeviceLostErrorIsReturned) { + REQUIRE_DISCRETE_DEVICE_OR_SKIP(*defaultHwInfo); auto ioctlHelper = static_cast(pDrm->ioctlHelper.get()); ioctlHelper->returnEmptyMemoryInfo = true; @@ -464,7 +491,7 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo } HWTEST2_F(SysmanDeviceMemoryFixture, GivenSysmanResourcesAreReleasedAndReInitializedWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - pMemoryManager->localMemorySupported[0] = true; + debugManager.flags.EnableLocalMemory.set(1); pLinuxSysmanImp->releaseSysmanDeviceResources(); pLinuxSysmanImp->pDrm = pDrm; @@ -503,7 +530,8 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenSysmanResourcesAreReleasedAndReInitial } HWTEST2_F(SysmanDeviceMemoryFixture, GivenSysmanResourcesAreReleasedAndReInitializedWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - pMemoryManager->localMemorySupported[0] = true; + REQUIRE_DISCRETE_DEVICE_OR_SKIP(*defaultHwInfo); + debugManager.flags.EnableLocalMemory.set(1); pLinuxSysmanImp->releaseSysmanDeviceResources(); pLinuxSysmanImp->pDrm = pDrm; @@ -558,7 +586,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemo } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthWhenVFID0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -593,7 +620,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthWhenVFID1IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -628,7 +654,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_READ_LFailsThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -651,7 +676,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_VFIDFailsForOldGuidThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -670,7 +694,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF1_VFIDFailsForOldGuidThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -691,7 +714,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_READ_HFailsThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -716,7 +738,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_WRITE_LFailsThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -743,7 +764,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_WRITE_HFailsThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -772,7 +792,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidUsRevIdForRevisionBWhenCallingzesSysmanMemoryGetBandwidthThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - setLocalSupportedAndReinit(true); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto &handle : handles) { @@ -797,7 +816,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidUsRevIdForRevisionBWhenCallingzes } TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformThenSuccessIsReturnedAndBandwidthIsValid) { - setLocalSupportedAndReinit(true); auto hwInfo = *NEO::defaultHwInfo.get(); hwInfo.platform.eProductFamily = IGFX_DG2; pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); @@ -825,7 +843,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemo } TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForUnknownPlatformThenFailureIsReturned) { - setLocalSupportedAndReinit(true); auto hwInfo = *NEO::defaultHwInfo.get(); hwInfo.platform.eProductFamily = IGFX_UNKNOWN; pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); @@ -839,7 +856,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemo } TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfIdiReadFailsTheFailureIsReturned) { - setLocalSupportedAndReinit(true); auto hwInfo = *NEO::defaultHwInfo.get(); hwInfo.platform.eProductFamily = IGFX_DG2; pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); @@ -859,7 +875,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemo } HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformAndReadingMaxBwFailsThenMaxBwIsReturnedAsZero, IsDG2) { - setLocalSupportedAndReinit(true); auto hwInfo = *NEO::defaultHwInfo.get(); hwInfo.platform.eProductFamily = IGFX_DG2; pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); @@ -879,7 +894,6 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM } TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfIdiWriteFailsTheFailureIsReturned) { - setLocalSupportedAndReinit(true); auto hwInfo = *NEO::defaultHwInfo.get(); hwInfo.platform.eProductFamily = IGFX_DG2; pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); @@ -899,7 +913,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemo } TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfDisplayVc1ReadFailsTheFailureIsReturned) { - setLocalSupportedAndReinit(true); auto hwInfo = *NEO::defaultHwInfo.get(); hwInfo.platform.eProductFamily = IGFX_DG2; pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); @@ -963,7 +976,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIs } TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1AreTrueThenErrorIsReturnedWhileGettingMemoryBandwidth) { - setLocalSupportedAndReinit(true); auto hwInfo = *NEO::defaultHwInfo.get(); hwInfo.platform.eProductFamily = IGFX_PVC; pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); @@ -986,7 +998,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1Are } TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1AreFalseThenErrorIsReturnedWhileGettingMemoryBandwidth) { - setLocalSupportedAndReinit(true); auto hwInfo = *NEO::defaultHwInfo.get(); hwInfo.platform.eProductFamily = IGFX_PVC; pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); @@ -1018,8 +1029,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIs } TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndFwUtilInterfaceIsAbsentThenMemoryHealthWillBeUnknown) { - setLocalSupportedAndReinit(true); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); auto handles = getMemoryHandles(memoryHandleComponentCount); @@ -1038,6 +1047,47 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemo } } +TEST_F(SysmanDeviceMemoryFixture, GivenMemFreeAndMemAvailableMissingInMemInfoWhenCallingGetStateThenFreeAndSizeValuesAreZero) { + REQUIRE_INTEGRATED_DEVICE_OR_SKIP(*defaultHwInfo); + pFsAccess->customMemInfo = { + "Buffers: 158772 kB", + "Cached: 11744244 kB"}; + setLocalSupportedAndReinit(false); + auto handles = getMemoryHandles(memoryHandleComponentCount); + zes_mem_state_t state = {}; + ze_result_t result = zesMemoryGetState(handles[0], &state); + + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); + EXPECT_EQ(state.free, 0u); + EXPECT_EQ(state.size, 0u); +} + +TEST_F(SysmanDeviceMemoryFixture, GivenMemInfoWithoutColonSeparatorWhenCallingGetStateThenFreeAndSizeValuesAreZero) { + REQUIRE_INTEGRATED_DEVICE_OR_SKIP(*defaultHwInfo); + pFsAccess->customMemInfo = { + "Buffers 158772 kB", + "Cached 11744244 kB"}; + auto handles = getMemoryHandles(memoryHandleComponentCount); + zes_mem_state_t state = {}; + ze_result_t result = zesMemoryGetState(handles[0], &state); + + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); + EXPECT_EQ(state.free, 0u); + EXPECT_EQ(state.size, 0u); +} + +TEST_F(SysmanDeviceMemoryFixture, GivenMemInfoIsEmptySeparatorWhenCallingGetStateThenFreeAndSizeValuesAreZero) { + REQUIRE_INTEGRATED_DEVICE_OR_SKIP(*defaultHwInfo); + pFsAccess->customMemInfo = {""}; + auto handles = getMemoryHandles(memoryHandleComponentCount); + zes_mem_state_t state = {}; + ze_result_t result = zesMemoryGetState(handles[0], &state); + + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); + EXPECT_EQ(state.free, 0u); + EXPECT_EQ(state.size, 0u); +} + TEST_F(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { zes_mem_properties_t properties = {}; ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; @@ -1063,17 +1113,13 @@ class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { if (!sysmanUltsEnable) { GTEST_SKIP(); } + debugManager.flags.EnableLocalMemory.set(1); SysmanMultiDeviceFixture::SetUp(); pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess; pSysfsAccess = std::make_unique(); pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get(); - pMemoryManagerOld = device->getDriverHandle()->getMemoryManager(); - pMemoryManager = new MockMemoryManagerSysman(*neoDevice->getExecutionEnvironment()); - pMemoryManager->localMemorySupported[0] = true; - device->getDriverHandle()->setMemoryManager(pMemoryManager); - pDrm = new MockMemoryNeoDrm(const_cast(neoDevice->getRootDeviceEnvironment())); pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); @@ -1099,7 +1145,6 @@ class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { if (!sysmanUltsEnable) { GTEST_SKIP(); } - device->getDriverHandle()->setMemoryManager(pMemoryManagerOld); SysmanMultiDeviceFixture::TearDown(); pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld; pLinuxSysmanImp->pDrm = pOriginalDrm; @@ -1107,14 +1152,10 @@ class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { delete pDrm; pDrm = nullptr; } - if (pMemoryManager != nullptr) { - delete pMemoryManager; - pMemoryManager = nullptr; - } } void setLocalSupportedAndReinit(bool supported) { - pMemoryManager->localMemorySupported[0] = supported; + debugManager.flags.EnableLocalMemory.set(supported); pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); uint32_t subDeviceCount = 0; @@ -1135,12 +1176,9 @@ class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); return handles; } - - MockMemoryManagerSysman *pMemoryManager = nullptr; - MemoryManager *pMemoryManagerOld; }; -TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingMemoryPropertiesWhileCallingGetValErrorThenValidMemoryPropertiesRetrieved) { +TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingMemoryPropertiesWhileCallingGetValErrorThenValidMemoryPropertiesRetrievedForDiscretePlatforms) { pSysfsAccess->mockReadStringValue.push_back("0"); pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); @@ -1154,12 +1192,14 @@ TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingMemoryPr EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); EXPECT_EQ(properties.subdeviceId, deviceProperties.subdeviceId); EXPECT_EQ(properties.onSubdevice, isSubDevice); - EXPECT_EQ(properties.physicalSize, 0u); + if (!defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.physicalSize, 0u); + } delete pLinuxMemoryImp; } } -TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { +TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrievedForDiscretePlatforms) { pSysfsAccess->mockReadStringValue.push_back(mockPhysicalSize.data()); pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); pSysfsAccess->isRepeated = true; @@ -1183,14 +1223,14 @@ TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidDevicePointerWhenGettingMemoryP EXPECT_EQ(zesMemoryGetProperties(handle, &properties), ZE_RESULT_SUCCESS); EXPECT_EQ(properties.subdeviceId, devicesProperties[subDeviceIndex].subdeviceId); EXPECT_TRUE(properties.onSubdevice); - EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.data(), nullptr, 16)); + if (!defaultHwInfo->capabilityTable.isIntegratedDevice) { + EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.data(), nullptr, 16)); + } subDeviceIndex++; } } -HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - setLocalSupportedAndReinit(true); - +HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { auto handles = getMemoryHandles(subDeviceCount); for (auto handle : handles) { @@ -1211,8 +1251,8 @@ HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSy EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour); } -HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - setLocalSupportedAndReinit(true); +HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { + REQUIRE_DISCRETE_DEVICE_OR_SKIP(*defaultHwInfo); auto handles = getMemoryHandles(subDeviceCount); diff --git a/shared/test/common/test_macros/test_checks_shared.cpp b/shared/test/common/test_macros/test_checks_shared.cpp index bb4c14399e..04647660f3 100644 --- a/shared/test/common/test_macros/test_checks_shared.cpp +++ b/shared/test/common/test_macros/test_checks_shared.cpp @@ -49,4 +49,8 @@ bool TestChecks::supportsImages(const HardwareInfo &hardwareInfo) { bool TestChecks::supportsImages(const std::unique_ptr &pHardwareInfo) { return supportsImages(*pHardwareInfo); +} + +bool TestChecks::isIntegrated(const HardwareInfo &hardwareInfo) { + return hardwareInfo.capabilityTable.isIntegratedDevice; } \ No newline at end of file diff --git a/shared/test/common/test_macros/test_checks_shared.h b/shared/test/common/test_macros/test_checks_shared.h index fbf7da727d..775a3f25be 100644 --- a/shared/test/common/test_macros/test_checks_shared.h +++ b/shared/test/common/test_macros/test_checks_shared.h @@ -21,6 +21,7 @@ bool fullySupportsBlitter(const RootDeviceEnvironment &rootDeviceEnvironment); bool allowsDcFlush(const Device *device); bool supportsImages(const HardwareInfo &hardwareInfo); bool supportsImages(const std::unique_ptr &pHardwareInfo); +bool isIntegrated(const HardwareInfo &hardwareInfo); } // namespace TestChecks } // namespace NEO @@ -54,3 +55,13 @@ bool supportsImages(const std::unique_ptr &pHardwareInfo); if (NEO::TestChecks::supportsImages(param) == false) { \ GTEST_SKIP(); \ } + +#define REQUIRE_INTEGRATED_DEVICE_OR_SKIP(hwInfoParam) \ + if (NEO::TestChecks::isIntegrated(hwInfoParam) == false) { \ + GTEST_SKIP(); \ + } + +#define REQUIRE_DISCRETE_DEVICE_OR_SKIP(hwInfoParam) \ + if (NEO::TestChecks::isIntegrated(hwInfoParam) == true) { \ + GTEST_SKIP(); \ + }