2626
2727#include "sshmem_ucx.h"
2828
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-
3629#define ALLOC_ELEM_SIZE sizeof(uint64_t)
3730#define min (a ,b ) ((a) < (b) ? (a) : (b))
3831#define max (a ,b ) ((a) > (b) ? (a) : (b))
@@ -104,7 +97,7 @@ static segment_allocator_t sshmem_ucx_allocator = {
10497
10598static int
10699segment_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 )
108101{
109102 mca_sshmem_ucx_segment_context_t * ctx ;
110103 int rc = OSHMEM_SUCCESS ;
@@ -120,15 +113,19 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
120113
121114 mem_map_params .field_mask = UCP_MEM_MAP_PARAM_FIELD_ADDRESS |
122115 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 ;
124118
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 ;
128123
129124 status = ucp_mem_map (spml -> ucp_context , & mem_map_params , & mem_h );
130125 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 ));
132129 rc = OSHMEM_ERROR ;
133130 goto out ;
134131 }
@@ -161,12 +158,7 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
161158 ds_buf -> super .va_end = (void * )((uintptr_t )ds_buf -> super .va_base + ds_buf -> seg_size );
162159 ds_buf -> context = ctx ;
163160 ds_buf -> type = MAP_SEGMENT_ALLOC_UCX ;
164- ds_buf -> alloc_hints = hint ;
165161 ctx -> ucp_memh = mem_h ;
166- ctx -> dev_mem = dev_mem ;
167- if (hint ) {
168- ds_buf -> allocator = & sshmem_ucx_allocator ;
169- }
170162
171163out :
172164 OPAL_OUTPUT_VERBOSE (
@@ -181,82 +173,37 @@ segment_create_internal(map_segment_t *ds_buf, void *address, size_t size,
181173 return rc ;
182174}
183175
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-
220176static int
221177segment_create (map_segment_t * ds_buf ,
222178 const char * file_name ,
223179 size_t size , long hint )
224180{
225181 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 ;
227184
228- #if HAVE_UCX_DEVICE_MEM
229- int ret = OSHMEM_ERROR ;
230185 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 ;
233193 }
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" );
250197#endif
198+ return OSHMEM_ERR_NOT_IMPLEMENTED ;
199+ }
251200
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 ;
259204 }
205+ return segment_create_internal (ds_buf , mca_sshmem_base_start_address , size ,
206+ flags , UCS_MEMORY_TYPE_HOST , 0 );
260207}
261208
262209static void *
@@ -303,12 +250,6 @@ segment_unlink(map_segment_t *ds_buf)
303250
304251 ucp_mem_unmap (spml -> ucp_context , ctx -> ucp_memh );
305252
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-
312253 ds_buf -> context = NULL ;
313254 free (ctx );
314255
0 commit comments