tf_1.8_xla_doc
cpu_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_CPU_CPU_COMPILER_H_
15 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_CPU_COMPILER_H_
16 #include <memory>
17 #include "tensorflow/compiler/xla/service/executable.h"
20 #include "tensorflow/compiler/xla/statusor.h"
21 #include "tensorflow/core/lib/gtl/array_slice.h"
22 #include "tensorflow/core/platform/macros.h"
23 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
24 namespace xla {
31 namespace cpu {
32 class CpuAotCompilationOptions : public AotCompilationOptions {
33  public:
34  // Relocation models available for compilation.
35  enum class RelocationModel {
36  // Corresponds to the -fno-pic compiler option.
37  Static,
38  // Corresponds to the -fpic compiler option.
39  SmallPic,
40  // Corresponds to the -fPIC compiler option.
41  BigPic,
42  // Corresponds to the -fpie compiler option.
43  SmallPie,
44  // Corresponds to the -fPIE compiler option.
45  BigPie
46  };
47  CpuAotCompilationOptions(string triple, string cpu_name, string features,
48  string entry_point_name,
49  RelocationModel relocation_model);
50  ~CpuAotCompilationOptions() override;
51  perftools::gputools::Platform::Id PlatformId() const override;
52  // The triple used for compilation, similar to clang's -target flag.
53  const string& triple() const { return triple_; }
54  // The CPU name used for compilation, similar to clang's -mcpu flag.
55  const string& cpu_name() const { return cpu_name_; }
56  // The target features used for compilation ("+avx2", "+neon", etc).
57  const string& features() const { return features_; }
58  // The name to be used for the compiled code's entry point.
59  const string& entry_point_name() const { return entry_point_name_; }
60  // The relocation model used for compilation.
61  RelocationModel relocation_model() const { return relocation_model_; }
62  private:
63  const string triple_;
64  const string cpu_name_;
65  const string features_;
66  const string entry_point_name_;
67  const RelocationModel relocation_model_;
68 };
69 class CpuAotCompilationResult : public AotCompilationResult {
70  public:
71  CpuAotCompilationResult(ObjectFileData object_file_data,
72  BufferSizes buffer_sizes, int64 result_buffer_index);
73  ~CpuAotCompilationResult();
74  const ObjectFileData& object_file_data() const { return object_file_data_; }
75  const BufferSizes& buffer_sizes() const { return buffer_sizes_; }
76  int64 result_buffer_index() const { return result_buffer_index_; }
77  private:
78  // Contains the compiled computation: an object file.
79  const ObjectFileData object_file_data_;
80  // The list of buffer sizes which should be allocated in order to execute the
81  // compiled computation. These buffers are used for temporary buffers used
82  // ephemerally during computation as well as the output result.
83  const BufferSizes buffer_sizes_;
84  // Contains which buffer index into |buffer_sizes| was designated to the
85  // result of the computation. This buffer should be passed into the output
86  // parameter when calling the compiled computation.
87  const int64 result_buffer_index_;
88 };
97 class CpuCompiler : public LLVMCompiler {
98  public:
99  CpuCompiler();
100  ~CpuCompiler() override {}
101  // Bring in
102  // StatusOr<std::vector<std::unique_ptr<Executable>>> Compile(
103  // std::vector<std::unique_ptr<HloModule>> modules,
104  // std::vector<std::vector<perftools::gputools::StreamExecutor*>>
105  // stream_execs)
106  using LLVMCompiler::Compile;
107  StatusOr<std::unique_ptr<HloModule>> RunHloPasses(
108  std::unique_ptr<HloModule> module,
109  perftools::gputools::StreamExecutor* stream_exec,
110  DeviceMemoryAllocator* device_allocator) override;
111  StatusOr<std::unique_ptr<Executable>> RunBackend(
112  std::unique_ptr<HloModule> module,
113  perftools::gputools::StreamExecutor* stream_exec,
114  DeviceMemoryAllocator* device_allocator) override;
115  StatusOr<std::vector<std::unique_ptr<AotCompilationResult>>>
116  CompileAheadOfTime(std::vector<std::unique_ptr<HloModule>> modules,
117  const AotCompilationOptions& options) override;
118  perftools::gputools::Platform::Id PlatformId() const override;
119  HloCostAnalysis::ShapeSizeFunction ShapeSizeBytesFunction() const override;
120  private:
121  // Initialize the LLVM target.
122  static void InitializeLLVMTarget();
123  // Runs the HLO passes which are necessary for both optimizations and
124  // correctness.
125  Status RunHloPasses(HloModule* module, bool is_aot_compile);
126  TF_DISALLOW_COPY_AND_ASSIGN(CpuCompiler);
127 };
128 } // namespace cpu
129 } // namespace xla
130 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_CPU_COMPILER_H_
StatusOr< std::vector< std::unique_ptr< AotCompilationResult > > > CompileAheadOfTime(std::vector< std::unique_ptr< HloModule >> modules, const AotCompilationOptions &options) override
Definition: cpu_compiler.cc:726
Definition: llvm_compiler.h:34
Definition: cpu_compiler.h:97
namespace for xla
Definition: client_library.cc:26
Definition: hlo_module.h:52