OpenMPI  0.1.1
pml_csum_hdr.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3  * University Research and Technology
4  * Corporation. All rights reserved.
5  * Copyright (c) 2004-2005 The University of Tennessee and The University
6  * of Tennessee Research Foundation. All rights
7  * reserved.
8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9  * University of Stuttgart. All rights reserved.
10  * Copyright (c) 2004-2005 The Regents of the University of California.
11  * All rights reserved.
12  * Copyright (c) 2009 IBM Corporation. All rights reserved.
13  * Copyright (c) 2009 Los Alamos National Security, LLC. All rights
14  * reserved.
15  * $COPYRIGHT$
16  *
17  * Additional copyrights may follow
18  *
19  * $HEADER$
20  */
21 /**
22  * @file
23  */
24 #ifndef MCA_PML_CSUM_HEADER_H
25 #define MCA_PML_CSUM_HEADER_H
26 
27 #include "ompi_config.h"
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
30 #endif
31 #ifdef HAVE_NETINET_IN_H
32 #include <netinet/in.h>
33 #endif
34 
35 #include "opal/types.h"
36 #include "opal/util/arch.h"
37 #include "ompi/mca/btl/btl.h"
38 #include "ompi/proc/proc.h"
39 
40 #define MCA_PML_CSUM_HDR_TYPE_MATCH (MCA_BTL_TAG_PML + 1)
41 #define MCA_PML_CSUM_HDR_TYPE_RNDV (MCA_BTL_TAG_PML + 2)
42 #define MCA_PML_CSUM_HDR_TYPE_RGET (MCA_BTL_TAG_PML + 3)
43 #define MCA_PML_CSUM_HDR_TYPE_ACK (MCA_BTL_TAG_PML + 4)
44 #define MCA_PML_CSUM_HDR_TYPE_NACK (MCA_BTL_TAG_PML + 5)
45 #define MCA_PML_CSUM_HDR_TYPE_FRAG (MCA_BTL_TAG_PML + 6)
46 #define MCA_PML_CSUM_HDR_TYPE_GET (MCA_BTL_TAG_PML + 7)
47 #define MCA_PML_CSUM_HDR_TYPE_PUT (MCA_BTL_TAG_PML + 8)
48 #define MCA_PML_CSUM_HDR_TYPE_FIN (MCA_BTL_TAG_PML + 9)
49 
50 #define MCA_PML_CSUM_HDR_FLAGS_ACK 1 /* is an ack required */
51 #define MCA_PML_CSUM_HDR_FLAGS_NBO 2 /* is the hdr in network byte order */
52 #define MCA_PML_CSUM_HDR_FLAGS_PIN 4 /* is user buffer pinned */
53 #define MCA_PML_CSUM_HDR_FLAGS_CONTIG 8 /* is user buffer contiguous */
54 #define MCA_PML_CSUM_HDR_FLAGS_NORDMA 16 /* rest will be send by copy-in-out */
55 
56 /**
57  * Common hdr attributes - must be first element in each hdr type
58  */
60  uint8_t hdr_type; /**< type of envelope */
61  uint8_t hdr_flags; /**< flags indicating how fragment should be processed */
62  uint16_t hdr_csum; /**< checksum over header */
63 };
65 
66 #define MCA_PML_CSUM_COMMON_HDR_NTOH(h) (h).hdr_csum = ntohs((h).hdr_csum);
67 #define MCA_PML_CSUM_COMMON_HDR_HTON(h) (h).hdr_csum = htons((h).hdr_csum);
68 
69 /**
70  * Header definition for the first fragment, contains the
71  * attributes required to match the corresponding posted receive.
72  */
74  mca_pml_csum_common_hdr_t hdr_common; /**< common attributes */
75  uint16_t hdr_ctx; /**< communicator index */
76  uint16_t hdr_seq; /**< message sequence number */
77  int32_t hdr_src; /**< source rank */
78  int32_t hdr_tag; /**< user tag */
79  uint32_t hdr_csum; /**< checksum over data */
80 };
81 #define OMPI_PML_CSUM_MATCH_HDR_LEN 20
82 
84 
85 #define MCA_PML_CSUM_MATCH_HDR_NTOH(h) \
86 do { \
87  MCA_PML_CSUM_COMMON_HDR_NTOH((h).hdr_common); \
88  (h).hdr_ctx = ntohs((h).hdr_ctx); \
89  (h).hdr_src = ntohl((h).hdr_src); \
90  (h).hdr_tag = ntohl((h).hdr_tag); \
91  (h).hdr_seq = ntohs((h).hdr_seq); \
92  (h).hdr_csum = ntohl((h).hdr_csum); \
93 } while (0)
94 
95 #define MCA_PML_CSUM_MATCH_HDR_HTON(h) \
96 do { \
97  MCA_PML_CSUM_COMMON_HDR_HTON((h).hdr_common); \
98  (h).hdr_ctx = htons((h).hdr_ctx); \
99  (h).hdr_src = htonl((h).hdr_src); \
100  (h).hdr_tag = htonl((h).hdr_tag); \
101  (h).hdr_seq = htons((h).hdr_seq); \
102  (h).hdr_csum = htonl((h).hdr_csum); \
103 } while (0)
104 
105 /**
106  * Header definition for the first fragment when an acknowledgment
107  * is required. This could be the first fragment of a large message
108  * or a short message that requires an ack (synchronous).
109  */
111  mca_pml_csum_match_hdr_t hdr_match;
112  uint64_t hdr_msg_length; /**< message length */
113  ompi_ptr_t hdr_src_req; /**< pointer to source request - returned in ack */
114 };
116 
117 /* Note that hdr_src_req is not put in network byte order because it
118  is never processed by the receiver, other than being copied into
119  the ack header */
120 #define MCA_PML_CSUM_RNDV_HDR_NTOH(h) \
121  do { \
122  MCA_PML_CSUM_MATCH_HDR_NTOH((h).hdr_match); \
123  (h).hdr_msg_length = ntoh64((h).hdr_msg_length); \
124  } while (0)
125 
126 #define MCA_PML_CSUM_RNDV_HDR_HTON(h) \
127  do { \
128  MCA_PML_CSUM_MATCH_HDR_HTON((h).hdr_match); \
129  (h).hdr_msg_length = hton64((h).hdr_msg_length); \
130  } while (0)
131 
132 /**
133  * Header definition for a combined rdma rendezvous/get
134  */
137  uint32_t hdr_seg_cnt; /**< number of segments for rdma */
138 #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT
139  uint8_t hdr_padding[4];
140 #endif
141  ompi_ptr_t hdr_des; /**< source descriptor */
142  mca_btl_base_segment_t hdr_segs[1]; /**< list of segments for rdma */
143 };
145 
146 #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT && OPAL_ENABLE_DEBUG
147 #define MCA_PML_CSUM_RGET_HDR_FILL(h) \
148 do { \
149  (h).hdr_padding[0] = 0; \
150  (h).hdr_padding[1] = 0; \
151  (h).hdr_padding[2] = 0; \
152  (h).hdr_padding[3] = 0; \
153 } while(0)
154 #else
155 #define MCA_PML_CSUM_RGET_HDR_FILL(h)
156 #endif /* OPAL_ENABLE_HETEROGENEOUS_SUPPORT && OPAL_ENABLE_DEBUG */
157 
158 #define MCA_PML_CSUM_RGET_HDR_NTOH(h) \
159  do { \
160  MCA_PML_CSUM_RNDV_HDR_NTOH((h).hdr_rndv); \
161  (h).hdr_seg_cnt = ntohl((h).hdr_seg_cnt); \
162  } while (0)
163 
164 #define MCA_PML_CSUM_RGET_HDR_HTON(h) \
165  do { \
166  MCA_PML_CSUM_RNDV_HDR_HTON((h).hdr_rndv); \
167  MCA_PML_CSUM_RGET_HDR_FILL(h); \
168  (h).hdr_seg_cnt = htonl((h).hdr_seg_cnt); \
169  } while (0)
170 
171 /**
172  * Header for subsequent fragments.
173  */
175  mca_pml_csum_common_hdr_t hdr_common; /**< common attributes */
176  uint32_t hdr_csum;
177  uint64_t hdr_frag_offset; /**< offset into message */
178  ompi_ptr_t hdr_src_req; /**< pointer to source request */
179  ompi_ptr_t hdr_dst_req; /**< pointer to matched receive */
180 };
182 
183 #define MCA_PML_CSUM_FRAG_HDR_NTOH(h) \
184  do { \
185  MCA_PML_CSUM_COMMON_HDR_NTOH((h).hdr_common); \
186  (h).hdr_csum = ntohl((h).hdr_csum); \
187  (h).hdr_frag_offset = ntoh64((h).hdr_frag_offset); \
188  } while (0)
189 
190 #define MCA_PML_CSUM_FRAG_HDR_HTON(h) \
191  do { \
192  MCA_PML_CSUM_COMMON_HDR_HTON((h).hdr_common); \
193  (h).hdr_csum = htonl((h).hdr_csum); \
194  (h).hdr_frag_offset = hton64((h).hdr_frag_offset); \
195  } while (0)
196 
197 /**
198  * Header used to acknowledgment outstanding fragment(s).
199  */
200 
202  mca_pml_csum_common_hdr_t hdr_common; /**< common attributes */
203 #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT
204  uint8_t hdr_padding[4];
205 #endif
206  ompi_ptr_t hdr_src_req; /**< source request */
207  ompi_ptr_t hdr_dst_req; /**< matched receive request */
208  uint64_t hdr_send_offset; /**< starting point of copy in/out */
209 };
211 
212 #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT && OPAL_ENABLE_DEBUG
213 #define MCA_PML_CSUM_ACK_HDR_FILL(h) \
214 do { \
215  (h).hdr_padding[0] = 0; \
216  (h).hdr_padding[1] = 0; \
217  (h).hdr_padding[2] = 0; \
218  (h).hdr_padding[3] = 0; \
219 } while (0)
220 #else
221 #define MCA_PML_CSUM_ACK_HDR_FILL(h)
222 #endif /* OPAL_ENABLE_HETEROGENEOUS_SUPPORT && OPAL_ENABLE_DEBUG */
223 
224 /* Note that the request headers are not put in NBO because the
225  src_req is already in receiver's byte order and the dst_req is not
226  used by the receiver for anything other than backpointers in return
227  headers */
228 #define MCA_PML_CSUM_ACK_HDR_NTOH(h) \
229  do { \
230  MCA_PML_CSUM_COMMON_HDR_NTOH((h).hdr_common); \
231  (h).hdr_send_offset = ntoh64((h).hdr_send_offset); \
232  } while (0)
233 
234 #define MCA_PML_CSUM_ACK_HDR_HTON(h) \
235  do { \
236  MCA_PML_CSUM_COMMON_HDR_HTON((h).hdr_common); \
237  MCA_PML_CSUM_ACK_HDR_FILL(h); \
238  (h).hdr_send_offset = hton64((h).hdr_send_offset); \
239  } while (0)
240 
241 /**
242  * Header used to initiate an RDMA operation.
243  */
244 
246  mca_pml_csum_common_hdr_t hdr_common; /**< common attributes */
247  uint32_t hdr_seg_cnt; /**< number of segments for rdma */
248  ompi_ptr_t hdr_req; /**< destination request */
249  ompi_ptr_t hdr_des; /**< source descriptor */
250  uint64_t hdr_rdma_offset; /**< current offset into user buffer */
251  mca_btl_base_segment_t hdr_segs[1]; /**< list of segments for rdma */
252 };
254 
255 #define MCA_PML_CSUM_RDMA_HDR_NTOH(h) \
256  do { \
257  MCA_PML_CSUM_COMMON_HDR_NTOH((h).hdr_common); \
258  (h).hdr_seg_cnt = ntohl((h).hdr_seg_cnt); \
259  (h).hdr_rdma_offset = ntoh64((h).hdr_rdma_offset); \
260  } while (0)
261 
262 #define MCA_PML_CSUM_RDMA_HDR_HTON(h) \
263  do { \
264  MCA_PML_CSUM_COMMON_HDR_HTON((h).hdr_common); \
265  (h).hdr_seg_cnt = htonl((h).hdr_seg_cnt); \
266  (h).hdr_rdma_offset = hton64((h).hdr_rdma_offset); \
267  } while (0)
268 
269 /**
270  * Header used to complete an RDMA operation.
271  */
272 
274  mca_pml_csum_common_hdr_t hdr_common; /**< common attributes */
275  uint32_t hdr_csum;
276  ompi_ptr_t hdr_des; /**< completed descriptor */
277  uint32_t hdr_fail; /**< RDMA operation failed */
278 };
280 
281 #define MCA_PML_CSUM_FIN_HDR_NTOH(h) \
282  do { \
283  MCA_PML_CSUM_COMMON_HDR_NTOH((h).hdr_common); \
284  (h).hdr_csum = ntohl((h).hdr_csum); \
285  (h).hdr_fail = ntohl((h).hdr_fail); \
286  } while (0)
287 
288 #define MCA_PML_CSUM_FIN_HDR_HTON(h) \
289  do { \
290  MCA_PML_CSUM_COMMON_HDR_HTON((h).hdr_common); \
291  (h).hdr_csum = htonl((h).hdr_csum); \
292  (h).hdr_fail = htonl((h).hdr_fail); \
293  } while (0)
294 
295 /**
296  * Union of defined hdr types.
297  */
299  mca_pml_csum_common_hdr_t hdr_common;
300  mca_pml_csum_match_hdr_t hdr_match;
302  mca_pml_csum_rget_hdr_t hdr_rget;
303  mca_pml_csum_frag_hdr_t hdr_frag;
304  mca_pml_csum_ack_hdr_t hdr_ack;
305  mca_pml_csum_rdma_hdr_t hdr_rdma;
306  mca_pml_csum_fin_hdr_t hdr_fin;
307 };
309 
310 #if !defined(WORDS_BIGENDIAN) && OPAL_ENABLE_HETEROGENEOUS_SUPPORT
311 static inline __opal_attribute_always_inline__ void
312 csum_hdr_ntoh(mca_pml_csum_hdr_t *hdr, const uint8_t hdr_type)
313 {
314  if(!(hdr->hdr_common.hdr_flags & MCA_PML_CSUM_HDR_FLAGS_NBO))
315  return;
316 
317  switch(hdr_type) {
318  case MCA_PML_CSUM_HDR_TYPE_MATCH:
319  MCA_PML_CSUM_MATCH_HDR_NTOH(hdr->hdr_match);
320  break;
321  case MCA_PML_CSUM_HDR_TYPE_RNDV:
322  MCA_PML_CSUM_RNDV_HDR_NTOH(hdr->hdr_rndv);
323  break;
324  case MCA_PML_CSUM_HDR_TYPE_RGET:
325  MCA_PML_CSUM_RGET_HDR_NTOH(hdr->hdr_rget);
326  break;
327  case MCA_PML_CSUM_HDR_TYPE_ACK:
328  MCA_PML_CSUM_ACK_HDR_NTOH(hdr->hdr_ack);
329  break;
330  case MCA_PML_CSUM_HDR_TYPE_FRAG:
331  MCA_PML_CSUM_FRAG_HDR_NTOH(hdr->hdr_frag);
332  break;
333  case MCA_PML_CSUM_HDR_TYPE_PUT:
334  MCA_PML_CSUM_RDMA_HDR_NTOH(hdr->hdr_rdma);
335  break;
336  case MCA_PML_CSUM_HDR_TYPE_FIN:
337  MCA_PML_CSUM_FIN_HDR_NTOH(hdr->hdr_fin);
338  break;
339  default:
340  assert(0);
341  break;
342  }
343 }
344 #else
345 #define csum_hdr_ntoh(h, t) do{}while(0)
346 #endif
347 
348 #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT
349 #define csum_hdr_hton(h, t, p) \
350  csum_hdr_hton_intr((mca_pml_csum_hdr_t*)h, t, p)
351 static inline __opal_attribute_always_inline__ void
352 csum_hdr_hton_intr(mca_pml_csum_hdr_t *hdr, const uint8_t hdr_type,
353  const ompi_proc_t *proc)
354 {
355 #ifdef WORDS_BIGENDIAN
356  hdr->hdr_common.hdr_flags |= MCA_PML_CSUM_HDR_FLAGS_NBO;
357 #else
358 
359  if(!(proc->proc_arch & OPAL_ARCH_ISBIGENDIAN))
360  return;
361 
362  hdr->hdr_common.hdr_flags |= MCA_PML_CSUM_HDR_FLAGS_NBO;
363  switch(hdr_type) {
364  case MCA_PML_CSUM_HDR_TYPE_MATCH:
365  MCA_PML_CSUM_MATCH_HDR_HTON(hdr->hdr_match);
366  break;
367  case MCA_PML_CSUM_HDR_TYPE_RNDV:
368  MCA_PML_CSUM_RNDV_HDR_HTON(hdr->hdr_rndv);
369  break;
370  case MCA_PML_CSUM_HDR_TYPE_RGET:
371  MCA_PML_CSUM_RGET_HDR_HTON(hdr->hdr_rget);
372  break;
373  case MCA_PML_CSUM_HDR_TYPE_ACK:
374  MCA_PML_CSUM_ACK_HDR_HTON(hdr->hdr_ack);
375  break;
376  case MCA_PML_CSUM_HDR_TYPE_FRAG:
377  MCA_PML_CSUM_FRAG_HDR_HTON(hdr->hdr_frag);
378  break;
379  case MCA_PML_CSUM_HDR_TYPE_PUT:
380  MCA_PML_CSUM_RDMA_HDR_HTON(hdr->hdr_rdma);
381  break;
382  case MCA_PML_CSUM_HDR_TYPE_FIN:
383  MCA_PML_CSUM_FIN_HDR_HTON(hdr->hdr_fin);
384  break;
385  default:
386  assert(0);
387  break;
388  }
389 #endif
390 }
391 #else
392 #define csum_hdr_hton(h, t, p) do{}while(0)
393 #endif
394 #endif
Header used to initiate an RDMA operation.
Definition: pml_csum_hdr.h:245
uint8_t hdr_flags
flags indicating how fragment should be processed
Definition: pml_csum_hdr.h:61
mca_pml_csum_common_hdr_t hdr_common
common attributes
Definition: pml_csum_hdr.h:175
int32_t hdr_tag
user tag
Definition: pml_csum_hdr.h:78
uint32_t hdr_seg_cnt
number of segments for rdma
Definition: pml_csum_hdr.h:247
uint64_t hdr_rdma_offset
current offset into user buffer
Definition: pml_csum_hdr.h:250
Header definition for a combined rdma rendezvous/get.
Definition: pml_csum_hdr.h:135
mca_btl_base_segment_t hdr_segs[1]
list of segments for rdma
Definition: pml_csum_hdr.h:251
ompi_ptr_t hdr_src_req
pointer to source request
Definition: pml_csum_hdr.h:178
uint64_t hdr_send_offset
starting point of copy in/out
Definition: pml_csum_hdr.h:208
Header definition for the first fragment, contains the attributes required to match the corresponding...
Definition: pml_csum_hdr.h:73
mca_pml_csum_common_hdr_t hdr_common
common attributes
Definition: pml_csum_hdr.h:274
Common hdr attributes - must be first element in each hdr type.
Definition: pml_csum_hdr.h:59
ompi_ptr_t hdr_des
completed descriptor
Definition: pml_csum_hdr.h:276
Union of defined hdr types.
Definition: pml_csum_hdr.h:298
mca_pml_csum_common_hdr_t hdr_common
common attributes
Definition: pml_csum_hdr.h:246
Definition: types.h:52
Header for subsequent fragments.
Definition: pml_csum_hdr.h:174
Process identification structure interface.
Remote Open MPI process structure.
Definition: proc.h:56
ompi_ptr_t hdr_des
source descriptor
Definition: pml_csum_hdr.h:249
Header used to acknowledgment outstanding fragment(s).
Definition: pml_csum_hdr.h:201
uint32_t hdr_seg_cnt
number of segments for rdma
Definition: pml_csum_hdr.h:137
Header definition for the first fragment when an acknowledgment is required.
Definition: pml_csum_hdr.h:110
ompi_ptr_t hdr_des
source descriptor
Definition: pml_csum_hdr.h:141
int32_t hdr_src
source rank
Definition: pml_csum_hdr.h:77
Byte Transfer Layer (BTL)
ompi_ptr_t hdr_src_req
source request
Definition: pml_csum_hdr.h:206
mca_pml_csum_common_hdr_t hdr_common
common attributes
Definition: pml_csum_hdr.h:74
uint64_t hdr_msg_length
message length
Definition: pml_csum_hdr.h:112
uint16_t hdr_csum
checksum over header
Definition: pml_csum_hdr.h:62
mca_btl_base_segment_t hdr_segs[1]
list of segments for rdma
Definition: pml_csum_hdr.h:142
ompi_ptr_t hdr_src_req
pointer to source request - returned in ack
Definition: pml_csum_hdr.h:113
uint32_t hdr_csum
checksum over data
Definition: pml_csum_hdr.h:79
uint8_t hdr_type
type of envelope
Definition: pml_csum_hdr.h:60
mca_pml_csum_common_hdr_t hdr_common
common attributes
Definition: pml_csum_hdr.h:202
uint32_t hdr_fail
RDMA operation failed.
Definition: pml_csum_hdr.h:277
ompi_ptr_t hdr_req
destination request
Definition: pml_csum_hdr.h:248
uint32_t proc_arch
architecture of this process
Definition: proc.h:66
ompi_ptr_t hdr_dst_req
pointer to matched receive
Definition: pml_csum_hdr.h:179
uint64_t hdr_frag_offset
offset into message
Definition: pml_csum_hdr.h:177
uint16_t hdr_seq
message sequence number
Definition: pml_csum_hdr.h:76
Header used to complete an RDMA operation.
Definition: pml_csum_hdr.h:273
uint16_t hdr_ctx
communicator index
Definition: pml_csum_hdr.h:75
Describes a region/segment of memory that is addressable by an BTL.
Definition: btl.h:236
ompi_ptr_t hdr_dst_req
matched receive request
Definition: pml_csum_hdr.h:207