コード例 #1
0
ファイル: pml_yalla.c プロジェクト: nrgraham23/ompi
int mca_pml_yalla_open(void)
{
    mxm_error_t error;

    PML_YALLA_VERBOSE(1, "mca_pml_yalla_open");

    /* 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(&ompi_pml_yalla.ctx_opts, &ompi_pml_yalla.ep_opts,
                                 "MPI", NULL, 0);
    if (MXM_OK != error) {
        return OMPI_ERROR;
    }

    error = mxm_init(ompi_pml_yalla.ctx_opts, &ompi_pml_yalla.mxm_context);
    if (MXM_OK != error) {
        return OMPI_ERROR;
    }

    return OMPI_SUCCESS;
}
コード例 #2
0
static int hcoll_open(void)
{
    mca_coll_hcoll_component_t *cm;
    cm  = &mca_coll_hcoll_component;

    mca_coll_hcoll_output = opal_output_open(NULL);
    opal_output_set_verbosity(mca_coll_hcoll_output, cm->hcoll_verbose);

    hcoll_rte_fns_setup();

    cm->libhcoll_initialized = false;

    /* Register memory hooks */
    if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) ==
        ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) &
         opal_mem_hooks_support_level()))
    {
        setenv("MXM_HCOLL_MEM_ON_DEMAND_MAP", "y", 0);
        HCOL_VERBOSE(1, "Enabling on-demand memory mapping");
        cm->using_mem_hooks = 1;
    } else {
        HCOL_VERBOSE(1, "Disabling on-demand memory mapping");
        cm->using_mem_hooks = 0;
    }

    return OMPI_SUCCESS;
}
コード例 #3
0
ファイル: opal_memory_basic.c プロジェクト: aosm/openmpi
int
main(int argc, char *argv[])
{
    int ret;
    int support;

    opal_init();

    /* this printf needs to be here for the test to work! */
    printf("running malloc hooks test\n");

    support = opal_mem_hooks_support_level();
    if (0 == support) {
        printf("no memory registration supported.  skipping test.\n");
        ret = 77;
    } else if ((OPAL_MEMORY_FREE_SUPPORT|OPAL_MEMORY_MALLOC_SUPPORT) ==
               ((OPAL_MEMORY_FREE_SUPPORT|OPAL_MEMORY_MALLOC_SUPPORT) & support)) {
        ret = alloc_free_test();
    } else if (OPAL_MEMORY_FREE_SUPPORT & support) {
        ret  = free_only_test();
    } else {
        printf("Odd support response: %d\n", support);
        ret = 1;
    }

    opal_finalize();

    return ret;
}
コード例 #4
0
ファイル: common_mx.c プロジェクト: rjrpaz/MyOpenMPI
int
ompi_common_mx_initialize(void)
{
    mx_return_t mx_return;
    struct mca_mpool_base_resources_t mpool_resources;
    int index, value;
    
    ompi_common_mx_initialize_ref_cnt++;
    
    if(ompi_common_mx_initialize_ref_cnt == 1) { 
        /* set the MX error handle to always return. This function is the
         * only MX function allowed to be called before mx_init in order
         * to make sure that if the MX is not up and running the MX
         * library does not exit the application.
         */
        mx_set_error_handler(MX_ERRORS_RETURN);
	
	/* If we have a memory manager available, and
	   mpi_leave_pinned == -1, then set mpi_leave_pinned to 1.

	   We have a memory manager if:
	   - we have both FREE and MUNMAP support
	   - we have MUNMAP support and the linux mallopt */
	value = opal_mem_hooks_support_level();
	if ((value & (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT))
            == (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT)) {
	  index = mca_base_param_find("mpi", NULL, "leave_pinned");
	  if (index >= 0)
            if ((mca_base_param_lookup_int(index, &value) == OPAL_SUCCESS) 
		&& (value == -1)) {
	      
	      ompi_mpi_leave_pinned = 1;
	      setenv("MX_RCACHE", "2", 1);
	      mpool_resources.regcache_clean = mx__regcache_clean;
	      ompi_common_mx_fake_mpool = 
		mca_mpool_base_module_create("fake", NULL, &mpool_resources);
	      if (!ompi_common_mx_fake_mpool) {
		ompi_mpi_leave_pinned = 0;
		setenv("MX_RCACHE", "0", 1);
		opal_output(0, "Error creating fake mpool (error %s)\n",
			    strerror(errno));
	      }
	    }
	}
	
        /* initialize the mx library */
        mx_return = mx_init(); 
        
        if(MX_SUCCESS != mx_return) {
            opal_output(0,
                        "Error in mx_init (error %s)\n",
                        mx_strerror(mx_return));
            return OMPI_ERR_NOT_AVAILABLE;
        }
        
    } 
    return OMPI_SUCCESS;
}
コード例 #5
0
static void mca_btl_ugni_autoset_leave_pinned (void) {
    int value = opal_mem_hooks_support_level();
    if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) ==
        ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & value)) {
        /* Set leave pinned to 1 if leave pinned pipeline is not set */
        if (-1 == ompi_mpi_leave_pinned) {
            ompi_mpi_leave_pinned = !ompi_mpi_leave_pinned_pipeline;
        }
    } else {
        ompi_mpi_leave_pinned = 0;
        ompi_mpi_leave_pinned_pipeline = 0;
    }
}
コード例 #6
0
int mca_mpool_base_close(void)
{
  opal_list_item_t *item;
  mca_mpool_base_selected_module_t *sm;
  int32_t modules_length;

  /* Need the initial length in order to know if some of the initializations
   * are done in the open function.
   */
  modules_length = opal_list_get_size(&mca_mpool_base_modules);

  /* Finalize all the mpool components and free their list items */

  for (item = opal_list_remove_first(&mca_mpool_base_modules);
       NULL != item; 
       item = opal_list_remove_first(&mca_mpool_base_modules)) {
    sm = (mca_mpool_base_selected_module_t *) item;

    /* Blatently ignore the return code (what would we do to recover,
       anyway?  This component is going away, so errors don't matter
       anymore).  Note that it's legal for the module to have NULL for
       the finalize function. */

    if (NULL != sm->mpool_module->mpool_finalize) {
        sm->mpool_module->mpool_finalize(sm->mpool_module);
    }
    OBJ_RELEASE(sm);
  }

  /* Close all remaining available components (may be one if this is a
     OMPI RTE program, or [possibly] multiple if this is ompi_info) */

  mca_base_components_close(mca_mpool_base_output, 
                            &mca_mpool_base_components, NULL);

  /* deregister memory free callback */
  if( (modules_length > 0) && mca_mpool_base_used_mem_hooks && 
     0 != (OPAL_MEMORY_FREE_SUPPORT & opal_mem_hooks_support_level())) {
      opal_mem_hooks_unregister_release(mca_mpool_base_mem_cb);
      OBJ_DESTRUCT(&mca_mpool_base_mem_cb_array);
  }
  /* All done */

  return OMPI_SUCCESS;
}
コード例 #7
0
ファイル: pml_ucx_component.c プロジェクト: thananon/ompi
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();
}
コード例 #8
0
static void mca_btl_ugni_autoset_leave_pinned (void) {
    if (MCA_BTL_UGNI_MPOOL_UDREG != mca_btl_ugni_component.mpool_type) {
        int value = opal_mem_hooks_support_level();
        if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) ==
            ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & value)) {
            /* Set leave pinned to 1 if leave pinned pipeline is not set */
            if (-1 == opal_leave_pinned) {
                opal_leave_pinned = !opal_leave_pinned_pipeline;
            }
        } else {
            opal_leave_pinned = 0;
            opal_leave_pinned_pipeline = 0;
        }
    } else if (-1 == opal_leave_pinned) {
        /* if udreg is in use we can set leave pinned without checking for the
         * memory hooks. */
        opal_leave_pinned = !opal_leave_pinned_pipeline;
    }
}
コード例 #9
0
ファイル: opal_memory_basic.c プロジェクト: aosm/openmpi
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;
}
コード例 #10
0
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; 
}
コード例 #11
0
ファイル: pml_yalla.c プロジェクト: Cai900205/test
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;
}