diff --git a/opencl/source/command_stream/aub_command_stream_receiver_hw.h b/opencl/source/command_stream/aub_command_stream_receiver_hw.h index 75a40df891..864ba10718 100644 --- a/opencl/source/command_stream/aub_command_stream_receiver_hw.h +++ b/opencl/source/command_stream/aub_command_stream_receiver_hw.h @@ -39,7 +39,6 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::stream; bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override; - void makeNonResident(GraphicsAllocation &gfxAllocation) override; void processResidency(const ResidencyContainer &allocationsForResidency, uint32_t handleId) override; @@ -67,7 +66,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::dumpAllocation(GraphicsAllocation &g AubAllocDump::dumpAllocation(dumpFormat, gfxAllocation, getAubStream(), getDumpHandle()); } -template -void AUBCommandStreamReceiverHw::makeNonResident(GraphicsAllocation &gfxAllocation) { - if (gfxAllocation.isResident(this->osContext->getContextId())) { - dumpAllocation(gfxAllocation); - this->getEvictionAllocations().push_back(&gfxAllocation); - gfxAllocation.releaseResidencyInOsContext(this->osContext->getContextId()); - } -} - template AubSubCaptureStatus AUBCommandStreamReceiverHw::checkAndActivateAubSubCapture(const MultiDispatchInfo &dispatchInfo) { auto status = subCaptureManager->checkAndActivateSubCapture(dispatchInfo); diff --git a/opencl/source/command_stream/command_stream_receiver_simulated_common_hw.h b/opencl/source/command_stream/command_stream_receiver_simulated_common_hw.h index fec89d041f..6ea9702f94 100644 --- a/opencl/source/command_stream/command_stream_receiver_simulated_common_hw.h +++ b/opencl/source/command_stream/command_stream_receiver_simulated_common_hw.h @@ -61,6 +61,10 @@ class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw::freeEngineInfo(AddressMa engineInfo.pRingBuffer = nullptr; } +template +void CommandStreamReceiverSimulatedCommonHw::makeNonResident(GraphicsAllocation &gfxAllocation) { + if (gfxAllocation.isResident(osContext->getContextId())) { + dumpAllocation(gfxAllocation); + this->getEvictionAllocations().push_back(&gfxAllocation); + gfxAllocation.releaseResidencyInOsContext(this->osContext->getContextId()); + } +} + template uint32_t CommandStreamReceiverSimulatedCommonHw::getDeviceIndex() const { return osContext->getDeviceBitfield().any() ? static_cast(Math::log2(static_cast(osContext->getDeviceBitfield().to_ulong()))) : 0u; diff --git a/opencl/source/command_stream/tbx_command_stream_receiver_hw.h b/opencl/source/command_stream/tbx_command_stream_receiver_hw.h index 28f5dca311..5cfa8133ce 100644 --- a/opencl/source/command_stream/tbx_command_stream_receiver_hw.h +++ b/opencl/source/command_stream/tbx_command_stream_receiver_hw.h @@ -56,6 +56,8 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::checkAndActivateAubSu } return status; } + +template +void TbxCommandStreamReceiverHw::dumpAllocation(GraphicsAllocation &gfxAllocation) { + if (!hardwareContextController) { + return; + } + + if (EngineHelpers::isBcs(this->osContext->getEngineType())) { + return; + } + + if (DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get()) { + if (!gfxAllocation.isAllocDumpable()) { + return; + } + gfxAllocation.setAllocDumpable(false); + } + + auto dumpFormat = AubAllocDump::getDumpFormat(gfxAllocation); + auto surfaceInfo = std::unique_ptr(AubAllocDump::getDumpSurfaceInfo(gfxAllocation, dumpFormat)); + if (surfaceInfo) { + hardwareContextController->pollForCompletion(); + hardwareContextController->dumpSurface(*surfaceInfo.get()); + } +} } // namespace NEO diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp index 346e3449a4..bd61c74396 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -712,6 +712,7 @@ struct MockSimulatedCsrHw : public CommandStreamReceiverSimulatedHw void pollForCompletion() override {} bool writeMemory(GraphicsAllocation &gfxAllocation) override { return true; } void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) override {} + void dumpAllocation(GraphicsAllocation &gfxAllocation) override {} }; HWTEST_F(SimulatedCommandStreamReceiverTest, givenCsrWithOsContextWhenGetDeviceIndexThenGetHighestEnabledBitInDeviceBitfield) { diff --git a/opencl/test/unit_test/command_stream/tbx_command_stream_tests.cpp b/opencl/test/unit_test/command_stream/tbx_command_stream_tests.cpp index d3018c3fa0..f425d141f3 100644 --- a/opencl/test/unit_test/command_stream/tbx_command_stream_tests.cpp +++ b/opencl/test/unit_test/command_stream/tbx_command_stream_tests.cpp @@ -14,6 +14,7 @@ #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/helpers/variable_backup.h" +#include "opencl/source/aub_mem_dump/aub_alloc_dump.h" #include "opencl/source/command_stream/aub_command_stream_receiver.h" #include "opencl/source/command_stream/command_stream_receiver_with_aub_dump.h" #include "opencl/source/command_stream/tbx_command_stream_receiver_hw.h" @@ -936,3 +937,105 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenDispatchBlitEnqueueThenProcessCor error = cmdQ.enqueueWriteBuffer(buffer.get(), CL_TRUE, 0, 1, &hostPtr, nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, error); } + +HWTEST_F(TbxCommandStreamTests, givenGraphicsAllocationWhenDumpAllocationIsCalledButBcsIsUsedThenGraphicsAllocationShouldNotBeDumped) { + MockTbxCsr tbxCsr(*pDevice->executionEnvironment); + MockOsContext osContext(0, 1, aub_stream::ENGINE_BCS, PreemptionMode::Disabled, false, false, false); + tbxCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); + + tbxCsr.dumpAllocation(*gfxAllocation); + EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledButDumpFormatIsNotSpecifiedThenGraphicsAllocationShouldNotBeDumped) { + MockTbxCsr tbxCsr(*pDevice->executionEnvironment); + MockOsContext osContext(0, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false); + tbxCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); + + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation)); + + tbxCsr.dumpAllocation(*gfxAllocation); + EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenGraphicsAllocationShouldBeDumped) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + MockTbxCsr tbxCsr(*pDevice->executionEnvironment); + MockOsContext osContext(0, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false); + tbxCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation)); + + tbxCsr.dumpAllocation(*gfxAllocation); + EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenGraphicsAllocationWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueReadOnlyIsSetThenDumpableFlagShouldBeRespected) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + MockTbxCsr tbxCsr(*pDevice->executionEnvironment); + MockOsContext osContext(0, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false); + tbxCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); + + for (bool dumpable : {false, true}) { + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + gfxAllocation->setAllocDumpable(dumpable); + + tbxCsr.dumpAllocation(*gfxAllocation); + EXPECT_EQ(dumpable, mockHardwareContext->dumpSurfaceCalled); + EXPECT_FALSE(gfxAllocation->isAllocDumpable()); + } + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenGraphicsAllocationWhenDumpAllocationIsCalledButUseAubStreamIsSetToFalseThenEarlyReturn) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.UseAubStream.set(false); + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get(), false, 1); + executionEnvironment.initializeMemoryManager(); + + MockTbxCsr tbxCsr(executionEnvironment); + EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[0]->aubCenter->getAubManager()); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); + + tbxCsr.dumpAllocation(*gfxAllocation); + EXPECT_TRUE(tbxCsr.dumpAllocationCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} diff --git a/opencl/test/unit_test/gen12lp/command_stream_receiver_simulated_common_hw_tests_gen12lp.inl b/opencl/test/unit_test/gen12lp/command_stream_receiver_simulated_common_hw_tests_gen12lp.inl index 977818bafb..3609ee818f 100644 --- a/opencl/test/unit_test/gen12lp/command_stream_receiver_simulated_common_hw_tests_gen12lp.inl +++ b/opencl/test/unit_test/gen12lp/command_stream_receiver_simulated_common_hw_tests_gen12lp.inl @@ -25,6 +25,7 @@ class MockSimulatedCsrHw : public CommandStreamReceiverSimulatedHw { void pollForCompletion() override {} bool writeMemory(GraphicsAllocation &gfxAllocation) override { return true; } void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) override {} + void dumpAllocation(GraphicsAllocation &gfxAllocation) override {} }; GEN12LPTEST_F(Gen12LPCommandStreamReceiverSimulatedCommonHwTests, givenAubCommandStreamReceiverWhewGlobalMmiosAreInitializedThenMOCSRegistersAreConfigured) { diff --git a/opencl/test/unit_test/mocks/mock_tbx_csr.h b/opencl/test/unit_test/mocks/mock_tbx_csr.h index b2fc67abf4..5a5d83ea87 100644 --- a/opencl/test/unit_test/mocks/mock_tbx_csr.h +++ b/opencl/test/unit_test/mocks/mock_tbx_csr.h @@ -55,6 +55,10 @@ class MockTbxCsr : public TbxCommandStreamReceiverHw { TbxCommandStreamReceiverHw::downloadAllocation(gfxAllocation); makeCoherentCalled = true; } + void dumpAllocation(GraphicsAllocation &gfxAllocation) override { + TbxCommandStreamReceiverHw::dumpAllocation(gfxAllocation); + dumpAllocationCalled = true; + } bool initializeEngineCalled = false; bool writeMemoryWithAubManagerCalled = false; bool writeMemoryCalled = false; @@ -64,5 +68,6 @@ class MockTbxCsr : public TbxCommandStreamReceiverHw { bool expectMemoryEqualCalled = false; bool expectMemoryNotEqualCalled = false; bool makeCoherentCalled = false; + bool dumpAllocationCalled = false; }; } // namespace NEO