Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disabling eager (and fix 0 byte eager max size) #794

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nccl_ofi_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ OFI_NCCL_PARAM_INT(net_latency, "NET_LATENCY", -1);
* Eager message size limit when using RDMA protocol. Message sizes greater than
* this limit will always be sent using RDMA write instead of eagerly.
*/
OFI_NCCL_PARAM_UINT(eager_max_size, "EAGER_MAX_SIZE", 8192);
OFI_NCCL_PARAM_INT(eager_max_size, "EAGER_MAX_SIZE", 8192);

/*
* Decide whether or not mutexes should default to errorcheck mode.
Expand Down
15 changes: 13 additions & 2 deletions include/nccl_ofi_rdma.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,19 @@ struct nccl_net_ofi_rdma_ep {
nccl_ofi_freelist_t *conn_msg_fl;
/* Size of ctrl rx buffers */
size_t ctrl_rx_buff_size;
/* Size of eager rx buffers */
size_t eager_rx_buff_size;
/* Size of eager rx buffers. Will be -1 if eager is entirely
* disabled. */
ssize_t eager_rx_buff_size;
/* max size of eager messages. This is only separate from
* eager_rx_buff_size because the EFA provider incorrectly throws an
* EINVAL when posting 0 byte rx buffers. To work around that,
* eager_rx_buff_size will either be -1 or positive (but not zero) and
* eager_send_size is the comparison that should be used for deciding
* whether a message is eligible for eager. eager_send_size will never
* be larger than eager_rx_buff_size. Will be -1 if eager is entirely
* disabled.
*/
ssize_t eager_send_size;

/* true if the current endpoint is a endpoint_per_communicator
receive communicator */
Expand Down
81 changes: 49 additions & 32 deletions src/nccl_ofi_rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@

/** Global variables **/

/* Maximum size of an eager message (see OFI_NCCL_EAGER_MAX_SIZE) */
static size_t eager_max_size = 0;

/* List of comms undergoing deferred cleanup */
static nccl_ofi_deque_t *s_comm_cleanup_list = NULL;
static nccl_ofi_deque_t *r_comm_cleanup_list = NULL;
Expand Down Expand Up @@ -2332,6 +2329,9 @@ static inline int eager_rx_buff_req_free(nccl_net_ofi_rdma_req_t *req,
assert(!dec_inflight_reqs);
rdma_req_rx_buff_data_t *rx_buff_data = get_rx_buff_data(req);
nccl_net_ofi_rdma_ep_t *ep = rx_buff_data->ep;

assert(ep->eager_rx_buff_size > 0);

/* Free buffer */
if (rx_buff_data->rx_buff_fl_elem) {
nccl_ofi_freelist_entry_free(ep->eager_rx_buff_fl, rx_buff_data->rx_buff_fl_elem);
Expand All @@ -2345,6 +2345,8 @@ static inline nccl_net_ofi_rdma_req_t *eager_rx_buff_req_alloc(nccl_net_ofi_rdma
nccl_net_ofi_rdma_req_t *req = allocate_req(ep->rx_buff_reqs_fl);
if (!req) return NULL;

assert(ep->eager_rx_buff_size > 0);

req->comm = NULL;
req->type = NCCL_OFI_RDMA_EAGER_RX_BUFF;
req->dev_id = rdma_endpoint_get_device(ep)->base.dev_id;
Expand Down Expand Up @@ -5567,7 +5569,9 @@ static int post_rx_buffer(nccl_net_ofi_rdma_req_t *req,
/* Reset memcheck guards of rx buffer freelist entry to
* accessible but undefined to cover cases where the buffer
* gets re-posted */
nccl_net_ofi_rdma_ep_t *ep = rx_buff_data->ep;
nccl_net_ofi_rdma_ep_t *ep = rx_buff_data->ep;
assert(req->type != NCCL_OFI_RDMA_EAGER_RX_BUFF || ep->eager_rx_buff_size > 0);

nccl_ofi_freelist_t *fl = (req->type == NCCL_OFI_RDMA_EAGER_RX_BUFF ?
ep->eager_rx_buff_fl : ep->ctrl_rx_buff_fl);
nccl_ofi_freelist_entry_set_undefined(fl, rx_buff_fl_elem->ptr);
Expand Down Expand Up @@ -6010,7 +6014,7 @@ static int send(nccl_net_ofi_send_comm_t *send_comm, void *data, int size, int t

/* Determine if this should be sent eagerly. */
eager = false;
if ((!have_ctrl && (size_t)size <= eager_max_size && s_comm->num_inflight_writes == 0) || (size == 0)) {
if (!have_ctrl && (ssize_t)size <= ep->eager_send_size && s_comm->num_inflight_writes == 0) {
eager = true;
}

Expand Down Expand Up @@ -6258,19 +6262,19 @@ static inline int init_rx_buffers(nccl_net_ofi_rdma_ep_t *ep)
return ret;
}

/* Set the eager freelist buffer size to at least the maximum of EAGER_RX_BUFFER_ALIGNMENT
* and eager_rx_buff_size. This ensures the freelist maintains a minimum size equal to
* EAGER_RX_BUFFER_ALIGNMENT even when OFI_NCCL_EAGER_MAX_SIZE is set to 0.
*/
ret = nccl_ofi_freelist_init_mr(NCCL_OFI_MAX(EAGER_RX_BUFFER_ALIGNMENT, ep->eager_rx_buff_size),
ofi_nccl_rdma_min_posted_bounce_buffers(), 16, 0,
freelist_regmr_host_fn, freelist_deregmr_host_fn,
ep, EAGER_RX_BUFFER_ALIGNMENT, &ep->eager_rx_buff_fl);
if (ret != 0) {
NCCL_OFI_WARN("Failed to init eager_rx_buff_size");
nccl_ofi_freelist_fini(ep->ctrl_rx_buff_fl);
nccl_ofi_freelist_fini(ep->rx_buff_reqs_fl);
return ret;
if (ep->eager_rx_buff_size > 0) {
ret = nccl_ofi_freelist_init_mr(ep->eager_rx_buff_size,
ofi_nccl_rdma_min_posted_bounce_buffers(), 16, 0,
freelist_regmr_host_fn, freelist_deregmr_host_fn,
ep, EAGER_RX_BUFFER_ALIGNMENT, &ep->eager_rx_buff_fl);
if (ret != 0) {
NCCL_OFI_WARN("Failed to init eager_rx_buff_size");
nccl_ofi_freelist_fini(ep->ctrl_rx_buff_fl);
nccl_ofi_freelist_fini(ep->rx_buff_reqs_fl);
return ret;
}
} else {
ep->eager_rx_buff_fl = NULL;
}

ret = nccl_ofi_freelist_init_mr(sizeof(nccl_ofi_rdma_connection_info_t),
Expand All @@ -6279,7 +6283,9 @@ static inline int init_rx_buffers(nccl_net_ofi_rdma_ep_t *ep)
ep, sizeof(void *), &ep->conn_msg_fl);
if (ret != 0) {
NCCL_OFI_WARN("Failed to init conn_msg freelist");
nccl_ofi_freelist_fini(ep->eager_rx_buff_fl);
if (ep->eager_rx_buff_fl != NULL) {
nccl_ofi_freelist_fini(ep->eager_rx_buff_fl);
}
nccl_ofi_freelist_fini(ep->ctrl_rx_buff_fl);
nccl_ofi_freelist_fini(ep->rx_buff_reqs_fl);
return ret;
Expand All @@ -6306,12 +6312,17 @@ static inline int init_rx_buffers(nccl_net_ofi_rdma_ep_t *ep)

for (int rail_id = 0; rail_id < ep->num_rails; ++rail_id) {
rail = rdma_endpoint_get_rail(ep, rail_id);
rail->min_rx_buff_posted = NCCL_OFI_DIV_CEIL(
ofi_nccl_rdma_min_posted_bounce_buffers(), ep->num_rails
);
rail->max_rx_buff_posted = NCCL_OFI_DIV_CEIL(
ofi_nccl_rdma_max_posted_bounce_buffers(), ep->num_rails
);
if (ep->eager_rx_buff_size >= 0) {
rail->min_rx_buff_posted = NCCL_OFI_DIV_CEIL(
ofi_nccl_rdma_min_posted_bounce_buffers(), ep->num_rails
);
rail->max_rx_buff_posted = NCCL_OFI_DIV_CEIL(
ofi_nccl_rdma_max_posted_bounce_buffers(), ep->num_rails
);
} else {
rail->min_rx_buff_posted = 0;
rail->max_rx_buff_posted = 0;
}
rail->num_rx_buff_posted = 0;
nccl_net_ofi_mutex_init(&rail->rx_buff_mutex, NULL);
rail->rx_buff_req_alloc = eager_rx_buff_req_alloc;
Expand Down Expand Up @@ -6340,10 +6351,12 @@ static inline int fini_rx_buffers(nccl_net_ofi_rdma_ep_t *ep)
return ret;
}

ret = nccl_ofi_freelist_fini(ep->eager_rx_buff_fl);
if (ret != 0) {
NCCL_OFI_WARN("Failed to fini eager_rx_buff_fl");
return ret;
if (ep->eager_rx_buff_fl != NULL) {
ret = nccl_ofi_freelist_fini(ep->eager_rx_buff_fl);
if (ret != 0) {
NCCL_OFI_WARN("Failed to fini eager_rx_buff_fl");
return ret;
}
}

ret = nccl_ofi_freelist_fini(ep->rx_buff_reqs_fl);
Expand Down Expand Up @@ -7337,7 +7350,12 @@ static int nccl_net_ofi_rdma_domain_create_endpoint(nccl_net_ofi_domain_t *base_
NCCL_OFI_MAX(sizeof(nccl_net_ofi_rdma_ctrl_msg_t),
NCCL_OFI_MAX(sizeof(nccl_ofi_rdma_connection_info_t),
sizeof(nccl_net_ofi_rdma_close_msg_t)));
ep->eager_rx_buff_size = eager_max_size;
ep->eager_send_size = ofi_nccl_eager_max_size();
/* Work around EFA provider bug around posting 0 byte rx buffers by not
posting 0 byte rx buffers. Note that if eager_send_size is -1
(disabled), eager_rx_buff_size will also be -1. */
ep->eager_rx_buff_size = (ep->eager_send_size == 0) ?
EAGER_RX_BUFFER_ALIGNMENT : ep->eager_send_size;

ep->is_endpoint_per_communicator_ep = false;

Expand Down Expand Up @@ -8091,12 +8109,11 @@ int nccl_net_ofi_rdma_init(const char *provider_filter,
goto error;
}

if (ofi_nccl_eager_max_size() > ofi_nccl_min_stripe_size()) {
if ((ssize_t)ofi_nccl_eager_max_size() > (ssize_t)ofi_nccl_min_stripe_size()) {
NCCL_OFI_WARN("Invalid value for EAGER_MAX_SIZE");
ret = ncclInvalidArgument;
goto error;
}
eager_max_size = (size_t) ofi_nccl_eager_max_size();

/* Create NCCL OFI topology */
topo = nccl_ofi_topo_create(provider_list);
Expand Down
8 changes: 6 additions & 2 deletions src/platform-aws.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,14 @@ static int configure_ep_max_msg_size(struct fid_ep *ep)
int ret = 0;

#if HAVE_DECL_FI_OPT_MAX_MSG_SIZE
size_t eager_max_size = (size_t)ofi_nccl_eager_max_size();
size_t optval = NCCL_OFI_MAX(NCCL_OFI_MAX(sizeof(nccl_net_ofi_rdma_ctrl_msg_t), eager_max_size),
ssize_t eager_max_size = (ssize_t)ofi_nccl_eager_max_size();
size_t optval = NCCL_OFI_MAX(sizeof(nccl_net_ofi_rdma_ctrl_msg_t),
sizeof(nccl_ofi_rdma_connection_info_t));

if (eager_max_size > 0) {
optval = NCCL_OFI_MAX(optval, (size_t)eager_max_size);
}

ret = fi_setopt(&ep->fid, FI_OPT_ENDPOINT, FI_OPT_MAX_MSG_SIZE, &optval, sizeof(optval));

NCCL_OFI_TRACE(NCCL_INIT, "fi_setopt(FI_OPT_MAX_MSG_SIZE) RC: %d", ret);
Expand Down