2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 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"
|
2020-07-16 16:35:40 +08:00
|
|
|
#include "shared/source/helpers/blit_commands_helper.h"
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#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-03-20 18:15:25 +08:00
|
|
|
#include "opencl/source/cl_device/cl_device.h"
|
2021-03-03 20:25:26 +08:00
|
|
|
#include "opencl/source/context/context.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#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-07-16 16:35:40 +08:00
|
|
|
const uint32_t PrintfHandler::printfSurfaceInitialDataSize;
|
|
|
|
|
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) {
|
2020-03-12 16:33:20 +08:00
|
|
|
auto printfSurfaceSize = device.getSharedDeviceInfo().printfBufferSize;
|
2017-12-21 07:45:38 +08:00
|
|
|
if (printfSurfaceSize == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-19 02:39:32 +08:00
|
|
|
auto rootDeviceIndex = device.getRootDeviceIndex();
|
2018-08-17 21:13:04 +08:00
|
|
|
kernel = multiDispatchInfo.peekMainKernel();
|
2020-11-19 02:39:32 +08:00
|
|
|
printfSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, printfSurfaceSize, GraphicsAllocation::AllocationType::PRINTF_SURFACE, device.getDeviceBitfield()});
|
2020-07-16 16:35:40 +08:00
|
|
|
|
|
|
|
auto &hwInfo = device.getHardwareInfo();
|
|
|
|
auto &helper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
2020-10-09 17:52:00 +08:00
|
|
|
|
|
|
|
MemoryTransferHelper::transferMemoryToAllocation(helper.isBlitCopyRequiredForLocalMemory(hwInfo, *printfSurface),
|
|
|
|
device.getDevice(), printfSurface, 0, &printfSurfaceInitialDataSize,
|
|
|
|
sizeof(printfSurfaceInitialDataSize));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-03-22 23:26:03 +08:00
|
|
|
const auto &printfSurfaceArg = kernel->getKernelInfo().kernelDescriptor.payloadMappings.implicitArgs.printfSurfaceAddress;
|
2021-03-22 19:06:23 +08:00
|
|
|
auto printfPatchAddress = ptrOffset(reinterpret_cast<uintptr_t *>(kernel->getCrossThreadData()), printfSurfaceArg.stateless);
|
2021-02-16 22:28:59 +08:00
|
|
|
patchWithRequiredSize(printfPatchAddress, printfSurfaceArg.pointerSize, (uintptr_t)printfSurface->getGpuAddressToPatch());
|
|
|
|
if (isValidOffset(printfSurfaceArg.bindful)) {
|
2021-03-22 23:26:03 +08:00
|
|
|
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(kernel->getSurfaceStateHeap()), printfSurfaceArg.bindful);
|
2017-12-21 07:45:38 +08:00
|
|
|
void *addressToPatch = printfSurface->getUnderlyingBuffer();
|
|
|
|
size_t sizeToPatch = printfSurface->getUnderlyingBufferSize();
|
2021-03-03 20:25:26 +08:00
|
|
|
Buffer::setSurfaceState(&device.getDevice(), surfaceState, false, false, sizeToPatch, addressToPatch, 0, printfSurface, 0, 0,
|
2021-03-22 23:26:03 +08:00
|
|
|
kernel->getKernelInfo().kernelDescriptor.kernelAttributes.flags.useGlobalAtomics,
|
2021-03-30 01:06:29 +08:00
|
|
|
kernel->areMultipleSubDevicesInContext());
|
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()),
|
2021-03-22 23:26:03 +08:00
|
|
|
kernel->is32Bit(), kernel->getKernelInfo().kernelDescriptor.kernelMetadata.printfStringsMap);
|
2017-12-21 07:45:38 +08:00
|
|
|
printFormatter.printKernelOutput();
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|