blob: 777a80f8b9255cd42fd326e0563b4732ab8e9bb4 [file] [log] [blame]
Georgios Pinitasc9369172018-09-26 11:25:40 +01001/*
2 * Copyright (c) 2018 ARM Limited.
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 */
24#ifndef __ARM_COMPUTE_CLFUSEBATCHNORMALIZATION_H__
25#define __ARM_COMPUTE_CLFUSEBATCHNORMALIZATION_H__
26
27#include "arm_compute/core/CL/kernels/CLFuseBatchNormalizationKernel.h"
28#include "arm_compute/core/Types.h"
29#include "arm_compute/runtime/IFunction.h"
30
31namespace arm_compute
32{
33// Forward declarations
34class ICLTensor;
35
36/** Basic function to fuse the batch normalization node to a preceding convolution node */
37class CLFuseBatchNormalization : public IFunction
38{
39public:
40 /** Default constructor */
41 CLFuseBatchNormalization();
42 /** Prevent instances of this class from being copied (As this class contains pointers) */
43 CLFuseBatchNormalization(const CLFuseBatchNormalization &) = delete;
44 /** Prevent instances of this class from being copied (As this class contains pointers) */
45 CLFuseBatchNormalization &operator=(const CLFuseBatchNormalization &) = delete;
46 /** Allow instances of this class to be moved */
47 CLFuseBatchNormalization(CLFuseBatchNormalization &&) = default;
48 /** Allow instances of this class to be moved */
49 CLFuseBatchNormalization &operator=(CLFuseBatchNormalization &&) = default;
50 /** Default destructor */
51 ~CLFuseBatchNormalization() = default;
52 /** Set the input and output tensors.
53 *
54 * @param[in] conv_weights Convolution layer weights tensor. Data type supported: F16/F32
55 * @param[in] bn_mean Batch normalization layer mean tensor. Same as @p conv_weights
56 * @param[in] bn_var Batch normalization layer variance tensor. Same as @p conv_weights
57 * @param[out] fused_weights Output fused weights tensor. Same as @p conv_weights
58 * @param[out] fused_bias Output fused bias tensor. Same as @p conv_weights
59 * @param[in] conv_bias (Optional) Convolution layer bias tensor. Same as @p conv_weights
60 * @param[in] bn_beta (Optional) Batch normalization layer beta tensor. Same as @p conv_weights
61 * @param[in] bn_gamma (Optional) Batch normalization layer gamma tensor. Same as @p conv_weights
62 * @param[in] epsilon (Optional) Batch normalization layer epsilon parameter. Defaults to 0.001f.
63 */
64 void configure(const ICLTensor *conv_weights, const ICLTensor *bn_mean, const ICLTensor *bn_var, ICLTensor *fused_weights, ICLTensor *fused_bias,
65 const ICLTensor *conv_bias = nullptr, const ICLTensor *bn_beta = nullptr, const ICLTensor *bn_gamma = nullptr,
66 float epsilon = 0.001f);
67 /** Static function to check if given info will lead to a valid configuration of @ref CLFuseBatchNormalization
68 *
69 * @param[in] conv_weights Convolution layer weights tensor. Data type supported: F16/F32
70 * @param[in] bn_mean Batch normalization layer mean tensor. Same as @p conv_weights
71 * @param[in] bn_var Batch normalization layer variance tensor. Same as @p conv_weights
72 * @param[in] fused_weights Output fused weights tensor. Same as @p conv_weights
73 * @param[in] fused_bias Output fused bias tensor. Same as @p conv_weights
74 * @param[in] conv_bias (Optional) Convolution layer bias tensor. Same as @p conv_weights
75 * @param[in] bn_beta (Optional) Batch normalization layer beta tensor. Same as @p conv_weights
76 * @param[in] bn_gamma (Optional) Batch normalization layer gamma tensor. Same as @p conv_weights
77 * @param[in] epsilon (Optional) Batch normalization layer epsilon parameter. Defaults to 0.001f.
78 *
79 * @return a status
80 */
81 static Status validate(const ITensorInfo *conv_weights, const ITensorInfo *bn_mean, const ITensorInfo *bn_var,
82 const ITensorInfo *fused_weights, const ITensorInfo *fused_bias,
83 const ITensorInfo *conv_bias = nullptr, const ITensorInfo *bn_beta = nullptr, const ITensorInfo *bn_gamma = nullptr,
84 float epsilon = 0.001f);
85
86 // Inherited methods overridden:
87 void run() override;
88
89private:
90 CLFuseBatchNormalizationKernel _fuse_bn_kernel;
91};
92} // namespace arm_compute
93#endif /*__ARM_COMPUTE_CLFUSEBATCHNORMALIZATION_H__ */