1 /* Copyright 2022 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_COMPILER_XLA_SERVICE_SCATTER_SIMPLIFIER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_SCATTER_SIMPLIFIER_H_ 18 19 #include "tensorflow/compiler/xla/service/op_expander_pass.h" 20 21 namespace xla { 22 23 // This pass rewrites scatter operations into a combination of transposes, 24 // reshapes and a simpler scatter. 25 // 26 // It implements the first two steps of the algorithm decribed in 27 // ScatterExpander::ExpandInstruction (scatter_expander.cc). Additionally, it 28 // transposes updates and operands to transform scatter_dims_to_operand_dims 29 // into the identity mapping. This is different from the algorithm in 30 // ScatterExpander, which instead applies the mapping in scatter_indices. 31 // 32 // The output scatter's attributes will have the following characteristics: 33 // - scatter_indices is a two-dimensional tensor 34 // - index_vector_dim is 1 35 // - inserted_window_dims is [] 36 // - update_window_dims is [0, 1, ...] 37 // - scatter_dims_to_operand_dims is [0, 1, ...] 38 // 39 // The purpose of this pass is to check whether this transformation has any 40 // performance implications. 41 class ScatterSimplifier : public OpExpanderPass { 42 public: name()43 absl::string_view name() const override { return "scatter_simplifier"; } 44 45 protected: 46 bool InstructionMatchesPattern(HloInstruction* inst) override; 47 48 StatusOr<HloInstruction*> ExpandInstruction(HloInstruction* inst) override; 49 }; 50 51 } // namespace xla 52 53 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_SCATTER_SIMPLIFIER_H_ 54