diff --git a/onnxruntime/core/graph/function.cc b/onnxruntime/core/graph/function.cc index 1f5cc3d2ce..93a360d1f3 100644 --- a/onnxruntime/core/graph/function.cc +++ b/onnxruntime/core/graph/function.cc @@ -225,7 +225,7 @@ FunctionImpl::FunctionImpl(const onnxruntime::Graph& graph, // Add node and node args into subgraph // The subgraph preserved the input/output tensor names // in the parent graph for later inlining purpose - auto attr_map = node_in_parent_graph->GetAttributes(); + const auto& attr_map = node_in_parent_graph->GetAttributes(); for (auto& node : onnx_func_proto_->node()) { std::vector inputs; std::vector outputs; @@ -274,8 +274,9 @@ FunctionImpl::FunctionImpl(const onnxruntime::Graph& graph, onnxruntime::NodeAttributes new_attr_map; for (auto& attr : node.attribute()) { if (attr.has_ref_attr_name()) { - if (attr_map.count(attr.ref_attr_name())) { - new_attr_map[attr.name()] = attr_map[attr.ref_attr_name()]; + auto entry = attr_map.find(attr.ref_attr_name()); + if (entry != attr_map.cend()) { + new_attr_map[attr.name()] = entry->second; } } else { new_attr_map[attr.name()] = attr; diff --git a/onnxruntime/core/graph/graph.cc b/onnxruntime/core/graph/graph.cc index e26f91117c..8e415416dd 100644 --- a/onnxruntime/core/graph/graph.cc +++ b/onnxruntime/core/graph/graph.cc @@ -1723,7 +1723,7 @@ Status Graph::VerifyNodeAndOpMatch() { // Attribute verification and fill node attribute with // default value defined in operator definition if needed. // Fill node attribute with default value specified in operator definition if any. - auto node_attributes = node.GetAttributes(); + const auto& node_attributes = node.GetAttributes(); for (const auto& attr_def : p_op->attributes()) { auto node_attr_iter = node_attributes.find(attr_def.first); if (node_attributes.end() == node_attr_iter) { diff --git a/onnxruntime/core/providers/cuda/cuda_execution_provider.cc b/onnxruntime/core/providers/cuda/cuda_execution_provider.cc index 2971b30e6d..b5e7d7efb8 100644 --- a/onnxruntime/core/providers/cuda/cuda_execution_provider.cc +++ b/onnxruntime/core/providers/cuda/cuda_execution_provider.cc @@ -820,7 +820,7 @@ static void RegisterCudaKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, - BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, @@ -875,7 +875,7 @@ std::shared_ptr CUDAExecutionProvider::GetKernelRegistry() const static bool RNNNeedFallbackToCPU(const onnxruntime::Node& node, const std::vector activations_supported, const std::string& op_type) { - auto node_attributes = node.GetAttributes(); + const auto& node_attributes = node.GetAttributes(); // Check attributes for (auto& attr : node_attributes) { auto attr_name = attr.first; @@ -929,7 +929,7 @@ static bool RNNNeedFallbackToCPU(const onnxruntime::Node& node, } static bool ConvNeedFallbackToCPU(const onnxruntime::Node& node) { - auto node_attributes = node.GetAttributes(); + const auto& node_attributes = node.GetAttributes(); // Check attributes for (auto& attr : node_attributes) { auto attr_name = attr.first; @@ -953,7 +953,7 @@ static bool ConvNeedFallbackToCPU(const onnxruntime::Node& node) { } static bool CastNeedFallbackToCPU(const onnxruntime::Node& node) { - auto node_attributes = node.GetAttributes(); + const auto& node_attributes = node.GetAttributes(); // Check attributes for (auto& attr : node_attributes) { auto attr_name = attr.first;