From d7b6c7b69e9bde858490567cba7d2b99ebbdc367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Zwoli=C5=84ski?= Date: Tue, 25 Nov 2025 08:40:07 +0000 Subject: [PATCH] fix: add AllocationType::printfSurface to is2MBPageAllocationType MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit printfSurface is always allocated with size 4 MB it doesn't need aligning. Adding it to is2MBPageAllocationType for clarity and certainty. Related-To: NEO-12287 Signed-off-by: Fabian ZwoliƄski --- .../source/printf_handler/printf_handler.cpp | 4 ++++ opencl/source/program/printf_handler.cpp | 10 +++++++--- .../memory_manager/graphics_allocation.h | 3 ++- .../graphics_allocation_tests.cpp | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/level_zero/core/source/printf_handler/printf_handler.cpp b/level_zero/core/source/printf_handler/printf_handler.cpp index ee87a3788b..20fe9d8080 100644 --- a/level_zero/core/source/printf_handler/printf_handler.cpp +++ b/level_zero/core/source/printf_handler/printf_handler.cpp @@ -24,6 +24,10 @@ NEO::GraphicsAllocation *PrintfHandler::createPrintfBuffer(Device *device) { NEO::AllocationProperties properties( device->getRootDeviceIndex(), PrintfHandler::printfBufferSize, NEO::AllocationType::printfSurface, device->getNEODevice()->getDeviceBitfield()); properties.alignment = MemoryConstants::pageSize64k; + + DEBUG_BREAK_IF(device->getNEODevice()->getProductHelper().is2MBLocalMemAlignmentEnabled() && + !isAligned(properties.size, MemoryConstants::pageSize2M)); + auto allocation = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties); *reinterpret_cast(allocation->getUnderlyingBuffer()) = diff --git a/opencl/source/program/printf_handler.cpp b/opencl/source/program/printf_handler.cpp index 61839dba48..991a9633fd 100644 --- a/opencl/source/program/printf_handler.cpp +++ b/opencl/source/program/printf_handler.cpp @@ -44,13 +44,17 @@ void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo) if (printfSurfaceSize == 0) { return; } - auto rootDeviceIndex = device.getRootDeviceIndex(); - kernel = multiDispatchInfo.peekMainKernel(); - printfSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, printfSurfaceSize, AllocationType::printfSurface, device.getDeviceBitfield()}); auto &rootDeviceEnvironment = device.getRootDeviceEnvironment(); const auto &productHelper = device.getProductHelper(); + DEBUG_BREAK_IF(productHelper.is2MBLocalMemAlignmentEnabled() && + !isAligned(printfSurfaceSize, MemoryConstants::pageSize2M)); + + auto rootDeviceIndex = device.getRootDeviceIndex(); + kernel = multiDispatchInfo.peekMainKernel(); + printfSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, printfSurfaceSize, AllocationType::printfSurface, device.getDeviceBitfield()}); + MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *printfSurface), device, printfSurface, 0, printfSurfaceInitialDataSizePtr.get(), sizeof(*printfSurfaceInitialDataSizePtr.get())); diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index 0dc2b2eef0..c11254347d 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -261,7 +261,8 @@ class GraphicsAllocation : public IDNode, NEO::NonCopyableAn static bool is2MBPageAllocationType(AllocationType type) { return type == AllocationType::timestampPacketTagBuffer || type == AllocationType::gpuTimestampDeviceBuffer || - type == AllocationType::profilingTagBuffer; + type == AllocationType::profilingTagBuffer || + type == AllocationType::printfSurface; } static bool isAccessedFromCommandStreamer(AllocationType allocationType) { diff --git a/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp b/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp index ddaa51df0d..580d768e59 100644 --- a/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp +++ b/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp @@ -215,6 +215,24 @@ TEST(GraphicsAllocationTest, whenAllocationTypeIsImageThenAllocationIsNotLockabl EXPECT_FALSE(GraphicsAllocation::isLockable(AllocationType::image)); } +TEST(GraphicsAllocationTest, givenAllocationTypeWhenCheckingIs2MBPageAllocationTypeThenReturnTrue) { + for (uint32_t i = 0; i < static_cast(AllocationType::count); i++) { + auto allocType = static_cast(i); + + switch (allocType) { + case AllocationType::timestampPacketTagBuffer: + case AllocationType::gpuTimestampDeviceBuffer: + case AllocationType::profilingTagBuffer: + case AllocationType::printfSurface: + EXPECT_TRUE(GraphicsAllocation::is2MBPageAllocationType(allocType)); + break; + default: + EXPECT_FALSE(GraphicsAllocation::is2MBPageAllocationType(allocType)); + break; + } + } +} + TEST(GraphicsAllocationTest, givenNumMemoryBanksWhenGettingNumHandlesForKmdSharedAllocationThenReturnCorrectValue) { DebugManagerStateRestore restore;