int ft_start_server(void) { int ret; ret = ft_getinfo(hints, &fi_pep); if (ret) return ret; ret = fi_fabric(fi_pep->fabric_attr, &fabric, NULL); if (ret) { FT_PRINTERR("fi_fabric", ret); return ret; } ret = fi_eq_open(fabric, &eq_attr, &eq, NULL); if (ret) { FT_PRINTERR("fi_eq_open", ret); return ret; } ret = fi_passive_ep(fabric, fi_pep, &pep, NULL); if (ret) { FT_PRINTERR("fi_passive_ep", ret); return ret; } ret = fi_pep_bind(pep, &eq->fid, 0); if (ret) { FT_PRINTERR("fi_pep_bind", ret); return ret; } ret = fi_listen(pep); if (ret) { FT_PRINTERR("fi_listen", ret); return ret; } return 0; }
static int run_test(void) { int ret = 0; ret = init_fabric(); if (ret) return ret; if (opts.dst_addr) { /* Execute RMA write operation from Client */ fprintf(stdout, "RMA write to server\n"); sprintf(buf, "%s", welcome_text); ret = write_data(sizeof(char *) * strlen(buf)); if (ret) return ret; ret = fi_cntr_wait(scntr, 1, -1); if (ret < 0) { FT_PRINTERR("fi_cntr_wait", ret); return ret; } fprintf(stdout, "Received a completion event for RMA write\n"); } else { /* Server waits for message from Client */ ret = fi_cntr_wait(rcntr, 1, -1); if (ret < 0) { FT_PRINTERR("fi_cntr_wait", ret); return ret; } fprintf(stdout, "Received data from Client: %s\n", (char *)buf); } /* TODO: need support for finalize operation to sync test */ free_ep_res(); fi_close(&dom->fid); fi_close(&fab->fid); return 0; }
int ft_finalize(void) { struct iovec iov; int ret; struct fi_context ctx; void *desc = fi_mr_desc(mr); strcpy(tx_buf + ft_tx_prefix_size(), "fin"); iov.iov_base = tx_buf; iov.iov_len = 4 + ft_tx_prefix_size(); if (hints->caps & FI_TAGGED) { struct fi_msg_tagged tmsg; memset(&tmsg, 0, sizeof tmsg); tmsg.msg_iov = &iov; tmsg.desc = &desc; tmsg.iov_count = 1; tmsg.addr = remote_fi_addr; tmsg.tag = tx_seq; tmsg.ignore = 0; tmsg.context = &ctx; ret = fi_tsendmsg(ep, &tmsg, FI_INJECT | FI_TRANSMIT_COMPLETE); } else { struct fi_msg msg; memset(&msg, 0, sizeof msg); msg.msg_iov = &iov; msg.desc = &desc; msg.iov_count = 1; msg.addr = remote_fi_addr; msg.context = &ctx; ret = fi_sendmsg(ep, &msg, FI_INJECT | FI_TRANSMIT_COMPLETE); } if (ret) { FT_PRINTERR("transmit", ret); return ret; } ret = ft_get_tx_comp(++tx_seq); if (ret) return ret; ret = ft_get_rx_comp(rx_seq); if (ret) return ret; return 0; }
static int write_data_with_cq_data(size_t size) { int ret; ret = fi_writedata(ep, buf, size, fi_mr_desc(mr), cq_data, remote_fi_addr, remote.addr, remote.key, &fi_ctx_writedata); if (ret) { FT_PRINTERR("fi_writedata", ret); return ret; } return 0; }
int ft_bind_comp(struct fid_ep *ep, uint64_t flags) { int ret; if (flags & FI_SEND) { ret = fi_ep_bind(ep, &txcq->fid, flags & ~FI_RECV); if (ret) { FT_PRINTERR("fi_ep_bind", ret); return ret; } } if (flags & FI_RECV) { ret = fi_ep_bind(ep, &rxcq->fid, flags & ~FI_SEND); if (ret) { FT_PRINTERR("fi_ep_bind", ret); return ret; } } return 0; }
static int recv_msg(void) { int ret; ret = fi_recv(srx_ctx, buf, rx_size, fi_mr_desc(mr), 0, &rx_ctx); if (ret) { FT_PRINTERR("fi_recv", ret); return ret; } ret = ft_get_rx_comp(++rx_seq); return ret; }
static int write_data(size_t size) { int ret; /* Using specified base address and MR key for RMA write */ ret = fi_write(ep, buf, size, fi_mr_desc(mr), remote_fi_addr, 0, user_defined_key, &fi_ctx_write); if (ret){ FT_PRINTERR("fi_write", ret); return ret; } return 0; }
static int alloc_cm_res(void) { struct fi_eq_attr cm_attr; int ret; memset(&cm_attr, 0, sizeof cm_attr); cm_attr.wait_obj = FI_WAIT_FD; ret = fi_eq_open(fab, &cm_attr, &cmeq, NULL); if (ret) FT_PRINTERR("fi_eq_open", ret); return ret; }
static int pp_post_send(struct pingpong_context *ctx) { int rc = 0; rc = fi_send(ctx->ep, ctx->buf, ctx->size, fi_mr_desc(ctx->mr), 0, (void *)(uintptr_t)PINGPONG_SEND_WCID); if (rc) { FT_PRINTERR("fi_send", rc); return 1; } return 0; }
static int read_data(size_t size) { int ret; ret = fi_read(ep, buf, size, fi_mr_desc(mr), 0, remote.addr, remote.key, ep); if (ret) { FT_PRINTERR("fi_read", ret); return ret; } return 0; }
static int send_msg(int size, uint64_t tag) { int ret; ret = fi_tsend(ep, buf, (size_t) size, fi_mr_desc(mr), remote_fi_addr, tag, &fi_ctx_send); if (ret) FT_PRINTERR("fi_tsend", ret); ret = wait_for_tagged_completion(scq, 1); return ret; }
static int bind_ep_res(void) { int i, ret; ret = fi_scalable_ep_bind(sep, &av->fid, 0); if (ret) { FT_PRINTERR("fi_scalable_ep_bind", ret); return ret; } for (i = 0; i < ctx_cnt; i++) { ret = fi_ep_bind(tx_ep[i], &txcq_array[i]->fid, FI_SEND); if (ret) { FT_PRINTERR("fi_ep_bind", ret); return ret; } ret = fi_enable(tx_ep[i]); if (ret) { FT_PRINTERR("fi_enable", ret); return ret; } } for (i = 0; i < ctx_cnt; i++) { ret = fi_ep_bind(rx_ep[i], &rxcq_array[i]->fid, FI_RECV); if (ret) { FT_PRINTERR("fi_ep_bind", ret); return ret; } ret = fi_enable(rx_ep[i]); if (ret) { FT_PRINTERR("fi_enable", ret); return ret; } ret = fi_recv(rx_ep[i], rx_buf, MAX(rx_size, FT_MAX_CTRL_MSG), mr_desc, 0, NULL); if (ret) { FT_PRINTERR("fi_recv", ret); return ret; } } ret = fi_enable(sep); if (ret) { FT_PRINTERR("fi_enable", ret); return ret; } return 0; }
static int recv_xfer(int size) { struct fi_cq_data_entry comp; int ret; do { ret = fi_cq_read(rcq, &comp, 1); if (ret < 0 && ret != -FI_EAGAIN) { if (ret == -FI_EAVAIL) { cq_readerr(rcq, "rcq"); } else { FT_PRINTERR("fi_cq_read", ret); } return ret; } } while (ret == -FI_EAGAIN); ret = fi_recv(ep, buf, buffer_size, fi_mr_desc(mr), 0, buf); if (ret) FT_PRINTERR("fi_recv", ret); return ret; }
static int execute_base_atomic_op(enum fi_op op) { int ret; ret = fi_atomic(ep, buf, 1, fi_mr_desc(mr), remote_fi_addr, remote.addr, remote.key, datatype, op, &fi_ctx_atomic); if (ret) { FT_PRINTERR("fi_atomic", ret); } else { ret = wait_for_completion(scq, 1); } return ret; }
static int recv_msg(void) { int ret; ret = fi_recv(ep, buf, buffer_size, fi_mr_desc(mr), 0, &fi_ctx_recv); if (ret) { FT_PRINTERR("fi_recv", ret); return ret; } ret = wait_for_completion(rcq, 1); return ret; }
static int recv_msg(void) { int ret; ret = fi_recv(ep, buf, rx_size, fi_mr_desc(mr), 0, &fi_ctx_recv); if (ret) { FT_PRINTERR("fi_recv", ret); return ret; } ret = ft_wait_for_comp(rxcq, 1); return ret; }
int main(int argc, char **argv) { int op, ret; int failed = 0; hints = fi_allocinfo(); if (!hints) return EXIT_FAILURE; while ((op = getopt(argc, argv, FAB_OPTS "h")) != -1) { switch (op) { default: ft_parseinfo(op, optarg, hints, &opts); break; case '?': case 'h': usage(); return EXIT_FAILURE; } } hints->mode = ~0; hints->domain_attr->mode = ~0; hints->domain_attr->mr_mode = ~(FI_MR_BASIC | FI_MR_SCALABLE); ret = fi_getinfo(FT_FIVERSION, NULL, 0, 0, hints, &fi); if (ret) { FT_PRINTERR("fi_getinfo", ret); goto out; } if (!fi->domain_attr->cntr_cnt) goto out; ret = ft_open_fabric_res(); if (ret) goto out; printf("Testing CNTRS on fabric %s\n", fi->fabric_attr->name); failed = run_tests(test_array, err_buf); if (failed > 0) printf("Summary: %d tests failed\n", failed); else printf("Summary: all tests passed\n"); out: ft_free_res(); return ret ? ft_exit_code(ret) : (failed > 0) ? EXIT_FAILURE : EXIT_SUCCESS; }
int ft_cq_readerr(struct fid_cq *cq) { struct fi_cq_err_entry cq_err; int ret; ret = fi_cq_readerr(cq, &cq_err, 0); if (ret < 0) { FT_PRINTERR("fi_cq_readerr", ret); } else { FT_CQ_ERR(cq, cq_err, NULL, 0); ret = -cq_err.err; } return ret; }
static int post_recvs(struct cma_node *node) { int i, ret = 0; for (i = 0; i < hints->tx_attr->size && !ret; i++ ) { ret = fi_recv(node->ep, node->mem, hints->ep_attr->max_msg_size, node->mrdesc, 0, node); if (ret) { FT_PRINTERR("fi_recv", ret); break; } } return ret; }
static int send_msg(int size) { int ret; ret = fi_send(ep_array[0], buf, (size_t) size, fi_mr_desc(mr), addr_array[0], &tx_ctx); if (ret) { FT_PRINTERR("fi_send", ret); return ret; } ret = ft_get_tx_comp(++tx_seq); return ret; }
static int pp_eq_create(struct pingpong_context *ctx) { struct fi_eq_attr cm_attr; int rc; memset(&cm_attr, 0, sizeof cm_attr); cm_attr.wait_obj = FI_WAIT_FD; rc = fi_eq_open(ctx->fabric, &cm_attr, &ctx->eq, NULL); if (rc) FT_PRINTERR("fi_eq_open", rc); return rc; }
static int bind_ep_res(void) { int ret; ret = fi_ep_bind(ep, &scq->fid, FI_SEND | FI_READ | FI_WRITE); if (ret) { FT_PRINTERR("fi_ep_bind", -ret); return ret; } ret = fi_ep_bind(ep, &rcq->fid, FI_RECV); if (ret) { FT_PRINTERR("fi_ep_bind", -ret); return ret; } ret = fi_ep_bind(ep, &av->fid, FI_RECV); if (ret) { FT_PRINTERR("fi_ep_bind", ret); return ret; } ret = fi_enable(ep); if(ret) { FT_PRINTERR("fi_enable", ret); return ret; } /* Post the first recv buffer */ ret = fi_recv(ep, buf, buffer_size, fi_mr_desc(mr), 0, &fi_ctx_recv); if (ret) { FT_PRINTERR("fi_recv", ret); return ret; } return ret; }
static int bind_ep_res(void) { int ret; ret = fi_ep_bind(ep, &scq->fid, FI_SEND); if (ret) { FT_PRINTERR("fi_ep_bind", ret); return ret; } ret = fi_ep_bind(ep, &rcq->fid, FI_RECV); if (ret) { FT_PRINTERR("fi_ep_bind", ret); return ret; } ret = fi_ep_bind(ep, &av->fid, 0); if (ret) { FT_PRINTERR("fi_ep_bind", ret); return ret; } ret = fi_enable(ep); if (ret) { FT_PRINTERR("fi_enable", ret); return ret; } /* Post a recv buffer for synchronization */ ret = fi_recv(ep, buf, buffer_size, fi_mr_desc(mr), 0, &fi_ctx_recv); if (ret) { FT_PRINTERR("fi_recv", ret); return ret; } return ret; }
static int receive_loop(size_t size) { int ret; int q_opts = 0; struct fi_context recv_ctx[max_opts]; while (q_opts < max_opts) { do { ft_tag = q_opts + 1; if (tagged) ret = fi_trecv(ep, rx_buf, size, NULL, remote_fi_addr, ft_tag, 0x0, (void *) &recv_ctx[q_opts]); else ret = fi_recv(ep, rx_buf, size, NULL, remote_fi_addr, (void *) &recv_ctx[q_opts]); if (ret == FI_SUCCESS) { rx_seq++; q_opts++; } } while (!ret && (q_opts != max_opts)); if (ret < 0) { if (ret == -FI_EAGAIN) { if (delay > 0) sleep(delay); ret = ft_get_rx_comp(rx_seq); if (ret) return ret; } else { FT_PRINTERR("Recv OP", ret); return ret; } } } if (delay > 0) sleep(delay); ret = ft_get_rx_comp(rx_seq); if (ret) return ret; if (opts.verbose) printf("Success: Completed %d queued ops\n", q_opts); return 0; }
static int run_client(void) { int i, ret, ret2; printf("cmatose: starting client\n"); printf("cmatose: connecting\n"); for (i = 0; i < connections; i++) { ret = fi_connect(nodes[i].ep, info->dest_addr, NULL, 0); if (ret) { FT_PRINTERR("fi_connect", ret); connects_left--; return ret; } } ret = connect_events(); if (ret) goto disc; if (hints->tx_attr->size) { printf("receiving data transfers\n"); ret = poll_cqs(RECV_CQ_INDEX); if (ret) goto disc; printf("sending replies\n"); for (i = 0; i < connections; i++) { ret = post_sends(nodes + i); if (ret) goto disc; } printf("completing sends\n"); ret = poll_cqs(SEND_CQ_INDEX); if (ret) goto disc; printf("data transfers complete\n"); } ret = 0; disc: ret2 = shutdown_events(); printf("disconnected\n"); if (ret2) ret = ret2; return ret; }
int ft_eq_readerr(void) { struct fi_eq_err_entry err; ssize_t ret; ret = fi_eq_readerr(eq, &err, 0); if (ret != sizeof(err)) { FT_PRINTERR("fi_eq_readerr", ret); return ret; } else { fprintf(stderr, "Error event %d %s\n", err.err, fi_strerror(err.err)); return err.err; } }
static int send_xfer(int size) { struct fi_cq_entry comp; int ret; while (!credits) { ret = fi_cq_read(scq, &comp, 1); if (ret > 0) { goto post; } else if (ret < 0 && ret != -FI_EAGAIN) { FT_PRINTERR("fi_cq_read", ret); return ret; } } credits--; post: ret = fi_send(ep, buf_ptr, (size_t) size, fi_mr_desc(mr), remote_fi_addr, NULL); if (ret) FT_PRINTERR("fi_send", ret); return ret; }
static int recv_msg(uint64_t tag) { int ret; // posting recv for next send ret = fi_trecv(ep, buf, buffer_size, fi_mr_desc(mr), remote_fi_addr, tag, 0, &fi_ctx_recv); if (ret) FT_PRINTERR("fi_trecv", ret); // wait for the completion event ret = wait_for_tagged_completion(rcq, 1); return ret; }
static int send_msg(int size) { int ret; ret = fi_send(ep, buf, (size_t) size, fi_mr_desc(mr), remote_fi_addr, &fi_ctx_send); if (ret) { FT_PRINTERR("fi_send", ret); return ret; } ret = ft_wait_for_comp(txcq, 1); return ret; }
int ft_open_fabric_res(void) { int ret; ret = fi_fabric(fi->fabric_attr, &fabric, NULL); if (ret) { FT_PRINTERR("fi_fabric", ret); return ret; } ret = fi_eq_open(fabric, &eq_attr, &eq, NULL); if (ret) { FT_PRINTERR("fi_eq_open", ret); return ret; } ret = fi_domain(fabric, fi, &domain, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); return ret; } return 0; }