2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-14 21:32:11 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-17 20:03:37 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "printf_handler.h"
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
|
|
|
#include "shared/source/program/print_formatter.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/device/cl_device.h"
|
|
|
|
#include "opencl/source/helpers/dispatch_info.h"
|
|
|
|
#include "opencl/source/kernel/kernel.h"
|
|
|
|
#include "opencl/source/mem_obj/buffer.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
PrintfHandler::PrintfHandler(ClDevice &deviceArg) : device(deviceArg) {}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
PrintfHandler::~PrintfHandler() {
|
|
|
|
device.getMemoryManager()->freeGraphicsMemory(printfSurface);
|
|
|
|
}
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
PrintfHandler *PrintfHandler::create(const MultiDispatchInfo &multiDispatchInfo, ClDevice &device) {
|
2019-11-30 00:34:18 +08:00
|
|
|
if (multiDispatchInfo.usesStatelessPrintfSurface()) {
|
|
|
|
return new PrintfHandler(device);
|
|
|
|
}
|
|
|
|
auto mainKernel = multiDispatchInfo.peekMainKernel();
|
|
|
|
if ((mainKernel != nullptr) &&
|
|
|
|
mainKernel->checkIfIsParentKernelAndBlocksUsesPrintf()) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return new PrintfHandler(device);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo) {
|
|
|
|
auto printfSurfaceSize = device.getDeviceInfo().printfBufferSize;
|
|
|
|
if (printfSurfaceSize == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-17 21:13:04 +08:00
|
|
|
kernel = multiDispatchInfo.peekMainKernel();
|
2019-11-07 21:15:04 +08:00
|
|
|
printfSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({device.getRootDeviceIndex(), printfSurfaceSize, GraphicsAllocation::AllocationType::PRINTF_SURFACE});
|
2017-12-21 07:45:38 +08:00
|
|
|
*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();
|
2020-02-21 06:54:48 +08:00
|
|
|
Buffer::setSurfaceState(&device.getDevice(), surfaceState, sizeToPatch, addressToPatch, 0, printfSurface, 0, 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintfHandler::makeResident(CommandStreamReceiver &commandStreamReceiver) {
|
|
|
|
commandStreamReceiver.makeResident(*printfSurface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintfHandler::printEnqueueOutput() {
|
2019-05-23 19:11:12 +08:00
|
|
|
PrintFormatter printFormatter(reinterpret_cast<const uint8_t *>(printfSurface->getUnderlyingBuffer()), static_cast<uint32_t>(printfSurface->getUnderlyingBufferSize()),
|
|
|
|
kernel->is32Bit(), kernel->getKernelInfo().patchInfo.stringDataMap);
|
2017-12-21 07:45:38 +08:00
|
|
|
printFormatter.printKernelOutput();
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|