tf_1.8_xla_doc
hlo_pass_pipeline.h
Go to the documentation of this file.
1 
3 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7  http://www.apache.org/licenses/LICENSE-2.0
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13 ==============================================================================*/
14 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_HLO_PASS_PIPELINE_H_
15 #define TENSORFLOW_COMPILER_XLA_SERVICE_HLO_PASS_PIPELINE_H_
16 #include <algorithm>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 #include "tensorflow/compiler/xla/ptr_util.h"
22 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h"
23 #include "tensorflow/compiler/xla/statusor.h"
24 #include "tensorflow/compiler/xla/types.h"
25 #include "tensorflow/core/platform/macros.h"
26 namespace xla {
30 class HloPassPipeline : public HloPassInterface {
31  public:
35  explicit HloPassPipeline(const string& name) : name_(name) {}
36  tensorflow::StringPiece name() const override { return name_; }
43  template <typename T, typename... Args>
44  T& AddPass(Args&&... args) {
45  CHECK(!run_called_) << "AddPass cannot be called after Run";
46  auto pass = new T(std::forward<Args>(args)...);
47  passes_.push_back(std::unique_ptr<T>(pass));
48  return *pass;
49  }
56  template <typename T, typename... Args>
57  T& AddInvariantChecker(Args&&... args) {
58  CHECK(!run_called_) << "AddInvariantChecker cannot be called after Run";
59  auto pass = new T(std::forward<Args>(args)...);
60  invariant_checkers_.push_back(std::unique_ptr<T>(pass));
61  return *pass;
62  }
63  // Run all passes on the given HLO module.
64  StatusOr<bool> Run(HloModule* module) override;
65  private:
66  const string name_;
67  std::vector<std::unique_ptr<HloPassInterface>> passes_;
68  std::vector<std::unique_ptr<HloPassInterface>> invariant_checkers_;
69  bool run_called_ = false;
70  TF_DISALLOW_COPY_AND_ASSIGN(HloPassPipeline);
71 };
72 } // namespace xla
73 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_HLO_PASS_PIPELINE_H_
74 
T & AddPass(Args &&... args)
Add a pass to the pipeline. It should be called with the arguments for the pass constructor: ...
Definition: hlo_pass_pipeline.h:44
HloPassPipeline(const string &name)
Definition: hlo_pass_pipeline.h:35
StatusOr< bool > Run(HloModule *module) override
Run the Hlo pipeline by invoking each class&#39; Run method.
Definition: hlo_pass_pipeline.cc:59
namespace for xla
Definition: client_library.cc:26
Definition: hlo_module.h:52
Definition: hlo_pass_pipeline.h:30
T & AddInvariantChecker(Args &&... args)
Definition: hlo_pass_pipeline.h:57