mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-23 19:32:23 +00:00
Switched the code to C++17. To build ONNX Runtime on old distros like CentOS 7, you need to install a newer GCC from additionary repos. If you build onnxruntime with the newer GCC, typically the result binary can't be distributed to other places because it depends on the new GCC's runtime libraries, something that the stock OS doesn't have. But on RHEL/CentOS, it can be better. We use Red Hat devtoolset 8/9/10 with CentOS7 building our code. The new library features(like std::filesystem) that not exists in the old C++ runtime will be statically linked into the applications with some restrictions: 1. GCC has dual ABI, but we can only use the old one. It means std::string is still copy-on-write and std::list::size() is still O(n). Also, if you build onnxruntime on CentOS 7 and link it with some binaries that were built on CentOS 8 or Ubuntu with the new ABI and export C++ symbols directly(instead of using a C API), the it won't work. 2. We still can't use std::optional. It is a limitation coming from macOS. We will solve it when we got macOS 11 build machines. It won't be too long. 3. Please avoid to use C++17 in CUDA files(*.cu). Also, the *.h files that they include(like core/framework/float16.h). This is Because CUDA 10.2 doesn't support C++17. You are welcome to use the new features in any *.cc files.
62 lines
1.9 KiB
C++
62 lines
1.9 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#pragma once
|
|
|
|
#include "core/flatbuffers/schema/ort.fbs.h"
|
|
|
|
#if !defined(ORT_MINIMAL_BUILD)
|
|
//
|
|
// Includes to parse json session config from onnx model file
|
|
//
|
|
#include "core/graph/onnx_protobuf.h"
|
|
#include "core/session/inference_session.h"
|
|
#include "core/framework/session_options.h"
|
|
#include "core/common/common.h"
|
|
#include "nlohmann/json.hpp"
|
|
using json = nlohmann::json;
|
|
#endif
|
|
|
|
namespace onnxruntime {
|
|
|
|
namespace inference_session_utils {
|
|
|
|
// need this value to be accessible in all builds in order to report error for attempted usage in a minimal build
|
|
static constexpr const char* kOrtLoadConfigFromModelEnvVar = "ORT_LOAD_CONFIG_FROM_MODEL";
|
|
|
|
#if !defined(ORT_MINIMAL_BUILD)
|
|
//
|
|
// Code to parse json session config from onnx model file
|
|
//
|
|
static constexpr const char* kOrtConfigKey = "ort_config";
|
|
static constexpr const char* kSessionOptionsKey = "session_options";
|
|
|
|
class JsonConfigParser {
|
|
public:
|
|
JsonConfigParser(const logging::Logger& logger) : logger_(logger) {
|
|
}
|
|
|
|
Status ParseOrtConfigJsonInModelProto(const ONNX_NAMESPACE::ModelProto& model_proto);
|
|
|
|
Status ParseSessionOptionsFromModelProto(/*out*/ SessionOptions& session_options);
|
|
|
|
Status ParseRunOptionsFromModelProto(/*out*/ RunOptions& run_options);
|
|
|
|
private:
|
|
// Logger instance that will be used to log events along the parsing steps
|
|
const logging::Logger& logger_;
|
|
|
|
// Flag indicating if the model has been checked for ort config json existence
|
|
bool is_model_checked_for_ort_config_json_ = false;
|
|
|
|
// Parsed json available for other utility methods to use (if the model did have a valid json)
|
|
nlohmann::json parsed_json_;
|
|
|
|
// Flag indicating if an ort config json is available to be used
|
|
bool is_ort_config_json_available_ = false;
|
|
};
|
|
|
|
#endif // !defined(ORT_MINIMAL_BUILD)
|
|
|
|
} // namespace inference_session_utils
|
|
} // namespace onnxruntime
|