diff --git a/opencl/source/program/printf_handler.cpp b/opencl/source/program/printf_handler.cpp index d45f1e4ca1..a91220a535 100644 --- a/opencl/source/program/printf_handler.cpp +++ b/opencl/source/program/printf_handler.cpp @@ -86,15 +86,20 @@ void PrintfHandler::makeResident(CommandStreamReceiver &commandStreamReceiver) { } void PrintfHandler::printEnqueueOutput() { + auto &hwInfo = device.getHardwareInfo(); + auto usesStringMap = kernel->getDescriptor().kernelAttributes.flags.usesStringMapForPrintf || nullptr != kernel->getImplicitArgs(); - const auto &hwInfoConfig = *HwInfoConfig::get(device.getHardwareInfo().platform.eProductFamily); + const auto &hwInfoConfig = *HwInfoConfig::get(hwInfo.platform.eProductFamily); auto printfOutputBuffer = reinterpret_cast(printfSurface->getUnderlyingBuffer()); auto printfOutputSize = static_cast(printfSurface->getUnderlyingBufferSize()); std::unique_ptr printfOutputDecompressed; - if (hwInfoConfig.allowStatelessCompression(device.getHardwareInfo())) { + + auto &helper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); + + if (hwInfoConfig.allowStatelessCompression(hwInfo) || helper.isBlitCopyRequiredForLocalMemory(hwInfo, *printfSurface)) { printfOutputDecompressed = std::make_unique(printfOutputSize); printfOutputBuffer = printfOutputDecompressed.get(); - auto &bcsEngine = device.getEngine(EngineHelpers::getBcsEngineType(device.getHardwareInfo(), device.getDeviceBitfield(), device.getSelectorCopyEngine(), true), EngineUsage::Regular); + auto &bcsEngine = device.getEngine(EngineHelpers::getBcsEngineType(hwInfo, device.getDeviceBitfield(), device.getSelectorCopyEngine(), true), EngineUsage::Regular); BlitPropertiesContainer blitPropertiesContainer; blitPropertiesContainer.push_back( diff --git a/opencl/test/unit_test/program/printf_handler_tests.cpp b/opencl/test/unit_test/program/printf_handler_tests.cpp index 2d75b7c36c..d87742802e 100644 --- a/opencl/test/unit_test/program/printf_handler_tests.cpp +++ b/opencl/test/unit_test/program/printf_handler_tests.cpp @@ -160,6 +160,57 @@ HWTEST_F(PrintfHandlerTests, givenEnabledStatelessCompressionWhenPrintEnqueueOut } } +HWTEST_F(PrintfHandlerTests, givenDisallowedLocalMemoryCpuAccessWhenPrintEnqueueOutputIsCalledThenBCSEngineIsUsedToCopyPrintfOutput) { + HardwareInfo hwInfo = *defaultHwInfo; + hwInfo.capabilityTable.blitterOperationsSupported = true; + REQUIRE_BLITTER_OR_SKIP(&hwInfo); + + class MockPrintfHandler : public PrintfHandler { + public: + using PrintfHandler::PrintfHandler; + using PrintfHandler::printfSurface; + + MockPrintfHandler(ClDevice &device) : PrintfHandler(device) {} + }; + + DebugManagerStateRestore restore; + DebugManager.flags.ForceLocalMemoryAccessMode.set(static_cast(LocalMemoryAccessMode::CpuAccessDisallowed)); + DebugManager.flags.EnableLocalMemory.set(1); + + auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + MockContext context(device.get()); + + auto kernelInfo = std::make_unique(); + kernelInfo->setPrintfSurface(sizeof(uintptr_t), 0); + + auto program = std::make_unique(&context, false, toClDeviceVector(*device)); + + uint64_t crossThread[10]{}; + auto kernel = std::make_unique(program.get(), *kernelInfo, *device); + kernel->setCrossThreadData(&crossThread, sizeof(uint64_t) * 8); + + MockMultiDispatchInfo multiDispatchInfo(device.get(), kernel.get()); + auto printfHandler = std::make_unique(*device); + + printfHandler->prepareDispatch(multiDispatchInfo); + EXPECT_NE(nullptr, printfHandler->getSurface()); + + device->getMemoryManager()->freeGraphicsMemory(printfHandler->printfSurface); + + auto allocation = new MockGraphicsAllocation(reinterpret_cast(0x1000), 0x1000); + allocation->memoryPool = MemoryPool::LocalMemory; + + printfHandler->printfSurface = allocation; + + printfHandler->printEnqueueOutput(); + + auto &bcsEngine = device->getEngine(EngineHelpers::getBcsEngineType(device->getHardwareInfo(), device->getDeviceBitfield(), device->getSelectorCopyEngine(), true), EngineUsage::Regular); + auto bcsCsr = static_cast *>(bcsEngine.commandStreamReceiver); + + EXPECT_TRUE(bcsCsr->blitBufferCalled >= 1); + EXPECT_EQ(BlitterConstants::BlitDirection::BufferToHostPtr, bcsCsr->receivedBlitProperties[0].blitDirection); +} + HWTEST_F(PrintfHandlerTests, givenPrintfHandlerWhenEnqueueIsBlockedThenDontUsePrintfObjectAfterMove) { DebugManagerStateRestore restore; DebugManager.flags.MakeEachEnqueueBlocking.set(true);