⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ibu.ibal.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
📖 第 1 页 / 共 4 页
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//**  (C) 2001 by Argonne National Laboratory.*      See COPYRIGHT in top-level directory.*/#include "mpidimpl.h"#include "ibu.h"#ifdef HAVE_STDIO_H#include <stdio.h>#endif#ifdef HAVE_MALLOC_H#include <malloc.h>#endif#include "mpidi_ch3_impl.h"#ifdef HAVE_WINDOWS_H#ifdef USE_DEBUG_ALLOCATION_HOOK#include <crtdbg.h>#endif#endif#ifdef USE_IB_IBAL#include "ibuimpl.ibal.h"#include <complib/cl_thread.h>IBU_Global IBU_Process;/*============== static functions prototypes ==================*/static int ibui_get_first_active_ca();/* utility ibu functions */#undef FUNCNAME#define FUNCNAME getMaxInlineSize#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)ib_api_status_t getMaxInlineSize( ibu_t ibu ){    ib_api_status_t status = IB_SUCCESS;    ib_qp_attr_t qp_prop;    MPIDI_STATE_DECL(MPID_STATE_IBU_GETMAXINLINESIZE);    MPIDI_FUNC_ENTER(MPID_STATE_IBU_GETMAXINLINESIZE);    MPIU_DBG_PRINTF(("entering getMaxInlineSize\n"));    status = ib_query_qp(ibu->qp_handle, &qp_prop);    if (status != IB_SUCCESS)    {	MPIU_Internal_error_printf("getMaxInlineSize: ib_query_qp failed, error %s\n", ib_get_err_str(status));	MPIDI_FUNC_EXIT(MPID_STATE_IBU_GETMAXINLINESIZE);	return status;    }    ibu->max_inline_size = qp_prop.sq_max_inline;    MPIU_DBG_PRINTF(("exiting getMaxInlineSize\n"));    MPIDI_FUNC_EXIT(MPID_STATE_IBU_GETMAXINLINESIZE);    return IBU_SUCCESS;}#undef FUNCNAME#define FUNCNAME modifyQP#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)ib_api_status_t modifyQP( ibu_t ibu, ib_qp_state_t qp_state ){    ib_api_status_t status;    ib_qp_mod_t qp_mod;    MPIDI_STATE_DECL(MPID_STATE_IBU_MODIFYQP);    MPIDI_FUNC_ENTER(MPID_STATE_IBU_MODIFYQP);    memset(&qp_mod, 0, sizeof(qp_mod));    MPIU_DBG_PRINTF(("entering modifyQP\n"));    if (qp_state == IB_QPS_INIT)    {	qp_mod.req_state = IB_QPS_INIT;	qp_mod.state.init.qkey = 0x0;	qp_mod.state.init.pkey_index = 0x0;	qp_mod.state.init.primary_port = IBU_Process.port;	qp_mod.state.init.access_ctrl = /* Mellanox, dafna April 11th added rdma write and read	for access control */	    IB_AC_LOCAL_WRITE | 	    IB_AC_RDMA_WRITE  |	    IB_AC_RDMA_READ;    }    else if (qp_state == IB_QPS_RTR)     {	qp_mod.req_state = IB_QPS_RTR;	qp_mod.state.rtr.rq_psn = cl_hton32(0x00000000); /*Mellanox, dafna April 11th changed from '1' to '0'*/	qp_mod.state.rtr.dest_qp = ibu->dest_qp_num;	qp_mod.state.rtr.resp_res = 1;	qp_mod.state.rtr.rnr_nak_timeout = 7;	qp_mod.state.rtr.pkey_index = 0x0;	qp_mod.state.rtr.opts = IB_MOD_QP_PRIMARY_AV;	qp_mod.state.rtr.primary_av.sl = 0;	qp_mod.state.rtr.primary_av.dlid = ibu->dlid;	qp_mod.state.rtr.primary_av.grh_valid = 0;	/* static rate: IB_PATH_RECORD_RATE_10_GBS for 4x link width, 30GBS for 12x*/	qp_mod.state.rtr.primary_av.static_rate = IB_PATH_RECORD_RATE_10_GBS; /* Mellanox dafna April 11th, TODO - set to IBU_Process.port_static_rate*/	qp_mod.state.rtr.primary_av.path_bits = 0;	if (IBU_Process.dev_id == 0x5A44) /* Tavor Based */	{	    qp_mod.state.rtr.primary_av.conn.path_mtu = IB_MTU_1024;	}	else	{	    qp_mod.state.rtr.primary_av.conn.path_mtu = IB_MTU_2048;	}			qp_mod.state.rtr.primary_av.conn.local_ack_timeout = 7;	qp_mod.state.rtr.primary_av.conn.seq_err_retry_cnt = 7;	qp_mod.state.rtr.primary_av.conn.rnr_retry_cnt = 7;	/*qp_mod.state.rtr.primary_av.port_num = IBU_Process.port;*/    }    else if (qp_state == IB_QPS_RTS)    {	qp_mod.req_state = IB_QPS_RTS;	qp_mod.state.rts.sq_psn = cl_hton32(0x00000000);/*Mellanox, dafna April 11th changed from '1' to '0'*/	qp_mod.state.rts.retry_cnt = 1; /*Mellanox, dafna April 11th changed from '7' to '1'*/	qp_mod.state.rts.rnr_retry_cnt = 3; /*Mellanox, dafna April 11th changed from '7' to '3'*/	qp_mod.state.rts.rnr_nak_timeout = 7;	qp_mod.state.rts.local_ack_timeout = 10; /*Mellanox, dafna April 11th changed from '20' to '10'*/	qp_mod.state.rts.init_depth = 7;	qp_mod.state.rts.opts = 0;    }    else if (qp_state == IB_QPS_RESET)    {	qp_mod.req_state = IB_QPS_RESET;	/* Mellanox, dafna April 11th no RESET union which holdes timewait anymore/ removed qp_mod.state.reset.timewait = 0*/    }    else    {	MPIDI_FUNC_EXIT(MPID_STATE_IBU_MODIFYQP);	return IBU_FAIL;    }    status = ib_modify_qp(ibu->qp_handle, &qp_mod);    if ( status != IB_SUCCESS )    {	MPIDI_FUNC_EXIT(MPID_STATE_IBU_MODIFYQP);	return status;    }    MPIU_DBG_PRINTF(("exiting modifyQP\n"));    MPIDI_FUNC_EXIT(MPID_STATE_IBU_MODIFYQP);    return IBU_SUCCESS;}#undef FUNCNAME#define FUNCNAME createQP#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)ib_api_status_t createQP(ibu_t ibu, ibu_set_t set){    ib_api_status_t status;    ib_qp_create_t qp_init_attr;    ib_qp_attr_t qp_prop;    MPIDI_STATE_DECL(MPID_STATE_IBU_CREATEQP);    MPIDI_FUNC_ENTER(MPID_STATE_IBU_CREATEQP);    MPIU_DBG_PRINTF(("entering createQP\n"));    qp_init_attr.qp_type = IB_QPT_RELIABLE_CONN;    /* Mellanox, dafna April 11th h_rdd not a member of qp_create anymore qp_init_attr.h_rdd = 0 */    qp_init_attr.sq_depth = IBU_DEFAULT_MAX_WQE; /* Mellanox, dafna April 11th 10000;*/    qp_init_attr.rq_depth = IBU_DEFAULT_MAX_WQE; /* Mellanox, dafna April 11th 10000;*/    qp_init_attr.sq_sge = 8;    qp_init_attr.rq_sge = 8;    qp_init_attr.h_sq_cq = set;    qp_init_attr.h_rq_cq = set;    qp_init_attr.sq_signaled = FALSE; /*TRUE;*/    status = ib_create_qp(IBU_Process.pd_handle, &qp_init_attr, NULL, NULL, &ibu->qp_handle);    if (status != IB_SUCCESS)    {	MPIU_Internal_error_printf("ib_create_qp failed, error %s\n", ib_get_err_str(status));	MPIDI_FUNC_EXIT(MPID_STATE_IBU_CREATEQP);	return status;    }    status = ib_query_qp(ibu->qp_handle, &qp_prop);    if (status != IB_SUCCESS)    {	MPIU_Internal_error_printf("ib_query_qp failed, error %s\n", ib_get_err_str(status));	MPIDI_FUNC_EXIT(MPID_STATE_IBU_CREATEQP);	return status;    }    MPIU_DBG_PRINTF(("qp: num = %d, dest_num = %d\n",	cl_ntoh32(qp_prop.num),	cl_ntoh32(qp_prop.dest_num)));    ibu->qp_num = qp_prop.num;    MPIU_DBG_PRINTF(("exiting createQP\n"));    MPIDI_FUNC_EXIT(MPID_STATE_IBU_CREATEQP);    return IBU_SUCCESS;}/* * Added by Mellanox, dafna April 11th * *args:ibu - pointer to ibu_state_tretrun value:p - memory hndl of the buffers , NULL if fail.Allocates local RDMA buffers and registers them to the HCA*/#undef FUNCNAME#define FUNCNAME ibui_update_remote_RDMA_buf#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int ibui_update_remote_RDMA_buf(ibu_t ibu, ibu_rdma_buf_t* buf, uint32_t rkey){    MPIDI_STATE_DECL(MPID_STATE_IBUI_UPDATE_REMOTE_RDMA_BUF);    MPIDI_FUNC_ENTER(MPID_STATE_IBUI_UPDATE_REMOTE_RDMA_BUF);    MPIU_DBG_PRINTF(("entering ibui_update_remote_RDMA_buf\n"));    ibu->remote_RDMA_buf_base = buf;    ibu->remote_RDMA_buf_hndl.rkey = rkey;    ibu->remote_RDMA_head = 0;    ibu->remote_RDMA_limit = IBU_NUM_OF_RDMA_BUFS - 1;    MPIU_DBG_PRINTF(("ibu_update_RDMA_buf  rkey = %x  buf= %p\n",rkey,buf));    MPIU_DBG_PRINTF(("ibu_update_RDMA_buf  ************** remote_RDMA_head = %d  remote_RDMA_limit= %d\n",	ibu->remote_RDMA_head,	ibu->remote_RDMA_limit));    MPIDI_FUNC_EXIT(MPID_STATE_IBUI_UPDATE_REMOTE_RDMA_BUF);    return IBU_SUCCESS;}/* * Added by Mellanox, dafna April 11th  * *args:ibu - pointer to ibu_state_t retrun value:p - memory hndl of the buffers , NULL if fail.Allocates local RDMA buffers and registers them to the HCA*/#undef FUNCNAME#define FUNCNAME ibui_RDMA_buf_init#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)ibu_rdma_buf_t* ibui_RDMA_buf_init(ibu_t ibu, uint32_t* rkey){    ibu_rdma_buf_t *buf;    ibu_mem_t mem_handle;    MPIDI_STATE_DECL(MPID_STATE_IBUI_RDMA_BUF_INIT);    MPIDI_FUNC_ENTER(MPID_STATE_IBUI_RDMA_BUF_INIT);    MPIU_DBG_PRINTF(("entering ibui_RDMA_buf_init\n"));    buf = ibuRDMAAllocInitIB(&mem_handle);     if (buf == NULL)    {	MPIDI_FUNC_EXIT(MPID_STATE_IBUI_RDMA_BUF_INIT);	return NULL;    }    ibu->local_RDMA_buf_base = buf;    ibu->local_RDMA_buf_hndl = mem_handle;     ibu->local_RDMA_head =  0;    ibu->local_last_updated_RDMA_limit = IBU_NUM_OF_RDMA_BUFS - 1;    *rkey = ibu->local_RDMA_buf_hndl.rkey;    MPIU_DBG_PRINTF(("ibui_RDMA_buf_init rkey = %x buf= %p\n", *rkey, buf));    MPIU_DBG_PRINTF(("ibui_RDMA_buf_init ************* ibu->local_RDMA_head = %d ibu->local_last_updated_RDMA_limit= %d\n", 	ibu->local_RDMA_head, ibu->local_last_updated_RDMA_limit));    MPIDI_FUNC_EXIT(MPID_STATE_IBUI_RDMA_BUF_INIT);    return buf;}#undef FUNCNAME#define FUNCNAME ibu_start_qp#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)ibu_t ibu_start_qp(ibu_set_t set, int *qp_num_ptr){    ib_api_status_t status;    ibu_t p;    MPIDI_STATE_DECL(MPID_STATE_IBU_START_QP);    MPIDI_FUNC_ENTER(MPID_STATE_IBU_START_QP);    MPIU_DBG_PRINTF(("entering ibu_start_qp\n"));    p = (ibu_t)MPIU_Malloc(sizeof(ibu_state_t));    if (p == NULL)    {	MPIDI_FUNC_EXIT(MPID_STATE_IBU_START_QP);	return NULL;    }    memset(p, 0, sizeof(ibu_state_t));    p->state = 0;    p->allocator = ibuBlockAllocInitIB();    /*MPIDI_DBG_PRINTF((60, FCNAME, "creating the queue pair\n"));*/    /* Create the queue pair */    status = createQP(p, set);    if (status != IBU_SUCCESS)    {	MPIU_Internal_error_printf("ibu_create_qp: createQP failed, error %s\n", ib_get_err_str(status));	MPIDI_FUNC_EXIT(MPID_STATE_IBU_START_QP);	return NULL;    }    *qp_num_ptr = p->qp_num;    MPIDI_FUNC_EXIT(MPID_STATE_IBU_START_QP);    return p;}#undef FUNCNAME#define FUNCNAME ibu_finish_qp#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int ibu_finish_qp(ibu_t p, int dest_lid, int dest_qp_num){    ib_api_status_t status;    MPIDI_STATE_DECL(MPID_STATE_IBU_FINISH_QP);    MPIDI_FUNC_ENTER(MPID_STATE_IBU_FINISH_QP);    MPIU_DBG_PRINTF(("entering ibu_finish_qp\n"));    p->dest_qp_num = dest_qp_num;    p->dlid = dest_lid;    /*MPIDI_DBG_PRINTF((60, FCNAME, "modifyQP(INIT)"));*/    status = modifyQP(p, IB_QPS_INIT);    if (status != IBU_SUCCESS)    {	MPIU_Internal_error_printf("ibu_finish_qp: modifyQP(INIT) failed, error %s\n", ib_get_err_str(status));	MPIDI_FUNC_EXIT(MPID_STATE_IBU_FINISH_QP);	return -1;    }    /*MPIDI_DBG_PRINTF((60, FCNAME, "modifyQP(RTR)"));*/    status = modifyQP(p, IB_QPS_RTR);    if (status != IBU_SUCCESS)    {	MPIU_Internal_error_printf("ibu_finish_qp: modifyQP(RTR) failed, error %s\n", ib_get_err_str(status));	MPIDI_FUNC_EXIT(MPID_STATE_IBU_FINISH_QP);	return -1;    }    /*MPIDI_DBG_PRINTF((60, FCNAME, "modifyQP(RTS)"));*/    status = modifyQP(p, IB_QPS_RTS);    if (status != IBU_SUCCESS)    {	MPIU_Internal_error_printf("ibu_finish_qp: modifyQP(RTS) failed, error %s\n", ib_get_err_str(status));	MPIDI_FUNC_EXIT(MPID_STATE_IBU_FINISH_QP);	return -1;    }    /* Added by Mellanox, dafna April 11th */     status = getMaxInlineSize(p);    if (status != IBU_SUCCESS)    {	MPIU_Internal_error_printf("ibu_finish_qp: getMaxInlineSize() failed, error %s\n", ib_get_err_str(status));	MPIDI_FUNC_EXIT(MPID_STATE_IBU_FINISH_QP);	return -1;    }    p->send_wqe_info_fifo.head = 0;    p->send_wqe_info_fifo.tail = 0;	    /* Finished scope added by Mellanox, dafna April 11th; removed receive posting.  */     MPIU_DBG_PRINTF(("exiting ibu_finish_qp\n"));        MPIDI_FUNC_EXIT(MPID_STATE_IBU_FINISH_QP);    return MPI_SUCCESS;}/* * Mellanox, dafna April 11th changed post_ack_write upside down to match new methodology * */#undef FUNCNAME#define FUNCNAME ibui_post_ack_write#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int ibui_post_ack_write(ibu_t ibu){    int mpi_errno = MPI_SUCCESS;    int num_bytes;    MPIDI_CH3_Pkt_t upkt;    MPIDI_CH3_Pkt_rdma_limit_upt_t * const ack_pkt = &upkt.limit_upt;    MPIDI_STATE_DECL(MPID_STATE_IBUI_POST_ACK_WRITE);    MPIDI_FUNC_ENTER(MPID_STATE_IBUI_POST_ACK_WRITE);    MPIU_DBG_PRINTF(("entering ibui_post_ack_write\n"));    ack_pkt->iov_len = 0;    ack_pkt->type = MPIDI_CH3_PKT_LMT_UPT;#ifdef MPICH_DBG_OUTPUT    MPIDI_DBG_Print_packet((MPIDI_CH3_Pkt_t*)ack_pkt);#endif    mpi_errno = ibu_write(ibu, ack_pkt, (int)sizeof(MPIDI_CH3_Pkt_t), &num_bytes); /* Mellanox - write with special ack pkt header */    if (mpi_errno != MPI_SUCCESS || num_bytes != sizeof(MPIDI_CH3_Pkt_t))    {	mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**nomem", 0);	MPIDI_FUNC_EXIT(MPID_STATE_IBUI_POST_ACK_WRITE);	return mpi_errno;    }    MPIU_DBG_PRINTF(("exiting ibui_post_ack_write\n"));    MPIDI_FUNC_EXIT(MPID_STATE_IBUI_POST_ACK_WRITE);    return mpi_errno;}/* ibu functions *///Mellanox, dafna April 11th added functions (up to ibu_write)#undef FUNCNAME#define FUNCNAME ibui_post_rndv_cts_iov_reg_err#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int ibui_post_rndv_cts_iov_reg_err(ibu_t ibu, MPID_Request * rreq){    int mpi_errno = MPI_SUCCESS;    int num_bytes;    MPIDI_CH3_Pkt_t upkt;    MPIDI_CH3_Pkt_rndv_reg_error_t* const cts_iov_reg_err_pkt = &upkt.rndv_reg_error;    MPIDI_STATE_DECL(MPID_STATE_IBUI_POST_RNDV_CTS_IOV_REG_ERR);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -