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_BITCAST_DECOMPOSER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_BITCAST_DECOMPOSER_H_ 18 19 #include "tensorflow/compiler/xla/service/hlo_module.h" 20 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 21 22 namespace xla { 23 24 // Decomposes expensive bitcasts inside of fusions into cheap-bitcast+transpose. 25 // 26 // Bitcasts outside of fusions are free in XLA:GPU, but bitcasts inside of 27 // fusions are expensive if !ReshapeIsBitcast. 28 // 29 // For each bitcast inside of a fusion where the bitcast has !ReshapeIsBitcast, 30 // this pass decomposes the bitcast into a sequence of reshape-is-bitcast plus 31 // transpose-is-bitcast operations. 32 // 33 // (In theory, we could do this decomposition logic inside of codegen itself, 34 // without requiring any modifications to the IR. But it's easier to express it 35 // in the IR as a late "codegen prepare" pass.) 36 class BitcastDecomposer : public HloModulePass { 37 public: name()38 absl::string_view name() const override { return "bitcast_decomposer"; } 39 using HloPassInterface::Run; 40 StatusOr<bool> Run( 41 HloModule* module, 42 const absl::flat_hash_set<absl::string_view>& execution_threads) override; 43 }; 44 45 } // namespace xla 46 47 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_BITCAST_DECOMPOSER_H_ 48