diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index 5771a4c8397da..51352b9f99346 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -62,5 +62,9 @@ std::unique_ptr HostingEnvironment::GetLogger(const std::string return default_logging_manager_.CreateLogger(id, severity_, false); } +onnxruntime::InferenceSession* HostingEnvironment::GetSession() const { + return session.get(); +} + } // namespace hosting } // namespace onnxruntime diff --git a/onnxruntime/hosting/environment.h b/onnxruntime/hosting/environment.h index c413a20c66303..011fc1336710f 100644 --- a/onnxruntime/hosting/environment.h +++ b/onnxruntime/hosting/environment.h @@ -25,11 +25,10 @@ class HostingEnvironment { std::unique_ptr GetLogger(const std::string& id); logging::Severity GetLogSeverity() const; - common::Status - InitializeModel(const std::string& model_path); + onnxruntime::InferenceSession* GetSession() const; + common::Status InitializeModel(const std::string& model_path); const std::vector& GetModelOutputNames() const; - std::unique_ptr session; private: const logging::Severity severity_; @@ -38,6 +37,7 @@ class HostingEnvironment { std::unique_ptr runtime_environment_; onnxruntime::SessionOptions options_; + std::unique_ptr session; std::vector model_output_names_; }; diff --git a/onnxruntime/hosting/executor.cc b/onnxruntime/hosting/executor.cc index a7ea6987f65fe..0a3f26d215548 100644 --- a/onnxruntime/hosting/executor.cc +++ b/onnxruntime/hosting/executor.cc @@ -114,7 +114,7 @@ protobufutil::Status Executor::Predict(const std::string& model_name, run_options.run_log_verbosity_level = static_cast(env_->GetLogSeverity()); run_options.run_tag = request_id_; - auto status = env_->session->Run(run_options, name_ml_value_map, output_names, &outputs); + auto status = env_->GetSession()->Run(run_options, name_ml_value_map, output_names, &outputs); if (!status.IsOK()) { LOGS(*logger, ERROR) << "Run() failed." diff --git a/onnxruntime/hosting/main.cc b/onnxruntime/hosting/main.cc index 8bbb58e38d9b5..6f8068f8c90fc 100644 --- a/onnxruntime/hosting/main.cc +++ b/onnxruntime/hosting/main.cc @@ -33,7 +33,7 @@ int main(int argc, char* argv[]) { LOGS(logger, VERBOSE) << "Initialize Model Successfully!"; } - status = env->session->Initialize(); + status = env->GetSession()->Initialize(); if (!status.IsOK()) { LOGS(logger, FATAL) << "Session Initialization Failed:" << status.Code() << " ---- Error: [" << status.ErrorMessage() << "]"; exit(EXIT_FAILURE);