fix: set memoryBanks correctly for single memory bank

Resolves: HSD-18040585222

Signed-off-by: Maciej Bielski <maciej.bielski@intel.com>
This commit is contained in:
Maciej Bielski
2025-01-07 13:49:10 +00:00
committed by Compute-Runtime-Automation
parent f28c45458e
commit ec5477e3ee
2 changed files with 51 additions and 25 deletions

View File

@@ -355,6 +355,7 @@ SubmissionStatus DrmMemoryManager::emitPinningRequestForBoContainer(BufferObject
}
StorageInfo DrmMemoryManager::createStorageInfoFromProperties(const AllocationProperties &properties) {
auto storageInfo{MemoryManager::createStorageInfoFromProperties(properties)};
auto *memoryInfo = getDrm(properties.rootDeviceIndex).getMemoryInfo();
@@ -366,9 +367,17 @@ StorageInfo DrmMemoryManager::createStorageInfoFromProperties(const AllocationPr
DEBUG_BREAK_IF(localMemoryRegions.empty());
DeviceBitfield allMemoryBanks{0b0};
for (auto i = 0u; i < localMemoryRegions.size(); ++i) {
if ((properties.subDevicesBitfield & localMemoryRegions[i].tilesMask).any()) {
allMemoryBanks.set(i);
if (storageInfo.tileInstanced) {
const auto deviceCount = GfxCoreHelper::getSubDevicesCount(executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getHardwareInfo());
const auto subDevicesMask = executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->deviceAffinityMask.getGenericSubDevicesMask().to_ulong();
const DeviceBitfield allTilesValue(properties.subDevicesBitfield.count() == 1 ? maxNBitValue(deviceCount) & subDevicesMask : properties.subDevicesBitfield);
allMemoryBanks = allTilesValue;
} else {
for (auto i = 0u; i < localMemoryRegions.size(); ++i) {
if ((properties.subDevicesBitfield & localMemoryRegions[i].tilesMask).any()) {
allMemoryBanks.set(i);
}
}
}
if (allMemoryBanks.none()) {
@@ -1780,7 +1789,8 @@ void DrmMemoryManager::unlockBufferObject(BufferObject *bo) {
bo->setLockedAddress(nullptr);
}
void createColouredGmms(GmmHelper *gmmHelper, DrmAllocation &allocation, const StorageInfo &storageInfo, bool compression) {
void createColouredGmms(GmmHelper *gmmHelper, DrmAllocation &allocation, bool compression) {
const StorageInfo &storageInfo = allocation.storageInfo;
DEBUG_BREAK_IF(storageInfo.colouringPolicy == ColouringPolicy::deviceCountBased && storageInfo.colouringGranularity != MemoryConstants::pageSize64k);
auto remainingSize = alignUp(allocation.getUnderlyingBufferSize(), storageInfo.colouringGranularity);
@@ -1824,12 +1834,14 @@ void createColouredGmms(GmmHelper *gmmHelper, DrmAllocation &allocation, const S
}
}
void fillGmmsInAllocation(GmmHelper *gmmHelper, DrmAllocation *allocation, const StorageInfo &storageInfo) {
void fillGmmsInAllocation(GmmHelper *gmmHelper, DrmAllocation *allocation) {
auto alignedSize = alignUp(allocation->getUnderlyingBufferSize(), MemoryConstants::pageSize64k);
auto &productHelper = gmmHelper->getRootDeviceEnvironment().getHelper<ProductHelper>();
GmmRequirements gmmRequirements{};
gmmRequirements.allowLargePages = true;
gmmRequirements.preferCompressed = false;
const StorageInfo &storageInfo = allocation->storageInfo;
for (auto handleId = 0u; handleId < storageInfo.getNumBanks(); handleId++) {
StorageInfo limitedStorageInfo = storageInfo;
limitedStorageInfo.memoryBanks &= 1u << handleId;
@@ -1945,18 +1957,16 @@ inline std::unique_ptr<DrmAllocation> DrmMemoryManager::makeDrmAllocation(const
auto allocation = std::make_unique<DrmAllocation>(allocationData.rootDeviceIndex, allocationData.storageInfo.getNumBanks(),
allocationData.type, nullptr, nullptr, gmmHelper->canonize(gpuAddress),
sizeAligned, MemoryPool::localMemory);
allocation->storageInfo = allocationData.storageInfo;
if (createSingleHandle) {
allocation->setDefaultGmm(gmm.release());
} else if (allocationData.storageInfo.multiStorage) {
createColouredGmms(gmmHelper,
*allocation,
allocationData.storageInfo,
allocationData.flags.preferCompressed);
createColouredGmms(gmmHelper, *allocation, allocationData.flags.preferCompressed);
} else {
fillGmmsInAllocation(gmmHelper, allocation.get(), allocationData.storageInfo);
fillGmmsInAllocation(gmmHelper, allocation.get());
}
allocation->storageInfo = allocationData.storageInfo;
allocation->setFlushL3Required(allocationData.flags.flushL3);
allocation->setUncacheable(allocationData.flags.uncacheable);
if (debugManager.flags.EnableHostAllocationMemPolicy.get()) {
@@ -2255,7 +2265,6 @@ bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation,
auto useKmdMigrationForBuffers = (AllocationType::buffer == allocation->getAllocationType() && (debugManager.flags.UseKmdMigrationForBuffers.get() > 0));
auto handles = storageInfo.getNumBanks();
bool useChunking = false;
size_t boTotalChunkSize = 0;
if (checkAllocationForChunking(allocation->getUnderlyingBufferSize(), drm->getMinimalSizeForChunking(),
@@ -2265,21 +2274,19 @@ bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation,
handles = 1;
allocation->resizeBufferObjects(handles);
bos.resize(handles);
useChunking = true;
boTotalChunkSize = allocation->getUnderlyingBufferSize();
} else if (storageInfo.colouringPolicy == ColouringPolicy::chunkSizeBased) {
handles = allocation->getNumGmms();
allocation->resizeBufferObjects(handles);
bos.resize(handles);
}
allocation->setNumHandles(handles);
int32_t pairHandle = -1;
if (useChunking) {
allocation->setNumHandles(handles);
return createDrmChunkedAllocation(drm, allocation, gpuAddress, boTotalChunkSize, maxOsContextCount);
}
if (storageInfo.colouringPolicy == ColouringPolicy::chunkSizeBased) {
handles = allocation->getNumGmms();
allocation->resizeBufferObjects(handles);
bos.resize(handles);
allocation->setNumHandles(handles);
}
int32_t pairHandle = -1;
for (auto handleId = 0u; handleId < handles; handleId++, currentBank++) {
if (currentBank == banksCnt) {
currentBank = 0;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2024 Intel Corporation
* Copyright (C) 2022-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -5512,7 +5512,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenSingleLocalMemoryWhenParticular
EXPECT_EQ(memoryManager->computeStorageInfoMemoryBanksCalled, 2UL);
}
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenSingleLocalMemoryWhenAllSubdevicesIndicatedThenCorrectBankIsSelected) {
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenSingleLocalMemoryAndClonedAllocationTypeWhenAllTilesIndicatedThenCorrectBankIsSelected) {
auto *memoryInfo = static_cast<MockMemoryInfo *>(mock->memoryInfo.get());
auto &localMemoryRegions = memoryInfo->localMemoryRegions;
localMemoryRegions.resize(1U);
@@ -5529,6 +5529,25 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenSingleLocalMemoryWhenAllSubdevi
EXPECT_EQ(memoryManager->computeStorageInfoMemoryBanksCalled, 2UL);
}
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenSingleLocalMemoryAndNonClonedAllocationTypeWhenAllTilesIndicatedThenCorrectBankIsSelected) {
auto *memoryInfo = static_cast<MockMemoryInfo *>(mock->memoryInfo.get());
auto &localMemoryRegions = memoryInfo->localMemoryRegions;
localMemoryRegions.resize(1U);
localMemoryRegions[0].tilesMask = 0b11;
AllocationProperties properties{1, true, 4096, AllocationType::workPartitionSurface, false, {}};
properties.subDevicesBitfield = 0b11;
memoryManager->computeStorageInfoMemoryBanksCalled = 0U;
auto storageInfo = memoryManager->createStorageInfoFromProperties(properties);
constexpr auto defaultMemoryBanks = 0b01;
EXPECT_NE(storageInfo.memoryBanks, defaultMemoryBanks);
EXPECT_EQ(storageInfo.memoryBanks, storageInfo.pageTablesVisibility);
EXPECT_TRUE(storageInfo.tileInstanced);
EXPECT_EQ(memoryManager->computeStorageInfoMemoryBanksCalled, 2UL);
}
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenMultipleLocalMemoryRegionsWhenParticularSubdeviceIndicatedThenItIsSelected) {
auto *memoryInfo = static_cast<MockMemoryInfo *>(mock->memoryInfo.get());
auto &localMemoryRegions = memoryInfo->localMemoryRegions;