From f4ad45eafd0305fc8940774831a07f3f2ab33879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Zwoli=C5=84ski?= Date: Tue, 13 Aug 2024 17:11:57 +0000 Subject: [PATCH] fix: initialize engine in AubMemoryOperationsHandler::makeResident MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian ZwoliƄski --- .../command_stream/command_stream_receiver.h | 1 + ...mand_stream_receiver_simulated_common_hw.h | 1 - .../aub_memory_operations_handler.cpp | 5 +++ .../mocks/mock_command_stream_receiver.h | 5 +++ .../aub_memory_operations_handler_tests.cpp | 40 +++++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/shared/source/command_stream/command_stream_receiver.h b/shared/source/command_stream/command_stream_receiver.h index 12d5f4651b..0cddacdfc2 100644 --- a/shared/source/command_stream/command_stream_receiver.h +++ b/shared/source/command_stream/command_stream_receiver.h @@ -286,6 +286,7 @@ class CommandStreamReceiver { MOCKABLE_VIRTUAL bool writeMemory(GraphicsAllocation &gfxAllocation) { return writeMemory(gfxAllocation, false, 0, 0); } virtual bool writeMemory(GraphicsAllocation &gfxAllocation, bool isChunkCopy, uint64_t gpuVaChunkOffset, size_t chunkSize) { return false; } virtual void writeMemoryAub(aub_stream::AllocationParams &allocationParams){}; + virtual void initializeEngine(){}; virtual bool isMultiOsContextCapable() const = 0; diff --git a/shared/source/command_stream/command_stream_receiver_simulated_common_hw.h b/shared/source/command_stream/command_stream_receiver_simulated_common_hw.h index 4e167c3450..27baa24915 100644 --- a/shared/source/command_stream/command_stream_receiver_simulated_common_hw.h +++ b/shared/source/command_stream/command_stream_receiver_simulated_common_hw.h @@ -69,7 +69,6 @@ class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHwgetDefaultEngine().commandStreamReceiver->initializeEngine(); + } + auto lock = acquireLock(resourcesLock); int hint = AubMemDump::DataTypeHintValues::TraceNotype; for (const auto &allocation : gfxAllocations) { diff --git a/shared/test/common/mocks/mock_command_stream_receiver.h b/shared/test/common/mocks/mock_command_stream_receiver.h index c6a65b747e..1528d89b29 100644 --- a/shared/test/common/mocks/mock_command_stream_receiver.h +++ b/shared/test/common/mocks/mock_command_stream_receiver.h @@ -88,6 +88,10 @@ class MockCommandStreamReceiver : public CommandStreamReceiver { writeMemoryAubCalled++; } + void initializeEngine() override { + initializeEngineCalled++; + } + bool isMultiOsContextCapable() const override { return multiOsContextCapable; } bool isGpuHangDetected() const override { @@ -252,6 +256,7 @@ class MockCommandStreamReceiver : public CommandStreamReceiver { uint32_t waitForCompletionWithTimeoutCalled = 0; uint32_t fillReusableAllocationsListCalled = 0; uint32_t writeMemoryAubCalled = 0; + uint32_t initializeEngineCalled = 0; uint32_t makeResidentCalledTimes = 0; uint32_t downloadAllocationsCalledCount = 0; uint32_t submitDependencyUpdateCalledTimes = 0; diff --git a/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp b/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp index fe63d00b47..a6c7ab8710 100644 --- a/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp +++ b/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp @@ -152,6 +152,46 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerAndAllocationInLocalMemor device->getDefaultEngine().commandStreamReceiver = oldCsr; } +TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThenInitializeEngineBeforeWriteMemory) { + DeviceBitfield deviceBitfield(1); + const auto csr = std::make_unique(*device->getExecutionEnvironment(), 0, deviceBitfield); + csr->localMemoryEnabled = true; + + auto oldCsr = device->getDefaultEngine().commandStreamReceiver; + device->getDefaultEngine().commandStreamReceiver = csr.get(); + + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + EXPECT_EQ(result, MemoryOperationsStatus::success); + EXPECT_EQ(1u, csr->initializeEngineCalled); + + auto itor = std::find(memoryOperationsInterface->residentAllocations.begin(), memoryOperationsInterface->residentAllocations.end(), allocPtr); + EXPECT_NE(memoryOperationsInterface->residentAllocations.end(), itor); + EXPECT_EQ(1u, memoryOperationsInterface->residentAllocations.size()); + + device->getDefaultEngine().commandStreamReceiver = oldCsr; +} + +TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledWithNullDeviceThenDoNotInitializeEngineBeforeWriteMemory) { + DeviceBitfield deviceBitfield(1); + const auto csr = std::make_unique(*device->getExecutionEnvironment(), 0, deviceBitfield); + csr->localMemoryEnabled = true; + + auto oldCsr = device->getDefaultEngine().commandStreamReceiver; + device->getDefaultEngine().commandStreamReceiver = csr.get(); + + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + auto result = memoryOperationsInterface->makeResident(nullptr, ArrayRef(&allocPtr, 1)); + EXPECT_EQ(result, MemoryOperationsStatus::success); + EXPECT_EQ(0u, csr->initializeEngineCalled); + + device->getDefaultEngine().commandStreamReceiver = oldCsr; +} + TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnCompressedAllocationThenPassCorrectParams) { MockAubManager aubManager; aubManager.storeAllocationParams = true;