Program Listing for File testOnnxLoad.cpp
↰ Return to documentation for file (Project-DJ-Engine\include\tests\testOnnxLoad.cpp)
#include <onnxruntime_cxx_api.h>
#include <exception>
#include <iostream>
#include <string>
#include <string_view>
#ifndef PDJE_EXPECTED_ONNXRUNTIME_VERSION
#define PDJE_EXPECTED_ONNXRUNTIME_VERSION ""
#endif
namespace {
constexpr std::string_view kExpectedOrtVersion = PDJE_EXPECTED_ONNXRUNTIME_VERSION;
} // namespace
int
main()
{
try {
const char *c_version = OrtGetApiBase()->GetVersionString();
if (c_version == nullptr) {
std::cerr << "ONNX Runtime returned a null version string" << std::endl;
return 2;
}
const std::string_view c_version_view(c_version);
if (c_version_view != kExpectedOrtVersion) {
std::cerr << "Unexpected ONNX Runtime C API version: " << c_version_view
<< std::endl;
return 3;
}
const std::string cpp_version = Ort::GetVersionString();
if (cpp_version != kExpectedOrtVersion) {
std::cerr << "Unexpected ONNX Runtime C++ API version: " << cpp_version
<< std::endl;
return 4;
}
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "testOnnxLoad");
Ort::SessionOptions session_options;
session_options.SetIntraOpNumThreads(1);
session_options.SetInterOpNumThreads(1);
session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_DISABLE_ALL);
std::cout << "ONNX Runtime load probe succeeded. version=" << cpp_version
<< std::endl;
return 0;
} catch (const Ort::Exception &ex) {
std::cerr << "ONNX Runtime exception: " << ex.what() << std::endl;
return 5;
} catch (const std::exception &ex) {
std::cerr << "std::exception: " << ex.what() << std::endl;
return 6;
} catch (...) {
std::cerr << "Unknown exception" << std::endl;
return 7;
}
}