Skip to content

Commit 092506d

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 6cf7824 commit 092506d

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,26 +92,20 @@ 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 = {
9696
.op_attr_mask =
97-
UCP_OP_ATTR_FIELD_CALLBACK | UCP_OP_ATTR_FIELD_RECV_INFO | UCP_OP_ATTR_FIELD_USER_DATA,
97+
UCP_OP_ATTR_FIELD_CALLBACK | UCP_OP_ATTR_FIELD_USER_DATA | UCP_OP_ATTR_FLAG_NO_IMM_CMPL,
9898
.cb.recv_am = &MPIDI_UCX_am_recv_callback_nbx,
99-
.recv_info.length = &received_length,
10099
.user_data = rreq,
101100
};
102101
void *data_desc = MPIDI_UCX_AM_RECV_REQUEST(rreq, data_desc);
103102
/* note: use in_data_sz to match promised data size */
104103
ucp_request = ucp_am_recv_data_nbx(MPIDI_UCX_global.ctx[vci].worker,
105104
data_desc, recv_buf, in_data_sz, &param);
106-
if (ucp_request == NULL) {
107-
/* completed immediately */
108-
MPIDI_UCX_ucp_request_t tmp_ucp_request;
109-
tmp_ucp_request.req = rreq;
110-
MPIDI_UCX_am_recv_callback_nbx(&tmp_ucp_request, UCS_OK, received_length, NULL);
111-
}
105+
MPIDI_UCX_CHK_REQUEST(ucp_request);
112106

113-
return MPI_SUCCESS;
107+
fn_fail:
108+
return mpi_errno;
114109
}
115110

116111
/* Am handler for messages sent from ucp_am_send_nbx. Registered with
@@ -176,7 +171,9 @@ void MPIDI_UCX_am_recv_callback_nbx(void *request, ucs_status_t status, size_t l
176171
MPIDIG_recv_done(length, rreq);
177172
}
178173
MPIDIG_REQUEST(rreq, req->target_cmpl_cb) (rreq);
179-
ucp_request_release(request);
174+
if (request) {
175+
ucp_request_release(request);
176+
}
180177
}
181178

182179
void MPIDI_UCX_am_isend_callback_nbx(void *request, ucs_status_t status, void *user_data)
@@ -190,5 +187,8 @@ void MPIDI_UCX_am_isend_callback_nbx(void *request, ucs_status_t status, void *u
190187
MPL_free(MPIDI_UCX_AM_SEND_REQUEST(req, pack_buffer));
191188
MPIDI_UCX_AM_SEND_REQUEST(req, pack_buffer) = NULL;
192189
MPIDIG_global.origin_cbs[handler_id] (req);
190+
if (request) {
191+
ucp_request_release(request);
192+
}
193193
}
194194
#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)