This source file includes following definitions.
- mca_memheap_base_select
- _memheap_size
- _memheap_create
1
2
3
4
5
6
7
8
9
10
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
36
37
38
39
40
41
42
43
44 static memheap_context_t* _memheap_create(void);
45
46
47
48
49
50
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
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
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
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
125 rc = OSHMEM_SUCCESS;
126 }
127 }
128
129
130 if (OSHMEM_SUCCESS == rc) {
131 rc = mca_memheap_base_static_init(&mca_memheap_base_map);
132 }
133
134
135 if (OSHMEM_SUCCESS == rc) {
136 rc = mca_memheap_base_reg(&mca_memheap_base_map);
137 }
138
139
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 }