Skip to content

Commit c13889c

Browse files
Fix printf allocation access mode
Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com> Use BCS if CPU access for local memory allocation is not allowed
1 parent 03e617d commit c13889c

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

opencl/source/program/printf_handler.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,20 @@ void PrintfHandler::makeResident(CommandStreamReceiver &commandStreamReceiver) {
8686
}
8787

8888
void PrintfHandler::printEnqueueOutput() {
89+
auto &hwInfo = device.getHardwareInfo();
90+
8991
auto usesStringMap = kernel->getDescriptor().kernelAttributes.flags.usesStringMapForPrintf || nullptr != kernel->getImplicitArgs();
90-
const auto &hwInfoConfig = *HwInfoConfig::get(device.getHardwareInfo().platform.eProductFamily);
92+
const auto &hwInfoConfig = *HwInfoConfig::get(hwInfo.platform.eProductFamily);
9193
auto printfOutputBuffer = reinterpret_cast<const uint8_t *>(printfSurface->getUnderlyingBuffer());
9294
auto printfOutputSize = static_cast<uint32_t>(printfSurface->getUnderlyingBufferSize());
9395
std::unique_ptr<uint8_t[]> printfOutputDecompressed;
94-
if (hwInfoConfig.allowStatelessCompression(device.getHardwareInfo())) {
96+
97+
auto &helper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
98+
99+
if (hwInfoConfig.allowStatelessCompression(hwInfo) || helper.isBlitCopyRequiredForLocalMemory(hwInfo, *printfSurface)) {
95100
printfOutputDecompressed = std::make_unique<uint8_t[]>(printfOutputSize);
96101
printfOutputBuffer = printfOutputDecompressed.get();
97-
auto &bcsEngine = device.getEngine(EngineHelpers::getBcsEngineType(device.getHardwareInfo(), device.getDeviceBitfield(), device.getSelectorCopyEngine(), true), EngineUsage::Regular);
102+
auto &bcsEngine = device.getEngine(EngineHelpers::getBcsEngineType(hwInfo, device.getDeviceBitfield(), device.getSelectorCopyEngine(), true), EngineUsage::Regular);
98103

99104
BlitPropertiesContainer blitPropertiesContainer;
100105
blitPropertiesContainer.push_back(

opencl/test/unit_test/program/printf_handler_tests.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,57 @@ HWTEST_F(PrintfHandlerTests, givenEnabledStatelessCompressionWhenPrintEnqueueOut
160160
}
161161
}
162162

163+
HWTEST_F(PrintfHandlerTests, givenDisallowedLocalMemoryCpuAccessWhenPrintEnqueueOutputIsCalledThenBCSEngineIsUsedToCopyPrintfOutput) {
164+
HardwareInfo hwInfo = *defaultHwInfo;
165+
hwInfo.capabilityTable.blitterOperationsSupported = true;
166+
REQUIRE_BLITTER_OR_SKIP(&hwInfo);
167+
168+
class MockPrintfHandler : public PrintfHandler {
169+
public:
170+
using PrintfHandler::PrintfHandler;
171+
using PrintfHandler::printfSurface;
172+
173+
MockPrintfHandler(ClDevice &device) : PrintfHandler(device) {}
174+
};
175+
176+
DebugManagerStateRestore restore;
177+
DebugManager.flags.ForceLocalMemoryAccessMode.set(static_cast<int32_t>(LocalMemoryAccessMode::CpuAccessDisallowed));
178+
DebugManager.flags.EnableLocalMemory.set(1);
179+
180+
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo));
181+
MockContext context(device.get());
182+
183+
auto kernelInfo = std::make_unique<MockKernelInfo>();
184+
kernelInfo->setPrintfSurface(sizeof(uintptr_t), 0);
185+
186+
auto program = std::make_unique<MockProgram>(&context, false, toClDeviceVector(*device));
187+
188+
uint64_t crossThread[10]{};
189+
auto kernel = std::make_unique<MockKernel>(program.get(), *kernelInfo, *device);
190+
kernel->setCrossThreadData(&crossThread, sizeof(uint64_t) * 8);
191+
192+
MockMultiDispatchInfo multiDispatchInfo(device.get(), kernel.get());
193+
auto printfHandler = std::make_unique<MockPrintfHandler>(*device);
194+
195+
printfHandler->prepareDispatch(multiDispatchInfo);
196+
EXPECT_NE(nullptr, printfHandler->getSurface());
197+
198+
device->getMemoryManager()->freeGraphicsMemory(printfHandler->printfSurface);
199+
200+
auto allocation = new MockGraphicsAllocation(reinterpret_cast<void *>(0x1000), 0x1000);
201+
allocation->memoryPool = MemoryPool::LocalMemory;
202+
203+
printfHandler->printfSurface = allocation;
204+
205+
printfHandler->printEnqueueOutput();
206+
207+
auto &bcsEngine = device->getEngine(EngineHelpers::getBcsEngineType(device->getHardwareInfo(), device->getDeviceBitfield(), device->getSelectorCopyEngine(), true), EngineUsage::Regular);
208+
auto bcsCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(bcsEngine.commandStreamReceiver);
209+
210+
EXPECT_TRUE(bcsCsr->blitBufferCalled >= 1);
211+
EXPECT_EQ(BlitterConstants::BlitDirection::BufferToHostPtr, bcsCsr->receivedBlitProperties[0].blitDirection);
212+
}
213+
163214
HWTEST_F(PrintfHandlerTests, givenPrintfHandlerWhenEnqueueIsBlockedThenDontUsePrintfObjectAfterMove) {
164215
DebugManagerStateRestore restore;
165216
DebugManager.flags.MakeEachEnqueueBlocking.set(true);

0 commit comments

Comments
 (0)