xref: /aosp_15_r20/external/tensorflow/tensorflow/lite/delegates/gpu/common/transformations/fuse_add_to_conv.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TRANSFORMATIONS_FUSE_ADD_TO_CONV_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TRANSFORMATIONS_FUSE_ADD_TO_CONV_H_
18 
19 #include <memory>
20 
21 #include "tensorflow/lite/delegates/gpu/common/model_transformer.h"
22 #include "tensorflow/lite/delegates/gpu/common/operations.h"
23 
24 namespace tflite {
25 namespace gpu {
26 
27 // Fuse Add Scalar or Add Broadcast after Convolution(Convolution2D,
28 // DepthWise, TransposedConvolution, FullyConnected) into biases of
29 // convolution.
30 std::unique_ptr<SequenceTransformation> NewMergeConvolutionWithAdd();
31 
32 // Fuse Add Scalar or Add Broadcast before Convolution2D into weights and biases
33 // of convolution.
34 std::unique_ptr<SequenceTransformation> NewMergeAddWithConvolution();
35 
36 // Modify Convolution2DAttributes so that after making convolution with
37 // modified attributes we will have the same result as convolution
38 // with old attributes and following add operation.
39 void FuseConvolution2DWithAdd(const ElementwiseAttributes& add_attr,
40                               Convolution2DAttributes* attr);
41 
42 // Modify DepthwiseConvolution2DAttributes so that after making depth wise
43 // convolution with modified attributes we will have the same result as depth
44 // wise convolution with old attributes and following add operation.
45 void FuseDepthwiseConvolution2DWithAdd(const ElementwiseAttributes& add_attr,
46                                        DepthwiseConvolution2DAttributes* attr);
47 
48 // Modify ConvolutionTransposedAttributes so that after making convolution
49 // transposed with modified attributes we will have the same result as
50 // convolution transposed with old attributes and following add operation.
51 void FuseConvolutionTransposedWithAdd(const ElementwiseAttributes& add_attr,
52                                       ConvolutionTransposedAttributes* attr);
53 
54 // Modify FullyConnectedAttributes so that after making fully connected with
55 // modified attributes we will have the same result as fully connected
56 // with old attributes and following add operation.
57 void FuseFullyConnectedWithAdd(const ElementwiseAttributes& add_attr,
58                                FullyConnectedAttributes* attr);
59 
60 }  // namespace gpu
61 }  // namespace tflite
62 
63 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TRANSFORMATIONS_FUSE_ADD_TO_CONV_H_
64