Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update C++ to standard 20 for Windows #17706

Open
wants to merge 75 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
3259827
C++20 for Windows
jchen351 Sep 26, 2023
c34e2df
Disable C4189 warnign for MSC_VER
jchen351 Oct 3, 2023
200fa0e
UPDATE to _WIN32
jchen351 Oct 4, 2023
3eb33e9
Merge branch 'main' into Cjian/win_c++20
jchen351 Oct 4, 2023
a4e7339
Merge branch 'main' into Cjian/win_c++20
jchen351 Oct 6, 2023
6281fbb
Update format
jchen351 Oct 6, 2023
fefb39a
Merge branch 'main' into Cjian/win_c++20
jchen351 Oct 12, 2023
8e74584
Try to fix std::move_iterator::operator->() is deprecated in C++20
jchen351 Oct 13, 2023
19aef6a
Replace is_pod with is_trivial
jchen351 Oct 13, 2023
b81fa78
Replace "" with nullptr
jchen351 Oct 13, 2023
f62ef98
Update capture for lamda function -> void*
jchen351 Oct 13, 2023
22d8289
Merge remote-tracking branch 'refs/remotes/origin/main' into Cjian/wi…
jchen351 Jun 3, 2024
9671ae7
Fix misspell
jchen351 Jun 3, 2024
9d5b8c4
change is_pod to is_trivial
jchen351 Jun 3, 2024
caafe6d
chrono
jchen351 Jun 3, 2024
aa07557
chrono
jchen351 Jun 4, 2024
17d0322
::date::operator<<
jchen351 Jun 4, 2024
c23528b
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Jun 6, 2024
59c8597
cast
jchen351 Jun 6, 2024
fe337ac
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Jun 13, 2024
a968243
reinterpret_cast
jchen351 Jun 13, 2024
3bbffc3
#pragma warning(disable : 4189) // Disable warning C4189
jchen351 Jun 13, 2024
62f4300
#pragma warning(disable : 4189) // Disable warning C4189
jchen351 Jun 13, 2024
b54cee6
#pragma warning(disable : 4189) // Disable warning C4189
jchen351 Jun 13, 2024
89e48b7
_WIN32
jchen351 Jun 14, 2024
1b73721
using timestamp_ns::operator<<;
jchen351 Jun 14, 2024
8307dfe
lint
jchen351 Jun 14, 2024
bb47599
Merge remote-tracking branch 'refs/remotes/origin/main' into Cjian/wi…
jchen351 Jun 19, 2024
6c4c15f
Merge remote-tracking branch 'refs/remotes/origin/main' into Cjian/wi…
jchen351 Jun 20, 2024
8b22860
Merge remote-tracking branch 'origin/main' into Cjian/win_c++20
jchen351 Jun 20, 2024
c4a739d
Merge remote-tracking branch 'origin/main' into Cjian/win_c++20
snnn Jul 30, 2024
84de59b
Merge remote-tracking branch 'origin/main' into Cjian/win_c++20
snnn Jul 30, 2024
2746743
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Aug 27, 2024
c3411c9
Merge remote-tracking branch 'origin/Cjian/win_c++20' into Cjian/win_…
jchen351 Aug 27, 2024
5360f02
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Aug 27, 2024
415d350
Remvoing the reference of date.h which is no longer part of abseil
jchen351 Aug 27, 2024
cf6ee7a
Adding #include "date/date.h" back to the top of logging.h file
jchen351 Aug 27, 2024
837f45d
Adding #include "date/date.h" back to the top of logging.h file
jchen351 Aug 27, 2024
46d6d03
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Aug 27, 2024
81496e0
fixes 2 problems that passes build in c++17 but would fail in c++20 o…
fs-eire Aug 27, 2024
38c8794
Including assert.h to the etw_sink.cc
jchen351 Aug 27, 2024
994f1bd
Merge remote-tracking branch 'refs/remotes/origin/fs-eire/small-fixes…
jchen351 Aug 27, 2024
ac3b8aa
Merge with fs-eire/small-fixes
jchen351 Aug 27, 2024
cce039b
Excluding ARM64 QNN from c++ supported platform
jchen351 Aug 27, 2024
1df956b
Changing ostingstream to wostringstream
jchen351 Aug 28, 2024
8184354
Change TestImageBindingStyleTransfer (..., .. , wchar_t*) to TestImag…
jchen351 Aug 28, 2024
c2f9a9b
Using wostringstream only on Windows
jchen351 Aug 30, 2024
acd5f23
Using wostringstream only on Windows
jchen351 Aug 30, 2024
cd1380c
change ifndef to ifdef
jchen351 Aug 30, 2024
dfa0b64
c_str()
jchen351 Aug 30, 2024
b59dfd3
c_str()
jchen351 Aug 30, 2024
93ffa11
lint
jchen351 Aug 30, 2024
2cc3079
Adding case when in windows for ostream sink
jchen351 Sep 3, 2024
fb1d7c6
Only allow OStreamSink to be used in Unix OSes
jchen351 Sep 4, 2024
4f82fc9
Implment FileSink with WOStreamSink for windows
jchen351 Sep 4, 2024
056e8c3
Implement FileSink with WOStreamSink for windows
jchen351 Sep 4, 2024
ee3d438
Revert previous changes
jchen351 Sep 4, 2024
ade9091
Update fileshink
jchen351 Sep 4, 2024
0137be2
Update sinks_test.cc
jchen351 Sep 4, 2024
9124045
Update sinks_test.cc
jchen351 Sep 4, 2024
3604a68
Update logging_test.cc
jchen351 Sep 4, 2024
b813203
Update lint
jchen351 Sep 4, 2024
7c6d738
Apply ToWideString to filename
jchen351 Sep 4, 2024
63bb6be
Add core/common/common.h
jchen351 Sep 4, 2024
933804b
Add core/common/common.h
jchen351 Sep 4, 2024
37afbfd
Merge branch 'refs/heads/main' into Cjian/wostream
jchen351 Sep 4, 2024
6bd7846
Fix comparing string with wstring
jchen351 Sep 4, 2024
efb7ea4
Using make_unique
jchen351 Sep 5, 2024
2d2354f
Update commend about date.h
jchen351 Sep 5, 2024
7afbb1e
onnxruntime::ToWideString(filename), false, false)
jchen351 Sep 6, 2024
287a69c
Merge branch 'refs/heads/Cjian/wostream' into Cjian/win_c++20
jchen351 Sep 6, 2024
e97ae47
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Sep 6, 2024
4b07785
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Sep 9, 2024
9901c2d
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Sep 10, 2024
5ca5da1
Merge branch 'refs/heads/main' into Cjian/win_c++20
jchen351 Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ include(CheckFunctionExists)
include(GNUInstallDirs) # onnxruntime_providers_* require CMAKE_INSTALL_* variables

# TODO: update this once all system adapt c++20
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT onnxruntime_USE_QNN))
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
Expand Down
12 changes: 6 additions & 6 deletions include/onnxruntime/core/common/gpu_profiler_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ class GPUTracerManager {
auto p_event_list = GetEventListForUniqueCorrelationId(unique_correlation_id);
if (p_event_list != nullptr) {
p_event_list->insert(p_event_list->end(),
std::make_move_iterator(events.begin()),
std::make_move_iterator(events.end()));
std::make_move_iterator(events.begin()).base(),
std::make_move_iterator(events.end()).base());
}
}

Expand Down Expand Up @@ -379,8 +379,8 @@ class GPUProfilerBase : public EpProfiler {
void MergeEvents(std::map<uint64_t, Events>& events_to_merge, Events& events) {
Events merged_events;

auto event_iter = std::make_move_iterator(events.begin());
auto event_end = std::make_move_iterator(events.end());
auto event_iter = std::make_move_iterator(events.begin()).base();
auto event_end = std::make_move_iterator(events.end()).base();
for (auto& map_iter : events_to_merge) {
if (map_iter.second.empty()) {
continue;
Expand Down Expand Up @@ -423,8 +423,8 @@ class GPUProfilerBase : public EpProfiler {
}

merged_events.insert(merged_events.end(),
std::make_move_iterator(map_iter.second.begin()),
std::make_move_iterator(map_iter.second.end()));
std::make_move_iterator(map_iter.second.begin()).base(),
std::make_move_iterator(map_iter.second.end()).base());
}

// move any remaining events
Expand Down
7 changes: 5 additions & 2 deletions include/onnxruntime/core/common/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
#include "core/common/logging/severity.h"
#include "core/common/logging/sink_types.h"
#include "core/platform/ort_mutex.h"
#include "date/date.h"

// date.h is from https://github.com/HowardHinnant/date, which is no longer supporing C++20. So we need replace it with std::chrono::operator<<

Check warning on line 22 in include/onnxruntime/core/common/logging/logging.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Lines should be <= 120 characters long [whitespace/line_length] [2] Raw Output: include/onnxruntime/core/common/logging/logging.h:22: Lines should be <= 120 characters long [whitespace/line_length] [2]
#if !(__cplusplus >= 202002L && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 140400L || _WIN32))
#include "date/date.h"
#endif
/*

Logging overview and expected usage:
Expand Down Expand Up @@ -61,7 +64,7 @@
// TODO: When other compilers support std::chrono::operator<<, update this.
// TODO: Check support for other compilers' version before enable C++20 for other compilers.
// Xcode added support for C++20's std::chrono::operator<< in SDK version 14.4.
#if __cplusplus >= 202002L && __MAC_OS_X_VERSION_MAX_ALLOWED >= 140400L
#if __cplusplus >= 202002L && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 140400L || _WIN32)
namespace timestamp_ns = std::chrono;
#else
namespace timestamp_ns = ::date;
Expand Down
8 changes: 5 additions & 3 deletions onnxruntime/core/common/logging/sinks/ostream_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ 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<<;

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.
//
// Going with #2 as it should scale better at the cost of creating the message in memory first
// before sending to the stream.

#ifdef _WIN32
std::wostringstream msg;
#else
std::ostringstream msg;
#endif

#ifndef ORT_MINIMAL_BUILD
if (message.Severity() == Severity::kWARNING) {
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/framework/bfc_arena.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Status BFCArena::Extend(size_t rounded_bytes) {
" is smaller than requested bytes of ", rounded_bytes);
}

auto safe_alloc = [this](size_t alloc_bytes) {
auto safe_alloc = [this](size_t alloc_bytes) -> void* {
void* new_mem = nullptr;
ORT_TRY {
new_mem = device_allocator_->Alloc(alloc_bytes);
Expand Down
2 changes: 0 additions & 2 deletions onnxruntime/core/platform/apple/logging/apple_log_sink.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#include <sstream>

#include "date/date.h"

namespace onnxruntime {
namespace logging {

Expand Down
3 changes: 1 addition & 2 deletions onnxruntime/core/platform/posix/logging/syslog_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
#include "core/common/logging/logging.h"
#include "core/common/logging/capture.h"
#include "syslog_sink.h"
#include "date/date.h"

namespace onnxruntime {
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<<;
using timestamp_ns::operator<<;
std::stringstream msg;

// syslog has it own timestamp but not as accurate as our timestamp. So we are going to keep both,
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/platform/windows/logging/etw_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// EtwSink.h must come before the windows includes
#include "core/platform/windows/logging/etw_sink.h"
#include <assert.h>

#ifdef ETW_TRACE_LOGGING_SUPPORTED

Expand Down
1 change: 0 additions & 1 deletion onnxruntime/core/platform/windows/logging/etw_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#ifdef ETW_TRACE_LOGGING_SUPPORTED

#include <date/date.h>
#include <atomic>
#include <iostream>
#include <string>
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/providers/cpu/tensor/upsample_antialias.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ void SetupUpsampleFilterAntiAlias(FilterParamsAntiAlias<T>& p,
}

float total_weight_inv = total_weight == 0.0f ? 1.f : 1.0f / total_weight;
auto* scale_buffer_int = reinterpret_cast<int32_t*>(scale_buffer);
for (x = 0; x < xmax_cut - xmin_cut; x++) {
scale_buffer[x] *= total_weight_inv;

// normalize the scale to 1 << 22 for int8/uint8
if constexpr (std::is_same<T, int32_t>::value) {
scale_buffer_int[x] = static_cast<int32_t>(std::round(scale_buffer[x] * ConstValue::mag_factor_x_2));
reinterpret_cast<int32_t*>(scale_buffer)[x] =
static_cast<int32_t>(std::round(scale_buffer[x] * ConstValue::mag_factor_x_2));
}
}
/*for (; x < window_size; x++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class QnnBackendManager {
ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(QnnBackendManager);

~QnnBackendManager();
char* DlError() {
const char* DlError() {
#ifdef _WIN32
return "";
#else
Expand Down
5 changes: 1 addition & 4 deletions onnxruntime/test/util/include/capturing_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

#pragma once

#include "core/common/logging/logging.h"
#include "core/common/logging/isink.h"

#include "date/date.h"

namespace onnxruntime {
namespace test {

Expand All @@ -17,7 +14,7 @@ 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<<;
using timestamp_ns::operator<<;
std::ostringstream msg;

msg << timestamp << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", "
Expand Down
2 changes: 1 addition & 1 deletion winml/test/api/LearningModelBindingAPITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static void ZipMapString() {
WINML_EXPECT_TRUE(iter2.HasCurrent());
const auto& pair1 = iter1.Current();
const auto& pair2 = iter2.Current();
WINML_LOG_COMMENT((std::ostringstream() << "key: " << pair1.Key().c_str() << ", value " << pair2.Value()).str());
WINML_LOG_COMMENT((std::wostringstream() << "key: " << pair1.Key().c_str() << ", value " << pair2.Value()).str());
WINML_EXPECT_TRUE(std::wstring(pair1.Key().c_str()).compare(labels[i]) == 0);
WINML_EXPECT_TRUE(std::wstring(pair2.Key().c_str()).compare(labels[i]) == 0);
WINML_EXPECT_TRUE(pair1.Value() == inputs[i] && pair2.Value() == inputs[i]);
Expand Down
4 changes: 2 additions & 2 deletions winml/test/image/imagetests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ImageTests : public ::testing::Test {
WINML_EXPECT_NO_THROW(m_model = LearningModel::LoadFromFilePath(full_path));
}

void ImageTests::PrepareModelSessionBinding(
void PrepareModelSessionBinding(
const std::wstring& model_file_name,
LearningModelDeviceKind device_kind,
std::optional<uint32_t> optimized_batch_size
Expand Down Expand Up @@ -834,7 +834,7 @@ TEST_F(ImageTests, ImageBindingInputAndOutput_BindInputTensorAsInspectable) {
}

static void TestImageBindingStyleTransfer(
const wchar_t* model_file_name, const wchar_t* input_data_image_filename, wchar_t* output_data_image_filename
const wchar_t* model_file_name, const wchar_t* input_data_image_filename, const wchar_t* output_data_image_filename
) {
GPUTEST;

Expand Down
Loading