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 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_GPU_REDUCTION_SPLITTER_H_ 16 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_REDUCTION_SPLITTER_H_ 17 18 #include "tensorflow/compiler/xla/service/hlo_module.h" 19 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 20 21 namespace xla { 22 namespace gpu { 23 24 // Splits a reduce op into two consecutive reduce ops if 25 // * the reduce dimensions are not contiguous and 26 // * at least one reduce dimension is large (i.e. corresponds to a large input 27 // shape dimension). 28 // 29 // Reductions with non-contiguous dimensions are emitted as simple element-wise 30 // loops. This is inefficient when reducing large input shape dimensions. 31 // Splitting such reductions allows using more efficient reduction emitters. 32 // 33 // This pass splits reduce ops into two consecutive reduce ops. Run it to a 34 // fixpoint to split reduce ops along multiple large dimensions. 35 // 36 // Precondition: ReductionDimensionGrouper has been run and adjacent reduce 37 // dimentsions have been grouped. Reduction layouts have been normalized. 38 39 class ReductionSplitter : public HloModulePass { 40 public: name()41 absl::string_view name() const override { return "reduction-splitter"; } 42 43 StatusOr<bool> Run(HloModule* module) override; 44 }; 45 46 } // namespace gpu 47 } // namespace xla 48 49 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_REDUCTION_SPLITTER_H_ 50