-
I'm looking at using ONNX from Rust using some community-developed bindings. One of the things that Rust offers is compile-time type checking around thread safety. The author of these bindings has been extremely conservative in how they've exposed ONNX to Rust with respect to thread safety; In practice this makes using ONNX fairly restrictive in Rust, but I wasn't sure how the original author of the bindings had arrived at this position; whether it was a pre-emptive decision to try and head off any concurrency issues, or possibly they just used the default provided (Rust will assume C pointers are not thread safe in any respect by default and have to explicitly be marked otherwise). My hope is that with more information I can modify these bindings to be less restrictive and make working with ONNX a lot easier. So my question is whether there's any definitive documentation around thread safety in ONNX? Can I've seen this mentioned explicitly a few times:
And the other methods of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In the Java API (which uses the C API) we have a singleton environment shared between all threads, and sessions themselves are thread safe after construction. We test the thread safety of |
Beta Was this translation helpful? Give feedback.
In the Java API (which uses the C API) we have a singleton environment shared between all threads, and sessions themselves are thread safe after construction. We test the thread safety of
Session.Run
in our unit tests - https://github.com/microsoft/onnxruntime/blob/master/java/src/test/java/ai/onnxruntime/InferenceTest.java#L614. I'm not sure how this interacts with some of the more complicated bits of the API around custom allocators, but we haven't exposed those in Java yet.