xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/service/gpu/fusion_bitcast_lift.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2021 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_GPU_FUSION_BITCAST_LIFT_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_FUSION_BITCAST_LIFT_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 namespace gpu {
24 
25 // Lift "rank-reducing bitcast" inside fusions to outside the fusion.
26 //
27 // Bitcast instruction are no-op, so we can duplicate them for free.
28 // "rank-reducing bitcast" is defined to be a bitcast whose output have
29 // a lower rank than the input.  Inside a fusion, we lift the
30 // "rank-reducing bitcast" out of the fusion as this allow using simpler,
31 // so faster, indexing.
32 class FusionBitcastLift : public HloModulePass {
33  public:
name()34   absl::string_view name() const override { return "fusion_bitcast_lift"; }
35 
36   using HloPassInterface::Run;
37   StatusOr<bool> Run(
38       HloModule* module,
39       const absl::flat_hash_set<absl::string_view>& execution_threads) override;
40 };
41 
42 }  // namespace gpu
43 }  // namespace xla
44 
45 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_FUSION_BITCAST_LIFT_H_
46