From 6d4f79b71bb0876680e8713a4a68cfd5628673c5 Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Wed, 1 Nov 2023 19:20:40 +0000 Subject: [PATCH] fix: hang during appendMemory Fixed command buffer size estimation in appendMemoryCopy code path. Related-To: NEO-8293 Signed-off-by: Zhang, Winston --- .../source/cmdlist/cmdlist_hw_immediate.inl | 3 ++- .../cmdlist/test_cmdlist_append_memory.cpp | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index 2af2c25a92..359e36eda5 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -551,7 +551,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryCopy( auto estimatedSize = commonImmediateCommandSize; if (isCopyOnly()) { - auto nBlits = static_cast(std::ceil(size / static_cast(BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight))); + auto nBlits = size / (NEO::BlitCommandsHelper::getMaxBlitWidth(this->device->getNEODevice()->getRootDeviceEnvironment()) * + NEO::BlitCommandsHelper::getMaxBlitHeight(this->device->getNEODevice()->getRootDeviceEnvironment(), true)); auto sizePerBlit = sizeof(typename GfxFamily::XY_COPY_BLT) + NEO::BlitCommandsHelper::estimatePostBlitCommandSize(this->device->getNEODevice()->getRootDeviceEnvironment()); estimatedSize += nBlits * sizePerBlit; } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp index 995be83fa7..9e1bc6ea45 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp @@ -607,6 +607,28 @@ HWTEST2_F(AppendMemoryCopy, givenSyncModeImmediateCommandListWhenAppendingMemory commandList->csr->getInternalAllocationStorage()->getTemporaryAllocations().freeAllGraphicsAllocations(device->getNEODevice()); } +HWTEST2_F(AppendMemoryCopy, givenImmediateCommandListWhenAppendingMemoryCopyThenNBlitsIsSuccessfullyCalculated, IsAtLeastSkl) { + Mock cmdQueue; + void *srcPtr = reinterpret_cast(0x1234); + void *dstPtr = reinterpret_cast(0x2345); + + auto commandList = std::make_unique>>(); + ASSERT_NE(nullptr, commandList); + commandList->device = device; + commandList->cmdQImmediate = &cmdQueue; + commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE; + commandList->csr = device->getNEODevice()->getDefaultEngine().commandStreamReceiver; + ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::Copy, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, ret); + + auto result = commandList->appendMemoryCopy(dstPtr, srcPtr, 8, nullptr, 0, nullptr, false, false); + EXPECT_TRUE(commandList->isCopyOnly()); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + commandList->cmdQImmediate = nullptr; + commandList->csr->getInternalAllocationStorage()->getTemporaryAllocations().freeAllGraphicsAllocations(device->getNEODevice()); +} + HWTEST2_F(AppendMemoryCopy, givenCommandListAndHostPointersWhenMemoryCopyCalledThenPipeControlWithDcFlushAdded, IsAtLeastSkl) { using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;