More code cleanup (#1406)

* more cleanup

* More cleanup

* fix build break.

* update
This commit is contained in:
Yuan Yu 2019-07-18 18:21:16 -07:00 committed by Ke Zhang
parent bbf64c2c45
commit c843c393e4
4 changed files with 20 additions and 25 deletions

View file

@ -84,7 +84,7 @@ LoggingManager::LoggingManager(std::unique_ptr<ISink> sink, Severity default_min
default_filter_user_data_{filter_user_data},
default_max_vlog_level_{default_max_vlog_level},
owns_default_logger_{false} {
if (!sink_) {
if (sink_ == nullptr) {
throw std::logic_error("ISink must be provided.");
}
@ -126,7 +126,6 @@ LoggingManager::~LoggingManager() {
void LoggingManager::CreateDefaultLogger(const std::string& logger_id) {
// this method is only called from ctor in scope where DefaultLoggerMutex() is already locked
if (s_default_logger_ != nullptr) {
throw std::logic_error("Default logger already set. ");
}
@ -186,7 +185,8 @@ std::exception LoggingManager::LogFatalAndCreateException(const char* category,
// create Capture in separate scope so it gets destructed (leading to log output) before we throw.
{
::onnxruntime::logging::Capture c{::onnxruntime::logging::LoggingManager::DefaultLogger(),
::onnxruntime::logging::Severity::kFATAL, category, ::onnxruntime::logging::DataType::SYSTEM, location};
::onnxruntime::logging::Severity::kFATAL, category,
::onnxruntime::logging::DataType::SYSTEM, location};
va_list args;
va_start(args, format_str);

View file

@ -1389,7 +1389,7 @@ Example 4:
pads_initializer->int64_data().end());
// fill with zeros if needed to reach appropriate size
if (pads_data.size() != static_cast<size_t>(2 * input_rank))
if (pads_data.size() != 2 * static_cast<size_t>(input_rank))
pads_data.resize(2 * input_rank, 0);
const auto& output_shape =

View file

@ -91,7 +91,8 @@ inline std::basic_string<T> GetCurrentTimeString() {
}
} // namespace
InferenceSession::InferenceSession(const SessionOptions& session_options, logging::LoggingManager* logging_manager)
InferenceSession::InferenceSession(const SessionOptions& session_options,
logging::LoggingManager* logging_manager)
: session_options_{session_options},
graph_transformation_mgr_{session_options_.max_num_graph_transformation_steps},
logging_manager_{logging_manager},
@ -603,7 +604,7 @@ common::Status InferenceSession::ValidateInputs(const std::vector<std::string>&
common::Status InferenceSession::ValidateOutputs(const std::vector<std::string>& output_names,
const std::vector<OrtValue>* p_fetches) {
if (!p_fetches) {
if (p_fetches == nullptr) {
return common::Status(common::ONNXRUNTIME, common::INVALID_ARGUMENT,
"Output vector pointer is NULL");
}
@ -646,8 +647,6 @@ Status InferenceSession::Run(const RunOptions& run_options, const std::vector<st
}
ORT_RETURN_IF_ERROR(ValidateInputs(feed_names, feeds));
// if the output vector is non-empty, ensure that its the same size as the output_names
ORT_RETURN_IF_ERROR(ValidateOutputs(output_names, p_fetches));
FeedsFetchesInfo info(feed_names, output_names);
@ -886,13 +885,12 @@ const logging::Logger& InferenceSession::CreateLoggerForRun(const RunOptions& ru
run_log_id += run_options.run_tag;
logging::Severity severity = logging::Severity::kWARNING;
if (run_options.run_log_severity_level < 0) {
if (run_options.run_log_severity_level == -1) {
severity = session_logger_->GetSeverity();
} else {
ORT_ENFORCE(run_options.run_log_severity_level >= 0 &&
run_options.run_log_severity_level <= static_cast<int>(logging::Severity::kFATAL),
"Invalid run log severity level. Must be a valid onnxruntime::logging::Severity value. Got ",
run_options.run_log_severity_level <= static_cast<int>(logging::Severity::kFATAL),
"Invalid run log severity level. Not a valid onnxruntime::logging::Severity value: ",
run_options.run_log_severity_level);
severity = static_cast<logging::Severity>(run_options.run_log_severity_level);
}
@ -915,26 +913,22 @@ const logging::Logger& InferenceSession::CreateLoggerForRun(const RunOptions& ru
void InferenceSession::InitLogger(logging::LoggingManager* logging_manager) {
// create logger for session, using provided logging manager if possible
if (logging_manager != nullptr) {
std::string session_logid = !session_options_.session_logid.empty()
? session_options_.session_logid
: "InferenceSession"; // there's probably a better default...
if (logging_manager != nullptr && !session_options_.session_logid.empty()) {
logging::Severity severity = logging::Severity::kWARNING;
if (session_options_.session_log_severity_level < 0) {
if (session_options_.session_log_severity_level == -1) {
severity = logging::LoggingManager::DefaultLogger().GetSeverity();
} else {
ORT_ENFORCE(session_options_.session_log_severity_level >= 0 &&
session_options_.session_log_severity_level <= static_cast<int>(logging::Severity::kFATAL),
"Invalid session log severity level. Must be a valid onnxruntime::logging::Severity value. Got ",
session_options_.session_log_severity_level <= static_cast<int>(logging::Severity::kFATAL),
"Invalid session log severity level. Not a valid onnxruntime::logging::Severity value: ",
session_options_.session_log_severity_level);
severity = static_cast<logging::Severity>(session_options_.session_log_severity_level);
}
owned_session_logger_ = logging_manager_->CreateLogger(session_logid, severity, false,
owned_session_logger_ = logging_manager_->CreateLogger(session_options_.session_logid,
severity,
false,
session_options_.session_log_verbosity_level);
session_logger_ = owned_session_logger_.get();
} else {
session_logger_ = &logging::LoggingManager::DefaultLogger();

View file

@ -391,14 +391,15 @@ class InferenceSession {
std::vector<std::string> transformers_to_enable_;
/// Logging manager if provided.
logging::LoggingManager* logging_manager_;
logging::LoggingManager* logging_manager_ = nullptr;
/// Logger for this session. WARNING: Will contain nullptr if logging_manager_ is nullptr.
std::unique_ptr<logging::Logger> owned_session_logger_;
std::unique_ptr<logging::Logger> owned_session_logger_ = nullptr;
// Profiler for this session.
profiling::Profiler session_profiler_;
// The list of execution providers.
ExecutionProviders execution_providers_;
protected: