@@ -115,6 +115,42 @@ OPAL_DECLSPEC int opal_common_ucx_del_procs_nofence(opal_common_ucx_del_proc_t *
115
115
size_t my_rank , size_t max_disconnect , ucp_worker_h worker );
116
116
OPAL_DECLSPEC void opal_common_ucx_mca_var_register (const mca_base_component_t * component );
117
117
118
+
119
+ /**
120
+ * Load an integer value of \c size bytes from \c ptr and cast it to uint64_t.
121
+ */
122
+ static inline
123
+ uint64_t opal_common_ucx_load_uint64 (void * ptr , size_t size )
124
+ {
125
+ if (sizeof (uint8_t ) == size ) {
126
+ return * (uint8_t * )ptr ;
127
+ } else if (sizeof (uint16_t ) == size ) {
128
+ return * (uint16_t * )ptr ;
129
+ } else if (sizeof (uint32_t ) == size ) {
130
+ return * (uint32_t * )ptr ;
131
+ } else {
132
+ return * (uint64_t * )ptr ;
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Cast and store a uint64_t value to a value of \c size bytes pointed to by \c ptr.
138
+ */
139
+ static inline
140
+ void opal_common_ucx_store_uint64 (uint64_t value , void * ptr , size_t size )
141
+ {
142
+ if (sizeof (uint8_t ) == size ) {
143
+ * (uint8_t * )ptr = value ;
144
+ } else if (sizeof (uint16_t ) == size ) {
145
+ * (uint16_t * )ptr = value ;
146
+ } else if (sizeof (uint32_t ) == size ) {
147
+ * (uint32_t * )ptr = value ;
148
+ } else {
149
+ * (uint64_t * )ptr = value ;
150
+ }
151
+ }
152
+
153
+
118
154
static inline
119
155
ucs_status_t opal_common_ucx_request_status (ucs_status_ptr_t request )
120
156
{
@@ -206,13 +242,7 @@ int opal_common_ucx_atomic_cswap(ucp_ep_h ep, uint64_t compare,
206
242
uint64_t remote_addr , ucp_rkey_h rkey ,
207
243
ucp_worker_h worker )
208
244
{
209
- if (op_size == sizeof (uint64_t )) {
210
- * (uint64_t * )result = value ;
211
- } else {
212
- assert (op_size == sizeof (uint32_t ));
213
- * (uint32_t * )result = value ;
214
- }
215
-
245
+ opal_common_ucx_store_uint64 (value , result , op_size );
216
246
return opal_common_ucx_atomic_fetch (ep , UCP_ATOMIC_FETCH_OP_CSWAP , compare , result ,
217
247
op_size , remote_addr , rkey , worker );
218
248
}
@@ -224,13 +254,7 @@ ucs_status_ptr_t opal_common_ucx_atomic_cswap_nb(ucp_ep_h ep, uint64_t compare,
224
254
ucp_send_callback_t req_handler ,
225
255
ucp_worker_h worker )
226
256
{
227
- if (op_size == sizeof (uint64_t )) {
228
- * (uint64_t * )result = value ;
229
- } else {
230
- assert (op_size == sizeof (uint32_t ));
231
- * (uint32_t * )result = value ;
232
- }
233
-
257
+ opal_common_ucx_store_uint64 (value , result , op_size );
234
258
return opal_common_ucx_atomic_fetch_nb (ep , UCP_ATOMIC_FETCH_OP_CSWAP , compare , result ,
235
259
op_size , remote_addr , rkey , req_handler , worker );
236
260
}
0 commit comments