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 16 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_DYNAMIC_PADDER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_DYNAMIC_PADDER_H_ 18 19 #include "tensorflow/compiler/xla/service/dynamic_dimension_inference.h" 20 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 21 22 namespace xla { 23 24 // With bounded shapes, only part of the shape contains effective data and the 25 // rest contains padded data, whose value can be anything depending on the 26 // source of the data. When a bounded shape is directly consumed by an 27 // instruction that collapses dimensions (reduce for example), the padding data 28 // would affect result of the instruction. 29 // 30 // DynamicPadder uses DynamicDimensionInference to detect bounded shapes in a 31 // hlo module, it then inserts certain instructions to reset the padding into an 32 // identity value so that in doesn't affect the result of subsequent 33 // instruction. For example, it'd reset the padding to 0 before a bounded shape 34 // is consumed by a reduce-sum. 35 class DynamicPadder : public HloModulePass { 36 public: name()37 absl::string_view name() const override { return "dynamic_padder"; } 38 39 StatusOr<bool> Run(HloModule* module) override; 40 }; 41 42 } // namespace xla 43 44 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_DYNAMIC_PADDER_H_ 45