root/oshmem/mca/memheap/base/memheap_base_select.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_memheap_base_select
  2. _memheap_size
  3. _memheap_create

   1 /*
   2  * Copyright (c) 2013-2015 Mellanox Technologies, Inc.
   3  *                         All rights reserved.
   4  * Copyright (c) 2015-2019 Research Organization for Information Science
   5  *                         and Technology (RIST).  All rights reserved.
   6  * $COPYRIGHT$
   7  *
   8  * Additional copyrights may follow
   9  *
  10  * $HEADER$
  11  */
  12 
  13 #include "oshmem_config.h"
  14 
  15 #include "opal/util/argv.h"
  16 #include "opal/util/show_help.h"
  17 #include "oshmem/mca/mca.h"
  18 #include "opal/mca/base/base.h"
  19 #include "opal/mca/base/mca_base_component_repository.h"
  20 #include "oshmem/info/info.h"
  21 #include "oshmem/util/oshmem_util.h"
  22 #include "oshmem/mca/memheap/memheap.h"
  23 #include "oshmem/mca/memheap/base/base.h"
  24 #include "oshmem/include/shmemx.h"
  25 #include "oshmem/mca/sshmem/base/base.h"
  26 
  27 
  28 mca_memheap_base_config_t mca_memheap_base_config = {
  29     .device_nic_mem_seg_size = 0
  30 };
  31 
  32 mca_memheap_base_module_t mca_memheap = {0};
  33 
  34 /**
  35  * Function for weeding out memheap components that shouldn't be executed.
  36  * Implementation inspired by btl/base.
  37  *
  38  * Call the init function on all available components to find out if
  39  * they want to run. Select all components that don't fail.  Failing
  40  * components will be closed and unloaded.  The selected modules will
  41  * be pointed to by mca_memheap_base_module_t.
  42  */
  43 
  44 static memheap_context_t* _memheap_create(void);
  45 
  46 /**
  47  * Choose to init one component with the highest priority.
  48  * If the include list if it is not empty choose a component that appear in the list.
  49  * O/W choose the highest priority component not in the exclude list.
  50  * Include and exclude lists may be given in the shmem launcher command line.
  51  */
  52 int mca_memheap_base_select()
  53 {
  54     int best_priority;
  55     memheap_context_t *context;
  56     mca_memheap_base_component_t *best_component = NULL;
  57     mca_memheap_base_module_t *best_module = NULL;
  58 
  59     if( OPAL_SUCCESS != mca_base_select("memheap", oshmem_memheap_base_framework.framework_output,
  60                                         &oshmem_memheap_base_framework.framework_components,
  61                                         (mca_base_module_t **) &best_module,
  62                                         (mca_base_component_t **) &best_component,
  63                                         &best_priority) ) {
  64         return OSHMEM_ERROR;
  65     }
  66 
  67     context = _memheap_create();
  68     if (NULL == context) {
  69         return OSHMEM_ERROR;
  70     }
  71 
  72     if (OSHMEM_SUCCESS != best_component->memheap_init(context)) {
  73         opal_show_help("help-oshmem-memheap.txt",
  74                        "find-available:none-found",
  75                        true,
  76                        "memheap");
  77         return OSHMEM_ERROR;
  78     }
  79 
  80     /* Calculate memheap size in case it was not set during component initialization */
  81     best_module->memheap_size = context->user_size;
  82     setenv(SHMEM_HEAP_TYPE,
  83            best_component->memheap_version.mca_component_name, 1);
  84 
  85     mca_memheap = *best_module;
  86 
  87     MEMHEAP_VERBOSE(10,
  88                     "SELECTED %s component %s",
  89                     best_component->memheap_version.mca_type_name, 
  90                     best_component->memheap_version.mca_component_name);
  91 
  92     return OSHMEM_SUCCESS;
  93 }
  94 
  95 static size_t _memheap_size(void)
  96 {
  97     return (size_t) memheap_align(oshmem_shmem_info_env.symmetric_heap_size);
  98 }
  99 
 100 static memheap_context_t* _memheap_create(void)
 101 {
 102     int rc = OSHMEM_SUCCESS;
 103     static memheap_context_t context;
 104     size_t user_size, size;
 105 
 106     user_size = _memheap_size();
 107     if (user_size < MEMHEAP_BASE_MIN_SIZE) {
 108         MEMHEAP_ERROR("Requested memheap size is less than minimal meamheap size (%llu < %llu)",
 109                       (unsigned long long)user_size, MEMHEAP_BASE_MIN_SIZE);
 110         return NULL ;
 111     }
 112     /* Inititialize symmetric area */
 113     if (OSHMEM_SUCCESS == rc) {
 114         rc = mca_memheap_base_alloc_init(&mca_memheap_base_map,
 115                                          user_size + MEMHEAP_BASE_PRIVATE_SIZE, 0);
 116     }
 117 
 118     /* Initialize atomic symmetric area */
 119     size = mca_memheap_base_config.device_nic_mem_seg_size;
 120     if ((OSHMEM_SUCCESS == rc) && (size > 0)) {
 121         rc = mca_memheap_base_alloc_init(&mca_memheap_base_map, size,
 122                                          SHMEM_HINT_DEVICE_NIC_MEM);
 123         if (rc == OSHMEM_ERR_NOT_IMPLEMENTED) {
 124             /* do not treat NOT_IMPLEMENTED as error */
 125             rc = OSHMEM_SUCCESS;
 126         }
 127     }
 128 
 129     /* Inititialize static/global variables area */
 130     if (OSHMEM_SUCCESS == rc) {
 131         rc = mca_memheap_base_static_init(&mca_memheap_base_map);
 132     }
 133 
 134     /* Memory Registration */
 135     if (OSHMEM_SUCCESS == rc) {
 136         rc = mca_memheap_base_reg(&mca_memheap_base_map);
 137     }
 138 
 139     /* Init OOB channel */
 140     if (OSHMEM_SUCCESS == rc) {
 141         rc = memheap_oob_init(&mca_memheap_base_map);
 142     }
 143 
 144     if (OSHMEM_SUCCESS == rc) {
 145         context.user_size = user_size;
 146         context.private_size = MEMHEAP_BASE_PRIVATE_SIZE;
 147         context.user_base_addr =
 148                 (void*) ((unsigned char*) mca_memheap_base_map.mem_segs[HEAP_SEG_INDEX].super.va_base
 149                         + 0);
 150         context.private_base_addr =
 151                 (void*) ((unsigned char*) mca_memheap_base_map.mem_segs[HEAP_SEG_INDEX].super.va_base
 152                         + context.user_size);
 153     }
 154 
 155     return ((OSHMEM_SUCCESS == rc) ? &context : NULL );
 156 }

/* [<][>][^][v][top][bottom][index][help] */