blob: b88fcf456731693ceae65a1c6f10060b650e38d2 [file] [log] [blame]
Michalis Spyroua6825a42018-09-13 12:24:03 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2018-2019 ARM Limited.
Michalis Spyroua6825a42018-09-13 12:24:03 +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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEYOLOLAYERKERNEL_H
25#define ARM_COMPUTE_NEYOLOLAYERKERNEL_H
Michalis Spyroua6825a42018-09-13 12:24:03 +010026
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
31class ITensor;
32
33/** Interface for the YOLO layer kernel. */
34class NEYOLOLayerKernel : public INEKernel
35{
36public:
37 const char *name() const override
38 {
39 return "NEYOLOLayerKernel";
40 }
41 /** Constructor */
42 NEYOLOLayerKernel();
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 NEYOLOLayerKernel(const NEYOLOLayerKernel &) = delete;
45 /** Default move constructor */
46 NEYOLOLayerKernel(NEYOLOLayerKernel &&) = default;
47 /** Prevent instances of this class from being copied (As this class contains pointers) */
48 NEYOLOLayerKernel &operator=(const NEYOLOLayerKernel &) = delete;
49 /** Default move assignment operator */
50 NEYOLOLayerKernel &operator=(NEYOLOLayerKernel &&) = default;
51 /** Default destructor */
52 ~NEYOLOLayerKernel() = default;
53 /** Set the input and output tensor.
54 *
55 * @note If the output tensor is a nullptr or is equal to the input, the activation function will be performed in-place
56 *
57 * @param[in, out] input Source tensor. In case of @p output tensor = nullptr, this tensor will store the result
58 * of the activation function. Data types supported: F16/F32.
59 * @param[out] output Destination tensor. Data type supported: same as @p input
60 * @param[in] act_info Activation layer parameters.
61 * @param[in] num_classes Number of classes to activate (must be submultiple of @p input channels)
62 */
63 void configure(ITensor *input, ITensor *output, const ActivationLayerInfo &act_info, int32_t num_classes);
64 /** Static function to check if given info will lead to a valid configuration of @ref NEYOLOLayerKernel
65 *
66 * @param[in] input Source tensor info. In case of @p output tensor info = nullptr, this tensor will store the result
67 * of the activation function. Data types supported: F16/F32.
68 * @param[in] output Destination tensor info. Data type supported: same as @p input
69 * @param[in] act_info Activation layer information.
70 * @param[in] num_classes Number of classes to activate (must be submultiple of @p input channels)
71 *
72 * @return a status
73 */
74 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info, int32_t num_classes);
75
76 // Inherited methods overridden:
77 void run(const Window &window, const ThreadInfo &info) override;
78
79private:
80#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
81 /** Function to run YOLO layer on fp16
82 *
83 * @param[in] window Region on which to execute the kernel.
84 */
85 void yolo_layer_fp16_nchw(const Window &window);
86 /** Function to run batch normalization on fp16 on tensors with NHWC format
87 *
88 * @param[in] window Region on which to execute the kernel.
89 */
90 void yolo_layer_fp16_nhwc(const Window &window);
91#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
92 /** Function to run YOLO layer on fp32
93 *
94 * @param[in] window Region on which to execute the kernel.
95 */
96 void yolo_layer_fp32_nchw(const Window &window);
97 /** Function to run YOLO layer on fp32 on tensors with NHWC format
98 *
99 * @param[in] window Region on which to execute the kernel.
100 */
101 void yolo_layer_fp32_nhwc(const Window &window);
102 /** Common signature for all the yolo layer functions
103 *
104 * @param[in] window Region on which to execute the kernel.
105 */
106 using YOLOFunctionPtr = void (NEYOLOLayerKernel::*)(const Window &window);
107
108private:
109 YOLOFunctionPtr _func;
110 ITensor *_input;
111 ITensor *_output;
112 ActivationLayerInfo _act_info;
113 int32_t _num_classes;
114};
115} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000116#endif /*ARM_COMPUTE_NEYOLOLAYERKERNEL_H */