| 1 |
/* |
| 2 |
* Copyright (C) by Argonne National Laboratory |
| 3 |
* See COPYRIGHT in top-level directory |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef MPID_NEM_IMPL_H_INCLUDED |
| 7 |
#define MPID_NEM_IMPL_H_INCLUDED |
| 8 |
|
| 9 |
#include "my_papi_defs.h" |
| 10 |
#include "mpidi_ch3_impl.h" |
| 11 |
#include "mpir_mem.h" |
| 12 |
#include "mpid_nem_net_module_defs.h" |
| 13 |
#include "mpid_nem_atomics.h" |
| 14 |
#include "mpid_nem_defs.h" |
| 15 |
#include "mpid_nem_fbox.h" |
| 16 |
#include "mpid_nem_nets.h" |
| 17 |
#include "mpid_nem_queue.h" |
| 18 |
|
| 19 |
#define MPID_NEM__BYPASS_Q_MAX_VAL ((MPID_NEM_MPICH_DATA_LEN) - (sizeof(MPIDI_CH3_Pkt_t))) |
| 20 |
|
| 21 |
int MPID_nem_mpich_init(void); |
| 22 |
int MPID_nem_coll_init (void); |
| 23 |
int MPID_nem_send_iov(MPIDI_VC_t *vc, MPIR_Request **sreq_ptr, struct iovec *iov, int n_iov); |
| 24 |
int MPID_nem_lmt_pkthandler_init(MPIDI_CH3_PktHandler_Fcn *pktArray[], int arraySize); |
| 25 |
int MPID_nem_register_initcomp_cb(int (* callback)(void)); |
| 26 |
int MPID_nem_choose_netmod(void); |
| 27 |
int MPIDI_CH3I_comm_create(MPIR_Comm *comm, void *param); |
| 28 |
int MPIDI_CH3I_comm_destroy(MPIR_Comm *comm, void *param); |
| 29 |
|
| 30 |
/* rendezvous hooks */ |
| 31 |
int MPID_nem_lmt_RndvSend(MPIR_Request **sreq_p, const void * buf, MPI_Aint count, MPI_Datatype datatype, int dt_contig, |
| 32 |
intptr_t data_sz, MPI_Aint dt_true_lb, int rank, int tag, MPIR_Comm * comm, int context_offset); |
| 33 |
int MPID_nem_lmt_RndvRecv(struct MPIDI_VC *vc, MPIR_Request *rreq); |
| 34 |
|
| 35 |
#define MPID_nem_mpich_release_fbox(cell) \ |
| 36 |
do { \ |
| 37 |
MPL_atomic_release_store_int(&MPID_nem_mem_region.mailboxes.in[(cell)->header.source]->flag, 0); \ |
| 38 |
} while (0) |
| 39 |
|
| 40 |
/* assumes flag!=0 means the fbox is full. Contains acquire barrier to |
| 41 |
* ensure that later operations that are dependent on this check don't |
| 42 |
* escape earlier than this check. */ |
| 43 |
#define MPID_nem_fbox_is_full(pbox_) (MPL_atomic_acquire_load_int(&(pbox_)->flag)) |
| 44 |
|
| 45 |
typedef struct MPID_nem_pkt_lmt_rts |
| 46 |
{ |
| 47 |
MPIDI_CH3_Pkt_type_t type; |
| 48 |
MPIDI_Message_match match; |
| 49 |
MPI_Request sender_req_id; |
| 50 |
intptr_t data_sz; |
| 51 |
intptr_t cookie_len; |
| 52 |
} |
| 53 |
MPID_nem_pkt_lmt_rts_t; |
| 54 |
|
| 55 |
typedef struct MPID_nem_pkt_lmt_cts |
| 56 |
{ |
| 57 |
MPIDI_CH3_Pkt_type_t type; |
| 58 |
MPI_Request sender_req_id; |
| 59 |
MPI_Request receiver_req_id; |
| 60 |
intptr_t data_sz; |
| 61 |
intptr_t cookie_len; |
| 62 |
} |
| 63 |
MPID_nem_pkt_lmt_cts_t; |
| 64 |
|
| 65 |
typedef struct MPID_nem_pkt_lmt_done |
| 66 |
{ |
| 67 |
MPIDI_CH3_Pkt_type_t type; |
| 68 |
MPI_Request req_id; |
| 69 |
} |
| 70 |
MPID_nem_pkt_lmt_done_t; |
| 71 |
|
| 72 |
typedef struct MPID_nem_pkt_lmt_cookie |
| 73 |
{ |
| 74 |
MPIDI_CH3_Pkt_type_t type; |
| 75 |
int from_sender; |
| 76 |
MPI_Request sender_req_id; |
| 77 |
MPI_Request receiver_req_id; |
| 78 |
intptr_t cookie_len; |
| 79 |
} |
| 80 |
MPID_nem_pkt_lmt_cookie_t; |
| 81 |
|
| 82 |
typedef struct MPID_nem_pkt_ckpt_marker |
| 83 |
{ |
| 84 |
MPIDI_CH3_Pkt_type_t type; |
| 85 |
int wave; /* used for debugging */ |
| 86 |
} |
| 87 |
MPID_nem_pkt_ckpt_marker_t; |
| 88 |
|
| 89 |
typedef struct MPID_nem_pkt_netmod |
| 90 |
{ |
| 91 |
MPIDI_CH3_Pkt_type_t type; |
| 92 |
unsigned subtype; |
| 93 |
} |
| 94 |
MPID_nem_pkt_netmod_t; |
| 95 |
|
| 96 |
typedef union MPIDI_CH3_nem_pkt |
| 97 |
{ |
| 98 |
MPID_nem_pkt_lmt_rts_t lmt_rts; |
| 99 |
MPID_nem_pkt_lmt_cts_t lmt_cts; |
| 100 |
MPID_nem_pkt_lmt_done_t lmt_done; |
| 101 |
MPID_nem_pkt_lmt_cookie_t lmt_cookie; |
| 102 |
MPID_nem_pkt_ckpt_marker_t ckpt_marker; |
| 103 |
MPID_nem_pkt_netmod_t netmod; |
| 104 |
} MPIDI_CH3_nem_pkt_t; |
| 105 |
|
| 106 |
|
| 107 |
/* MPID_PKT_DECL_CAST(pkt_u_var, s_pkt_type, s_pkt_p_var) |
| 108 |
To avoid strict aliasing warnings when doing something like: |
| 109 |
pkt_t upkt; |
| 110 |
rts_pkt_t * const rts_pkt = (rts_pkt_t *)&upkt; |
| 111 |
this macro does the same but through a union. |
| 112 |
|
| 113 |
pkt_u_var -- variable name of the packet union |
| 114 |
s_pkt_type -- type of the sub-packet |
| 115 |
s_pkt_p_var -- variable name of the sub-packet pointer |
| 116 |
*/ |
| 117 |
#define MPID_PKT_DECL_CAST(pkt_u_var, s_pkt_type, s_pkt_p_var) \ |
| 118 |
union \ |
| 119 |
{ \ |
| 120 |
MPIDI_CH3_Pkt_t p; \ |
| 121 |
s_pkt_type s; \ |
| 122 |
} pkt_u_var; \ |
| 123 |
s_pkt_type * const s_pkt_p_var = &pkt_u_var.s |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
/* Macros for sending lmt messages from inside network modules. |
| 128 |
These assume mpi_errno is declared and the fn_exit and fn_fail |
| 129 |
labels are defined. |
| 130 |
*/ |
| 131 |
|
| 132 |
#define MPID_nem_lmt_send_RTS(vc, rts_pkt, s_cookie_buf, s_cookie_len) do { \ |
| 133 |
MPIR_Request *_rts_req; \ |
| 134 |
struct iovec _iov[2]; \ |
| 135 |
\ |
| 136 |
MPL_DBG_MSG(MPIDI_CH3_DBG_OTHER,VERBOSE,"sending rndv RTS packet"); \ |
| 137 |
(rts_pkt)->cookie_len = (s_cookie_len); \ |
| 138 |
\ |
| 139 |
_iov[0].iov_base = (void *)(rts_pkt); \ |
| 140 |
_iov[0].iov_len = sizeof(*(rts_pkt)); \ |
| 141 |
_iov[1].iov_base = (void *)(s_cookie_buf); \ |
| 142 |
_iov[1].iov_len = (s_cookie_len); \ |
| 143 |
\ |
| 144 |
MPL_DBG_MSGPKT((vc), (rts_pkt)->match.parts.tag, (rts_pkt)->match.parts.context_id, (rts_pkt)->match.parts.rank, \ |
| 145 |
(rts_pkt)->data_sz, "Rndv"); \ |
| 146 |
\ |
| 147 |
mpi_errno = MPIDI_CH3_iStartMsgv((vc), _iov, ((s_cookie_len)) ? 2 : 1, &_rts_req); \ |
| 148 |
/* --BEGIN ERROR HANDLING-- */ \ |
| 149 |
if (mpi_errno != MPI_SUCCESS) \ |
| 150 |
{ \ |
| 151 |
if (NULL != _rts_req) { \ |
| 152 |
/* error case: drop both the ch3 and nemesis \ |
| 153 |
* references, so the request can be cleanly freed */ \ |
| 154 |
MPIR_Request_free(_rts_req); \ |
| 155 |
MPIR_Request_free(_rts_req); \ |
| 156 |
} \ |
| 157 |
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**rtspkt"); \ |
| 158 |
} \ |
| 159 |
/* --END ERROR HANDLING-- */ \ |
| 160 |
if (_rts_req != NULL) \ |
| 161 |
{ \ |
| 162 |
if (_rts_req->status.MPI_ERROR != MPI_SUCCESS) \ |
| 163 |
{ \ |
| 164 |
mpi_errno = _rts_req->status.MPI_ERROR; \ |
| 165 |
/* error case: drop both the ch3 and nemesis \ |
| 166 |
* references, so the request can be cleanly freed */ \ |
| 167 |
MPIR_Request_free(_rts_req); \ |
| 168 |
MPIR_Request_free(_rts_req); \ |
| 169 |
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**rtspkt"); \ |
| 170 |
} \ |
| 171 |
MPIR_Request_free(_rts_req); \ |
| 172 |
} \ |
| 173 |
} while (0) |
| 174 |
|
| 175 |
#define MPID_nem_lmt_send_CTS(vc, rreq, r_cookie_buf, r_cookie_len) do { \ |
| 176 |
MPID_PKT_DECL_CAST(_upkt, MPID_nem_pkt_lmt_cts_t, _cts_pkt); \ |
| 177 |
MPIR_Request *_cts_req; \ |
| 178 |
struct iovec _iov[2]; \ |
| 179 |
\ |
| 180 |
MPL_DBG_MSG(MPIDI_CH3_DBG_OTHER,VERBOSE,"sending rndv CTS packet"); \ |
| 181 |
MPIDI_Pkt_init(_cts_pkt, MPIDI_NEM_PKT_LMT_CTS); \ |
| 182 |
_cts_pkt->sender_req_id = (rreq)->ch.lmt_req_id; \ |
| 183 |
_cts_pkt->receiver_req_id = (rreq)->handle; \ |
| 184 |
_cts_pkt->cookie_len = (r_cookie_len); \ |
| 185 |
_cts_pkt->data_sz = (rreq)->ch.lmt_data_sz; \ |
| 186 |
\ |
| 187 |
_iov[0].iov_base = (void *)_cts_pkt; \ |
| 188 |
_iov[0].iov_len = sizeof(*_cts_pkt); \ |
| 189 |
_iov[1].iov_base = (void *)(r_cookie_buf); \ |
| 190 |
_iov[1].iov_len = (r_cookie_len); \ |
| 191 |
\ |
| 192 |
mpi_errno = MPIDI_CH3_iStartMsgv((vc), _iov, (r_cookie_len) ? 2 : 1, &_cts_req); \ |
| 193 |
MPIR_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**ctspkt"); \ |
| 194 |
if (_cts_req != NULL) \ |
| 195 |
{ \ |
| 196 |
MPIR_ERR_CHKANDJUMP(_cts_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**ctspkt"); \ |
| 197 |
MPIR_Request_free(_cts_req); \ |
| 198 |
} \ |
| 199 |
} while (0) |
| 200 |
|
| 201 |
static inline int MPID_nem_lmt_send_COOKIE(MPIDI_VC_t *vc, MPIR_Request *req, |
| 202 |
void *cookie_buf, MPI_Aint cookie_len) |
| 203 |
{ |
| 204 |
int mpi_errno = MPI_SUCCESS; |
| 205 |
MPID_PKT_DECL_CAST(_upkt, MPID_nem_pkt_lmt_cookie_t, cookie_pkt); |
| 206 |
MPIR_Request *cookie_req; |
| 207 |
struct iovec iov[2]; |
| 208 |
|
| 209 |
MPL_DBG_MSG(MPIDI_CH3_DBG_OTHER,VERBOSE,"sending rndv COOKIE packet"); |
| 210 |
MPIDI_Pkt_init(cookie_pkt, MPIDI_NEM_PKT_LMT_COOKIE); |
| 211 |
cookie_pkt->cookie_len = (cookie_len); |
| 212 |
|
| 213 |
/* We need to send both handle IDs in case there was |
| 214 |
no CTS message in this protocol. */ |
| 215 |
switch (MPIDI_Request_get_type(req)) { |
| 216 |
case MPIDI_REQUEST_TYPE_RECV: |
| 217 |
cookie_pkt->from_sender = FALSE; |
| 218 |
cookie_pkt->sender_req_id = (req)->ch.lmt_req_id; |
| 219 |
cookie_pkt->receiver_req_id = (req)->handle; |
| 220 |
break; |
| 221 |
case MPIDI_REQUEST_TYPE_SEND: |
| 222 |
case MPIDI_REQUEST_TYPE_RSEND: |
| 223 |
case MPIDI_REQUEST_TYPE_SSEND: |
| 224 |
case MPIDI_REQUEST_TYPE_BSEND: |
| 225 |
cookie_pkt->from_sender = TRUE; |
| 226 |
cookie_pkt->sender_req_id = (req)->handle; |
| 227 |
cookie_pkt->receiver_req_id = (req)->ch.lmt_req_id; |
| 228 |
break; |
| 229 |
default: |
| 230 |
MPIR_ERR_INTERNALANDJUMP(mpi_errno, "unexpected request type"); |
| 231 |
break; |
| 232 |
} |
| 233 |
|
| 234 |
iov[0].iov_base = (void *) cookie_pkt; |
| 235 |
iov[0].iov_len = sizeof(*cookie_pkt); |
| 236 |
iov[1].iov_base = (void *) cookie_buf; |
| 237 |
iov[1].iov_len = cookie_len; |
| 238 |
|
| 239 |
mpi_errno = MPIDI_CH3_iStartMsgv(vc, iov, (cookie_len ? 2 : 1), &cookie_req); |
| 240 |
MPIR_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**cookiepkt"); |
| 241 |
if (cookie_req != NULL) |
| 242 |
{ |
| 243 |
MPIR_ERR_CHKANDJUMP(cookie_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**cookiepkt"); |
| 244 |
MPIR_Request_free(cookie_req); |
| 245 |
} |
| 246 |
|
| 247 |
fn_fail: |
| 248 |
return mpi_errno; |
| 249 |
} |
| 250 |
|
| 251 |
#define MPID_nem_lmt_send_DONE(vc, rreq) do { \ |
| 252 |
MPID_PKT_DECL_CAST(_upkt, MPID_nem_pkt_lmt_done_t, _done_pkt); \ |
| 253 |
MPIR_Request *_done_req; \ |
| 254 |
\ |
| 255 |
MPL_DBG_MSG(MPIDI_CH3_DBG_OTHER,VERBOSE,"sending rndv DONE packet"); \ |
| 256 |
MPIDI_Pkt_init(_done_pkt, MPIDI_NEM_PKT_LMT_DONE); \ |
| 257 |
_done_pkt->req_id = (rreq)->ch.lmt_req_id; \ |
| 258 |
\ |
| 259 |
mpi_errno = MPIDI_CH3_iStartMsg((vc), _done_pkt, sizeof(*_done_pkt), &_done_req); \ |
| 260 |
MPIR_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**donepkt"); \ |
| 261 |
if (_done_req != NULL) \ |
| 262 |
{ \ |
| 263 |
MPIR_ERR_CHKANDJUMP(_done_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**donepkt"); \ |
| 264 |
MPIR_Request_free(_done_req); \ |
| 265 |
} \ |
| 266 |
} while (0) |
| 267 |
|
| 268 |
|
| 269 |
#endif /* MPID_NEM_IMPL_H_INCLUDED */ |