2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-17 14:03:37 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "printf_handler.h"
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
2020-07-16 10:35:40 +02:00
|
|
|
#include "shared/source/helpers/blit_commands_helper.h"
|
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2021-09-08 15:07:46 +00:00
|
|
|
#include "shared/source/os_interface/hw_info_config.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/program/print_formatter.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-03-20 11:15:25 +01:00
|
|
|
#include "opencl/source/cl_device/cl_device.h"
|
2021-03-03 12:25:26 +00:00
|
|
|
#include "opencl/source/context/context.h"
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/helpers/dispatch_info.h"
|
|
|
|
|
#include "opencl/source/kernel/kernel.h"
|
|
|
|
|
#include "opencl/source/mem_obj/buffer.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-09-01 00:34:29 +00:00
|
|
|
PrintfHandler::PrintfHandler(ClDevice &deviceArg) : device(deviceArg) {
|
|
|
|
|
printfSurfaceInitialDataSizePtr = std::make_unique<uint32_t>();
|
|
|
|
|
*printfSurfaceInitialDataSizePtr = sizeof(uint32_t);
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
PrintfHandler::~PrintfHandler() {
|
|
|
|
|
device.getMemoryManager()->freeGraphicsMemory(printfSurface);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
PrintfHandler *PrintfHandler::create(const MultiDispatchInfo &multiDispatchInfo, ClDevice &device) {
|
2019-11-29 17:34:18 +01:00
|
|
|
if (multiDispatchInfo.usesStatelessPrintfSurface()) {
|
|
|
|
|
return new PrintfHandler(device);
|
|
|
|
|
}
|
|
|
|
|
auto mainKernel = multiDispatchInfo.peekMainKernel();
|
|
|
|
|
if ((mainKernel != nullptr) &&
|
|
|
|
|
mainKernel->checkIfIsParentKernelAndBlocksUsesPrintf()) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return new PrintfHandler(device);
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo) {
|
2020-03-12 09:33:20 +01:00
|
|
|
auto printfSurfaceSize = device.getSharedDeviceInfo().printfBufferSize;
|
2017-12-21 00:45:38 +01:00
|
|
|
if (printfSurfaceSize == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-11-18 18:39:32 +00:00
|
|
|
auto rootDeviceIndex = device.getRootDeviceIndex();
|
2018-08-17 15:13:04 +02:00
|
|
|
kernel = multiDispatchInfo.peekMainKernel();
|
2020-11-18 18:39:32 +00:00
|
|
|
printfSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, printfSurfaceSize, GraphicsAllocation::AllocationType::PRINTF_SURFACE, device.getDeviceBitfield()});
|
2020-07-16 10:35:40 +02:00
|
|
|
|
|
|
|
|
auto &hwInfo = device.getHardwareInfo();
|
|
|
|
|
auto &helper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
2020-10-09 11:52:00 +02:00
|
|
|
|
|
|
|
|
MemoryTransferHelper::transferMemoryToAllocation(helper.isBlitCopyRequiredForLocalMemory(hwInfo, *printfSurface),
|
2021-09-01 00:34:29 +00:00
|
|
|
device.getDevice(), printfSurface, 0, printfSurfaceInitialDataSizePtr.get(),
|
|
|
|
|
sizeof(*printfSurfaceInitialDataSizePtr.get()));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-03-22 15:26:03 +00:00
|
|
|
const auto &printfSurfaceArg = kernel->getKernelInfo().kernelDescriptor.payloadMappings.implicitArgs.printfSurfaceAddress;
|
2021-03-22 11:06:23 +00:00
|
|
|
auto printfPatchAddress = ptrOffset(reinterpret_cast<uintptr_t *>(kernel->getCrossThreadData()), printfSurfaceArg.stateless);
|
2021-02-16 15:28:59 +01:00
|
|
|
patchWithRequiredSize(printfPatchAddress, printfSurfaceArg.pointerSize, (uintptr_t)printfSurface->getGpuAddressToPatch());
|
|
|
|
|
if (isValidOffset(printfSurfaceArg.bindful)) {
|
2021-03-22 15:26:03 +00:00
|
|
|
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(kernel->getSurfaceStateHeap()), printfSurfaceArg.bindful);
|
2017-12-21 00:45:38 +01:00
|
|
|
void *addressToPatch = printfSurface->getUnderlyingBuffer();
|
|
|
|
|
size_t sizeToPatch = printfSurface->getUnderlyingBufferSize();
|
2021-03-03 12:25:26 +00:00
|
|
|
Buffer::setSurfaceState(&device.getDevice(), surfaceState, false, false, sizeToPatch, addressToPatch, 0, printfSurface, 0, 0,
|
2021-03-22 15:26:03 +00:00
|
|
|
kernel->getKernelInfo().kernelDescriptor.kernelAttributes.flags.useGlobalAtomics,
|
2021-03-29 17:06:29 +00:00
|
|
|
kernel->areMultipleSubDevicesInContext());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2021-09-08 13:20:44 +00:00
|
|
|
auto pImplicitArgs = kernel->getImplicitArgs();
|
|
|
|
|
if (pImplicitArgs) {
|
|
|
|
|
pImplicitArgs->printfBufferPtr = printfSurface->getGpuAddress();
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrintfHandler::makeResident(CommandStreamReceiver &commandStreamReceiver) {
|
|
|
|
|
commandStreamReceiver.makeResident(*printfSurface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrintfHandler::printEnqueueOutput() {
|
2021-09-08 15:07:46 +00:00
|
|
|
const auto &hwInfoConfig = *HwInfoConfig::get(device.getHardwareInfo().platform.eProductFamily);
|
|
|
|
|
if (hwInfoConfig.allowStatelessCompression(device.getHardwareInfo())) {
|
2021-09-01 00:34:29 +00:00
|
|
|
auto printOutputSize = static_cast<uint32_t>(printfSurface->getUnderlyingBufferSize());
|
|
|
|
|
auto printOutputDecompressed = std::make_unique<uint8_t[]>(printOutputSize);
|
2021-08-17 14:15:49 +00:00
|
|
|
auto &bcsEngine = device.getEngine(EngineHelpers::getBcsEngineType(device.getHardwareInfo(), device.getDeviceBitfield(), device.getSelectorCopyEngine(), true), EngineUsage::Regular);
|
2021-09-01 00:34:29 +00:00
|
|
|
|
2021-07-29 11:45:53 +00:00
|
|
|
BlitPropertiesContainer blitPropertiesContainer;
|
|
|
|
|
blitPropertiesContainer.push_back(
|
2021-09-01 00:34:29 +00:00
|
|
|
BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::BufferToHostPtr,
|
|
|
|
|
*bcsEngine.commandStreamReceiver, printfSurface, nullptr,
|
|
|
|
|
printOutputDecompressed.get(),
|
|
|
|
|
printfSurface->getGpuAddress(),
|
|
|
|
|
0, 0, 0, Vec3<size_t>(printOutputSize, 0, 0), 0, 0, 0, 0));
|
2021-07-29 11:45:53 +00:00
|
|
|
bcsEngine.commandStreamReceiver->blitBuffer(blitPropertiesContainer, true, false, device.getDevice());
|
2021-09-01 00:34:29 +00:00
|
|
|
|
|
|
|
|
PrintFormatter printFormatter(printOutputDecompressed.get(), printOutputSize,
|
|
|
|
|
kernel->is32Bit(),
|
|
|
|
|
kernel->getDescriptor().kernelAttributes.flags.usesStringMapForPrintf ? &kernel->getDescriptor().kernelMetadata.printfStringsMap : nullptr);
|
|
|
|
|
printFormatter.printKernelOutput();
|
|
|
|
|
return;
|
2021-07-29 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-23 13:11:12 +02:00
|
|
|
PrintFormatter printFormatter(reinterpret_cast<const uint8_t *>(printfSurface->getUnderlyingBuffer()), static_cast<uint32_t>(printfSurface->getUnderlyingBufferSize()),
|
2021-03-17 15:31:36 +01:00
|
|
|
kernel->is32Bit(),
|
|
|
|
|
kernel->getDescriptor().kernelAttributes.flags.usesStringMapForPrintf ? &kernel->getDescriptor().kernelMetadata.printfStringsMap : nullptr);
|
2017-12-21 00:45:38 +01:00
|
|
|
printFormatter.printKernelOutput();
|
|
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|