From 627f853a446205c880eccd06dbb1c3b77ec498c4 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 3 Oct 2019 15:40:46 -0700 Subject: [PATCH] Downgrade compiler to CentOS 4.8.5 (#1985) Make onnxruntime CPU build and run on CentOS GCC 4.8.5 --- cmake/CMakeLists.txt | 5 +- cmake/onnxruntime_mlas.cmake | 11 +- include/onnxruntime/core/graph/node_arg.h | 2 +- .../UnitTests/Featurizer_UnitTest.cpp | 19 ++-- onnxruntime/core/common/profiler.cc | 2 +- .../core/framework/allocation_planner.cc | 18 +-- onnxruntime/core/framework/allocatormgr.cc | 5 +- onnxruntime/core/framework/execution_frame.cc | 12 +- onnxruntime/core/framework/kernel_registry.cc | 4 +- onnxruntime/core/framework/node_index_info.cc | 2 +- .../framework/ort_value_pattern_planner.cc | 2 +- .../core/framework/ort_value_tensor_slicer.cc | 12 +- .../core/framework/ort_value_tensor_slicer.h | 2 +- .../core/framework/parallel_executor.cc | 2 +- onnxruntime/core/framework/session_state.cc | 2 +- onnxruntime/core/framework/session_state.h | 4 +- .../framework/session_state_initializer.cc | 10 +- onnxruntime/core/graph/graph.cc | 15 +-- onnxruntime/core/optimizer/gelu_fusion.cc | 2 +- .../core/optimizer/transformer_memcpy.h | 2 +- .../providers/cpu/math/element_wise_ops.h | 4 +- onnxruntime/core/providers/cpu/math/softmax.h | 2 +- .../providers/cpu/nn/string_normalizer.cc | 107 ++++++++++++++++-- .../core/providers/cpu/nn/tfidfvectorizer.cc | 56 ++++++--- .../core/providers/cpu/tensor/where_op.cc | 18 +-- onnxruntime/core/session/inference_session.cc | 8 +- onnxruntime/core/session/onnxruntime_c_api.cc | 2 +- onnxruntime/core/util/math_cpuonly.h | 5 +- onnxruntime/gsl/gsl-lite.hpp | 10 +- .../contrib_ops/word_conv_embedding_test.cc | 1 - .../test/framework/execution_frame_test.cc | 2 +- .../test/framework/opaque_kernels_test.cc | 12 +- onnxruntime/test/onnx/main.cc | 3 + .../test/optimizer/graph_transform_test.cc | 6 +- .../test/providers/cpu/controlflow/if_test.cc | 4 +- .../providers/cpu/controlflow/loop_test.cc | 2 +- .../cpu/math/element_wise_ops_test.cc | 52 ++++----- .../test/providers/cpu/math/sign_test.cc | 26 +++-- .../cpu/ml/array_feature_extractor_test.cc | 2 +- .../cpu/nn/string_normalizer_test.cc | 1 - .../test/providers/provider_test_utils.h | 48 +++++--- 41 files changed, 327 insertions(+), 177 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 80fc368f7e..944ce25b26 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -12,7 +12,10 @@ set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) include(CheckCXXCompilerFlag) include(CheckLanguage) -# Set C++14 as standard for the whole project +# CentOS compiler is old but it does allow certain C++14 features +# such as lambda captures and they are convinient +# On the other hand it does not allow some others. +# So we cant' regulate simply with the standard. set(CMAKE_CXX_STANDARD 14) # General C# prperties diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake index 2149791bdf..4c03761542 100644 --- a/cmake/onnxruntime_mlas.cmake +++ b/cmake/onnxruntime_mlas.cmake @@ -180,13 +180,17 @@ else() ) set_source_files_properties(${mlas_platform_srcs_avx2} PROPERTIES COMPILE_FLAGS "-mavx2 -mfma") + set(mlas_platform_srcs_avx512f ${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/DgemmKernelAvx512F.S ${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/SgemmKernelAvx512F.S ${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/SconvKernelAvx512F.S ${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/SpoolKernelAvx512F.S ) - set_source_files_properties(${mlas_platform_srcs_avx512f} PROPERTIES COMPILE_FLAGS "-mavx512f") + check_cxx_compiler_flag("-mavx512f" HAS_AVX512F) + if(HAS_AVX512F) + set_source_files_properties(${mlas_platform_srcs_avx512f} PROPERTIES COMPILE_FLAGS "-mavx512f") + endif() set(mlas_platform_srcs_avx512bw ${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/QgemmU8S8KernelAvx512BW.S @@ -194,7 +198,10 @@ else() ${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/QgemmU8U8KernelAvx512BW.S ${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/QgemmU8U8KernelAvx512Vnni.S ) - set_source_files_properties(${mlas_platform_srcs_avx512bw} PROPERTIES COMPILE_FLAGS "-mavx512bw") + check_cxx_compiler_flag("-mavx512bw" HAS_AVX512BW) + if(HAS_AVX512BW) + set_source_files_properties(${mlas_platform_srcs_avx512bw} PROPERTIES COMPILE_FLAGS "-mavx512bw") + endif() set(mlas_platform_srcs ${mlas_platform_srcs_sse2} diff --git a/include/onnxruntime/core/graph/node_arg.h b/include/onnxruntime/core/graph/node_arg.h index 06ff04cdac..c2bd144fbf 100644 --- a/include/onnxruntime/core/graph/node_arg.h +++ b/include/onnxruntime/core/graph/node_arg.h @@ -38,7 +38,7 @@ class NodeArg { NodeArg(const std::string& name, const ONNX_NAMESPACE::TypeProto* p_arg_type); - NodeArg(NodeArg&& other) = default; + NodeArg(NodeArg&&) = default; /** Gets the name. */ const std::string& Name() const noexcept; diff --git a/onnxruntime/core/automl/featurizers/src/FeaturizerPrep/UnitTests/Featurizer_UnitTest.cpp b/onnxruntime/core/automl/featurizers/src/FeaturizerPrep/UnitTests/Featurizer_UnitTest.cpp index 2f6ee41076..26d3bef02e 100644 --- a/onnxruntime/core/automl/featurizers/src/FeaturizerPrep/UnitTests/Featurizer_UnitTest.cpp +++ b/onnxruntime/core/automl/featurizers/src/FeaturizerPrep/UnitTests/Featurizer_UnitTest.cpp @@ -88,15 +88,16 @@ TEST(FeaturizerTests, EstimatorFunctionality) { ASSERT_TRUE(MyEstimator().fit(0).commit()->transform(2)); } -TEST(FeaturizerTests, EstimatorErrors) { - MyEstimator e; - - ASSERT_NE(e.commit(), nullptr); - //CHECK_THROWS_WITH(e.fit(1), Catch::Contains("has already been committed")); - //CHECK_THROWS_WITH(e.commit(), Catch::Contains("has already been committed")); - - //CHECK_THROWS_WITH(MyEstimator(true).commit(), Catch::Matches("Invalid result")); -} +//TEST(FeaturizerTests, EstimatorErrors) { +// Commented out bc Linux complains e is not inited. +// MyEstimator e; +// +// ASSERT_NE(e.commit(), nullptr); +// //CHECK_THROWS_WITH(e.fit(1), Catch::Contains("has already been committed")); +// //CHECK_THROWS_WITH(e.commit(), Catch::Contains("has already been committed")); +// +// //CHECK_THROWS_WITH(MyEstimator(true).commit(), Catch::Matches("Invalid result")); +//} TEST(FeaturizerTests, EstimatorFitAndCommit) { ASSERT_TRUE(Microsoft::Featurizer::fit_and_commit(1, false)->transform(1)); diff --git a/onnxruntime/core/common/profiler.cc b/onnxruntime/core/common/profiler.cc index 1fa0577a67..6a99e6daf3 100644 --- a/onnxruntime/core/common/profiler.cc +++ b/onnxruntime/core/common/profiler.cc @@ -45,7 +45,7 @@ void Profiler::StartProfiling(const logging::Logger* custom_logger) { template void Profiler::StartProfiling(const std::basic_string& file_name) { enabled_ = true; - profile_stream_ = std::ofstream(file_name, std::ios::out | std::ios::trunc); + profile_stream_.open(file_name, std::ios::out | std::ios::trunc); profile_stream_file_ = ToMBString(file_name); profiling_start_time_ = StartTime(); } diff --git a/onnxruntime/core/framework/allocation_planner.cc b/onnxruntime/core/framework/allocation_planner.cc index a4e3024d90..169c2fc876 100644 --- a/onnxruntime/core/framework/allocation_planner.cc +++ b/onnxruntime/core/framework/allocation_planner.cc @@ -106,14 +106,14 @@ class PlannerImpl { const std::vector& outer_scope_node_args, const ExecutionProviders& providers, const KernelRegistryManager& kernel_registry, const OrtValueNameIdxMap& ort_value_name_idx_map, const ISequentialPlannerContext& context, SequentialExecutionPlan& plan) - : context_{context}, - plan_{plan}, - parent_node_{parent_node}, - graph_viewer_{graph_viewer}, - outer_scope_node_args_{outer_scope_node_args}, - execution_providers_{providers}, - kernel_registry_{kernel_registry}, - ort_value_name_idx_map_{ort_value_name_idx_map} {} + : context_(context), + plan_(plan), + parent_node_(parent_node), + graph_viewer_(graph_viewer), + outer_scope_node_args_(outer_scope_node_args), + execution_providers_(providers), + kernel_registry_(kernel_registry), + ort_value_name_idx_map_(ort_value_name_idx_map) {} Status CreatePlan(); @@ -500,7 +500,7 @@ class PlannerImpl { // Should only be used after ProcessDef() Status ComputeReusePlan() { - std::vector& execution_plan{plan_.execution_plan}; + std::vector& execution_plan(plan_.execution_plan); // Identify allocation/deallocation plan for every ml-value diff --git a/onnxruntime/core/framework/allocatormgr.cc b/onnxruntime/core/framework/allocatormgr.cc index ea258e4529..a06e35f901 100644 --- a/onnxruntime/core/framework/allocatormgr.cc +++ b/onnxruntime/core/framework/allocatormgr.cc @@ -14,11 +14,12 @@ using namespace ::onnxruntime::common; AllocatorPtr CreateAllocator(DeviceAllocatorRegistrationInfo info, int device_id) { auto device_allocator = std::unique_ptr(info.factory(device_id)); - if (device_allocator->AllowsArena()) + if (device_allocator->AllowsArena()) { return std::shared_ptr( onnxruntime::make_unique(std::move(device_allocator), info.max_mem)); + } - return device_allocator; + return AllocatorPtr(std::move(device_allocator)); } DeviceAllocatorRegistry& DeviceAllocatorRegistry::Instance() { diff --git a/onnxruntime/core/framework/execution_frame.cc b/onnxruntime/core/framework/execution_frame.cc index 7bdbe73019..298f84268c 100644 --- a/onnxruntime/core/framework/execution_frame.cc +++ b/onnxruntime/core/framework/execution_frame.cc @@ -22,9 +22,9 @@ IExecutionFrame::IExecutionFrame(const std::vector& feed_mlvalue_idxs, cons const std::unordered_map& initializers, const std::vector& fetch_mlvalue_idxs, const std::vector& fetches, const OrtValueNameIdxMap& ort_value_idx_map, const NodeIndexInfo& node_index_info) - : node_index_info_{node_index_info}, - all_values_size_{static_cast(ort_value_idx_map.MaxIdx()) + 1}, - fetch_mlvalue_idxs_{fetch_mlvalue_idxs} { + : node_index_info_(node_index_info), + all_values_size_(static_cast(ort_value_idx_map.MaxIdx()) + 1), + fetch_mlvalue_idxs_(fetch_mlvalue_idxs) { ORT_ENFORCE(feeds.size() == feed_mlvalue_idxs.size()); ORT_ENFORCE(fetches.empty() || fetches.size() == fetch_mlvalue_idxs_.size()); ORT_ENFORCE(node_index_info_.GetMaxMLValueIdx() == ort_value_idx_map.MaxIdx(), @@ -171,9 +171,9 @@ ExecutionFrame::ExecutionFrame(const std::vector& feed_mlvalue_idxs, const const SessionState& session_state) : IExecutionFrame(feed_mlvalue_idxs, feeds, session_state.GetInitializedTensors(), fetch_mlvalue_idxs, fetches, session_state.GetOrtValueNameIdxMap(), session_state.GetNodeIndexInfo()), - session_state_{session_state}, - mem_patterns_{nullptr}, - planner_{nullptr} { + session_state_(session_state), + mem_patterns_(nullptr), + planner_(nullptr) { // map the custom allocators to ort_value_idx entries if (!fetch_allocators.empty()) { for (size_t idx = 0, end = fetch_mlvalue_idxs.size(); idx < end; ++idx) { diff --git a/onnxruntime/core/framework/kernel_registry.cc b/onnxruntime/core/framework/kernel_registry.cc index dbcd2a532e..feb26f06a0 100644 --- a/onnxruntime/core/framework/kernel_registry.cc +++ b/onnxruntime/core/framework/kernel_registry.cc @@ -62,8 +62,8 @@ void TraverseFormalParametersWithTypeProto(const Node& node, class TypeBindingResolver { public: TypeBindingResolver(const Node& node, bool use_lookup_map) - : node_{node}, - type_binding_map_{} { + : node_(node), + type_binding_map_() { if (use_lookup_map) { type_binding_map_ = onnxruntime::make_unique(); TraverseFormalParametersWithTypeProto( diff --git a/onnxruntime/core/framework/node_index_info.cc b/onnxruntime/core/framework/node_index_info.cc index d77a72cabc..4063d0104f 100644 --- a/onnxruntime/core/framework/node_index_info.cc +++ b/onnxruntime/core/framework/node_index_info.cc @@ -11,7 +11,7 @@ namespace onnxruntime { // if we have a full GraphViewer, assume the min node index is 0 NodeIndexInfo::NodeIndexInfo(const GraphViewer& graph_viewer, const OrtValueNameIdxMap& ort_value_idx_map) - : min_node_index_{0}, max_mlvalue_idx_{ort_value_idx_map.MaxIdx()} { + : min_node_index_(0), max_mlvalue_idx_(ort_value_idx_map.MaxIdx()) { Init(graph_viewer.Nodes(), graph_viewer.MaxNodeIndex(), ort_value_idx_map); } diff --git a/onnxruntime/core/framework/ort_value_pattern_planner.cc b/onnxruntime/core/framework/ort_value_pattern_planner.cc index 9239ca0949..e4df7c6560 100644 --- a/onnxruntime/core/framework/ort_value_pattern_planner.cc +++ b/onnxruntime/core/framework/ort_value_pattern_planner.cc @@ -7,7 +7,7 @@ namespace onnxruntime { OrtValuePatternPlanner::OrtValuePatternPlanner(const ExecutionPlanBase& execution_plan) - : execution_planner_{execution_plan} { + : execution_planner_(execution_plan) { for (auto& location : execution_plan.GetAllLocations()) { planner_map_.emplace(location, onnxruntime::make_unique()); } diff --git a/onnxruntime/core/framework/ort_value_tensor_slicer.cc b/onnxruntime/core/framework/ort_value_tensor_slicer.cc index 82eabf7c1e..a936995257 100644 --- a/onnxruntime/core/framework/ort_value_tensor_slicer.cc +++ b/onnxruntime/core/framework/ort_value_tensor_slicer.cc @@ -8,13 +8,13 @@ namespace onnxruntime { template OrtValueTensorSlicer OrtValueTensorSlicer::Create(T& ort_value, int64_t slice_dimension, int64_t dim0_offset) { - static_assert(std::is_same, OrtValue>::value, + static_assert(std::is_same::type, OrtValue>::value, "OrtValueTensorSlicer can only be used with 'OrtValue' or 'const OrtValue'"); ORT_ENFORCE(ort_value.IsTensor(), "Can't slice a non-tensor OrtValue. Type was ", ort_value.Type()); ORT_ENFORCE(ort_value.IsAllocated(), "OrtValue has not been allocated so can't be sliced."); - auto& tensor_shape{ort_value.template Get().Shape()}; + auto& tensor_shape = ort_value.template Get().Shape(); ORT_ENFORCE(gsl::narrow_cast(tensor_shape.NumDimensions()) >= slice_dimension, "Insufficient dimensions to slice on ", slice_dimension, ". Shape:", tensor_shape); @@ -27,10 +27,10 @@ OrtValueTensorSlicer OrtValueTensorSlicer::Create(T& ort_value, int64_t sl template OrtValueTensorSlicer::Iterator::Iterator(T& ort_value, size_t slice_dimension, size_t dim0_offset, int64_t position, Direction direction) - : ort_value_{&ort_value}, - position_{position}, - increment_by_{direction == Direction::kForward ? 1 : -1}, - position_materialized_{-1} { + : ort_value_(&ort_value), + position_(position), + increment_by_(direction == Direction::kForward ? 1 : -1), + position_materialized_(-1) { const auto& tensor = ort_value.template Get(); tensor_data_type_ = tensor.DataType(); tensor_location_ = &tensor.Location(); diff --git a/onnxruntime/core/framework/ort_value_tensor_slicer.h b/onnxruntime/core/framework/ort_value_tensor_slicer.h index 47ae14532d..042ce9b5c0 100644 --- a/onnxruntime/core/framework/ort_value_tensor_slicer.h +++ b/onnxruntime/core/framework/ort_value_tensor_slicer.h @@ -133,7 +133,7 @@ class OrtValueTensorSlicer { private: OrtValueTensorSlicer(T& ort_value, int64_t slice_dimension, int64_t dim0_offset) noexcept - : ort_value_{&ort_value}, slice_dimension_{slice_dimension}, dim0_offset_{dim0_offset} {} + : ort_value_(&ort_value), slice_dimension_(slice_dimension), dim0_offset_(dim0_offset) {} T* ort_value_; int64_t slice_dimension_; diff --git a/onnxruntime/core/framework/parallel_executor.cc b/onnxruntime/core/framework/parallel_executor.cc index e47ad21f89..301ae73183 100644 --- a/onnxruntime/core/framework/parallel_executor.cc +++ b/onnxruntime/core/framework/parallel_executor.cc @@ -19,7 +19,7 @@ namespace onnxruntime { ParallelExecutor::ParallelExecutor(const SessionState& session_state, const bool& terminate_flag) - : out_standings_(0), terminate_flag_{terminate_flag}, executor_pool_(session_state.GetInterOpThreadPool()) { + : out_standings_(0), terminate_flag_(terminate_flag), executor_pool_(session_state.GetInterOpThreadPool()) { auto graph_viewer = session_state.GetGraphViewer(); node_refs_.resize(graph_viewer->MaxNodeIndex()); for (auto& node : graph_viewer->Nodes()) { diff --git a/onnxruntime/core/framework/session_state.cc b/onnxruntime/core/framework/session_state.cc index 7b30bd888d..bafac8fba9 100644 --- a/onnxruntime/core/framework/session_state.cc +++ b/onnxruntime/core/framework/session_state.cc @@ -281,7 +281,7 @@ SessionState* SessionState::GetMutableSubgraphSessionState(onnxruntime::NodeInde auto node_entry = subgraph_session_states_.find(index); if (node_entry != subgraph_session_states_.cend()) { - const auto& attribute_state_map{node_entry->second}; + const auto& attribute_state_map = node_entry->second; const auto& subgraph_entry = attribute_state_map.find(attribute_name); if (subgraph_entry != attribute_state_map.cend()) { diff --git a/onnxruntime/core/framework/session_state.h b/onnxruntime/core/framework/session_state.h index ddf811e16f..a8c0a9833c 100644 --- a/onnxruntime/core/framework/session_state.h +++ b/onnxruntime/core/framework/session_state.h @@ -240,7 +240,7 @@ class SessionState { std::unique_ptr p_seq_exec_plan_ = nullptr; const logging::Logger* logger_ = nullptr; - profiling::Profiler* profiler_; + profiling::Profiler* profiler_ = nullptr; // switch for enable memory pattern optimization or not. const bool enable_mem_pattern_; @@ -264,7 +264,7 @@ class SessionState { bool export_fused_dll_ = false; FuncManager fused_funcs_mgr_; - const DataTransferManager* data_transfer_mgr_; + const DataTransferManager* data_transfer_mgr_ = nullptr; std::unique_ptr node_index_info_; std::multimap> cached_feeds_fetches_managers_; diff --git a/onnxruntime/core/framework/session_state_initializer.cc b/onnxruntime/core/framework/session_state_initializer.cc index 698c365146..a4b5e00ef4 100644 --- a/onnxruntime/core/framework/session_state_initializer.cc +++ b/onnxruntime/core/framework/session_state_initializer.cc @@ -48,11 +48,11 @@ SessionStateInitializer::SessionStateInitializer(bool enable_mem_pattern, const ExecutionProviders& providers, KernelRegistryManager& kernel_registry_manager) : graph_loc_(graph_loc), - graph_{graph}, - session_state_{session_state}, - execution_providers_{providers}, - kernel_registry_manager_{kernel_registry_manager}, - logger_{session_state.Logger()}, + graph_(graph), + session_state_(session_state), + execution_providers_(providers), + kernel_registry_manager_(kernel_registry_manager), + logger_(session_state.Logger()), enable_mem_pattern_(enable_mem_pattern) {} common::Status SessionStateInitializer::CreatePlan( diff --git a/onnxruntime/core/graph/graph.cc b/onnxruntime/core/graph/graph.cc index 30a57f5cf4..9f8c4550d5 100644 --- a/onnxruntime/core/graph/graph.cc +++ b/onnxruntime/core/graph/graph.cc @@ -430,7 +430,7 @@ void Node::CreateSubgraph(const std::string& attr_name) { if (attr != attributes_.cend() && utils::HasGraph(attr->second)) { GraphProto& mutable_graph = *attr->second.mutable_g(); std::unique_ptr subgraph{new Graph(*graph_, *this, mutable_graph)}; - attr_to_subgraph_map_.insert({std::string{attr_name}, gsl::not_null{subgraph.get()}}); + attr_to_subgraph_map_.insert({std::string(attr_name), gsl::not_null{subgraph.get()}}); subgraphs_.push_back(std::move(subgraph)); } } @@ -585,8 +585,9 @@ const Graph* Node::GetGraphAttribute(const std::string& attr_name) const { std::vector> Node::GetSubgraphs() const { std::vector> subgraphs; subgraphs.reserve(attr_to_subgraph_map_.size()); + using value_type = std::unordered_map>::value_type; std::transform(attr_to_subgraph_map_.cbegin(), attr_to_subgraph_map_.cend(), std::back_inserter(subgraphs), - [](const auto& entry) { return entry.second; }); + [](const value_type& entry) { return entry.second; }); return subgraphs; } @@ -646,14 +647,14 @@ Graph::Graph(GraphProto* graph_proto, Graph::Graph(GraphProto* graph_proto, const std::unordered_map& domain_to_version, Version ir_version, IOnnxRuntimeOpSchemaCollectionPtr schema_registry, Graph* parent_graph, const Node* parent_node, const std::unordered_map& model_functions) - : graph_proto_{graph_proto}, + : graph_proto_(graph_proto), schema_registry_(schema_registry), graph_resolve_needed_(true), domain_to_version_(domain_to_version), model_functions_(model_functions), ir_version_(ir_version), - parent_graph_{parent_graph}, - parent_node_{parent_node} { + parent_graph_(parent_graph), + parent_node_(parent_node) { ORT_ENFORCE(graph_proto != nullptr, "graph_proto cannot be null"); ArgNameToTypeMap name_to_type_map; @@ -1245,7 +1246,7 @@ using SubgraphInferencingFunc = class GraphInferencerImpl : public ONNX_NAMESPACE::GraphInferencer { public: GraphInferencerImpl(const Node& node, Graph& graph, SubgraphInferencingFunc& inferencing_func) - : node_{node}, graph_{graph}, inferencing_func_{inferencing_func} { + : node_(node), graph_(graph), inferencing_func_(inferencing_func) { } // Perform inferencing on the graph contained in GraphInferencer. @@ -1543,7 +1544,7 @@ Status Graph::InferAndVerifyTypeMatch(Node& node, const OpSchema& op) { return Status(ONNXRUNTIME, FAIL, ex.what()); } - const auto& onnx_inferred_types{context.InferredOutputTypes()}; + const auto& onnx_inferred_types(context.InferredOutputTypes()); // Infer and verify node output arg type information. int i = -1; diff --git a/onnxruntime/core/optimizer/gelu_fusion.cc b/onnxruntime/core/optimizer/gelu_fusion.cc index 6d09891f98..29854d0aa7 100644 --- a/onnxruntime/core/optimizer/gelu_fusion.cc +++ b/onnxruntime/core/optimizer/gelu_fusion.cc @@ -24,7 +24,7 @@ static bool CheckConstantInput(const Graph& graph, const NodeArg& input_arg, flo return false; } - auto init_const = std::make_unique(tensor_proto); + auto init_const = onnxruntime::make_unique(tensor_proto); const auto data_type = tensor_proto->data_type(); if (data_type == ONNX_NAMESPACE::TensorProto_DataType_FLOAT) { float* val = init_const->data(); diff --git a/onnxruntime/core/optimizer/transformer_memcpy.h b/onnxruntime/core/optimizer/transformer_memcpy.h index af5aa25e2c..b3793eef1a 100644 --- a/onnxruntime/core/optimizer/transformer_memcpy.h +++ b/onnxruntime/core/optimizer/transformer_memcpy.h @@ -20,7 +20,7 @@ Transformer that inserts nodes to copy memory between devices when needed. class MemcpyTransformer : public GraphTransformer { public: MemcpyTransformer(const std::vector& provider_types, const KernelRegistryManager& registry_manager) - : GraphTransformer("MemcpyTransformer"), provider_types_{provider_types}, registry_manager_(std::cref(registry_manager)) {} + : GraphTransformer("MemcpyTransformer"), provider_types_(provider_types), registry_manager_(std::cref(registry_manager)) {} private: common::Status ApplyImpl(Graph& graph, bool& modified, int graph_level) const override; diff --git a/onnxruntime/core/providers/cpu/math/element_wise_ops.h b/onnxruntime/core/providers/cpu/math/element_wise_ops.h index 438dd7d36e..50f1a9f925 100644 --- a/onnxruntime/core/providers/cpu/math/element_wise_ops.h +++ b/onnxruntime/core/providers/cpu/math/element_wise_ops.h @@ -298,9 +298,9 @@ class Erf final : public OpKernel { }; template -auto MakeEigenArrayMap(Tensor& t) { return EigenVectorArrayMap(t.template MutableData(), t.Shape().Size()); } +auto MakeEigenArrayMap(Tensor& t) -> EigenVectorArrayMap { return EigenVectorArrayMap(t.template MutableData(), t.Shape().Size()); } template -auto MakeEigenArrayMap(const Tensor& t) { return ConstEigenVectorArrayMap(t.template Data(), t.Shape().Size()); } +auto MakeEigenArrayMap(const Tensor& t) -> ConstEigenVectorArrayMap { return ConstEigenVectorArrayMap(t.template Data(), t.Shape().Size()); } struct BroadcastIterator { size_t AdvanceBy(size_t delta) { diff --git a/onnxruntime/core/providers/cpu/math/softmax.h b/onnxruntime/core/providers/cpu/math/softmax.h index dcb6cdeff8..484c6057d5 100644 --- a/onnxruntime/core/providers/cpu/math/softmax.h +++ b/onnxruntime/core/providers/cpu/math/softmax.h @@ -93,7 +93,7 @@ class Softmax final : public OpKernel { if (tensor_pointer == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch"); const Tensor& X = *tensor_pointer; - const TensorShape& input_shape{X.Shape()}; + const TensorShape& input_shape = X.Shape(); VLOGS(ctx->Logger(), 2) << "Input tensor shape: " << input_shape; diff --git a/onnxruntime/core/providers/cpu/nn/string_normalizer.cc b/onnxruntime/core/providers/cpu/nn/string_normalizer.cc index 7ce49bef4a..c7b473186d 100644 --- a/onnxruntime/core/providers/cpu/nn/string_normalizer.cc +++ b/onnxruntime/core/providers/cpu/nn/string_normalizer.cc @@ -7,10 +7,15 @@ #include "core/framework/tensor.h" #ifdef _MSC_VER -#include -#endif - #include +#include +#elif (defined __APPLE__) +#include +#else +#include +#include +#endif // _MSC_VER + #include #include #include @@ -68,12 +73,15 @@ class Locale { _locale_t loc_; }; +using Utf8Converter = std::wstring_convert>; + const std::string default_locale("en-US"); -#else +#else // MS_VER + class Locale { public: - explicit Locale(const std::string& name) try : loc_(name) { + explicit Locale(const std::string& name) try : loc_(name.c_str()) { } catch (const std::runtime_error& e) { ORT_THROW("Failed to construct locale with name:", name, ":", e.what(), ":Please, install necessary language-pack-XX and configure locales"); @@ -97,14 +105,93 @@ class Locale { std::locale loc_; }; -const std::string default_locale("en_US.UTF-8"); +#ifdef __APPLE__ +using Utf8Converter = std::wstring_convert>; +#else -#endif +// All others (Linux) +class Utf8Converter { + public: + + Utf8Converter(const std::string&, const std::wstring&) {} + + std::wstring from_bytes(const std::string& s) const { + std::wstring result; + if (s.empty()) { + return result; + } + // Order of arguments is to, from + auto icvt = iconv_open("WCHAR_T", "UTF-8"); + // CentOS is not happy with -1 + if (std::numeric_limits::max() == icvt) { + return wconv_error; + } + + char* iconv_in = const_cast(s.c_str()); + size_t iconv_in_bytes = s.length(); + // Temporary buffer assumes 1 byte to 1 wchar_t + // to make sure it is enough. + const size_t buffer_len = iconv_in_bytes * sizeof(wchar_t); + auto buffer = onnxruntime::make_unique(buffer_len); + char* iconv_out = buffer.get(); + size_t iconv_out_bytes = buffer_len; + auto ret = iconv(icvt, &iconv_in, &iconv_in_bytes, &iconv_out, &iconv_out_bytes); + if (static_cast(-1) == ret) { + result = wconv_error; + } else { + size_t converted_bytes = buffer_len - iconv_out_bytes; + assert((converted_bytes % sizeof(wchar_t)) == 0); + result.assign(reinterpret_cast(buffer.get()), converted_bytes / sizeof(wchar_t)); + } + iconv_close(icvt); + return result; + } + + std::string to_bytes(const std::wstring& wstr) const { + std::string result; + if (wstr.empty()) { + return result; + } + // Order of arguments is to, from + auto icvt = iconv_open("UTF-8", "WCHAR_T"); + // CentOS is not happy with -1 + if (std::numeric_limits::max() == icvt) { + return conv_error; + } + + // I hope this does not modify the incoming buffer + wchar_t* non_const_in = const_cast(wstr.c_str()); + char* iconv_in = reinterpret_cast(non_const_in); + size_t iconv_in_bytes = wstr.length() * sizeof(wchar_t); + // Temp buffer, assume every code point converts into 3 bytes, this should be enough + // We do not convert terminating zeros + const size_t buffer_len = wstr.length() * 3; + auto buffer = onnxruntime::make_unique(buffer_len); + + char* iconv_out = buffer.get(); + size_t iconv_out_bytes = buffer_len; + auto ret = iconv(icvt, &iconv_in, &iconv_in_bytes, &iconv_out, &iconv_out_bytes); + if (static_cast(-1) == ret) { + result = conv_error; + } else { + size_t converted_len = buffer_len - iconv_out_bytes; + result.assign(buffer.get(), converted_len); + } + iconv_close(icvt); + return result; + } +}; + +#endif // __APPLE__ + +const std::string default_locale("en_US.UTF-8"); // All non-MS + +#endif // MS_VER template Status CopyCaseAction(ForwardIter first, ForwardIter end, OpKernelContext* ctx, const Locale& loc, - std::wstring_convert>& converter, + Utf8Converter& converter, size_t N, size_t C, StringNormalizer::CaseAction caseaction) { std::vector output_dims; @@ -182,7 +269,7 @@ StringNormalizer::StringNormalizer(const OpKernelInfo& info) : OpKernel(info), locale_name_ = info.GetAttrOrDefault("locale", default_locale); Locale locale(locale_name_); - std::wstring_convert> converter(conv_error, wconv_error); + Utf8Converter converter(conv_error, wconv_error); std::vector swords = info.GetAttrsOrDefault("stopwords"); for (const auto& sw : swords) { @@ -229,7 +316,7 @@ Status StringNormalizer::Compute(OpKernelContext* ctx) const { Status status; Locale locale(locale_name_); - std::wstring_convert> converter(conv_error, wconv_error); + Utf8Converter converter(conv_error, wconv_error); auto const input_data = X->template Data(); using StrRef = std::reference_wrapper; if (is_case_sensitive_) { diff --git a/onnxruntime/core/providers/cpu/nn/tfidfvectorizer.cc b/onnxruntime/core/providers/cpu/nn/tfidfvectorizer.cc index a69c94959a..37d121dd9d 100644 --- a/onnxruntime/core/providers/cpu/nn/tfidfvectorizer.cc +++ b/onnxruntime/core/providers/cpu/nn/tfidfvectorizer.cc @@ -61,7 +61,7 @@ class NgramEntry : public NgramEntryBase { size_t hash_ = 0; void RunningHash(int64_t v) { - std::hash hf{}; + std::hash hf; hash_ ^= hf(v) + 0x9e3779b9 + (hash_ << 6) + (hash_ >> 2); } @@ -112,7 +112,7 @@ class NgramEntry : public NgramEntryBase { size_t hash_ = 0; void RunningHash(const std::string& s) { - std::hash hf{}; + std::hash hf; hash_ ^= hf(s) + 0x9e3779b9 + (hash_ << 6) + (hash_ >> 2); } @@ -142,9 +142,13 @@ class NgramEntry : public NgramEntryBase { bool operator==(const NgramEntry& o) const { if (items_.size() == o.items_.size()) { - return std::equal(items_.cbegin(), items_.cend(), - o.items_.cbegin(), o.items_.cend(), - std::equal_to()); + std::equal_to pred; + for (size_t i = 0; i < items_.size(); ++i) { + if (!pred(items_[i], o.items_[i])) { + return false; + } + } + return true; } return false; } @@ -153,11 +157,6 @@ class NgramEntry : public NgramEntryBase { } }; -using IntegerPoolSet = std::unordered_set>; -// Does not own strings, contains references to them. This helps -// to search by string references that point to the current input. -using StringPoolSet = std::unordered_set>; - template inline void Emplace(ForwardIter first, size_t ngrams, size_t ngram_size, size_t& ngram_id, Cont& c) { for (; ngrams > 0; --ngrams) { @@ -185,6 +184,27 @@ struct hash> { namespace onnxruntime { +using IntegerPoolSet = std::unordered_set>; +// Does not own strings, contains references to them. This helps +// to search by string references that point to the current input. +using StringPoolSet = std::unordered_set>; + +template +struct Return; + +template <> +struct Return { + using type = IntegerPoolSet::const_iterator; +}; + +template <> +struct Return : Return {}; + +template <> +struct Return { + using type = StringPoolSet::const_iterator; +}; + // The weighting criteria. // "TF"(term frequency), // the counts are propagated to output @@ -233,10 +253,10 @@ struct TfIdfVectorizer::Impl { Impl& operator=(const Impl&) = delete; template - auto PoolEnd() const; + typename Return::type PoolEnd() const; template - auto PoolFind(const ngram_details::NgramEntry&) const; + typename Return::type PoolFind(const ngram_details::NgramEntry&) const; void IncrementCount(size_t ngram_id, size_t row_num, std::vector& frequencies) const { @@ -248,32 +268,32 @@ struct TfIdfVectorizer::Impl { }; template <> -inline auto TfIdfVectorizer::Impl::PoolEnd() const { +inline Return::type TfIdfVectorizer::Impl::PoolEnd() const { return int64_set_.cend(); } template <> -inline auto TfIdfVectorizer::Impl::PoolEnd() const { +inline Return::type TfIdfVectorizer::Impl::PoolEnd() const { return PoolEnd(); } template <> -inline auto TfIdfVectorizer::Impl::PoolEnd() const { +inline Return::type TfIdfVectorizer::Impl::PoolEnd() const { return str_set_.cend(); } template <> -inline auto TfIdfVectorizer::Impl::PoolFind(const NgramEntry& i) const { +inline Return::type TfIdfVectorizer::Impl::PoolFind(const NgramEntry& i) const { return int64_set_.find(i); } template <> -inline auto TfIdfVectorizer::Impl::PoolFind(const NgramEntry& i) const { +inline Return::type TfIdfVectorizer::Impl::PoolFind(const NgramEntry& i) const { return int64_set_.find(i); } template <> -inline auto TfIdfVectorizer::Impl::PoolFind(const NgramEntry& i) const { +inline Return::type TfIdfVectorizer::Impl::PoolFind(const NgramEntry& i) const { return str_set_.find(i); } diff --git a/onnxruntime/core/providers/cpu/tensor/where_op.cc b/onnxruntime/core/providers/cpu/tensor/where_op.cc index bd946c4619..d518352af8 100644 --- a/onnxruntime/core/providers/cpu/tensor/where_op.cc +++ b/onnxruntime/core/providers/cpu/tensor/where_op.cc @@ -41,11 +41,15 @@ WHERE_TYPED_KERNEL_WITH_TYPE_NAME(std::string, string) #undef WHERE_TYPED_KERNEL namespace { -template -constexpr bool IsEigenScalarCompatible = std::is_arithmetic::value; + +template +using EnableIfEigenScalar = typename std::enable_if::value, R>::type; + +template +using EnableIfEigenNotScalar = typename std::enable_if::value, R>::type; template -std::enable_if_t, void> +EnableIfEigenScalar SelectBroadcastLoop(bool target, TBroadcaster* select_broadcaster, TBroadcastOutput* select_broadcast_output) { @@ -69,7 +73,7 @@ SelectBroadcastLoop(bool target, } template -std::enable_if_t, void> +EnableIfEigenNotScalar SelectBroadcastLoop(bool target, TBroadcaster* select_broadcaster, TBroadcastOutput* select_broadcast_output) { BroadcastLoopSpan( @@ -110,10 +114,10 @@ std::unique_ptr Select(bool target, const Tensor& condition_tensor, cons } template -std::enable_if_t, void> +EnableIfEigenScalar MergeBroadcastLoop(TBroadcaster* merge_broadcaster, TBroadcastOutput* merge_broadcast_output) { const auto merge_scalar_and_vector = [](EigenVectorMap output, - const T& scalar_value, ConstEigenVectorMap vector_value) { + const T& scalar_value, ConstEigenVectorMap vector_value) { if (scalar_value != T{}) { output = EigenVectorMap::PlainObject::Constant(vector_value.size(), scalar_value); } else { @@ -137,7 +141,7 @@ MergeBroadcastLoop(TBroadcaster* merge_broadcaster, TBroadcastOutput* m } template -std::enable_if_t, void> +EnableIfEigenNotScalar MergeBroadcastLoop(TBroadcaster* merge_broadcaster, TBroadcastOutput* merge_broadcast_output) { const auto merge_scalar_and_vector = [](gsl::span output, const T& scalar_value, gsl::span vector_value) { if (!scalar_value.empty()) { diff --git a/onnxruntime/core/session/inference_session.cc b/onnxruntime/core/session/inference_session.cc index 3e5cb1b5c4..d52d5e404b 100644 --- a/onnxruntime/core/session/inference_session.cc +++ b/onnxruntime/core/session/inference_session.cc @@ -94,9 +94,9 @@ inline std::basic_string GetCurrentTimeString() { InferenceSession::InferenceSession(const SessionOptions& session_options, logging::LoggingManager* logging_manager) - : session_options_{session_options}, - graph_transformation_mgr_{session_options.max_num_graph_transformation_steps}, - logging_manager_{logging_manager}, + : session_options_(session_options), + graph_transformation_mgr_(session_options.max_num_graph_transformation_steps), + logging_manager_(logging_manager), thread_pool_(concurrency::CreateThreadPool("intra_op_thread_pool", session_options.intra_op_num_threads)), inter_op_thread_pool_(!session_options.enable_sequential_execution @@ -107,7 +107,7 @@ InferenceSession::InferenceSession(const SessionOptions& session_options, session_options.enable_mem_pattern && session_options.enable_sequential_execution, thread_pool_.get(), inter_op_thread_pool_.get()), - insert_cast_transformer_{"CastFloat16Transformer"} { + insert_cast_transformer_("CastFloat16Transformer") { ORT_ENFORCE(Environment::IsInitialized(), "Environment must be initialized before creating an InferenceSession."); diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index a082fd3669..8a0466064b 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -75,7 +75,7 @@ struct OrtEnv { class LoggingWrapper : public ISink { public: LoggingWrapper(OrtLoggingFunction logging_function, void* logger_param) - : logging_function_{logging_function}, logger_param_{logger_param} { + : logging_function_(logging_function), logger_param_(logger_param) { } void SendImpl(const Timestamp& /*timestamp*/ /*timestamp*/, const std::string& logger_id, diff --git a/onnxruntime/core/util/math_cpuonly.h b/onnxruntime/core/util/math_cpuonly.h index 66a0d4d0e4..d25e60fa88 100644 --- a/onnxruntime/core/util/math_cpuonly.h +++ b/onnxruntime/core/util/math_cpuonly.h @@ -61,11 +61,12 @@ template using ConstEigenMatrixMapRowMajor = Eigen::Map>; template -auto EigenMap(Tensor& t) { +auto EigenMap(Tensor& t) -> EigenVectorMap { return EigenVectorMap(t.template MutableData(), t.Shape().Size()); } template -auto EigenMap(const Tensor& t) { +auto EigenMap(const Tensor& t) -> ConstEigenVectorMap { + return ConstEigenVectorMap(t.template Data(), t.Shape().Size()); } diff --git a/onnxruntime/gsl/gsl-lite.hpp b/onnxruntime/gsl/gsl-lite.hpp index 7ffe189358..876defb5aa 100644 --- a/onnxruntime/gsl/gsl-lite.hpp +++ b/onnxruntime/gsl/gsl-lite.hpp @@ -1780,24 +1780,24 @@ gsl_DISABLE_MSVC_WARNINGS(26410 26415 26418 26472 26439 26440 26473 26481 26482 // 26.7.3.3 Subviews [span.sub] gsl_api gsl_constexpr14 span first(index_type count) const gsl_noexcept { - Expects(0 <= count && count <= this->size()); + Expects(count <= this->size()); return span(this->data(), count); } gsl_api gsl_constexpr14 span last(index_type count) const gsl_noexcept { - Expects(0 <= count && count <= this->size()); + Expects(count <= this->size()); return span(this->data() + this->size() - count, count); } gsl_api gsl_constexpr14 span subspan(index_type offset) const gsl_noexcept { - Expects(0 <= offset && offset <= this->size()); + Expects(offset <= this->size()); return span(this->data() + offset, this->size() - offset); } gsl_api gsl_constexpr14 span subspan(index_type offset, index_type count) const gsl_noexcept { Expects( - 0 <= offset && offset <= this->size() && - 0 <= count && count <= this->size() - offset); + offset <= this->size() && + count <= this->size() - offset); return span(this->data() + offset, count); } diff --git a/onnxruntime/test/contrib_ops/word_conv_embedding_test.cc b/onnxruntime/test/contrib_ops/word_conv_embedding_test.cc index c2e12569f5..fb4189cf3d 100644 --- a/onnxruntime/test/contrib_ops/word_conv_embedding_test.cc +++ b/onnxruntime/test/contrib_ops/word_conv_embedding_test.cc @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include #include #include "gtest/gtest.h" #include "test/providers/provider_test_utils.h" diff --git a/onnxruntime/test/framework/execution_frame_test.cc b/onnxruntime/test/framework/execution_frame_test.cc index c5aa5848d5..1d853b02a8 100644 --- a/onnxruntime/test/framework/execution_frame_test.cc +++ b/onnxruntime/test/framework/execution_frame_test.cc @@ -195,7 +195,7 @@ TEST_F(ExecutionFrameTest, MemPatternTest) { status = state.SetGraphAndCreateKernels(graph, kernel_registry_manager); EXPECT_TRUE(status.IsOK()) << status.ErrorMessage(); - const OrtValueNameIdxMap& mlvalue_name_idx_map{state.GetOrtValueNameIdxMap()}; + const OrtValueNameIdxMap& mlvalue_name_idx_map(state.GetOrtValueNameIdxMap()); int x1_idx, x2_idx, x3_idx; int t1_idx, t2_idx, t3_idx; diff --git a/onnxruntime/test/framework/opaque_kernels_test.cc b/onnxruntime/test/framework/opaque_kernels_test.cc index ab994cce96..e9529b926e 100644 --- a/onnxruntime/test/framework/opaque_kernels_test.cc +++ b/onnxruntime/test/framework/opaque_kernels_test.cc @@ -53,27 +53,27 @@ class SparseTensorSample final { SparseTensorSample(SparseTensorSample&&) = default; SparseTensorSample& operator=(SparseTensorSample&&) = default; - const auto& Values() const { + const std::vector& Values() const { return values_; } - const auto& Indicies() const { + const std::vector& Indicies() const { return indicies_; } - const auto& Size() const { + int64_t Size() const { return size_; } - auto& Values() { + std::vector& Values() { return values_; } - auto& Indicies() { + std::vector& Indicies() { return indicies_; } - auto& Size() { + int64_t& Size() { return size_; } diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index 4a23f10bd9..f323dbd38e 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -364,6 +364,9 @@ int real_main(int argc, char* argv[], Ort::Env& env) { std::string test_name_; std::string reason_; std::set broken_versions_ = {}; // apply to all versions if empty + BrokenTest(std::string name, std::string reason) : test_name_(std::move(name)), reason_(std::move(reason)) {} + BrokenTest(std::string name, std::string reason, const std::initializer_list& versions) : + test_name_(std::move(name)), reason_(std::move(reason)), broken_versions_(versions) {} bool operator < (const struct BrokenTest& test) const { return strcmp(test_name_.c_str(), test.test_name_.c_str()) < 0; } diff --git a/onnxruntime/test/optimizer/graph_transform_test.cc b/onnxruntime/test/optimizer/graph_transform_test.cc index afe7b2dabb..6fdb5e4501 100644 --- a/onnxruntime/test/optimizer/graph_transform_test.cc +++ b/onnxruntime/test/optimizer/graph_transform_test.cc @@ -170,8 +170,8 @@ TEST(GraphTransformationTests, ConstantFoldingSubgraph) { GraphProto subgraph; create_subgraph(subgraph); - if_node.AddAttribute("then_branch", {subgraph}); - if_node.AddAttribute("else_branch", {subgraph}); + if_node.AddAttribute("then_branch", subgraph); + if_node.AddAttribute("else_branch", subgraph); auto status = graph.Resolve(); ASSERT_TRUE(status.IsOK()) << status; @@ -614,7 +614,7 @@ TEST(GraphTransformationTests, GeluFusionTest) { Graph& graph = p_model->MainGraph(); onnxruntime::GraphTransformerManager graph_transformation_mgr{5}; - graph_transformation_mgr.Register(std::make_unique(), TransformerLevel::Level2); + graph_transformation_mgr.Register(onnxruntime::make_unique(), TransformerLevel::Level2); auto ret = graph_transformation_mgr.ApplyTransformers(graph, TransformerLevel::Level2); ASSERT_TRUE(ret.IsOK()); diff --git a/onnxruntime/test/providers/cpu/controlflow/if_test.cc b/onnxruntime/test/providers/cpu/controlflow/if_test.cc index a3193c57a3..408e2fa855 100644 --- a/onnxruntime/test/providers/cpu/controlflow/if_test.cc +++ b/onnxruntime/test/providers/cpu/controlflow/if_test.cc @@ -97,8 +97,8 @@ class IfOpTester : public OpTester { auto then_proto = CreateSubgraph(true, options_); auto else_proto = CreateSubgraph(false, options_); - if_node.AddAttribute("then_branch", {then_proto}); - if_node.AddAttribute("else_branch", {else_proto}); + if_node.AddAttribute("then_branch", then_proto); + if_node.AddAttribute("else_branch", else_proto); } // add Identity node so if_graph_input_0 comes from graph inputs diff --git a/onnxruntime/test/providers/cpu/controlflow/loop_test.cc b/onnxruntime/test/providers/cpu/controlflow/loop_test.cc index d30116f83c..bede6451fe 100644 --- a/onnxruntime/test/providers/cpu/controlflow/loop_test.cc +++ b/onnxruntime/test/providers/cpu/controlflow/loop_test.cc @@ -75,7 +75,7 @@ class LoopOpTester : public OpTester { auto& loop_node = graph.AddNode("loop", "Loop", "Loop node", graph_input_defs, graph_output_defs); auto body = create_subgraph_(options_); - loop_node.AddAttribute("body", {body}); + loop_node.AddAttribute("body", body); } } diff --git a/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc b/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc index 3d66b1205a..0a2b105ec2 100644 --- a/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc +++ b/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc @@ -33,11 +33,11 @@ TEST(MathOpTest, Add_float) { test.AddInput("A", dims, {1.0f, 2.0f, -1.0f, 0.0f, 1.5f, -100.0f, - -5.4f, 9.3f, -10'000.0f}); + -5.4f, 9.3f, -10000.0f}); test.AddInput("B", dims, {-1.0f, 4.4f, 432.3f, 0.0f, 3.5f, 64.0f, - -5.4f, 9.3f, 10'000.0f}); + -5.4f, 9.3f, 10000.0f}); test.AddOutput("C", dims, {0.0f, 6.4f, 431.3f, 0.0f, 5.0f, -36.0f, @@ -56,11 +56,11 @@ TEST(MathOpTest, Add_double) { test.AddInput("A", dims, {1.0, 2.0, -1.0, 0.0, 1.5, -100.0, - -5.4, 9.3, -10'000.0}); + -5.4, 9.3, -10000.0}); test.AddInput("B", dims, {-1.0, 4.4, 432.3, 0.0, 3.5, 64.0, - -5.4, 9.3, 10'000.0}); + -5.4, 9.3, 10000.0}); test.AddOutput("C", dims, {0.0, 6.4, 431.3, 0.0, 5.0, -36.0, @@ -287,15 +287,15 @@ TEST(MathOpTest, Sub) { test.AddInput("A", dims, {1.0f, 2.0f, -1.0f, 0.0f, 1.5f, -100.0f, - -5.4f, 9.3f, -10'000.0f}); + -5.4f, 9.3f, -10000.0f}); test.AddInput("B", dims, {-1.0f, 4.4f, 432.3f, 0.0f, 3.5f, 64.0f, - -5.4f, 9.3f, 10'000.0f}); + -5.4f, 9.3f, 10000.0f}); test.AddOutput("C", dims, {2.0f, -2.4f, -433.3f, 0.0f, -2.0f, -164.0f, - 0.0f, 0.0f, -20'000.0f}); + 0.0f, 0.0f, -20000.0f}); test.Run(); } @@ -305,12 +305,12 @@ TEST(MathOpTest, Sub_Broadcast_Scalar) { test.AddInput("A", dims, {1.0f, 2.0f, -1.0f, 0.0f, 1.5f, -100.0f, - -5.4f, 9.3f, -10'000.0f}); + -5.4f, 9.3f, -10000.0f}); test.AddInput("B", {}, {5.0f}); test.AddOutput("C", dims, {-4.0f, -3.0f, -6.0f, -5.0f, -3.5f, -105.0f, - -10.4f, 4.3f, -10'005.0f}); + -10.4f, 4.3f, -10005.0f}); test.Run(); } @@ -336,15 +336,15 @@ TEST(MathOpTest, Mul) { test.AddInput("A", dims, {1.0f, 2.0f, -1.0f, 0.0f, 1.5f, -100.0f, -5.4f, - 9.30f, -10'000.0f}); + 9.30f, -10000.0f}); test.AddInput("B", dims, {-1.0f, 4.4f, 432.3f, 0.0f, 3.5f, 64.0f, -5.4f, - 9.30f, 10'000.0f}); + 9.30f, 10000.0f}); test.AddOutput("C", dims, {-1.0f, 8.8f, -432.3f, - 0.0f, 5.25f, -6'400.0f, - 29.16f, 86.49f, -100'000'000.0f}); + 0.0f, 5.25f, -6400.0f, + 29.16f, 86.49f, -100000000.0f}); #if defined(OPENVINO_CONFIG_MYRIAD) || defined(OPENVINO_CONFIG_GPU_FP16) || defined(OPENVINO_CONFIG_VAD_M) test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kOpenVINOExecutionProvider}); //OpenVINO: Disabled due to accuracy issues for MYRIAD FP16 @@ -373,10 +373,10 @@ TEST(MathOpTest, Div) { OpTester test("Div"); std::vector dims{2, 3}; test.AddInput("A", dims, - {1'000.0f, 1.0f, 6.0f, + {1000.0f, 1.0f, 6.0f, 0.0f, -10.0f, -1.0f}); test.AddInput("B", dims, - {1'000.0f, 2.0f, 3.0f, + {1000.0f, 2.0f, 3.0f, 1.0f, -1.0f, 4.0f}); test.AddOutput("C", dims, {1.0f, 0.5f, 2.0f, @@ -596,7 +596,7 @@ TEST(MathOpTest, Sum_6) { test.AddInput("data_0", dims, {1.0f, 0.0f, 1.0f, -1.0f, 1.1f, -100.0f, - -5.4f, 0.01f, -10'000.0f}); + -5.4f, 0.01f, -10000.0f}); test.AddInput("data_1", dims, {1.0f, 0.0f, 2.0f, -2.0f, 2.2f, 64.0f, @@ -604,7 +604,7 @@ TEST(MathOpTest, Sum_6) { test.AddInput("data_3", dims, {1.0f, 0.0f, 3.0f, -3.0f, 3.3f, 64.0f, - 5.4f, 0.03f, 10'000.0f}); + 5.4f, 0.03f, 10000.0f}); test.AddOutput("sum", dims, {3.0f, 0.0f, 6.0f, -6.0f, 6.6f, 28.0f, @@ -684,7 +684,7 @@ TEST(MathOpTest, Min_6) { test.AddInput("data_0", dims, {1.0f, 0.0f, 1.0f, -1.0f, 1.1f, -100.0f, - -5.4f, 0.01f, -10'000.0f}); + -5.4f, 0.01f, -10000.0f}); test.AddInput("data_1", dims, {1.0f, 0.0f, 2.0f, -2.0f, 2.2f, 64.0f, @@ -692,11 +692,11 @@ TEST(MathOpTest, Min_6) { test.AddInput("data_3", dims, {1.0f, 0.0f, 3.0f, -3.0f, 3.3f, 64.0f, - 5.4f, 0.03f, 10'000.0f}); + 5.4f, 0.03f, 10000.0f}); test.AddOutput("sum", dims, {1.0f, 0.0f, 1.0f, -3.0f, 1.1f, -100.0f, - -5.4f, 0.01f, -10'000.0f}); + -5.4f, 0.01f, -10000.0f}); test.Run(); } @@ -706,7 +706,7 @@ TEST(MathOpTest, Min_8) { test.AddInput("data_0", dims, {1.0f, 0.0f, 1.0f, -1.0f, 1.1f, -100.0f, - -5.4f, 0.01f, -10'000.0f}); + -5.4f, 0.01f, -10000.0f}); test.AddInput("data_1", dims, {1.0f, 0.0f, 2.0f, -2.0f, 2.2f, 64.0f, @@ -714,11 +714,11 @@ TEST(MathOpTest, Min_8) { test.AddInput("data_3", dims, {1.0f, 0.0f, 3.0f, -3.0f, 3.3f, 64.0f, - 5.4f, 0.03f, 10'000.0f}); + 5.4f, 0.03f, 10000.0f}); test.AddOutput("min", dims, {1.0f, 0.0f, 1.0f, -3.0f, 1.1f, -100.0f, - -5.4f, 0.01f, -10'000.0f}); + -5.4f, 0.01f, -10000.0f}); test.Run(); } @@ -728,7 +728,7 @@ TEST(MathOpTest, Max_6) { test.AddInput("data_0", dims, {1.0f, 0.0f, 1.0f, -1.0f, 1.1f, -100.0f, - -5.4f, 0.01f, -10'000.0f}); + -5.4f, 0.01f, -10000.0f}); test.AddInput("data_1", dims, {1.0f, 0.0f, 2.0f, -2.0f, 2.2f, 64.0f, @@ -736,11 +736,11 @@ TEST(MathOpTest, Max_6) { test.AddInput("data_2", dims, {1.0f, 0.0f, 3.0f, -3.0f, 3.3f, 64.0f, - 5.4f, 0.03f, 10'000.0f}); + 5.4f, 0.03f, 10000.0f}); test.AddOutput("max", dims, {1.0f, 0.0f, 3.0f, -1.0f, 3.3f, 64.0f, - 5.4f, 0.03f, 10'000.0f}); + 5.4f, 0.03f, 10000.0f}); test.Run(); } diff --git a/onnxruntime/test/providers/cpu/math/sign_test.cc b/onnxruntime/test/providers/cpu/math/sign_test.cc index ea6cd1993a..793fe578d0 100644 --- a/onnxruntime/test/providers/cpu/math/sign_test.cc +++ b/onnxruntime/test/providers/cpu/math/sign_test.cc @@ -50,19 +50,25 @@ GenerateSequence(OutputIter out) { } template -inline auto to_testable_type(T v) { +struct ToTestableType { + static T to_type(T v) { return v; -} + } +}; template <> -inline auto to_testable_type(MLFloat16 v) { - return math::halfToFloat(v.val); -} +struct ToTestableType { + static float to_type(MLFloat16 v) { + return math::halfToFloat(v.val); + } +}; template <> -inline auto to_testable_type(BFloat16 v) { - return v.ToFloat(); -} +struct ToTestableType { + inline float to_type(BFloat16 v) { + return v.ToFloat(); + } +}; template typename std::enable_if::is_signed && @@ -70,7 +76,7 @@ typename std::enable_if::is_signed && !std::is_same::value>::type TestImpl(ForwardIter first, ForwardIter last, OutputIter out) { std::transform(first, last, out, [](T v) { - auto t = to_testable_type(v); + auto t = ToTestableType::to_type(v); if (t == 0) { t = 0; } else { @@ -86,7 +92,7 @@ typename std::enable_if::is_signed || std::is_same::value>::type TestImpl(ForwardIter first, ForwardIter last, OutputIter out) { std::transform(first, last, out, [](T v) { - auto t = to_testable_type(v); + auto t = ToTestableType::to_type(v); if (t == 0) { t = 0; } else if (t > 0) { diff --git a/onnxruntime/test/providers/cpu/ml/array_feature_extractor_test.cc b/onnxruntime/test/providers/cpu/ml/array_feature_extractor_test.cc index 8d8b5b04e0..1cd29abe9e 100644 --- a/onnxruntime/test/providers/cpu/ml/array_feature_extractor_test.cc +++ b/onnxruntime/test/providers/cpu/ml/array_feature_extractor_test.cc @@ -45,7 +45,7 @@ TEST_F(ArrayFeatureExtractorTest, Basic) { TEST_F(ArrayFeatureExtractorTest, HigherDimensionalX) { const std::vector x_dims{2, 3, 4, 5}; const int64_t x_size = std::accumulate( - x_dims.begin(), x_dims.end(), static_cast(1), std::multiplies<>{}); + x_dims.begin(), x_dims.end(), static_cast(1), std::multiplies()); const std::vector X = [x_size]() { std::vector v(x_size); std::iota(v.begin(), v.end(), 0); diff --git a/onnxruntime/test/providers/cpu/nn/string_normalizer_test.cc b/onnxruntime/test/providers/cpu/nn/string_normalizer_test.cc index 3da6533394..6e9f99fc35 100644 --- a/onnxruntime/test/providers/cpu/nn/string_normalizer_test.cc +++ b/onnxruntime/test/providers/cpu/nn/string_normalizer_test.cc @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include #include "gtest/gtest.h" #include "test/providers/provider_test_utils.h" diff --git a/onnxruntime/test/providers/provider_test_utils.h b/onnxruntime/test/providers/provider_test_utils.h index cd881df1d8..2892150673 100644 --- a/onnxruntime/test/providers/provider_test_utils.h +++ b/onnxruntime/test/providers/provider_test_utils.h @@ -109,7 +109,12 @@ struct TTypeProto : ONNX_NAMESPACE::TypeProto { // Variable template for ONNX_NAMESPACE::TensorProto_DataTypes, s_type_proto, etc.. template -const TTypeProto s_type_proto; +struct TTensorType { + static const TTypeProto s_type_proto; +}; + +template +const TTypeProto TTensorType::s_type_proto; //TypeProto for map template @@ -122,7 +127,12 @@ struct MTypeProto : ONNX_NAMESPACE::TypeProto { }; template -const MTypeProto s_map_type_proto; +struct MMapType { + static const MTypeProto s_map_type_proto; +}; + +template +const MTypeProto MMapType::s_map_type_proto; //TypeProto for vector> template @@ -136,7 +146,12 @@ struct VectorOfMapTypeProto : ONNX_NAMESPACE::TypeProto { }; template -const VectorOfMapTypeProto s_vec_map_type_proto; +struct VectorOfMapType { + static const VectorOfMapTypeProto s_vec_map_type_proto; +}; + +template +const VectorOfMapTypeProto VectorOfMapType::s_vec_map_type_proto; // To use OpTester: // 1. Create one with the op name @@ -185,7 +200,7 @@ class OpTester { OrtValue value; value.Init(ptr.get(), mltype, mltype->GetDeleteFunc()); ptr.release(); - input_data_.push_back({{name, mltype->GetTypeProto()}, value, optional(), optional()}); + input_data_.push_back(Data(NodeArg(name, mltype->GetTypeProto()), std::move(value), optional(), optional())); } template @@ -196,10 +211,9 @@ class OpTester { OrtValue value; value.Init(ptr.get(), mltype, mltype->GetDeleteFunc()); ptr.release(); - input_data_.push_back({{name, mltype->GetTypeProto()}, value, optional(), optional()}); + input_data_.push_back(Data(NodeArg(name, mltype->GetTypeProto()), std::move(value), optional(), optional())); } - template void AddInput(const char* name, const std::map& val) { std::unique_ptr> ptr = onnxruntime::make_unique>(val); @@ -207,13 +221,13 @@ class OpTester { value.Init(ptr.release(), DataTypeImpl::GetType>(), DataTypeImpl::GetType>()->GetDeleteFunc()); - input_data_.push_back({{name, &s_map_type_proto}, value, optional(), optional()}); + input_data_.push_back(Data(NodeArg(name, &MMapType::s_map_type_proto), std::move(value), optional(), optional())); } template void AddMissingOptionalInput() { std::string name; // empty == input doesn't exist - input_data_.push_back({{name, &s_type_proto}, {}, optional(), optional()}); + input_data_.push_back(Data(NodeArg(name, &TTensorType::s_type_proto), OrtValue(), optional(), optional())); } template @@ -229,7 +243,7 @@ class OpTester { template void AddMissingOptionalOutput() { std::string name; // empty == input doesn't exist - output_data_.push_back({{name, &s_type_proto}, {}, optional(), optional()}); + output_data_.push_back(Data(NodeArg(name, &TTensorType::s_type_proto), OrtValue(), optional(), optional())); } // Add other registered types, possibly experimental @@ -241,7 +255,7 @@ class OpTester { OrtValue value; value.Init(ptr.get(), mltype, mltype->GetDeleteFunc()); ptr.release(); - output_data_.push_back({{name, mltype->GetTypeProto()}, value, optional(), optional()}); + output_data_.push_back(Data(NodeArg(name, mltype->GetTypeProto()), std::move(value), optional(), optional())); } template @@ -252,7 +266,7 @@ class OpTester { OrtValue value; value.Init(ptr.get(), mltype, mltype->GetDeleteFunc()); ptr.release(); - output_data_.push_back({{name, mltype->GetTypeProto()}, value, optional(), optional()}); + output_data_.push_back(Data(NodeArg(name, mltype->GetTypeProto()), std::move(value), optional(), optional())); } // Add non tensor output @@ -263,7 +277,7 @@ class OpTester { ml_value.Init(ptr.release(), DataTypeImpl::GetType>>(), DataTypeImpl::GetType>>()->GetDeleteFunc()); - output_data_.push_back({{name, &s_vec_map_type_proto}, ml_value, optional(), optional()}); + output_data_.push_back(Data(NodeArg(name, &VectorOfMapType::s_vec_map_type_proto), std::move(ml_value), optional(), optional())); } void AddCustomOpRegistry(std::shared_ptr registry) { @@ -304,6 +318,10 @@ class OpTester { OrtValue data_; optional relative_error_; optional absolute_error_; + Data(onnxruntime::NodeArg&& def, OrtValue&& data, optional&& rel, optional&& abs) : + def_(std::move(def)), data_(std::move(data)), relative_error_(std::move(rel)), absolute_error_(abs) {} + Data(Data&&) = default; + Data& operator=(Data&&) = default; }; protected: @@ -337,8 +355,8 @@ class OpTester { auto allocator = test::AllocatorManager::Instance().GetAllocator(CPU); auto p_tensor = onnxruntime::make_unique(DataTypeImpl::GetType(), - shape, - allocator); + shape, + allocator); auto* data_ptr = p_tensor->template MutableData(); for (int64_t i = 0; i < values_count; i++) { @@ -354,7 +372,7 @@ class OpTester { TTypeProto type_proto(add_shape_to_tensor_data_ ? &dims_for_proto : nullptr); OrtValue value; value.Init(p_tensor.release(), DataTypeImpl::GetType(), DataTypeImpl::GetType()->GetDeleteFunc()); - data.push_back({{name, &type_proto}, value, optional(), optional()}); + data.push_back(Data(NodeArg(name, &type_proto), std::move(value), optional(), optional())); if (is_initializer) initializer_index_.push_back(data.size() - 1); } catch (const std::exception& ex) {