diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.h b/level_zero/core/source/cmdqueue/cmdqueue_hw.h index 18040d6115..b93d8653af 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.h +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.h @@ -37,7 +37,7 @@ struct CommandQueueHw : public CommandQueueImp { void programGeneralStateBaseAddress(uint64_t gsba, bool useLocalMemoryForIndirectHeap, NEO::LinearStream &commandStream); size_t estimateStateBaseAddressCmdSize(); - void programFrontEnd(uint64_t scratchAddress, NEO::LinearStream &commandStream); + MOCKABLE_VIRTUAL void programFrontEnd(uint64_t scratchAddress, NEO::LinearStream &commandStream); size_t estimateFrontEndCmdSize(); size_t estimatePipelineSelect(); diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index b155b60cec..2570ee718d 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -142,7 +142,10 @@ ze_result_t CommandQueueHw::executeCommandLists( interlockedMax(commandQueuePerThreadScratchSize, commandList->getCommandListPerThreadScratchSize()); if (commandList->getCommandListPerThreadScratchSize() != 0) { - heapContainer.push_back(commandList->commandContainer.getIndirectHeap(NEO::HeapType::SURFACE_STATE)); + heapContainer.push_back(commandList->commandContainer.getIndirectHeap(NEO::HeapType::SURFACE_STATE)->getGraphicsAllocation()); + for (auto element : commandList->commandContainer.sshAllocations) { + heapContainer.push_back(element); + } } } diff --git a/level_zero/core/test/unit_tests/mocks/mock_cmdlist.h b/level_zero/core/test/unit_tests/mocks/mock_cmdlist.h index 3b8d5afa61..ad06dd3f39 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_cmdlist.h +++ b/level_zero/core/test/unit_tests/mocks/mock_cmdlist.h @@ -35,11 +35,13 @@ struct WhiteBox<::L0::CommandListCoreFamily> using BaseClass::appendMemoryCopyBlitRegion; using BaseClass::appendSignalEventPostWalker; using BaseClass::applyMemoryRangesBarrier; + using BaseClass::commandListPerThreadScratchSize; using BaseClass::commandListPreemptionMode; using BaseClass::getAlignedAllocation; using BaseClass::getAllocationFromHostPtrMap; using BaseClass::getHostPtrAlloc; using BaseClass::hostPtrMap; + using BaseClass::initialize; WhiteBox() : ::L0::CommandListCoreFamily(BaseClass::defaultNumIddsPerBlock) {} }; diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp index af3766c38f..b34ca4018e 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp @@ -354,6 +354,54 @@ HWTEST_F(ContextCreateCommandQueueTest, givenOrdinalBigerThanAvailableEnginesWhe EXPECT_EQ(nullptr, commandQueue); } +template +class MockCommandQueue : public L0::CommandQueueHw { + public: + using L0::CommandQueueHw::CommandQueueHw; + MockCommandQueue(L0::Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc) : L0::CommandQueueHw(device, csr, desc) {} + using BaseClass = ::L0::CommandQueueHw; + NEO::HeapContainer heapContainer; + void handleScratchSpace(NEO::ResidencyContainer &residency, + NEO::HeapContainer &heapContainer, + NEO::ScratchSpaceController *scratchController, + bool &gsbaState, bool &frontEndState) override { + this->heapContainer = heapContainer; + } + + void programFrontEnd(uint64_t scratchAddress, NEO::LinearStream &commandStream) override { + return; + } +}; + +using CommandQueueExecuteTest = Test; +using CommandQueueExecuteTestSupport = IsAtLeastProduct; + +HWTEST2_F(CommandQueueDestroy, givenCommandQueueAndCommandListWithSshAndScratchWhenExecuteThenSshWasUsed, CommandQueueExecuteTestSupport) { + ze_command_queue_desc_t desc = {}; + NEO::CommandStreamReceiver *csr; + device->getCsrForOrdinalAndIndex(&csr, 0u, 0u); + auto commandQueue = new MockCommandQueue(device, csr, &desc); + commandQueue->initialize(false); + auto commandList = new CommandListCoreFamily(); + commandList->initialize(device, NEO::EngineGroupType::Compute); + commandList->commandListPerThreadScratchSize = 100u; + auto commandListHandle = commandList->toHandle(); + + void *alloc = alignedMalloc(0x100, 0x100); + NEO::GraphicsAllocation graphicsAllocation1(0, NEO::GraphicsAllocation::AllocationType::BUFFER, alloc, 0u, 0u, 1u, MemoryPool::System4KBPages, 1u); + NEO::GraphicsAllocation graphicsAllocation2(0, NEO::GraphicsAllocation::AllocationType::BUFFER, alloc, 0u, 0u, 1u, MemoryPool::System4KBPages, 1u); + + commandList->commandContainer.sshAllocations.push_back(&graphicsAllocation1); + commandList->commandContainer.sshAllocations.push_back(&graphicsAllocation2); + + commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); + + EXPECT_EQ(commandQueue->heapContainer.size(), 3u); + commandQueue->destroy(); + commandList->destroy(); + alignedFree(alloc); +} + using CommandQueueSynchronizeTest = Test; HWTEST_F(CommandQueueSynchronizeTest, givenCallToSynchronizeThenCorrectEnableTimeoutAndTimeoutValuesAreUsed) { diff --git a/shared/source/command_container/cmdcontainer.cpp b/shared/source/command_container/cmdcontainer.cpp index f191864dc2..f5a29c91c4 100644 --- a/shared/source/command_container/cmdcontainer.cpp +++ b/shared/source/command_container/cmdcontainer.cpp @@ -119,6 +119,7 @@ void CommandContainer::reset() { slmSize = std::numeric_limits::max(); getResidencyContainer().clear(); getDeallocationContainer().clear(); + sshAllocations.clear(); for (size_t i = 1; i < cmdBufferAllocations.size(); i++) { device->getMemoryManager()->freeGraphicsMemory(cmdBufferAllocations[i]); @@ -191,6 +192,7 @@ IndirectHeap *CommandContainer::getHeapWithRequiredSizeAndAlignment(HeapType hea setHeapDirty(heapType); if (heapType == HeapType::SURFACE_STATE) { indirectHeap->getSpace(reservedSshSize); + sshAllocations.push_back(oldAlloc); } } diff --git a/shared/source/command_container/cmdcontainer.h b/shared/source/command_container/cmdcontainer.h index 1e45f04cb1..591c20268f 100644 --- a/shared/source/command_container/cmdcontainer.h +++ b/shared/source/command_container/cmdcontainer.h @@ -103,6 +103,7 @@ class CommandContainer : public NonCopyableOrMovableClass { void setReservedSshSize(size_t reserveSize) { reservedSshSize = reserveSize; } + HeapContainer sshAllocations; protected: void *iddBlock = nullptr; diff --git a/shared/source/command_stream/scratch_space_controller.h b/shared/source/command_stream/scratch_space_controller.h index 7e32d11c05..19c3b609b0 100644 --- a/shared/source/command_stream/scratch_space_controller.h +++ b/shared/source/command_stream/scratch_space_controller.h @@ -20,8 +20,6 @@ class MemoryManager; struct HardwareInfo; class OsContext; -using HeapContainer = std::vector; - namespace ScratchSpaceConstants { constexpr size_t scratchSpaceOffsetFor64Bit = 4096u; } diff --git a/shared/source/indirect_heap/indirect_heap.h b/shared/source/indirect_heap/indirect_heap.h index a6d0f5caf1..595448d7bd 100644 --- a/shared/source/indirect_heap/indirect_heap.h +++ b/shared/source/indirect_heap/indirect_heap.h @@ -16,6 +16,8 @@ namespace NEO { class GraphicsAllocation; +using HeapContainer = std::vector; + constexpr size_t defaultHeapSize = 64 * KB; class IndirectHeap : public LinearStream { diff --git a/shared/test/unit_test/command_container/command_container_tests.cpp b/shared/test/unit_test/command_container/command_container_tests.cpp index c47a7da5f7..20df760d95 100644 --- a/shared/test/unit_test/command_container/command_container_tests.cpp +++ b/shared/test/unit_test/command_container/command_container_tests.cpp @@ -233,6 +233,7 @@ HWTEST_F(CommandContainerTest, givenNotEnoughSpaceInSSHWhenGettingHeapWithRequir cmdContainer->getHeapWithRequiredSizeAndAlignment(HeapType::SURFACE_STATE, sizeof(RENDER_SURFACE_STATE), 0); EXPECT_EQ(4 * MemoryConstants::pageSize, heap->getUsed()); + EXPECT_EQ(cmdContainer->sshAllocations.size(), 1u); } TEST_F(CommandContainerTest, givenAvailableSpaceWhenGetHeapWithRequiredSizeAndAlignmentCalledThenExistingAllocationIsReturned) {