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_TASKS_CONVOLUTION_TRANSPOSED_4X4_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONVOLUTION_TRANSPOSED_4X4_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 ConvolutionTransposed4x4 : public GPUOperation { 38 public: 39 ConvolutionTransposed4x4() = default; GetPossibleKernelWorkGroups(TuningType tuning_type,const GpuInfo & gpu_info,const KernelInfo & kernel_info,std::vector<int3> * work_groups)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 work_groups->push_back(work_group_size_); 45 } 46 absl::Status BindArguments(ArgumentsBinder* args) override; 47 int3 GetGridSize() const override; 48 49 // Move only 50 ConvolutionTransposed4x4(ConvolutionTransposed4x4&& operation) = default; 51 ConvolutionTransposed4x4& operator=(ConvolutionTransposed4x4&& operation) = 52 default; 53 ConvolutionTransposed4x4(const ConvolutionTransposed4x4&) = delete; 54 ConvolutionTransposed4x4& operator=(const ConvolutionTransposed4x4&) = delete; 55 GetWeightsDescription()56 WeightsDescription GetWeightsDescription() const { 57 WeightsDescription desc; 58 desc.layout = weights_layout_; 59 desc.spatial_remap = GetSpatialWeightsRemap(); 60 return desc; 61 } 62 63 enum class WeightsUploadType { 64 LOCAL_MEM_ASYNC, 65 LOCAL_MEM_BY_THREADS, 66 GLOBAL_MEM, 67 CONSTANT_MEM, 68 }; 69 70 private: 71 ConvolutionTransposed4x4(const OperationDef& definition, 72 const GpuInfo& gpu_info); 73 74 friend ConvolutionTransposed4x4 CreateConvolutionTransposed4x4( 75 const GpuInfo& gpu_info, const OperationDef& definition, 76 const ConvolutionTransposedAttributes& attr); 77 friend ConvolutionTransposed4x4 CreateConvolutionTransposed4x4DynamicWeights( 78 const GpuInfo& gpu_info, const OperationDef& definition, 79 const ConvolutionTransposedAttributes& attr); 80 81 void UploadWeights( 82 const tflite::gpu::Tensor<OHWI, DataType::FLOAT32>& weights, 83 WeightsUploadType weights_upload_type); 84 85 std::vector<int> GetSpatialWeightsRemap() const; 86 87 std::string GenerateConvolutionTransposedCode( 88 const GpuInfo& gpu_info, const OperationDef& op_def, 89 WeightsUploadType weights_upload_type); 90 91 WeightsLayout weights_layout_; 92 }; 93 94 bool IsConvolutionTransposed4x4Supported( 95 const OperationDef& definition, 96 const ConvolutionTransposedAttributes& attr); 97 98 ConvolutionTransposed4x4 CreateConvolutionTransposed4x4( 99 const GpuInfo& gpu_info, const OperationDef& definition, 100 const ConvolutionTransposedAttributes& attr); 101 102 ConvolutionTransposed4x4 CreateConvolutionTransposed4x4DynamicWeights( 103 const GpuInfo& gpu_info, const OperationDef& definition, 104 const ConvolutionTransposedAttributes& attr); 105 106 } // namespace gpu 107 } // namespace tflite 108 109 #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONVOLUTION_TRANSPOSED_4X4_H_ 110