[code-reflection] RFR: ONNX FFM Runtime initial work [v3]

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Feb 10 14:40:25 UTC 2025


On Sun, 9 Feb 2025 14:31:14 GMT, Adam Sotona <asotona at openjdk.org> wrote:

>> This is initial work on ONNX FFM runtime with very raw connection with OnnxInterpreter and Tensor.
>> 
>> It is a rebase of https://github.com/PaulSandoz/babylon/pull/1
>
> Adam Sotona has updated the pull request incrementally with one additional commit since the last revision:
> 
>   minor rename

Did a quick experiment with jextract. I can write code like this:


        var apiBase = OrtGetApiBase();
        System.out.println(apiBase);
        var version = OrtApiBase.GetVersionString.invoke(OrtApiBase.GetVersionString(apiBase));
        System.out.println(version.getString(0));
        var api = OrtApiBase.GetApi.invoke(OrtApiBase.GetApi(apiBase), 1);
        System.out.println(api); // prints 1.20.1
        MemorySegment buf = Arena.ofAuto().allocate(ValueLayout.ADDRESS);
        var res = OrtApi.CreateSessionOptions.invoke(OrtApi.CreateSessionOptions(api), buf);
        var sessionOptions = buf.get(ValueLayout.ADDRESS, 0);
        System.out.println(sessionOptions);


While not super-compact (due to the way the API is defined, via function pointers stored in structs), this is fairly mechanical, and should provide a good foundation for your `Environment` API.

I note something that jextract could deal with slightly better - when invoking a function pointer on a struct, the `invoke` method takes the function pointer address (as that form is more primitive) - but in this case it would be handy if the method took a pointer to the base struct, so that this code:


        var version = OrtApiBase.GetVersionString.invoke(OrtApiBase.GetVersionString(apiBase));


Could become just:


        var version = OrtApiBase.GetVersionString.invoke(apiBase);


(after all jextract knows where that function pointer is, given a pointer to the base struct).

-------------

PR Comment: https://git.openjdk.org/babylon/pull/311#issuecomment-2648192400


More information about the babylon-dev mailing list