[code-reflection] RFR: Model lifetimes of onnx session-related objects more explicitly

Adam Sotona asotona at openjdk.org
Sun Mar 2 14:58:05 UTC 2025


On Fri, 28 Feb 2025 22:21:30 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> I think you are on to something here. I am wondering if we can refame it like this:
> 
> ```
> try (OnnxRuntime or = OnnxRuntime.of(MethodHandles.lookup(), Area.ofConfined()) {
>   or.execute(() -> cnn(imageTensor))
> }
> ```
> 
> ?
> 
> I realize there can be only one runtime instance of a native ONNX runtime but i don't think we should be beholden to that constraint regarding the scoping of executing one or more models and with tensor memory under same lookup and arena (and even execution mode). Maybe there is a better name than `OnnxRuntime` to avoid any confusion.

We can do that, however it requires to involve the same (and for sure the only one) runtime instance to create all tensors (including the imageTensor in the fragment above). The runtime must be the only one, however tensors can be created anywhere and many models/sessions executed also.

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

PR Comment: https://git.openjdk.org/babylon/pull/332#issuecomment-2692768714


More information about the babylon-dev mailing list