|
| 1 | +/* |
| 2 | + * Copyright (c) 2018, Intel Corporation |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | + * copy of this software and associated documentation files (the "Software"), |
| 6 | + * to deal in the Software without restriction, including without limitation |
| 7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | + * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | + * Software is furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included |
| 12 | + * in all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | + * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + */ |
| 22 | + |
| 23 | +#pragma once |
| 24 | +#include "config.h" |
| 25 | +#include "CL/cl.h" |
| 26 | +#include "runtime/built_ins/built_ins.h" |
| 27 | +#include "runtime/kernel/kernel.h" |
| 28 | +#include "runtime/utilities/vec.h" |
| 29 | + |
| 30 | +#include <array> |
| 31 | +#include <cstdint> |
| 32 | +#include <fstream> |
| 33 | +#include <memory> |
| 34 | +#include <mutex> |
| 35 | +#include <string> |
| 36 | +#include <tuple> |
| 37 | +#include <vector> |
| 38 | + |
| 39 | +namespace OCLRT { |
| 40 | +typedef std::vector<char> BuiltinResourceT; |
| 41 | + |
| 42 | +class Context; |
| 43 | +class Device; |
| 44 | +class MemObj; |
| 45 | +struct MultiDispatchInfo; |
| 46 | +class Program; |
| 47 | + |
| 48 | +class BuiltinDispatchInfoBuilder { |
| 49 | + public: |
| 50 | + struct BuiltinOpParams { |
| 51 | + void *srcPtr = nullptr; |
| 52 | + void *dstPtr = nullptr; |
| 53 | + MemObj *srcMemObj = nullptr; |
| 54 | + MemObj *dstMemObj = nullptr; |
| 55 | + GraphicsAllocation *srcSvmAlloc = nullptr; |
| 56 | + GraphicsAllocation *dstSvmAlloc = nullptr; |
| 57 | + Vec3<size_t> srcOffset = {0, 0, 0}; |
| 58 | + Vec3<size_t> dstOffset = {0, 0, 0}; |
| 59 | + Vec3<size_t> size = {0, 0, 0}; |
| 60 | + size_t srcRowPitch = 0; |
| 61 | + size_t dstRowPitch = 0; |
| 62 | + size_t srcSlicePitch = 0; |
| 63 | + size_t dstSlicePitch = 0; |
| 64 | + uint32_t srcMipLevel = 0; |
| 65 | + uint32_t dstMipLevel = 0; |
| 66 | + }; |
| 67 | + |
| 68 | + BuiltinDispatchInfoBuilder(BuiltIns &kernelLib) : kernelsLib(kernelLib) {} |
| 69 | + |
| 70 | + template <typename... KernelsDescArgsT> |
| 71 | + void populate(Context &context, Device &device, EBuiltInOps operation, const char *options, KernelsDescArgsT &&... desc); |
| 72 | + |
| 73 | + virtual bool buildDispatchInfos(MultiDispatchInfo &multiDispatchInfo, const BuiltinOpParams &operationParams) const { |
| 74 | + return false; |
| 75 | + } |
| 76 | + |
| 77 | + virtual bool buildDispatchInfos(MultiDispatchInfo &multiDispatchInfo, Kernel *kernel, |
| 78 | + const uint32_t dim, const Vec3<size_t> &gws, const Vec3<size_t> &elws, const Vec3<size_t> &offset) const { |
| 79 | + return false; |
| 80 | + } |
| 81 | + |
| 82 | + virtual cl_int validateDispatch(Kernel *kernel, uint32_t inworkDim, const Vec3<size_t> &gws, const Vec3<size_t> &elws, const Vec3<size_t> &offset) const { |
| 83 | + return CL_SUCCESS; |
| 84 | + } |
| 85 | + |
| 86 | + // returns true if argument should be updated in kernel exposed to user code |
| 87 | + virtual bool setExplicitArg(uint32_t argIndex, size_t argSize, const void *argVal, cl_int &err) const { |
| 88 | + return true; |
| 89 | + } |
| 90 | + |
| 91 | + void takeOwnership(Context *context); |
| 92 | + void releaseOwnership(); |
| 93 | + |
| 94 | + protected: |
| 95 | + template <typename KernelNameT, typename... KernelsDescArgsT> |
| 96 | + void grabKernels(KernelNameT &&kernelName, Kernel *&kernelDst, KernelsDescArgsT &&... kernelsDesc) { |
| 97 | + const KernelInfo *ki = prog->getKernelInfo(kernelName); |
| 98 | + cl_int err = 0; |
| 99 | + kernelDst = Kernel::create(prog.get(), *ki, &err); |
| 100 | + kernelDst->isBuiltIn = true; |
| 101 | + usedKernels.push_back(std::unique_ptr<Kernel>(kernelDst)); |
| 102 | + grabKernels(std::forward<KernelsDescArgsT>(kernelsDesc)...); |
| 103 | + } |
| 104 | + |
| 105 | + cl_int grabKernels() { return CL_SUCCESS; } |
| 106 | + |
| 107 | + std::unique_ptr<Program> prog; |
| 108 | + std::vector<std::unique_ptr<Kernel>> usedKernels; |
| 109 | + BuiltIns &kernelsLib; |
| 110 | +}; |
| 111 | + |
| 112 | +} // namespace OCLRT |
0 commit comments