tf_1.8_xla_doc
cpu_parallelization_preparation.h
Go to the documentation of this file.
1 
3 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ==============================================================================*/
17 
18 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_CPU_CPU_PARALLELIZATION_PREPARATION_H_
19 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_CPU_PARALLELIZATION_PREPARATION_H_
20 
21 #include "tensorflow/compiler/xla/service/hlo_cost_analysis.h"
23 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h"
24 
25 namespace xla {
26 namespace cpu {
38 class ParallelizationPreparation : public HloPassInterface {
39  public:
40  // 'max_parallelism': the maximum parallel task count per instruction.
41  // 'shape_size': shape size function used by HloCostAnalysis during parallel
42  // task assignment.
44  const int64 max_parallelism,
45  const HloCostAnalysis::ShapeSizeFunction& shape_size)
46  : max_parallelism_(max_parallelism), shape_size_(shape_size) {}
47  ~ParallelizationPreparation() override {}
48 
49  tensorflow::StringPiece name() const override {
50  return "cpu-parallel-prepare";
51  }
52 
53  // Run parallel preparation on the given computation. Returns whether the
54  // computation was changed.
55  StatusOr<bool> Run(HloModule* module) override;
56 
57  private:
58  // Assigns parallel task partitions to conformant instructions in 'module'.
59  // Returns true on success or error status otherwise.
60  StatusOr<bool> RunParallelTaskAssignment(HloModule* module);
61 
62  // Outlines 'instruction' from entry computation, if it had
63  // been assigned parallel tasks in an earlier pass through the computation.
64  // Returns true if 'instruction' was successfully outlined, false otherwise.
65  bool OutlineParallelizableInstruction(HloInstruction* instruction);
66 
67  // Returns true if 'instruction' can be outlined into the same sub-computation
68  // with its single user (parallelizable instructions are not outlined with
69  // each other). Returns false otherwise.
70  bool CanOutlineWithUser(HloInstruction* instruction);
71 
72  // Returns true if 'instruction' (or the root of the sub-computation that
73  // 'instruction' calls) has had parallel tasks assigned in earlier pass.
74  // Returns false otherwise.
75  bool AssignedParallelTasks(HloInstruction* instruction);
76 
77  const int64 max_parallelism_;
78  const HloCostAnalysis::ShapeSizeFunction shape_size_;
79 };
80 
81 } // namespace cpu
82 } // namespace xla
83 
84 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_CPU_PARALLELIZATION_PREPARATION_H_
Definition: cpu_parallelization_preparation.h:38
Definition: hlo_instruction.h:165
namespace for xla
Definition: client_library.cc:26
Definition: hlo_module.h:52