sshmem_mkey_t *mca_spml_ikrit_register(void* addr, size_t size, uint64_t shmid, int *count) { int i; sshmem_mkey_t *mkeys; mxm_error_t err; mxm_mem_key_t *m_key; int my_rank = oshmem_my_proc_id(); *count = 0; mkeys = (sshmem_mkey_t *) calloc(1, MXM_PTL_LAST * sizeof(*mkeys)); if (!mkeys) { return NULL ; } for (i = 0; i < MXM_PTL_LAST; i++) { mkeys[i].u.key = MAP_SEGMENT_SHM_INVALID; switch (i) { case MXM_PTL_SHM: if ((int)shmid != MAP_SEGMENT_SHM_INVALID) { mkeys[i].u.key = shmid; mkeys[i].va_base = 0; } else { mkeys[i].len = 0; mkeys[i].va_base = addr; } mkeys[i].spml_context = 0; break; case MXM_PTL_RDMA: mkeys[i].va_base = addr; mkeys[i].spml_context = 0; if (mca_spml_ikrit.ud_only) { mkeys[i].len = 0; break; } err = mxm_mem_map(mca_spml_ikrit.mxm_context, &addr, &size, 0, 0, 0); if (MXM_OK != err) { SPML_ERROR("Failed to register memory: %s", mxm_error_string(err)); goto error_out; } mkeys[i].spml_context = (void *)(unsigned long)size; m_key = malloc(sizeof(*m_key)); if (NULL == m_key) { SPML_ERROR("Failed to allocate m_key memory"); goto error_out; } mkeys[i].len = sizeof(*m_key); mkeys[i].u.data = m_key; err = mxm_mem_get_key(mca_spml_ikrit.mxm_context, addr, m_key); if (MXM_OK != err) { SPML_ERROR("Failed to get memory key: %s", mxm_error_string(err)); goto error_out; } break; default: SPML_ERROR("unsupported PTL: %d", i); goto error_out; } SPML_VERBOSE(5, "rank %d ptl %d addr %p size %llu %s", my_rank, i, addr, (unsigned long long)size, mca_spml_base_mkey2str(&mkeys[i])); mca_spml_ikrit_cache_mkeys(&mkeys[i], memheap_find_segnum(addr), my_rank, i); } *count = MXM_PTL_LAST; return mkeys; error_out: mca_spml_ikrit_deregister(mkeys); return NULL; }
sshmem_mkey_t *mca_spml_ucx_register(void* addr, size_t size, uint64_t shmid, int *count) { sshmem_mkey_t *mkeys; ucs_status_t status; spml_ucx_mkey_t *ucx_mkey; size_t len; ucp_mem_map_params_t mem_map_params; int segno; map_segment_t *mem_seg; unsigned flags; int my_pe = oshmem_my_proc_id(); *count = 0; mkeys = (sshmem_mkey_t *) calloc(1, sizeof(*mkeys)); if (!mkeys) { return NULL; } segno = memheap_find_segnum(addr); mem_seg = memheap_find_seg(segno); ucx_mkey = &mca_spml_ucx_ctx_default.ucp_peers[my_pe].mkeys[segno].key; mkeys[0].spml_context = ucx_mkey; /* if possible use mem handle already created by ucx allocator */ if (MAP_SEGMENT_ALLOC_UCX != mem_seg->type) { flags = 0; if (mca_spml_ucx.heap_reg_nb && memheap_is_va_in_segment(addr, HEAP_SEG_INDEX)) { flags = UCP_MEM_MAP_NONBLOCK; } mem_map_params.field_mask = UCP_MEM_MAP_PARAM_FIELD_ADDRESS | UCP_MEM_MAP_PARAM_FIELD_LENGTH | UCP_MEM_MAP_PARAM_FIELD_FLAGS; mem_map_params.address = addr; mem_map_params.length = size; mem_map_params.flags = flags; status = ucp_mem_map(mca_spml_ucx.ucp_context, &mem_map_params, &ucx_mkey->mem_h); if (UCS_OK != status) { goto error_out; } } else { ucx_mkey->mem_h = (ucp_mem_h)mem_seg->context; } status = ucp_rkey_pack(mca_spml_ucx.ucp_context, ucx_mkey->mem_h, &mkeys[0].u.data, &len); if (UCS_OK != status) { goto error_unmap; } if (len >= 0xffff) { SPML_UCX_ERROR("packed rkey is too long: %llu >= %d", (unsigned long long)len, 0xffff); oshmem_shmem_abort(-1); } status = ucp_ep_rkey_unpack(mca_spml_ucx_ctx_default.ucp_peers[oshmem_group_self->my_pe].ucp_conn, mkeys[0].u.data, &ucx_mkey->rkey); if (UCS_OK != status) { SPML_UCX_ERROR("failed to unpack rkey"); goto error_unmap; } mkeys[0].len = len; mkeys[0].va_base = addr; *count = 1; mca_spml_ucx_cache_mkey(&mca_spml_ucx_ctx_default, &mkeys[0], segno, my_pe); return mkeys; error_unmap: ucp_mem_unmap(mca_spml_ucx.ucp_context, ucx_mkey->mem_h); error_out: free(mkeys); return NULL ; }