26
26
27
27
#include "sshmem_ucx.h"
28
28
29
- //#include <ucs/sys/math.h>
30
-
31
- #if HAVE_UCX_DEVICE_MEM
32
- #include <ucp/core/ucp_resource.h>
33
- #include <uct/ib/base/ib_alloc.h>
34
- #endif
35
-
36
29
#define ALLOC_ELEM_SIZE sizeof(uint64_t)
37
30
#define min (a ,b ) ((a) < (b) ? (a) : (b))
38
31
#define max (a ,b ) ((a) > (b) ? (a) : (b))
@@ -104,7 +97,7 @@ static segment_allocator_t sshmem_ucx_allocator = {
104
97
105
98
static int
106
99
segment_create_internal (map_segment_t * ds_buf , void * address , size_t size ,
107
- unsigned flags , long hint , void * dev_mem )
100
+ unsigned flags , ucs_memory_type_t mem_type , int err_level )
108
101
{
109
102
mca_sshmem_ucx_segment_context_t * ctx ;
110
103
int rc = OSHMEM_SUCCESS ;
@@ -120,15 +113,19 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
120
113
121
114
mem_map_params .field_mask = UCP_MEM_MAP_PARAM_FIELD_ADDRESS |
122
115
UCP_MEM_MAP_PARAM_FIELD_LENGTH |
123
- UCP_MEM_MAP_PARAM_FIELD_FLAGS ;
116
+ UCP_MEM_MAP_PARAM_FIELD_FLAGS |
117
+ UCP_MEM_MAP_PARAM_FIELD_MEMORY_TYPE ;
124
118
125
- mem_map_params .address = address ;
126
- mem_map_params .length = size ;
127
- mem_map_params .flags = flags ;
119
+ mem_map_params .address = address ;
120
+ mem_map_params .length = size ;
121
+ mem_map_params .flags = flags ;
122
+ mem_map_params .memory_type = mem_type ;
128
123
129
124
status = ucp_mem_map (spml -> ucp_context , & mem_map_params , & mem_h );
130
125
if (UCS_OK != status ) {
131
- SSHMEM_ERROR ("ucp_mem_map() failed: %s\n" , ucs_status_string (status ));
126
+ SSHMEM_VERBOSE (err_level , "ucp_mem_map(memory_type=%s) failed: %s\n" ,
127
+ ucs_memory_type_names [mem_type ],
128
+ ucs_status_string (status ));
132
129
rc = OSHMEM_ERROR ;
133
130
goto out ;
134
131
}
@@ -161,12 +158,7 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
161
158
ds_buf -> super .va_end = (void * )((uintptr_t )ds_buf -> super .va_base + ds_buf -> seg_size );
162
159
ds_buf -> context = ctx ;
163
160
ds_buf -> type = MAP_SEGMENT_ALLOC_UCX ;
164
- ds_buf -> alloc_hints = hint ;
165
161
ctx -> ucp_memh = mem_h ;
166
- ctx -> dev_mem = dev_mem ;
167
- if (hint ) {
168
- ds_buf -> allocator = & sshmem_ucx_allocator ;
169
- }
170
162
171
163
out :
172
164
OPAL_OUTPUT_VERBOSE (
@@ -181,82 +173,37 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
181
173
return rc ;
182
174
}
183
175
184
- #if HAVE_UCX_DEVICE_MEM
185
- static uct_ib_device_mem_h alloc_device_mem (mca_spml_ucx_t * spml , size_t size ,
186
- void * * address_p )
187
- {
188
- uct_ib_device_mem_h dev_mem = NULL ;
189
- ucs_status_t status ;
190
- uct_md_h uct_md ;
191
- void * address ;
192
- size_t length ;
193
-
194
- uct_md = ucp_context_find_tl_md (spml -> ucp_context , "mlx5" );
195
- if (uct_md == NULL ) {
196
- SSHMEM_VERBOSE (1 , "ucp_context_find_tl_md() returned NULL\n" );
197
- return NULL ;
198
- }
199
-
200
- /* If found a matching memory domain, allocate device memory on it */
201
- length = size ;
202
- address = NULL ;
203
- status = uct_ib_md_alloc_device_mem (uct_md , & length , & address ,
204
- UCT_MD_MEM_ACCESS_ALL , "sshmem_seg" ,
205
- & dev_mem );
206
- if (status != UCS_OK ) {
207
- /* If could not allocate device memory - fallback to mmap (since some
208
- * PEs in the job may succeed and while others failed */
209
- SSHMEM_VERBOSE (1 , "uct_ib_md_alloc_dm() failed: %s\n" ,
210
- ucs_status_string (status ));
211
- return NULL ;
212
- }
213
-
214
- SSHMEM_VERBOSE (3 , "uct_ib_md_alloc_dm() returned address %p\n" , address );
215
- * address_p = address ;
216
- return dev_mem ;
217
- }
218
- #endif
219
-
220
176
static int
221
177
segment_create (map_segment_t * ds_buf ,
222
178
const char * file_name ,
223
179
size_t size , long hint )
224
180
{
225
181
mca_spml_ucx_t * spml = (mca_spml_ucx_t * )mca_spml .self ;
226
- unsigned flags ;
182
+ unsigned flags = UCP_MEM_MAP_ALLOCATE ;
183
+ int status ;
227
184
228
- #if HAVE_UCX_DEVICE_MEM
229
- int ret = OSHMEM_ERROR ;
230
185
if (hint & SHMEM_HINT_DEVICE_NIC_MEM ) {
231
- if (size > UINT_MAX ) {
232
- return OSHMEM_ERR_BAD_PARAM ;
186
+ #if HAVE_DECL_UCS_MEMORY_TYPE_RDMA
187
+ status = segment_create_internal (ds_buf , NULL , size , flags ,
188
+ UCS_MEMORY_TYPE_RDMA , 3 );
189
+ if (status == OSHMEM_SUCCESS ) {
190
+ ds_buf -> alloc_hints = hint ;
191
+ ds_buf -> allocator = & sshmem_ucx_allocator ;
192
+ return OSHMEM_SUCCESS ;
233
193
}
234
-
235
- void * dev_mem_address ;
236
- uct_ib_device_mem_h dev_mem = alloc_device_mem (spml , size ,
237
- & dev_mem_address );
238
- if (dev_mem != NULL ) {
239
- int ret ;
240
- ret = segment_create_internal (ds_buf , dev_mem_address , size , 0 ,
241
- hint , dev_mem );
242
- if (ret == OSHMEM_SUCCESS ) {
243
- return OSHMEM_SUCCESS ;
244
- } else if (dev_mem != NULL ) {
245
- uct_ib_md_release_device_mem (dev_mem );
246
- /* fallback to regular allocation */
247
- }
248
- }
249
- }
194
+ #else
195
+ SSHMEM_VERBOSE (3 , "DEVICE_NIC_MEM hint ignored since UCX does not "
196
+ "support MEMORY_TYPE_RDMA" );
250
197
#endif
198
+ return OSHMEM_ERR_NOT_IMPLEMENTED ;
199
+ }
251
200
252
- flags = UCP_MEM_MAP_ALLOCATE | (spml -> heap_reg_nb ? UCP_MEM_MAP_NONBLOCK : 0 );
253
- if (hint ) {
254
- return segment_create_internal (ds_buf , NULL , size , flags , hint , NULL );
255
- } else {
256
- return segment_create_internal (ds_buf , mca_sshmem_base_start_address ,
257
- size , flags | UCP_MEM_MAP_FIXED , hint ,
258
- NULL );
201
+ flags |= UCP_MEM_MAP_FIXED ;
202
+ if (spml -> heap_reg_nb ) {
203
+ flags |= UCP_MEM_MAP_NONBLOCK ;
259
204
}
205
+ return segment_create_internal (ds_buf , mca_sshmem_base_start_address , size ,
206
+ flags , UCS_MEMORY_TYPE_HOST , 0 );
260
207
}
261
208
262
209
static void *
@@ -303,12 +250,6 @@ segment_unlink(map_segment_t *ds_buf)
303
250
304
251
ucp_mem_unmap (spml -> ucp_context , ctx -> ucp_memh );
305
252
306
- #if HAVE_UCX_DEVICE_MEM
307
- if (ctx -> dev_mem ) {
308
- uct_ib_md_release_device_mem (ctx -> dev_mem );
309
- }
310
- #endif
311
-
312
253
ds_buf -> context = NULL ;
313
254
free (ctx );
314
255
0 commit comments