[code-reflection] RFR: Use memory segment
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Feb 26 10:23:08 UTC 2025
On Tue, 25 Feb 2025 19:09:36 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
> Replace many uses of `ByteBuffer` use with idiomatic `MemorySegment` use. This also tends to make clearer the life cycle of segments. Generally in any ONNX APIs we design i think we should avoid exposing `*Buffer`. The "escape hatch" for accessing the data of a `Tensor` should be `MemorySegment`.
Looks good -- I was similarly wondering why not using segments more directly, but I was not sure about the connection with the protobuf which I imagine is more BB-oriented.
cr-examples/onnx/src/main/java/oracle/code/onnx/OnnxProtoBuilder.java line 318:
> 316: .forEach(outputNames, (g, oName) -> g.output(new ValueInfoProto().name(oName))))
> 317: .opset_import(new OperatorSetIdProto().version(OPSET_VERSION))
> 318: .buf.toByteArray();
is `buf` a protobuf `ByteString` ? If so, note that ByteString supports `copyTo` a byte buffer. So a possibility would be to create the memory segment, then get a BB view of the segment, and then pass that view to the `copyTo` method. This should avoid the intermediate array creation (but cannot avoid the memory zeroing).
-------------
Marked as reviewed by mcimadamore (Reviewer).
PR Review: https://git.openjdk.org/babylon/pull/328#pullrequestreview-2643937822
PR Review Comment: https://git.openjdk.org/babylon/pull/328#discussion_r1971322247
More information about the babylon-dev
mailing list