2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2023-01-02 11:14:39 +00:00
|
|
|
* Copyright (C) 2018-2023 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"
|
|
|
|
|
|
2023-01-03 16:20:12 +00:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2023-01-02 11:14:39 +00:00
|
|
|
#include "shared/source/compiler_interface/compiler_cache.h"
|
2022-09-29 16:36:48 +02:00
|
|
|
#include "shared/source/device/device.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
2023-01-18 15:52:24 +00:00
|
|
|
#include "shared/source/helpers/blit_properties.h"
|
2023-02-01 16:23:01 +00:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2023-01-03 16:20:12 +00:00
|
|
|
#include "shared/source/kernel/implicit_args.h"
|
2022-12-07 11:51:44 +00:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2023-01-04 09:45:07 +00:00
|
|
|
#include "shared/source/memory_manager/compression_selector.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#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-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
|
|
|
|
2022-09-29 16:36:48 +02:00
|
|
|
PrintfHandler::PrintfHandler(Device &deviceArg) : device(deviceArg) {
|
2021-09-01 00:34:29 +00:00
|
|
|
printfSurfaceInitialDataSizePtr = std::make_unique<uint32_t>();
|
|
|
|
|
*printfSurfaceInitialDataSizePtr = sizeof(uint32_t);
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
PrintfHandler::~PrintfHandler() {
|
|
|
|
|
device.getMemoryManager()->freeGraphicsMemory(printfSurface);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 16:36:48 +02:00
|
|
|
PrintfHandler *PrintfHandler::create(const MultiDispatchInfo &multiDispatchInfo, Device &device) {
|
2019-11-29 17:34:18 +01:00
|
|
|
if (multiDispatchInfo.usesStatelessPrintfSurface()) {
|
|
|
|
|
return new PrintfHandler(device);
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo) {
|
2022-09-29 16:36:48 +02:00
|
|
|
auto printfSurfaceSize = device.getDeviceInfo().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();
|
2022-02-04 13:59:01 +00:00
|
|
|
printfSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, printfSurfaceSize, AllocationType::PRINTF_SURFACE, device.getDeviceBitfield()});
|
2020-07-16 10:35:40 +02:00
|
|
|
|
2023-01-26 16:21:09 +00:00
|
|
|
auto &rootDeviceEnvironment = device.getRootDeviceEnvironment();
|
2022-12-28 22:59:37 +00:00
|
|
|
const auto &productHelper = device.getProductHelper();
|
2020-10-09 11:52:00 +02:00
|
|
|
|
2023-01-26 16:21:09 +00:00
|
|
|
MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *printfSurface),
|
2022-09-29 16:36:48 +02:00
|
|
|
device, printfSurface, 0, printfSurfaceInitialDataSizePtr.get(),
|
2021-09-01 00:34:29 +00:00
|
|
|
sizeof(*printfSurfaceInitialDataSizePtr.get()));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2022-09-29 16:36:48 +02:00
|
|
|
const auto &printfSurfaceArg = kernel->getKernelInfo().kernelDescriptor.payloadMappings.implicitArgs.printfSurfaceAddress;
|
|
|
|
|
auto printfPatchAddress = ptrOffset(reinterpret_cast<uintptr_t *>(kernel->getCrossThreadData()), printfSurfaceArg.stateless);
|
|
|
|
|
patchWithRequiredSize(printfPatchAddress, printfSurfaceArg.pointerSize, (uintptr_t)printfSurface->getGpuAddressToPatch());
|
|
|
|
|
if (isValidOffset(printfSurfaceArg.bindful)) {
|
|
|
|
|
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(kernel->getSurfaceStateHeap()), printfSurfaceArg.bindful);
|
|
|
|
|
void *addressToPatch = printfSurface->getUnderlyingBuffer();
|
|
|
|
|
size_t sizeToPatch = printfSurface->getUnderlyingBufferSize();
|
|
|
|
|
Buffer::setSurfaceState(&device, surfaceState, false, false, sizeToPatch, addressToPatch, 0, printfSurface, 0, 0,
|
|
|
|
|
kernel->getKernelInfo().kernelDescriptor.kernelAttributes.flags.useGlobalAtomics,
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-05 16:52:25 +00:00
|
|
|
bool PrintfHandler::printEnqueueOutput() {
|
2023-01-26 16:21:09 +00:00
|
|
|
auto &rootDeviceEnvironment = device.getRootDeviceEnvironment();
|
2022-02-14 16:05:39 +00:00
|
|
|
auto usesStringMap = kernel->getDescriptor().kernelAttributes.usesStringMap();
|
2022-12-28 22:59:37 +00:00
|
|
|
const auto &productHelper = device.getProductHelper();
|
2021-09-22 13:16:09 +00:00
|
|
|
auto printfOutputBuffer = reinterpret_cast<const uint8_t *>(printfSurface->getUnderlyingBuffer());
|
|
|
|
|
auto printfOutputSize = static_cast<uint32_t>(printfSurface->getUnderlyingBufferSize());
|
|
|
|
|
std::unique_ptr<uint8_t[]> printfOutputDecompressed;
|
2021-12-14 19:14:27 +00:00
|
|
|
|
2023-01-26 16:21:09 +00:00
|
|
|
if (CompressionSelector::allowStatelessCompression() || productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *printfSurface)) {
|
2021-09-22 13:16:09 +00:00
|
|
|
printfOutputDecompressed = std::make_unique<uint8_t[]>(printfOutputSize);
|
|
|
|
|
printfOutputBuffer = printfOutputDecompressed.get();
|
2023-01-26 16:21:09 +00:00
|
|
|
auto &bcsEngine = device.getEngine(EngineHelpers::getBcsEngineType(rootDeviceEnvironment, 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,
|
2021-09-22 13:16:09 +00:00
|
|
|
printfOutputDecompressed.get(),
|
2021-09-01 00:34:29 +00:00
|
|
|
printfSurface->getGpuAddress(),
|
2021-09-22 13:16:09 +00:00
|
|
|
0, 0, 0, Vec3<size_t>(printfOutputSize, 0, 0), 0, 0, 0, 0));
|
2022-05-05 16:52:25 +00:00
|
|
|
|
2022-09-29 16:36:48 +02:00
|
|
|
const auto newTaskCount = bcsEngine.commandStreamReceiver->flushBcsTask(blitPropertiesContainer, true, false, device);
|
2022-11-04 13:57:42 +00:00
|
|
|
if (newTaskCount > CompletionStamp::notReady) {
|
2022-05-05 16:52:25 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-07-29 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-22 13:16:09 +00:00
|
|
|
PrintFormatter printFormatter(printfOutputBuffer, printfOutputSize, kernel->is32Bit(),
|
|
|
|
|
usesStringMap ? &kernel->getDescriptor().kernelMetadata.printfStringsMap : nullptr);
|
2017-12-21 00:45:38 +01:00
|
|
|
printFormatter.printKernelOutput();
|
2022-05-05 16:52:25 +00:00
|
|
|
|
|
|
|
|
return true;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2022-05-05 16:52:25 +00:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|