From 718ffb113107da9b2bcebe9f21634eac44513829 Mon Sep 17 00:00:00 2001 From: Ivan Berg Date: Wed, 20 Dec 2023 11:51:23 -0800 Subject: [PATCH] Fixes for PR cross-platform build, cpplint --- .../onnxruntime/core/common/logging/logging.h | 3 ++- onnxruntime/core/common/logging/logging.cc | 5 ++++- .../core/common/logging/sinks/composite_sink.h | 2 ++ .../core/framework/execution_providers.h | 4 ++-- .../core/framework/sequential_executor.cc | 6 +++--- .../core/framework/stream_execution_context.cc | 2 +- onnxruntime/core/platform/telemetry.cc | 2 +- onnxruntime/core/platform/telemetry.h | 2 +- .../core/platform/windows/logging/etw_sink.cc | 18 ++++++++++-------- .../core/platform/windows/logging/etw_sink.h | 2 +- onnxruntime/core/platform/windows/telemetry.cc | 6 +++--- onnxruntime/core/platform/windows/telemetry.h | 2 +- .../qnn/builder/qnn_backend_manager.cc | 10 ++++++++-- onnxruntime/core/session/inference_session.cc | 6 +++--- .../core/session/provider_registration.cc | 2 +- .../logging/HowToValidateEtwSinkOutput.md | 2 +- 16 files changed, 44 insertions(+), 30 deletions(-) diff --git a/include/onnxruntime/core/common/logging/logging.h b/include/onnxruntime/core/common/logging/logging.h index 8ff08c9789d52..b67fb5a84e831 100644 --- a/include/onnxruntime/core/common/logging/logging.h +++ b/include/onnxruntime/core/common/logging/logging.h @@ -348,7 +348,8 @@ unsigned int GetProcessId(); /** If the ONNXRuntimeTraceLoggingProvider ETW Provider is enabled, then adds to the existing logger. */ -std::unique_ptr EnhanceLoggerWithEtw(std::unique_ptr existingLogger, logging::Severity originalSeverity, logging::Severity etwSeverity); +std::unique_ptr EnhanceLoggerWithEtw(std::unique_ptr existingLogger, logging::Severity originalSeverity, + logging::Severity etwSeverity); /** If the ONNXRuntimeTraceLoggingProvider ETW Provider is enabled, then can override the logging level. diff --git a/onnxruntime/core/common/logging/logging.cc b/onnxruntime/core/common/logging/logging.cc index 6f4ba1a3c52b1..982040e44c245 100644 --- a/onnxruntime/core/common/logging/logging.cc +++ b/onnxruntime/core/common/logging/logging.cc @@ -245,7 +245,8 @@ unsigned int GetProcessId() { #endif } -std::unique_ptr EnhanceLoggerWithEtw(std::unique_ptr existingLogger, logging::Severity originalSeverity, logging::Severity etwSeverity) { +std::unique_ptr EnhanceLoggerWithEtw(std::unique_ptr existingLogger, logging::Severity originalSeverity, + logging::Severity etwSeverity) { #ifdef _WIN32 auto& manager = EtwRegistrationManager::Instance(); if (manager.IsEnabled()) { @@ -258,6 +259,8 @@ std::unique_ptr EnhanceLoggerWithEtw(std::unique_ptr existingLogge } #else // On non-Windows platforms, just return the existing logger + (void)originalSeverity; + (void)etwSeverity; return existingLogger; #endif // _WIN32 } diff --git a/onnxruntime/core/common/logging/sinks/composite_sink.h b/onnxruntime/core/common/logging/sinks/composite_sink.h index 284bfa5f322b3..9d18eb527ffdd 100644 --- a/onnxruntime/core/common/logging/sinks/composite_sink.h +++ b/onnxruntime/core/common/logging/sinks/composite_sink.h @@ -5,6 +5,8 @@ #include #include +#include +#include #include "core/common/logging/isink.h" #include "core/common/logging/logging.h" diff --git a/onnxruntime/core/framework/execution_providers.h b/onnxruntime/core/framework/execution_providers.h index 0320715a0c7a5..38e1790808456 100644 --- a/onnxruntime/core/framework/execution_providers.h +++ b/onnxruntime/core/framework/execution_providers.h @@ -13,8 +13,8 @@ #include "core/graph/graph_viewer.h" #include "core/common/logging/logging.h" #ifdef _WIN32 +#include #include "core/platform/tracing.h" -#include "winmeta.h" #endif namespace onnxruntime { @@ -48,7 +48,7 @@ class ExecutionProviders { TraceLoggingWrite( telemetry_provider_handle, "ProviderOptions", - TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), + TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingString(provider_id.c_str(), "ProviderId"), TraceLoggingString(config_pair.first.c_str(), "Key"), diff --git a/onnxruntime/core/framework/sequential_executor.cc b/onnxruntime/core/framework/sequential_executor.cc index 9ded6dc23d0e4..ea7f1397c961b 100644 --- a/onnxruntime/core/framework/sequential_executor.cc +++ b/onnxruntime/core/framework/sequential_executor.cc @@ -181,7 +181,7 @@ class SessionScope { } auto& logger = session_state_.Logger(); - VLOGS(logger, VERBOSE) << "Begin execution"; + VLOGS(logger, 0) << "Begin execution"; const SequentialExecutionPlan& seq_exec_plan = *session_state_.GetExecutionPlan(); const auto& exec_plan_vec = seq_exec_plan.execution_plan; VLOGS(logger, 1) << "Size of execution plan vector: " << exec_plan_vec.size(); @@ -515,7 +515,7 @@ onnxruntime::Status ExecuteKernel(StreamExecutionContext& ctx, return Status(status.Category(), status.Code(), msg_string); } ctx.RecycleNodeInputs(idx); - VLOGS(logger, VERBOSE) << "stream " << stream_idx << " launch kernel with idx " << idx; + VLOGS(logger, 0) << "stream " << stream_idx << " launch kernel with idx " << idx; return Status::OK(); } @@ -531,7 +531,7 @@ onnxruntime::Status ExecuteThePlan(const SessionState& session_state, gsl::span< const bool only_execute_path_to_fetches, bool single_thread_mode) { auto* execution_plan = session_state.GetExecutionPlan(); - VLOGS(logger, VERBOSE) << "Number of streams: " << execution_plan->execution_plan.size(); + VLOGS(logger, 0) << "Number of streams: " << execution_plan->execution_plan.size(); int32_t valid_streams = 0; for (auto& stream : execution_plan->execution_plan) { if (stream && stream->steps_.size() > 0) diff --git a/onnxruntime/core/framework/stream_execution_context.cc b/onnxruntime/core/framework/stream_execution_context.cc index 4eef9639a2339..875e7f395bfa8 100644 --- a/onnxruntime/core/framework/stream_execution_context.cc +++ b/onnxruntime/core/framework/stream_execution_context.cc @@ -168,7 +168,7 @@ void StreamExecutionContext::RecycleNodeInputs(onnxruntime::NodeIndex node_index for (auto idx : execution_plan->node_release_list[node_index]) { if (--release_plan_[idx] == 0) { ORT_ENFORCE(frame_.ReleaseMLValue(static_cast(execution_plan->release_actions[idx].value_index)).IsOK()); - VLOGS(*logger_, VERBOSE) << "ort value " << execution_plan->release_actions[idx].value_index << " released"; + VLOGS(*logger_, 0) << "ort value " << execution_plan->release_actions[idx].value_index << " released"; } } } diff --git a/onnxruntime/core/platform/telemetry.cc b/onnxruntime/core/platform/telemetry.cc index 9070200e49f58..8dcdae21a36d6 100644 --- a/onnxruntime/core/platform/telemetry.cc +++ b/onnxruntime/core/platform/telemetry.cc @@ -22,7 +22,7 @@ unsigned char Telemetry::Level() const { } // Get the current keyword -unsigned long long Telemetry::Keyword() const { +uint64_t Telemetry::Keyword() const { return 0; } diff --git a/onnxruntime/core/platform/telemetry.h b/onnxruntime/core/platform/telemetry.h index 7b2c24d3930ad..7b61de9d54073 100644 --- a/onnxruntime/core/platform/telemetry.h +++ b/onnxruntime/core/platform/telemetry.h @@ -44,7 +44,7 @@ class Telemetry { virtual unsigned char Level() const; // Get the current keyword - virtual unsigned long long Keyword() const; + virtual uint64_t Keyword() const; virtual void LogProcessInfo() const; diff --git a/onnxruntime/core/platform/windows/logging/etw_sink.cc b/onnxruntime/core/platform/windows/logging/etw_sink.cc index c2e853b0c9c00..d2f21978df41f 100644 --- a/onnxruntime/core/platform/windows/logging/etw_sink.cc +++ b/onnxruntime/core/platform/windows/logging/etw_sink.cc @@ -145,7 +145,9 @@ void EtwRegistrationManager::LazyInitialize() { } } -void EtwRegistrationManager::InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword, ULONGLONG MatchAllKeyword, PEVENT_FILTER_DESCRIPTOR FilterData, PVOID CallbackContext) { +void EtwRegistrationManager::InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword, + ULONGLONG MatchAllKeyword, PEVENT_FILTER_DESCRIPTOR FilterData, + PVOID CallbackContext) { std::lock_guard lock(callbacks_mutex_); for (const auto& callback : callbacks_) { callback(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext); @@ -176,13 +178,13 @@ void EtwSink::SendImpl(const Timestamp& timestamp, const std::string& logger_id, // TraceLoggingWrite requires (painfully) a compile time constant for the TraceLoggingLevel, // forcing us to use an ugly macro for the call. #define ETW_EVENT_NAME "ONNXRuntimeLogEvent" -#define TRACE_LOG_WRITE(level) \ - TraceLoggingWrite(etw_provider_handle, ETW_EVENT_NAME, \ - TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Logs)), \ - TraceLoggingLevel(level), \ - TraceLoggingString(logger_id.c_str(), "logger"), \ - TraceLoggingString(message.Category(), "category"), \ - TraceLoggingString(message.Location().ToString().c_str(), "location"), \ +#define TRACE_LOG_WRITE(level) \ + TraceLoggingWrite(etw_provider_handle, ETW_EVENT_NAME, \ + TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Logs)), \ + TraceLoggingLevel(level), \ + TraceLoggingString(logger_id.c_str(), "logger"), \ + TraceLoggingString(message.Category(), "category"), \ + TraceLoggingString(message.Location().ToString().c_str(), "location"), \ TraceLoggingString(message.Message().c_str(), "message")) const auto severity{message.Severity()}; diff --git a/onnxruntime/core/platform/windows/logging/etw_sink.h b/onnxruntime/core/platform/windows/logging/etw_sink.h index e54767b647e7e..4744bcde22465 100644 --- a/onnxruntime/core/platform/windows/logging/etw_sink.h +++ b/onnxruntime/core/platform/windows/logging/etw_sink.h @@ -62,7 +62,7 @@ class EtwRegistrationManager { Severity MapLevelToSeverity(); // Get the current keyword - ULONGLONG Keyword() const; + uint64_t Keyword() const; // Get the ETW registration status HRESULT Status() const; diff --git a/onnxruntime/core/platform/windows/telemetry.cc b/onnxruntime/core/platform/windows/telemetry.cc index ed65d23c8cbae..500cb14d6b629 100644 --- a/onnxruntime/core/platform/windows/telemetry.cc +++ b/onnxruntime/core/platform/windows/telemetry.cc @@ -62,7 +62,7 @@ uint32_t WindowsTelemetry::global_register_count_ = 0; bool WindowsTelemetry::enabled_ = true; uint32_t WindowsTelemetry::projection_ = 0; UCHAR WindowsTelemetry::level_ = 0; -ULONGLONG WindowsTelemetry::keyword_ = 0; +UINT64 WindowsTelemetry::keyword_ = 0; WindowsTelemetry::WindowsTelemetry() { std::lock_guard lock(mutex_); @@ -95,7 +95,7 @@ UCHAR WindowsTelemetry::Level() const { return level_; } -ULONGLONG WindowsTelemetry::Keyword() const { +UINT64 WindowsTelemetry::Keyword() const { std::lock_guard lock(provider_change_mutex_); return keyword_; } @@ -244,7 +244,7 @@ void WindowsTelemetry::LogSessionCreation(uint32_t session_id, int64_t ir_versio TraceLoggingBool(true, "UTCReplace_AppSessionGuid"), TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage), TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), - TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), + TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), TraceLoggingLevel(WINEVENT_LEVEL_INFO), // Telemetry info TraceLoggingUInt8(0, "schemaVersion"), diff --git a/onnxruntime/core/platform/windows/telemetry.h b/onnxruntime/core/platform/windows/telemetry.h index 526971ebd0f7c..c3798943d491d 100644 --- a/onnxruntime/core/platform/windows/telemetry.h +++ b/onnxruntime/core/platform/windows/telemetry.h @@ -30,7 +30,7 @@ class WindowsTelemetry : public Telemetry { unsigned char Level() const override; // Get the current keyword - unsigned long long Keyword() const override; + UINT64 Keyword() const override; // Get the ETW registration status // static HRESULT Status(); diff --git a/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc b/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc index 0709814275c2c..d4563718a2551 100644 --- a/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc +++ b/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc @@ -19,8 +19,8 @@ #include "core/providers/qnn/builder/onnx_ctx_model_helper.h" #ifdef _WIN32 +#include #include "core/platform/tracing.h" -#include "winmeta.h" #endif // Flag to determine if Backend should do node validation for each opNode added @@ -943,6 +943,10 @@ Status QnnBackendManager::ExtractProfilingEventBasic( std::string message = GetEventTypeString(event_data.type); std::string unit = GetUnitString(event_data.unit); +#ifndef _WIN32 + tracelogging_provider_ep_enabled = false; +#endif + if (!tracelogging_provider_ep_enabled) { outfile << "UNKNOWN" << "," @@ -1013,10 +1017,11 @@ void QnnBackendManager::LogQnnProfileEventAsTraceLogging( const std::string& timingSource, const std::string& eventLevel, const char* eventIdentifier) { +#ifdef _WIN32 TraceLoggingWrite( telemetry_provider_handle, "QNNProfilingEvent", - TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Profiling)), + TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Profiling)), TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingValue(timestamp, "Timestamp"), TraceLoggingString(message.c_str(), "Message"), @@ -1025,6 +1030,7 @@ void QnnBackendManager::LogQnnProfileEventAsTraceLogging( TraceLoggingString(timingSource.c_str(), "Timing Source"), TraceLoggingString(eventLevel.c_str(), "Event Level"), TraceLoggingString(eventIdentifier, "Event Identifier")); +#endif } const std::string& QnnBackendManager::GetUnitString(QnnProfile_EventUnit_t unitType) { diff --git a/onnxruntime/core/session/inference_session.cc b/onnxruntime/core/session/inference_session.cc index 576953d7304e5..c2f1a5733e315 100644 --- a/onnxruntime/core/session/inference_session.cc +++ b/onnxruntime/core/session/inference_session.cc @@ -479,7 +479,7 @@ void InferenceSession::TraceSessionOptions(const SessionOptions& session_options #ifdef _WIN32 TraceLoggingWrite(telemetry_provider_handle, "SessionOptions", - TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), + TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingUInt8(static_cast(session_options.execution_mode), "execution_mode"), TraceLoggingUInt8(static_cast(session_options.execution_order), "execution_order"), @@ -501,7 +501,7 @@ void InferenceSession::TraceSessionOptions(const SessionOptions& session_options TraceLoggingWrite( telemetry_provider_handle, "SessionOptions_IntraOrtThreadPoolParams", - TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), + TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingInt32(session_options.intra_op_param.thread_pool_size, "thread_pool_size"), TraceLoggingBoolean(session_options.intra_op_param.auto_set_affinity, "auto_set_affinity"), @@ -515,7 +515,7 @@ void InferenceSession::TraceSessionOptions(const SessionOptions& session_options TraceLoggingWrite( telemetry_provider_handle, "SessionOptions_ConfigEntry", - TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), + TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingString(config_pair.first.c_str(), "Key"), TraceLoggingString(config_pair.second.c_str(), "Value")); diff --git a/onnxruntime/core/session/provider_registration.cc b/onnxruntime/core/session/provider_registration.cc index 5880a26073e52..e05030f9773c5 100644 --- a/onnxruntime/core/session/provider_registration.cc +++ b/onnxruntime/core/session/provider_registration.cc @@ -77,7 +77,7 @@ ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider, TraceLoggingWrite( telemetry_provider_handle, "ProviderOptionsAppendExecutionProvider", - TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), + TraceLoggingKeyword(static_cast(onnxruntime::logging::TLKeyword::Session)), TraceLoggingLevel(WINEVENT_LEVEL_INFO), TraceLoggingString(provider_name, "ProviderName"), TraceLoggingString(config_pair.first.c_str(), "Key"), diff --git a/onnxruntime/test/platform/windows/logging/HowToValidateEtwSinkOutput.md b/onnxruntime/test/platform/windows/logging/HowToValidateEtwSinkOutput.md index 6048fffa558f8..59fe946b929f2 100644 --- a/onnxruntime/test/platform/windows/logging/HowToValidateEtwSinkOutput.md +++ b/onnxruntime/test/platform/windows/logging/HowToValidateEtwSinkOutput.md @@ -5,7 +5,7 @@ The ETW Sink (ONNXRuntimeTraceLoggingProvider) allows ONNX semi-structured print ETW makes it easy and useful to only enable and listen for events with great performance, and when you need them instead of only at compile time. Therefore ONNX will preserve any existing loggers and log severity [provided at compile time](docs/FAQ.md?plain=1#L7). -However, when the provider is enabled a new ETW logger sink will also be added and the severity seperately controlled via ETW dynamically. +However, when the provider is enabled a new ETW logger sink will also be added and the severity separately controlled via ETW dynamically. - Provider GUID: 929DD115-1ECB-4CB5-B060-EBD4983C421D - Keyword: Logs (0x2) keyword per [logging.h](include\onnxruntime\core\common\logging\logging.h)