/* * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/source/built_ins/built_ins.h" #include "shared/source/helpers/vec.h" #include "opencl/source/kernel/kernel.h" #include "CL/cl.h" #include "built_in_ops.h" #include #include #include #include #include #include #include #include namespace NEO { typedef std::vector BuiltinResourceT; class Context; class Device; class MemObj; struct MultiDispatchInfo; class Program; struct BuiltinOpParams { void *srcPtr = nullptr; void *dstPtr = nullptr; MemObj *srcMemObj = nullptr; MemObj *dstMemObj = nullptr; GraphicsAllocation *srcSvmAlloc = nullptr; GraphicsAllocation *dstSvmAlloc = nullptr; GraphicsAllocation *transferAllocation = nullptr; //mapAllocation or hostPtrAllocation AuxTranslationDirection auxTranslationDirection = AuxTranslationDirection::None; bool unifiedMemoryArgsRequireMemSync = true; Vec3 srcOffset = {0, 0, 0}; Vec3 dstOffset = {0, 0, 0}; Vec3 size = {0, 0, 0}; size_t srcRowPitch = 0; size_t dstRowPitch = 0; size_t srcSlicePitch = 0; size_t dstSlicePitch = 0; uint32_t srcMipLevel = 0; uint32_t dstMipLevel = 0; }; class BuiltinDispatchInfoBuilder { public: BuiltinDispatchInfoBuilder(BuiltIns &kernelLib) : kernelsLib(kernelLib) {} virtual ~BuiltinDispatchInfoBuilder() = default; template void populate(Device &device, EBuiltInOps::Type operation, const char *options, KernelsDescArgsT &&... desc); virtual bool buildDispatchInfos(MultiDispatchInfo &multiDispatchInfo, const BuiltinOpParams &operationParams) const { return false; } virtual bool buildDispatchInfos(MultiDispatchInfo &multiDispatchInfo, Kernel *kernel, const uint32_t dim, const Vec3 &gws, const Vec3 &elws, const Vec3 &offset) const { return false; } virtual cl_int validateDispatch(Kernel *kernel, uint32_t inworkDim, const Vec3 &gws, const Vec3 &elws, const Vec3 &offset) const { return CL_SUCCESS; } // returns true if argument should be updated in kernel exposed to user code virtual bool setExplicitArg(uint32_t argIndex, size_t argSize, const void *argVal, cl_int &err) const { err = 0; return true; } std::vector> &peekUsedKernels() { return usedKernels; } protected: template void grabKernels(KernelNameT &&kernelName, Kernel *&kernelDst, KernelsDescArgsT &&... kernelsDesc) { const KernelInfo *kernelInfo = prog->getKernelInfo(kernelName); UNRECOVERABLE_IF(nullptr == kernelInfo); cl_int err = 0; kernelDst = Kernel::create(prog.get(), *kernelInfo, &err); kernelDst->isBuiltIn = true; usedKernels.push_back(std::unique_ptr(kernelDst)); grabKernels(std::forward(kernelsDesc)...); } cl_int grabKernels() { return CL_SUCCESS; } std::unique_ptr prog; std::vector> usedKernels; BuiltIns &kernelsLib; }; class BuiltInDispatchBuilderOp { public: static BuiltinDispatchInfoBuilder &getBuiltinDispatchInfoBuilder(EBuiltInOps::Type op, Device &device); static BuiltinDispatchInfoBuilder &getUnknownDispatchInfoBuilder(EBuiltInOps::Type op, Device &device); std::unique_ptr setBuiltinDispatchInfoBuilder(EBuiltInOps::Type op, Device &device, std::unique_ptr newBuilder); }; class BuiltInOwnershipWrapper : public NonCopyableOrMovableClass { public: BuiltInOwnershipWrapper() = default; BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder, Context *context); ~BuiltInOwnershipWrapper(); void takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder, Context *context); protected: BuiltinDispatchInfoBuilder *builder = nullptr; }; } // namespace NEO