From c269bc062f85afedac600077b08e6290145233d4 Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Tue, 23 Apr 2019 15:57:23 +0200 Subject: [PATCH] Limit overestimation in multi kernel scenarios. - There was overestimation that resulted in each kernel getting page aligned estimation size. - After this change every kernel aligns only to cache line and final size is aligned to page size. Change-Id: Iee06bdd0083724ea7e9415f3d0fe70198acca407 Signed-off-by: Mrozek, Michal --- runtime/helpers/kernel_commands.inl | 3 +- .../get_size_required_buffer_tests.cpp | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/runtime/helpers/kernel_commands.inl b/runtime/helpers/kernel_commands.inl index d9be2d057c..3d32439cbf 100644 --- a/runtime/helpers/kernel_commands.inl +++ b/runtime/helpers/kernel_commands.inl @@ -90,9 +90,10 @@ size_t getSizeRequired(const MultiDispatchInfo &multiDispatchInfo, SizeGetterT & size_t totalSize = 0; auto it = multiDispatchInfo.begin(); for (auto e = multiDispatchInfo.end(); it != e; ++it) { - totalSize = alignUp(totalSize, MemoryConstants::pageSize); + totalSize = alignUp(totalSize, MemoryConstants::cacheLineSize); totalSize += getSize(*it, std::forward(args)...); } + totalSize = alignUp(totalSize, MemoryConstants::pageSize); return totalSize; } diff --git a/unit_tests/command_queue/get_size_required_buffer_tests.cpp b/unit_tests/command_queue/get_size_required_buffer_tests.cpp index 60b983ee12..55d5c00df8 100644 --- a/unit_tests/command_queue/get_size_required_buffer_tests.cpp +++ b/unit_tests/command_queue/get_size_required_buffer_tests.cpp @@ -369,6 +369,35 @@ HWTEST_F(GetSizeRequiredBufferTest, enqueueWriteBufferBlocking) { EXPECT_GE(expectedSizeSSH, usedAfterSSH - usedBeforeSSH); } +HWTEST_F(GetSizeRequiredBufferTest, givenMultipleKernelRequiringSshWhenTotalSizeIsComputedThenItIsProperlyAligned) { + MultiDispatchInfo multiDispatchInfo; + auto &builder = pCmdQ->getDevice().getExecutionEnvironment()->getBuiltIns()->getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer, + pCmdQ->getContext(), pCmdQ->getDevice()); + ASSERT_NE(nullptr, &builder); + + BuiltinDispatchInfoBuilder::BuiltinOpParams dc; + dc.srcPtr = EnqueueWriteBufferTraits::hostPtr; + dc.dstMemObj = dstBuffer; + dc.dstOffset = {EnqueueWriteBufferTraits::offset, 0, 0}; + dc.size = {dstBuffer->getSize(), 0, 0}; + builder.buildDispatchInfos(multiDispatchInfo, dc); + builder.buildDispatchInfos(multiDispatchInfo, dc); + builder.buildDispatchInfos(multiDispatchInfo, dc); + builder.buildDispatchInfos(multiDispatchInfo, dc); + + auto sizeSSH = multiDispatchInfo.begin()->getKernel()->getSurfaceStateHeapSize(); + sizeSSH += sizeSSH ? FamilyType::BINDING_TABLE_STATE::SURFACESTATEPOINTER_ALIGN_SIZE : 0; + + sizeSSH = alignUp(sizeSSH, MemoryConstants::cacheLineSize); + + sizeSSH *= 4u; + sizeSSH = alignUp(sizeSSH, MemoryConstants::pageSize); + + EXPECT_EQ(4u, multiDispatchInfo.size()); + auto expectedSizeSSH = KernelCommandsHelper::getTotalSizeRequiredSSH(multiDispatchInfo); + EXPECT_EQ(sizeSSH, expectedSizeSSH); +} + HWTEST_F(GetSizeRequiredBufferTest, enqueueKernelHelloWorld) { typedef HelloWorldKernelFixture KernelFixture; auto &commandStream = pCmdQ->getCS(1024);