From f411dc2e655e4a22fe3d7c22c6d11d1bb363c366 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Mon, 6 Oct 2025 13:47:43 +0000 Subject: [PATCH] fix: debug key for using temp memory when writing to aub Related-To: NEO-16276 Signed-off-by: Mateusz Hoppe --- .../command_stream_receiver_simulated_hw.h | 7 +++ .../debug_settings/debug_variables_base.inl | 1 + shared/test/common/test_files/igdrcl.config | 1 + .../aub_command_stream_receiver_3_tests.cpp | 43 +++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/shared/source/command_stream/command_stream_receiver_simulated_hw.h b/shared/source/command_stream/command_stream_receiver_simulated_hw.h index 71c1514a7e..01c3a14897 100644 --- a/shared/source/command_stream/command_stream_receiver_simulated_hw.h +++ b/shared/source/command_stream/command_stream_receiver_simulated_hw.h @@ -106,6 +106,13 @@ class CommandStreamReceiverSimulatedHw : public CommandStreamReceiverSimulatedCo allocSize = chunkSize; } + std::unique_ptr memoryCopy; + if (graphicsAllocation.isLocked() && debugManager.flags.CopyLockedMemoryBeforeWrite.get()) { + memoryCopy = std::make_unique_for_overwrite(allocSize); + memcpy_s(memoryCopy.get(), allocSize, cpuAddress, allocSize); + cpuAddress = memoryCopy.get(); + } + aub_stream::AllocationParams allocationParams(gpuAddress, cpuAddress, allocSize, this->getMemoryBank(&graphicsAllocation), hint, graphicsAllocation.getUsedPageSize()); diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index a2308e4a67..ec5246dad2 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -39,6 +39,7 @@ DECLARE_DEBUG_VARIABLE(bool, AUBDumpAllocsOnEnqueueSVMMemcpyOnly, false, "Force DECLARE_DEBUG_VARIABLE(bool, AUBDumpForceAllToLocalMemory, false, "Force placing every allocation in local memory address space") DECLARE_DEBUG_VARIABLE(bool, GenerateAubFilePerProcessId, true, "Generate aub file with process id") DECLARE_DEBUG_VARIABLE(bool, SetBufferHostMemoryAlwaysAubWritable, false, "Make buffer host memory allocation always uploaded to AUB/TBX") +DECLARE_DEBUG_VARIABLE(bool, CopyLockedMemoryBeforeWrite, false, "Copy memory before writing to aub") DECLARE_DEBUG_VARIABLE(int32_t, EnableTbxPageFaultManager, -1, "Enable/Disable TbxPageFaultManager, overrides SetBufferHostMemoryAlwaysAubWritable to false if enabled: default 1, 0 - disable, 1 - enable") /*DEBUG FLAGS*/ diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 06956112eb..f2ccd5367f 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -670,4 +670,5 @@ SplitBcsForCopyOffload = -1 LimitIsaPrefetchSize = -1 EnableUsmAllocationPoolManager = -1 ForceTotalWMTPDataSize = -1 +CopyLockedMemoryBeforeWrite = 0 # Please don't edit below this line diff --git a/shared/test/unit_test/command_stream/aub_command_stream_receiver_3_tests.cpp b/shared/test/unit_test/command_stream/aub_command_stream_receiver_3_tests.cpp index f8a9a4e812..ef6a978831 100644 --- a/shared/test/unit_test/command_stream/aub_command_stream_receiver_3_tests.cpp +++ b/shared/test/unit_test/command_stream/aub_command_stream_receiver_3_tests.cpp @@ -145,6 +145,49 @@ HWTEST_F(AubCsrTest, WhenWriteWithAubManagerIsCalledThenAubManagerIsInvokedWithC executionEnvironment->memoryManager->freeGraphicsMemory(allocation2); } +HWTEST_F(AubCsrTest, GivenCopyLockedMemoryBeforeWriteWhenWriteWithAubManagerIsCalledThenAubManagerIsInvokedWithCorrectHintAndParams) { + auto hwInfo = *NEO::defaultHwInfo.get(); + DebugManagerStateRestore dbgRestore; + debugManager.flags.CopyLockedMemoryBeforeWrite.set(true); + + std::unique_ptr executionEnvironment(new ExecutionEnvironment); + DeviceBitfield deviceBitfield(1); + executionEnvironment->prepareRootDeviceEnvironments(1); + uint32_t rootDeviceIndex = 0u; + + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfoAndInitHelpers(&hwInfo); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->initGmm(); + + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->initAubCenter(false, "", CommandStreamReceiverType::aub); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter->getAubManager(); + + executionEnvironment->initializeMemoryManager(); + MockAubManager aubManager; + std::unique_ptr> aubCsr(new MockAubCsr("", false, *executionEnvironment, rootDeviceIndex, deviceBitfield)); + aubCsr->aubManager = &aubManager; + auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(aubCsr.get(), + EngineDescriptorHelper::getDefaultDescriptor({getChosenEngineType(hwInfo), EngineUsage::regular}, + PreemptionHelper::getDefaultPreemptionMode(hwInfo))); + aubCsr->setupContext(*osContext); + aubManager.writeMemory2Called = false; + + auto allocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, true, MemoryConstants::pageSize, AllocationType::linearStream}); + executionEnvironment->memoryManager->lockResource(allocation); + + EXPECT_TRUE(allocation->isLocked()); + aubManager.storeAllocationParams = true; + aubCsr->writeMemoryWithAubManager(*allocation, true, 1, 1); + EXPECT_TRUE(aubManager.writeMemory2Called); + EXPECT_EQ(AubMemDump::DataTypeHintValues::TraceNotype, aubManager.hintToWriteMemory); + ASSERT_EQ(1u, aubManager.storedAllocationParams.size()); + + EXPECT_NE(ptrOffset(allocation->getUnderlyingBuffer(), 1), aubManager.storedAllocationParams[0].memory); + EXPECT_EQ(ptrOffset(allocation->getGpuAddress(), 1), aubManager.storedAllocationParams[0].gfxAddress); + EXPECT_EQ(1u, aubManager.storedAllocationParams[0].size); + + executionEnvironment->memoryManager->freeGraphicsMemory(allocation); +} + using HardwareContextContainerTests = ::testing::Test; TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupportedThenInitialzeHwContextsWithValidIndexes) {