onnxruntime/java/src
Adam Pocock cfa45df6b5
[java] Migrate OnnxTensors created from arrays over to a backing Java buffer (#18556)
### Description
Following from #16578 and #16835 this migrates over
`OnnxTensor.createTensor(<array>)` to first instantiate a
`java.nio.Buffer` and then copy the array into that buffer in Java
before creating the tensor. It also changes the `OnnxTensor.getValue()`
method which returns a multidimensional array so it does the array
construction and value copy in Java. This allows the removal of some
unpleasant recursive C code which repeatedly calls into the JVM to
traverse Java's arrays. The equivalent Java code is still unpleasant and
recursive, but it's easier to reason about and memory safe. As a bonus,
more `OnnxTensor`s are now backed by buffers which allow users to pin
memory and reduce allocations by reusing them for same sized inputs.

Some of the JNI code which parses Java arrays still exists as it's used
by `OnnxMap`, removing that will be the target of a future refactor.
Strings are still processed in JNI as it is easier to work with String
tensors and UTF-8 arrays in C.

### Motivation and Context
Minimizing the amount of JNI code makes it easier to maintain and using
buffers in preference to arrays allows for fewer allocations.
2024-09-24 15:36:52 +10:00
..
main [java] Migrate OnnxTensors created from arrays over to a backing Java buffer (#18556) 2024-09-24 15:36:52 +10:00
test [java] Migrate OnnxTensors created from arrays over to a backing Java buffer (#18556) 2024-09-24 15:36:52 +10:00