1 /* Copyright 2017 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 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_INTERPRETER_COMPILER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_INTERPRETER_COMPILER_H_ 18 19 #include <memory> 20 #include <vector> 21 22 #include "tensorflow/compiler/xla/service/compiler.h" 23 #include "tensorflow/compiler/xla/service/executable.h" 24 #include "tensorflow/compiler/xla/service/hlo_cost_analysis.h" 25 #include "tensorflow/compiler/xla/service/hlo_module.h" 26 #include "tensorflow/compiler/xla/service/hlo_module_config.h" 27 #include "tensorflow/compiler/xla/service/interpreter/platform_id.h" 28 #include "tensorflow/compiler/xla/status.h" 29 #include "tensorflow/compiler/xla/statusor.h" 30 #include "tensorflow/core/lib/core/status.h" 31 #include "tensorflow/stream_executor/stream_executor.h" 32 33 namespace xla { 34 namespace interpreter { 35 36 // Despite the inherited "compiler" naming, InterpreterCompiler does not 37 // perform any lowering as other backends do. It operates at HLO-level for 38 // and is responsible for generating an InterpreterExecutable. 39 // Refer to interpreter/README.md for more. 40 class InterpreterCompiler : public Compiler { 41 public: InterpreterCompiler()42 InterpreterCompiler() {} ~InterpreterCompiler()43 ~InterpreterCompiler() override {} 44 45 StatusOr<std::unique_ptr<HloModule>> RunHloPasses( 46 std::unique_ptr<HloModule> hlo_module, se::StreamExecutor* stream_exec, 47 const CompileOptions& options) override; 48 StatusOr<std::unique_ptr<Executable>> RunBackend( 49 std::unique_ptr<HloModule> hlo_module, se::StreamExecutor* stream_exec, 50 const CompileOptions& options) override; 51 StatusOr<std::vector<std::unique_ptr<Executable>>> Compile( 52 std::unique_ptr<HloModuleGroup> module_group, 53 std::vector<std::vector<se::StreamExecutor*>> stream_exec, 54 const CompileOptions& options) override; 55 56 StatusOr<std::vector<std::unique_ptr<AotCompilationResult>>> 57 CompileAheadOfTime(std::unique_ptr<HloModuleGroup> module_group, 58 const AotCompilationOptions& aot_options) override; 59 60 HloCostAnalysis::ShapeSizeFunction ShapeSizeBytesFunction() const override; 61 62 se::Platform::Id PlatformId() const override; 63 64 private: 65 Status RunHloOptimization(HloModule* hlo_module); 66 67 InterpreterCompiler(const InterpreterCompiler&) = delete; 68 InterpreterCompiler& operator=(const InterpreterCompiler&) = delete; 69 }; 70 71 } // namespace interpreter 72 } // namespace xla 73 74 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_INTERPRETER_COMPILER_H_ 75