/* * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "core/command_stream/linear_stream.h" #include "runtime/helpers/completion_stamp.h" #include "runtime/helpers/hw_info.h" #include "runtime/helpers/properties_helper.h" #include "runtime/helpers/timestamp_packet.h" #include "runtime/indirect_heap/indirect_heap.h" #include "runtime/utilities/iflist.h" #include #include namespace NEO { class CommandQueue; class CommandStreamReceiver; class InternalAllocationStorage; class Kernel; class MemObj; class Surface; class PrintfHandler; struct HwTimeStamps; class TimestampPacketContainer; template struct TagNode; enum MapOperationType { MAP, UNMAP }; struct KernelOperation { protected: struct ResourceCleaner { ResourceCleaner() = delete; ResourceCleaner(InternalAllocationStorage *storageForAllocations) : storageForAllocations(storageForAllocations){}; template void operator()(ObjectT *object); InternalAllocationStorage *storageForAllocations = nullptr; } resourceCleaner{nullptr}; using LinearStreamUniquePtrT = std::unique_ptr; using IndirectHeapUniquePtrT = std::unique_ptr; public: KernelOperation() = delete; KernelOperation(LinearStream *commandStream, InternalAllocationStorage &storageForAllocations) { resourceCleaner.storageForAllocations = &storageForAllocations; this->commandStream = LinearStreamUniquePtrT(commandStream, resourceCleaner); } void setHeaps(IndirectHeap *dsh, IndirectHeap *ioh, IndirectHeap *ssh) { this->dsh = IndirectHeapUniquePtrT(dsh, resourceCleaner); this->ioh = IndirectHeapUniquePtrT(ioh, resourceCleaner); this->ssh = IndirectHeapUniquePtrT(ssh, resourceCleaner); } ~KernelOperation() { if (ioh.get() == dsh.get()) { ioh.release(); } } LinearStreamUniquePtrT commandStream{nullptr, resourceCleaner}; IndirectHeapUniquePtrT dsh{nullptr, resourceCleaner}; IndirectHeapUniquePtrT ioh{nullptr, resourceCleaner}; IndirectHeapUniquePtrT ssh{nullptr, resourceCleaner}; size_t surfaceStateHeapSizeEM = 0; }; class Command : public IFNode { public: // returns command's taskCount obtained from completion stamp // as acquired from command stream receiver virtual CompletionStamp &submit(uint32_t taskLevel, bool terminated) = 0; Command() = delete; Command(CommandQueue &commandQueue); Command(CommandQueue &commandQueue, std::unique_ptr &kernelOperation); virtual ~Command(); virtual LinearStream *getCommandStream() { return nullptr; } void setTimestampPacketNode(TimestampPacketContainer ¤t, TimestampPacketContainer &previous); void setEventsRequest(EventsRequest &eventsRequest); void makeTimestampPacketsResident(); TagNode *timestamp = nullptr; CompletionStamp completionStamp = {}; protected: CommandQueue &commandQueue; std::unique_ptr kernelOperation; std::unique_ptr currentTimestampPacketNodes; std::unique_ptr previousTimestampPacketNodes; EventsRequest eventsRequest = {0, nullptr, nullptr}; std::vector eventsWaitlist; }; class CommandMapUnmap : public Command { public: CommandMapUnmap(MapOperationType operationType, MemObj &memObj, MemObjSizeArray ©Size, MemObjOffsetArray ©Offset, bool readOnly, CommandQueue &commandQueue); ~CommandMapUnmap() override = default; CompletionStamp &submit(uint32_t taskLevel, bool terminated) override; private: MemObj &memObj; MemObjSizeArray copySize; MemObjOffsetArray copyOffset; bool readOnly; MapOperationType operationType; }; class CommandComputeKernel : public Command { public: CommandComputeKernel(CommandQueue &commandQueue, std::unique_ptr &kernelOperation, std::vector &surfaces, bool flushDC, bool usesSLM, bool ndRangeKernel, std::unique_ptr printfHandler, PreemptionMode preemptionMode, Kernel *kernel, uint32_t kernelCount); ~CommandComputeKernel() override; CompletionStamp &submit(uint32_t taskLevel, bool terminated) override; LinearStream *getCommandStream() override { return kernelOperation->commandStream.get(); } protected: std::vector surfaces; bool flushDC; bool slmUsed; bool NDRangeKernel; std::unique_ptr printfHandler; Kernel *kernel; uint32_t kernelCount; PreemptionMode preemptionMode; }; class CommandMarker : public Command { public: using Command::Command; CompletionStamp &submit(uint32_t taskLevel, bool terminated) override; }; } // namespace NEO