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_REDUCE_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_REDUCE_H_ 18 19 #include <map> 20 #include <set> 21 22 #include "tensorflow/lite/delegates/gpu/common/kernel_info.h" 23 #include "tensorflow/lite/delegates/gpu/common/operations.h" 24 #include "tensorflow/lite/delegates/gpu/common/task/gpu_operation.h" 25 #include "tensorflow/lite/delegates/gpu/common/types.h" 26 27 namespace tflite { 28 namespace gpu { 29 30 class Reduce : public GPUOperation { 31 public: 32 Reduce() = default; 33 Reduce(const std::map<Axis, int>& axis_to_reduce, OperationType op_type, 34 const OperationDef& definition, const GpuInfo& gpu_info); 35 36 void GetPossibleKernelWorkGroups( 37 TuningType tuning_type, const GpuInfo& gpu_info, 38 const KernelInfo& kernel_info, 39 std::vector<int3>* work_groups) const override; 40 absl::Status BindArguments(ArgumentsBinder* args) override; 41 int3 GetGridSize() const override; 42 43 // Move only 44 Reduce(Reduce&& operation); 45 Reduce& operator=(Reduce&& operation); 46 Reduce(const Reduce&) = delete; 47 Reduce& operator=(const Reduce&) = delete; 48 49 private: 50 std::string GetReduceKernelCode(const OperationDef& op_def, 51 const int3& work_group_size, 52 const std::vector<Axis>& axis_to_reduce, 53 OperationType op_type); 54 55 bool use_wg_reduction_; 56 }; 57 58 Reduce CreateReduce(const std::set<Axis>& axis_to_reduce, const BHWC& src_shape, 59 OperationType op_type, const OperationDef& definition, 60 const GpuInfo& gpu_info); 61 62 Reduce CreateReduce(const std::set<Axis>& axis_to_reduce, 63 const BHWDC& src_shape, OperationType op_type, 64 const OperationDef& definition, const GpuInfo& gpu_info); 65 66 } // namespace gpu 67 } // namespace tflite 68 69 #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASKS_REDUCE_H_ 70