mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
InferenceSession::Run needs to call OnRunEnd for any EP that OnRunStart was called for so they can cleanup. Currently it only calls OnRunEnd if the Status is OK. Due to this the CUDA EP will throw during shutdown as the per-thread information has not been cleaned up prior to the CUDA library shutting down. (#2881)
Also update onnxruntime_perf_test to catch the exception from the call to Run and return a Status. Otherwise it exits with an 'unknown exception' error.
This commit is contained in:
parent
38b34babe0
commit
9f5e8c4ae8
2 changed files with 24 additions and 4 deletions
|
|
@ -1016,6 +1016,9 @@ Status InferenceSession::Run(const RunOptions& run_options, const std::vector<st
|
|||
#endif
|
||||
Status retval = Status::OK();
|
||||
|
||||
std::vector<IExecutionProvider*> exec_providers_to_stop;
|
||||
exec_providers_to_stop.reserve(execution_providers_.NumProviders());
|
||||
|
||||
try {
|
||||
if (!is_inited_) {
|
||||
LOGS(*session_logger_, ERROR) << "Session was not initialized";
|
||||
|
|
@ -1044,7 +1047,16 @@ Status InferenceSession::Run(const RunOptions& run_options, const std::vector<st
|
|||
// info all execution providers InferenceSession:Run started
|
||||
// TODO: only call OnRunStart for all providers in-use
|
||||
for (auto& xp : execution_providers_) {
|
||||
ORT_CHECK_AND_SET_RETVAL(xp->OnRunStart());
|
||||
// call OnRunStart and add to exec_providers_to_stop if successful
|
||||
auto start_func = [&xp, &exec_providers_to_stop]() {
|
||||
auto status = xp->OnRunStart();
|
||||
if (status.IsOK())
|
||||
exec_providers_to_stop.push_back(xp.get());
|
||||
|
||||
return status;
|
||||
};
|
||||
|
||||
ORT_CHECK_AND_SET_RETVAL(start_func());
|
||||
}
|
||||
|
||||
// execute the graph
|
||||
|
|
@ -1060,8 +1072,9 @@ Status InferenceSession::Run(const RunOptions& run_options, const std::vector<st
|
|||
}
|
||||
|
||||
// info all execution providers InferenceSession:Run ended
|
||||
for (auto& xp : execution_providers_) {
|
||||
ORT_CHECK_AND_SET_RETVAL(xp->OnRunEnd());
|
||||
for (auto* xp : exec_providers_to_stop) {
|
||||
auto status = xp->OnRunEnd();
|
||||
ORT_CHECK_AND_SET_RETVAL(status);
|
||||
}
|
||||
|
||||
--current_num_runs_;
|
||||
|
|
|
|||
|
|
@ -99,7 +99,14 @@ class PerformanceRunner {
|
|||
|
||||
template <bool isWarmup>
|
||||
Status RunOneIteration() {
|
||||
std::chrono::duration<double> duration_seconds = session_->Run();
|
||||
std::chrono::duration<double> duration_seconds;
|
||||
|
||||
try {
|
||||
duration_seconds = session_->Run();
|
||||
} catch (const std::exception& ex) {
|
||||
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "PerformanceRunner::RunOneIteration caught exception: ", ex.what());
|
||||
}
|
||||
|
||||
if (!isWarmup) {
|
||||
std::lock_guard<std::mutex> guard(results_mutex_);
|
||||
performance_result_.time_costs.emplace_back(duration_seconds.count());
|
||||
|
|
|
|||
Loading…
Reference in a new issue