giuros01 | 15ecc9a | 2018-12-06 10:47:34 +0000 | [diff] [blame] | 1 | /* |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
giuros01 | 15ecc9a | 2018-12-06 10:47:34 +0000 | [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 |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
giuros01 | 15ecc9a | 2018-12-06 10:47:34 +0000 | [diff] [blame] | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
giuros01 | 15ecc9a | 2018-12-06 10:47:34 +0000 | [diff] [blame] | 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_NEFUSEBATCHNORMALIZATION_H__ |
| 25 | #define __ARM_COMPUTE_NEFUSEBATCHNORMALIZATION_H__ |
| 26 | |
| 27 | #include "arm_compute/core/ITensor.h" |
| 28 | #include "arm_compute/core/NEON/kernels/NEFuseBatchNormalizationKernel.h" |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | #include "arm_compute/runtime/IFunction.h" |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | // Forward declarations |
| 35 | class ITensor; |
| 36 | |
| 37 | /** Basic function to fuse the batch normalization node to a preceding convolution node */ |
| 38 | class NEFuseBatchNormalization : public IFunction |
| 39 | { |
| 40 | public: |
| 41 | /** Default constructor */ |
| 42 | NEFuseBatchNormalization(); |
| 43 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 44 | NEFuseBatchNormalization(const NEFuseBatchNormalization &) = delete; |
| 45 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 46 | NEFuseBatchNormalization &operator=(const NEFuseBatchNormalization &) = delete; |
| 47 | /** Allow instances of this class to be moved */ |
| 48 | NEFuseBatchNormalization(NEFuseBatchNormalization &&) = default; |
| 49 | /** Allow instances of this class to be moved */ |
| 50 | NEFuseBatchNormalization &operator=(NEFuseBatchNormalization &&) = default; |
| 51 | /** Default destructor */ |
| 52 | ~NEFuseBatchNormalization() = default; |
| 53 | /** Set the input and output tensors. |
| 54 | * |
| 55 | * @param[in] conv_weights Convolution layer weights tensor. Data type supported: F16/F32 |
| 56 | * @param[in] bn_mean Batch normalization layer mean tensor. Same as @p conv_weights |
| 57 | * @param[in] bn_var Batch normalization layer variance tensor. Same as @p conv_weights |
| 58 | * @param[out] fused_weights Output fused weights tensor. Same as @p conv_weights |
| 59 | * @param[out] fused_bias Output fused bias tensor. Same as @p conv_weights |
| 60 | * @param[in] conv_bias (Optional) Convolution layer bias tensor. Same as @p conv_weights |
| 61 | * @param[in] bn_beta (Optional) Batch normalization layer beta tensor. Same as @p conv_weights |
| 62 | * @param[in] bn_gamma (Optional) Batch normalization layer gamma tensor. Same as @p conv_weights |
| 63 | * @param[in] epsilon (Optional) Batch normalization layer epsilon parameter. Defaults to 0.001f. |
| 64 | */ |
| 65 | void configure(const ITensor *conv_weights, const ITensor *bn_mean, const ITensor *bn_var, ITensor *fused_weights, ITensor *fused_bias, |
| 66 | const ITensor *conv_bias = nullptr, const ITensor *bn_beta = nullptr, const ITensor *bn_gamma = nullptr, |
| 67 | float epsilon = 0.001f); |
| 68 | /** Static function to check if given info will lead to a valid configuration of @ref NEFuseBatchNormalization |
| 69 | * |
| 70 | * @param[in] conv_weights Convolution layer weights tensor. Data type supported: F16/F32 |
| 71 | * @param[in] bn_mean Batch normalization layer mean tensor. Same as @p conv_weights |
| 72 | * @param[in] bn_var Batch normalization layer variance tensor. Same as @p conv_weights |
| 73 | * @param[in] fused_weights Output fused weights tensor. Same as @p conv_weights |
| 74 | * @param[in] fused_bias Output fused bias tensor. Same as @p conv_weights |
| 75 | * @param[in] conv_bias (Optional) Convolution layer bias tensor. Same as @p conv_weights |
| 76 | * @param[in] bn_beta (Optional) Batch normalization layer beta tensor. Same as @p conv_weights |
| 77 | * @param[in] bn_gamma (Optional) Batch normalization layer gamma tensor. Same as @p conv_weights |
| 78 | * @param[in] epsilon (Optional) Batch normalization layer epsilon parameter. Defaults to 0.001f. |
| 79 | * |
| 80 | * @return a status |
| 81 | */ |
| 82 | static Status validate(const ITensorInfo *conv_weights, const ITensorInfo *bn_mean, const ITensorInfo *bn_var, |
| 83 | const ITensorInfo *fused_weights, const ITensorInfo *fused_bias, |
| 84 | const ITensorInfo *conv_bias = nullptr, const ITensorInfo *bn_beta = nullptr, const ITensorInfo *bn_gamma = nullptr, |
| 85 | float epsilon = 0.001f); |
| 86 | |
| 87 | // Inherited methods overridden: |
| 88 | void run() override; |
| 89 | |
| 90 | private: |
| 91 | NEFuseBatchNormalizationKernel _fuse_bn_kernel; |
| 92 | }; |
| 93 | } // namespace arm_compute |
| 94 | #endif /*__ARM_COMPUTE_NEFUSEBATCHNORMALIZATION_H__ */ |