Skip to content

Commit

Permalink
UCP/PROTO/MULTI: Allow header be greater than max_frag, sort lanes by BW
Browse files Browse the repository at this point in the history
  • Loading branch information
iyastreb committed Oct 28, 2024
1 parent 7b19557 commit ce3f490
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
27 changes: 25 additions & 2 deletions src/ucp/proto/proto_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,24 @@
#include "proto_debug.h"
#include "proto_multi.inl"

#include <ucs/algorithm/qsort_r.h>
#include <ucs/debug/assert.h>
#include <ucs/debug/log.h>


static int ucp_proto_multi_compare_tl_perf(const void *elem1, const void *elem2,
void *arg)
{
const ucp_lane_index_t *lane1 = elem1;
const ucp_lane_index_t *lane2 = elem2;
const ucp_proto_common_tl_perf_t *lanes_perf = arg;
int diff;

diff = lanes_perf[*lane2].bandwidth - lanes_perf[*lane1].bandwidth;
/* If bandwidths are equal, prefer to maintain the original ordering */
return (diff != 0) ? diff : (elem1 - elem2);
}

ucs_status_t ucp_proto_multi_init(const ucp_proto_multi_init_params_t *params,
const char *perf_name,
ucp_proto_perf_t **perf_p,
Expand Down Expand Up @@ -59,8 +73,7 @@ ucs_status_t ucp_proto_multi_init(const ucp_proto_multi_init_params_t *params,
&params->super, params->first.lane_type, params->first.tl_cap_flags,
1, 0, lanes);
if (num_lanes == 0) {
ucs_trace("no lanes for %s",
ucp_proto_id_field(params->super.super.proto_id, name));
ucs_trace("no lanes for %s", perf_name);
return UCS_ERR_NO_ELEM;
}

Expand All @@ -86,6 +99,16 @@ ucs_status_t ucp_proto_multi_init(const ucp_proto_multi_init_params_t *params,
max_bandwidth = ucs_max(max_bandwidth, lane_perf->bandwidth);
}

/* Sort lanes by bandwidth */
if (num_lanes > 1) {
/* If type of the first lane is not the same as in the middle, then
* exclude this lane from sorting */
lane = (params->first.lane_type == params->middle.lane_type) ? 0 : 1;
/* Sort lanes array by lanes_perf bandwidth */
ucs_qsort_r(lanes + lane, num_lanes - lane, sizeof(ucp_lane_index_t),
ucp_proto_multi_compare_tl_perf, lanes_perf);
}

/* Select the lanes to use, and calculate their aggregate performance */
perf.bandwidth = 0;
perf.send_pre_overhead = 0;
Expand Down
7 changes: 5 additions & 2 deletions src/ucp/proto/proto_multi.inl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ ucp_proto_multi_max_payload(ucp_request_t *req,
size_t max_frag = lpriv->max_frag - hdr_size;
size_t max_payload;

ucs_assertv(lpriv->max_frag > hdr_size, "max_frag=%zu hdr_size=%zu",
lpriv->max_frag, hdr_size);
/* If header is greater than max_frag - that's ok, we allow it, but we send
* only the header data and keep the payload empty */
if (lpriv->max_frag <= hdr_size) {
return 0;
}

/* Do not split very small sends to chunks, it's not worth it, and
generic datatype may not be able to pack to a smaller buffer */
Expand Down

0 comments on commit ce3f490

Please sign in to comment.