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_3X3_THIN_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONVOLUTION_TRANSPOSED_3X3_THIN_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 ConvolutionTransposed3x3Thin : public GPUOperation { 38 public: 39 ConvolutionTransposed3x3Thin() = default; 40 int3 GetGridSize() const override; 41 42 // Move only 43 ConvolutionTransposed3x3Thin(ConvolutionTransposed3x3Thin&& operation) = 44 default; 45 ConvolutionTransposed3x3Thin& operator=( 46 ConvolutionTransposed3x3Thin&& operation) = default; 47 ConvolutionTransposed3x3Thin(const ConvolutionTransposed3x3Thin&) = delete; 48 ConvolutionTransposed3x3Thin& operator=(const ConvolutionTransposed3x3Thin&) = 49 delete; 50 GetWeightsDescription()51 WeightsDescription GetWeightsDescription() const { 52 WeightsDescription desc; 53 desc.layout = weights_layout_; 54 desc.spatial_remap = GetSpatialWeightsRemap(); 55 return desc; 56 } 57 58 private: 59 ConvolutionTransposed3x3Thin(const GpuInfo& gpu_info, 60 const OperationDef& definition, 61 const ConvolutionTransposedAttributes& attr); 62 63 friend ConvolutionTransposed3x3Thin CreateConvolutionTransposed3x3Thin( 64 const GpuInfo& gpu_info, const OperationDef& definition, 65 const ConvolutionTransposedAttributes& attr); 66 friend ConvolutionTransposed3x3Thin 67 CreateConvolutionTransposed3x3ThinDynamicWeights( 68 const GpuInfo& gpu_info, const OperationDef& definition, 69 const ConvolutionTransposedAttributes& attr); 70 71 void UploadWeights( 72 const tflite::gpu::Tensor<OHWI, DataType::FLOAT32>& weights); 73 74 std::vector<int> GetSpatialWeightsRemap() const; 75 76 std::string GenerateConvolutionTransposedCode(const OperationDef& op_def, 77 int src_depth, int dst_depth); 78 79 WeightsLayout weights_layout_; 80 }; 81 82 bool IsConvolutionTransposed3x3ThinSupported( 83 const ConvolutionTransposedAttributes& attr); 84 85 ConvolutionTransposed3x3Thin CreateConvolutionTransposed3x3Thin( 86 const GpuInfo& gpu_info, const OperationDef& definition, 87 const ConvolutionTransposedAttributes& attr); 88 89 ConvolutionTransposed3x3Thin CreateConvolutionTransposed3x3ThinDynamicWeights( 90 const GpuInfo& gpu_info, const OperationDef& definition, 91 const ConvolutionTransposedAttributes& attr); 92 93 } // namespace gpu 94 } // namespace tflite 95 96 #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONVOLUTION_TRANSPOSED_3X3_THIN_H_ 97