Update Sysman Memory APIs

This change:

 - Currently for all subdevices in LinuxMemoryImp::getState function,
   free and size values are returned similar values. This change fixes this
   issue and now correct value of size and free memory is returned as
   per subdevice.

Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma
2020-11-18 14:48:58 +05:30
committed by Compute-Runtime-Automation
parent 240563099c
commit 4c55491dc1
4 changed files with 19 additions and 85 deletions

View File

@@ -13,44 +13,31 @@
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() {
return pDevice->getDriverHandle()->getMemoryManager()->isLocalMemorySupported(pDevice->getRootDeviceIndex());
}
static ze_result_t queryMemoryRegions(NEO::Drm *pDrm, drm_i915_memory_region_info &memRegions) {
if (pDrm->queryMemoryInfo() == false) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
auto memoryInfo = static_cast<NEO::MemoryInfoImpl *>(pDrm->getMemoryInfo());
auto regions = std::find_if(memoryInfo->regions.begin(), memoryInfo->regions.end(), [](auto tempRegion) {
return (tempRegion.region.memory_class == I915_MEMORY_CLASS_DEVICE);
});
if (regions == memoryInfo->regions.end()) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
memRegions = *regions;
return ZE_RESULT_SUCCESS;
}
ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) {
drm_i915_memory_region_info memRegions = {};
ze_result_t result = queryMemoryRegions(pDrm, memRegions);
if (result == ZE_RESULT_SUCCESS) {
if (memRegions.region.memory_class == I915_MEMORY_CLASS_DEVICE)
pProperties->location = ZES_MEM_LOC_DEVICE;
} else {
// by default failure case also it will be DEVICE
pProperties->location = ZES_MEM_LOC_DEVICE;
}
pProperties->location = ZES_MEM_LOC_DEVICE;
pProperties->type = ZES_MEM_TYPE_DDR;
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
@@ -66,17 +53,9 @@ ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) {
}
ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
drm_i915_memory_region_info memRegions = {};
ze_result_t result = queryMemoryRegions(pDrm, memRegions);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
pState->health = ZES_MEM_HEALTH_OK;
pState->free = memRegions.unallocated_size;
pState->size = memRegions.probed_size;
pState->free = deviceRegions[subdeviceId].unallocated_size;
pState->size = deviceRegions[subdeviceId].probed_size;
return ZE_RESULT_SUCCESS;
}

View File

@@ -33,5 +33,7 @@ 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

View File

@@ -60,26 +60,6 @@ struct Mock<MemoryNeoDrm> : public MemoryNeoDrm {
return true;
}
bool queryMemoryInfoMockReturnFalse() {
return false;
}
bool queryMemoryInfoMockWithoutDevice() {
drm_i915_memory_region_info regionInfo[3] = {};
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probed_size = 8 * GB;
regionInfo[0].unallocated_size = 6 * GB;
regionInfo[1].region = {I915_MEMORY_CLASS_STOLEN_SYSTEM, 0};
regionInfo[1].probed_size = 16 * GB;
regionInfo[1].unallocated_size = 12 * GB;
regionInfo[2].region = {I915_MEMORY_CLASS_STOLEN_DEVICE, 0};
regionInfo[2].probed_size = 32 * GB;
regionInfo[2].unallocated_size = 25 * GB;
this->memoryInfo.reset(new MemoryInfoImpl(regionInfo, 3));
return true;
}
MOCK_METHOD(bool, queryMemoryInfo, (), (override));
};

View File

@@ -53,6 +53,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
pDrm->queryMemoryInfo();
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
}
@@ -218,34 +219,6 @@ 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, GivenValidMemoryHandleWhenCallingzetSysmanMemoryGetStateAndIfQueryMemoryDidntProvideDeviceMemoryThenErrorIsReturned) {
setLocalSupportedAndReinit(true);
ON_CALL(*pDrm, queryMemoryInfo())
.WillByDefault(::testing::Invoke(pDrm, &Mock<MemoryNeoDrm>::queryMemoryInfoMockWithoutDevice));
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(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) {
zes_mem_properties_t properties = {};
ze_device_properties_t deviceProperties = {};