a614d5259a3f38d91f4e94fb104c7877991f84fb
[platform/core/ml/nnfw.git] / compute / ARMComputeEx / arm_compute / core / CL / kernels / CLEmbeddingLookupKernel.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  * Copyright (c) 2016-2018 ARM Limited.
19  *
20  * SPDX-License-Identifier: MIT
21  *
22  * Permission is hereby granted, free of charge, to any person obtaining a copy
23  * of this software and associated documentation files (the "Software"), to
24  * deal in the Software without restriction, including without limitation the
25  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
26  * sell copies of the Software, and to permit persons to whom the Software is
27  * furnished to do so, subject to the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be included in all
30  * copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38  * SOFTWARE.
39  */
40
41 /**
42  * @file      CLEmbeddingLookupKernel.h
43  * @ingroup   COM_AI_RUNTIME
44  * @brief     This file defines CLEmbeddingLookupKernel class
45  */
46
47 #ifndef __ARM_COMPUTE_CLEMBEDDINGLOOKUPKERNEL_H__
48 #define __ARM_COMPUTE_CLEMBEDDINGLOOKUPKERNEL_H__
49
50 #include "arm_compute/core/CL/ICLKernel.h"
51
52 namespace arm_compute
53 {
54 class ICLTensor;
55
56 /**
57 * @brief Class to perform EmbeddingLookup operation with opencl kernel
58 */
59 class CLEmbeddingLookupKernel : public ICLKernel
60 {
61 public:
62   /**
63    * @brief Construct a CLEmbeddingLookupKernel object
64    * */
65   CLEmbeddingLookupKernel();
66
67   /**
68    * @brief Prevent instances of this class from being copied (As this class contains pointers)
69    * */
70   CLEmbeddingLookupKernel(const CLEmbeddingLookupKernel &) = delete;
71
72   /**
73    * @brief Prevent instances of this class from being copied (As this class contains pointers)
74    * */
75   CLEmbeddingLookupKernel &operator=(const CLEmbeddingLookupKernel &) = delete;
76
77   /**
78    * @brief Construct a CLEmbeddingLookupKernel object by using default move constructor
79    * @param[in] CLEmbeddingLookupKernel object to move
80    * */
81   CLEmbeddingLookupKernel(CLEmbeddingLookupKernel &&) = default;
82
83   /**
84    * @brief Move assignment operator
85    * @param[in] CLEmbeddingLookupKernel object to move
86    * */
87   CLEmbeddingLookupKernel &operator=(CLEmbeddingLookupKernel &&) = default;
88
89   /**
90    * @brief Destruct this object
91    * */
92   ~CLEmbeddingLookupKernel() = default;
93
94   /**
95    * @brief Set the input and output of the kernel
96    * @param[in]  input          Source tensor.
97    *                            Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
98    * @param[out] output         Destination tensor. Data type supported: Same as @p input
99    * @param[in]  lookups        Lookups are 1D tensor that values are indices into the first
100    *                            dimension of input.
101    *                            Data types supported: S32.
102    * @return N/A
103    */
104   void configure(const ICLTensor *input, ICLTensor *output, const ICLTensor *lookups);
105
106   /**
107    * @brief Static function to check if given info will lead to a valid configuration of @ref
108    *        CLEmbeddingLookupKernel
109    * @param[in]  input          The input tensor info.
110    *                            Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
111    * @param[in]  output         The output tensor info, Data types supported: same as @p input1.
112    * @param[in]  lookups        Lookups info. Data types supported: S32.
113    * @return a status
114    */
115   static Status validate(const ITensorInfo *input, const ITensorInfo *output,
116                          const ITensorInfo *lookups);
117
118   /**
119    * @brief Enqueue the OpenCL kernel to process the given window on the passed OpenCL command
120    *        queue.
121    * @note  The queue is *not* flushed by this method, and therefore the kernel will not have
122    *        been executed by the time this method returns.
123    * @param[in]     window  Region on which to execute the kernel. (Must be a valid region of
124    *                        the window returned by window()).
125    * @param[in,out] queue   Command queue on which to enqueue the kernel.@return N/A
126    * @return N/A
127    */
128   void run(const Window &window, cl::CommandQueue &queue) override;
129
130 private:
131   const ICLTensor *_input;   /** Source tensor */
132   ICLTensor *_output;        /** Destination tensor */
133   const ICLTensor *_lookups; /** Lookups tensor */
134 };
135 } // namespace arm_compute
136 #endif /*__ARM_COMPUTE_CLEMBEDDINGLOOKUPKERNEL_H__ */