Skip to content

Commit 7392b5f

Browse files
Add new colouring policy
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent dc9bcb9 commit 7392b5f

File tree

10 files changed

+85
-12
lines changed

10 files changed

+85
-12
lines changed

opencl/test/unit_test/memory_manager/storage_info_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ TEST_F(MultiDeviceStorageInfoTest, whenCreatingStorageInfoForBufferCompressedThe
246246
EXPECT_EQ(allTilesMask, storageInfo.memoryBanks);
247247
EXPECT_EQ(allTilesMask, storageInfo.pageTablesVisibility);
248248
EXPECT_TRUE(storageInfo.multiStorage);
249+
EXPECT_EQ(storageInfo.colouringGranularity, MemoryConstants::pageSize64k);
250+
EXPECT_EQ(storageInfo.colouringPolicy, ColouringPolicy::DeviceCountBased);
249251
}
250252

251253
TEST_F(MultiDeviceStorageInfoTest, whenCreatingStorageInfoForBufferThenAllMemoryBanksAreOnAndPageTableClonningIsRequired) {
@@ -255,6 +257,8 @@ TEST_F(MultiDeviceStorageInfoTest, whenCreatingStorageInfoForBufferThenAllMemory
255257
EXPECT_EQ(allTilesMask, storageInfo.memoryBanks);
256258
EXPECT_EQ(allTilesMask, storageInfo.pageTablesVisibility);
257259
EXPECT_TRUE(storageInfo.multiStorage);
260+
EXPECT_EQ(storageInfo.colouringGranularity, MemoryConstants::pageSize64k);
261+
EXPECT_EQ(storageInfo.colouringPolicy, ColouringPolicy::DeviceCountBased);
258262
}
259263

260264
TEST_F(MultiDeviceStorageInfoTest, whenCreatingStorageInfoForSVMGPUThenAllMemoryBanksAreOnAndPageTableClonningIsRequired) {
@@ -264,6 +268,22 @@ TEST_F(MultiDeviceStorageInfoTest, whenCreatingStorageInfoForSVMGPUThenAllMemory
264268
EXPECT_EQ(allTilesMask, storageInfo.memoryBanks);
265269
EXPECT_EQ(allTilesMask, storageInfo.pageTablesVisibility);
266270
EXPECT_TRUE(storageInfo.multiStorage);
271+
EXPECT_EQ(storageInfo.colouringGranularity, MemoryConstants::pageSize64k);
272+
EXPECT_EQ(storageInfo.colouringPolicy, ColouringPolicy::DeviceCountBased);
273+
}
274+
275+
TEST_F(MultiDeviceStorageInfoTest, givenMultiStorageGranularityWhenCreatingStorageInfoThenProperGranularityIsSet) {
276+
DebugManagerStateRestore restorer;
277+
DebugManager.flags.MultiStorageGranularity.set(128);
278+
279+
AllocationProperties properties{mockRootDeviceIndex, false, 10 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::SVM_GPU, true, allTilesMask};
280+
auto storageInfo = memoryManager->createStorageInfoFromProperties(properties);
281+
EXPECT_TRUE(storageInfo.cloningOfPageTables);
282+
EXPECT_EQ(allTilesMask, storageInfo.memoryBanks);
283+
EXPECT_EQ(allTilesMask, storageInfo.pageTablesVisibility);
284+
EXPECT_TRUE(storageInfo.multiStorage);
285+
EXPECT_EQ(storageInfo.colouringGranularity, MemoryConstants::kiloByte * 128);
286+
EXPECT_EQ(storageInfo.colouringPolicy, ColouringPolicy::ChunkSizeBased);
267287
}
268288

269289
TEST_F(MultiDeviceStorageInfoTest, givenTwoPagesAllocationSizeWhenCreatingStorageInfoForBufferThenSingleMemoryBankIsOnAndPageTableClonningIsRequired) {

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ OverridePreemptionSurfaceSizeInMb = -1
190190
OverrideLeastOccupiedBank = -1
191191
UseAsyncDrmExec = -1
192192
EnableMultiStorageResources = -1
193+
MultiStorageGranularity = -1
193194
PrintExecutionBuffer = 0
194195
PrintBOsForSubmit = 0
195196
EnableCrossDeviceAccess = -1

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, PauseOnEnqueue, -1, "-1: default, -2: always, x:
9494
DECLARE_DEBUG_VARIABLE(int32_t, PauseOnBlitCopy, -1, "-1: default, -2: always, x: pause on blit enqueue number x and ask for user confirmation before and after execution, counted from 0. Note that single blit enqueue may have multiple copy instructions")
9595
DECLARE_DEBUG_VARIABLE(int32_t, PauseOnGpuMode, -1, "-1: default (before and after), 0: before only, 1: after only")
9696
DECLARE_DEBUG_VARIABLE(int32_t, EnableMultiStorageResources, -1, "-1: default, 0: Disable, 1: Enable")
97+
DECLARE_DEBUG_VARIABLE(int32_t, MultiStorageGranularity, -1, "Forces chunk size based resource colouring with given granularity: -1 - disabled (default, subdevice count based colouring), >0 - enabled chunk size based colouring with granularity in kb (should be multiple of 64kb page size, because of alignment restrictions)")
9798
DECLARE_DEBUG_VARIABLE(int32_t, LimitBlitterMaxWidth, -1, "-1: default, >=0: Max width")
9899
DECLARE_DEBUG_VARIABLE(int32_t, LimitBlitterMaxHeight, -1, "-1: default, >=0: Max height")
99100
DECLARE_DEBUG_VARIABLE(int32_t, PostBlitCommand, -1, "-1: default, 0: MI_ARB_CHECK, 1: MI_FLUSH, 2: Nothing")

shared/source/helpers/common_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ enum class DebugPauseState : uint32_t {
2626
terminate
2727
};
2828

29+
enum class ColouringPolicy : uint32_t {
30+
ChunkSizeBased,
31+
DeviceCountBased
32+
};
33+
2934
class TagTypeBase {
3035
};
3136

shared/source/memory_manager/allocation_properties.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct AllocationProperties {
3939
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::UNKNOWN;
4040
ImageInfo *imgInfo = nullptr;
4141
bool multiStorageResource = false;
42+
ColouringPolicy colouringPolicy = ColouringPolicy::DeviceCountBased;
43+
size_t colouringGranularity = MemoryConstants::pageSize64k;
4244
DeviceBitfield subDevicesBitfield{};
4345
uint64_t gpuAddress = 0;
4446
OsContext *osContext = nullptr;

shared/source/memory_manager/definitions/storage_info.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,25 @@ StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationPrope
111111
break;
112112
case GraphicsAllocation::AllocationType::BUFFER:
113113
case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED:
114-
case GraphicsAllocation::AllocationType::SVM_GPU:
114+
case GraphicsAllocation::AllocationType::SVM_GPU: {
115+
auto colouringPolicy = properties.colouringPolicy;
116+
auto granularity = properties.colouringGranularity;
117+
118+
if (DebugManager.flags.MultiStorageGranularity.get() != -1) {
119+
colouringPolicy = ColouringPolicy::ChunkSizeBased;
120+
granularity = DebugManager.flags.MultiStorageGranularity.get() * MemoryConstants::kiloByte;
121+
}
122+
123+
DEBUG_BREAK_IF(colouringPolicy == ColouringPolicy::DeviceCountBased && granularity != MemoryConstants::pageSize64k);
124+
115125
if (this->supportsMultiStorageResources &&
116126
properties.multiStorageResource &&
117-
properties.size >= deviceCount * MemoryConstants::pageSize64k &&
127+
properties.size >= deviceCount * granularity &&
118128
properties.subDevicesBitfield.count() != 1u) {
119129
storageInfo.memoryBanks = allTilesValue;
120130
storageInfo.multiStorage = true;
131+
storageInfo.colouringPolicy = colouringPolicy;
132+
storageInfo.colouringGranularity = granularity;
121133
if (DebugManager.flags.OverrideMultiStoragePlacement.get() != -1) {
122134
storageInfo.memoryBanks = DebugManager.flags.OverrideMultiStoragePlacement.get();
123135
}
@@ -130,6 +142,7 @@ StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationPrope
130142
}
131143
storageInfo.localOnlyRequired = true;
132144
break;
145+
}
133146
case GraphicsAllocation::AllocationType::UNIFIED_SHARED_MEMORY:
134147
storageInfo.memoryBanks = allTilesValue;
135148
break;

shared/source/memory_manager/definitions/storage_info.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#pragma once
99
#include "shared/source/helpers/app_resource_defines.h"
10+
#include "shared/source/helpers/basic_math.h"
1011
#include "shared/source/helpers/common_types.h"
12+
#include "shared/source/helpers/constants.h"
1113

1214
#include <cstdint>
1315

@@ -23,11 +25,14 @@ struct StorageInfo {
2325
bool cloningOfPageTables = true;
2426
bool tileInstanced = false;
2527
bool multiStorage = false;
28+
ColouringPolicy colouringPolicy = ColouringPolicy::DeviceCountBased;
29+
size_t colouringGranularity = MemoryConstants::pageSize64k;
2630
bool readOnlyMultiStorage = false;
2731
bool cpuVisibleSegment = false;
2832
bool isLockable = false;
2933
bool localOnlyRequired = false;
3034
char resourceTag[AppResourceDefines::maxStrLen + 1] = "";
3135
uint32_t getMemoryBanks() const { return static_cast<uint32_t>(memoryBanks.to_ulong()); }
36+
uint32_t getTotalBanksCnt() const { return Math::log2(getMemoryBanks()) + 1; }
3237
};
3338
} // namespace NEO

shared/source/memory_manager/graphics_allocation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
268268
void setGmm(Gmm *gmm, uint32_t handleId) {
269269
gmms[handleId] = gmm;
270270
}
271+
void resizeGmms(uint32_t size) {
272+
gmms.resize(size);
273+
}
271274

272275
uint32_t getNumGmms() const {
273276
return static_cast<uint32_t>(gmms.size());

shared/source/os_interface/linux/drm_allocation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class DrmAllocation : public GraphicsAllocation {
6363
return bufferObjects[handleIndex];
6464
}
6565

66+
void resizeBufferObjects(uint32_t size) {
67+
this->bufferObjects.resize(size);
68+
}
69+
6670
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
6771

6872
bool setCacheRegion(Drm *drm, CacheRegion regionIndex);

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,16 @@ void DrmMemoryManager::unlockResourceInLocalMemoryImpl(BufferObject *bo) {
11201120
}
11211121

11221122
void createColouredGmms(GmmClientContext *clientContext, DrmAllocation &allocation, const StorageInfo &storageInfo, bool compression) {
1123-
auto remainingSize = alignUp(allocation.getUnderlyingBufferSize(), MemoryConstants::pageSize64k);
1123+
DEBUG_BREAK_IF(storageInfo.colouringPolicy == ColouringPolicy::DeviceCountBased && storageInfo.colouringGranularity != MemoryConstants::pageSize64k);
1124+
1125+
auto remainingSize = alignUp(allocation.getUnderlyingBufferSize(), storageInfo.colouringGranularity);
11241126
auto handles = storageInfo.getNumBanks();
1127+
auto banksCnt = storageInfo.getTotalBanksCnt();
1128+
1129+
if (storageInfo.colouringPolicy == ColouringPolicy::ChunkSizeBased) {
1130+
handles = static_cast<uint32_t>(remainingSize / storageInfo.colouringGranularity);
1131+
allocation.resizeGmms(handles);
1132+
}
11251133
/* This logic is to colour resource as equally as possible.
11261134
Divide size by number of devices and align result up to 64kb page, then subtract it from whole size and allocate it on the first tile. First tile has it's chunk.
11271135
In the following iteration divide rest of a size by remaining devices and again subtract it.
@@ -1136,10 +1144,10 @@ void createColouredGmms(GmmClientContext *clientContext, DrmAllocation &allocati
11361144
11371145
It was tested and doesn't require any debug*/
11381146
for (auto handleId = 0u; handleId < handles; handleId++) {
1139-
auto currentSize = alignUp(remainingSize / (handles - handleId), MemoryConstants::pageSize64k);
1147+
auto currentSize = alignUp(remainingSize / (handles - handleId), storageInfo.colouringGranularity);
11401148
remainingSize -= currentSize;
11411149
StorageInfo limitedStorageInfo = storageInfo;
1142-
limitedStorageInfo.memoryBanks &= 1u << handleId;
1150+
limitedStorageInfo.memoryBanks &= (1u << (handleId % banksCnt));
11431151
auto gmm = new Gmm(clientContext,
11441152
nullptr,
11451153
currentSize,
@@ -1324,11 +1332,25 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm,
13241332
}
13251333

13261334
bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
1327-
std::array<std::unique_ptr<BufferObject>, EngineLimits::maxHandleCount> bos{};
1335+
BufferObjects bos{};
13281336
auto &storageInfo = allocation->storageInfo;
13291337
auto boAddress = gpuAddress;
13301338
auto currentBank = 0u;
1331-
for (auto handleId = 0u; handleId < storageInfo.getNumBanks(); handleId++, currentBank++) {
1339+
auto iterationOffset = 0u;
1340+
auto banksCnt = storageInfo.getTotalBanksCnt();
1341+
1342+
auto handles = storageInfo.getNumBanks();
1343+
if (storageInfo.colouringPolicy == ColouringPolicy::ChunkSizeBased) {
1344+
handles = allocation->getNumGmms();
1345+
allocation->resizeBufferObjects(handles);
1346+
bos.resize(handles);
1347+
}
1348+
1349+
for (auto handleId = 0u; handleId < handles; handleId++, currentBank++) {
1350+
if (currentBank == banksCnt) {
1351+
currentBank = 0;
1352+
iterationOffset += banksCnt;
1353+
}
13321354
uint32_t memoryBanks = static_cast<uint32_t>(storageInfo.memoryBanks.to_ulong());
13331355
if (storageInfo.getNumBanks() > 1) {
13341356
//check if we have this bank, if not move to next one
@@ -1339,18 +1361,15 @@ bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation,
13391361
memoryBanks &= 1u << currentBank;
13401362
}
13411363
auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k);
1342-
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount));
1364+
bos[handleId] = createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount);
13431365
if (nullptr == bos[handleId]) {
13441366
return false;
13451367
}
1346-
allocation->getBufferObjectToModify(currentBank) = bos[handleId].get();
1368+
allocation->getBufferObjectToModify(currentBank + iterationOffset) = bos[handleId];
13471369
if (storageInfo.multiStorage) {
13481370
boAddress += boSize;
13491371
}
13501372
}
1351-
for (auto &bo : bos) {
1352-
bo.release();
1353-
}
13541373
return true;
13551374
}
13561375

0 commit comments

Comments
 (0)