1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*
* Copyright (c) 2017-2019 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef ARM_COMPUTE_IGCKERNEL_H
#define ARM_COMPUTE_IGCKERNEL_H
#include "arm_compute/core/GLES_COMPUTE/GCKernelLibrary.h"
#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h"
#include "arm_compute/core/GPUTarget.h"
#include "arm_compute/core/IKernel.h"
namespace arm_compute
{
class IGCTensor;
class Window;
/** Common interface for all the GLES kernels */
class IGCKernel : public IKernel
{
public:
/** Constructor */
IGCKernel();
/** Returns a reference to the GLES kernel of this object.
*
* @return A reference to the GLES kernel of this object.
*/
GCKernel &kernel();
/** Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx.
*
* @param[in] idx Index at which to start adding the tensor's arguments.Input and output tensor will have sperated index, multiple indices start from 1, single index have to be set to 0.
* @param[in] tensor Tensor to set as an argument of the object's kernel.
* @param[in] binding_point Tensor's binding point in this kernel.
* @param[in] window Window the kernel will be executed on.
*/
void add_1D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window);
/** Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx.
*
* @param[in] idx Index at which to start adding the tensor's arguments.Input and output tensor will have sperated index, multiple indices start from 1, single index have to be set to 0.
* @param[in] tensor Tensor to set as an argument of the object's kernel.
* @param[in] binding_point Tensor's binding point in this kernel.
* @param[in] window Window the kernel will be executed on.
*/
void add_2D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window);
/** Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
*
* @param[in] idx Index at which to start adding the tensor's arguments.Input and output tensor will have sperated index, multiple indices start from 1, single index have to be set to 0.
* @param[in] tensor Tensor to set as an argument of the object's kernel.
* @param[in] binding_point Tensor's binding point in this kernel.
* @param[in] window Window the kernel will be executed on.
*/
void add_3D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window);
/** Returns the number of arguments enqueued per 1D tensor object.
*
* @return The number of arguments enqueues per 1D tensor object.
*/
unsigned int num_arguments_per_1D_tensor() const;
/** Returns the number of arguments enqueued per 2D tensor object.
*
* @return The number of arguments enqueues per 2D tensor object.
*/
unsigned int num_arguments_per_2D_tensor() const;
/** Returns the number of arguments enqueued per 3D tensor object.
*
* @return The number of arguments enqueues per 3D tensor object.
*/
unsigned int num_arguments_per_3D_tensor() const;
/** Enqueue the OpenGL ES shader to process the given window
*
* @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
*/
virtual void run(const Window &window) = 0;
/** Set the Local-Workgroup-Size hint
*
* @note This method should be called after the configuration of the kernel
*
* @param[in] lws_hint Local-Workgroup-Size to use
*/
void set_lws_hint(gles::NDRange &lws_hint)
{
_lws_hint = lws_hint;
}
/** Set the targeted GPU architecture
*
* @param[in] target The targeted GPU architecture
*/
void set_target(GPUTarget target)
{
_target = target;
}
/** Get the targeted GPU architecture
*
* @return The targeted GPU architecture.
*/
GPUTarget get_target() const
{
return _target;
}
private:
/** Add the passed tensor's parameters to the object's kernel's arguments starting from the index idx.
*
* @param[in] idx Index at which to start adding the tensor's arguments.Input and output tensor will have sperated index, multiple indices start from 1, single index have to be set to 0.
* @param[in] tensor Tensor to set as an argument of the object's kernel.
* @param[in] binding_point Tensor's binding point in this kernel.
* @param[in] window Window the kernel will be executed on.
*/
template <unsigned int dimension_size>
void add_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window);
/** Returns the number of arguments enqueued per tensor object.
*
* @return The number of arguments enqueued per tensor object.
*/
template <unsigned int dimension_size>
unsigned int num_arguments_per_tensor() const;
protected:
GCKernel _kernel; /**< GLES kernel to run */
gles::NDRange _lws_hint; /**< Local workgroup size hint for the GLES kernel */
GPUTarget _target; /**< The targeted GPU */
};
/** Add the kernel to the command queue with the given window.
*
* @note Depending on the size of the window, this might translate into several jobs being enqueued.
*
* @note If kernel->kernel() is empty then the function will return without adding anything to the queue.
*
* @param[in] kernel Kernel to enqueue
* @param[in] window Window the kernel has to process.
* @param[in] lws Local workgroup size requested, by default (1, 1, 1)
*
* @note If any dimension of the lws is greater than the global workgroup size then no lws will be passed.
*/
void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws = gles::NDRange(1U, 1U, 1U));
}
#endif /*ARM_COMPUTE_IGCKERNEL_H */
|