[code-reflection] RFR: Use memory segment
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Feb 26 10:23:08 UTC 2025
On Wed, 26 Feb 2025 10:18:43 GMT, Maurizio Cimadamore <mcimadamore 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`.
>
> 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).
nvm - this seems to be an output stream
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/328#discussion_r1971324924
More information about the babylon-dev
mailing list