From 148141dd5fc0651da6ed8f7522d8ee57a48cde5f Mon Sep 17 00:00:00 2001 From: Ryan Hill <38674843+RyanUnderhill@users.noreply.github.com> Date: Tue, 4 Jun 2019 08:34:32 -0700 Subject: [PATCH] Change Compute function to return a status code instead of an integer. (#1139) --- .../core/framework/execution_provider.h | 2 +- include/onnxruntime/core/framework/func_api.h | 4 +-- onnxruntime/core/framework/func_kernel.h | 5 +--- .../ngraph/ngraph_execution_provider.cc | 5 +--- .../tensorrt/tensorrt_execution_provider.cc | 28 +++++++++---------- onnxruntime/test/tvm/tvm_basic_test.cc | 6 ++-- 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/include/onnxruntime/core/framework/execution_provider.h b/include/onnxruntime/core/framework/execution_provider.h index be4f604f8b..d03b461c01 100644 --- a/include/onnxruntime/core/framework/execution_provider.h +++ b/include/onnxruntime/core/framework/execution_provider.h @@ -28,7 +28,7 @@ typedef std::map AllocatorMap; // if we are export the fused function to dll, the function will still in the same binary as lotus // use std function to give execution provider some chance to capture some state. using CreateFunctionStateFunc = std::function; -using ComputeFunc = std::function; +using ComputeFunc = std::function; using DestroyFunctionStateFunc = std::function; struct NodeComputeInfo { diff --git a/include/onnxruntime/core/framework/func_api.h b/include/onnxruntime/core/framework/func_api.h index cf1ba25d0b..d1f9576916 100644 --- a/include/onnxruntime/core/framework/func_api.h +++ b/include/onnxruntime/core/framework/func_api.h @@ -19,8 +19,8 @@ typedef struct { using FunctionState = void*; // take the ComputeContext, and create a function state. using CreateFunctionStateC = int (*)(ComputeContext*, FunctionState*); -// pass in the function state and input/output tensors, perform compute and return status code, 0 - succeed. -using ComputeFuncC = int (*)(FunctionState, const OrtCustomOpApi*, OrtKernelContext*); +// pass in the function state and input/output tensors, perform compute and return status +using ComputeFuncC = Status (*)(FunctionState, const OrtCustomOpApi*, OrtKernelContext*); // release the function state. using DestroyFunctionStateC = void (*)(FunctionState); } // namespace onnxruntime diff --git a/onnxruntime/core/framework/func_kernel.h b/onnxruntime/core/framework/func_kernel.h index c2401fcd33..eb26df464b 100644 --- a/onnxruntime/core/framework/func_kernel.h +++ b/onnxruntime/core/framework/func_kernel.h @@ -40,10 +40,7 @@ class FunctionKernel : public OpKernel { virtual Status Compute(OpKernelContext* context) const override { auto* context_internal = static_cast(context); - int ret = func_(func_state_, &GetCustomOpApi(), reinterpret_cast(context_internal)); - if (ret != 0) - return Status(common::ONNXRUNTIME, common::FAIL, "FuncKernel call failed with error code: " + std::to_string(ret)); - return Status::OK(); + return func_(func_state_, &GetCustomOpApi(), reinterpret_cast(context_internal)); } private: diff --git a/onnxruntime/core/providers/ngraph/ngraph_execution_provider.cc b/onnxruntime/core/providers/ngraph/ngraph_execution_provider.cc index 94532c81c7..356df912ba 100644 --- a/onnxruntime/core/providers/ngraph/ngraph_execution_provider.cc +++ b/onnxruntime/core/providers/ngraph/ngraph_execution_provider.cc @@ -547,10 +547,7 @@ Status NGRAPHExecutionProvider::Compile(const std::vector& f compute_info.compute_func = [](FunctionState state, const OrtCustomOpApi* api, OrtKernelContext* context) { onnxruntime::ngraph_ep::NGRAPHCustomOp* ng_custom_op = reinterpret_cast(state); - - const Status compute_status = ng_custom_op->Compute(api, context); - - return compute_status == Status::OK() ? 0 : 1; + return ng_custom_op->Compute(api, context); }; node_compute_funcs.push_back(compute_info); diff --git a/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc b/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc index 2e44d50c4d..2d0cab8216 100644 --- a/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc +++ b/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc @@ -23,12 +23,12 @@ using namespace ::onnxruntime::logging; namespace onnxruntime { -#define CHECK_CUDA(call) \ - do { \ - cudaError_t status = call; \ - if (status != cudaSuccess) { \ - return -1; \ - } \ +#define CHECK_CUDA(call) \ + do { \ + cudaError_t status = call; \ + if (status != cudaSuccess) { \ + return common::Status(common::ONNXRUNTIME, common::FAIL); \ + } \ } while (0) TensorrtExecutionProvider::TensorrtExecutionProvider() @@ -57,7 +57,7 @@ std::unique_ptr TensorrtExecutionProvider::GetSubGraph(SubGraph std::unique_ptr sub_graph = std::make_unique(); // Find inputs and outputs of the subgraph - std::unordered_map fused_inputs, fused_outputs, fused_outputs_to_add; + std::unordered_map fused_inputs, fused_outputs, fused_outputs_to_add; std::unordered_set erased; int input_order = 0; int output_order = 0; @@ -114,7 +114,7 @@ std::unique_ptr TensorrtExecutionProvider::GetSubGraph(SubGraph fused_outputs.insert(fused_outputs_to_add.begin(), fused_outputs_to_add.end()); // Sort inputs and outputs by the order they were added - std::multimap inputs, outputs; + std::multimap inputs, outputs; for (auto it = fused_inputs.begin(), end = fused_inputs.end(); it != end; ++it) { inputs.insert(std::pair(it->second, it->first)); } @@ -168,7 +168,7 @@ SubGraphCollection_t TensorrtExecutionProvider::GetSupportedList(SubGraphCollect //Add node and node args for (const auto& index : group.first) { const auto& node = graph.GetNode(node_index[index]); - std::vector inputs, outputs; + std::vector inputs, outputs; for (auto input : node->InputDefs()) { auto& n_input = graph_build.GetOrCreateNodeArg(input->Name(), input->TypeAsProto()); inputs.push_back(&n_input); @@ -223,7 +223,7 @@ TensorrtExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph, onnxruntime::Model model(graph.Name(), true, ModelMetaData(), IOnnxRuntimeOpSchemaRegistryList(), graph.DomainToVersionMap()); onnxruntime::Graph& graph_build = model.MainGraph(); for (const auto& node : graph.Nodes()) { - std::vector inputs, outputs; + std::vector inputs, outputs; for (auto input : node.InputDefs()) { auto& n_input = graph_build.GetOrCreateNodeArg(input->Name(), input->TypeAsProto()); inputs.push_back(&n_input); @@ -485,7 +485,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector(common::StatusCode::NOT_IMPLEMENTED); + return common::Status(common::ONNXRUNTIME, common::NOT_IMPLEMENTED); } } @@ -498,7 +498,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector(common::StatusCode::NOT_IMPLEMENTED); + return common::Status(common::ONNXRUNTIME, common::NOT_IMPLEMENTED); } } @@ -528,7 +528,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector(common::StatusCode::NOT_IMPLEMENTED); + return common::Status(common::ONNXRUNTIME, common::NOT_IMPLEMENTED); } } @@ -542,7 +542,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector