From 588463774b1144cef27061f7b9f55f58ef499c7b Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Tue, 27 Jan 2026 13:09:29 -0800 Subject: [PATCH 01/13] Update to C++20. --- cmake/CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 42432041a8b01..6b17389f7f4bf 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -35,12 +35,7 @@ include(CheckSymbolExists) include(GNUInstallDirs) # onnxruntime_providers_* require CMAKE_INSTALL_* variables if (NOT CMAKE_CXX_STANDARD) - # TODO: update this once all system adapt c++20 - if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") - set(CMAKE_CXX_STANDARD 20) - else() - set(CMAKE_CXX_STANDARD 17) - endif() + set(CMAKE_CXX_STANDARD 20) endif() if (MSVC) From 98c31aef4bd50e6ab8febce2e7df5feb92a1074f Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Tue, 27 Jan 2026 13:10:31 -0800 Subject: [PATCH 02/13] Fix ostream::operator<< usage with wchar_t*. --- onnxruntime/core/session/utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/session/utils.cc b/onnxruntime/core/session/utils.cc index a354cf26368d4..7ad09e1a2cd5e 100644 --- a/onnxruntime/core/session/utils.cc +++ b/onnxruntime/core/session/utils.cc @@ -549,7 +549,7 @@ Status LoadPluginOrProviderBridge(const std::string& registration_name, true, ProviderLibraryPathType::Absolute); bool is_provider_bridge = provider_library->Load() == Status::OK(); // library has GetProvider - LOGS_DEFAULT(INFO) << "Loading EP library: " << library_path + LOGS_DEFAULT(INFO) << "Loading EP library: " << resolved_library_path << (is_provider_bridge ? " as a provider bridge" : " as a plugin"); // create EpLibraryPlugin to ensure CreateEpFactories and ReleaseEpFactory are available From 9171d14ed45ae153e2c54cf7fb445fa396e2417e Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Tue, 27 Jan 2026 17:03:56 -0800 Subject: [PATCH 03/13] try to fix time_point output operator availability check --- .../onnxruntime/core/common/logging/logging.h | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/include/onnxruntime/core/common/logging/logging.h b/include/onnxruntime/core/common/logging/logging.h index dc930ce52eaa9..38e3aa3725b71 100644 --- a/include/onnxruntime/core/common/logging/logging.h +++ b/include/onnxruntime/core/common/logging/logging.h @@ -58,33 +58,9 @@ namespace logging { using Timestamp = std::chrono::time_point; -// C++20 has operator<< in std::chrono for Timestamp type but mac builds need additional checks -// to ensure usage is valid. -// TODO: As we enable C++20 on other platforms we may need similar checks. -// define a temporary value to determine whether to use the std::chrono or date implementation. -#define ORT_USE_CXX20_STD_CHRONO __cplusplus >= 202002L - -// Apply constraints for mac builds -#if __APPLE__ -#include - -// Catalyst check must be first as it has both TARGET_OS_MACCATALYST and TARGET_OS_MAC set -#if TARGET_OS_MACCATALYST -// maccatalyst requires version 16.3 -#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 160300) -#undef ORT_USE_CXX20_STD_CHRONO -#endif - -#elif TARGET_OS_MAC -// Xcode added support for C++20's std::chrono::operator<< in SDK version 14.4, -// but the target macOS version must also be >= 13.3 for it to be used. -#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED < 140400) || \ - (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 130300) -#undef ORT_USE_CXX20_STD_CHRONO -#endif - -#endif -#endif // __APPLE__ +// C++20 has operator<< in std::chrono for Timestamp type but we need to check if it is available. +// define temporary macro ORT_USE_CXX20_STD_CHRONO to determine whether to use the std::chrono or date implementation. +#define ORT_USE_CXX20_STD_CHRONO __cpp_lib_chrono >= 201803L #if ORT_USE_CXX20_STD_CHRONO namespace timestamp_ns = std::chrono; From 92b3334f0cd5b685501ae5baa59787f9063e80c6 Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Tue, 27 Jan 2026 19:01:16 -0800 Subject: [PATCH 04/13] add back Apple stuff and handle IOS --- .../onnxruntime/core/common/logging/logging.h | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/include/onnxruntime/core/common/logging/logging.h b/include/onnxruntime/core/common/logging/logging.h index 38e3aa3725b71..329c0ed1bf8c5 100644 --- a/include/onnxruntime/core/common/logging/logging.h +++ b/include/onnxruntime/core/common/logging/logging.h @@ -58,10 +58,32 @@ namespace logging { using Timestamp = std::chrono::time_point; -// C++20 has operator<< in std::chrono for Timestamp type but we need to check if it is available. +// C++20 has operator<< in std::chrono for Timestamp type but we need to check if usage is valid. // define temporary macro ORT_USE_CXX20_STD_CHRONO to determine whether to use the std::chrono or date implementation. #define ORT_USE_CXX20_STD_CHRONO __cpp_lib_chrono >= 201803L +// Apply constraints for Apple builds +#if __APPLE__ +#include + +// iOS check must be first as it also has TARGET_OS_MAC set +#if TARGET_OS_IOS +// iOS requires version 16.3 +#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 160300) +#undef ORT_USE_CXX20_STD_CHRONO +#endif + +#elif TARGET_OS_MAC +// Xcode added support for C++20's std::chrono::operator<< in SDK version 14.4, +// but the target macOS version must also be >= 13.3 for it to be used. +#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED < 140400) || \ + (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 130300) +#undef ORT_USE_CXX20_STD_CHRONO +#endif + +#endif +#endif // __APPLE__ + #if ORT_USE_CXX20_STD_CHRONO namespace timestamp_ns = std::chrono; #else From 831ae91ad7007826403f605cb8ce04bda29e1cc6 Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Wed, 28 Jan 2026 20:34:16 -0800 Subject: [PATCH 05/13] make Timestamp a separate type and implement stream insertion operator for it --- .../onnxruntime/core/common/logging/logging.h | 26 +++++++++++++++---- .../core/common/logging/sinks/ostream_sink.cc | 6 +---- .../platform/apple/logging/apple_log_sink.mm | 4 +-- onnxruntime/test/common/logging/helpers.h | 2 -- .../test/util/include/test/capturing_sink.h | 2 -- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/onnxruntime/core/common/logging/logging.h b/include/onnxruntime/core/common/logging/logging.h index 329c0ed1bf8c5..386a9421fc47e 100644 --- a/include/onnxruntime/core/common/logging/logging.h +++ b/include/onnxruntime/core/common/logging/logging.h @@ -56,9 +56,7 @@ struct OrtLogger; // opaque API type. is always an instance of Logger namespace onnxruntime { namespace logging { -using Timestamp = std::chrono::time_point; - -// C++20 has operator<< in std::chrono for Timestamp type but we need to check if usage is valid. +// C++20 has std::chrono::operator<< for std::chrono::system_clock::time_point but we need to check if usage is valid. // define temporary macro ORT_USE_CXX20_STD_CHRONO to determine whether to use the std::chrono or date implementation. #define ORT_USE_CXX20_STD_CHRONO __cpp_lib_chrono >= 201803L @@ -85,13 +83,31 @@ using Timestamp = std::chrono::time_point; #endif // __APPLE__ #if ORT_USE_CXX20_STD_CHRONO -namespace timestamp_ns = std::chrono; +namespace timestamp_stream_insertion_op_ns = std::chrono; #else -namespace timestamp_ns = ::date; +namespace timestamp_stream_insertion_op_ns = ::date; #endif #undef ORT_USE_CXX20_STD_CHRONO +// This class wraps `std::chrono::system_clock::time_point` and provides `operator<<`. +// It is a workaround for the inconsistent availability of `std::chrono::operator<<` for +// `std::chrono::system_clock::time_point`. +// When all builds support `std::chrono::operator<<`, we can simplify to this: +// `using Timestamp = std::chrono::system_clock::time_point;` +class Timestamp { + public: + using TimePoint = std::chrono::system_clock::time_point; + Timestamp(const TimePoint& time_point) noexcept : time_point_{time_point} {} + + friend std::ostream& operator<<(std::ostream& os, const Timestamp& time_stamp) { + return timestamp_stream_insertion_op_ns::operator<<(os, time_stamp.time_point_); + } + + private: + TimePoint time_point_{}; +}; + #ifndef NDEBUG ORT_ATTRIBUTE_UNUSED static bool vlog_enabled = true; // Set directly based on your needs. #else diff --git a/onnxruntime/core/common/logging/sinks/ostream_sink.cc b/onnxruntime/core/common/logging/sinks/ostream_sink.cc index 64441a2b20de2..f8fdb5e1906ed 100644 --- a/onnxruntime/core/common/logging/sinks/ostream_sink.cc +++ b/onnxruntime/core/common/logging/sinks/ostream_sink.cc @@ -23,9 +23,6 @@ struct Color { #ifndef _WIN32 void OStreamSink::SendImpl(const Timestamp& timestamp, const std::string& logger_id, const Capture& message) { - // operator for formatting of timestamp in ISO8601 format including microseconds - using timestamp_ns::operator<<; - // Two options as there may be multiple calls attempting to write to the same sink at once: // 1) Use mutex to synchronize access to the stream. // 2) Create the message in an ostringstream and output in one call. @@ -45,8 +42,7 @@ void OStreamSink::SendImpl(const Timestamp& timestamp, const std::string& logger } #endif - timestamp_ns::operator<<(msg, timestamp); // handle ambiguity with C++20 where date and std::chrono have operator<< - msg << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", " + msg << timestamp << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", " << message.Location().ToString() << "] " << message.Message(); #ifndef ORT_MINIMAL_BUILD diff --git a/onnxruntime/core/platform/apple/logging/apple_log_sink.mm b/onnxruntime/core/platform/apple/logging/apple_log_sink.mm index 6abbe76a7f151..862ea0bf3c825 100644 --- a/onnxruntime/core/platform/apple/logging/apple_log_sink.mm +++ b/onnxruntime/core/platform/apple/logging/apple_log_sink.mm @@ -11,11 +11,9 @@ namespace logging { void AppleLogSink::SendImpl(const Timestamp& timestamp, const std::string& logger_id, const Capture& message) { - using timestamp_ns::operator<<; std::ostringstream msg; - timestamp_ns::operator<<(msg, timestamp); // handle ambiguity with C++20 where date and std::chrono have operator<< - msg << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", " + msg << timestamp << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", " << message.Location().ToString() << "] " << message.Message(); NSLog(@"%s", msg.str().c_str()); } diff --git a/onnxruntime/test/common/logging/helpers.h b/onnxruntime/test/common/logging/helpers.h index 0b623fe9ee09a..bf4d30184b7f6 100644 --- a/onnxruntime/test/common/logging/helpers.h +++ b/onnxruntime/test/common/logging/helpers.h @@ -39,8 +39,6 @@ class MockEtwSink : public ::onnxruntime::logging::ISink { #endif ACTION(PrintArgs) { - using onnxruntime::logging::timestamp_ns::operator<<; - // const Timestamp ×tamp, const std::string &logger_id, const Message &message // arg0 arg1 arg2 std::cout << arg1 << "@" << arg0 << " " diff --git a/onnxruntime/test/util/include/test/capturing_sink.h b/onnxruntime/test/util/include/test/capturing_sink.h index 7d978d1bd1e56..37e1aecabdf25 100644 --- a/onnxruntime/test/util/include/test/capturing_sink.h +++ b/onnxruntime/test/util/include/test/capturing_sink.h @@ -14,8 +14,6 @@ using namespace ::onnxruntime::logging; class CapturingSink : public logging::ISink { public: void SendImpl(const Timestamp& timestamp, const std::string& logger_id, const Capture& message) override { - // operator for formatting of timestamp in ISO8601 format including microseconds - using timestamp_ns::operator<<; std::ostringstream msg; msg << timestamp << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", " From 1e2ad83b6b147bae1bc9a11d241c7479b81d7c5f Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Thu, 29 Jan 2026 10:28:08 -0800 Subject: [PATCH 06/13] move date.h dependency into logging.cc --- .../onnxruntime/core/common/logging/logging.h | 39 ++---------------- onnxruntime/core/common/logging/logging.cc | 41 +++++++++++++++++++ .../platform/posix/logging/syslog_sink.cc | 2 - .../core/platform/windows/logging/etw_sink.h | 1 - .../test/common/logging/logging_test.cc | 2 - .../test/util/include/capturing_sink.h | 4 -- 6 files changed, 44 insertions(+), 45 deletions(-) diff --git a/include/onnxruntime/core/common/logging/logging.h b/include/onnxruntime/core/common/logging/logging.h index 386a9421fc47e..ec6f5df38778d 100644 --- a/include/onnxruntime/core/common/logging/logging.h +++ b/include/onnxruntime/core/common/logging/logging.h @@ -17,7 +17,6 @@ #include "core/common/logging/macros.h" #include "core/common/logging/severity.h" #include "core/common/logging/sink_types.h" -#include "date/date.h" /* @@ -56,40 +55,6 @@ struct OrtLogger; // opaque API type. is always an instance of Logger namespace onnxruntime { namespace logging { -// C++20 has std::chrono::operator<< for std::chrono::system_clock::time_point but we need to check if usage is valid. -// define temporary macro ORT_USE_CXX20_STD_CHRONO to determine whether to use the std::chrono or date implementation. -#define ORT_USE_CXX20_STD_CHRONO __cpp_lib_chrono >= 201803L - -// Apply constraints for Apple builds -#if __APPLE__ -#include - -// iOS check must be first as it also has TARGET_OS_MAC set -#if TARGET_OS_IOS -// iOS requires version 16.3 -#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 160300) -#undef ORT_USE_CXX20_STD_CHRONO -#endif - -#elif TARGET_OS_MAC -// Xcode added support for C++20's std::chrono::operator<< in SDK version 14.4, -// but the target macOS version must also be >= 13.3 for it to be used. -#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED < 140400) || \ - (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 130300) -#undef ORT_USE_CXX20_STD_CHRONO -#endif - -#endif -#endif // __APPLE__ - -#if ORT_USE_CXX20_STD_CHRONO -namespace timestamp_stream_insertion_op_ns = std::chrono; -#else -namespace timestamp_stream_insertion_op_ns = ::date; -#endif - -#undef ORT_USE_CXX20_STD_CHRONO - // This class wraps `std::chrono::system_clock::time_point` and provides `operator<<`. // It is a workaround for the inconsistent availability of `std::chrono::operator<<` for // `std::chrono::system_clock::time_point`. @@ -101,10 +66,12 @@ class Timestamp { Timestamp(const TimePoint& time_point) noexcept : time_point_{time_point} {} friend std::ostream& operator<<(std::ostream& os, const Timestamp& time_stamp) { - return timestamp_stream_insertion_op_ns::operator<<(os, time_stamp.time_point_); + return time_stamp.WriteToStream(os); } private: + std::ostream& WriteToStream(std::ostream& os) const; + TimePoint time_point_{}; }; diff --git a/onnxruntime/core/common/logging/logging.cc b/onnxruntime/core/common/logging/logging.cc index a79e7300cffce..3f80ee4bcec50 100644 --- a/onnxruntime/core/common/logging/logging.cc +++ b/onnxruntime/core/common/logging/logging.cc @@ -28,8 +28,49 @@ #include "logging.h" #endif +// C++20 has std::chrono::operator<< for std::chrono::system_clock::time_point but we need to check if usage is valid. +// define temporary macro ORT_USE_CXX20_STD_CHRONO to determine whether to use the std::chrono or date implementation. +#define ORT_USE_CXX20_STD_CHRONO __cpp_lib_chrono >= 201803L + +// Apply constraints for Apple builds +#if __APPLE__ +#include + +// iOS check must be first as it also has TARGET_OS_MAC set +#if TARGET_OS_IOS +// iOS requires version 16.3 +#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 160300) +#undef ORT_USE_CXX20_STD_CHRONO +#endif + +#elif TARGET_OS_MAC +// Xcode added support for C++20's std::chrono::operator<< in SDK version 14.4, +// but the target macOS version must also be >= 13.3 for it to be used. +#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED < 140400) || \ + (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 130300) +#undef ORT_USE_CXX20_STD_CHRONO +#endif + +#endif +#endif // __APPLE__ + +#if ORT_USE_CXX20_STD_CHRONO +namespace timestamp_stream_insertion_op_ns = std::chrono; +#else +#include "date/date.h" + +namespace timestamp_stream_insertion_op_ns = ::date; +#endif + +#undef ORT_USE_CXX20_STD_CHRONO + namespace onnxruntime { namespace logging { + +std::ostream& Timestamp::WriteToStream(std::ostream& os) const { + return timestamp_stream_insertion_op_ns::operator<<(os, time_point_); +} + const char* Category::onnxruntime = "onnxruntime"; const char* Category::System = "System"; diff --git a/onnxruntime/core/platform/posix/logging/syslog_sink.cc b/onnxruntime/core/platform/posix/logging/syslog_sink.cc index 9fbd26f093498..e5b60cf4742ef 100644 --- a/onnxruntime/core/platform/posix/logging/syslog_sink.cc +++ b/onnxruntime/core/platform/posix/logging/syslog_sink.cc @@ -4,7 +4,6 @@ #include "core/common/logging/logging.h" #include "core/common/logging/capture.h" #include "syslog_sink.h" -#include "date/date.h" namespace onnxruntime { namespace logging { @@ -12,7 +11,6 @@ namespace logging { constexpr const char* SYSLOG_LEVEL = "76432"; void SysLogSink::SendImpl(const Timestamp& timestamp, const std::string& logger_id, const Capture& message) { - using date::operator<<; std::stringstream msg; // syslog has it own timestamp but not as accurate as our timestamp. So we are going to keep both, diff --git a/onnxruntime/core/platform/windows/logging/etw_sink.h b/onnxruntime/core/platform/windows/logging/etw_sink.h index 62b762886ca82..d0c08a2144c20 100644 --- a/onnxruntime/core/platform/windows/logging/etw_sink.h +++ b/onnxruntime/core/platform/windows/logging/etw_sink.h @@ -16,7 +16,6 @@ #ifdef ETW_TRACE_LOGGING_SUPPORTED -#include #include #include #include diff --git a/onnxruntime/test/common/logging/logging_test.cc b/onnxruntime/test/common/logging/logging_test.cc index d3af022f83e86..8e1817e777d9e 100644 --- a/onnxruntime/test/common/logging/logging_test.cc +++ b/onnxruntime/test/common/logging/logging_test.cc @@ -14,8 +14,6 @@ #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(disable : 26400) #endif -// if we pull in the whole 'testing' namespace we get warnings from date.h as both use '_' in places. -// to avoid that we explicitly pull in the pieces we are using using testing::Eq; using testing::Field; using testing::Ge; diff --git a/onnxruntime/test/util/include/capturing_sink.h b/onnxruntime/test/util/include/capturing_sink.h index 39788947602df..37e1aecabdf25 100644 --- a/onnxruntime/test/util/include/capturing_sink.h +++ b/onnxruntime/test/util/include/capturing_sink.h @@ -6,8 +6,6 @@ #include "core/common/logging/logging.h" #include "core/common/logging/isink.h" -#include "date/date.h" - namespace onnxruntime { namespace test { @@ -16,8 +14,6 @@ using namespace ::onnxruntime::logging; class CapturingSink : public logging::ISink { public: void SendImpl(const Timestamp& timestamp, const std::string& logger_id, const Capture& message) override { - // operator for formatting of timestamp in ISO8601 format including microseconds - using date::operator<<; std::ostringstream msg; msg << timestamp << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", " From dad1617c8abaf4c3f847ba564298efcb1cc58ad0 Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Thu, 29 Jan 2026 14:19:12 -0800 Subject: [PATCH 07/13] add exception for MSVC CUDA EP build for now... --- cmake/CMakeLists.txt | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 6b17389f7f4bf..8eca34f4f80e7 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -21,11 +21,6 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "IntelLLVM") endif() endif() -# Needed for Java -if (NOT CMAKE_CXX_STANDARD) - set(CMAKE_C_STANDARD 99) -endif() - include(CheckCXXCompilerFlag) include(CheckLanguage) include(CMakeDependentOption) @@ -34,10 +29,6 @@ include(CheckFunctionExists) include(CheckSymbolExists) include(GNUInstallDirs) # onnxruntime_providers_* require CMAKE_INSTALL_* variables -if (NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 20) -endif() - if (MSVC) # Make sure Visual Studio sets __cplusplus macro correctly: https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") @@ -249,6 +240,24 @@ option(onnxruntime_USE_OPENVINO_INTERFACE "Build ONNXRuntime shared lib which is option(onnxruntime_USE_VITISAI_INTERFACE "Build ONNXRuntime shared lib which is compatible with Vitis-AI EP interface" OFF) option(onnxruntime_USE_QNN_INTERFACE "Build ONNXRuntime shared lib which is compatible with QNN EP interface" OFF) +# Set C/C++ standard versions +if (NOT CMAKE_C_STANDARD) + # Needed for Java + set(CMAKE_C_STANDARD 99) +endif() + +if (NOT CMAKE_CXX_STANDARD) + # TODO move all builds to C++20 + if (MSVC AND onnxruntime_USE_CUDA) + # There's a compilation error from CUTLASS header "cute/tensor.hpp" when attempting to use C++20: + # cutlass-src\include\cute\stride.hpp(299,46): error C3545: 'Ints': parameter pack expects a non-type template + # argument + set(CMAKE_CXX_STANDARD 17) + else() + set(CMAKE_CXX_STANDARD 20) + endif() +endif() + if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 11.1) message(FATAL_ERROR "GCC version must be greater than or equal to 11.1") endif() From 7f34d3bf95466234b16a1a1adc5a674abb3c6a59 Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Thu, 29 Jan 2026 18:48:11 -0800 Subject: [PATCH 08/13] add wostream overloads for Timestamp operator<< --- include/onnxruntime/core/common/logging/logging.h | 5 +++++ onnxruntime/core/common/logging/logging.cc | 4 ++++ onnxruntime/core/common/logging/sinks/ostream_sink.cc | 3 --- onnxruntime/core/session/inference_session.cc | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/onnxruntime/core/common/logging/logging.h b/include/onnxruntime/core/common/logging/logging.h index ec6f5df38778d..4e70f0414cb70 100644 --- a/include/onnxruntime/core/common/logging/logging.h +++ b/include/onnxruntime/core/common/logging/logging.h @@ -69,8 +69,13 @@ class Timestamp { return time_stamp.WriteToStream(os); } + friend std::wostream& operator<<(std::wostream& os, const Timestamp& time_stamp) { + return time_stamp.WriteToWStream(os); + } + private: std::ostream& WriteToStream(std::ostream& os) const; + std::wostream& WriteToWStream(std::wostream& os) const; TimePoint time_point_{}; }; diff --git a/onnxruntime/core/common/logging/logging.cc b/onnxruntime/core/common/logging/logging.cc index 3f80ee4bcec50..2f02199bde379 100644 --- a/onnxruntime/core/common/logging/logging.cc +++ b/onnxruntime/core/common/logging/logging.cc @@ -71,6 +71,10 @@ std::ostream& Timestamp::WriteToStream(std::ostream& os) const { return timestamp_stream_insertion_op_ns::operator<<(os, time_point_); } +std::wostream& Timestamp::WriteToWStream(std::wostream& os) const { + return timestamp_stream_insertion_op_ns::operator<<(os, time_point_); +} + const char* Category::onnxruntime = "onnxruntime"; const char* Category::System = "System"; diff --git a/onnxruntime/core/common/logging/sinks/ostream_sink.cc b/onnxruntime/core/common/logging/sinks/ostream_sink.cc index f8fdb5e1906ed..1c4968502eabb 100644 --- a/onnxruntime/core/common/logging/sinks/ostream_sink.cc +++ b/onnxruntime/core/common/logging/sinks/ostream_sink.cc @@ -62,9 +62,6 @@ void OStreamSink::SendImpl(const Timestamp& timestamp, const std::string& logger } #else void WOStreamSink::SendImpl(const Timestamp& timestamp, const std::string& logger_id, const Capture& message) { - // operator for formatting of timestamp in ISO8601 format including microseconds - using date::operator<<; - // Two options as there may be multiple calls attempting to write to the same sink at once: // 1) Use mutex to synchronize access to the stream. // 2) Create the message in an ostringstream and output in one call. diff --git a/onnxruntime/core/session/inference_session.cc b/onnxruntime/core/session/inference_session.cc index 0944be87591e2..863ea76e7aa3d 100644 --- a/onnxruntime/core/session/inference_session.cc +++ b/onnxruntime/core/session/inference_session.cc @@ -113,7 +113,7 @@ inline const wchar_t* GetDateFormatString() { return L"%Y-%m-%d_%H-%M-%S"; } #endif -// TODO: use LoggingManager::GetTimestamp and date::operator<< +// TODO: use LoggingManager::GetTimestamp and operator<< // (see ostream_sink.cc for an example) // to simplify this and match the log file timestamp format. template From ad1aab8198f4be00bdeb9d2d63a62e888ee47567 Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Fri, 30 Jan 2026 11:28:17 -0800 Subject: [PATCH 09/13] use std::filesystem::path:string instead of u8string in onnxruntime/core/providers/vitisai/imp/global_api.cc --- onnxruntime/core/providers/vitisai/imp/global_api.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/onnxruntime/core/providers/vitisai/imp/global_api.cc b/onnxruntime/core/providers/vitisai/imp/global_api.cc index ec529c2ad1fc2..b74eb1cae4a16 100644 --- a/onnxruntime/core/providers/vitisai/imp/global_api.cc +++ b/onnxruntime/core/providers/vitisai/imp/global_api.cc @@ -238,7 +238,7 @@ vaip_core::DllSafe>> c if (s_library_vitisaiep.compile_onnx_model_vitisai_ep_v4) { Status status = Status::OK(); auto status_ptr = reinterpret_cast(&status); - auto ret = vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_vitisai_ep_v4(model_path.u8string(), graph_viewer.GetGraph(), options, status_ptr, change_status_with_error, logger), vaip_execution_provider_deletor); + auto ret = vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_vitisai_ep_v4(model_path.string(), graph_viewer.GetGraph(), options, status_ptr, change_status_with_error, logger), vaip_execution_provider_deletor); if (!status.IsOK()) { ORT_THROW(status); } @@ -246,7 +246,7 @@ vaip_core::DllSafe>> c } else if (s_library_vitisaiep.compile_onnx_model_vitisai_ep_v3) { Status status = Status::OK(); auto status_ptr = reinterpret_cast(&status); - auto ret = vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_vitisai_ep_v3(model_path.u8string(), graph_viewer.GetGraph(), options, status_ptr, change_status_with_error), vaip_execution_provider_deletor); + auto ret = vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_vitisai_ep_v3(model_path.string(), graph_viewer.GetGraph(), options, status_ptr, change_status_with_error), vaip_execution_provider_deletor); if (!status.IsOK()) { ORT_THROW(status); } @@ -254,13 +254,13 @@ vaip_core::DllSafe>> c } else if (s_library_vitisaiep.compile_onnx_model_vitisai_ep_with_error_handling) { Status status = Status::OK(); auto status_ptr = reinterpret_cast(&status); - auto ret = vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_vitisai_ep_with_error_handling(model_path.u8string(), graph_viewer.GetGraph(), options, status_ptr, change_status_with_error), vaip_execution_provider_deletor); + auto ret = vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_vitisai_ep_with_error_handling(model_path.string(), graph_viewer.GetGraph(), options, status_ptr, change_status_with_error), vaip_execution_provider_deletor); if (!status.IsOK()) { ORT_THROW(status); } return ret; } else { - return vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_with_options(model_path.u8string(), graph_viewer.GetGraph(), options), vaip_execution_provider_deletor); + return vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_with_options(model_path.string(), graph_viewer.GetGraph(), options), vaip_execution_provider_deletor); } } @@ -707,4 +707,4 @@ CreateExecutionProviderFromAnotherEp(const std::string& lib, const OrtSessionOpt std::ignore = provider->CreateIExecutionProvider(nullptr, nullptr, 0, const_cast(provider_options), session_options, *((OrtLogger*)nullptr), ret); return ret; -} \ No newline at end of file +} From 848c8b1757d3ac9dde84542cc40f67ab515f2257 Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Mon, 2 Feb 2026 11:05:12 -0800 Subject: [PATCH 10/13] don't build android from Docker in minimal build workflow --- .github/workflows/linux_minimal_build.yml | 62 +++-------------------- 1 file changed, 6 insertions(+), 56 deletions(-) diff --git a/.github/workflows/linux_minimal_build.yml b/.github/workflows/linux_minimal_build.yml index 7d481475e7ded..1f78f56c412a7 100644 --- a/.github/workflows/linux_minimal_build.yml +++ b/.github/workflows/linux_minimal_build.yml @@ -530,43 +530,18 @@ jobs: --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF # Job 7: Extended minimal build with NNAPI EP for Android(arm64-v8a) and skip tests. - # NOTE: Keeping this as direct docker run due to custom volume mounts needed for Android SDK/NDK build_extended_minimal_android: name: 7. Build Extended Minimal (Android NNAPI) - needs: build_full_ort # Depends on Job 1 for test data runs-on: [ "self-hosted", "1ES.Pool=onnxruntime-github-Ubuntu2204-AMD-CPU", "JobId=build_extended_minimal_android-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}" ] - permissions: # Permissions needed for build-docker-image - contents: read - packages: write - id-token: write # If using OIDC for ACR login steps: - name: Checkout repository uses: actions/checkout@v6 with: submodules: false - - uses: actions/setup-node@v6 - with: - node-version: 20 - - name: Download Test Data Artifact - uses: actions/download-artifact@v7 - with: - name: test_data - path: ${{ runner.temp }}/.test_data/ - - - name: Get Docker Image using Action - uses: microsoft/onnxruntime-github-actions/build-docker-image@v0.0.9 - id: build_docker_image_step - with: - dockerfile: ${{ github.workspace }}/tools/ci_build/github/linux/docker/inference/x86_64/default/cpu/Dockerfile - image-name: ghcr.io/microsoft/onnxruntime/onnxruntimecpubuildcix64 - push: true - azure-container-registry-name: onnxruntimebuildcache - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Setup Android NDK uses: ./.github/actions/setup-android-ndk @@ -574,43 +549,18 @@ jobs: ndk-version: 28.0.13004108 # Use default android-sdk-root if not specified - - name: Run Build 7 (Using docker run) + - name: Run Build 7 shell: bash run: | - # Create the target dir for build output inside the runner's temp dir first - mkdir -p ${{ runner.temp }}/7 - - # Ensure ANDROID_NDK_HOME is available and get its real path - if [ -z "$ANDROID_NDK_HOME" ]; then - echo "ANDROID_NDK_HOME is not set." - exit 1 - fi - NDK_HOME_REALPATH=$(realpath $ANDROID_NDK_HOME) - - # Ensure ANDROID_HOME is available - if [ -z "$ANDROID_HOME" ]; then - echo "ANDROID_HOME is not set. Using default /usr/local/lib/android/sdk" - export ANDROID_HOME=/usr/local/lib/android/sdk - fi - - docker run --rm \ - --volume ${{ env.BUILD_SOURCES_DIRECTORY }}:/onnxruntime_src \ - --volume ${{ runner.temp }}:/build \ - --volume $ANDROID_HOME:/android_home \ - --volume $NDK_HOME_REALPATH:/ndk_home \ - -e ALLOW_RELEASED_ONNX_OPSET_ONLY=1 \ - -e NIGHTLY_BUILD=1 -e RUNNER_TEMP=/build \ - ${{ steps.build_docker_image_step.outputs.full-image-name }} \ - bash -c "python3 -m pip install -r /onnxruntime_src/tools/ci_build/requirements/pybind/requirements.txt \ - && python3 /onnxruntime_src/tools/ci_build/build.py \ - --build_dir /build/7 \ + python3 ./tools/ci_build/build.py \ + --build_dir ./build.extended_minimal.nnapi \ --cmake_generator Ninja \ --config MinSizeRel \ --skip_submodule_sync \ --parallel --use_binskim_compliant_compile_flags \ --android \ - --android_sdk_path /android_home \ - --android_ndk_path /ndk_home \ + --android_sdk_path "$ANDROID_HOME" \ + --android_ndk_path "$ANDROID_NDK_HOME" \ --android_abi=arm64-v8a \ --android_api=29 \ --use_nnapi \ @@ -618,5 +568,5 @@ jobs: --build_shared_lib \ --disable_ml_ops \ --disable_exceptions \ - --skip_tests" + --skip_tests working-directory: ${{ env.BUILD_SOURCES_DIRECTORY }} From 2c78745f754793203ea34df6fde23e0a0a8bef8d Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Mon, 2 Feb 2026 13:17:51 -0800 Subject: [PATCH 11/13] disable C++20 when onnxruntime_USE_CUDA is enabled for all builds, update comment --- cmake/CMakeLists.txt | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 8eca34f4f80e7..03a37764169df 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -247,11 +247,24 @@ if (NOT CMAKE_C_STANDARD) endif() if (NOT CMAKE_CXX_STANDARD) - # TODO move all builds to C++20 - if (MSVC AND onnxruntime_USE_CUDA) - # There's a compilation error from CUTLASS header "cute/tensor.hpp" when attempting to use C++20: - # cutlass-src\include\cute\stride.hpp(299,46): error C3545: 'Ints': parameter pack expects a non-type template - # argument + # TODO: enable C++20 for all builds + # set(CMAKE_CXX_STANDARD 20) + + if (onnxruntime_USE_CUDA) + # Known issues when updating from C++17 to C++20: + # - MSVC + onnxruntime_USE_CUDA: + # - Compilation error from CUTLASS header "cute/tensor.hpp" when attempting to use C++20: + # cutlass-src\include\cute\stride.hpp(299,46): error C3545: 'Ints': parameter pack expects a non-type + # template argument + # - GCC + onnxruntime_USE_CUDA: + # - Compilation error from onnxruntime/contrib_ops/cuda/llm/cutlass_heuristic.cc when adding an element to + # `std::vector` in + # onnxruntime/contrib_ops/cuda/llm/cutlass_heuristic.cc: + # /opt/rh/gcc-toolset-14/root/usr/include/c++/14/bits/stl_construct.h:97:14: error: writing 1 byte into a + # region of size 0 [-Werror=stringop-overflow=] + # - Possibly a spurious warning + # + # When the CUDA EP becomes an independent plugin EP, we can keep building it with C++17 if needed. set(CMAKE_CXX_STANDARD 17) else() set(CMAKE_CXX_STANDARD 20) From a035d7f0f194d4326198f343b40bd61f8c4bfa48 Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Mon, 2 Feb 2026 13:21:02 -0800 Subject: [PATCH 12/13] update comment again --- cmake/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 03a37764169df..3d3f19c829d85 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -264,7 +264,8 @@ if (NOT CMAKE_CXX_STANDARD) # region of size 0 [-Werror=stringop-overflow=] # - Possibly a spurious warning # - # When the CUDA EP becomes an independent plugin EP, we can keep building it with C++17 if needed. + # When the CUDA EP becomes an independent plugin EP, hopefully we can update all of onnxruntime to C++20. + # We can keep building the CUDA plugin EP with C++17 if needed. set(CMAKE_CXX_STANDARD 17) else() set(CMAKE_CXX_STANDARD 20) From 06fec4fa4eb28a5e79fd1f21c3e89d83e2fb4515 Mon Sep 17 00:00:00 2001 From: edgchen1 <18449977+edgchen1@users.noreply.github.com> Date: Tue, 3 Feb 2026 18:15:05 -0800 Subject: [PATCH 13/13] tweak comment --- cmake/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 3d3f19c829d85..6d8c09bea6f8e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -253,13 +253,12 @@ if (NOT CMAKE_CXX_STANDARD) if (onnxruntime_USE_CUDA) # Known issues when updating from C++17 to C++20: # - MSVC + onnxruntime_USE_CUDA: - # - Compilation error from CUTLASS header "cute/tensor.hpp" when attempting to use C++20: + # - Compilation error from CUTLASS header cute/tensor.hpp: # cutlass-src\include\cute\stride.hpp(299,46): error C3545: 'Ints': parameter pack expects a non-type # template argument # - GCC + onnxruntime_USE_CUDA: # - Compilation error from onnxruntime/contrib_ops/cuda/llm/cutlass_heuristic.cc when adding an element to - # `std::vector` in - # onnxruntime/contrib_ops/cuda/llm/cutlass_heuristic.cc: + # `std::vector`: # /opt/rh/gcc-toolset-14/root/usr/include/c++/14/bits/stl_construct.h:97:14: error: writing 1 byte into a # region of size 0 [-Werror=stringop-overflow=] # - Possibly a spurious warning