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