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_CONV_WEIGHTS_CONVERTER_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONV_WEIGHTS_CONVERTER_H_ 18 19 #include "tensorflow/lite/delegates/gpu/common/status.h" 20 #include "tensorflow/lite/delegates/gpu/common/task/gpu_operation.h" 21 #include "tensorflow/lite/delegates/gpu/common/task/weights_layout.h" 22 #include "tensorflow/lite/delegates/gpu/common/types.h" 23 24 namespace tflite { 25 namespace gpu { 26 27 class ConverterToConvWeights : public GPUOperation { 28 public: 29 ConverterToConvWeights(const OperationDef& definition, 30 const WeightsDescription& weights_desc); 31 absl::Status BindArguments(ArgumentsBinder* args) override; 32 int3 GetGridSize() const override; 33 34 // Move only 35 ConverterToConvWeights(ConverterToConvWeights&& operation); 36 ConverterToConvWeights& operator=(ConverterToConvWeights&& operation); 37 ConverterToConvWeights(const ConverterToConvWeights&) = delete; 38 ConverterToConvWeights& operator=(const ConverterToConvWeights&) = delete; 39 40 private: 41 std::string GetConverterToConvWeightsCode( 42 const OperationDef& op_def, const WeightsDescription& weights_desc); 43 44 WeightsDescription weights_desc_; 45 }; 46 47 // We expect src BHWC tensor and we assume that B is O, H = H, W = W, C is I 48 // as dst we expect Tensor with storage type BUFFER and 49 // dst.b * dst.h * dst.w * dst.c = AlignByN(src.b, 4) * src.h * src.w 50 // AlignByN(src.c, 4) 51 ConverterToConvWeights CreateConverterToConvWeights( 52 const OperationDef& definition, const WeightsDescription& weights_desc); 53 54 } // namespace gpu 55 } // namespace tflite 56 57 #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONV_WEIGHTS_CONVERTER_H_ 58