mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-24 19:43:35 +00:00
* init no exception changes * initial test * disable exceptions * more throw handling * minor update * fix linux build break * fix windows/nuphar build break * address cr comments, move #ifdef to ORT_CATCH * address cr comments, move #ifdef to ORT_CATCH * handle return statement in ORT_CATCH * linux build break fix * addressed cr comments, remove ort_catch_end * addressed cr comments, remove ort_catch_end * move mlas to a separated ifdef flag * merge master, move some new code in master to no_exc Co-authored-by: gwang0000 <62914304+gwang0000@users.noreply.github.com>
87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
// onnxruntime dependencies
|
|
#include <core/session/onnxruntime_c_api.h>
|
|
#include <random>
|
|
#include "command_args_parser.h"
|
|
#include "performance_runner.h"
|
|
#include <google/protobuf/stubs/common.h>
|
|
|
|
using namespace onnxruntime;
|
|
const OrtApi* g_ort = NULL;
|
|
|
|
#ifdef _WIN32
|
|
int real_main(int argc, wchar_t* argv[]) {
|
|
#else
|
|
int real_main(int argc, char* argv[]) {
|
|
#endif
|
|
g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION);
|
|
perftest::PerformanceTestConfig test_config;
|
|
if (!perftest::CommandLineParser::ParseArguments(test_config, argc, argv)) {
|
|
perftest::CommandLineParser::ShowUsage();
|
|
return -1;
|
|
}
|
|
Ort::Env env{nullptr};
|
|
{
|
|
bool failed = false;
|
|
ORT_TRY {
|
|
OrtLoggingLevel logging_level = test_config.run_config.f_verbose
|
|
? ORT_LOGGING_LEVEL_VERBOSE
|
|
: ORT_LOGGING_LEVEL_WARNING;
|
|
env = Ort::Env(logging_level, "Default");
|
|
}
|
|
ORT_CATCH(const Ort::Exception& e) {
|
|
ORT_HANDLE_EXCEPTION([&]() {
|
|
fprintf(stderr, "Error creating environment: %s \n", e.what());
|
|
failed = true;
|
|
});
|
|
}
|
|
|
|
if (failed)
|
|
return -1;
|
|
}
|
|
|
|
if (test_config.machine_config.provider_type_name == onnxruntime::kOpenVINOExecutionProvider) {
|
|
if (test_config.run_config.concurrent_session_runs != 1) {
|
|
fprintf(stderr, "OpenVINO doesn't support more than 1 session running simultaneously default value of 1 will be set \n");
|
|
test_config.run_config.concurrent_session_runs = 1;
|
|
}
|
|
if (test_config.run_config.execution_mode == ExecutionMode::ORT_PARALLEL) {
|
|
fprintf(stderr, "OpenVINO doesn't support parallel executor using sequential executor\n");
|
|
test_config.run_config.execution_mode = ExecutionMode::ORT_SEQUENTIAL;
|
|
}
|
|
}
|
|
std::random_device rd;
|
|
perftest::PerformanceRunner perf_runner(env, test_config, rd);
|
|
auto status = perf_runner.Run();
|
|
if (!status.IsOK()) {
|
|
printf("Run failed:%s\n", status.ErrorMessage().c_str());
|
|
return -1;
|
|
}
|
|
|
|
perf_runner.SerializeResult();
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
int wmain(int argc, wchar_t* argv[]) {
|
|
#else
|
|
int main(int argc, char* argv[]) {
|
|
#endif
|
|
int retval = -1;
|
|
ORT_TRY {
|
|
retval = real_main(argc, argv);
|
|
}
|
|
ORT_CATCH(const std::exception& ex) {
|
|
ORT_HANDLE_EXCEPTION([&]() {
|
|
fprintf(stderr, "%s\n", ex.what());
|
|
retval = -1;
|
|
});
|
|
}
|
|
|
|
::google::protobuf::ShutdownProtobufLibrary();
|
|
|
|
return retval;
|
|
}
|