tf_1.8_xla_doc
llvm_compiler.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_LLVM_COMPILER_H_
15 #define TENSORFLOW_COMPILER_XLA_SERVICE_LLVM_COMPILER_H_
16 #include "llvm/IR/Module.h"
18 namespace xla {
34 class LLVMCompiler : public Compiler {
35  public:
36  ~LLVMCompiler() override {}
37  // A callback of this type can be run before and/or after IR-level
38  // optimization to e.g. dump out the generated IR to disk or gather some
39  // statistics.
40  using ModuleHook = std::function<Status(const llvm::Module&)>;
41  void SetPreOptimizationHook(ModuleHook hook) {
42  CHECK(!user_pre_optimization_hook_)
43  << "Pre-optimization hook is already set";
44  CHECK(hook) << "hook cannot be null";
45  user_pre_optimization_hook_ = hook;
46  }
47  void RemovePreOptimizationHook() { user_pre_optimization_hook_ = nullptr; }
48  void SetPostOptimizationHook(ModuleHook hook) {
49  CHECK(!user_post_optimization_hook_)
50  << "Post-optimization hook is already set";
51  CHECK(hook) << "hook cannot be null";
52  user_post_optimization_hook_ = hook;
53  }
54  void RemovePostOptimizationHook() { user_post_optimization_hook_ = nullptr; }
55  // Bring in
56  // StatusOr<std::unique_ptr<Executable>> RunBackend(
57  // std::unique_ptr<HloModule> module,
58  // perftools::gputools::StreamExecutor* stream_exec,
59  // DeviceMemoryAllocator* device_allocator)
60  // StatusOr<std::unique_ptr<HloModule>> RunHloPasses(
61  // std::unique_ptr<HloModule> module,
62  // perftools::gputools::StreamExecutor* stream_exec,
63  // DeviceMemoryAllocator* device_allocator)
64  using Compiler::RunBackend;
65  using Compiler::RunHloPasses;
66  StatusOr<std::vector<std::unique_ptr<Executable>>> Compile(
67  std::vector<std::unique_ptr<HloModule>> modules,
68  std::vector<std::vector<perftools::gputools::StreamExecutor*>>
69  stream_execs,
70  DeviceMemoryAllocator* device_allocator) override;
71  protected:
72  ModuleHook user_pre_optimization_hook_;
73  ModuleHook user_post_optimization_hook_;
74 };
75 } // namespace xla
76 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_LLVM_COMPILER_H_
Definition: llvm_compiler.h:34
namespace for xla
Definition: client_library.cc:26
Definition: compiler.h:92