2525
2626#include "sshmem_ucx.h"
2727
28- //#include <ucs/sys/math.h>
29-
30- #if HAVE_UCX_DEVICE_MEM
31- #include <ucp/core/ucp_resource.h>
32- #include <uct/ib/base/ib_alloc.h>
33- #endif
34-
3528#define ALLOC_ELEM_SIZE sizeof(uint64_t)
3629#define min (a ,b ) ((a) < (b) ? (a) : (b))
3730#define max (a ,b ) ((a) > (b) ? (a) : (b))
@@ -103,7 +96,7 @@ static segment_allocator_t sshmem_ucx_allocator = {
10396
10497static int
10598segment_create_internal (map_segment_t * ds_buf , void * address , size_t size ,
106- unsigned flags , long hint , void * dev_mem )
99+ unsigned flags , ucs_memory_type_t mem_type , int err_level )
107100{
108101 mca_sshmem_ucx_segment_context_t * ctx ;
109102 int rc = OSHMEM_SUCCESS ;
@@ -119,15 +112,19 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
119112
120113 mem_map_params .field_mask = UCP_MEM_MAP_PARAM_FIELD_ADDRESS |
121114 UCP_MEM_MAP_PARAM_FIELD_LENGTH |
122- UCP_MEM_MAP_PARAM_FIELD_FLAGS ;
115+ UCP_MEM_MAP_PARAM_FIELD_FLAGS |
116+ UCP_MEM_MAP_PARAM_FIELD_MEMORY_TYPE ;
123117
124- mem_map_params .address = address ;
125- mem_map_params .length = size ;
126- mem_map_params .flags = flags ;
118+ mem_map_params .address = address ;
119+ mem_map_params .length = size ;
120+ mem_map_params .flags = flags ;
121+ mem_map_params .memory_type = mem_type ;
127122
128123 status = ucp_mem_map (spml -> ucp_context , & mem_map_params , & mem_h );
129124 if (UCS_OK != status ) {
130- SSHMEM_ERROR ("ucp_mem_map() failed: %s\n" , ucs_status_string (status ));
125+ SSHMEM_VERBOSE (err_level , "ucp_mem_map(memory_type=%s) failed: %s\n" ,
126+ ucs_memory_type_names [mem_type ],
127+ ucs_status_string (status ));
131128 rc = OSHMEM_ERROR ;
132129 goto out ;
133130 }
@@ -160,12 +157,7 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
160157 ds_buf -> super .va_end = (void * )((uintptr_t )ds_buf -> super .va_base + ds_buf -> seg_size );
161158 ds_buf -> context = ctx ;
162159 ds_buf -> type = MAP_SEGMENT_ALLOC_UCX ;
163- ds_buf -> alloc_hints = hint ;
164160 ctx -> ucp_memh = mem_h ;
165- ctx -> dev_mem = dev_mem ;
166- if (hint ) {
167- ds_buf -> allocator = & sshmem_ucx_allocator ;
168- }
169161
170162out :
171163 OPAL_OUTPUT_VERBOSE (
@@ -180,81 +172,37 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
180172 return rc ;
181173}
182174
183- #if HAVE_UCX_DEVICE_MEM
184- static uct_ib_device_mem_h alloc_device_mem (mca_spml_ucx_t * spml , size_t size ,
185- void * * address_p )
186- {
187- uct_ib_device_mem_h dev_mem = NULL ;
188- ucs_status_t status ;
189- uct_md_h uct_md ;
190- void * address ;
191- size_t length ;
192-
193- uct_md = ucp_context_find_tl_md (spml -> ucp_context , "mlx5" );
194- if (uct_md == NULL ) {
195- SSHMEM_VERBOSE (1 , "ucp_context_find_tl_md() returned NULL\n" );
196- return NULL ;
197- }
198-
199- /* If found a matching memory domain, allocate device memory on it */
200- length = size ;
201- address = NULL ;
202- status = uct_ib_md_alloc_device_mem (uct_md , & length , & address ,
203- UCT_MD_MEM_ACCESS_ALL , "sshmem_seg" ,
204- & dev_mem );
205- if (status != UCS_OK ) {
206- /* If could not allocate device memory - fallback to mmap (since some
207- * PEs in the job may succeed and while others failed */
208- SSHMEM_VERBOSE (1 , "uct_ib_md_alloc_dm() failed: %s\n" ,
209- ucs_status_string (status ));
210- return NULL ;
211- }
212-
213- SSHMEM_VERBOSE (3 , "uct_ib_md_alloc_dm() returned address %p\n" , address );
214- * address_p = address ;
215- return dev_mem ;
216- }
217- #endif
218-
219175static int
220176segment_create (map_segment_t * ds_buf ,
221177 const char * file_name ,
222178 size_t size , long hint )
223179{
224180 mca_spml_ucx_t * spml = (mca_spml_ucx_t * )mca_spml .self ;
225- unsigned flags ;
181+ unsigned flags = UCP_MEM_MAP_ALLOCATE ;
182+ int status ;
226183
227- #if HAVE_UCX_DEVICE_MEM
228- int ret = OSHMEM_ERROR ;
229184 if (hint & SHMEM_HINT_DEVICE_NIC_MEM ) {
230- if (size > UINT_MAX ) {
231- return OSHMEM_ERR_BAD_PARAM ;
185+ #if HAVE_DECL_UCS_MEMORY_TYPE_RDMA
186+ status = segment_create_internal (ds_buf , NULL , size , flags ,
187+ UCS_MEMORY_TYPE_RDMA , 3 );
188+ if (status == OSHMEM_SUCCESS ) {
189+ ds_buf -> alloc_hints = hint ;
190+ ds_buf -> allocator = & sshmem_ucx_allocator ;
191+ return OSHMEM_SUCCESS ;
232192 }
233-
234- void * dev_mem_address ;
235- uct_ib_device_mem_h dev_mem = alloc_device_mem (spml , size ,
236- & dev_mem_address );
237- if (dev_mem != NULL ) {
238- ret = segment_create_internal (ds_buf , dev_mem_address , size , 0 ,
239- hint , dev_mem );
240- if (ret == OSHMEM_SUCCESS ) {
241- return OSHMEM_SUCCESS ;
242- } else if (dev_mem != NULL ) {
243- uct_ib_md_release_device_mem (dev_mem );
244- /* fallback to regular allocation */
245- }
246- }
247- }
193+ #else
194+ SSHMEM_VERBOSE (3 , "DEVICE_NIC_MEM hint ignored since UCX does not "
195+ "support MEMORY_TYPE_RDMA" );
248196#endif
197+ return OSHMEM_ERR_NOT_IMPLEMENTED ;
198+ }
249199
250- flags = UCP_MEM_MAP_ALLOCATE | (spml -> heap_reg_nb ? UCP_MEM_MAP_NONBLOCK : 0 );
251- if (hint ) {
252- return segment_create_internal (ds_buf , NULL , size , flags , hint , NULL );
253- } else {
254- return segment_create_internal (ds_buf , mca_sshmem_base_start_address ,
255- size , flags | UCP_MEM_MAP_FIXED , hint ,
256- NULL );
200+ flags |= UCP_MEM_MAP_FIXED ;
201+ if (spml -> heap_reg_nb ) {
202+ flags |= UCP_MEM_MAP_NONBLOCK ;
257203 }
204+ return segment_create_internal (ds_buf , mca_sshmem_base_start_address , size ,
205+ flags , UCS_MEMORY_TYPE_HOST , 0 );
258206}
259207
260208static void *
@@ -301,12 +249,6 @@ segment_unlink(map_segment_t *ds_buf)
301249
302250 ucp_mem_unmap (spml -> ucp_context , ctx -> ucp_memh );
303251
304- #if HAVE_UCX_DEVICE_MEM
305- if (ctx -> dev_mem ) {
306- uct_ib_md_release_device_mem (ctx -> dev_mem );
307- }
308- #endif
309-
310252 ds_buf -> context = NULL ;
311253 free (ctx );
312254
0 commit comments