mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-28 08:37:12 +08:00
Query free memory info inside zesMemoryGetState API
Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
571007cfe9
commit
ea6e2982fb
@@ -13,23 +13,10 @@
|
||||
|
||||
namespace L0 {
|
||||
|
||||
void LinuxMemoryImp::init() {
|
||||
auto memoryInfo = static_cast<NEO::MemoryInfoImpl *>(pDrm->getMemoryInfo());
|
||||
if (!memoryInfo) {
|
||||
return;
|
||||
}
|
||||
for (auto region : memoryInfo->regions) {
|
||||
if (region.region.memory_class == I915_MEMORY_CLASS_DEVICE) {
|
||||
deviceRegions.push_back(region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
|
||||
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
pDrm = &pLinuxSysmanImp->getDrm();
|
||||
pDevice = pLinuxSysmanImp->getDeviceHandle();
|
||||
init();
|
||||
}
|
||||
|
||||
bool LinuxMemoryImp::isMemoryModuleSupported() {
|
||||
@@ -53,9 +40,23 @@ ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) {
|
||||
}
|
||||
|
||||
ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
|
||||
pState->health = ZES_MEM_HEALTH_OK;
|
||||
std::vector<drm_i915_memory_region_info> deviceRegions;
|
||||
if (pDrm->queryMemoryInfo() == false) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
auto memoryInfo = static_cast<NEO::MemoryInfoImpl *>(pDrm->getMemoryInfo());
|
||||
if (!memoryInfo) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
for (auto region : memoryInfo->regions) {
|
||||
if (region.region.memory_class == I915_MEMORY_CLASS_DEVICE) {
|
||||
deviceRegions.push_back(region);
|
||||
}
|
||||
}
|
||||
pState->free = deviceRegions[subdeviceId].unallocated_size;
|
||||
pState->size = deviceRegions[subdeviceId].probed_size;
|
||||
pState->health = ZES_MEM_HEALTH_OK;
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,5 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass {
|
||||
private:
|
||||
bool isSubdevice = false;
|
||||
uint32_t subdeviceId = 0;
|
||||
void init();
|
||||
std::vector<drm_i915_memory_region_info> deviceRegions;
|
||||
};
|
||||
} // namespace L0
|
||||
|
||||
@@ -60,6 +60,14 @@ struct Mock<MemoryNeoDrm> : public MemoryNeoDrm {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool queryMemoryInfoMockReturnFalse() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool queryMemoryInfoMockReturnFakeTrue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
MOCK_METHOD(bool, queryMemoryInfo, (), (override));
|
||||
};
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
|
||||
deviceHandles.resize(subDeviceCount, nullptr);
|
||||
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
|
||||
}
|
||||
pDrm->queryMemoryInfo();
|
||||
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
|
||||
}
|
||||
|
||||
@@ -208,6 +207,34 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzetSysmanMemo
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzetSysmanMemoryGetStateAndIfQueryMemoryInfoFailsThenErrorIsReturned) {
|
||||
setLocalSupportedAndReinit(true);
|
||||
|
||||
ON_CALL(*pDrm, queryMemoryInfo())
|
||||
.WillByDefault(::testing::Invoke(pDrm, &Mock<MemoryNeoDrm>::queryMemoryInfoMockReturnFalse));
|
||||
|
||||
auto handles = get_memory_handles(memoryHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_mem_state_t state;
|
||||
EXPECT_EQ(zesMemoryGetState(handle, &state), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzetSysmanMemoryGetStateAndIfQueryMemoryInfoAndIfMemoryInfoIsNotCorrectThenErrorIsReturned) {
|
||||
setLocalSupportedAndReinit(true);
|
||||
|
||||
ON_CALL(*pDrm, queryMemoryInfo())
|
||||
.WillByDefault(::testing::Invoke(pDrm, &Mock<MemoryNeoDrm>::queryMemoryInfoMockReturnFakeTrue));
|
||||
|
||||
auto handles = get_memory_handles(memoryHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_mem_state_t state;
|
||||
EXPECT_EQ(zesMemoryGetState(handle, &state), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzetSysmanMemoryGetBandwidthhenVerifySysmanMemoryGetBandwidthCallReturnUnsupportedFeature) {
|
||||
setLocalSupportedAndReinit(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user