diff --git a/onnxruntime/core/framework/kernel_registry_manager.cc b/onnxruntime/core/framework/kernel_registry_manager.cc index 5fe803b368..203bc7c21e 100644 --- a/onnxruntime/core/framework/kernel_registry_manager.cc +++ b/onnxruntime/core/framework/kernel_registry_manager.cc @@ -14,11 +14,21 @@ Status KernelRegistryManager::CreateKernel(const onnxruntime::Node& node, const IExecutionProvider& execution_provider, const SessionState& session_state, /*out*/ std::unique_ptr& op_kernel) const { + auto create_error_message = [&node](const std::string& error) { + std::ostringstream errormsg; + errormsg << error << node.OpType(); + if (node.Op() != nullptr) errormsg << "(" << node.Op()->since_version() << ")"; + if (!node.Name().empty()) errormsg << " (node " << node.Name() << ")"; + return errormsg.str(); + }; + const std::string& ptype = node.GetExecutionProviderType(); if (ptype.empty()) { return Status(ONNXRUNTIME, FAIL, - "The node is not placed on any Execution Provider, therefore, can't find a suitable kernel for it"); + create_error_message("The node is not placed on any Execution Provider, " + "therefore, can't find a suitable kernel for ")); } + Status status; { for (auto& registry : custom_kernel_registries_) { @@ -41,11 +51,7 @@ Status KernelRegistryManager::CreateKernel(const onnxruntime::Node& node, } } - std::ostringstream errormsg; - errormsg << "Failed to find kernel for " << node.OpType(); - if (node.Op() != nullptr) errormsg << "(" << node.Op()->since_version() << ")"; - if (!node.Name().empty()) errormsg << " (node " << node.Name() << ")"; - return Status(ONNXRUNTIME, FAIL, errormsg.str()); + return Status(ONNXRUNTIME, FAIL, create_error_message("Failed to find kernel for ")); } Status KernelRegistryManager::RegisterKernels(const ExecutionProviders& execution_providers) {