mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-24 19:43:35 +00:00
Change Compute function to return a status code instead of an integer. (#1139)
This commit is contained in:
parent
c18de6817b
commit
148141dd5f
6 changed files with 22 additions and 28 deletions
|
|
@ -28,7 +28,7 @@ typedef std::map<int, AllocatorPtr> 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<int(ComputeContext*, FunctionState*)>;
|
||||
using ComputeFunc = std::function<int(FunctionState, const OrtCustomOpApi*, OrtKernelContext*)>;
|
||||
using ComputeFunc = std::function<Status(FunctionState, const OrtCustomOpApi*, OrtKernelContext*)>;
|
||||
using DestroyFunctionStateFunc = std::function<void(FunctionState)>;
|
||||
|
||||
struct NodeComputeInfo {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,10 +40,7 @@ class FunctionKernel : public OpKernel {
|
|||
|
||||
virtual Status Compute(OpKernelContext* context) const override {
|
||||
auto* context_internal = static_cast<OpKernelContextInternal*>(context);
|
||||
int ret = func_(func_state_, &GetCustomOpApi(), reinterpret_cast<OrtKernelContext*>(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<OrtKernelContext*>(context_internal));
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -547,10 +547,7 @@ Status NGRAPHExecutionProvider::Compile(const std::vector<onnxruntime::Node*>& f
|
|||
|
||||
compute_info.compute_func = [](FunctionState state, const OrtCustomOpApi* api, OrtKernelContext* context) {
|
||||
onnxruntime::ngraph_ep::NGRAPHCustomOp* ng_custom_op = reinterpret_cast<onnxruntime::ngraph_ep::NGRAPHCustomOp*>(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);
|
||||
|
|
|
|||
|
|
@ -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<IndexedSubGraph> TensorrtExecutionProvider::GetSubGraph(SubGraph
|
|||
std::unique_ptr<IndexedSubGraph> sub_graph = std::make_unique<IndexedSubGraph>();
|
||||
|
||||
// Find inputs and outputs of the subgraph
|
||||
std::unordered_map<const NodeArg *, int> fused_inputs, fused_outputs, fused_outputs_to_add;
|
||||
std::unordered_map<const NodeArg*, int> fused_inputs, fused_outputs, fused_outputs_to_add;
|
||||
std::unordered_set<const NodeArg*> erased;
|
||||
int input_order = 0;
|
||||
int output_order = 0;
|
||||
|
|
@ -114,7 +114,7 @@ std::unique_ptr<IndexedSubGraph> 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<int, const NodeArg *> inputs, outputs;
|
||||
std::multimap<int, const NodeArg*> inputs, outputs;
|
||||
for (auto it = fused_inputs.begin(), end = fused_inputs.end(); it != end; ++it) {
|
||||
inputs.insert(std::pair<int, const NodeArg*>(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<onnxruntime::NodeArg *> inputs, outputs;
|
||||
std::vector<onnxruntime::NodeArg*> 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<onnxruntime::NodeArg *> inputs, outputs;
|
||||
std::vector<onnxruntime::NodeArg*> 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<onnxruntime:
|
|||
CHECK_CUDA(cudaMalloc(&buffers[i], input_size * sizeof(int32_t)));
|
||||
CHECK_CUDA(cudaMemcpy(buffers[i], input, input_size * sizeof(int32_t), cudaMemcpyHostToDevice));
|
||||
} else {
|
||||
return static_cast<int>(common::StatusCode::NOT_IMPLEMENTED);
|
||||
return common::Status(common::ONNXRUNTIME, common::NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -498,7 +498,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector<onnxruntime:
|
|||
} else if (output_types[i] == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32 || output_types[i] == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64) {
|
||||
CHECK_CUDA(cudaMalloc(&buffers[i + num_binding_inputs], batch_size * output_dim_sizes[i] * sizeof(int32_t)));
|
||||
} else {
|
||||
return static_cast<int>(common::StatusCode::NOT_IMPLEMENTED);
|
||||
return common::Status(common::ONNXRUNTIME, common::NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -528,7 +528,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector<onnxruntime:
|
|||
}
|
||||
delete[] output;
|
||||
} else {
|
||||
return static_cast<int>(common::StatusCode::NOT_IMPLEMENTED);
|
||||
return common::Status(common::ONNXRUNTIME, common::NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -542,7 +542,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector<onnxruntime:
|
|||
CHECK_CUDA(cudaFree(buffers[i]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
return Status::OK();
|
||||
};
|
||||
|
||||
node_compute_funcs.push_back(compute_info);
|
||||
|
|
|
|||
|
|
@ -270,12 +270,12 @@ class FuseExecutionProviderX : public CPUExecutionProvider {
|
|||
try {
|
||||
evaluate_func_.CallPacked(tvm_args, &rvalue);
|
||||
} catch (std::exception ex) {
|
||||
return -1;
|
||||
return Status(common::ONNXRUNTIME, common::FAIL); // TODO: Translate exception to error code
|
||||
}
|
||||
if (rvalue.type_code() != kNull) {
|
||||
return -1; // TODO: get error code.
|
||||
return Status(common::ONNXRUNTIME, common::FAIL); // TODO: get error code.
|
||||
} else {
|
||||
return 0;
|
||||
return Status::OK();
|
||||
}
|
||||
};
|
||||
node_compute_funcs.push_back(compute_info);
|
||||
|
|
|
|||
Loading…
Reference in a new issue