int mca_pml_yalla_init(void) { mxm_error_t error; int rc; PML_YALLA_VERBOSE(1, "mca_pml_yalla_init"); if (ompi_pml_yalla.using_mem_hooks) { opal_mem_hooks_register_release(mca_pml_yalla_mem_release_cb, NULL); } error = mxm_ep_create(ompi_pml_yalla.mxm_context, ompi_pml_yalla.ep_opts, &ompi_pml_yalla.mxm_ep); if (MXM_OK != error) { return OMPI_ERROR; } rc = send_ep_address(); if (rc < 0) { return rc; } OBJ_CONSTRUCT(&ompi_pml_yalla.send_reqs, mca_pml_yalla_freelist_t); OBJ_CONSTRUCT(&ompi_pml_yalla.bsend_reqs, mca_pml_yalla_freelist_t); OBJ_CONSTRUCT(&ompi_pml_yalla.recv_reqs, mca_pml_yalla_freelist_t); OBJ_CONSTRUCT(&ompi_pml_yalla.convs, mca_pml_yalla_freelist_t); opal_progress_register(mca_pml_yalla_progress); PML_YALLA_VERBOSE(2, "created mxm context %p ep %p", (void *)ompi_pml_yalla.mxm_context, (void *)ompi_pml_yalla.mxm_ep); return OMPI_SUCCESS; }
static int mca_pml_ucx_component_open(void) { ompi_pml_ucx.output = opal_output_open(NULL); opal_output_set_verbosity(ompi_pml_ucx.output, ompi_pml_ucx.verbose); /* Set memory hooks */ if (ompi_pml_ucx.opal_mem_hooks && (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) == ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & opal_mem_hooks_support_level())) { PML_UCX_VERBOSE(1, "%s", "using OPAL memory hooks as external events"); ucm_set_external_event(UCM_EVENT_VM_UNMAPPED); opal_mem_hooks_register_release(mca_pml_ucx_mem_release_cb, NULL); } return mca_pml_ucx_open(); }
static int alloc_free_test(void) { void *foo, *bar; int retval; retval = opal_mem_hooks_register_release(release_callback, NULL); retval |= opal_mem_hooks_register_alloc(alloc_callback, NULL); if (retval != OMPI_SUCCESS) { printf("handler registration failed\n"); return retval; } /* make some big malloc that should always trip a release on free */ printf(" - malloc big buffer\n"); counter = 0; foo = malloc(bigsize); assert(counter >= 1); printf(" - free of big buffer\n"); counter = 1; free(foo); assert(counter == 0); /* check mmap / munmap */ printf(" - mmap of buffer\n"); counter = 0; bar = mmap(NULL, 4096, PROT_READ, MAP_ANON, -1, 0); if (opal_mem_hooks_support_level() & OPAL_MEMORY_MMAP_SUPPORT) { assert(counter >= 1); } printf(" - munmap of buffer\n"); /* mmap might call malloc internally, so do this or we might appear to leak memory */ counter = 1; munmap(NULL, 0); assert(counter == 0); retval = opal_mem_hooks_unregister_release(release_callback); retval |= opal_mem_hooks_unregister_alloc(alloc_callback); return OPAL_SUCCESS; }
int ompi_mtl_mxm_module_init(void) { #if MXM_API < MXM_VERSION(2,0) ompi_mtl_mxm_ep_conn_info_t ep_info; #endif void *ep_address; size_t ep_address_len; mxm_error_t err; uint32_t jobid; uint64_t mxlr; ompi_proc_t **procs; unsigned ptl_bitmap; size_t totps, proc; int lr, nlps; int rc; mxlr = 0; lr = -1; jobid = ompi_mtl_mxm_get_job_id(); if (0 == jobid) { MXM_ERROR("Failed to generate jobid"); return OMPI_ERROR; } if (NULL == (procs = ompi_proc_world(&totps))) { MXM_ERROR("Unable to obtain process list"); return OMPI_ERROR; } if (totps < (size_t)ompi_mtl_mxm.mxm_np) { MXM_VERBOSE(1, "MXM support will be disabled because of total number " "of processes (%lu) is less than the minimum set by the " "mtl_mxm_np MCA parameter (%u)", totps, ompi_mtl_mxm.mxm_np); return OMPI_ERR_NOT_SUPPORTED; } MXM_VERBOSE(1, "MXM support enabled"); if (ORTE_NODE_RANK_INVALID == (lr = ompi_process_info.my_node_rank)) { MXM_ERROR("Unable to obtain local node rank"); return OMPI_ERROR; } nlps = ompi_process_info.num_local_peers + 1; for (proc = 0; proc < totps; proc++) { if (OPAL_PROC_ON_LOCAL_NODE(procs[proc]->proc_flags)) { mxlr = max(mxlr, procs[proc]->proc_name.vpid); } } /* Setup the endpoint options and local addresses to bind to. */ #if MXM_API < MXM_VERSION(2,0) ptl_bitmap = ompi_mtl_mxm.mxm_ctx_opts->ptl_bitmap; #else ptl_bitmap = 0; #endif /* Open MXM endpoint */ err = ompi_mtl_mxm_create_ep(ompi_mtl_mxm.mxm_context, &ompi_mtl_mxm.ep, ptl_bitmap, lr, jobid, mxlr, nlps); if (MXM_OK != err) { opal_show_help("help-mtl-mxm.txt", "unable to create endpoint", true, mxm_error_string(err)); return OMPI_ERROR; } /* * Get address for each PTL on this endpoint, and share it with other ranks. */ #if MXM_API < MXM_VERSION(2,0) if ((ptl_bitmap & MXM_BIT(MXM_PTL_SELF)) && OMPI_SUCCESS != ompi_mtl_mxm_get_ep_address(&ep_info, MXM_PTL_SELF)) { return OMPI_ERROR; } if ((ptl_bitmap & MXM_BIT(MXM_PTL_RDMA)) && OMPI_SUCCESS != ompi_mtl_mxm_get_ep_address(&ep_info, MXM_PTL_RDMA)) { return OMPI_ERROR; } if ((ptl_bitmap & MXM_BIT(MXM_PTL_SHM)) && OMPI_SUCCESS != ompi_mtl_mxm_get_ep_address(&ep_info, MXM_PTL_SHM)) { return OMPI_ERROR; } ep_address = &ep_info; ep_address_len = sizeof(ep_info); #else rc = ompi_mtl_mxm_get_ep_address(&ep_address, &ep_address_len); if (OMPI_SUCCESS != rc) { return rc; } #endif rc = ompi_mtl_mxm_send_ep_address(ep_address, ep_address_len); if (OMPI_SUCCESS != rc) { MXM_ERROR("Modex session failed."); return rc; } #if MXM_API >= MXM_VERSION(2,0) free(ep_address); #endif /* Register the MXM progress function */ opal_progress_register(ompi_mtl_mxm_progress); #if MXM_API >= MXM_VERSION(2,0) if (ompi_mtl_mxm.using_mem_hooks) { opal_mem_hooks_register_release(ompi_mtl_mxm_mem_release_cb, NULL); } #endif return OMPI_SUCCESS; }
mca_mpool_base_module_t* mca_mpool_base_module_create( const char* name, void* user_data, struct mca_mpool_base_resources_t* resources) { mca_mpool_base_component_t* component = NULL; mca_mpool_base_module_t* module = NULL; opal_list_item_t* item; mca_mpool_base_selected_module_t *sm; for (item = opal_list_get_first(&mca_mpool_base_components); item != opal_list_get_end(&mca_mpool_base_components); item = opal_list_get_next(item)) { mca_base_component_list_item_t *cli = (mca_base_component_list_item_t *) item; component = (mca_mpool_base_component_t *) cli->cli_component; if(0 == strcmp(component->mpool_version.mca_component_name, name)) { break; } } if (opal_list_get_end(&mca_mpool_base_components) == item) { return NULL; } module = component->mpool_init(resources); if ( NULL == module ) { return NULL; } sm = OBJ_NEW(mca_mpool_base_selected_module_t); sm->mpool_component = component; sm->mpool_module = module; sm->user_data = user_data; sm->mpool_resources = resources; opal_list_append(&mca_mpool_base_modules, (opal_list_item_t*) sm); /* on the very first creation of a module we init the memory callback */ if (opal_list_get_size(&mca_mpool_base_modules) == 1) { /* Default to not using memory hooks */ int use_mem_hooks = 0; /* Use the memory hooks if leave_pinned or leave_pinned_pipeline is enabled (note that either of these leave_pinned variables may have been set by a user MCA param or elsewhere in the code base). Yes, we could have coded this more succinctly, but this is more clear. */ if (ompi_mpi_leave_pinned || ompi_mpi_leave_pinned_pipeline) { use_mem_hooks = 1; } if (use_mem_hooks) { if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) == ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & opal_mem_hooks_support_level())) { opal_mem_hooks_register_release(mca_mpool_base_mem_cb, NULL); } else { orte_show_help("help-mpool-base.txt", "leave pinned failed", true, name, ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), orte_process_info.nodename); return NULL; } /* Set this to true so that mpool_base_close knows to cleanup */ mca_mpool_base_used_mem_hooks = 1; } } return module; }
int mca_pml_yalla_init(void) { mxm_context_opts_t *ctx_opts; mxm_ep_opts_t *ep_opts; mxm_error_t error; int rc; PML_YALLA_VERBOSE(1, "mca_pml_yalla_init"); /* Set memory hooks */ if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) == ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & opal_mem_hooks_support_level())) { PML_YALLA_VERBOSE(1, "enabling on-demand memory mapping"); opal_setenv("MXM_PML_MEM_ON_DEMAND_MAP", "y", false, &environ); ompi_pml_yalla.using_mem_hooks = 1; } else { PML_YALLA_VERBOSE(1, "disabling on-demand memory mapping"); ompi_pml_yalla.using_mem_hooks = 0; } opal_setenv("MXM_PML_SINGLE_THREAD", ompi_mpi_thread_multiple ? "n" : "y", false, &environ); /* Read options */ error = mxm_config_read_opts(&ctx_opts, &ep_opts, "PML", NULL, 0); if (MXM_OK != error) { return OMPI_ERROR; } error = mxm_init(ctx_opts, &ompi_pml_yalla.mxm_context); if (MXM_OK != error) { return OMPI_ERROR; } if (ompi_pml_yalla.using_mem_hooks) { opal_mem_hooks_register_release(mca_pml_yalla_mem_release_cb, NULL); } error = mxm_ep_create(ompi_pml_yalla.mxm_context, ep_opts, &ompi_pml_yalla.mxm_ep); if (MXM_OK != error) { return OMPI_ERROR; } mxm_config_free_context_opts(ctx_opts); mxm_config_free_ep_opts(ep_opts); rc = send_ep_address(); if (rc < 0) { return rc; } OBJ_CONSTRUCT(&ompi_pml_yalla.send_reqs, mca_pml_yalla_freelist_t); OBJ_CONSTRUCT(&ompi_pml_yalla.bsend_reqs, mca_pml_yalla_freelist_t); OBJ_CONSTRUCT(&ompi_pml_yalla.recv_reqs, mca_pml_yalla_freelist_t); OBJ_CONSTRUCT(&ompi_pml_yalla.convs, mca_pml_yalla_freelist_t); opal_progress_register(mca_pml_yalla_progress); PML_YALLA_VERBOSE(2, "created mxm context %p ep %p", ompi_pml_yalla.mxm_context, ompi_pml_yalla.mxm_ep); return OMPI_SUCCESS; }
/* * Invoked when there's a new communicator that has been created. * Look at the communicator and decide which set of functions and * priority we want to return. */ mca_coll_base_module_t * mca_coll_hcoll_comm_query(struct ompi_communicator_t *comm, int *priority) { mca_coll_base_module_t *module; mca_coll_hcoll_module_t *hcoll_module; ompi_attribute_fn_ptr_union_t del_fn; ompi_attribute_fn_ptr_union_t copy_fn; mca_coll_hcoll_component_t *cm; int err; int rc; cm = &mca_coll_hcoll_component; *priority = 0; module = NULL; if (!cm->hcoll_enable) { return NULL; } if (OMPI_COMM_IS_INTER(comm) || ompi_comm_size(comm) < cm->hcoll_np || ompi_comm_size(comm) < 2) { return NULL; } if (!cm->libhcoll_initialized) { /* libhcoll should be initialized here since current implmentation of mxm bcol in libhcoll needs world_group fully functional during init world_group, i.e. ompi_comm_world, is not ready at hcoll component open call */ opal_progress_register(mca_coll_hcoll_progress); HCOL_VERBOSE(10,"Calling hcoll_init();"); #if HCOLL_API >= HCOLL_VERSION(3,2) hcoll_read_init_opts(&cm->init_opts); cm->init_opts->base_tag = MCA_COLL_BASE_TAG_HCOLL_BASE; cm->init_opts->max_tag = mca_pml.pml_max_tag; cm->init_opts->enable_thread_support = ompi_mpi_thread_multiple; rc = hcoll_init_with_opts(&cm->init_opts); #else hcoll_set_runtime_tag_offset(MCA_COLL_BASE_TAG_HCOLL_BASE, mca_pml.pml_max_tag); rc = hcoll_init(); #endif if (HCOLL_SUCCESS != rc) { cm->hcoll_enable = 0; opal_progress_unregister(mca_coll_hcoll_progress); HCOL_ERROR("Hcol library init failed"); return NULL; } #if HCOLL_API >= HCOLL_VERSION(3,2) if (cm->using_mem_hooks && cm->init_opts->mem_hook_needed) { #else if (cm->using_mem_hooks && hcoll_check_mem_release_cb_needed()) { #endif opal_mem_hooks_register_release(mca_coll_hcoll_mem_release_cb, NULL); } else { cm->using_mem_hooks = 0; } copy_fn.attr_communicator_copy_fn = (MPI_Comm_internal_copy_attr_function*) MPI_COMM_NULL_COPY_FN; del_fn.attr_communicator_delete_fn = hcoll_comm_attr_del_fn; err = ompi_attr_create_keyval(COMM_ATTR, copy_fn, del_fn, &hcoll_comm_attr_keyval, NULL ,0, NULL); if (OMPI_SUCCESS != err) { cm->hcoll_enable = 0; hcoll_finalize(); opal_progress_unregister(mca_coll_hcoll_progress); HCOL_ERROR("Hcol comm keyval create failed"); return NULL; } if (mca_coll_hcoll_component.derived_types_support_enabled) { copy_fn.attr_datatype_copy_fn = (MPI_Type_internal_copy_attr_function *) MPI_TYPE_NULL_COPY_FN; del_fn.attr_datatype_delete_fn = hcoll_type_attr_del_fn; err = ompi_attr_create_keyval(TYPE_ATTR, copy_fn, del_fn, &hcoll_type_attr_keyval, NULL ,0, NULL); if (OMPI_SUCCESS != err) { cm->hcoll_enable = 0; hcoll_finalize(); opal_progress_unregister(mca_coll_hcoll_progress); HCOL_ERROR("Hcol type keyval create failed"); return NULL; } } OBJ_CONSTRUCT(&cm->dtypes, opal_free_list_t); opal_free_list_init(&cm->dtypes, sizeof(mca_coll_hcoll_dtype_t), 8, OBJ_CLASS(mca_coll_hcoll_dtype_t), 0, 0, 32, -1, 32, NULL, 0, NULL, NULL, NULL); } hcoll_module = OBJ_NEW(mca_coll_hcoll_module_t); if (!hcoll_module) { if (!cm->libhcoll_initialized) { cm->hcoll_enable = 0; hcoll_finalize(); opal_progress_unregister(mca_coll_hcoll_progress); } return NULL; } hcoll_module->comm = comm; HCOL_VERBOSE(10,"Creating hcoll_context for comm %p, comm_id %d, comm_size %d", (void*)comm,comm->c_contextid,ompi_comm_size(comm)); hcoll_module->hcoll_context = hcoll_create_context((rte_grp_handle_t)comm); if (NULL == hcoll_module->hcoll_context) { HCOL_VERBOSE(1,"hcoll_create_context returned NULL"); OBJ_RELEASE(hcoll_module); if (!cm->libhcoll_initialized) { cm->hcoll_enable = 0; hcoll_finalize(); opal_progress_unregister(mca_coll_hcoll_progress); } return NULL; } hcoll_module->super.coll_module_enable = mca_coll_hcoll_module_enable; hcoll_module->super.coll_barrier = hcoll_collectives.coll_barrier ? mca_coll_hcoll_barrier : NULL; hcoll_module->super.coll_bcast = hcoll_collectives.coll_bcast ? mca_coll_hcoll_bcast : NULL; hcoll_module->super.coll_allgather = hcoll_collectives.coll_allgather ? mca_coll_hcoll_allgather : NULL; hcoll_module->super.coll_allgatherv = hcoll_collectives.coll_allgatherv ? mca_coll_hcoll_allgatherv : NULL; hcoll_module->super.coll_allreduce = hcoll_collectives.coll_allreduce ? mca_coll_hcoll_allreduce : NULL; hcoll_module->super.coll_alltoall = hcoll_collectives.coll_alltoall ? mca_coll_hcoll_alltoall : NULL; hcoll_module->super.coll_alltoallv = hcoll_collectives.coll_alltoallv ? mca_coll_hcoll_alltoallv : NULL; hcoll_module->super.coll_gatherv = hcoll_collectives.coll_gatherv ? mca_coll_hcoll_gatherv : NULL; hcoll_module->super.coll_reduce = hcoll_collectives.coll_reduce ? mca_coll_hcoll_reduce : NULL; hcoll_module->super.coll_ibarrier = hcoll_collectives.coll_ibarrier ? mca_coll_hcoll_ibarrier : NULL; hcoll_module->super.coll_ibcast = hcoll_collectives.coll_ibcast ? mca_coll_hcoll_ibcast : NULL; hcoll_module->super.coll_iallgather = hcoll_collectives.coll_iallgather ? mca_coll_hcoll_iallgather : NULL; #if HCOLL_API >= HCOLL_VERSION(3,5) hcoll_module->super.coll_iallgatherv = hcoll_collectives.coll_iallgatherv ? mca_coll_hcoll_iallgatherv : NULL; #else hcoll_module->super.coll_iallgatherv = NULL; #endif hcoll_module->super.coll_iallreduce = hcoll_collectives.coll_iallreduce ? mca_coll_hcoll_iallreduce : NULL; #if HCOLL_API >= HCOLL_VERSION(3,5) hcoll_module->super.coll_ireduce = hcoll_collectives.coll_ireduce ? mca_coll_hcoll_ireduce : NULL; #else hcoll_module->super.coll_ireduce = NULL; #endif hcoll_module->super.coll_gather = /*hcoll_collectives.coll_gather ? mca_coll_hcoll_gather :*/ NULL; hcoll_module->super.coll_igatherv = hcoll_collectives.coll_igatherv ? mca_coll_hcoll_igatherv : NULL; hcoll_module->super.coll_ialltoall = /*hcoll_collectives.coll_ialltoall ? mca_coll_hcoll_ialltoall : */ NULL; #if HCOLL_API >= HCOLL_VERSION(3,7) hcoll_module->super.coll_ialltoallv = hcoll_collectives.coll_ialltoallv ? mca_coll_hcoll_ialltoallv : NULL; #else hcoll_module->super.coll_ialltoallv = NULL; #endif *priority = cm->hcoll_priority; module = &hcoll_module->super; if (!cm->libhcoll_initialized) { cm->libhcoll_initialized = true; } return module; } OBJ_CLASS_INSTANCE(mca_coll_hcoll_module_t, mca_coll_base_module_t, mca_coll_hcoll_module_construct, mca_coll_hcoll_module_destruct);