Skip to content

Commit 27514c2

Browse files
committed
Allow for packing less data than expected.
Return the updated amount to allow the upper level to gracefully handle the case. Signed-off-by: George Bosilca <[email protected]>
1 parent f29109a commit 27514c2

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

opal/mca/btl/uct/btl_uct_am.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mca_btl_base_descriptor_t *mca_btl_uct_alloc(mca_btl_base_module_t *btl,
5151
}
5252

5353
static inline void _mca_btl_uct_send_pack(void *data, void *header, size_t header_size,
54-
opal_convertor_t *convertor, size_t payload_size)
54+
opal_convertor_t *convertor, size_t* payload_size)
5555
{
5656
uint32_t iov_count = 1;
5757
struct iovec iov;
@@ -64,11 +64,9 @@ static inline void _mca_btl_uct_send_pack(void *data, void *header, size_t heade
6464

6565
/* pack the data into the supplied buffer */
6666
iov.iov_base = (IOVBASE_TYPE *) ((intptr_t) data + header_size);
67-
iov.iov_len = length = payload_size;
67+
iov.iov_len = *payload_size;
6868

69-
(void) opal_convertor_pack(convertor, &iov, &iov_count, &length);
70-
71-
assert(length == payload_size);
69+
(void) opal_convertor_pack(convertor, &iov, &iov_count, payload_size);
7270
}
7371

7472
struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src(mca_btl_base_module_t *btl,
@@ -92,7 +90,10 @@ struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src(mca_btl_base_module_t
9290
}
9391

9492
_mca_btl_uct_send_pack((void *) ((intptr_t) frag->uct_iov.buffer + reserve), NULL, 0,
95-
convertor, *size);
93+
convertor, size);
94+
/* update the length of the fragment according to the convertor packed data */
95+
frag->segments[0].seg_len = reserve + *size;
96+
frag->uct_iov.length = frag->segments[0].seg_len;
9697
} else {
9798
opal_convertor_get_current_pointer(convertor, &data_ptr);
9899
assert(NULL != data_ptr);
@@ -286,7 +287,7 @@ static size_t mca_btl_uct_sendi_pack(void *data, void *arg)
286287

287288
am_header->value = args->am_header;
288289
_mca_btl_uct_send_pack((void *) ((intptr_t) data + 8), args->header, args->header_size,
289-
args->convertor, args->payload_size);
290+
args->convertor, &args->payload_size);
290291
return args->header_size + args->payload_size + 8;
291292
}
292293

@@ -329,9 +330,18 @@ int mca_btl_uct_sendi(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpo
329330
} else if (msg_size < (size_t) MCA_BTL_UCT_TL_ATTR(uct_btl->am_tl, context->context_id)
330331
.cap.am.max_short) {
331332
int8_t *data = alloca(total_size);
332-
_mca_btl_uct_send_pack(data, header, header_size, convertor, payload_size);
333-
ucs_status = uct_ep_am_short(ep_handle, MCA_BTL_UCT_FRAG, am_header.value, data,
334-
total_size);
333+
size_t packed_payload_size = payload_size;
334+
_mca_btl_uct_send_pack(data, header, header_size, convertor, &packed_payload_size);
335+
if (packed_payload_size != payload_size) {
336+
/* This should never happen as the packed data should go in a single pack. But
337+
in case it does, fallback onto a descriptor allocation and let the caller
338+
send the data.
339+
*/
340+
ucs_status = UCS_ERR_NO_RESOURCE;
341+
} else {
342+
ucs_status = uct_ep_am_short(ep_handle, MCA_BTL_UCT_FRAG, am_header.value, data,
343+
total_size);
344+
}
335345
} else {
336346
ssize_t size;
337347

0 commit comments

Comments
 (0)