xref: /aosp_15_r20/external/tensorflow/tensorflow/lite/delegates/gpu/common/tasks/conv_weights_converter.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 <string>
20 
21 #include "tensorflow/lite/delegates/gpu/common/status.h"
22 #include "tensorflow/lite/delegates/gpu/common/task/gpu_operation.h"
23 #include "tensorflow/lite/delegates/gpu/common/task/weights_layout.h"
24 #include "tensorflow/lite/delegates/gpu/common/types.h"
25 
26 namespace tflite {
27 namespace gpu {
28 
29 class ConverterToConvWeights : public GPUOperation {
30  public:
31   ConverterToConvWeights(const OperationDef& definition,
32                          const WeightsDescription& weights_desc,
33                          Layout input_layout);
34   absl::Status BindArguments(ArgumentsBinder* args) override;
35   int3 GetGridSize() const override;
36 
37   // Move only
38   ConverterToConvWeights(ConverterToConvWeights&& operation) = default;
39   ConverterToConvWeights& operator=(ConverterToConvWeights&& operation) =
40       default;
41   ConverterToConvWeights(const ConverterToConvWeights&) = delete;
42   ConverterToConvWeights& operator=(const ConverterToConvWeights&) = delete;
43 
44  private:
45   std::string GetConverterToConvWeightsCode();
46 
47   OHWI GetWeightsSize() const;
48 
49   WeightsDescription weights_desc_;
50 
51   Layout input_layout_;  // Can be only OHWI or HWIO
52   // if input_layout_ is OHWI: reinterpreting weights as OHWI-BHWC tensor
53   // if input_layout_ is HWIO: reinterpreting weights as HWIO-BHWC tensor
54 };
55 
56 ConverterToConvWeights CreateConverterToConvWeights(
57     const OperationDef& definition, const WeightsDescription& weights_desc,
58     Layout input_layout);
59 
60 }  // namespace gpu
61 }  // namespace tflite
62 
63 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_CONV_WEIGHTS_CONVERTER_H_
64