11/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ 
22/* 
3-  * Copyright (c) 2014       Los Alamos National Security, LLC. All rights 
3+  * Copyright (c) 2014-2016  Los Alamos National Security, LLC. All rights 
44 *                         reserved. 
55 * $COPYRIGHT$ 
66 * 
1111
1212#include  "btl_ugni_rdma.h" 
1313
14- static  gni_fma_cmd_type_t  famo_cmds [] =  {
15-     [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC_FADD ,
16-     [MCA_BTL_ATOMIC_AND ] =  GNI_FMA_ATOMIC_FAND ,
17-     [MCA_BTL_ATOMIC_OR ] =  GNI_FMA_ATOMIC_FOR ,
18-     [MCA_BTL_ATOMIC_XOR ] =  GNI_FMA_ATOMIC_FXOR ,
14+ static  gni_fma_cmd_type_t  amo_cmds [][MCA_BTL_ATOMIC_LAST ] =  {
15+     [OPAL_INT32 ] =  {
16+         [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC2_IADD_S ,
17+         [MCA_BTL_ATOMIC_LAND ] =  GNI_FMA_ATOMIC2_AND_S ,
18+         [MCA_BTL_ATOMIC_LOR ] =  GNI_FMA_ATOMIC2_OR_S ,
19+         [MCA_BTL_ATOMIC_LXOR ] =  GNI_FMA_ATOMIC2_XOR_S ,
20+         [MCA_BTL_ATOMIC_SWAP ] =  GNI_FMA_ATOMIC2_SWAP_S ,
21+         [MCA_BTL_ATOMIC_MIN ] =  GNI_FMA_ATOMIC2_IMIN_S ,
22+         [MCA_BTL_ATOMIC_MAX ] =  GNI_FMA_ATOMIC2_IMAX_S ,
23+     },
24+     [OPAL_INT64 ] =  {
25+         [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC_ADD ,
26+         [MCA_BTL_ATOMIC_AND ] =  GNI_FMA_ATOMIC_AND ,
27+         [MCA_BTL_ATOMIC_OR ] =  GNI_FMA_ATOMIC_OR ,
28+         [MCA_BTL_ATOMIC_XOR ] =  GNI_FMA_ATOMIC_XOR ,
29+         [MCA_BTL_ATOMIC_SWAP ] =  GNI_FMA_ATOMIC2_SWAP ,
30+         [MCA_BTL_ATOMIC_MIN ] =  GNI_FMA_ATOMIC2_IMIN ,
31+         [MCA_BTL_ATOMIC_MAX ] =  GNI_FMA_ATOMIC2_IMAX ,
32+     },
33+     [OPAL_FLOAT ] =  {
34+         [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC2_FPADD_S ,
35+         [MCA_BTL_ATOMIC_MIN ] =  GNI_FMA_ATOMIC2_FPMIN_S ,
36+         [MCA_BTL_ATOMIC_MAX ] =  GNI_FMA_ATOMIC2_FPMAX_S ,
37+     },
38+     [OPAL_DOUBLE ] =  {
39+         [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC2_FPADD ,
40+         [MCA_BTL_ATOMIC_MIN ] =  GNI_FMA_ATOMIC2_FPMIN ,
41+         [MCA_BTL_ATOMIC_MAX ] =  GNI_FMA_ATOMIC2_FPMAX ,
42+     },
1943};
2044
21- static  gni_fma_cmd_type_t  amo_cmds [] =  {
22-     [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC_ADD ,
23-     [MCA_BTL_ATOMIC_AND ] =  GNI_FMA_ATOMIC_AND ,
24-     [MCA_BTL_ATOMIC_OR ] =  GNI_FMA_ATOMIC_OR ,
25-     [MCA_BTL_ATOMIC_XOR ] =  GNI_FMA_ATOMIC_XOR ,
45+ static  gni_fma_cmd_type_t  famo_cmds [][MCA_BTL_ATOMIC_LAST ] =  {
46+     [OPAL_INT32 ] =  {
47+         [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC2_FIADD_S ,
48+         [MCA_BTL_ATOMIC_LAND ] =  GNI_FMA_ATOMIC2_FAND_S ,
49+         [MCA_BTL_ATOMIC_LOR ] =  GNI_FMA_ATOMIC2_FOR_S ,
50+         [MCA_BTL_ATOMIC_LXOR ] =  GNI_FMA_ATOMIC2_FXOR_S ,
51+         [MCA_BTL_ATOMIC_SWAP ] =  GNI_FMA_ATOMIC2_FSWAP_S ,
52+         [MCA_BTL_ATOMIC_MIN ] =  GNI_FMA_ATOMIC2_FIMIN_S ,
53+         [MCA_BTL_ATOMIC_MAX ] =  GNI_FMA_ATOMIC2_FIMAX_S ,
54+     },
55+     [OPAL_INT64 ] =  {
56+         [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC_FADD ,
57+         [MCA_BTL_ATOMIC_AND ] =  GNI_FMA_ATOMIC_FAND ,
58+         [MCA_BTL_ATOMIC_OR ] =  GNI_FMA_ATOMIC_FOR ,
59+         [MCA_BTL_ATOMIC_XOR ] =  GNI_FMA_ATOMIC_FXOR ,
60+         [MCA_BTL_ATOMIC_SWAP ] =  GNI_FMA_ATOMIC2_FSWAP ,
61+         [MCA_BTL_ATOMIC_MIN ] =  GNI_FMA_ATOMIC2_FIMIN ,
62+         [MCA_BTL_ATOMIC_MAX ] =  GNI_FMA_ATOMIC2_FIMAX ,
63+     },
64+     [OPAL_FLOAT ] =  {
65+         [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC2_FFPADD_S ,
66+         [MCA_BTL_ATOMIC_MIN ] =  GNI_FMA_ATOMIC2_FFPMIN_S ,
67+         [MCA_BTL_ATOMIC_MAX ] =  GNI_FMA_ATOMIC2_FFPMAX_S ,
68+     },
69+     [OPAL_DOUBLE ] =  {
70+         [MCA_BTL_ATOMIC_ADD ] =  GNI_FMA_ATOMIC2_FFPADD ,
71+         [MCA_BTL_ATOMIC_MIN ] =  GNI_FMA_ATOMIC2_FFPMIN ,
72+         [MCA_BTL_ATOMIC_MAX ] =  GNI_FMA_ATOMIC2_FFPMAX ,
73+     },
2674};
2775
2876int  mca_btl_ugni_aop  (struct  mca_btl_base_module_t  * btl , struct  mca_btl_base_endpoint_t  * endpoint ,
@@ -32,7 +80,20 @@ int mca_btl_ugni_aop (struct mca_btl_base_module_t *btl, struct mca_btl_base_end
3280{
3381    gni_mem_handle_t  dummy  =  {0 , 0 };
3482    mca_btl_ugni_post_descriptor_t  * post_desc ;
35-     int  rc ;
83+     int  gni_op , rc , type ;
84+     size_t  size ;
85+ 
86+     size  =  (MCA_BTL_ATOMIC_FLAG_32BIT  &  flags ) ? 4  : 8 ;
87+     if  (MCA_BTL_ATOMIC_FLAG_FLOAT  &  flags ) {
88+         type  =  (MCA_BTL_ATOMIC_FLAG_32BIT  &  flags ) ? OPAL_FLOAT  : OPAL_DOUBLE ;
89+     } else  {
90+         type  =  (MCA_BTL_ATOMIC_FLAG_32BIT  &  flags ) ? OPAL_INT32  : OPAL_INT64 ;
91+     }
92+ 
93+     gni_op  =  amo_cmds [type ][op ];
94+     if  (0  ==  gni_op ) {
95+         return  OPAL_ERR_NOT_SUPPORTED ;
96+     }
3697
3798    rc  =  mca_btl_ugni_check_endpoint_state_rdma  (endpoint );
3899    if  (OPAL_UNLIKELY (OPAL_SUCCESS  !=  rc )) {
@@ -45,15 +106,19 @@ int mca_btl_ugni_aop (struct mca_btl_base_module_t *btl, struct mca_btl_base_end
45106    }
46107
47108    init_gni_post_desc  (& post_desc -> desc , order , GNI_POST_AMO , 0 , dummy , remote_address ,
48-                         remote_handle -> gni_handle , 8 , 0 );
49-     post_desc -> desc .base .amo_cmd  =  amo_cmds [ op ] ;
109+                         remote_handle -> gni_handle , size , 0 );
110+     post_desc -> desc .base .amo_cmd  =  gni_op ;
50111
51112    post_desc -> desc .base .first_operand  =  operand ;
52113
53114    OPAL_THREAD_LOCK (& endpoint -> btl -> device -> dev_lock );
54115    rc  =  GNI_PostFma  (endpoint -> rdma_ep_handle , & post_desc -> desc .base );
55116    OPAL_THREAD_UNLOCK (& endpoint -> btl -> device -> dev_lock );
56117    if  (GNI_RC_SUCCESS  !=  rc ) {
118+         mca_btl_ugni_return_post_descriptor  (endpoint -> btl , post_desc );
119+         if  (GNI_RC_ILLEGAL_OP  ==  rc ) {
120+             return  OPAL_ERR_NOT_SUPPORTED ;
121+         }
57122        return  OPAL_ERR_OUT_OF_RESOURCE ;
58123    }
59124
@@ -67,7 +132,20 @@ int mca_btl_ugni_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_en
67132                       void  * cbcontext , void  * cbdata )
68133{
69134    mca_btl_ugni_post_descriptor_t  * post_desc ;
70-     int  rc ;
135+     int  gni_op , rc , type ;
136+     size_t  size ;
137+ 
138+     size  =  (MCA_BTL_ATOMIC_FLAG_32BIT  &  flags ) ? 4  : 8 ;
139+     if  (MCA_BTL_ATOMIC_FLAG_FLOAT  &  flags ) {
140+         type  =  (MCA_BTL_ATOMIC_FLAG_32BIT  &  flags ) ? OPAL_FLOAT  : OPAL_DOUBLE ;
141+     } else  {
142+         type  =  (MCA_BTL_ATOMIC_FLAG_32BIT  &  flags ) ? OPAL_INT32  : OPAL_INT64 ;
143+     }
144+ 
145+     gni_op  =  famo_cmds [type ][op ];
146+     if  (0  ==  gni_op ) {
147+         return  OPAL_ERR_NOT_SUPPORTED ;
148+     }
71149
72150    rc  =  mca_btl_ugni_check_endpoint_state_rdma  (endpoint );
73151    if  (OPAL_UNLIKELY (OPAL_SUCCESS  !=  rc )) {
@@ -81,8 +159,8 @@ int mca_btl_ugni_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_en
81159
82160
83161    init_gni_post_desc  (& post_desc -> desc , order , GNI_POST_AMO , (intptr_t ) local_address , local_handle -> gni_handle ,
84-                         remote_address , remote_handle -> gni_handle , 8 , 0 );
85-     post_desc -> desc .base .amo_cmd  =  famo_cmds [ op ] ;
162+                         remote_address , remote_handle -> gni_handle , size , 0 );
163+     post_desc -> desc .base .amo_cmd  =  gni_op ;
86164
87165    post_desc -> desc .base .first_operand  =  operand ;
88166
@@ -91,6 +169,9 @@ int mca_btl_ugni_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_en
91169    OPAL_THREAD_UNLOCK (& endpoint -> btl -> device -> dev_lock );
92170    if  (GNI_RC_SUCCESS  !=  rc ) {
93171        mca_btl_ugni_return_post_descriptor  (endpoint -> btl , post_desc );
172+         if  (GNI_RC_ILLEGAL_OP  ==  rc ) {
173+             return  OPAL_ERR_NOT_SUPPORTED ;
174+         }
94175        return  OPAL_ERR_OUT_OF_RESOURCE ;
95176    }
96177
@@ -103,7 +184,11 @@ int mca_btl_ugni_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_
103184                         int  order , mca_btl_base_rdma_completion_fn_t  cbfunc , void  * cbcontext , void  * cbdata )
104185{
105186    mca_btl_ugni_post_descriptor_t  * post_desc ;
106-     int  rc ;
187+     int  gni_op , rc ;
188+     size_t  size ;
189+ 
190+     gni_op  =  (MCA_BTL_ATOMIC_FLAG_32BIT  &  flags ) ? GNI_FMA_ATOMIC2_CSWAP_S  : GNI_FMA_ATOMIC_CSWAP ;
191+     size  =  (MCA_BTL_ATOMIC_FLAG_32BIT  &  flags ) ? 4  : 8 ;
107192
108193    rc  =  mca_btl_ugni_check_endpoint_state_rdma  (endpoint );
109194    if  (OPAL_UNLIKELY (OPAL_SUCCESS  !=  rc )) {
@@ -117,8 +202,8 @@ int mca_btl_ugni_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_
117202
118203
119204    init_gni_post_desc  (& post_desc -> desc , order , GNI_POST_AMO , (intptr_t ) local_address , local_handle -> gni_handle ,
120-                         remote_address , remote_handle -> gni_handle , 8 , 0 );
121-     post_desc -> desc .base .amo_cmd  =  GNI_FMA_ATOMIC_CSWAP ;
205+                         remote_address , remote_handle -> gni_handle , size , 0 );
206+     post_desc -> desc .base .amo_cmd  =  gni_op ;
122207
123208    post_desc -> desc .base .first_operand  =  compare ;
124209    post_desc -> desc .base .second_operand  =  value ;
0 commit comments