Debian Codegraph @

Documentation/tag_matching.md

raw
1 # Hardware tag matching
2
3 ## Introduction
4
5 The MPI standard defines a set of rules, known as tag-matching, for matching
6 source send operations to destination receives according to the following
7 attributes:
8
9 * Communicator
10 * User tag - wild card may be specified by the receiver
11 * Source rank - wild card may be specified by the receiver
12 * Destination rank - wild card may be specified by the receiver
13
14 These matching attributes are specified by all Send and Receive operations.
15 Send operations from a given source to a given destination are processed in
16 the order in which the Sends were posted. Receive operations are associated
17 with the earliest send operation (from any source) that matches the
18 attributes, in the order in which the Receives were posted. Note that Receive
19 tags are not necessarily consumed in the order they are created, e.g., a later
20 generated tag may be consumed if earlier tags do not satisfy the matching
21 rules.
22
23 When a message arrives at the receiver, MPI implementations often classify it
24 as either 'expected' or 'unexpected' according to whether a Receive operation
25 with a matching tag has already been posted by the application. In the
26 expected case, the message may be processed immediately. In the unexpected
27 case, the message is saved in an unexpected message queue, and will be
28 processed when a matching Receive operation is posted.
29
30 To bound the amount of memory to hold unexpected messages, MPI implementations
31 use 2 data transfer protocols. The 'eager' protocol is used for small
32 messages. Eager messages are sent without any prior synchronization and
33 processed/buffered at the receiver. Typically, with RDMA, a single RDMA-Send
34 operation is used to transfer the data.
35
36 The 'rendezvous' protocol is used for large messages. Initially, only the
37 message tag is sent along with some meta-data. Only when the tag is matched to
38 a Receive operation, will the receiver initiate the corresponding data
39 transfer. A common RDMA implementation is to send the message tag with an
40 RDMA-Send, and transfer the data with an RDMA-Read issued by the receiver.
41 When the transfer is complete, the receiver will notify the sender that its
42 buffer may be freed using an RDMA-Send.
43
44 ## RDMA tag-matching offload
45
46 Tag-matching offload satisfies the following principals:
47 - Tag-matching is viewed as an RDMA application, and thus does not affect the
48 RDMA transport in any way [(*)](#m1)
49 - Tag-matching processing will be split between HW and SW.
50 * HW will hold a bounded prefix of Receive tags
51 - HW will process and transfer any expected message that matches a tag held
52 in HW.
53 * In case the message uses the rendezvous protocol, HW will also initiate
54 the RDMA-Read data transfer and send a notification message when the
55 data transfer completes.
56 - SW will handle any message that is either unexpected or whose tag is not
57 held in HW.
58
59 <a name="m1">(*)</a>
60 This concept can apply to additional application-specific offloads in the
61 future.
62
63 Tag-matching is initially defined for RC transport. Tag-matching messages are
64 encapsulated in RDMA-Send messages and contain the following headers:
65
66 ```
67 0 1 2 3
68 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
69 Tag Matching Header (TMH):
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 | Operation | reserved |
72 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 | User data (optional) |
74 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 | Tag |
76 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 | Tag |
78 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79
80 Rendezvous Header (RVH):
81 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 | Virtual Address |
83 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
84 | Virtual Address |
85 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
86 | Remote Key |
87 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88 | Length |
89 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 ```
91
92 Tag-matching messages always contain a TMH. An RHV is added for Rendezvous
93 request messages. The following message formats are defined:
94 - Eager request: TMH | payload
95 - Rendezvous request: TMH | RHV | optional meta-data [(**)](#m2)
96 - Rendezvous response: TMH
97
98 Note that rendezvous data transfers are standard RDMA-Reads
99
100 <a name="m2">(**)</a>
101 Rendezvous request messages may also arrive unexpected; in this case, the
102 message is handled in SW, optionally leveraging additional meta-data passed by
103 the sender.
104
105 As tag-matching messages are standard RDMA-Sends, no special HW support is
106 needed at the sender. At the receiver, we introduce a new SRQ type - a
107 Tag-Matching SRQ (TM-SRQ). The TM-SRQ forms the serialization point for
108 matching messages coming from any of the associated RC connections, and reports
109 all tag matching completions and events to a dedicated CQ.
110 2 kinds of buffers may be posted to the TM-SRQ:
111 - Buffers associated with tags (tagged-buffers), which are used when a match
112 is made by HW
113 - Standard SRQ buffers, which are used for unexpected messages (from HW's
114 perspective)
115 When a message is matched by HW, the payload is transferred directly to the
116 application buffer (both in the eager and the rendezvous case), while skipping
117 any TM headers. Otherwise, the entire message, including any TM headers, is
118 scattered to the SRQ buffer.
119
120 Since unexpected messages are handled in SW, there exists an inherent race
121 between the arrival of messages from the wire and posting of new tagged
122 buffers. For example, consider 2 incoming messages m1 and m2 and matching
123 buffers b1 and b2 that are posted asynchronously. If b1 is posted after m1
124 arrives but before m2, m1 would be delivered as an unexpected message while m2
125 would match b1, violating the ordering rules.
126
127 Consequently, whenever HW deems a message unexpected, tag matching must be
128 disabled for new tags until SW and HW synchronize. This synchronization is
129 achieved by reporting to HW the number of unexpected messages handled by SW
130 (with respect to the current posted tags). When the SW and HW are in synch, tag
131 matching resumes normally.
132
133 ## Tag Matching Verbs
134
135 ### Capabilities
136
137 Tag matching capabilities are queried by ibv_query_device_ex(), and report the
138 following attributes:
139
140 * **max_rndv_hdr_size** - Max size of rendezvous request header
141 * **max_num_tags** - Max number of tagged buffers in a TM-SRQ matching list
142 * **max_ops** - Max number of outstanding tag matching list operations
143 * **max_sge** - Max number of SGEs in a tagged buffer
144 * **flags** - the following flags are currently defined:
145 - IBV_TM_CAP_RC - Support tag matching on RC transport
146
147
148 ### TM-SRQ creation
149
150 TM-SRQs are created by the ibv_create_srq_ex() Verb, which accepts the
151 following new attributes:
152 * **srq_type** - set to **IBV_SRQT_TM**
153 * **comp_mask** - set the **IBV_SRQ_INIT_ATTR_TM** flag
154 * **tm_cap** - TM properties for this TM-SRQ; defined as follows:
155
156 ```h
157 struct ibv_tm_cap {
158 uint32_t max_num_tags; /* Matching list size */
159 uint32_t max_ops; /* Number of outstanding TM operations */
160 }
161 ```
162 Similarly to XRC SRQs, a TM-SRQ has a dedicated CQ.
163
164 RC QPs are associated with the TM-SRQ just like standard SRQs. However, the
165 ownership of the QP's Send Queue is passed to the TM-SRQ, which uses it to
166 initiate rendezvous RDMA-Reads. Receive completions are reported to the
167 TM-SRQ's CQ.
168
169
170 ### Managing TM receive buffers
171
172 Untagged (unexpected) buffers are posted using the standard
173 **ibv_post_srq_recv**() Verb.
174
175 Tagged buffers are manipulated by a new **ibv_post_srq_ops**() Verb:
176
177 ```h
178 int ibv_post_srq_ops(struct ibv_srq *srq, struct ibv_ops_wr *wr,
179 struct ibv_ops_wr **bad_wr);
180 ```
181 ```h
182 struct ibv_ops_wr {
183 uint64_t wr_id; /* User defined WR ID */
184 /* Pointer to next WR in list, NULL if last WR */
185 struct ibv_ops_wr *next;
186 enum ibv_ops_wr_opcode opcode; /* From enum ibv_ops_wr_opcode */
187 int flags; /* From enum ibv_ops_flags */
188 struct {
189 /* Number of unexpected messages
190 * handled by SW */
191 uint32_t unexpected_cnt;
192 /* Input parameter for the DEL opcode
193 * and output parameter for the ADD opcode */
194 uint32_t handle;
195 struct {
196 /* WR ID for TM_RECV */
197 uint64_t recv_wr_id;
198 struct ibv_sge *sg_list;
199 int num_sge;
200 uint64_t tag;
201 uint64_t mask;
202 } add;
203 } tm;
204 };
205 ```
206
207 The following opcodes are defined:
208
209 Opcode **IBV_WR_TAG_ADD** - add a tagged buffer entry to the tag matching list.
210 The input consists of an SGE list, a tag, a mask (matching parameters), and the
211 latest unexpected message count. A handle that uniquely identifies the entry is
212 returned upon success.
213
214 Opcode **IBV_WR_TAG_DEL** - delete a tag entry.
215 The input is an entry handle returned from a previous **IBV_WR_TAG_ADD**
216 operation, and the latest unexpected message count.
217
218 Note that the operation may fail if the associated tag was consumed by an
219 incoming message. In this case **IBV_WC_TM_ERR** status will be returned in WC.
220
221 Opcode **IBV_WR_TAG_SYNC** - report the number of unexpected messages handled by
222 the SW.
223 The input comprises only the unexpected message count. To reduce explicit
224 synchronization to a minimum, all completions indicate when synchronization is
225 necessary by setting the **IBV_WC_TM_SYNC_REQ** flag.
226
227 **ibv_post_srq_ops**() operations are non-signaled by default. To request an
228 explicit completion for a given operation, the standard **IBV_OPS_SIGNALED**
229 flag must be set. The number of outstanding tag-manipulation operations must
230 not exceed the **max_ops** capability.
231
232 While **wr_id** identifies the tag manipulation operation itself, the
233 **recv_wr_id** field is used to identify the tagged buffer in receive
234 completions.
235
236
237 ### Sending TM messages
238
239 TM messages are sent using standard RC Send operations. A TM message comprises
240 a Tag-Matching Header (TMH), an optional Rendezvous Header (RVH), and
241 a payload.
242
243 TMH and RVH are defined in infiniband/tm_types.h:
244
245 ```h
246 struct ibv_tmh {
247 uint8_t opcode;
248 uint8_t reserved[3];
249 __be32 app_ctx;
250 __be64 tag;
251 };
252 ```
253 ```h
254 struct ibv_rvh {
255 __be64 va;
256 __be32 rkey;
257 __be32 len;
258 };
259 ```
260
261 The following opcodes are defined:
262
263 * **IBV_TM_NO_TAG** - Send a message without a tag.
264 Such a message will always be treated as unexpected by the receiver TM-SRQ.
265 Any data following the opcode is ignored by the tag matching logic, and the
266 message is delivered in its entirety (including the opcode) to the standard
267 SRQ buffer.
268
269 * **IBV_TM_OP_EAGER** - Send an eager tagged message.
270 The message consists of a TMH followed by payload.
271
272 * **IBV_TM_OP_RNDV** - Send a tagged rendezvous request.
273 The message consists of a TMH, an RVH, and optional additional data (which may
274 be inspected by receiver SW if the message is deemed unexpected). The RVH must
275 refer to a registered buffer containing the rendezvous payload. The total
276 rendezvous message size must not exceed the **max_rndv_hdr_size** capability.
277 The Sender must consider the operation outstanding until a TM message with the
278 **IBV_TM_OP_FIN** opcode is received, after which the buffer may be deregistered
279 and freed.
280
281 * **IBV_TM_OP_FIN** - Send a rendezvous completion indication.
282 The message consists of a copy of the original TMH and RVH of the rendezvous
283 request, apart the opcode. This message is sent after the receiver has
284 completed the transfer of the rendezvous payload by an RDMA-read operation. It
285 may be sent either by HW or SW, depending on whether the rendezvous request
286 was handled as expected or unexpected by the TM-SRQ.
287
288
289 ### TM completion processing
290
291 There are 2 types of TM completions: tag-manipulation and receive completions.
292
293 Tag-manipulation operations generate the following completion opcodes:
294 * **IBV_WC_TM_ADD** - completion of a tag addition operation
295 * **IBV_WC_TM_DEL** - completion of a tag removal operation
296 * **IBV_WC_TM_SYNC** - completion of a synchronization operation
297
298 These completions are complemented by the **IBV_WC_TM_SYNC_REQ** flag, which
299 indicates whether further HW synchronization is needed.
300
301 TM receive completions generate the following completion codes:
302 * **IBV_WC_RECV** - standard SRQ completion; used for unexpected messages
303 * **IBV_WC_TM_NO_TAG** - completion of a message sent with the
304 **IBV_TM_NO_TAG** opcode.
305 * **IBV_WC_TM_RECV** - completion of a tag-matching operation
306
307 The **IBV_WC_TM_RECV** completion is complemented by the following completion
308 flags:
309 - **IBV_WC_TM_MATCH** - a match was performed
310 - **IBV_WC_TM_DATA_VALID** - all data of the matched message has been
311 delivered to memory
312
313 In single-packet eager messages, both flags are set. When larger messages or
314 rendezvous transfers are involved, matching and data transfer completion are
315 distinct events that generate 2 completion events for the same **recv_wr_id**.
316 While data transfer completions may be arbitrarily delayed depending on
317 message size, matching completion is reported immediately and is always
318 serialized with respect to other matches and the completion of unexpected
319 messages.
320
321 In addition, **IBV_WC_TM_RECV** completions provide further information about
322 the matched message. This information is obtained using extended CQ processing
323 via the following extractor function:
324
325 ```h
326 static inline void ibv_wc_read_tm_info(struct ibv_cq_ex *cq,
327 struct ibv_wc_tm_info *tm_info);
328 ```
329 ```h
330 struct ibv_wc_tm_info {
331 uint64_t tag; /* tag from TMH */
332 uint32_t priv; /* opaque user data from TMH */
333 };
334 ```
335
336 Finally, when a posted tagged buffer is insufficient to hold the data of a
337 rendezvous request, the HW completes the buffer with an
338 IBV_WC_TM_RNDV_INCOMPLETE status. In this case, the TMH and RVH headers are
339 scattered into the tagged buffer (tag-matching has still been completed!), and
340 message handling is resumed by SW.
341