|
| 1 | +<!-- |
| 2 | +SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +SPDX-License-Identifier: Apache-2.0 |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +--> |
| 17 | + |
| 18 | +# dynamo.connect.Connector |
| 19 | + |
| 20 | +Core class for managing the connection between workers in a distributed environment. |
| 21 | +Use this class to create readable and writable operations, or read and write data to remote workers. |
| 22 | + |
| 23 | +This class is responsible for interfacing with the NIXL-based RDMA subsystem and providing a "Pythonic" interface |
| 24 | +with which to utilize GPU Direct RDMA accelerated data transfers between models hosted by different workers in a Dynamo pipeline. |
| 25 | +The connector provides two methods of moving data between workers: |
| 26 | + |
| 27 | + - Preparing local memory to be written to by a remote worker. |
| 28 | + |
| 29 | + - Preparing local memory to be read by a remote worker. |
| 30 | + |
| 31 | +In both cases, local memory is registered with the NIXL-based RDMA subsystem via the [`Descriptor`](#descriptor) class and provided to the connector. |
| 32 | +The connector then configures the RDMA subsystem to expose the memory for the requested operation and returns an operation control object. |
| 33 | +The operation control object, either a [`ReadableOperation`](readable_operation.md) or a [`WritableOperation`](writable_operation.md), |
| 34 | +provides RDMA metadata ([RdmaMetadata](rdma_metadata.md)) via its `.metadata()` method, functionality to query the operation's current state, as well as the ability to cancel the operation prior to its completion. |
| 35 | + |
| 36 | +The RDMA metadata must be provided to the remote worker expected to complete the operation. |
| 37 | +The metadata contains required information (identifiers, keys, etc.) which enables the remote worker to interact with the provided memory. |
| 38 | + |
| 39 | +> [!Warning] |
| 40 | +> RDMA metadata contains a worker's address as well as security keys to access specific registered memory descriptors. |
| 41 | +> This data provides direct memory access between workers, and should be considered sensitive and therefore handled accordingly. |
| 42 | +
|
| 43 | + |
| 44 | +## Example Usage |
| 45 | + |
| 46 | +```python |
| 47 | + @async_on_start |
| 48 | + async def async_init(self): |
| 49 | + runtime = dynamo_context["runtime"] |
| 50 | + |
| 51 | + self.connector = dynamo.connect.Connector(runtime=runtime) |
| 52 | + await self.connector.initialize() |
| 53 | +``` |
| 54 | + |
| 55 | +> [!Tip] |
| 56 | +> See [`ReadOperation`](read_operation.md#example-usage), [`ReadableOperation`](readable_operation.md#example-usage), |
| 57 | +> [`WritableOperation`](writable_operation.md#example-usage), and [`WriteOperation`](write_operation.md#example-usage) |
| 58 | +> for additional examples. |
| 59 | +
|
| 60 | + |
| 61 | +## Methods |
| 62 | + |
| 63 | +### `begin_read` |
| 64 | + |
| 65 | +Creates a [`ReadOperation`](read_operation.md) for transferring data from a remote worker. |
| 66 | + |
| 67 | +To create the operation, the serialized request from a remote worker's [`ReadableOperation`](readable_operation.md) |
| 68 | +along with a matching set of local memory descriptors which reference memory intended to receive data from the remote worker |
| 69 | +must be provided. |
| 70 | +The serialized request must be transferred from the remote to the local worker via a secondary channel, most likely HTTP or TCP+NATS. |
| 71 | + |
| 72 | +Once created, data transfer will begin immediately. |
| 73 | + |
| 74 | +Disposal of the object will instruct the RDMA subsystem to cancel the operation, |
| 75 | +therefore the operation should be awaited until completed unless cancellation is intended. |
| 76 | + |
| 77 | +Use [`.wait_for_completion()`](read_operation.md#wait_for_completion) to block the caller until the operation has completed or encountered an error. |
| 78 | + |
| 79 | +### `begin_write` |
| 80 | + |
| 81 | +Creates a [`WriteOperation`](write_operation.md) for transferring data to a remote worker. |
| 82 | + |
| 83 | +To create the operation, the serialized request from a remote worker's [`WritableOperation`](writable_operation.md) |
| 84 | +along with a matching set of local memory descriptors which reference memory to be transferred to the remote worker |
| 85 | +must be provided. |
| 86 | +The serialized request must be transferred from the remote to the local worker via a secondary channel, most likely HTTP or TCP+NATS. |
| 87 | + |
| 88 | +Once created, data transfer will begin immediately. |
| 89 | + |
| 90 | +Disposal of the object will instruct the RDMA subsystem to cancel the operation, |
| 91 | +therefore the operation should be awaited until completed unless cancellation is intended. |
| 92 | + |
| 93 | +Use [`.wait_for_completion()`](write_operation.md#wait_for_completion) to block the caller until the operation has completed or encountered an error. |
| 94 | + |
| 95 | +### `create_readable` |
| 96 | + |
| 97 | +Creates a [`ReadableOperation`](readable_operation.md) for transferring data to a remote worker. |
| 98 | + |
| 99 | +To create the operation, a set of local memory descriptors must be provided that reference memory intended to be transferred to a remote worker. |
| 100 | +Once created, the memory referenced by the provided descriptors becomes immediately readable by a remote worker with the necessary metadata. |
| 101 | +The metadata required to access the memory referenced by the provided descriptors is accessible via the operation's `.metadata()` method. |
| 102 | +Once acquired, the metadata needs to be provided to a remote worker via a secondary channel, most likely HTTP or TCP+NATS. |
| 103 | + |
| 104 | +Disposal of the object will instruct the RDMA subsystem to cancel the operation, |
| 105 | +therefore the operation should be awaited until completed unless cancellation is intended. |
| 106 | + |
| 107 | +Use [`.wait_for_completion()`](readable_operation.md#wait_for_completion) to block the caller until the operation has completed or encountered an error. |
| 108 | + |
| 109 | +### `create_writable` |
| 110 | + |
| 111 | +Creates a [`WritableOperation`](writable_operation.md) for transferring data from a remote worker. |
| 112 | + |
| 113 | +To create the operation, a set of local memory descriptors must be provided which reference memory intended to receive data from a remote worker. |
| 114 | +Once created, the memory referenced by the provided descriptors becomes immediately writable by a remote worker with the necessary metadata. |
| 115 | +The metadata required to access the memory referenced by the provided descriptors is accessible via the operation's `.metadata()` method. |
| 116 | +Once acquired, the metadata needs to be provided to a remote worker via a secondary channel, most likely HTTP or TCP+NATS. |
| 117 | + |
| 118 | +Disposal of the object will instruct the RDMA subsystem to cancel the operation, |
| 119 | +therefore the operation should be awaited until completed unless cancellation is intended. |
| 120 | + |
| 121 | +Use [`.wait_for_completion()`](writable_operation.md#wait_for_completion) to block the caller until the operation has completed or encountered an error. |
| 122 | + |
| 123 | + |
| 124 | +## Related Classes |
| 125 | + |
| 126 | + - [Descriptor](descriptor.md) |
| 127 | + - [Device](device.md) |
| 128 | + - [OperationStatus](operation_status.md) |
| 129 | + - [RdmaMetadata](rdma_metadata.md) |
| 130 | + - [ReadOperation](read_operation.md) |
| 131 | + - [ReadableOperation](readable_operation.md) |
| 132 | + - [WritableOperation](writable_operation.md) |
| 133 | + - [WriteOperation](write_operation.md) |
0 commit comments