• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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_TASKS_CONVOLUTION_TRANSPOSED_3X3_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONVOLUTION_TRANSPOSED_3X3_H_
18 
19 #include <vector>
20 
21 #include "tensorflow/lite/delegates/gpu/common/data_type.h"
22 #include "tensorflow/lite/delegates/gpu/common/operations.h"
23 #include "tensorflow/lite/delegates/gpu/common/shape.h"
24 #include "tensorflow/lite/delegates/gpu/common/status.h"
25 #include "tensorflow/lite/delegates/gpu/common/task/buffer_desc.h"
26 #include "tensorflow/lite/delegates/gpu/common/task/gpu_operation.h"
27 #include "tensorflow/lite/delegates/gpu/common/task/tensor_desc.h"
28 #include "tensorflow/lite/delegates/gpu/common/task/tensor_linear_desc.h"
29 #include "tensorflow/lite/delegates/gpu/common/task/weights_conversion.h"
30 #include "tensorflow/lite/delegates/gpu/common/task/weights_layout.h"
31 #include "tensorflow/lite/delegates/gpu/common/tensor.h"
32 #include "tensorflow/lite/delegates/gpu/common/types.h"
33 
34 namespace tflite {
35 namespace gpu {
36 
37 class ConvolutionTransposed3x3 : public GPUOperation {
38  public:
39   ConvolutionTransposed3x3() = default;
40   void GetPossibleKernelWorkGroups(
41       TuningType tuning_type, const GpuInfo& gpu_info,
42       const KernelInfo& kernel_info,
43       std::vector<int3>* work_groups) const override;
44   absl::Status BindArguments(ArgumentsBinder* args) override;
45   int3 GetGridSize() const override;
46 
47   // Move only
48   ConvolutionTransposed3x3(ConvolutionTransposed3x3&& operation) = default;
49   ConvolutionTransposed3x3& operator=(ConvolutionTransposed3x3&& operation) =
50       default;
51   ConvolutionTransposed3x3(const ConvolutionTransposed3x3&) = delete;
52   ConvolutionTransposed3x3& operator=(const ConvolutionTransposed3x3&) = delete;
53 
GetWeightsDescription()54   WeightsDescription GetWeightsDescription() const {
55     WeightsDescription desc;
56     desc.layout = weights_layout_;
57     desc.spatial_remap = GetSpatialWeightsRemap();
58     return desc;
59   }
60 
61   enum class WeightsUploadType {
62     LOCAL_MEM_ASYNC,
63     LOCAL_MEM_BY_THREADS,
64     GLOBAL_MEM,
65     CONSTANT_MEM,
66   };
67 
68  private:
69   ConvolutionTransposed3x3(const OperationDef& definition,
70                            const GpuInfo& gpu_info, int2 padding);
71   friend ConvolutionTransposed3x3 CreateConvolutionTransposed3x3(
72       const GpuInfo& gpu_info, const OperationDef& definition,
73       const ConvolutionTransposedAttributes& attr);
74   friend ConvolutionTransposed3x3 CreateConvolutionTransposed3x3DynamicWeights(
75       const GpuInfo& gpu_info, const OperationDef& definition,
76       const ConvolutionTransposedAttributes& attr);
77 
78   void UploadWeights(
79       const tflite::gpu::Tensor<OHWI, DataType::FLOAT32>& weights);
80 
81   std::vector<int> GetSpatialWeightsRemap() const;
82 
83   std::string GenerateConvolutionTransposedCode(
84       const GpuInfo& gpu_info, const OperationDef& op_def,
85       ConvolutionTransposed3x3::WeightsUploadType weights_upload_type,
86       int2 padding, int3 work_group_launch_order);
87 
88   int2 padding_;
89   WeightsUploadType weights_upload_type_;
90   WeightsLayout weights_layout_;
91 };
92 
93 bool IsConvolutionTransposed3x3Supported(
94     const OperationDef& definition,
95     const ConvolutionTransposedAttributes& attr);
96 
97 ConvolutionTransposed3x3 CreateConvolutionTransposed3x3(
98     const GpuInfo& gpu_info, const OperationDef& definition,
99     const ConvolutionTransposedAttributes& attr);
100 
101 ConvolutionTransposed3x3 CreateConvolutionTransposed3x3DynamicWeights(
102     const GpuInfo& gpu_info, const OperationDef& definition,
103     const ConvolutionTransposedAttributes& attr);
104 
105 }  // namespace gpu
106 }  // namespace tflite
107 
108 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONVOLUTION_TRANSPOSED_3X3_H_
109