Skip to content

Commit b60d963

Browse files
Add debug variable to force default heap allocation size
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent abd9030 commit b60d963

File tree

7 files changed

+53
-4
lines changed

7 files changed

+53
-4
lines changed

opencl/test/unit_test/command_queue/command_queue_tests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,23 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledT
821821
delete indirectHeap;
822822
}
823823

824+
TEST_F(CommandQueueIndirectHeapTest, givenForceDefaultHeapSizeWhenGetHeapMemoryIsCalledThenHeapIsCreatedWithProperSize) {
825+
DebugManagerStateRestore restorer;
826+
DebugManager.flags.ForceDefaultHeapSize.set(64 * MemoryConstants::kiloByte);
827+
828+
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
829+
MockCommandQueue cmdQ(context.get(), pClDevice, props, false);
830+
831+
IndirectHeap *indirectHeap = nullptr;
832+
cmdQ.allocateHeapMemory(IndirectHeap::Type::INDIRECT_OBJECT, 100, indirectHeap);
833+
EXPECT_NE(nullptr, indirectHeap);
834+
EXPECT_NE(nullptr, indirectHeap->getGraphicsAllocation());
835+
EXPECT_EQ(indirectHeap->getAvailableSpace(), 64 * MemoryConstants::megaByte);
836+
837+
pDevice->getMemoryManager()->freeGraphicsMemory(indirectHeap->getGraphicsAllocation());
838+
delete indirectHeap;
839+
}
840+
824841
TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledWithAlreadyAllocatedHeapThenGraphicsAllocationIsCreated) {
825842
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
826843
MockCommandQueue cmdQ(context.get(), pClDevice, props, false);

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ ZebinAppendElws = 0
207207
ZebinIgnoreIcbeVersion = 0
208208
LogWaitingForCompletion = 0
209209
ForceUserptrAlignment = -1
210+
ForceCommandBufferAlignment = -1
211+
ForceDefaultHeapSize = -1
210212
UseExternalAllocatorForSshAndDsh = 0
211213
DirectSubmissionDrmContext = -1
212214
DirectSubmissionOverrideBlitterSupport = -1

shared/source/command_stream/command_stream_receiver.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ void CommandStreamReceiver::ensureCommandBufferAllocation(LinearStream &commandS
188188
return;
189189
}
190190

191-
const auto allocationSize = alignUp(minimumRequiredSize + additionalAllocationSize, MemoryConstants::pageSize64k);
191+
auto alignment = MemoryConstants::pageSize64k;
192+
193+
if (DebugManager.flags.ForceCommandBufferAlignment.get() != -1) {
194+
alignment = DebugManager.flags.ForceCommandBufferAlignment.get() * MemoryConstants::kiloByte;
195+
}
196+
197+
const auto allocationSize = alignUp(minimumRequiredSize + additionalAllocationSize, alignment);
192198
constexpr static auto allocationType = AllocationType::COMMAND_BUFFER;
193199
auto allocation = this->getInternalAllocationStorage()->obtainReusableAllocation(allocationSize, allocationType).release();
194200
if (allocation == nullptr) {
@@ -474,7 +480,7 @@ IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType
474480
void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
475481
size_t minRequiredSize, IndirectHeap *&indirectHeap) {
476482
size_t reservedSize = 0;
477-
auto finalHeapSize = defaultHeapSize;
483+
auto finalHeapSize = getDefaultHeapSize();
478484
if (IndirectHeap::Type::SURFACE_STATE == heapType) {
479485
finalHeapSize = defaultSshSize;
480486
}

shared/source/command_stream/command_stream_receiver_hw_bdw_and_later.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 Intel Corporation
2+
* Copyright (C) 2019-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -14,7 +14,7 @@ namespace NEO {
1414

1515
template <typename GfxFamily>
1616
size_t CommandStreamReceiverHw<GfxFamily>::getSshHeapSize() {
17-
return defaultHeapSize;
17+
return getDefaultHeapSize();
1818
}
1919

2020
template <typename GfxFamily>

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ DECLARE_DEBUG_VARIABLE(int32_t, UseKmdMigration, -1, "-1: devices default mode,
368368
DECLARE_DEBUG_VARIABLE(int32_t, ForceSemaphoreDelayBetweenWaits, -1, "Specifies the minimum number of microseconds allowed for command streamer to wait before re-fetching the data. 0 - poll interval will be equal to the memory latency of the read completion")
369369
DECLARE_DEBUG_VARIABLE(int32_t, ForceLocalMemoryAccessMode, -1, "-1: don't override, 0: default rules apply, 1: CPU can access local memory, 3: CPU never accesses local memory")
370370
DECLARE_DEBUG_VARIABLE(int32_t, ForceUserptrAlignment, -1, "-1: no force (4kb), >0: n kb alignment")
371+
DECLARE_DEBUG_VARIABLE(int32_t, ForceCommandBufferAlignment, -1, "-1: no force (64kb), >0: n kb alignment")
372+
DECLARE_DEBUG_VARIABLE(int32_t, ForceDefaultHeapSize, -1, "-1: no force (64kb), >0: n kb size")
371373
DECLARE_DEBUG_VARIABLE(int32_t, PreferCopyEngineForCopyBufferToBuffer, -1, "-1: default, 0: prefer EUs, 1: prefer blitter")
372374
DECLARE_DEBUG_VARIABLE(int64_t, ForceSystemMemoryPlacement, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, force system memory placement")
373375
DECLARE_DEBUG_VARIABLE(int64_t, ForceNonSystemMemoryPlacement, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, force non-system memory placement")

shared/source/indirect_heap/indirect_heap.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ using HeapContainer = std::vector<GraphicsAllocation *>;
2121

2222
constexpr size_t defaultHeapSize = 64 * KB;
2323

24+
inline size_t getDefaultHeapSize() {
25+
auto defaultSize = defaultHeapSize;
26+
if (DebugManager.flags.ForceDefaultHeapSize.get() != -1) {
27+
defaultSize = DebugManager.flags.ForceDefaultHeapSize.get() * MemoryConstants::kiloByte;
28+
}
29+
return defaultSize;
30+
}
31+
2432
class IndirectHeap : public LinearStream {
2533
typedef LinearStream BaseClass;
2634

shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,20 @@ TEST_F(CommandStreamReceiverTest, givenMinimumSizeExceedsCurrentWhenCallingEnsur
14771477
memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation());
14781478
}
14791479

1480+
TEST_F(CommandStreamReceiverTest, givenForceCommandBufferAlignmentWhenEnsureCommandBufferAllocationThenItHasProperAlignment) {
1481+
DebugManagerStateRestore restorer;
1482+
DebugManager.flags.ForceCommandBufferAlignment.set(2048);
1483+
1484+
GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties({commandStreamReceiver->getRootDeviceIndex(), 128u, AllocationType::COMMAND_BUFFER, pDevice->getDeviceBitfield()});
1485+
LinearStream commandStream{allocation};
1486+
1487+
commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 129u, 0u);
1488+
EXPECT_EQ(2 * MemoryConstants::megaByte, commandStream.getGraphicsAllocation()->getUnderlyingBufferSize());
1489+
EXPECT_EQ(2 * MemoryConstants::megaByte, commandStream.getMaxAvailableSpace());
1490+
1491+
memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation());
1492+
}
1493+
14801494
TEST_F(CommandStreamReceiverTest, givenAdditionalAllocationSizeWhenCallingEnsureCommandBufferAllocationThenSizesOfAllocationAndCommandBufferAreCorrect) {
14811495
GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties({commandStreamReceiver->getRootDeviceIndex(), 128u, AllocationType::COMMAND_BUFFER, pDevice->getDeviceBitfield()});
14821496
LinearStream commandStream{allocation};

0 commit comments

Comments
 (0)