@@ -822,13 +822,36 @@ static int init_one_port(opal_list_t *btl_list, mca_btl_openib_device_t *device,
822822            openib_btl -> super .btl_get_local_registration_threshold  =  0 ;
823823
824824#if  HAVE_DECL_IBV_ATOMIC_HCA 
825-             if  (openib_btl -> device -> ib_dev_attr .atomic_cap  ==  IBV_ATOMIC_NONE ) {
825+             openib_btl -> atomic_ops_be  =  false;
826+ 
827+ #if  HAVE_DECL_IBV_EXP_QUERY_DEVICE 
828+             /* check that 8-byte atomics are supported */ 
829+             if  (!(device -> ib_exp_dev_attr .ext_atom .log_atomic_arg_sizes  &  (1 <<3ull ))) {
826830                openib_btl -> super .btl_flags  &= ~MCA_BTL_FLAGS_ATOMIC_FOPS ;
827831                openib_btl -> super .btl_atomic_flags  =  0 ;
828832                openib_btl -> super .btl_atomic_fop  =  NULL ;
829833                openib_btl -> super .btl_atomic_cswap  =  NULL ;
830-             } else  if  (IBV_ATOMIC_GLOB  ==  openib_btl -> device -> ib_dev_attr .atomic_cap ) {
834+             }
835+ #endif 
836+ 
837+             switch  (openib_btl -> device -> ib_dev_attr .atomic_cap ) {
838+             case  IBV_ATOMIC_GLOB :
831839                openib_btl -> super .btl_flags  |= MCA_BTL_ATOMIC_SUPPORTS_GLOB ;
840+                 break ;
841+ #if  HAVE_DECL_IBV_EXP_ATOMIC_HCA_REPLY_BE 
842+             case  IBV_EXP_ATOMIC_HCA_REPLY_BE :
843+                 openib_btl -> atomic_ops_be  =  true;
844+                 break ;
845+ #endif 
846+             case  IBV_ATOMIC_HCA :
847+                 break ;
848+             case  IBV_ATOMIC_NONE :
849+             default :
850+                 /* no atomics or an unsupported atomic type */ 
851+                 openib_btl -> super .btl_flags  &= ~MCA_BTL_FLAGS_ATOMIC_FOPS ;
852+                 openib_btl -> super .btl_atomic_flags  =  0 ;
853+                 openib_btl -> super .btl_atomic_fop  =  NULL ;
854+                 openib_btl -> super .btl_atomic_cswap  =  NULL ;
832855            }
833856#endif 
834857
@@ -1626,7 +1649,13 @@ static int init_one_device(opal_list_t *btl_list, struct ibv_device* ib_dev)
16261649                    ibv_get_device_name (device -> ib_dev ), strerror (errno )));
16271650        goto error ;
16281651    }
1629- 
1652+ #if  HAVE_DECL_IBV_EXP_QUERY_DEVICE 
1653+     if (ibv_exp_query_device (device -> ib_dev_context , & device -> ib_exp_dev_attr )){
1654+         BTL_ERROR (("error obtaining device attributes for %s errno says %s" ,
1655+                     ibv_get_device_name (device -> ib_dev ), strerror (errno )));
1656+         goto error ;
1657+     }
1658+ #endif 
16301659    if (ibv_query_device (device -> ib_dev_context , & device -> ib_dev_attr )){
16311660        BTL_ERROR (("error obtaining device attributes for %s errno says %s" ,
16321661                    ibv_get_device_name (device -> ib_dev ), strerror (errno )));
@@ -3442,6 +3471,11 @@ static void handle_wc(mca_btl_openib_device_t* device, const uint32_t cq,
34423471
34433472            mca_btl_openib_get_frag_t  * get_frag  =  to_get_frag (des );
34443473
3474+             /* check if atomic result needs to be byte swapped (mlx5) */ 
3475+             if  (openib_btl -> atomic_ops_be  &&  IBV_WC_RDMA_READ  !=  wc -> opcode ) {
3476+                 * ((int64_t  * ) frag -> sg_entry .addr ) =  ntoh64  (* ((int64_t  * ) frag -> sg_entry .addr ));
3477+             }
3478+ 
34453479            get_frag -> cb .func  (& openib_btl -> super , endpoint , (void  * )(intptr_t ) frag -> sg_entry .addr ,
34463480                               get_frag -> cb .local_handle , get_frag -> cb .context , get_frag -> cb .data ,
34473481                               OPAL_SUCCESS );
0 commit comments