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
10 changes: 7 additions & 3 deletions onnxruntime/core/optimizer/skip_layer_norm_fusion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ Status SkipLayerNormFusion::ApplyImpl(Graph& graph, bool& modified, int graph_le
Format matched_format = Format::None;

// Format 1
std::vector<graph_utils::EdgeEndToMatch> format1_parent_path{
// The matcher paths are compile-time constants, so make them function-local `static const`:
// built once (not per node iteration), and their destructors run at program exit rather than
// inlined into ApplyImpl, which sidesteps a GCC 15 -Wfree-nonheap-object false positive on the
// vector's destructor.
static const std::vector<graph_utils::EdgeEndToMatch> format1_parent_path{
{0, 0, "Add", {7, 13, 14}, kOnnxDomain},
{0, 0, "Add", {7, 13, 14}, kOnnxDomain}};

Expand All @@ -218,7 +222,7 @@ Status SkipLayerNormFusion::ApplyImpl(Graph& graph, bool& modified, int graph_le

if (matched_format == Format::None) {
// Format 2
std::vector<graph_utils::EdgeEndToMatch> format2_parent_path{
static const std::vector<graph_utils::EdgeEndToMatch> format2_parent_path{
{0, 0, "Add", {7, 13, 14}, kOnnxDomain},
{0, 1, "Add", {7, 13, 14}, kOnnxDomain}};

Expand All @@ -237,7 +241,7 @@ Status SkipLayerNormFusion::ApplyImpl(Graph& graph, bool& modified, int graph_le

if (matched_format == Format::None) {
// Format 3
std::vector<graph_utils::EdgeEndToMatch> format3_parent_path{
static const std::vector<graph_utils::EdgeEndToMatch> format3_parent_path{
{0, 0, "Add", {7, 13, 14}, kOnnxDomain}};

if (graph_utils::FindPath(ln_node, true, format3_parent_path, edges, logger)) {
Expand Down
6 changes: 5 additions & 1 deletion onnxruntime/test/providers/cpu/ml/zipmap_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ using namespace std;
namespace onnxruntime {
namespace test {
template <typename T>
void TestHelper(const std::vector<T>& classes,
void TestHelper(std::initializer_list<T> classes_init,
const std::string& type,
const vector<int64_t>& input_dims,
OpTester::ExpectResult expect_result = OpTester::ExpectResult::kExpectSuccess) {
// Materialize the class list inside the helper rather than binding a braced std::vector temporary
// at each call site: keeps the vector's construction/destruction out of the inlined TEST body,
// where GCC 15 emits a -Wfree-nonheap-object false positive on the vector's destructor.
const std::vector<T> classes(classes_init);
OpTester test("ZipMap", 1, onnxruntime::kMLDomain);

std::vector<float> input{1.f, 0.f, 3.f, 44.f, 23.f, 11.3f};
Expand Down
26 changes: 13 additions & 13 deletions onnxruntime/test/unittest_util/conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@

#pragma once

#include <algorithm>
#include <cstdint>

#include "core/common/float16.h"
#include "core/util/math_cpuonly.h"

namespace onnxruntime {
namespace test {
// These converters use std::transform rather than an Eigen Map cast-assignment. The Eigen path
// vectorizes to a 16-wide _mm512_loadu_ps under -march=native, which GCC 15 mis-flags with a
// -Warray-bounds false positive when the helper is inlined into callers that pass small fixed-size
// buffers (it assumes the guarded packet load runs at input_size < 16). The element-wise transforms
// keep identical conversion semantics (Eigen::half round-to-nearest for float<->half; static_cast
// for the integer casts) without the vectorized load.
inline void ConvertFloatToMLFloat16(const float* f_datat, MLFloat16* h_data, size_t input_size) {
auto in_vector = ConstEigenVectorMap<float>(f_datat, input_size);
auto output_vector = EigenVectorMap<Eigen::half>(static_cast<Eigen::half*>(static_cast<void*>(h_data)), input_size);
output_vector = in_vector.template cast<Eigen::half>();
auto* h = static_cast<Eigen::half*>(static_cast<void*>(h_data));
std::transform(f_datat, f_datat + input_size, h, [](float f) { return static_cast<Eigen::half>(f); });
}

inline void ConvertFloatToUint8_t(const float* f_datat, uint8_t* u8_data, size_t input_size) {
auto in_vector = ConstEigenVectorMap<float>(f_datat, input_size);
auto output_vector = EigenVectorMap<uint8_t>(static_cast<uint8_t*>(static_cast<void*>(u8_data)), input_size);
output_vector = in_vector.template cast<uint8_t>();
std::transform(f_datat, f_datat + input_size, u8_data, [](float f) { return static_cast<uint8_t>(f); });
}

inline void ConvertFloatToInt8_t(const float* f_datat, int8_t* i8_data, size_t input_size) {
auto in_vector = ConstEigenVectorMap<float>(f_datat, input_size);
auto output_vector = EigenVectorMap<int8_t>(static_cast<int8_t*>(static_cast<void*>(i8_data)), input_size);
output_vector = in_vector.template cast<int8_t>();
std::transform(f_datat, f_datat + input_size, i8_data, [](float f) { return static_cast<int8_t>(f); });
}

inline void ConvertMLFloat16ToFloat(const MLFloat16* h_data, float* f_data, size_t input_size) {
auto in_vector =
ConstEigenVectorMap<Eigen::half>(static_cast<const Eigen::half*>(static_cast<const void*>(h_data)), input_size);
auto output_vector = EigenVectorMap<float>(f_data, input_size);
output_vector = in_vector.template cast<float>();
const auto* h = static_cast<const Eigen::half*>(static_cast<const void*>(h_data));
std::transform(h, h + input_size, f_data, [](Eigen::half h) { return static_cast<float>(h); });
}

inline std::vector<MLFloat16> FloatsToMLFloat16s(const std::vector<float>& f) {
Expand Down