Files
compute-runtime/runtime/program/printf_handler.cpp
Mateusz Jablonski 8ec072d39c Simplify Memory Manager API [3/4]
- remove method allocateGraphicsMemory(size_t size)
- pass allocation type in allocation properties
- set allocation type in allocateGraphicsMemoryInPreferredPool

Change-Id: Ia9296d0ab2f711b7d78aff615cb56b3a246b60ec
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
2018-12-17 10:42:16 +01:00

65 lines
2.6 KiB
C++

/*
* Copyright (C) 2017-2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "printf_handler.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/program/print_formatter.h"
#include "runtime/kernel/kernel.h"
#include "runtime/helpers/dispatch_info.h"
#include "runtime/helpers/ptr_math.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/memory_manager/memory_manager.h"
namespace OCLRT {
PrintfHandler::PrintfHandler(Device &deviceArg) : device(deviceArg) {}
PrintfHandler::~PrintfHandler() {
device.getMemoryManager()->freeGraphicsMemory(printfSurface);
}
PrintfHandler *PrintfHandler::create(const MultiDispatchInfo &multiDispatchInfo, Device &device) {
if (multiDispatchInfo.usesStatelessPrintfSurface() ||
(multiDispatchInfo.peekMainKernel()->checkIfIsParentKernelAndBlocksUsesPrintf())) {
return new PrintfHandler(device);
}
return nullptr;
}
void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo) {
auto printfSurfaceSize = device.getDeviceInfo().printfBufferSize;
if (printfSurfaceSize == 0) {
return;
}
kernel = multiDispatchInfo.peekMainKernel();
printfSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({printfSurfaceSize, GraphicsAllocation::AllocationType::PRINTF_SURFACE});
*reinterpret_cast<uint32_t *>(printfSurface->getUnderlyingBuffer()) = printfSurfaceInitialDataSize;
auto printfPatchAddress = ptrOffset(reinterpret_cast<uintptr_t *>(kernel->getCrossThreadData()),
kernel->getKernelInfo().patchInfo.pAllocateStatelessPrintfSurface->DataParamOffset);
patchWithRequiredSize(printfPatchAddress, kernel->getKernelInfo().patchInfo.pAllocateStatelessPrintfSurface->DataParamSize, (uintptr_t)printfSurface->getGpuAddressToPatch());
if (kernel->requiresSshForBuffers()) {
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(kernel->getSurfaceStateHeap()),
kernel->getKernelInfo().patchInfo.pAllocateStatelessPrintfSurface->SurfaceStateHeapOffset);
void *addressToPatch = printfSurface->getUnderlyingBuffer();
size_t sizeToPatch = printfSurface->getUnderlyingBufferSize();
Buffer::setSurfaceState(&device, surfaceState, sizeToPatch, addressToPatch, printfSurface);
}
}
void PrintfHandler::makeResident(CommandStreamReceiver &commandStreamReceiver) {
commandStreamReceiver.makeResident(*printfSurface);
}
void PrintfHandler::printEnqueueOutput() {
PrintFormatter printFormatter(*kernel, *printfSurface);
printFormatter.printKernelOutput();
}
} // namespace OCLRT