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_EXECUTABLE_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_INTERPRETER_EXECUTABLE_H_ 18 19 #include <memory> 20 21 #include "absl/types/span.h" 22 #include "tensorflow/compiler/xla/service/executable.h" 23 #include "tensorflow/compiler/xla/service/hlo_cost_analysis.h" 24 #include "tensorflow/compiler/xla/service/hlo_evaluator.h" 25 #include "tensorflow/compiler/xla/service/hlo_execution_profile.h" 26 #include "tensorflow/compiler/xla/service/hlo_module.h" 27 #include "tensorflow/compiler/xla/service/hlo_module_config.h" 28 #include "tensorflow/compiler/xla/service/interpreter/executable_base.h" 29 #include "tensorflow/compiler/xla/service/service_executable_run_options.h" 30 #include "tensorflow/compiler/xla/service/shaped_buffer.h" 31 #include "tensorflow/compiler/xla/statusor.h" 32 #include "tensorflow/compiler/xla/types.h" 33 #include "tensorflow/compiler/xla/xla_data.pb.h" 34 #include "tensorflow/core/platform/stream_executor_no_cuda.h" 35 36 namespace xla { 37 namespace interpreter { 38 39 // Responsible for running a HLO graph through the HloEvaluator and output 40 // buffer allocation. Refer to interpreter/README.md for more. 41 class InterpreterExecutable : public InterpreterExecutableBase { 42 public: 43 InterpreterExecutable( 44 std::unique_ptr<HloModule> hlo_module, 45 std::unique_ptr<HloEvaluator> evaluator, 46 std::optional<DynamicDimensionInference> dynamic_dymension_inference); 47 48 static int64_t ShapeSizeBytes(const Shape& shape); 49 50 protected: 51 StatusOr<Literal> Evaluate(const ServiceExecutableRunOptions* run_options, 52 const HloComputation& computation, 53 absl::Span<const Literal> arg_literals) override 54 ABSL_LOCKS_EXCLUDED(evaluator_lock_); 55 56 // The interpreter interprets executables with an HloEvaluator. 57 std::unique_ptr<HloEvaluator> evaluator_ ABSL_PT_GUARDED_BY(evaluator_lock_); 58 mutable absl::Mutex evaluator_lock_; 59 60 private: 61 std::optional<DynamicDimensionInference> dynamic_dimension_inference_; 62 InterpreterExecutable(const InterpreterExecutable&) = delete; 63 InterpreterExecutable& operator=(const InterpreterExecutable&) = delete; 64 }; 65 66 } // namespace interpreter 67 } // namespace xla 68 69 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_INTERPRETER_EXECUTABLE_H_ 70