Michalis Spyrou | a6825a4 | 2018-09-13 12:24:03 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Michalis Spyrou | a6825a4 | 2018-09-13 12:24:03 +0100 | [diff] [blame] | 3 | * |
| 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 Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEYOLOLAYERKERNEL_H |
| 25 | #define ARM_COMPUTE_NEYOLOLAYERKERNEL_H |
Michalis Spyrou | a6825a4 | 2018-09-13 12:24:03 +0100 | [diff] [blame] | 26 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 27 | #include "src/core/NEON/INEKernel.h" |
Michalis Spyrou | a6825a4 | 2018-09-13 12:24:03 +0100 | [diff] [blame] | 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | class ITensor; |
| 32 | |
| 33 | /** Interface for the YOLO layer kernel. */ |
| 34 | class NEYOLOLayerKernel : public INEKernel |
| 35 | { |
| 36 | public: |
| 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 | |
| 79 | private: |
Michalis Spyrou | bb1ad0c | 2020-02-28 17:31:27 +0000 | [diff] [blame] | 80 | /** Function to run YOLO layer |
Michalis Spyrou | a6825a4 | 2018-09-13 12:24:03 +0100 | [diff] [blame] | 81 | * |
| 82 | * @param[in] window Region on which to execute the kernel. |
| 83 | */ |
Michalis Spyrou | bb1ad0c | 2020-02-28 17:31:27 +0000 | [diff] [blame] | 84 | template <typename T, int S> |
| 85 | void yolo_layer_nchw(const Window &window); |
| 86 | /** Function to run YOLO layer on tensors with NHWC format |
Michalis Spyrou | a6825a4 | 2018-09-13 12:24:03 +0100 | [diff] [blame] | 87 | * |
| 88 | * @param[in] window Region on which to execute the kernel. |
| 89 | */ |
Michalis Spyrou | bb1ad0c | 2020-02-28 17:31:27 +0000 | [diff] [blame] | 90 | template <typename T> |
| 91 | void yolo_layer_nhwc(const Window &window); |
Michalis Spyrou | a6825a4 | 2018-09-13 12:24:03 +0100 | [diff] [blame] | 92 | /** Common signature for all the yolo layer functions |
| 93 | * |
| 94 | * @param[in] window Region on which to execute the kernel. |
| 95 | */ |
| 96 | using YOLOFunctionPtr = void (NEYOLOLayerKernel::*)(const Window &window); |
| 97 | |
| 98 | private: |
| 99 | YOLOFunctionPtr _func; |
| 100 | ITensor *_input; |
| 101 | ITensor *_output; |
| 102 | ActivationLayerInfo _act_info; |
| 103 | int32_t _num_classes; |
| 104 | }; |
| 105 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 106 | #endif /*ARM_COMPUTE_NEYOLOLAYERKERNEL_H */ |