mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-23 22:13:38 +00:00
* Fix up constness in pybindings Fix up return argument treatments. Specifically, for all functions that return pointers or references to the members of other pybind registered classes, we want not to copy them, but internally bump up a reference to the hosting class so they do not disappear before the reference to the returned members is re-claimed. This policy is applied by default to def_property and def_readwrite but not to def_readonly and other def methods. See https://pybind11-jagerman.readthedocs.io/en/stable/advanced.html#return-value-policies https://pybind11.readthedocs.io/en/stable/advanced/functions.html#return-value-policies Move OrtValue binding to a separate file Move IOBinding into separate file.
71 lines
No EOL
2.6 KiB
C++
71 lines
No EOL
2.6 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "onnxruntime_pybind_exceptions.h"
|
|
|
|
namespace onnxruntime {
|
|
namespace python {
|
|
namespace py = pybind11;
|
|
|
|
void ThrowIfPyErrOccured() {
|
|
if (PyErr_Occurred()) {
|
|
PyObject *ptype, *pvalue, *ptraceback;
|
|
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
|
|
|
|
PyObject* pStr = PyObject_Str(ptype);
|
|
std::string sType = py::reinterpret_borrow<py::str>(pStr);
|
|
Py_XDECREF(pStr);
|
|
pStr = PyObject_Str(pvalue);
|
|
sType += ": ";
|
|
sType += py::reinterpret_borrow<py::str>(pStr);
|
|
Py_XDECREF(pStr);
|
|
throw Fail(sType);
|
|
}
|
|
}
|
|
|
|
void RegisterExceptions(pybind11::module& m) {
|
|
pybind11::register_exception<Fail>(m, "Fail");
|
|
pybind11::register_exception<InvalidArgument>(m, "InvalidArgument");
|
|
pybind11::register_exception<NoSuchFile>(m, "NoSuchFile");
|
|
pybind11::register_exception<NoModel>(m, "NoModel");
|
|
pybind11::register_exception<EngineError>(m, "EngineError");
|
|
pybind11::register_exception<RuntimeException>(m, "RuntimeException");
|
|
pybind11::register_exception<InvalidProtobuf>(m, "InvalidProtobuf");
|
|
pybind11::register_exception<ModelLoaded>(m, "ModelLoaded");
|
|
pybind11::register_exception<NotImplemented>(m, "NotImplemented");
|
|
pybind11::register_exception<InvalidGraph>(m, "InvalidGraph");
|
|
pybind11::register_exception<EPFail>(m, "EPFail");
|
|
}
|
|
|
|
void OrtPybindThrowIfError(onnxruntime::common::Status status) {
|
|
std::string msg = status.ToString();
|
|
if (!status.IsOK()) {
|
|
switch (status.Code()) {
|
|
case onnxruntime::common::StatusCode::FAIL:
|
|
throw Fail(std::move(msg));
|
|
case onnxruntime::common::StatusCode::INVALID_ARGUMENT:
|
|
throw InvalidArgument(std::move(msg));
|
|
case onnxruntime::common::StatusCode::NO_SUCHFILE:
|
|
throw NoSuchFile(std::move(msg));
|
|
case onnxruntime::common::StatusCode::NO_MODEL:
|
|
throw NoModel(std::move(msg));
|
|
case onnxruntime::common::StatusCode::ENGINE_ERROR:
|
|
throw EngineError(std::move(msg));
|
|
case onnxruntime::common::StatusCode::RUNTIME_EXCEPTION:
|
|
throw RuntimeException(std::move(msg));
|
|
case onnxruntime::common::StatusCode::INVALID_PROTOBUF:
|
|
throw InvalidProtobuf(std::move(msg));
|
|
case onnxruntime::common::StatusCode::NOT_IMPLEMENTED:
|
|
throw NotImplemented(std::move(msg));
|
|
case onnxruntime::common::StatusCode::INVALID_GRAPH:
|
|
throw InvalidGraph(std::move(msg));
|
|
case onnxruntime::common::StatusCode::EP_FAIL:
|
|
throw EPFail(std::move(msg));
|
|
default:
|
|
throw std::runtime_error(std::move(msg));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |