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
16 changes: 7 additions & 9 deletions include/onnxruntime/core/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class Node {
Fused = 1, ///< The node refers to a function.
};

explicit Node() = default;
// Constructor and destructor defined out-of-line in graph.cc so that Graph
// is a complete type when std::unique_ptr<Graph> in subgraphs_ is destroyed
// (required by libc++).
explicit Node();

#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD) || defined(ORT_MINIMAL_BUILD_CUSTOM_OPS)
Node(std::string_view name,
Expand All @@ -82,15 +85,10 @@ class Node {
gsl::span<NodeArg* const> input_args,
gsl::span<NodeArg* const> output_args,
const NodeAttributes* attributes,
std::string_view domain) {
Init(name, op_type, description,
input_args,
output_args,
attributes, domain);
}
std::string_view domain);
#endif

~Node() = default;
~Node();

/**
@class EdgeEnd
Expand Down Expand Up @@ -580,7 +578,7 @@ class Node {
// NOTE: This friendship relationship should ONLY be used for calling methods of the Node class and not accessing
// the data members directly, so that the Node can maintain its internal invariants.
friend class Graph;
Node(NodeIndex index, Graph& graph) : index_(index), graph_(&graph), can_be_saved_(true) {}
Node(NodeIndex index, Graph& graph);

protected:
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
Expand Down
4 changes: 2 additions & 2 deletions include/onnxruntime/core/session/onnxruntime_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ extern "C" {
#define ORT_MUST_USE_RESULT
#define ORTCHAR_T wchar_t
#else
// To make symbols visible on macOS/iOS
#ifdef __APPLE__
// To make symbols visible on macOS/iOS/Linux
#if defined(__GNUC__)
#define ORT_EXPORT __attribute__((visibility("default")))
#else
#define ORT_EXPORT
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/contrib_ops/cpu/bert/bias_gelu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "core/providers/common.h"
#include "core/util/math_cpuonly.h"
#include "core/mlas/inc/mlas.h"
#include "core/common/math_constants.h"
using onnxruntime::narrow;
namespace onnxruntime {
namespace contrib {
Expand Down
24 changes: 24 additions & 0 deletions onnxruntime/core/common/math_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// Portable math constant definitions.
// POSIX constants like M_PI and M_SQRT2 are not part of the C++ standard and
// are not provided by all standard library implementations (e.g. libc++).
// This header provides them when missing, enabling compilation with any
// conforming C++ standard library.

#pragma once

#include <cmath>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#ifndef M_SQRT1_2
#define M_SQRT1_2 0.70710678118654752440
#endif

#ifndef M_SQRT2
#define M_SQRT2 1.41421356237309504880
#endif
Comment on lines +4 to +24
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

The PR description mentions providing additional constants like M_LOG2E, etc., but this new header currently only defines M_PI, M_SQRT1_2, and M_SQRT2. Either extend this header to include the other promised constants (as needed by the build) or update the PR description to match what’s actually being introduced.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated PR description to match the constants actually defined.

2 changes: 2 additions & 0 deletions onnxruntime/core/graph/ep_api_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ static bool IsOptionalAttribute(const Node& node, const std::string& attr_name)
// EpNode
//

EpNode::SubgraphState::~SubgraphState() = default;

EpNode::EpNode(const EpGraph* ep_graph, const Node& node, PrivateTag)
: OrtNode(OrtGraphIrApi::kEpApi), ep_graph_(ep_graph), node_(node) {}

Expand Down
3 changes: 3 additions & 0 deletions onnxruntime/core/graph/ep_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ struct EpNode : public OrtNode {
struct SubgraphState {
SubgraphState() = default;
SubgraphState(SubgraphState&& other) = default;
// Destructor defined out-of-line so EpGraph is complete when
// unique_ptr<EpGraph> is destroyed (required by libc++).
~SubgraphState();
std::string attribute_name;
std::unique_ptr<GraphViewer> subgraph_viewer; // The graph_viewer wrapped by EpGraph below.
std::unique_ptr<EpGraph> ep_subgraph;
Expand Down
22 changes: 22 additions & 0 deletions onnxruntime/core/graph/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,28 @@ bool NodeArg::Exists() const noexcept {
return exists_;
}

// Out-of-line constructor and destructor so Graph is complete when
// unique_ptr<Graph> in subgraphs_ is destroyed (required by libc++).
Node::Node() = default;
Node::~Node() = default;

Node::Node(NodeIndex index, Graph& graph) : index_(index), graph_(&graph), can_be_saved_(true) {}

#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD) || defined(ORT_MINIMAL_BUILD_CUSTOM_OPS)
Node::Node(std::string_view name,
std::string_view op_type,
std::string_view description,
gsl::span<NodeArg* const> input_args,
gsl::span<NodeArg* const> output_args,
const NodeAttributes* attributes,
std::string_view domain) {
Init(name, op_type, description,
input_args,
output_args,
attributes, domain);
}
#endif

Node::EdgeEnd::EdgeEnd(const Node& node, int src_arg_index, int dst_arg_index) noexcept
: node_(&node),
src_arg_index_(src_arg_index),
Expand Down
3 changes: 3 additions & 0 deletions onnxruntime/core/mlas/lib/aarch64/asmmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Macro Description:
#if defined(__APPLE__)
.globl _\FunctionName\()
_\FunctionName\():
#elif defined(_WIN32)
.globl \FunctionName\()
\FunctionName\():
#else
.globl \FunctionName\()
.type \FunctionName\(),%function
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/mlas/lib/activate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct MLAS_ACTIVATION_FUNCTION<MlasLeakyReluActivation>
MLAS_FLOAT32X4 ValueTimesAlpha = MlasMultiplyFloat32x4(Value, AlphaBroadcast);

#if defined(MLAS_NEON_INTRINSICS)
#if defined(_WIN32)
#if defined(_WIN32) && !defined(__clang__)
return vbslq_f32(vcleq_z_f32_ex(Value), ValueTimesAlpha, Value);
#else
// N.B. Standard NEON headers lack an intrinsic for the "vcle #0" form.
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/mlas/lib/mlasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ MlasConvDepthwiseMultiplier2CHWKernel7x7S2Avx512F(
// Also define additional standard NEON intrinsics using the MSVC aliases.
//

#if defined(_M_ARM64)
#if defined(_M_ARM64) && !defined(__clang__)
#ifndef vmaxvq_f32
#define vmaxvq_f32(src) neon_fmaxv(src)
#endif
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/mlas/lib/qladd.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ MlasCalcQLinearAddParameters(

#if defined(MLAS_NEON_INTRINSICS)

#if ! defined(_MSC_VER)
#if !defined(_MSC_VER) || defined(__clang__)

#define vld1q_s8_ex(pD, align) vld1q_s8((int8_t*)__builtin_assume_aligned(pD, ((align)/8)))
#define vst1_s8_ex(pD, D, align) vst1_s8((int8_t*)__builtin_assume_aligned(pD, ((align)/8)), D)
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/optimizer/gelu_fusion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "core/graph/graph_utils.h"
#include "float.h"
#include <deque>
#include "core/common/math_constants.h"

using namespace ONNX_NAMESPACE;
using namespace onnxruntime::common;
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/core/optimizer/optimizer_execution_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static size_t EstimateInputsOutputs(gsl::span<const Node* const> nodes) {
return num;
}

OptimizerExecutionFrame::Info::~Info() = default;

OptimizerExecutionFrame::Info::Info(const std::vector<const Node*>& nodes,
const InitializedTensorSet& initialized_tensor_set,
const std::filesystem::path& model_path,
Expand Down
4 changes: 3 additions & 1 deletion onnxruntime/core/optimizer/optimizer_execution_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class OptimizerExecutionFrame final : public IExecutionFrame {
const std::function<bool(const std::string&)>& is_sparse_initializer_func,
const logging::Logger& logger);

~Info() = default;
// Destructor defined out-of-line so NodeIndexInfo is complete when
// unique_ptr<NodeIndexInfo> is destroyed (required by libc++).
~Info();

const AllocatorPtr& GetAllocator() const {
return allocator_ptr_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
namespace onnxruntime {
namespace QDQ {

// Out-of-line constructor/destructor definitions so NodeGroupSelector is
// complete when unique_ptr<NodeGroupSelector> is destroyed (required by libc++).
OpVersionsAndSelector::OpVersionsAndSelector(const OpVersionsMap& ops_and_versions_in,
std::unique_ptr<NodeGroupSelector> selector_in)
: op_versions_map{ops_and_versions_in},
selector{std::move(selector_in)} {}

OpVersionsAndSelector::~OpVersionsAndSelector() = default;

Selectors::Selectors() = default;
Selectors::~Selectors() = default;

SelectorManager::~SelectorManager() = default;

void Selectors::RegisterSelector(const OpVersionsAndSelector::OpVersionsMap& ops_and_versions_in,
std::unique_ptr<NodeGroupSelector> selector_in) {
auto entry = std::make_unique<OpVersionsAndSelector>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ struct OpVersionsAndSelector {
using OpVersionsMap = std::unordered_map<std::string, std::vector<ONNX_NAMESPACE::OperatorSetVersion>>;

OpVersionsAndSelector(const OpVersionsMap& ops_and_versions_in,
std::unique_ptr<NodeGroupSelector> selector_in)
: op_versions_map{ops_and_versions_in},
selector{std::move(selector_in)} {}
std::unique_ptr<NodeGroupSelector> selector_in);

// Destructor defined out-of-line so NodeGroupSelector is complete when
// unique_ptr<NodeGroupSelector> is destroyed (required by libc++).
~OpVersionsAndSelector();

OpVersionsMap op_versions_map;
std::unique_ptr<NodeGroupSelector> selector;
Expand All @@ -44,7 +46,8 @@ struct OpVersionsAndSelector {
// class that manages a set of node group selectors
class Selectors {
public:
Selectors() = default;
Selectors();
~Selectors();

// register a selector for the specified ops.
void RegisterSelector(const OpVersionsAndSelector::OpVersionsMap& ops_and_versions_in,
Expand All @@ -64,6 +67,7 @@ class Selectors {
class SelectorManager {
public:
SelectorManager();
~SelectorManager();

// Methods that finds and returns a vector of QDQ::NodeGroup in a given graph
// Can be used in QDQ support in different EPs
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/optimizer/stft_decomposition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "core/optimizer/utils.h"
#include "core/framework/op_kernel.h"
#include "core/framework/tensorprotoutils.h"
#include "core/common/math_constants.h"

using namespace onnxruntime::common;

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/platform/windows/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class WindowsEnv : public Env {
#endif
EnvThread* CreateThread(_In_opt_z_ const ORTCHAR_T* name_prefix, int index,
unsigned (*start_address)(int id, Eigen::ThreadPoolInterface* param),
Eigen::ThreadPoolInterface* param, const ThreadOptions& thread_options);
Eigen::ThreadPoolInterface* param, const ThreadOptions& thread_options) override;
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif
Expand Down
6 changes: 3 additions & 3 deletions onnxruntime/core/platform/windows/stacktrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <mutex>
#include <sstream>
#ifdef __has_include
#if __has_include(<stacktrace>)
#if __has_include(<stacktrace>) && !defined(_LIBCPP_VERSION)
#include <stacktrace>
#endif
#endif
Expand All @@ -30,7 +30,7 @@ class CaptureStackTrace {
// Get the stack trace. Currently only enabled for a DEBUG build as we require the DbgHelp library.
std::vector<std::string> GetStackTrace() {
#ifndef NDEBUG
#if (defined __cpp_lib_stacktrace) && !(defined _OPSCHEMA_LIB_) && !(defined _GAMING_XBOX) && !(defined ONNXRUNTIME_ENABLE_MEMLEAK_CHECK)
#if (defined __cpp_lib_stacktrace) && !defined(_LIBCPP_VERSION) && !(defined _OPSCHEMA_LIB_) && !(defined _GAMING_XBOX) && !(defined ONNXRUNTIME_ENABLE_MEMLEAK_CHECK)
return detail::CaptureStackTrace().Trace();
#else
return {};
Expand All @@ -42,7 +42,7 @@ std::vector<std::string> GetStackTrace() {

namespace detail {
#ifndef NDEBUG
#if (defined __cpp_lib_stacktrace) && !(defined _OPSCHEMA_LIB_) && !(defined _GAMING_XBOX) && !(defined ONNXRUNTIME_ENABLE_MEMLEAK_CHECK)
#if (defined __cpp_lib_stacktrace) && !defined(_LIBCPP_VERSION) && !(defined _OPSCHEMA_LIB_) && !(defined _GAMING_XBOX) && !(defined ONNXRUNTIME_ENABLE_MEMLEAK_CHECK)

std::vector<std::string> CaptureStackTrace::Trace() const {
std::vector<std::string> stacktrace;
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/providers/cpu/math/cumsum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ CumSum<T>::CumSum(const OpKernelInfo& info) : OpKernel(info), exclusive_(), reve
if (exclusive == 1 || exclusive == 0) {
exclusive_ = exclusive;
} else {
ORT_ENFORCE("attribute exclusive can only be 0 or 1");
ORT_ENFORCE(false, "attribute exclusive can only be 0 or 1");
}
}
int64_t reverse = 0;
Comment on lines 106 to 112
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

This change correctly fixes the exclusive attribute validation to pass a boolean condition to ORT_ENFORCE. However, the reverse attribute validation in the same constructor still uses ORT_ENFORCE("attribute reverse can only be 0 or 1") (string literal as the condition), which will never fail and still allows invalid values. Please update the reverse validation to use ORT_ENFORCE(false, ...) (or a real condition) as well for consistent, correct enforcement.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Updated reverse validation to use ORT_ENFORCE(false, ...) as well.

Expand All @@ -115,7 +115,7 @@ CumSum<T>::CumSum(const OpKernelInfo& info) : OpKernel(info), exclusive_(), reve
if (reverse == 1 || reverse == 0) {
reverse_ = reverse;
} else {
ORT_ENFORCE("attribute reverse can only be 0 or 1");
ORT_ENFORCE(false, "attribute reverse can only be 0 or 1");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/providers/cpu/ml/ml_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "core/mlas/inc/mlas.h"
#include "core/platform/threadpool.h"
#include "core/common/inlined_containers.h"
#include "core/common/math_constants.h"
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

core/common/math_constants.h is now included, but this file no longer uses any of the M_* constants (e.g., M_PI, M_SQRT2). To reduce unnecessary macro pollution and keep constants consistent, either switch the hard-coded numeric literals back to M_PI/M_SQRT2 from this header, or remove this include.

Suggested change
#include "core/common/math_constants.h"

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Now uses M_PI and M_SQRT2 from math_constants.h.


namespace onnxruntime {
namespace ml { // name space for onnx.ml operators
Expand Down
3 changes: 2 additions & 1 deletion onnxruntime/core/providers/cpu/signal/dft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "core/providers/cpu/signal/utils.h"
#include "core/util/math_cpuonly.h"
#include "Eigen/src/Core/Map.h"
#include "core/common/math_constants.h"

namespace onnxruntime {

Expand Down Expand Up @@ -204,7 +205,7 @@ static Status dft_bluestein_z_chirp(
OpKernelContext* ctx, const Tensor* X, Tensor* Y, Tensor& b_fft, Tensor& chirp, size_t X_offset, size_t X_stride, size_t Y_offset, size_t Y_stride,
int64_t axis, size_t dft_length, const Tensor* window, bool inverse, InlinedVector<std::complex<T>>& V,
InlinedVector<std::complex<T>>& temp_output) {
static constexpr T pi = static_cast<T>(M_PI);
static const T pi = static_cast<T>(3.14159265358979323846);

AllocatorPtr alloc;
ORT_RETURN_IF_ERROR(ctx->GetTempSpaceAllocator(&alloc));
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/providers/cpu/signal/window_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "core/providers/common.h"
#include "core/providers/cpu/signal/utils.h"
#include "core/common/math_constants.h"

namespace onnxruntime {
ONNX_CPU_OPERATOR_KERNEL(HannWindow, 17,
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/session/inference_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ static Status LoadOrtModelBytes(const PathString& model_uri,

bytes_data_holder.resize(num_bytes);

std::ifstream bytes_stream(model_uri, std::ifstream::in | std::ifstream::binary);
std::ifstream bytes_stream(std::filesystem::path(model_uri), std::ifstream::in | std::ifstream::binary);
bytes_stream.read(reinterpret_cast<char*>(bytes_data_holder.data()), num_bytes);

if (!bytes_stream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ PluginExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_vie
return result;
}

// Out-of-line destructor: EpNode and EpValueInfo must be complete types
// when unique_ptr members are destroyed (required by libc++).
PluginExecutionProvider::FusedNodeState::~FusedNodeState() = default;

Status PluginExecutionProvider::FusedNodeState::AddFusedNode(const Node& fused_node, /*out*/ EpNode*& added_ep_node) {
std::unique_ptr<EpNode> unique_ep_fused_node = nullptr;
ORT_RETURN_IF_ERROR(EpNode::Create(fused_node, /*parent graph*/ nullptr, this->value_infos, unique_ep_fused_node));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ class PluginExecutionProvider : public IExecutionProvider {
struct FusedNodeState {
FusedNodeState() = default;
FusedNodeState(FusedNodeState&& other) = default;
FusedNodeState& operator=(FusedNodeState&& other) = default;
FusedNodeState(const FusedNodeState& other) = delete;
// Destructor defined out-of-line so EpNode/EpValueInfo are complete when
// unique_ptr<EpNode>/unique_ptr<EpValueInfo> are destroyed (required by libc++).
~FusedNodeState();
Status AddFusedNode(const Node& fused_node, /*out*/ EpNode*& added_ep_node);

std::vector<std::unique_ptr<EpNode>> nodes;
Expand Down
Loading