[code-reflection] Integrated: Split OnnxRuntime into high-level and low-level generated code
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Feb 24 19:36:21 UTC 2025
On Thu, 20 Feb 2025 13:03:41 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> This PR reorganizes the code in the OnnxRuntime class. It now contains an higher-level implementation of the onnx C API, which is separate from the low-level bindings. These bindings are defined in the new `foreign` package, and have been mechanically generated with a tweaked version of `jextract` which:
> * omits some of the code that is not required (e.g. struct getters/setters)
> * make the generated code more usable for onnx use case -- meaning each struct field should have an "invoker" accessor, which fetches the struct pointer and then invokes it
>
> The generated code is still quite big (OrtApi struct contains 10K LoC). I can make the bindings smaller if we only want to focus on the handful of functions we use today -- but in its current form, the low-level bindings are "complete" and support the full C API.
>
> The main changes in OnnxRuntime are as follows:
> * calls to function pointers in OrtApi/OrtApiBase now are handled as calls to static wrappers generated by jextract.
> * there's no need to try/catch and wrap exceptions because the generated code does that
> * some of the explicit reinterpret calls with an explicit size have been replaced by generated `reinterpret` methods (which use the correct struct layout size)
> * some of the constants (logging level, API version) are now taken from the generated code
>
> When doing this exercise, I uncovered an issue with the MHs for a couple of functions (`ReleaseEnv` and `ReleaseSession`) being incorrect -- the underlying function pointers for these are void (so no result) and they don't accept a trailing `ret` segment. Also calling `checkStatus` on them makes no sense (again, because these functions don't return a status).
This pull request has now been integrated.
Changeset: 4752b37c
Author: Maurizio Cimadamore <mcimadamore at openjdk.org>
URL: https://git.openjdk.org/babylon/commit/4752b37cb924f18dfe0c8d4b7e5553a06eac44dd
Stats: 14414 lines in 4 files changed: 14189 ins; 158 del; 67 mod
Split OnnxRuntime into high-level and low-level generated code
-------------
PR: https://git.openjdk.org/babylon/pull/323
More information about the babylon-dev
mailing list