• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 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 #include "tensorflow/compiler/xla/service/despecializer.h"
17 
18 #include "tensorflow/compiler/xla/service/bfloat16_normalization.h"
19 #include "tensorflow/compiler/xla/service/defuser.h"
20 #include "tensorflow/compiler/xla/service/hlo_memory_scheduler.h"
21 
22 namespace xla {
23 
24 namespace {
25 
26 // Pass which strips control dependencies from all instructions in the module.
27 class ControlDepRemover : public HloModulePass {
28  public:
29   ControlDepRemover() = default;
name() const30   absl::string_view name() const override { return "control-dep-remover"; }
31 
Run(HloModule * module)32   StatusOr<bool> Run(HloModule* module) override {
33     bool changed = false;
34     for (HloComputation* computation : module->computations()) {
35       for (HloInstruction* instruction : computation->instructions()) {
36         changed = changed || !instruction->control_predecessors().empty();
37         TF_RETURN_IF_ERROR(instruction->DropAllControlDeps());
38       }
39     }
40     return changed;
41   }
42 };
43 
44 }  // namespace
45 
Despecializer()46 Despecializer::Despecializer() : pipeline_("despecializer") {
47   // TODO(b/70588125): Also deal with window reversal in a fast way.
48   pipeline_.AddPass<HloDescheduler>();
49   pipeline_.AddPass<ControlDepRemover>();
50   pipeline_.AddPass<Defuser>();
51   pipeline_.AddPass<BFloat16MixedPrecisionRemoval>();
52 }
53 
Run(HloModule * module)54 StatusOr<bool> Despecializer::Run(HloModule* module) {
55   return pipeline_.Run(module);
56 }
57 
58 }  // namespace xla
59