diff --git a/opencl/test/unit_test/command_queue/command_queue_tests.cpp b/opencl/test/unit_test/command_queue/command_queue_tests.cpp index 548b6af3f8..d0d0e3f86c 100644 --- a/opencl/test/unit_test/command_queue/command_queue_tests.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_tests.cpp @@ -821,6 +821,23 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledT delete indirectHeap; } +TEST_F(CommandQueueIndirectHeapTest, givenForceDefaultHeapSizeWhenGetHeapMemoryIsCalledThenHeapIsCreatedWithProperSize) { + DebugManagerStateRestore restorer; + DebugManager.flags.ForceDefaultHeapSize.set(64 * MemoryConstants::kiloByte); + + const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; + MockCommandQueue cmdQ(context.get(), pClDevice, props, false); + + IndirectHeap *indirectHeap = nullptr; + cmdQ.allocateHeapMemory(IndirectHeap::Type::INDIRECT_OBJECT, 100, indirectHeap); + EXPECT_NE(nullptr, indirectHeap); + EXPECT_NE(nullptr, indirectHeap->getGraphicsAllocation()); + EXPECT_EQ(indirectHeap->getAvailableSpace(), 64 * MemoryConstants::megaByte); + + pDevice->getMemoryManager()->freeGraphicsMemory(indirectHeap->getGraphicsAllocation()); + delete indirectHeap; +} + TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledWithAlreadyAllocatedHeapThenGraphicsAllocationIsCreated) { const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; MockCommandQueue cmdQ(context.get(), pClDevice, props, false); diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index 0f2277aaa1..785101cb46 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -207,6 +207,8 @@ ZebinAppendElws = 0 ZebinIgnoreIcbeVersion = 0 LogWaitingForCompletion = 0 ForceUserptrAlignment = -1 +ForceCommandBufferAlignment = -1 +ForceDefaultHeapSize = -1 UseExternalAllocatorForSshAndDsh = 0 DirectSubmissionDrmContext = -1 DirectSubmissionOverrideBlitterSupport = -1 diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index 94244da688..b25a73a96e 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -188,7 +188,13 @@ void CommandStreamReceiver::ensureCommandBufferAllocation(LinearStream &commandS return; } - const auto allocationSize = alignUp(minimumRequiredSize + additionalAllocationSize, MemoryConstants::pageSize64k); + auto alignment = MemoryConstants::pageSize64k; + + if (DebugManager.flags.ForceCommandBufferAlignment.get() != -1) { + alignment = DebugManager.flags.ForceCommandBufferAlignment.get() * MemoryConstants::kiloByte; + } + + const auto allocationSize = alignUp(minimumRequiredSize + additionalAllocationSize, alignment); constexpr static auto allocationType = AllocationType::COMMAND_BUFFER; auto allocation = this->getInternalAllocationStorage()->obtainReusableAllocation(allocationSize, allocationType).release(); if (allocation == nullptr) { @@ -474,7 +480,7 @@ IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType, size_t minRequiredSize, IndirectHeap *&indirectHeap) { size_t reservedSize = 0; - auto finalHeapSize = defaultHeapSize; + auto finalHeapSize = getDefaultHeapSize(); if (IndirectHeap::Type::SURFACE_STATE == heapType) { finalHeapSize = defaultSshSize; } diff --git a/shared/source/command_stream/command_stream_receiver_hw_bdw_and_later.inl b/shared/source/command_stream/command_stream_receiver_hw_bdw_and_later.inl index bd52644886..5fea20da6a 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_bdw_and_later.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_bdw_and_later.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 Intel Corporation + * Copyright (C) 2019-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,7 +14,7 @@ namespace NEO { template size_t CommandStreamReceiverHw::getSshHeapSize() { - return defaultHeapSize; + return getDefaultHeapSize(); } template diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 570aeb64b4..9bd035a398 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -368,6 +368,8 @@ DECLARE_DEBUG_VARIABLE(int32_t, UseKmdMigration, -1, "-1: devices default mode, 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") 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") DECLARE_DEBUG_VARIABLE(int32_t, ForceUserptrAlignment, -1, "-1: no force (4kb), >0: n kb alignment") +DECLARE_DEBUG_VARIABLE(int32_t, ForceCommandBufferAlignment, -1, "-1: no force (64kb), >0: n kb alignment") +DECLARE_DEBUG_VARIABLE(int32_t, ForceDefaultHeapSize, -1, "-1: no force (64kb), >0: n kb size") DECLARE_DEBUG_VARIABLE(int32_t, PreferCopyEngineForCopyBufferToBuffer, -1, "-1: default, 0: prefer EUs, 1: prefer blitter") DECLARE_DEBUG_VARIABLE(int64_t, ForceSystemMemoryPlacement, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, force system memory placement") DECLARE_DEBUG_VARIABLE(int64_t, ForceNonSystemMemoryPlacement, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, force non-system memory placement") diff --git a/shared/source/indirect_heap/indirect_heap.h b/shared/source/indirect_heap/indirect_heap.h index e3dde78d57..b2d2eaa15a 100644 --- a/shared/source/indirect_heap/indirect_heap.h +++ b/shared/source/indirect_heap/indirect_heap.h @@ -21,6 +21,14 @@ using HeapContainer = std::vector; constexpr size_t defaultHeapSize = 64 * KB; +inline size_t getDefaultHeapSize() { + auto defaultSize = defaultHeapSize; + if (DebugManager.flags.ForceDefaultHeapSize.get() != -1) { + defaultSize = DebugManager.flags.ForceDefaultHeapSize.get() * MemoryConstants::kiloByte; + } + return defaultSize; +} + class IndirectHeap : public LinearStream { typedef LinearStream BaseClass; diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index 30423836f3..8756651380 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -1477,6 +1477,20 @@ TEST_F(CommandStreamReceiverTest, givenMinimumSizeExceedsCurrentWhenCallingEnsur memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation()); } +TEST_F(CommandStreamReceiverTest, givenForceCommandBufferAlignmentWhenEnsureCommandBufferAllocationThenItHasProperAlignment) { + DebugManagerStateRestore restorer; + DebugManager.flags.ForceCommandBufferAlignment.set(2048); + + GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties({commandStreamReceiver->getRootDeviceIndex(), 128u, AllocationType::COMMAND_BUFFER, pDevice->getDeviceBitfield()}); + LinearStream commandStream{allocation}; + + commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 129u, 0u); + EXPECT_EQ(2 * MemoryConstants::megaByte, commandStream.getGraphicsAllocation()->getUnderlyingBufferSize()); + EXPECT_EQ(2 * MemoryConstants::megaByte, commandStream.getMaxAvailableSpace()); + + memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation()); +} + TEST_F(CommandStreamReceiverTest, givenAdditionalAllocationSizeWhenCallingEnsureCommandBufferAllocationThenSizesOfAllocationAndCommandBufferAreCorrect) { GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties({commandStreamReceiver->getRootDeviceIndex(), 128u, AllocationType::COMMAND_BUFFER, pDevice->getDeviceBitfield()}); LinearStream commandStream{allocation};