Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 6 additions & 56 deletions .github/workflows/linux_minimal_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -530,93 +530,43 @@ 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's an error with CMake not finding clang-scan-deps from the NDK for the particular configuration of:

  • Linux build with Docker container
  • C++20
  • Ninja generator

it works fine when running outside of Docker. this is what the other Android CI builds do, e.g., here:

I just simplified this to make it consistent instead of debugging further for now.

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
with:
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 \
--minimal_build extended \
--build_shared_lib \
--disable_ml_ops \
--disable_exceptions \
--skip_tests"
--skip_tests
working-directory: ${{ env.BUILD_SOURCES_DIRECTORY }}
45 changes: 31 additions & 14 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -34,15 +29,6 @@ include(CheckFunctionExists)
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()
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")
Expand Down Expand Up @@ -254,6 +240,37 @@ 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: 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:
# 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<onnxruntime::llm::cutlass_extensions::CutlassGemmConfig>`:
# /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, 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)
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()
Expand Down
54 changes: 20 additions & 34 deletions include/onnxruntime/core/common/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/*

Expand Down Expand Up @@ -56,43 +55,30 @@
namespace onnxruntime {
namespace logging {

using Timestamp = std::chrono::time_point<std::chrono::system_clock>;

// 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 <TargetConditionals.h>

// 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
// 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} {}

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

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Single-parameter constructors should be marked explicit. [runtime/explicit] [4] Raw Output: include/onnxruntime/core/common/logging/logging.h:66: Single-parameter constructors should be marked explicit. [runtime/explicit] [4]

#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
friend std::ostream& operator<<(std::ostream& os, const Timestamp& time_stamp) {
return time_stamp.WriteToStream(os);
}

#endif
#endif // __APPLE__
friend std::wostream& operator<<(std::wostream& os, const Timestamp& time_stamp) {
return time_stamp.WriteToWStream(os);
}

#if ORT_USE_CXX20_STD_CHRONO
namespace timestamp_ns = std::chrono;
#else
namespace timestamp_ns = ::date;
#endif
private:
std::ostream& WriteToStream(std::ostream& os) const;
std::wostream& WriteToWStream(std::wostream& os) const;

#undef ORT_USE_CXX20_STD_CHRONO
TimePoint time_point_{};
};

#ifndef NDEBUG
ORT_ATTRIBUTE_UNUSED static bool vlog_enabled = true; // Set directly based on your needs.
Expand Down
45 changes: 45 additions & 0 deletions onnxruntime/core/common/logging/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,53 @@
#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 <TargetConditionals.h>

// 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_);
}

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";

Expand Down
9 changes: 1 addition & 8 deletions onnxruntime/core/common/logging/sinks/ostream_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -66,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.
Expand Down
4 changes: 1 addition & 3 deletions onnxruntime/core/platform/apple/logging/apple_log_sink.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 0 additions & 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,13 @@
#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<<;
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: 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
10 changes: 5 additions & 5 deletions onnxruntime/core/providers/vitisai/imp/global_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,29 @@ vaip_core::DllSafe<std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>> c
if (s_library_vitisaiep.compile_onnx_model_vitisai_ep_v4) {
Status status = Status::OK();
auto status_ptr = reinterpret_cast<void*>(&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);
}
return ret;
} else if (s_library_vitisaiep.compile_onnx_model_vitisai_ep_v3) {
Status status = Status::OK();
auto status_ptr = reinterpret_cast<void*>(&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);
}
return ret;
} else if (s_library_vitisaiep.compile_onnx_model_vitisai_ep_with_error_handling) {
Status status = Status::OK();
auto status_ptr = reinterpret_cast<void*>(&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);
}
}

Expand Down Expand Up @@ -707,4 +707,4 @@ CreateExecutionProviderFromAnotherEp(const std::string& lib, const OrtSessionOpt
std::ignore = provider->CreateIExecutionProvider(nullptr, nullptr, 0, const_cast<onnxruntime::ProviderOptions&>(provider_options), session_options, *((OrtLogger*)nullptr), ret);

return ret;
}
}
Loading
Loading