Skip to content

Commit 55db51e

Browse files
committed
ch4/ucx: Unify AM completion logic
Since we already have allocated requests at the time we start an active message send or recv operation, the completion logic is always the same. In the receive path, we can simply force the completion callback to execute even for immediately complete operations. On the send side, forcing the callback execution appears to be broken in UCX, so we manually call it instead.
1 parent 4b1c94c commit 55db51e

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/mpid/ch4/netmod/ucx/ucx_am.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void MPIDI_UCX_am_send_callback(void *request, ucs_status_t status)
7373
/* Called when recv buffer is posted */
7474
int MPIDI_UCX_do_am_recv(MPIR_Request * rreq)
7575
{
76+
int mpi_errno = MPI_SUCCESS;
7677
void *recv_buf;
7778
bool is_contig;
7879
MPI_Aint data_sz, in_data_sz;
@@ -91,25 +92,19 @@ int MPIDI_UCX_do_am_recv(MPIR_Request * rreq)
9192
}
9293

9394
MPIDI_UCX_ucp_request_t *ucp_request;
94-
size_t received_length;
9595
ucp_request_param_t param = {
96-
.op_attr_mask = UCP_OP_ATTR_FIELD_CALLBACK | UCP_OP_ATTR_FIELD_RECV_INFO | UCP_OP_ATTR_FIELD_USER_DATA,
96+
.op_attr_mask = UCP_OP_ATTR_FIELD_CALLBACK | UCP_OP_ATTR_FIELD_USER_DATA | UCP_OP_ATTR_FLAG_NO_IMM_CMPL,
9797
.cb.recv_am = &MPIDI_UCX_am_recv_callback_nbx,
98-
.recv_info.length = &received_length,
9998
.user_data = rreq,
10099
};
101100
void *data_desc = MPIDI_UCX_AM_RECV_REQUEST(rreq, data_desc);
102101
/* note: use in_data_sz to match promised data size */
103102
ucp_request = ucp_am_recv_data_nbx(MPIDI_UCX_global.ctx[vci].worker,
104103
data_desc, recv_buf, in_data_sz, &param);
105-
if (ucp_request == NULL) {
106-
/* completed immediately */
107-
MPIDI_UCX_ucp_request_t tmp_ucp_request;
108-
tmp_ucp_request.req = rreq;
109-
MPIDI_UCX_am_recv_callback_nbx(&tmp_ucp_request, UCS_OK, received_length, NULL);
110-
}
104+
MPIDI_UCX_CHK_REQUEST(ucp_request);
111105

112-
return MPI_SUCCESS;
106+
fn_fail:
107+
return mpi_errno;
113108
}
114109

115110
/* Am handler for messages sent from ucp_am_send_nbx. Registered with
@@ -175,7 +170,9 @@ void MPIDI_UCX_am_recv_callback_nbx(void *request, ucs_status_t status, size_t l
175170
MPIDIG_recv_done(length, rreq);
176171
}
177172
MPIDIG_REQUEST(rreq, req->target_cmpl_cb) (rreq);
178-
ucp_request_release(request);
173+
if (request) {
174+
ucp_request_release(request);
175+
}
179176
}
180177

181178
void MPIDI_UCX_am_isend_callback_nbx(void *request, ucs_status_t status, void *user_data)
@@ -189,5 +186,8 @@ void MPIDI_UCX_am_isend_callback_nbx(void *request, ucs_status_t status, void *u
189186
MPL_free(MPIDI_UCX_AM_SEND_REQUEST(req, pack_buffer));
190187
MPIDI_UCX_AM_SEND_REQUEST(req, pack_buffer) = NULL;
191188
MPIDIG_global.origin_cbs[handler_id] (req);
189+
if (request) {
190+
ucp_request_release(request);
191+
}
192192
}
193193
#endif

src/mpid/ch4/netmod/ucx/ucx_am.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,17 @@ MPL_STATIC_INLINE_PREFIX int MPIDI_NM_am_isend(int rank,
6565
data_ptr = data;
6666
data_sz = count;
6767
}
68+
MPIDI_UCX_AM_SEND_REQUEST(sreq, pack_buffer) = header;
69+
MPIDI_UCX_AM_SEND_REQUEST(sreq, handler_id) = handler_id;
6870
ucp_request = (MPIDI_UCX_ucp_request_t *) ucp_am_send_nbx(ep, MPIDI_UCX_AM_NBX_HANDLER_ID,
6971
header, header_size,
7072
data_ptr, data_sz, &param);
7173
MPIDI_UCX_CHK_REQUEST(ucp_request);
72-
/* if send is done, free all resources and complete the request */
7374
if (ucp_request == NULL) {
74-
MPL_free(header);
75-
MPIDIG_global.origin_cbs[handler_id] (sreq);
76-
goto fn_exit;
75+
/* call callback because UCP_OP_ATTR_FLAG_NO_IMM_CMPL is broken for ucp_am_send_nbx */
76+
MPIDI_UCX_am_isend_callback_nbx(NULL, UCS_OK, sreq);
7777
}
7878

79-
MPIDI_UCX_AM_SEND_REQUEST(sreq, pack_buffer) = header;
80-
MPIDI_UCX_AM_SEND_REQUEST(sreq, handler_id) = handler_id;
81-
ucp_request_release(ucp_request);
82-
8379
#else /* !HAVE_UCP_AM_NBX */
8480

8581
MPL_pointer_attr_t attr;

0 commit comments

Comments
 (0)