From f01b7c6446f651108125311415ee4bdb01435f09 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Fri, 12 Apr 2024 18:09:11 -0400 Subject: [PATCH 01/30] GH-41179: [Docs] Documentation for Dissociated IPC Protocol --- docs/source/format/Columnar.rst | 2 + docs/source/format/DissociatedIPC.rst | 333 ++++++++++++++++++ .../format/DissociatedIPC/ClientFlowchart.mmd | 40 +++ .../DissociatedIPC/ClientFlowchart.mmd.svg | 1 + .../DissociatedIPC/SequenceDiagramSame.mmd | 46 +++ .../SequenceDiagramSame.mmd.svg | 1 + .../SequenceDiagramSeparate.mmd | 47 +++ .../SequenceDiagramSeparate.mmd.svg | 1 + docs/source/format/Flight.rst | 2 + 9 files changed, 473 insertions(+) create mode 100644 docs/source/format/DissociatedIPC.rst create mode 100644 docs/source/format/DissociatedIPC/ClientFlowchart.mmd create mode 100644 docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg create mode 100644 docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd create mode 100644 docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg create mode 100644 docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd create mode 100644 docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg diff --git a/docs/source/format/Columnar.rst b/docs/source/format/Columnar.rst index 0cfece258629..ec6a7fa5e334 100644 --- a/docs/source/format/Columnar.rst +++ b/docs/source/format/Columnar.rst @@ -1108,6 +1108,8 @@ includes a serialized Flatbuffer type along with an optional message body. We define this message format before describing how to serialize each constituent IPC message type. +.. _ipc-message-format: + Encapsulated message format --------------------------- diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst new file mode 100644 index 000000000000..8d66822f8e02 --- /dev/null +++ b/docs/source/format/DissociatedIPC.rst @@ -0,0 +1,333 @@ +.. Licensed to the Apache Software Foundation (ASF) under one +.. or more contributor license agreements. See the NOTICE file +.. distributed with this work for additional information +.. regarding copyright ownership. The ASF licenses this file +.. to you under the Apache License, Version 2.0 (the +.. "License"); you may not use this file except in compliance +.. with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, +.. software distributed under the License is distributed on an +.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +.. KIND, either express or implied. See the License for the +.. specific language governing permissions and limitations +.. under the License. + +.. _dissociated-ipc: + +======================== +Dissociated IPC Protocol +======================== + +.. warning:: + + Experimental: The Dissociated IPC Protocol is experimental in its current + form. Based on feedback and usage the protocol definition may change until + it is fully standardized. + +Rationale +========= + +The :ref:`Arrow IPC format ` describes a protocol for transferring +Arrow data as a stream of record batches. This protocol expects a continuous +stream of bytes divided into discrete messages (using a length prefix and +continuation indicator). Each discrete message consists of two portions: + +* A `Flatbuffers`_ header message +* A series of bytes consisting of the flattened and packed body buffers (some +message types, like Schema messages, do not have this section) + - This is referred to as the *message body* in the IPC format spec. + +For most cases, the existing IPC format as it currently exists is extremely efficient: + +* Receiving data in the IPC format allows zero-copy utilization of the body +buffer bytes, no deserialization is required to form Arrow Arrays +* An IPC (Feather) file can be memory-mapped because it is location agnostic +and the bytes of the file are exactly what is expected in memory. + +However, there are use cases that aren't handled by this: + +* Constructing the IPC record batch message requires allocating a contiguous +chunk of bytes and copying all of the data buffers into it, packed together +back-to-back. You currently cannot zero-copy **create** IPC messages. +* If the Arrow data is located in a shared-memory location, there is no standard +way to share the handle to the shared-memory across processes or transports that +allow for remote memory accessing. +* Arrow data located on a non-CPU device (such as a GPU) cannot be sent using +Arrow IPC without having to copy the data back to the host device or copying +the flatbuffer metadata bytes into device memory. + - By the same token, receiving IPC messages into device memory would require + performing a copy of the flatbuffer metadata back to the host CPU device. + +This protocol is intended to attempt to solve these use cases in an efficient manner. + +Goals +----- + +* Define a generic protocol for passing Arrow IPC data, not tied to any particular +transport, that also allows for utilizing non-CPU device memory, shared memory, and +newer "high performance" transports such as `ucx`_ or `libfabric`_. +* Allow for using :ref:`Flight RPC ` purely for control flow by separating +the stream of IPC metadata from IPC body bytes + - This allows for the data in the body to be kept on non-CPU devices (like GPUs) + without expensive Device -> Host copies. + +Definitions +----------- + +.. glossary:: + + IPC Metadata + The flatbuffer message bytes that encompass the header of an Arrow IPC message + + Tag + A ``uint64`` value used as an ID for a message. Specific bits can be masked to + allow identifying messages by only a portion of the tag, leaving the rest of the + bits to be used for control flow or other message metadata. + + Sequence Number + A little-endian, 4-byte unsigned integer starting at 0 for a stream, indicating + the sequence order of messages. It is also used to identify specific messages to + tie the IPC metadata header to its corresponding body since the metadata and body + can be sent across separate pipes/streams/transports. + + If a sequence number reaches ``UINT32_MAX``, it should be allowed to roll over as + it is unlikely there would be enough unprocessed messages waiting to be processed + that would cause an overlap of sequence numbers. + + The sequence number serves two purposes: To identify corresponding metadata and + tagged body data messages and to ensure we do not rely on messages having to arrive + in order. A client should use the sequence number to correctly order messages as + they arrive for processing. + + Backpressure + *Currently* this proposal does not specify any way to manage the backpressure of + messages to throttle for memory and bandwidth reasons. For now, this will be + **transport-defined** rather than lock into something sub-optimal. + + As usage among different transports and libraries grows, common patterns will emerge + that will allow for a generic, but efficient, way to handle backpressure across + different use cases. + + .. note:: + The current usage and examples have been tested using UCX and libfabric transports + so far, but that's all. + + +Protocol Description +==================== + +A reference example implementation utilizing `libcudf`_ and `ucx`_ can be found at +https://github.com/zeroshade/cudf-flight-ucx. + +Requirements +------------ + +A transport implementing this protocol **MUST** provide two pieces of functionality: + +* Message sending + - Delimited messages (like gRPC) as opposed to non-delimited streams (like plain TCP + without further framing). + - Alternatively, a framing mechanism like the `encapsulated message format ` + for the IPC protocol can be used while leaving out the body bytes. +* Tagged message sending + - Sending a message that has an attached little-endian, unsigned 64-bit integral tag + for control flow. A tag like this allows control flow to operate on a message whose body + is on a non-CPU device without requiring the message itself to get copied off of the device. + +URI Specification +----------------- + +When providing a URI to a consumer to contact for use with this protocol (such as via +the `Location URI for Flight `), the URI should specify a scheme +like *ucx://* or *fabric://*, that is easily identifiable. In addition, the URI should +encode the following URI query parameters: + +.. note:: + As this protocol matures, this document will get updated with commonly recognized + transport schemes that get used with it. + +* ``want_data`` - **REQUIRED** - uint64 integer value + - This value should be used to tag an initial message to the server to initiate a + data transfer. The body of the initiating message should be an opaque binary identifier + of the data stream being requested (like the ``Ticket`` in the Flight RPC protocol) +* ``free_data`` - **OPTIONAL** - uint64 integer value + - If the server might send messages using offsets / addresses for remote memory accessing + or shared memory locations, the URI should include this parameter. This value is used to + tag messages sent from the client to the data server, containing specific offsets / addresses + which were provided that are no longer required by the client (i.e. any operations that + directly reference those memory locations, such as copying the remote data into local memory, + have been completed). +* ``remote_handle`` - **OPTIONAL** - base64-encoded string + - When working with shared memory or remote memory, this value indicates any required + handle or identifier that is necessary for accessing the memory. + + Using UCX, this would be an *rkey* value + + With CUDA IPC, this would be the value of the base GPU pointer or memory handle, + and subsequent addresses would be offsets from this base pointer. + +Protocol Description +==================== + +There are two possibilities that can occur: + +#. The streams of metadata and body data are across separate connections + +.. figure:: ./DissociatedIPC/SequenceDiagramSeparate.mmd.svg + +#. The streams of metadata and body data are sent simultaneously across the +same connection + +.. figure:: ./DissociatedIPC/SequenceDiagramSame.mmd.svg + +Server Sequence +--------------- + +There can be either a single server handling both the IPC Metadata stream and the +Body data streams, or separate servers for handling the IPC Metadata and the body +data. This allows for streaming of data across either a single transport pipe or +two pipes if desired. + +Metadata Stream Sequence +'''''''''''''''''''''''' + +The standing state of the server is waiting for a **tagged** message with the specified +```` tag value to initiate a transfer. The body of that message will contain an +opaque, binary identifier to indicate a particular dataset / data stream to send. + +.. note:: + + For instance, the **ticket** that was passed with a *FlightInfo* message would be + the body of this message. Because it is opaque, it can be anything the server wants + to use. The URI and identifier do not need to be given to the client via Flight RPC, + but could come across from any transport or protocol desired. + +Upon receiving a ```` request, the server *should* respond by sending a stream +of messages consisting of the following: + +* A 5-byte prefix + - The first byte of the message indicates the type of message, currently there are only + two allowed message types (more types may get added in the future): + 0) End of Stream + 1) Flatbuffer IPC Metadata Message + - the next 4-bytes are a little-endian, 32-bit integer indicating the sequence number of + the message. The first message in the stream (**MUST** always be a schema message) **MUST** + have a sequence number of ``0``. Each subsequent message **MUST** increment the number by + ``1``. +* The full Flatbuffer bytes of an Arrow IPC header + +After sending the last metadata message, the server **MUST** indicate the end of the stream +by sending a message consisting of **exactly** 5 bytes: + +* The first byte is ``0``, indicating an **End of Stream** message +* The last 4 bytes are the sequence number (4-byte, unsigned integer in little-endian byte order) + +Data Stream Sequence +'''''''''''''''''''' + +If a single server is handling both the data and metadata streams, then the data messages +**should** begin being sent to the client in parallel with the metadata messages. Otherwise, +as with the metadata sequence, the standing state of the server is to wait for a **tagged** +message with the ```` tag value, whose body indicates the dataset / data stream +to send to the client. + +For each IPC message in the stream of data, a **tagged** message **MUST** be sent on the data +stream if that message has a body (i.e. a Record Batch or Dictionary message). The +:term:`tag ` for each message should be structured as follows: + +* The *least significant* 4-bytes (bits 0 - 31) of the tag should be the 32-bit, little-endian sequence +number of the message. +* The *most significant* byte (bits 56 - 63) of the tag indicates the message body **type** as an 8-bit +unsigned integer. Currently only two message types are specified, but more can be added as +needed to expand the protocol: + 0) The body contains the raw body buffer bytes as a packed buffer (i.e. the standard IPC + format body bytes) + 1) The body contains a series of unsigned, little-endian 64-bit integer pairs to represent + either shared or remote memory, schematically structured as + - The first two integers (e.g. the first 16 bytes) represent the *total* size (in bytes) + of all buffers and the number of buffers in this message (and thus the number of following + pairs of ``uint64``) + - Each subsequent pair of ``uint64`` values are an address/offset followed the length of + that particular buffer. +* All unspecified bits (bits 32 - 55) of the tag are *reserved* for future use by potential updates +to this protocol. For now they **MUST** be 0. + +.. note:: + + Any shared/remote memory addresses that are sent across **MUST** be kept alive by the server + until a corresponding tagged ```` message is received. If the client disconnects + before sending any ```` messages, it can be assumed to be safe to clean up the memory + if desired by the server. + +After sending the last tagged IPC body message, the server should maintain the connection and wait +for tagged ```` messages. The structure of these ```` messages is simple: +1 or more unsigned, little-endian 64-bit integers which indicate the addresses/offsets that can +be freed. + +Once there are no more outstanding addresses to be freed, the work for this connection is complete. + +Client Sequence +--------------- + +A client for this protocol needs to asynchronously handle both the data and metadata streams of +messages which may either both come from the same server or different servers. Below is a flowchart +showing how a client might handle the metadata and data streams: + +.. figure:: ./DissociatedIPC/ClientFlowchart.mmd.svg + +#. First the client sends a tagged message using the ```` value it was provided in the +URI as the tag, and the opaque ID as the body. + * If the metadata and data servers are separate, then a ```` message needs to be sent + separately to each. + * In either scenario, the metadata and data streams can be processed concurrently and/or asynchronously + depending on the nature of the transports. +#. For each **untagged** message the client receives in the metadata stream: + * The first byte of the message indicates whether it is an *End of Stream* message (value ``0``) + or a metadata message (value ``1``). + * The next 4 bytes are the sequence number of the message, an unsigned 32-bit integer in + little-endian byte order. + * If it is **not** an *End of Stream* message, the remaining bytes are the IPC Flatbuffer bytes which + can be interpreted as normal. + - If the message has a body (i.e. Record Batch or Dictionary message) then the client should retrieve + a tagged message from the Data Stream using the same sequence number. + * If it **is** an *End of Stream* message, then it is safe to close the metadata connection if there are + no gaps in the sequence numbers received. +#. When a metadata message that requires a body is received, the tag mask of ``0x00000000FFFFFFFF`` **should** +be used alongside the sequence number to match the message regardless of the higher bytes (e.g. we only +care about matching the lower 4 bytes to the sequence number) + * Once recieved, the Most Significant Byte's value determines how the client processes the body data: + - If the most significant byte is 0: Then the body of the message is the raw IPC packed body buffers + allowing it to easily be processed with the corresponding metadata header bytes. + - If the most significant byte is 1: The body of the message will consist of a series of pairs of + unsigned, 64-bit integers in little-endian byte order. + + The first two integers represent *1)* the total size of all the body buffers together to allow + for easy allocation if an intermediate buffer is needed and *2)* the number of buffers being sent (``nbuf``). + + The rest of the message will be ``nbuf`` pairs of integers, one for each buffer. Each pair is + *1)* the address / offset of the buffer and *2)* the length of that buffer. Memory can then be retrieved + via shared or remote memory routines based on the underlying transport. These addresses / offsets **MUST** + be retained so they can be sent back in ```` messages later, indicating to the server that + the client no longer needs the shared memory. +#. Once an *End of Stream* message is received, the client should process any remaining un-processed +IPC metadata messages. +#. After individual memory addresses / offsets are able to be freed by the remote server (in the case where +it has sent these rather than the full body bytes), the client should send corresponding ```` messages +to the server. + * A single ```` message consists of an arbitrary number of unsigned 64-bit integer values, representing + the addresses / offsets which can be freed. The reason for it being an *arbitrary number* is to allow a client + to choose whether to send multiple messages to free multiple addresses or to coalesce multiple addresses into + fewer messages to be freed (thus making the protocol less "chatty" if desired) + +Continuing Development +====================== + +If you decide to try this protocol in your own environments and system, we'd love feedback and to learn about +your use case. As this is an **experimental** protocol currently, we need real-world usage in order to facilitate +improving it and finding the right generalizations to standardize on across transports. + +Please chime in using the Arrow Developers Mailing list: dev@arrow.apache.org. + +.. _Flatbuffers: https://github.com/google/flatbuffers +.. _ucx: https://openucx.org/ +.. _libfabric: https://ofiwg.github.io/libfabric/ +.. _libcudf: https://docs.rapids.ai/api \ No newline at end of file diff --git a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd new file mode 100644 index 000000000000..e13d0d45dc70 --- /dev/null +++ b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd @@ -0,0 +1,40 @@ +%% Licensed to the Apache Software Foundation (ASF) under one +%% or more contributor license agreements. See the NOTICE file +%% distributed with this work for additional information +%% regarding copyright ownership. The ASF licenses this file +%% to you under the Apache License, Version 2.0 (the +%% "License"); you may not use this file except in compliance +%% with the License. You may obtain a copy of the License at + +%% http://www.apache.org/licenses/LICENSE-2.0 + +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. + +%% To generate the diagram, use mermaid-cli +%% Example: docker run --rm -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/ClientFlowchart.mmd + +graph TD +client((Client))-->c1{{Send #60;want_data#gt; Msg}} +subgraph meta [Meta Message] + direction LR + m1[/Msg Type #40;byte 0#41;
Seq Num #40;bytes 1-5#41;/]-- type 1 -->m2[[Process IPC Header]] + m2-- IPC has body -->m3[Get Corresponding
Tagged Msg] + m2-- Schema Msg -->m4[/Store Schema/] + m1-- type 0 -->e[Indicate End of Stream] +end +subgraph data [Data Stream] + direction LR + d1[Request Msg
for Seq Num]-->d2{Most Significant
Byte} + d2-- 0 -->d3[Construct from
Metadata and Body] + d2-- 1 -->d4[Get shared/remote
buffers] + d4 -->d5[Construct from
Metadata and buffers] + d3 & d5 -->e2[Output Batch] +end + +client -- recv untagged msg --> meta +client -- get tagged msg --> data diff --git a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg new file mode 100644 index 000000000000..711ffaf4f64d --- /dev/null +++ b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg @@ -0,0 +1 @@ +
recv untagged msg
get tagged msg
Data Stream
0
1
Most Significant
Byte
Request Msg
for Seq Num
Construct from
Metadata and Body
Get shared/remote
buffers
Construct from
Metadata and buffers
Output Batch
Meta Message
type 1
IPC has body
Schema Msg
type 0
Process IPC Header
Msg Type (byte 0)
Seq Num (bytes 1-5)
Get Corresponding
Tagged Msg
Store Schema
Indicate End of Stream
Client
Send <want_data> Msg
\ No newline at end of file diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd new file mode 100644 index 000000000000..4a8069b5459f --- /dev/null +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd @@ -0,0 +1,46 @@ +%% Licensed to the Apache Software Foundation (ASF) under one +%% or more contributor license agreements. See the NOTICE file +%% distributed with this work for additional information +%% regarding copyright ownership. The ASF licenses this file +%% to you under the Apache License, Version 2.0 (the +%% "License"); you may not use this file except in compliance +%% with the License. You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. + +%% To generate the diagram, use mermaid-cli +%% Example: docker run --rm -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/SequenceDiagramSame.mmd + +sequenceDiagram + participant C as Client + participant S as Server + activate C + C-->>+S: TAG: BODY: + S-->>C: MSG: [1] + + + par + loop each chunk + S-->>C: MSG: [1] + + + end + S-->>C: [0] + + and + loop each chunk + alt + S-->>C: TAG: | BODY: + else + S-->>C: TAG: | BODY: + end + end + end + + loop + C-->>S: TAG: BODY: + end + deactivate S + deactivate C diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg new file mode 100644 index 000000000000..a8ad6f9c2ef2 --- /dev/null +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg @@ -0,0 +1 @@ +ServerClientServerClientloop[each chunk]alt​loop[each chunk]par​loop​TAG: <want_data> BODY: <opaque ID>MSG: [1] + <sequence number> + <schema metadata>MSG: [1] + <sequence number> + <IPC metadata>[0] + <sequence number>TAG: <inline data> | <sequence number> BODY: <raw body bytes>TAG: <pointer list> | <sequence number> BODY: <pairs of uint64>TAG: <free_data> BODY: <list of uint64> \ No newline at end of file diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd new file mode 100644 index 000000000000..a376e3e19d26 --- /dev/null +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd @@ -0,0 +1,47 @@ +%% Licensed to the Apache Software Foundation (ASF) under one +%% or more contributor license agreements. See the NOTICE file +%% distributed with this work for additional information +%% regarding copyright ownership. The ASF licenses this file +%% to you under the Apache License, Version 2.0 (the +%% "License"); you may not use this file except in compliance +%% with the License. You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. + +%% To generate the diagram, use mermaid-cli +%% Example: docker run --rm -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/SequenceDiagramSeparate.mmd + +sequenceDiagram + participant D as Data Stream + participant C as Client + participant M as Metadata Stream + + activate C + C-->>+M: TAG: BODY: + C-->>+D: TAG: BODY: + M-->>C: MSG: [1] + + + loop each chunk + par + M-->>C: MSG: [1] + + + and + alt + D-->>C: TAG: | BODY: + else + D-->>C: TAG: | BODY: + end + end + end + M-->>C: [0] + + deactivate M + loop + C-->>D: TAG: BODY: + end + deactivate D + deactivate C diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg new file mode 100644 index 000000000000..efb3b0a8f3e9 --- /dev/null +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg @@ -0,0 +1 @@ +Metadata StreamClientData StreamMetadata StreamClientData Streamalt​par​loop[each chunk]loop​TAG: <want_data> BODY: <opaque ID>TAG: <want_data> BODY: <opaque ID>MSG: [1] + <sequence number> + <schema metadata>MSG: [1] + <sequence number> + <IPC metadata>TAG: <inline data> | <sequence number> BODY: <raw body bytes>TAG: <pointer list> | <sequence number> BODY: <pairs of uint64>[0] + <sequence number>TAG: <free_data> BODY: <list of uint64> \ No newline at end of file diff --git a/docs/source/format/Flight.rst b/docs/source/format/Flight.rst index c65a1f70bde7..2c5487d857ea 100644 --- a/docs/source/format/Flight.rst +++ b/docs/source/format/Flight.rst @@ -310,6 +310,8 @@ well, in which case any `authentication method supported by gRPC .. _Mutual TLS (mTLS): https://grpc.io/docs/guides/auth/#supported-auth-mechanisms +.. _flight-location-uris: + Location URIs ============= From e706979e2bb44ad21ea1f52462446e6e229c39b8 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Mon, 15 Apr 2024 15:03:19 -0400 Subject: [PATCH 02/30] updates from feedback --- docs/source/format/DissociatedIPC.rst | 140 +++++++++--------- .../format/DissociatedIPC/ClientFlowchart.mmd | 2 +- .../DissociatedIPC/ClientFlowchart.mmd.svg | 2 +- docs/source/format/index.rst | 1 + 4 files changed, 74 insertions(+), 71 deletions(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 8d66822f8e02..c5c014c97f80 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -37,29 +37,31 @@ continuation indicator). Each discrete message consists of two portions: * A `Flatbuffers`_ header message * A series of bytes consisting of the flattened and packed body buffers (some -message types, like Schema messages, do not have this section) + message types, like Schema messages, do not have this section) - This is referred to as the *message body* in the IPC format spec. For most cases, the existing IPC format as it currently exists is extremely efficient: * Receiving data in the IPC format allows zero-copy utilization of the body -buffer bytes, no deserialization is required to form Arrow Arrays + buffer bytes, no deserialization is required to form Arrow Arrays * An IPC (Feather) file can be memory-mapped because it is location agnostic -and the bytes of the file are exactly what is expected in memory. + and the bytes of the file are exactly what is expected in memory. However, there are use cases that aren't handled by this: * Constructing the IPC record batch message requires allocating a contiguous -chunk of bytes and copying all of the data buffers into it, packed together -back-to-back. You currently cannot zero-copy **create** IPC messages. + chunk of bytes and copying all of the data buffers into it, packed together + back-to-back. It's exceedingly difficult to zero-copy **create** IPC messages. * If the Arrow data is located in a shared-memory location, there is no standard -way to share the handle to the shared-memory across processes or transports that -allow for remote memory accessing. + way to share the handle to the shared-memory across processes or transports that + allow for remote memory accessing. * Arrow data located on a non-CPU device (such as a GPU) cannot be sent using -Arrow IPC without having to copy the data back to the host device or copying -the flatbuffer metadata bytes into device memory. + Arrow IPC without having to copy the data back to the host device or copying + the flatbuffer metadata bytes into device memory. - By the same token, receiving IPC messages into device memory would require - performing a copy of the flatbuffer metadata back to the host CPU device. + performing a copy of the flatbuffer metadata back to the host CPU device. This + is due to the fact that the IPC stream interleaves data and metadata across a + single stream. This protocol is intended to attempt to solve these use cases in an efficient manner. @@ -67,12 +69,12 @@ Goals ----- * Define a generic protocol for passing Arrow IPC data, not tied to any particular -transport, that also allows for utilizing non-CPU device memory, shared memory, and -newer "high performance" transports such as `ucx`_ or `libfabric`_. + transport, that also allows for utilizing non-CPU device memory, shared memory, and + newer "high performance" transports such as `ucx`_ or `libfabric`_. * Allow for using :ref:`Flight RPC ` purely for control flow by separating -the stream of IPC metadata from IPC body bytes + the stream of IPC metadata from IPC body bytes - This allows for the data in the body to be kept on non-CPU devices (like GPUs) - without expensive Device -> Host copies. + without expensive Device -> Host copies. Definitions ----------- @@ -112,8 +114,8 @@ Definitions different use cases. .. note:: - The current usage and examples have been tested using UCX and libfabric transports - so far, but that's all. + While the protocol itself is transport agnostic, the current usage and examples + only have been tested using UCX and libfabric transports so far, but that's all. Protocol Description @@ -129,19 +131,19 @@ A transport implementing this protocol **MUST** provide two pieces of functional * Message sending - Delimited messages (like gRPC) as opposed to non-delimited streams (like plain TCP - without further framing). + without further framing). - Alternatively, a framing mechanism like the `encapsulated message format ` - for the IPC protocol can be used while leaving out the body bytes. + for the IPC protocol can be used while leaving out the body bytes. * Tagged message sending - Sending a message that has an attached little-endian, unsigned 64-bit integral tag - for control flow. A tag like this allows control flow to operate on a message whose body - is on a non-CPU device without requiring the message itself to get copied off of the device. + for control flow. A tag like this allows control flow to operate on a message whose body + is on a non-CPU device without requiring the message itself to get copied off of the device. URI Specification ----------------- When providing a URI to a consumer to contact for use with this protocol (such as via -the `Location URI for Flight `), the URI should specify a scheme +the `Location URI for Flight `_), the URI should specify a scheme like *ucx://* or *fabric://*, that is easily identifiable. In addition, the URI should encode the following URI query parameters: @@ -151,33 +153,33 @@ encode the following URI query parameters: * ``want_data`` - **REQUIRED** - uint64 integer value - This value should be used to tag an initial message to the server to initiate a - data transfer. The body of the initiating message should be an opaque binary identifier - of the data stream being requested (like the ``Ticket`` in the Flight RPC protocol) + data transfer. The body of the initiating message should be an opaque binary identifier + of the data stream being requested (like the ``Ticket`` in the Flight RPC protocol) * ``free_data`` - **OPTIONAL** - uint64 integer value - If the server might send messages using offsets / addresses for remote memory accessing - or shared memory locations, the URI should include this parameter. This value is used to - tag messages sent from the client to the data server, containing specific offsets / addresses - which were provided that are no longer required by the client (i.e. any operations that - directly reference those memory locations, such as copying the remote data into local memory, - have been completed). + or shared memory locations, the URI should include this parameter. This value is used to + tag messages sent from the client to the data server, containing specific offsets / addresses + which were provided that are no longer required by the client (i.e. any operations that + directly reference those memory locations, such as copying the remote data into local memory, + have been completed). * ``remote_handle`` - **OPTIONAL** - base64-encoded string - When working with shared memory or remote memory, this value indicates any required - handle or identifier that is necessary for accessing the memory. + handle or identifier that is necessary for accessing the memory. + Using UCX, this would be an *rkey* value + With CUDA IPC, this would be the value of the base GPU pointer or memory handle, - and subsequent addresses would be offsets from this base pointer. + and subsequent addresses would be offsets from this base pointer. Protocol Description ==================== There are two possibilities that can occur: -#. The streams of metadata and body data are across separate connections +1. The streams of metadata and body data are across separate connections .. figure:: ./DissociatedIPC/SequenceDiagramSeparate.mmd.svg -#. The streams of metadata and body data are sent simultaneously across the -same connection +2. The streams of metadata and body data are sent simultaneously across the + same connection .. figure:: ./DissociatedIPC/SequenceDiagramSame.mmd.svg @@ -208,13 +210,13 @@ of messages consisting of the following: * A 5-byte prefix - The first byte of the message indicates the type of message, currently there are only - two allowed message types (more types may get added in the future): + two allowed message types (more types may get added in the future): 0) End of Stream 1) Flatbuffer IPC Metadata Message - the next 4-bytes are a little-endian, 32-bit integer indicating the sequence number of - the message. The first message in the stream (**MUST** always be a schema message) **MUST** - have a sequence number of ``0``. Each subsequent message **MUST** increment the number by - ``1``. + the message. The first message in the stream (**MUST** always be a schema message) **MUST** + have a sequence number of ``0``. Each subsequent message **MUST** increment the number by + ``1``. * The full Flatbuffer bytes of an Arrow IPC header After sending the last metadata message, the server **MUST** indicate the end of the stream @@ -237,21 +239,21 @@ stream if that message has a body (i.e. a Record Batch or Dictionary message). T :term:`tag ` for each message should be structured as follows: * The *least significant* 4-bytes (bits 0 - 31) of the tag should be the 32-bit, little-endian sequence -number of the message. + number of the message. * The *most significant* byte (bits 56 - 63) of the tag indicates the message body **type** as an 8-bit -unsigned integer. Currently only two message types are specified, but more can be added as -needed to expand the protocol: + unsigned integer. Currently only two message types are specified, but more can be added as + needed to expand the protocol: 0) The body contains the raw body buffer bytes as a packed buffer (i.e. the standard IPC - format body bytes) + format body bytes) 1) The body contains a series of unsigned, little-endian 64-bit integer pairs to represent - either shared or remote memory, schematically structured as + either shared or remote memory, schematically structured as - The first two integers (e.g. the first 16 bytes) represent the *total* size (in bytes) - of all buffers and the number of buffers in this message (and thus the number of following - pairs of ``uint64``) + of all buffers and the number of buffers in this message (and thus the number of following + pairs of ``uint64``) - Each subsequent pair of ``uint64`` values are an address/offset followed the length of - that particular buffer. + that particular buffer. * All unspecified bits (bits 32 - 55) of the tag are *reserved* for future use by potential updates -to this protocol. For now they **MUST** be 0. + to this protocol. For now they **MUST** be 0. .. note:: @@ -277,46 +279,46 @@ showing how a client might handle the metadata and data streams: .. figure:: ./DissociatedIPC/ClientFlowchart.mmd.svg #. First the client sends a tagged message using the ```` value it was provided in the -URI as the tag, and the opaque ID as the body. + URI as the tag, and the opaque ID as the body. * If the metadata and data servers are separate, then a ```` message needs to be sent - separately to each. + separately to each. * In either scenario, the metadata and data streams can be processed concurrently and/or asynchronously - depending on the nature of the transports. + depending on the nature of the transports. #. For each **untagged** message the client receives in the metadata stream: * The first byte of the message indicates whether it is an *End of Stream* message (value ``0``) - or a metadata message (value ``1``). + or a metadata message (value ``1``). * The next 4 bytes are the sequence number of the message, an unsigned 32-bit integer in - little-endian byte order. + little-endian byte order. * If it is **not** an *End of Stream* message, the remaining bytes are the IPC Flatbuffer bytes which - can be interpreted as normal. + can be interpreted as normal. - If the message has a body (i.e. Record Batch or Dictionary message) then the client should retrieve - a tagged message from the Data Stream using the same sequence number. + a tagged message from the Data Stream using the same sequence number. * If it **is** an *End of Stream* message, then it is safe to close the metadata connection if there are - no gaps in the sequence numbers received. + no gaps in the sequence numbers received. #. When a metadata message that requires a body is received, the tag mask of ``0x00000000FFFFFFFF`` **should** -be used alongside the sequence number to match the message regardless of the higher bytes (e.g. we only -care about matching the lower 4 bytes to the sequence number) + be used alongside the sequence number to match the message regardless of the higher bytes (e.g. we only + care about matching the lower 4 bytes to the sequence number) * Once recieved, the Most Significant Byte's value determines how the client processes the body data: - If the most significant byte is 0: Then the body of the message is the raw IPC packed body buffers - allowing it to easily be processed with the corresponding metadata header bytes. + allowing it to easily be processed with the corresponding metadata header bytes. - If the most significant byte is 1: The body of the message will consist of a series of pairs of - unsigned, 64-bit integers in little-endian byte order. + unsigned, 64-bit integers in little-endian byte order. + The first two integers represent *1)* the total size of all the body buffers together to allow - for easy allocation if an intermediate buffer is needed and *2)* the number of buffers being sent (``nbuf``). + for easy allocation if an intermediate buffer is needed and *2)* the number of buffers being sent (``nbuf``). + The rest of the message will be ``nbuf`` pairs of integers, one for each buffer. Each pair is - *1)* the address / offset of the buffer and *2)* the length of that buffer. Memory can then be retrieved - via shared or remote memory routines based on the underlying transport. These addresses / offsets **MUST** - be retained so they can be sent back in ```` messages later, indicating to the server that - the client no longer needs the shared memory. + *1)* the address / offset of the buffer and *2)* the length of that buffer. Memory can then be retrieved + via shared or remote memory routines based on the underlying transport. These addresses / offsets **MUST** + be retained so they can be sent back in ```` messages later, indicating to the server that + the client no longer needs the shared memory. #. Once an *End of Stream* message is received, the client should process any remaining un-processed -IPC metadata messages. + IPC metadata messages. #. After individual memory addresses / offsets are able to be freed by the remote server (in the case where -it has sent these rather than the full body bytes), the client should send corresponding ```` messages -to the server. + it has sent these rather than the full body bytes), the client should send corresponding ```` messages + to the server. * A single ```` message consists of an arbitrary number of unsigned 64-bit integer values, representing - the addresses / offsets which can be freed. The reason for it being an *arbitrary number* is to allow a client - to choose whether to send multiple messages to free multiple addresses or to coalesce multiple addresses into - fewer messages to be freed (thus making the protocol less "chatty" if desired) + the addresses / offsets which can be freed. The reason for it being an *arbitrary number* is to allow a client + to choose whether to send multiple messages to free multiple addresses or to coalesce multiple addresses into + fewer messages to be freed (thus making the protocol less "chatty" if desired) Continuing Development ====================== diff --git a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd index e13d0d45dc70..275ce33df30f 100644 --- a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd +++ b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd @@ -18,7 +18,7 @@ %% To generate the diagram, use mermaid-cli %% Example: docker run --rm -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/ClientFlowchart.mmd -graph TD +graph LR client((Client))-->c1{{Send #60;want_data#gt; Msg}} subgraph meta [Meta Message] direction LR diff --git a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg index 711ffaf4f64d..a59ac8732b77 100644 --- a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg +++ b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg @@ -1 +1 @@ -
recv untagged msg
get tagged msg
Data Stream
0
1
Most Significant
Byte
Request Msg
for Seq Num
Construct from
Metadata and Body
Get shared/remote
buffers
Construct from
Metadata and buffers
Output Batch
Meta Message
type 1
IPC has body
Schema Msg
type 0
Process IPC Header
Msg Type (byte 0)
Seq Num (bytes 1-5)
Get Corresponding
Tagged Msg
Store Schema
Indicate End of Stream
Client
Send <want_data> Msg
\ No newline at end of file +
recv untagged msg
get tagged msg
Data Stream
0
1
Most Significant
Byte
Request Msg
for Seq Num
Construct from
Metadata and Body
Get shared/remote
buffers
Construct from
Metadata and buffers
Output Batch
Meta Message
type 1
IPC has body
Schema Msg
type 0
Process IPC Header
Msg Type (byte 0)
Seq Num (bytes 1-5)
Get Corresponding
Tagged Msg
Store Schema
Indicate End of Stream
Client
Send <want_data> Msg
\ No newline at end of file diff --git a/docs/source/format/index.rst b/docs/source/format/index.rst index 856830d86324..44ea3e8e7e60 100644 --- a/docs/source/format/index.rst +++ b/docs/source/format/index.rst @@ -30,6 +30,7 @@ Specifications CDataInterface CStreamInterface CDeviceDataInterface + DissociatedIPC Flight FlightSql ADBC From b05a3aaa5219b666f2c817d8c876ff3f9cdbc1f0 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:38:46 -0400 Subject: [PATCH 03/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index c5c014c97f80..e43170adb0ee 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -44,7 +44,7 @@ For most cases, the existing IPC format as it currently exists is extremely effi * Receiving data in the IPC format allows zero-copy utilization of the body buffer bytes, no deserialization is required to form Arrow Arrays -* An IPC (Feather) file can be memory-mapped because it is location agnostic +* An IPC file format can be memory-mapped because it is location agnostic and the bytes of the file are exactly what is expected in memory. However, there are use cases that aren't handled by this: From 4739f361bdbcc553068217e25e9c5058fdbf4439 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:39:14 -0400 Subject: [PATCH 04/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index e43170adb0ee..4b7fe0ac74ed 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -58,7 +58,7 @@ However, there are use cases that aren't handled by this: * Arrow data located on a non-CPU device (such as a GPU) cannot be sent using Arrow IPC without having to copy the data back to the host device or copying the flatbuffer metadata bytes into device memory. - - By the same token, receiving IPC messages into device memory would require + * By the same token, receiving IPC messages into device memory would require performing a copy of the flatbuffer metadata back to the host CPU device. This is due to the fact that the IPC stream interleaves data and metadata across a single stream. From 99d4e1af7374a3fc51361de191be4d0ced488270 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:39:27 -0400 Subject: [PATCH 05/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 4b7fe0ac74ed..84cab086d0e8 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -73,7 +73,7 @@ Goals newer "high performance" transports such as `ucx`_ or `libfabric`_. * Allow for using :ref:`Flight RPC ` purely for control flow by separating the stream of IPC metadata from IPC body bytes - - This allows for the data in the body to be kept on non-CPU devices (like GPUs) + * This allows for the data in the body to be kept on non-CPU devices (like GPUs) without expensive Device -> Host copies. Definitions From 288828fcbd3000ec6c96eacb5c9c018e2944758c Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:39:49 -0400 Subject: [PATCH 06/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 84cab086d0e8..8aa34ed85cf8 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -70,7 +70,7 @@ Goals * Define a generic protocol for passing Arrow IPC data, not tied to any particular transport, that also allows for utilizing non-CPU device memory, shared memory, and - newer "high performance" transports such as `ucx`_ or `libfabric`_. + newer "high performance" transports such as `UCX`_ or `libfabric`_. * Allow for using :ref:`Flight RPC ` purely for control flow by separating the stream of IPC metadata from IPC body bytes * This allows for the data in the body to be kept on non-CPU devices (like GPUs) From bbb0b9d33bfb4ba8cf9b1231b22bd1b484e8dcd9 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:40:04 -0400 Subject: [PATCH 07/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 8aa34ed85cf8..e3c5a36bd7e8 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -330,6 +330,6 @@ improving it and finding the right generalizations to standardize on across tran Please chime in using the Arrow Developers Mailing list: dev@arrow.apache.org. .. _Flatbuffers: https://github.com/google/flatbuffers -.. _ucx: https://openucx.org/ +.. _UCX: https://openucx.org/ .. _libfabric: https://ofiwg.github.io/libfabric/ .. _libcudf: https://docs.rapids.ai/api \ No newline at end of file From 6e1bd4827384f7aa1dd1f0bde5e6b4bfcb220e23 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:40:17 -0400 Subject: [PATCH 08/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index e3c5a36bd7e8..d06c0b713026 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -121,7 +121,7 @@ Definitions Protocol Description ==================== -A reference example implementation utilizing `libcudf`_ and `ucx`_ can be found at +A reference example implementation utilizing `libcudf`_ and `UCX`_ can be found at https://github.com/zeroshade/cudf-flight-ucx. Requirements From 862420f324907177853b58a2a53303ded3922bc4 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:40:38 -0400 Subject: [PATCH 09/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index d06c0b713026..ee2a21b15dce 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -130,7 +130,7 @@ Requirements A transport implementing this protocol **MUST** provide two pieces of functionality: * Message sending - - Delimited messages (like gRPC) as opposed to non-delimited streams (like plain TCP + * Delimited messages (like gRPC) as opposed to non-delimited streams (like plain TCP without further framing). - Alternatively, a framing mechanism like the `encapsulated message format ` for the IPC protocol can be used while leaving out the body bytes. From 0d8d298cd26ecefb1ad5727e132fe82920181478 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:41:01 -0400 Subject: [PATCH 10/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index ee2a21b15dce..e53e0e90e084 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -132,7 +132,7 @@ A transport implementing this protocol **MUST** provide two pieces of functional * Message sending * Delimited messages (like gRPC) as opposed to non-delimited streams (like plain TCP without further framing). - - Alternatively, a framing mechanism like the `encapsulated message format ` + * Alternatively, a framing mechanism like the :ref:`encapsulated message format ` for the IPC protocol can be used while leaving out the body bytes. * Tagged message sending - Sending a message that has an attached little-endian, unsigned 64-bit integral tag From 8f827d83bc4acfc49712da5eec2307d5eef32f63 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 10:44:16 -0400 Subject: [PATCH 11/30] Apply suggestions from code review Co-authored-by: Antoine Pitrou Co-authored-by: Sutou Kouhei --- docs/source/format/DissociatedIPC.rst | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index e53e0e90e084..6f9092f51edc 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -40,7 +40,7 @@ continuation indicator). Each discrete message consists of two portions: message types, like Schema messages, do not have this section) - This is referred to as the *message body* in the IPC format spec. -For most cases, the existing IPC format as it currently exists is extremely efficient: +For most cases, the existing IPC format as it currently exists is sufficiently efficient: * Receiving data in the IPC format allows zero-copy utilization of the body buffer bytes, no deserialization is required to form Arrow Arrays @@ -59,11 +59,11 @@ However, there are use cases that aren't handled by this: Arrow IPC without having to copy the data back to the host device or copying the flatbuffer metadata bytes into device memory. * By the same token, receiving IPC messages into device memory would require - performing a copy of the flatbuffer metadata back to the host CPU device. This + performing a copy of the Flatbuffers metadata back to the host CPU device. This is due to the fact that the IPC stream interleaves data and metadata across a single stream. -This protocol is intended to attempt to solve these use cases in an efficient manner. +This protocol attempts to solve these use cases in an efficient manner. Goals ----- @@ -74,7 +74,7 @@ Goals * Allow for using :ref:`Flight RPC ` purely for control flow by separating the stream of IPC metadata from IPC body bytes * This allows for the data in the body to be kept on non-CPU devices (like GPUs) - without expensive Device -> Host copies. + without expensive device-to-host copies. Definitions ----------- @@ -135,7 +135,7 @@ A transport implementing this protocol **MUST** provide two pieces of functional * Alternatively, a framing mechanism like the :ref:`encapsulated message format ` for the IPC protocol can be used while leaving out the body bytes. * Tagged message sending - - Sending a message that has an attached little-endian, unsigned 64-bit integral tag + * Sending a message that has an attached little-endian, unsigned 64-bit integral tag for control flow. A tag like this allows control flow to operate on a message whose body is on a non-CPU device without requiring the message itself to get copied off of the device. @@ -143,8 +143,8 @@ URI Specification ----------------- When providing a URI to a consumer to contact for use with this protocol (such as via -the `Location URI for Flight `_), the URI should specify a scheme -like *ucx://* or *fabric://*, that is easily identifiable. In addition, the URI should +the :ref:`Location URI for Flight `), the URI should specify a scheme +like *ucx:* or *fabric:*, that is easily identifiable. In addition, the URI should encode the following URI query parameters: .. note:: @@ -152,21 +152,21 @@ encode the following URI query parameters: transport schemes that get used with it. * ``want_data`` - **REQUIRED** - uint64 integer value - - This value should be used to tag an initial message to the server to initiate a + * This value should be used to tag an initial message to the server to initiate a data transfer. The body of the initiating message should be an opaque binary identifier of the data stream being requested (like the ``Ticket`` in the Flight RPC protocol) * ``free_data`` - **OPTIONAL** - uint64 integer value - - If the server might send messages using offsets / addresses for remote memory accessing + * If the server might send messages using offsets / addresses for remote memory accessing or shared memory locations, the URI should include this parameter. This value is used to tag messages sent from the client to the data server, containing specific offsets / addresses which were provided that are no longer required by the client (i.e. any operations that directly reference those memory locations, such as copying the remote data into local memory, have been completed). * ``remote_handle`` - **OPTIONAL** - base64-encoded string - - When working with shared memory or remote memory, this value indicates any required + * When working with shared memory or remote memory, this value indicates any required handle or identifier that is necessary for accessing the memory. - + Using UCX, this would be an *rkey* value - + With CUDA IPC, this would be the value of the base GPU pointer or memory handle, + * Using UCX, this would be an *rkey* value + * With CUDA IPC, this would be the value of the base GPU pointer or memory handle, and subsequent addresses would be offsets from this base pointer. Protocol Description @@ -174,7 +174,7 @@ Protocol Description There are two possibilities that can occur: -1. The streams of metadata and body data are across separate connections +1. The streams of metadata and body data are sent across separate connections .. figure:: ./DissociatedIPC/SequenceDiagramSeparate.mmd.svg @@ -213,7 +213,7 @@ of messages consisting of the following: two allowed message types (more types may get added in the future): 0) End of Stream 1) Flatbuffer IPC Metadata Message - - the next 4-bytes are a little-endian, 32-bit integer indicating the sequence number of + - the next 4-bytes are a little-endian, unsigned 32-bit integer indicating the sequence number of the message. The first message in the stream (**MUST** always be a schema message) **MUST** have a sequence number of ``0``. Each subsequent message **MUST** increment the number by ``1``. @@ -238,7 +238,7 @@ For each IPC message in the stream of data, a **tagged** message **MUST** be sen stream if that message has a body (i.e. a Record Batch or Dictionary message). The :term:`tag ` for each message should be structured as follows: -* The *least significant* 4-bytes (bits 0 - 31) of the tag should be the 32-bit, little-endian sequence +* The *least significant* 4-bytes (bits 0 - 31) of the tag should be the unsigned 32-bit, little-endian sequence number of the message. * The *most significant* byte (bits 56 - 63) of the tag indicates the message body **type** as an 8-bit unsigned integer. Currently only two message types are specified, but more can be added as @@ -250,7 +250,7 @@ stream if that message has a body (i.e. a Record Batch or Dictionary message). T - The first two integers (e.g. the first 16 bytes) represent the *total* size (in bytes) of all buffers and the number of buffers in this message (and thus the number of following pairs of ``uint64``) - - Each subsequent pair of ``uint64`` values are an address/offset followed the length of + - Each subsequent pair of ``uint64`` values are an address / offset followed the length of that particular buffer. * All unspecified bits (bits 32 - 55) of the tag are *reserved* for future use by potential updates to this protocol. For now they **MUST** be 0. From f92ff3d147789fd970e15aeb4e0846294abfb746 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 11:38:04 -0400 Subject: [PATCH 12/30] updates from feedback --- docs/source/format/DissociatedIPC.rst | 96 +++++++++++++++------------ 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 6f9092f51edc..f55ab8c25b1b 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -52,9 +52,9 @@ However, there are use cases that aren't handled by this: * Constructing the IPC record batch message requires allocating a contiguous chunk of bytes and copying all of the data buffers into it, packed together back-to-back. It's exceedingly difficult to zero-copy **create** IPC messages. -* If the Arrow data is located in a shared-memory location, there is no standard +* If the Arrow data is located in a shared memory location, there is no standard way to share the handle to the shared-memory across processes or transports that - allow for remote memory accessing. + allow for remote memory accessing, such as UCX. * Arrow data located on a non-CPU device (such as a GPU) cannot be sent using Arrow IPC without having to copy the data back to the host device or copying the flatbuffer metadata bytes into device memory. @@ -82,12 +82,12 @@ Definitions .. glossary:: IPC Metadata - The flatbuffer message bytes that encompass the header of an Arrow IPC message + The Flatbuffers message bytes that encompass the header of an Arrow IPC message Tag - A ``uint64`` value used as an ID for a message. Specific bits can be masked to - allow identifying messages by only a portion of the tag, leaving the rest of the - bits to be used for control flow or other message metadata. + A little-endian ``uint64`` value used as an ID for a message. Specific bits can + be masked to allow identifying messages by only a portion of the tag, leaving the + rest of the bits to be used for control flow or other message metadata. Sequence Number A little-endian, 4-byte unsigned integer starting at 0 for a stream, indicating @@ -194,8 +194,11 @@ two pipes if desired. Metadata Stream Sequence '''''''''''''''''''''''' -The standing state of the server is waiting for a **tagged** message with the specified -```` tag value to initiate a transfer. The body of that message will contain an +The standing state of the server is waiting for a **tagged** message with a specific +```` tag value to initiate a transfer. This ```` value is defined +by the server and propagated to any clients via the URI they are provided. This protocol +does not prescribe any particular value so that it will not interfere with any other +existing protocols that rely on tag values. The body of that message will contain an opaque, binary identifier to indicate a particular dataset / data stream to send. .. note:: @@ -212,12 +215,15 @@ of messages consisting of the following: - The first byte of the message indicates the type of message, currently there are only two allowed message types (more types may get added in the future): 0) End of Stream - 1) Flatbuffer IPC Metadata Message + 1) Flatbuffers IPC Metadata Message - the next 4-bytes are a little-endian, unsigned 32-bit integer indicating the sequence number of the message. The first message in the stream (**MUST** always be a schema message) **MUST** have a sequence number of ``0``. Each subsequent message **MUST** increment the number by ``1``. -* The full Flatbuffer bytes of an Arrow IPC header +* The full Flatbuffers bytes of an Arrow IPC header + +As defined in the Arrow IPC format, each metadata message can represent a chunk of data or +dictionaries for use by the stream of data. After sending the last metadata message, the server **MUST** indicate the end of the stream by sending a message consisting of **exactly** 5 bytes: @@ -264,15 +270,15 @@ stream if that message has a body (i.e. a Record Batch or Dictionary message). T After sending the last tagged IPC body message, the server should maintain the connection and wait for tagged ```` messages. The structure of these ```` messages is simple: -1 or more unsigned, little-endian 64-bit integers which indicate the addresses/offsets that can +one or more unsigned, little-endian 64-bit integers which indicate the addresses/offsets that can be freed. -Once there are no more outstanding addresses to be freed, the work for this connection is complete. +Once there are no more outstanding addresses to be freed, the work for this stream is complete. Client Sequence --------------- -A client for this protocol needs to asynchronously handle both the data and metadata streams of +A client for this protocol needs to concurrently handle both the data and metadata streams of messages which may either both come from the same server or different servers. Below is a flowchart showing how a client might handle the metadata and data streams: @@ -280,45 +286,53 @@ showing how a client might handle the metadata and data streams: #. First the client sends a tagged message using the ```` value it was provided in the URI as the tag, and the opaque ID as the body. - * If the metadata and data servers are separate, then a ```` message needs to be sent - separately to each. - * In either scenario, the metadata and data streams can be processed concurrently and/or asynchronously - depending on the nature of the transports. + + * If the metadata and data servers are separate, then a ```` message needs to be sent + separately to each. + * In either scenario, the metadata and data streams can be processed concurrently and/or asynchronously + depending on the nature of the transports. + #. For each **untagged** message the client receives in the metadata stream: - * The first byte of the message indicates whether it is an *End of Stream* message (value ``0``) - or a metadata message (value ``1``). - * The next 4 bytes are the sequence number of the message, an unsigned 32-bit integer in - little-endian byte order. - * If it is **not** an *End of Stream* message, the remaining bytes are the IPC Flatbuffer bytes which - can be interpreted as normal. - - If the message has a body (i.e. Record Batch or Dictionary message) then the client should retrieve + + * The first byte of the message indicates whether it is an *End of Stream* message (value ``0``) + or a metadata message (value ``1``). + * The next 4 bytes are the sequence number of the message, an unsigned 32-bit integer in + little-endian byte order. + * If it is **not** an *End of Stream* message, the remaining bytes are the IPC Flatbuffer bytes which + can be interpreted as normal. + * If the message has a body (i.e. Record Batch or Dictionary message) then the client should retrieve a tagged message from the Data Stream using the same sequence number. * If it **is** an *End of Stream* message, then it is safe to close the metadata connection if there are no gaps in the sequence numbers received. + #. When a metadata message that requires a body is received, the tag mask of ``0x00000000FFFFFFFF`` **should** be used alongside the sequence number to match the message regardless of the higher bytes (e.g. we only care about matching the lower 4 bytes to the sequence number) - * Once recieved, the Most Significant Byte's value determines how the client processes the body data: - - If the most significant byte is 0: Then the body of the message is the raw IPC packed body buffers - allowing it to easily be processed with the corresponding metadata header bytes. - - If the most significant byte is 1: The body of the message will consist of a series of pairs of - unsigned, 64-bit integers in little-endian byte order. - + The first two integers represent *1)* the total size of all the body buffers together to allow - for easy allocation if an intermediate buffer is needed and *2)* the number of buffers being sent (``nbuf``). - + The rest of the message will be ``nbuf`` pairs of integers, one for each buffer. Each pair is - *1)* the address / offset of the buffer and *2)* the length of that buffer. Memory can then be retrieved - via shared or remote memory routines based on the underlying transport. These addresses / offsets **MUST** - be retained so they can be sent back in ```` messages later, indicating to the server that - the client no longer needs the shared memory. + + * Once recieved, the Most Significant Byte's value determines how the client processes the body data: + * If the most significant byte is 0: Then the body of the message is the raw IPC packed body buffers + allowing it to easily be processed with the corresponding metadata header bytes. + * If the most significant byte is 1: The body of the message will consist of a series of pairs of + unsigned, 64-bit integers in little-endian byte order. + * The first two integers represent *1)* the total size of all the body buffers together to allow + for easy allocation if an intermediate buffer is needed and *2)* the number of buffers being sent (``nbuf``). + * The rest of the message will be ``nbuf`` pairs of integers, one for each buffer. Each pair is + *1)* the address / offset of the buffer and *2)* the length of that buffer. Memory can then be retrieved + via shared or remote memory routines based on the underlying transport. These addresses / offsets **MUST** + be retained so they can be sent back in ```` messages later, indicating to the server that + the client no longer needs the shared memory. + #. Once an *End of Stream* message is received, the client should process any remaining un-processed IPC metadata messages. + #. After individual memory addresses / offsets are able to be freed by the remote server (in the case where it has sent these rather than the full body bytes), the client should send corresponding ```` messages to the server. - * A single ```` message consists of an arbitrary number of unsigned 64-bit integer values, representing - the addresses / offsets which can be freed. The reason for it being an *arbitrary number* is to allow a client - to choose whether to send multiple messages to free multiple addresses or to coalesce multiple addresses into - fewer messages to be freed (thus making the protocol less "chatty" if desired) + + * A single ```` message consists of an arbitrary number of unsigned 64-bit integer values, representing + the addresses / offsets which can be freed. The reason for it being an *arbitrary number* is to allow a client + to choose whether to send multiple messages to free multiple addresses or to coalesce multiple addresses into + fewer messages to be freed (thus making the protocol less "chatty" if desired) Continuing Development ====================== @@ -327,7 +341,7 @@ If you decide to try this protocol in your own environments and system, we'd lov your use case. As this is an **experimental** protocol currently, we need real-world usage in order to facilitate improving it and finding the right generalizations to standardize on across transports. -Please chime in using the Arrow Developers Mailing list: dev@arrow.apache.org. +Please chime in using the Arrow Developers Mailing list: https://arrow.apache.org/community/#mailing-lists .. _Flatbuffers: https://github.com/google/flatbuffers .. _UCX: https://openucx.org/ From 3ceb343683ff908f3edc51b4b98b34380333861a Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 16 Apr 2024 15:06:09 -0400 Subject: [PATCH 13/30] formatting fixes --- docs/source/format/DissociatedIPC.rst | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index f55ab8c25b1b..0f8994e8ac56 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -57,7 +57,8 @@ However, there are use cases that aren't handled by this: allow for remote memory accessing, such as UCX. * Arrow data located on a non-CPU device (such as a GPU) cannot be sent using Arrow IPC without having to copy the data back to the host device or copying - the flatbuffer metadata bytes into device memory. + the Flatbuffers metadata bytes into device memory. + * By the same token, receiving IPC messages into device memory would require performing a copy of the Flatbuffers metadata back to the host CPU device. This is due to the fact that the IPC stream interleaves data and metadata across a @@ -73,6 +74,7 @@ Goals newer "high performance" transports such as `UCX`_ or `libfabric`_. * Allow for using :ref:`Flight RPC ` purely for control flow by separating the stream of IPC metadata from IPC body bytes + * This allows for the data in the body to be kept on non-CPU devices (like GPUs) without expensive device-to-host copies. @@ -130,11 +132,15 @@ Requirements A transport implementing this protocol **MUST** provide two pieces of functionality: * Message sending + * Delimited messages (like gRPC) as opposed to non-delimited streams (like plain TCP without further framing). + * Alternatively, a framing mechanism like the :ref:`encapsulated message format ` for the IPC protocol can be used while leaving out the body bytes. + * Tagged message sending + * Sending a message that has an attached little-endian, unsigned 64-bit integral tag for control flow. A tag like this allows control flow to operate on a message whose body is on a non-CPU device without requiring the message itself to get copied off of the device. @@ -152,20 +158,27 @@ encode the following URI query parameters: transport schemes that get used with it. * ``want_data`` - **REQUIRED** - uint64 integer value + * This value should be used to tag an initial message to the server to initiate a data transfer. The body of the initiating message should be an opaque binary identifier of the data stream being requested (like the ``Ticket`` in the Flight RPC protocol) + * ``free_data`` - **OPTIONAL** - uint64 integer value + * If the server might send messages using offsets / addresses for remote memory accessing or shared memory locations, the URI should include this parameter. This value is used to tag messages sent from the client to the data server, containing specific offsets / addresses which were provided that are no longer required by the client (i.e. any operations that directly reference those memory locations, such as copying the remote data into local memory, have been completed). + * ``remote_handle`` - **OPTIONAL** - base64-encoded string + * When working with shared memory or remote memory, this value indicates any required handle or identifier that is necessary for accessing the memory. + * Using UCX, this would be an *rkey* value + * With CUDA IPC, this would be the value of the base GPU pointer or memory handle, and subsequent addresses would be offsets from this base pointer. @@ -212,14 +225,18 @@ Upon receiving a ```` request, the server *should* respond by sending of messages consisting of the following: * A 5-byte prefix + - The first byte of the message indicates the type of message, currently there are only two allowed message types (more types may get added in the future): + 0) End of Stream 1) Flatbuffers IPC Metadata Message + - the next 4-bytes are a little-endian, unsigned 32-bit integer indicating the sequence number of the message. The first message in the stream (**MUST** always be a schema message) **MUST** have a sequence number of ``0``. Each subsequent message **MUST** increment the number by ``1``. + * The full Flatbuffers bytes of an Arrow IPC header As defined in the Arrow IPC format, each metadata message can represent a chunk of data or @@ -249,15 +266,19 @@ stream if that message has a body (i.e. a Record Batch or Dictionary message). T * The *most significant* byte (bits 56 - 63) of the tag indicates the message body **type** as an 8-bit unsigned integer. Currently only two message types are specified, but more can be added as needed to expand the protocol: + 0) The body contains the raw body buffer bytes as a packed buffer (i.e. the standard IPC format body bytes) 1) The body contains a series of unsigned, little-endian 64-bit integer pairs to represent either shared or remote memory, schematically structured as + - The first two integers (e.g. the first 16 bytes) represent the *total* size (in bytes) of all buffers and the number of buffers in this message (and thus the number of following pairs of ``uint64``) + - Each subsequent pair of ``uint64`` values are an address / offset followed the length of that particular buffer. + * All unspecified bits (bits 32 - 55) of the tag are *reserved* for future use by potential updates to this protocol. For now they **MUST** be 0. @@ -300,8 +321,10 @@ showing how a client might handle the metadata and data streams: little-endian byte order. * If it is **not** an *End of Stream* message, the remaining bytes are the IPC Flatbuffer bytes which can be interpreted as normal. + * If the message has a body (i.e. Record Batch or Dictionary message) then the client should retrieve a tagged message from the Data Stream using the same sequence number. + * If it **is** an *End of Stream* message, then it is safe to close the metadata connection if there are no gaps in the sequence numbers received. @@ -310,12 +333,16 @@ showing how a client might handle the metadata and data streams: care about matching the lower 4 bytes to the sequence number) * Once recieved, the Most Significant Byte's value determines how the client processes the body data: + * If the most significant byte is 0: Then the body of the message is the raw IPC packed body buffers allowing it to easily be processed with the corresponding metadata header bytes. + * If the most significant byte is 1: The body of the message will consist of a series of pairs of unsigned, 64-bit integers in little-endian byte order. + * The first two integers represent *1)* the total size of all the body buffers together to allow for easy allocation if an intermediate buffer is needed and *2)* the number of buffers being sent (``nbuf``). + * The rest of the message will be ``nbuf`` pairs of integers, one for each buffer. Each pair is *1)* the address / offset of the buffer and *2)* the length of that buffer. Memory can then be retrieved via shared or remote memory routines based on the underlying transport. These addresses / offsets **MUST** From 298f803caa12cd52bcb52ce559848d4c8f378494 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Wed, 17 Apr 2024 11:14:21 -0400 Subject: [PATCH 14/30] more formatting fixes --- docs/source/format/DissociatedIPC.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 0f8994e8ac56..ddac6843cb3a 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -272,12 +272,12 @@ stream if that message has a body (i.e. a Record Batch or Dictionary message). T 1) The body contains a series of unsigned, little-endian 64-bit integer pairs to represent either shared or remote memory, schematically structured as - - The first two integers (e.g. the first 16 bytes) represent the *total* size (in bytes) - of all buffers and the number of buffers in this message (and thus the number of following - pairs of ``uint64``) + * The first two integers (e.g. the first 16 bytes) represent the *total* size (in bytes) + of all buffers and the number of buffers in this message (and thus the number of following + pairs of ``uint64``) - - Each subsequent pair of ``uint64`` values are an address / offset followed the length of - that particular buffer. + * Each subsequent pair of ``uint64`` values are an address / offset followed the length of + that particular buffer. * All unspecified bits (bits 32 - 55) of the tag are *reserved* for future use by potential updates to this protocol. For now they **MUST** be 0. @@ -322,11 +322,11 @@ showing how a client might handle the metadata and data streams: * If it is **not** an *End of Stream* message, the remaining bytes are the IPC Flatbuffer bytes which can be interpreted as normal. - * If the message has a body (i.e. Record Batch or Dictionary message) then the client should retrieve - a tagged message from the Data Stream using the same sequence number. + * If the message has a body (i.e. Record Batch or Dictionary message) then the client should retrieve + a tagged message from the Data Stream using the same sequence number. - * If it **is** an *End of Stream* message, then it is safe to close the metadata connection if there are - no gaps in the sequence numbers received. + * If it **is** an *End of Stream* message, then it is safe to close the metadata connection if there are + no gaps in the sequence numbers received. #. When a metadata message that requires a body is received, the tag mask of ``0x00000000FFFFFFFF`` **should** be used alongside the sequence number to match the message regardless of the higher bytes (e.g. we only From feb5eb170a1fb9a7753573153146b4b6effd393d Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Wed, 17 Apr 2024 12:01:13 -0400 Subject: [PATCH 15/30] some formatting changes --- docs/source/format/DissociatedIPC.rst | 38 +++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index ddac6843cb3a..9c3929ae1519 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -81,8 +81,6 @@ Goals Definitions ----------- -.. glossary:: - IPC Metadata The Flatbuffers message bytes that encompass the header of an Arrow IPC message @@ -104,24 +102,10 @@ Definitions The sequence number serves two purposes: To identify corresponding metadata and tagged body data messages and to ensure we do not rely on messages having to arrive in order. A client should use the sequence number to correctly order messages as - they arrive for processing. - - Backpressure - *Currently* this proposal does not specify any way to manage the backpressure of - messages to throttle for memory and bandwidth reasons. For now, this will be - **transport-defined** rather than lock into something sub-optimal. - - As usage among different transports and libraries grows, common patterns will emerge - that will allow for a generic, but efficient, way to handle backpressure across - different use cases. - - .. note:: - While the protocol itself is transport agnostic, the current usage and examples - only have been tested using UCX and libfabric transports so far, but that's all. + they arrive for processing. - -Protocol Description -==================== +The Protocol +============ A reference example implementation utilizing `libcudf`_ and `UCX`_ can be found at https://github.com/zeroshade/cudf-flight-ucx. @@ -182,6 +166,22 @@ encode the following URI query parameters: * With CUDA IPC, this would be the value of the base GPU pointer or memory handle, and subsequent addresses would be offsets from this base pointer. +Handling of Backpressure +------------------------ + +*Currently* this proposal does not specify any way to manage the backpressure of +messages to throttle for memory and bandwidth reasons. For now, this will be +**transport-defined** rather than lock into something sub-optimal. + +As usage among different transports and libraries grows, common patterns will emerge +that will allow for a generic, but efficient, way to handle backpressure across +different use cases. + +.. note:: + While the protocol itself is transport agnostic, the current usage and examples + only have been tested using UCX and libfabric transports so far, but that's all. + + Protocol Description ==================== From d24eef3240dc76be3e36b5cb197c2a6db3cf341d Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Mon, 22 Apr 2024 11:55:50 -0400 Subject: [PATCH 16/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Benjamin Kietzman --- docs/source/format/DissociatedIPC.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 9c3929ae1519..01df07b33455 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -51,7 +51,8 @@ However, there are use cases that aren't handled by this: * Constructing the IPC record batch message requires allocating a contiguous chunk of bytes and copying all of the data buffers into it, packed together - back-to-back. It's exceedingly difficult to zero-copy **create** IPC messages. + back-to-back. This pessimizes the common case of wrapping existing, directly + consumable data into an IPC message. * If the Arrow data is located in a shared memory location, there is no standard way to share the handle to the shared-memory across processes or transports that allow for remote memory accessing, such as UCX. From c6ca46bb07fcf9d1dd016e9fe0d5e250049f6088 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Mon, 22 Apr 2024 12:02:14 -0400 Subject: [PATCH 17/30] Update docs/source/format/DissociatedIPC.rst Co-authored-by: Benjamin Kietzman --- docs/source/format/DissociatedIPC.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 01df07b33455..69144bb06895 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -53,9 +53,9 @@ However, there are use cases that aren't handled by this: chunk of bytes and copying all of the data buffers into it, packed together back-to-back. This pessimizes the common case of wrapping existing, directly consumable data into an IPC message. -* If the Arrow data is located in a shared memory location, there is no standard - way to share the handle to the shared-memory across processes or transports that - allow for remote memory accessing, such as UCX. +* Even if Arrow data is located in a memory accessible across process boundaries + or transports (such as UCX), there is no standard way to specify that shared + location to consumers which could take advantage of it. * Arrow data located on a non-CPU device (such as a GPU) cannot be sent using Arrow IPC without having to copy the data back to the host device or copying the Flatbuffers metadata bytes into device memory. From be46c3ac4da4ca8139c4f8e3cc9dc2ebf3abfbe0 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Mon, 22 Apr 2024 12:47:40 -0400 Subject: [PATCH 18/30] update diagrams from feedback --- .../DissociatedIPC/SequenceDiagramSame.mmd | 16 +++++++-------- .../SequenceDiagramSame.mmd.svg | 2 +- .../SequenceDiagramSeparate.mmd | 20 +++++++++---------- .../SequenceDiagramSeparate.mmd.svg | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd index 4a8069b5459f..5b7d49982304 100644 --- a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd @@ -16,31 +16,31 @@ %% under the License. %% To generate the diagram, use mermaid-cli -%% Example: docker run --rm -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/SequenceDiagramSame.mmd +%% Example: docker run --rm `id -u`:`id -g` -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/SequenceDiagramSame.mmd sequenceDiagram participant C as Client participant S as Server activate C - C-->>+S: TAG: BODY: - S-->>C: MSG: [1] + + + C-->>+S: TaggedMessage(server.want_data, bytes=ID_of_desired_data) + S-->>C: Message(bytes([1]) + le_bytes(sequence_number) + schema_metadata) par loop each chunk - S-->>C: MSG: [1] + + + S-->>C: Message(bytes([1]) + le_bytes(sequence_number) + batch_metadata) end - S-->>C: [0] + + S-->>C: Message(bytes([0]) + le_bytes(sequence_number)) and loop each chunk alt - S-->>C: TAG: | BODY: + S-->>C: TaggedMessage((bytes[0] << 55) | le_bytes(sequence_number),
bytes=batch_data) else - S-->>C: TAG: | BODY: + S-->>C: TaggedMessage((bytes[1] << 55) | le_bytes(sequence_number),
bytes=uint64_pairs) end end end loop - C-->>S: TAG: BODY: + C-->>S: TaggedMessage(server.free_data, bytes=uint64_list) end deactivate S deactivate C diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg index a8ad6f9c2ef2..265594c30207 100644 --- a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg @@ -1 +1 @@ -ServerClientServerClientloop[each chunk]alt​loop[each chunk]par​loop​TAG: <want_data> BODY: <opaque ID>MSG: [1] + <sequence number> + <schema metadata>MSG: [1] + <sequence number> + <IPC metadata>[0] + <sequence number>TAG: <inline data> | <sequence number> BODY: <raw body bytes>TAG: <pointer list> | <sequence number> BODY: <pairs of uint64>TAG: <free_data> BODY: <list of uint64> \ No newline at end of file +ServerClientServerClientloop[each chunk]alt​loop[each chunk]par​loop​TaggedMessage(server.want_data, bytes=ID_of_desired_data)Message(bytes([1]) + le_bytes(sequence_number) + schema_metadata)Message(bytes([1]) + le_bytes(sequence_number) + batch_metadata)Message(bytes([0]) + le_bytes(sequence_number))TaggedMessage((bytes[0] << 55) | le_bytes(sequence_number),bytes=batch_data)TaggedMessage((bytes[1] << 55) | le_bytes(sequence_number),bytes=uint64_pairs)TaggedMessage(server.free_data, bytes=uint64_list) \ No newline at end of file diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd index a376e3e19d26..dafeb118e168 100644 --- a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd @@ -16,7 +16,7 @@ %% under the License. %% To generate the diagram, use mermaid-cli -%% Example: docker run --rm -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/SequenceDiagramSeparate.mmd +%% Example: docker run --rm -u `id -u`:`id -g` -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/SequenceDiagramSeparate.mmd sequenceDiagram participant D as Data Stream @@ -24,24 +24,24 @@ sequenceDiagram participant M as Metadata Stream activate C - C-->>+M: TAG: BODY: - C-->>+D: TAG: BODY: - M-->>C: MSG: [1] + + - loop each chunk + C-->>+M: TaggedMessage(server.want_data, bytes=ID_of_desired_data) + C-->>+D: TaggedMessage(server.want_data, bytes=ID_of_desired_data) + M-->>C: Message(bytes([1]) + le_bytes(sequence_number) + schema_metadata) + loop each batch par - M-->>C: MSG: [1] + + + M-->>C: Message(bytes([1]) + le_bytes(sequence_number) + batch_metadata) and alt - D-->>C: TAG: | BODY: + D-->>C: TaggedMessage((bytes[0] << 55) | le_bytes(sequence_number),
bytes=batch_data) else - D-->>C: TAG: | BODY: + D-->>C: TaggedMessage((bytes[1] << 55) | le_bytes(sequence_number),
bytes=uint64_pairs) end end end - M-->>C: [0] + + M-->>C: Message(bytes([0]) + le_bytes(sequence_number)) deactivate M loop - C-->>D: TAG: BODY: + C-->>D: TaggedMessage(server.free_data, bytes=uint64_list) end deactivate D deactivate C diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg index efb3b0a8f3e9..ef4415ec6140 100644 --- a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg @@ -1 +1 @@ -Metadata StreamClientData StreamMetadata StreamClientData Streamalt​par​loop[each chunk]loop​TAG: <want_data> BODY: <opaque ID>TAG: <want_data> BODY: <opaque ID>MSG: [1] + <sequence number> + <schema metadata>MSG: [1] + <sequence number> + <IPC metadata>TAG: <inline data> | <sequence number> BODY: <raw body bytes>TAG: <pointer list> | <sequence number> BODY: <pairs of uint64>[0] + <sequence number>TAG: <free_data> BODY: <list of uint64> \ No newline at end of file +Metadata StreamClientData StreamMetadata StreamClientData Streamalt​par​loop[each batch]loop​TaggedMessage(server.want_data, bytes=ID_of_desired_data)TaggedMessage(server.want_data, bytes=ID_of_desired_data)Message(bytes([1]) + le_bytes(sequence_number) + schema_metadata)Message(bytes([1]) + le_bytes(sequence_number) + batch_metadata)TaggedMessage((bytes[0] << 55) | le_bytes(sequence_number),bytes=batch_data)TaggedMessage((bytes[1] << 55) | le_bytes(sequence_number),bytes=uint64_pairs)Message(bytes([0]) + le_bytes(sequence_number))TaggedMessage(server.free_data, bytes=uint64_list) \ No newline at end of file From 77b4bd1376e63588801821d336bbb68b34d9760c Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Tue, 23 Apr 2024 12:49:08 -0400 Subject: [PATCH 19/30] add mermaid sphinx extension plus more diagrams --- docs/source/conf.py | 4 + docs/source/format/DissociatedIPC.rst | 82 ++++++++++++------- .../DissociatedIPC/ClientFlowchart.mmd.svg | 1 - .../SequenceDiagramSame.mmd.svg | 1 - .../SequenceDiagramSeparate.mmd.svg | 1 - 5 files changed, 58 insertions(+), 31 deletions(-) delete mode 100644 docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg delete mode 100644 docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg delete mode 100644 docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg diff --git a/docs/source/conf.py b/docs/source/conf.py index b487200555a0..413ca3367b88 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -591,6 +591,10 @@ mermaid_output_format = 'svg' +# -- Options for mermaid output ------------------------------------------- + +mermaid_output_format = 'svg' + def setup(app): # Use a config value to indicate whether CUDA API docs can be generated. # This will also rebuild appropriately when the value changes. diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 69144bb06895..5862ecc22439 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -73,37 +73,42 @@ Goals * Define a generic protocol for passing Arrow IPC data, not tied to any particular transport, that also allows for utilizing non-CPU device memory, shared memory, and newer "high performance" transports such as `UCX`_ or `libfabric`_. -* Allow for using :ref:`Flight RPC ` purely for control flow by separating - the stream of IPC metadata from IPC body bytes - + * This allows for the data in the body to be kept on non-CPU devices (like GPUs) without expensive device-to-host copies. +* Allow for using :ref:`Flight RPC ` purely for control flow by separating + the stream of IPC metadata from IPC body bytes + Definitions ----------- - IPC Metadata - The Flatbuffers message bytes that encompass the header of an Arrow IPC message - - Tag - A little-endian ``uint64`` value used as an ID for a message. Specific bits can - be masked to allow identifying messages by only a portion of the tag, leaving the - rest of the bits to be used for control flow or other message metadata. - - Sequence Number - A little-endian, 4-byte unsigned integer starting at 0 for a stream, indicating - the sequence order of messages. It is also used to identify specific messages to - tie the IPC metadata header to its corresponding body since the metadata and body - can be sent across separate pipes/streams/transports. - - If a sequence number reaches ``UINT32_MAX``, it should be allowed to roll over as - it is unlikely there would be enough unprocessed messages waiting to be processed - that would cause an overlap of sequence numbers. - - The sequence number serves two purposes: To identify corresponding metadata and - tagged body data messages and to ensure we do not rely on messages having to arrive - in order. A client should use the sequence number to correctly order messages as - they arrive for processing. +IPC Metadata + The Flatbuffers message bytes that encompass the header of an Arrow IPC message + +Tag + A little-endian ``uint64`` value used for flow control and used in determining + how to interpret the body of a message. Specific bits can be masked to allow + identifying messages by only a portion of the tag, leaving the rest of the bits + to be used for control flow or other message metadata. Some transports, such as + UCX, have built-in support for such tag values and will provide them in CPU + memory regardless of whether or not the body of the message may reside on a + non-CPU device. + +Sequence Number + A little-endian, 4-byte unsigned integer starting at 0 for a stream, indicating + the sequence order of messages. It is also used to identify specific messages to + tie the IPC metadata header to its corresponding body since the metadata and body + can be sent across separate pipes/streams/transports. + + If a sequence number reaches ``UINT32_MAX``, it should be allowed to roll over as + it is unlikely there would be enough unprocessed messages waiting to be processed + that would cause an overlap of sequence numbers. + + The sequence number serves two purposes: To identify corresponding metadata and + tagged body data messages and to ensure we do not rely on messages having to arrive + in order. A client should use the sequence number to correctly order messages as + they arrive for processing. The Protocol ============ @@ -190,12 +195,13 @@ There are two possibilities that can occur: 1. The streams of metadata and body data are sent across separate connections -.. figure:: ./DissociatedIPC/SequenceDiagramSeparate.mmd.svg +.. mermaid:: ./DissociatedIPC/SequenceDiagramSeparate.mmd + 2. The streams of metadata and body data are sent simultaneously across the same connection -.. figure:: ./DissociatedIPC/SequenceDiagramSame.mmd.svg +.. mermaid:: ./DissociatedIPC/SequenceDiagramSame.mmd Server Sequence --------------- @@ -225,6 +231,17 @@ opaque, binary identifier to indicate a particular dataset / data stream to send Upon receiving a ```` request, the server *should* respond by sending a stream of messages consisting of the following: +.. mermaid:: + + block-beta + columns 8 + + block:P["\n\n\n\nPrefix"]:5 + T["Message type\nByte 0"] + S["Sequence number\nBytes 1-4"] + end + H["Flatbuffer bytes\nRest of the message"]:3 + * A 5-byte prefix - The first byte of the message indicates the type of message, currently there are only @@ -262,6 +279,15 @@ For each IPC message in the stream of data, a **tagged** message **MUST** be sen stream if that message has a body (i.e. a Record Batch or Dictionary message). The :term:`tag ` for each message should be structured as follows: +.. mermaid:: + + block-beta + columns 8 + + S["Sequence number\nBytes 0-3"]:4 + U["Unused (Reserved)\nBytes 4-6"]:3 + T["Message type\nByte 7"]:1 + * The *least significant* 4-bytes (bits 0 - 31) of the tag should be the unsigned 32-bit, little-endian sequence number of the message. * The *most significant* byte (bits 56 - 63) of the tag indicates the message body **type** as an 8-bit @@ -304,7 +330,7 @@ A client for this protocol needs to concurrently handle both the data and metada messages which may either both come from the same server or different servers. Below is a flowchart showing how a client might handle the metadata and data streams: -.. figure:: ./DissociatedIPC/ClientFlowchart.mmd.svg +.. mermaid:: ./DissociatedIPC/ClientFlowchart.mmd #. First the client sends a tagged message using the ```` value it was provided in the URI as the tag, and the opaque ID as the body. diff --git a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg deleted file mode 100644 index a59ac8732b77..000000000000 --- a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd.svg +++ /dev/null @@ -1 +0,0 @@ -
recv untagged msg
get tagged msg
Data Stream
0
1
Most Significant
Byte
Request Msg
for Seq Num
Construct from
Metadata and Body
Get shared/remote
buffers
Construct from
Metadata and buffers
Output Batch
Meta Message
type 1
IPC has body
Schema Msg
type 0
Process IPC Header
Msg Type (byte 0)
Seq Num (bytes 1-5)
Get Corresponding
Tagged Msg
Store Schema
Indicate End of Stream
Client
Send <want_data> Msg
\ No newline at end of file diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg deleted file mode 100644 index 265594c30207..000000000000 --- a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd.svg +++ /dev/null @@ -1 +0,0 @@ -ServerClientServerClientloop[each chunk]alt​loop[each chunk]par​loop​TaggedMessage(server.want_data, bytes=ID_of_desired_data)Message(bytes([1]) + le_bytes(sequence_number) + schema_metadata)Message(bytes([1]) + le_bytes(sequence_number) + batch_metadata)Message(bytes([0]) + le_bytes(sequence_number))TaggedMessage((bytes[0] << 55) | le_bytes(sequence_number),bytes=batch_data)TaggedMessage((bytes[1] << 55) | le_bytes(sequence_number),bytes=uint64_pairs)TaggedMessage(server.free_data, bytes=uint64_list) \ No newline at end of file diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg deleted file mode 100644 index ef4415ec6140..000000000000 --- a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd.svg +++ /dev/null @@ -1 +0,0 @@ -Metadata StreamClientData StreamMetadata StreamClientData Streamalt​par​loop[each batch]loop​TaggedMessage(server.want_data, bytes=ID_of_desired_data)TaggedMessage(server.want_data, bytes=ID_of_desired_data)Message(bytes([1]) + le_bytes(sequence_number) + schema_metadata)Message(bytes([1]) + le_bytes(sequence_number) + batch_metadata)TaggedMessage((bytes[0] << 55) | le_bytes(sequence_number),bytes=batch_data)TaggedMessage((bytes[1] << 55) | le_bytes(sequence_number),bytes=uint64_pairs)Message(bytes([0]) + le_bytes(sequence_number))TaggedMessage(server.free_data, bytes=uint64_list) \ No newline at end of file From 8a8cbb4d1ad083943a8cfc2c2bc2b12e985251f9 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Wed, 24 Apr 2024 12:52:18 -0400 Subject: [PATCH 20/30] trampoline to avoid chrome dependency --- docs/mermaid.sh | 8 ++++++++ docs/source/conf.py | 2 ++ 2 files changed, 10 insertions(+) create mode 100755 docs/mermaid.sh diff --git a/docs/mermaid.sh b/docs/mermaid.sh new file mode 100755 index 000000000000..a7e16531b666 --- /dev/null +++ b/docs/mermaid.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +INDIR=`dirname $2` +INNAME=`basename $2` +OUTDIR=`dirname $4` +OUTNAME=`basename $4` + +docker run --rm -u `id -u`:`id -g` -v "$INDIR:/data" -v "$OUTDIR:/dataout" minlag/mermaid-cli $1 "/data/$INNAME" $3 "/dataout/$OUTNAME" diff --git a/docs/source/conf.py b/docs/source/conf.py index 413ca3367b88..f0dd14d48f03 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -595,6 +595,8 @@ mermaid_output_format = 'svg' +mermaid_cmd = os.path.abspath(os.path.join(os.getcwd(), "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/../mermaid.sh")) + def setup(app): # Use a config value to indicate whether CUDA API docs can be generated. # This will also rebuild appropriately when the value changes. From 668d5be8d87e900c7fab1424b16eed4e9fde082a Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Wed, 24 Apr 2024 12:53:51 -0400 Subject: [PATCH 21/30] fix license --- docs/mermaid.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/mermaid.sh b/docs/mermaid.sh index a7e16531b666..fbe6cad042f3 100755 --- a/docs/mermaid.sh +++ b/docs/mermaid.sh @@ -1,4 +1,21 @@ -#!/bin/bash +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. INDIR=`dirname $2` INNAME=`basename $2` From 6137525202da9f1b996916c9e6b319e788dd4d66 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Wed, 24 Apr 2024 13:56:28 -0400 Subject: [PATCH 22/30] screwed up the python path handling --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index f0dd14d48f03..7aece64d55d2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -595,7 +595,7 @@ mermaid_output_format = 'svg' -mermaid_cmd = os.path.abspath(os.path.join(os.getcwd(), "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/../mermaid.sh")) +mermaid_cmd = os.path.abspath(os.path.join(os.getcwd(), "../mermaid.sh")) def setup(app): # Use a config value to indicate whether CUDA API docs can be generated. From 6f44259b6cf4024ec063e99155c8cf01490dec31 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Wed, 24 Apr 2024 16:04:10 -0400 Subject: [PATCH 23/30] AHA dependency issues possibly solved? --- docs/mermaid.sh | 25 ------------------------- docs/source/conf.py | 2 +- 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100755 docs/mermaid.sh diff --git a/docs/mermaid.sh b/docs/mermaid.sh deleted file mode 100755 index fbe6cad042f3..000000000000 --- a/docs/mermaid.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -INDIR=`dirname $2` -INNAME=`basename $2` -OUTDIR=`dirname $4` -OUTNAME=`basename $4` - -docker run --rm -u `id -u`:`id -g` -v "$INDIR:/data" -v "$OUTDIR:/dataout" minlag/mermaid-cli $1 "/data/$INNAME" $3 "/dataout/$OUTNAME" diff --git a/docs/source/conf.py b/docs/source/conf.py index 7aece64d55d2..d00671021fea 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -595,7 +595,7 @@ mermaid_output_format = 'svg' -mermaid_cmd = os.path.abspath(os.path.join(os.getcwd(), "../mermaid.sh")) +mermaid_params = ['-p', '/puppeteer-config.json'] def setup(app): # Use a config value to indicate whether CUDA API docs can be generated. From 86b553c30a0b71f858de7d1fa9d8cbb55ab8d496 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Thu, 25 Apr 2024 13:28:16 -0400 Subject: [PATCH 24/30] update url for reference example impl --- docs/source/format/DissociatedIPC.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 5862ecc22439..47f6e2e9b4d3 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -113,8 +113,8 @@ Sequence Number The Protocol ============ -A reference example implementation utilizing `libcudf`_ and `UCX`_ can be found at -https://github.com/zeroshade/cudf-flight-ucx. +A reference example implementation utilizing `libcudf`_ and `UCX`_ can be found in the +`arrow-experiments repo `_. Requirements ------------ From c2238fb9d0fd5422c6e50c84c6f60ba56a5d5a46 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Fri, 26 Apr 2024 10:34:27 -0400 Subject: [PATCH 25/30] updates from feedback --- ci/docker/linux-apt-docs.dockerfile | 1 + docs/source/format/DissociatedIPC/ClientFlowchart.mmd | 3 --- docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd | 3 --- docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd | 3 --- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/ci/docker/linux-apt-docs.dockerfile b/ci/docker/linux-apt-docs.dockerfile index 1c916840e071..6b30a8106c07 100644 --- a/ci/docker/linux-apt-docs.dockerfile +++ b/ci/docker/linux-apt-docs.dockerfile @@ -53,6 +53,7 @@ RUN apt-get update -y && \ doxygen \ gi-docgen \ gobject-introspection \ + libasound2-dev && \ libcurl4-openssl-dev \ libfontconfig1-dev \ libfribidi-dev \ diff --git a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd index 275ce33df30f..652cabc1c742 100644 --- a/docs/source/format/DissociatedIPC/ClientFlowchart.mmd +++ b/docs/source/format/DissociatedIPC/ClientFlowchart.mmd @@ -15,9 +15,6 @@ %% specific language governing permissions and limitations %% under the License. -%% To generate the diagram, use mermaid-cli -%% Example: docker run --rm -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/ClientFlowchart.mmd - graph LR client((Client))-->c1{{Send #60;want_data#gt; Msg}} subgraph meta [Meta Message] diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd index 5b7d49982304..adf26bdc3276 100644 --- a/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSame.mmd @@ -15,9 +15,6 @@ %% specific language governing permissions and limitations %% under the License. -%% To generate the diagram, use mermaid-cli -%% Example: docker run --rm `id -u`:`id -g` -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/SequenceDiagramSame.mmd - sequenceDiagram participant C as Client participant S as Server diff --git a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd index dafeb118e168..11d2d9d6387e 100644 --- a/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd +++ b/docs/source/format/DissociatedIPC/SequenceDiagramSeparate.mmd @@ -15,9 +15,6 @@ %% specific language governing permissions and limitations %% under the License. -%% To generate the diagram, use mermaid-cli -%% Example: docker run --rm -u `id -u`:`id -g` -v $(pwd)/DissociatedIPC:/data minlag/mermaid-cli -i /data/SequenceDiagramSeparate.mmd - sequenceDiagram participant D as Data Stream participant C as Client From 74acc1ca35187c69f1f117c19534c7b51cad85b4 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Thu, 9 May 2024 14:38:39 -0400 Subject: [PATCH 26/30] no need for asound anymore --- ci/docker/linux-apt-docs.dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/docker/linux-apt-docs.dockerfile b/ci/docker/linux-apt-docs.dockerfile index 6b30a8106c07..3a8e86d5707a 100644 --- a/ci/docker/linux-apt-docs.dockerfile +++ b/ci/docker/linux-apt-docs.dockerfile @@ -52,8 +52,7 @@ RUN apt-get update -y && \ curl \ doxygen \ gi-docgen \ - gobject-introspection \ - libasound2-dev && \ + gobject-introspection \ libcurl4-openssl-dev \ libfontconfig1-dev \ libfribidi-dev \ From ab4bbe64328a37e23f8ec2f7b98872fbbae34260 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Thu, 9 May 2024 14:39:00 -0400 Subject: [PATCH 27/30] trim whitespace --- ci/docker/linux-apt-docs.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/docker/linux-apt-docs.dockerfile b/ci/docker/linux-apt-docs.dockerfile index 3a8e86d5707a..1c916840e071 100644 --- a/ci/docker/linux-apt-docs.dockerfile +++ b/ci/docker/linux-apt-docs.dockerfile @@ -52,7 +52,7 @@ RUN apt-get update -y && \ curl \ doxygen \ gi-docgen \ - gobject-introspection \ + gobject-introspection \ libcurl4-openssl-dev \ libfontconfig1-dev \ libfribidi-dev \ From a8f83f99ba73782ad66b9fc7859ae29ef3b8f568 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Thu, 9 May 2024 14:39:47 -0400 Subject: [PATCH 28/30] remove duplicate --- docs/source/conf.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index d00671021fea..b487200555a0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -591,12 +591,6 @@ mermaid_output_format = 'svg' -# -- Options for mermaid output ------------------------------------------- - -mermaid_output_format = 'svg' - -mermaid_params = ['-p', '/puppeteer-config.json'] - def setup(app): # Use a config value to indicate whether CUDA API docs can be generated. # This will also rebuild appropriately when the value changes. From c063aae464e78d0b40014750631757f10648d8c1 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Thu, 9 May 2024 14:42:27 -0400 Subject: [PATCH 29/30] trinm whitespace --- docs/source/format/DissociatedIPC.rst | 78 +++++++++++++-------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 47f6e2e9b4d3..194fdd608d7d 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -59,7 +59,7 @@ However, there are use cases that aren't handled by this: * Arrow data located on a non-CPU device (such as a GPU) cannot be sent using Arrow IPC without having to copy the data back to the host device or copying the Flatbuffers metadata bytes into device memory. - + * By the same token, receiving IPC messages into device memory would require performing a copy of the Flatbuffers metadata back to the host CPU device. This is due to the fact that the IPC stream interleaves data and metadata across a @@ -88,16 +88,16 @@ IPC Metadata Tag A little-endian ``uint64`` value used for flow control and used in determining - how to interpret the body of a message. Specific bits can be masked to allow - identifying messages by only a portion of the tag, leaving the rest of the bits + how to interpret the body of a message. Specific bits can be masked to allow + identifying messages by only a portion of the tag, leaving the rest of the bits to be used for control flow or other message metadata. Some transports, such as - UCX, have built-in support for such tag values and will provide them in CPU + UCX, have built-in support for such tag values and will provide them in CPU memory regardless of whether or not the body of the message may reside on a non-CPU device. Sequence Number - A little-endian, 4-byte unsigned integer starting at 0 for a stream, indicating - the sequence order of messages. It is also used to identify specific messages to + A little-endian, 4-byte unsigned integer starting at 0 for a stream, indicating + the sequence order of messages. It is also used to identify specific messages to tie the IPC metadata header to its corresponding body since the metadata and body can be sent across separate pipes/streams/transports. @@ -105,10 +105,10 @@ Sequence Number it is unlikely there would be enough unprocessed messages waiting to be processed that would cause an overlap of sequence numbers. - The sequence number serves two purposes: To identify corresponding metadata and + The sequence number serves two purposes: To identify corresponding metadata and tagged body data messages and to ensure we do not rely on messages having to arrive in order. A client should use the sequence number to correctly order messages as - they arrive for processing. + they arrive for processing. The Protocol ============ @@ -122,10 +122,10 @@ Requirements A transport implementing this protocol **MUST** provide two pieces of functionality: * Message sending - - * Delimited messages (like gRPC) as opposed to non-delimited streams (like plain TCP + + * Delimited messages (like gRPC) as opposed to non-delimited streams (like plain TCP without further framing). - + * Alternatively, a framing mechanism like the :ref:`encapsulated message format ` for the IPC protocol can be used while leaving out the body bytes. @@ -138,7 +138,7 @@ A transport implementing this protocol **MUST** provide two pieces of functional URI Specification ----------------- -When providing a URI to a consumer to contact for use with this protocol (such as via +When providing a URI to a consumer to contact for use with this protocol (such as via the :ref:`Location URI for Flight `), the URI should specify a scheme like *ucx:* or *fabric:*, that is easily identifiable. In addition, the URI should encode the following URI query parameters: @@ -148,7 +148,7 @@ encode the following URI query parameters: transport schemes that get used with it. * ``want_data`` - **REQUIRED** - uint64 integer value - + * This value should be used to tag an initial message to the server to initiate a data transfer. The body of the initiating message should be an opaque binary identifier of the data stream being requested (like the ``Ticket`` in the Flight RPC protocol) @@ -176,15 +176,15 @@ Handling of Backpressure ------------------------ *Currently* this proposal does not specify any way to manage the backpressure of -messages to throttle for memory and bandwidth reasons. For now, this will be -**transport-defined** rather than lock into something sub-optimal. +messages to throttle for memory and bandwidth reasons. For now, this will be +**transport-defined** rather than lock into something sub-optimal. As usage among different transports and libraries grows, common patterns will emerge that will allow for a generic, but efficient, way to handle backpressure across different use cases. .. note:: - While the protocol itself is transport agnostic, the current usage and examples + While the protocol itself is transport agnostic, the current usage and examples only have been tested using UCX and libfabric transports so far, but that's all. @@ -218,7 +218,7 @@ The standing state of the server is waiting for a **tagged** message with a spec ```` tag value to initiate a transfer. This ```` value is defined by the server and propagated to any clients via the URI they are provided. This protocol does not prescribe any particular value so that it will not interfere with any other -existing protocols that rely on tag values. The body of that message will contain an +existing protocols that rely on tag values. The body of that message will contain an opaque, binary identifier to indicate a particular dataset / data stream to send. .. note:: @@ -235,7 +235,7 @@ of messages consisting of the following: block-beta columns 8 - + block:P["\n\n\n\nPrefix"]:5 T["Message type\nByte 0"] S["Sequence number\nBytes 1-4"] @@ -243,22 +243,22 @@ of messages consisting of the following: H["Flatbuffer bytes\nRest of the message"]:3 * A 5-byte prefix - + - The first byte of the message indicates the type of message, currently there are only two allowed message types (more types may get added in the future): - + 0) End of Stream 1) Flatbuffers IPC Metadata Message - + - the next 4-bytes are a little-endian, unsigned 32-bit integer indicating the sequence number of the message. The first message in the stream (**MUST** always be a schema message) **MUST** - have a sequence number of ``0``. Each subsequent message **MUST** increment the number by + have a sequence number of ``0``. Each subsequent message **MUST** increment the number by ``1``. * The full Flatbuffers bytes of an Arrow IPC header As defined in the Arrow IPC format, each metadata message can represent a chunk of data or -dictionaries for use by the stream of data. +dictionaries for use by the stream of data. After sending the last metadata message, the server **MUST** indicate the end of the stream by sending a message consisting of **exactly** 5 bytes: @@ -276,10 +276,10 @@ message with the ```` tag value, whose body indicates the dataset / d to send to the client. For each IPC message in the stream of data, a **tagged** message **MUST** be sent on the data -stream if that message has a body (i.e. a Record Batch or Dictionary message). The +stream if that message has a body (i.e. a Record Batch or Dictionary message). The :term:`tag ` for each message should be structured as follows: -.. mermaid:: +.. mermaid:: block-beta columns 8 @@ -288,21 +288,21 @@ stream if that message has a body (i.e. a Record Batch or Dictionary message). T U["Unused (Reserved)\nBytes 4-6"]:3 T["Message type\nByte 7"]:1 -* The *least significant* 4-bytes (bits 0 - 31) of the tag should be the unsigned 32-bit, little-endian sequence +* The *least significant* 4-bytes (bits 0 - 31) of the tag should be the unsigned 32-bit, little-endian sequence number of the message. * The *most significant* byte (bits 56 - 63) of the tag indicates the message body **type** as an 8-bit unsigned integer. Currently only two message types are specified, but more can be added as needed to expand the protocol: - + 0) The body contains the raw body buffer bytes as a packed buffer (i.e. the standard IPC format body bytes) 1) The body contains a series of unsigned, little-endian 64-bit integer pairs to represent either shared or remote memory, schematically structured as - + * The first two integers (e.g. the first 16 bytes) represent the *total* size (in bytes) of all buffers and the number of buffers in this message (and thus the number of following pairs of ``uint64``) - + * Each subsequent pair of ``uint64`` values are an address / offset followed the length of that particular buffer. @@ -319,7 +319,7 @@ stream if that message has a body (i.e. a Record Batch or Dictionary message). T After sending the last tagged IPC body message, the server should maintain the connection and wait for tagged ```` messages. The structure of these ```` messages is simple: one or more unsigned, little-endian 64-bit integers which indicate the addresses/offsets that can -be freed. +be freed. Once there are no more outstanding addresses to be freed, the work for this stream is complete. @@ -334,28 +334,28 @@ showing how a client might handle the metadata and data streams: #. First the client sends a tagged message using the ```` value it was provided in the URI as the tag, and the opaque ID as the body. - + * If the metadata and data servers are separate, then a ```` message needs to be sent - separately to each. + separately to each. * In either scenario, the metadata and data streams can be processed concurrently and/or asynchronously depending on the nature of the transports. #. For each **untagged** message the client receives in the metadata stream: - + * The first byte of the message indicates whether it is an *End of Stream* message (value ``0``) or a metadata message (value ``1``). - * The next 4 bytes are the sequence number of the message, an unsigned 32-bit integer in + * The next 4 bytes are the sequence number of the message, an unsigned 32-bit integer in little-endian byte order. * If it is **not** an *End of Stream* message, the remaining bytes are the IPC Flatbuffer bytes which - can be interpreted as normal. - + can be interpreted as normal. + * If the message has a body (i.e. Record Batch or Dictionary message) then the client should retrieve a tagged message from the Data Stream using the same sequence number. - + * If it **is** an *End of Stream* message, then it is safe to close the metadata connection if there are no gaps in the sequence numbers received. -#. When a metadata message that requires a body is received, the tag mask of ``0x00000000FFFFFFFF`` **should** +#. When a metadata message that requires a body is received, the tag mask of ``0x00000000FFFFFFFF`` **should** be used alongside the sequence number to match the message regardless of the higher bytes (e.g. we only care about matching the lower 4 bytes to the sequence number) @@ -364,7 +364,7 @@ showing how a client might handle the metadata and data streams: * If the most significant byte is 0: Then the body of the message is the raw IPC packed body buffers allowing it to easily be processed with the corresponding metadata header bytes. - * If the most significant byte is 1: The body of the message will consist of a series of pairs of + * If the most significant byte is 1: The body of the message will consist of a series of pairs of unsigned, 64-bit integers in little-endian byte order. * The first two integers represent *1)* the total size of all the body buffers together to allow From ccf1c876dbfc266c20b30f2737cd14ea4e59fe28 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Thu, 9 May 2024 14:44:55 -0400 Subject: [PATCH 30/30] newline at end of file --- docs/source/format/DissociatedIPC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/format/DissociatedIPC.rst b/docs/source/format/DissociatedIPC.rst index 194fdd608d7d..0b0861399cb2 100644 --- a/docs/source/format/DissociatedIPC.rst +++ b/docs/source/format/DissociatedIPC.rst @@ -400,4 +400,4 @@ Please chime in using the Arrow Developers Mailing list: https://arrow.apache.or .. _Flatbuffers: https://github.com/google/flatbuffers .. _UCX: https://openucx.org/ .. _libfabric: https://ofiwg.github.io/libfabric/ -.. _libcudf: https://docs.rapids.ai/api \ No newline at end of file +.. _libcudf: https://docs.rapids.ai/api