Skip to content

Commit c9b8580

Browse files
committed
Move is_atomic_size_supported() to base.
It's a common function between rdma and ucx, put it somewhere both can access it. Signed-off-by: Austen Lauria <[email protected]>
1 parent ea42ae7 commit c9b8580

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

ompi/mca/osc/base/base.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* University of Stuttgart. All rights reserved.
88
* Copyright (c) 2004-2005 The Regents of the University of California.
99
* All rights reserved.
10-
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
10+
* Copyright (c) 2016-2021 IBM Corporation. All rights reserved.
1111
* $COPYRIGHT$
1212
*
1313
* Additional copyrights may follow
@@ -50,6 +50,17 @@ int ompi_osc_base_finalize(void);
5050

5151
OMPI_DECLSPEC extern mca_base_framework_t ompi_osc_base_framework;
5252

53+
54+
/* Helper to check whether osc can support atomic operation on the size the operands
55+
* Currently used with rdma and ucx.
56+
*/
57+
static inline __opal_attribute_always_inline__ bool ompi_osc_base_is_atomic_size_supported(uint64_t remote_addr,
58+
size_t size)
59+
{
60+
return ((sizeof(uint32_t) == size && !(remote_addr & 0x3)) ||
61+
(sizeof(uint64_t) == size && !(remote_addr & 0x7)));
62+
}
63+
5364
END_C_DECLS
5465

5566
#endif

ompi/mca/osc/rdma/osc_rdma_accumulate.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "osc_rdma_request.h"
2121
#include "osc_rdma_comm.h"
2222

23+
#include "ompi/mca/osc/base/base.h"
2324
#include "ompi/mca/osc/base/osc_base_obj_convert.h"
2425

2526
static inline void ompi_osc_rdma_peer_accumulate_cleanup (ompi_osc_rdma_module_t *module, ompi_osc_rdma_peer_t *peer, bool lock_acquired)
@@ -331,13 +332,6 @@ static inline int ompi_osc_rdma_gacc_amo (ompi_osc_rdma_module_t *module, ompi_o
331332
return OMPI_SUCCESS;
332333
}
333334

334-
static inline __opal_attribute_always_inline__ bool ompi_osc_rdma_is_atomic_size_supported(uint64_t remote_addr,
335-
size_t size)
336-
{
337-
return ((sizeof(uint32_t) == size && !(remote_addr & 0x3)) ||
338-
(sizeof(uint64_t) == size && !(remote_addr & 0x7)));
339-
}
340-
341335
static inline int ompi_osc_rdma_gacc_contig (ompi_osc_rdma_sync_t *sync, const void *source, int source_count,
342336
ompi_datatype_t *source_datatype, void *result, int result_count,
343337
ompi_datatype_t *result_datatype, opal_convertor_t *result_convertor,
@@ -360,7 +354,7 @@ static inline int ompi_osc_rdma_gacc_contig (ompi_osc_rdma_sync_t *sync, const v
360354
* the atomic operation. this should be safe in all cases as either 1) the user has assured us they will
361355
* never use atomics with count > 1, 2) we have the accumulate lock, or 3) we have an exclusive lock */
362356
if ((target_dtype_size <= 8) && (((unsigned long) target_count) <= module->network_amo_max_count) &&
363-
ompi_osc_rdma_is_atomic_size_supported(target_address, target_dtype_size)) {
357+
ompi_osc_base_is_atomic_size_supported(target_address, target_dtype_size)) {
364358
ret = ompi_osc_rdma_gacc_amo (module, sync, source, result, result_count, result_datatype, result_convertor,
365359
peer, target_address, target_handle, target_count, target_datatype, op, request);
366360
if (OPAL_LIKELY(OMPI_SUCCESS == ret)) {

ompi/mca/osc/ucx/osc_ucx_comm.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (C) 2001-2017 Mellanox Technologies Ltd. ALL RIGHTS RESERVED.
33
* Copyright (c) 2019-2020 High Performance Computing Center Stuttgart,
44
* University of Stuttgart. All rights reserved.
5+
* Copyright (c) 2021 IBM Corporation. All rights reserved.
56
* $COPYRIGHT$
67
*
78
* Additional copyrights may follow
@@ -26,14 +27,6 @@
2627
return OMPI_ERROR; \
2728
}
2829

29-
/* helper to check whether UCX supports atomic operation on the size the operands */
30-
static inline __opal_attribute_always_inline__ bool is_atomic_size_supported(uint64_t remote_addr,
31-
size_t size)
32-
{
33-
return ((sizeof(uint32_t) == size && !(remote_addr & 0x3)) ||
34-
(sizeof(uint64_t) == size && !(remote_addr & 0x7)));
35-
}
36-
3730
typedef struct ucx_iovec {
3831
void *addr;
3932
size_t len;
@@ -403,7 +396,7 @@ bool use_atomic_op(
403396
ompi_datatype_type_size(origin_dt, &origin_dt_bytes);
404397
ompi_datatype_type_size(target_dt, &target_dt_bytes);
405398
/* UCX only supports 32 and 64-bit operands atm */
406-
if (is_atomic_size_supported(remote_addr, origin_dt_bytes) &&
399+
if (ompi_osc_base_is_atomic_size_supported(remote_addr, origin_dt_bytes) &&
407400
origin_dt_bytes == target_dt_bytes && origin_count == target_count) {
408401
return true;
409402
}
@@ -796,7 +789,7 @@ int ompi_osc_ucx_compare_and_swap(const void *origin_addr, const void *compare_a
796789
}
797790

798791
ompi_datatype_type_size(dt, &dt_bytes);
799-
if (is_atomic_size_supported(remote_addr, dt_bytes)) {
792+
if (ompi_osc_base_is_atomic_size_supported(remote_addr, dt_bytes)) {
800793
// fast path using UCX atomic operations
801794
return do_atomic_compare_and_swap(origin_addr, compare_addr,
802795
result_addr, dt, target,
@@ -852,7 +845,7 @@ int ompi_osc_ucx_fetch_and_op(const void *origin_addr, void *result_addr,
852845
ompi_datatype_type_size(dt, &dt_bytes);
853846

854847
/* UCX atomics are only supported on 32 and 64 bit values */
855-
if (is_atomic_size_supported(remote_addr, dt_bytes) &&
848+
if (ompi_osc_base_is_atomic_size_supported(remote_addr, dt_bytes) &&
856849
(op == &ompi_mpi_op_no_op.op || op == &ompi_mpi_op_replace.op ||
857850
op == &ompi_mpi_op_sum.op)) {
858851
uint64_t value;

0 commit comments

Comments
 (0)