Skip to content

Commit 0394543

Browse files
committed
osc/rdma: Refactor btl wrapper code
Refactor wrapper calls around the btl atomic code into their own header, removing them from the lock interface header. Clean up some resulting header dependency changes. Signed-off-by: Brian Barrett <[email protected]>
1 parent e93f041 commit 0394543

File tree

8 files changed

+295
-222
lines changed

8 files changed

+295
-222
lines changed

ompi/mca/osc/rdma/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# Copyright (c) 2014-2015 Los Alamos National Security, LLC. All rights
1212
# reserved.
1313
# Copyright (c) 2017 IBM Corporation. All rights reserved.
14+
# Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
15+
# All Rights reserved.
1416
# $COPYRIGHT$
1517
#
1618
# Additional copyrights may follow
@@ -21,6 +23,8 @@
2123
rdma_sources = \
2224
osc_rdma.h \
2325
osc_rdma_module.c \
26+
osc_rdma_btl_comm.h \
27+
osc_rdma_btl_comm.c \
2428
osc_rdma_comm.h \
2529
osc_rdma_comm.c \
2630
osc_rdma_accumulate.c \

ompi/mca/osc/rdma/osc_rdma_accumulate.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Copyright (c) 2019-2021 Google, LLC. All rights reserved.
1111
* Copyright (c) 2021 IBM Corporation. All rights reserved.
1212
* Copyright (c) 2022 Cisco Systems, Inc. All rights reserved
13+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
14+
* All Rights reserved.
1315
* $COPYRIGHT$
1416
*
1517
* Additional copyrights may follow
@@ -20,6 +22,8 @@
2022
#include "osc_rdma_accumulate.h"
2123
#include "osc_rdma_request.h"
2224
#include "osc_rdma_comm.h"
25+
#include "osc_rdma_lock.h"
26+
#include "osc_rdma_btl_comm.h"
2327

2428
#include "ompi/mca/osc/base/base.h"
2529
#include "ompi/mca/osc/base/osc_base_obj_convert.h"

ompi/mca/osc/rdma/osc_rdma_active_target.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,6 @@ OBJ_CLASS_INSTANCE(ompi_osc_rdma_pending_op_t, opal_list_item_t,
7777
ompi_osc_rdma_pending_op_construct,
7878
ompi_osc_rdma_pending_op_destruct);
7979

80-
/**
81-
* Dummy completion function for atomic operations
82-
*/
83-
void ompi_osc_rdma_atomic_complete (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
84-
void *local_address, mca_btl_base_registration_handle_t *local_handle,
85-
void *context, void *data, int status)
86-
{
87-
ompi_osc_rdma_pending_op_t *pending_op = (ompi_osc_rdma_pending_op_t *) context;
88-
89-
OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_INFO, "pending atomic %p complete with status %d", (void*)pending_op, status);
90-
91-
if (pending_op->op_result) {
92-
memmove (pending_op->op_result, pending_op->op_buffer, pending_op->op_size);
93-
}
94-
95-
if (NULL != pending_op->cbfunc) {
96-
pending_op->cbfunc (pending_op->cbdata, pending_op->cbcontext, status);
97-
}
98-
99-
if (NULL != pending_op->op_frag) {
100-
ompi_osc_rdma_frag_complete (pending_op->op_frag);
101-
pending_op->op_frag = NULL;
102-
}
103-
104-
pending_op->op_complete = true;
105-
OBJ_RELEASE(pending_op);
106-
}
10780

10881
/**
10982
* compare_ranks:

ompi/mca/osc/rdma/osc_rdma_btl_comm.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2004-2005 The Trustees of Indiana University.
4+
* All rights reserved.
5+
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
6+
* All rights reserved.
7+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
8+
* University of Stuttgart. All rights reserved.
9+
* Copyright (c) 2004-2005 The Regents of the University of California.
10+
* All rights reserved.
11+
* Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights
12+
* reserved.
13+
* Copyright (c) 2010 IBM Corporation. All rights reserved.
14+
* Copyright (c) 2012-2013 Sandia National Laboratories. All rights reserved.
15+
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
16+
* Copyright (c) 2017 The University of Tennessee and The University
17+
* of Tennessee Research Foundation. All rights
18+
* reserved.
19+
* Copyright (c) 2017-2018 Intel, Inc. All rights reserved.
20+
* Copyright (c) 2021 Google, LLC. All rights reserved.
21+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
22+
* All Rights reserved.
23+
* $COPYRIGHT$
24+
*
25+
* Additional copyrights may follow
26+
*
27+
* $HEADER$
28+
*/
29+
30+
#include "ompi_config.h"
31+
32+
#include "osc_rdma.h"
33+
#include "osc_rdma_frag.h"
34+
#include "osc_rdma_btl_comm.h"
35+
36+
#include "opal/mca/btl/base/base.h"
37+
38+
void ompi_osc_rdma_atomic_complete (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
39+
void *local_address, mca_btl_base_registration_handle_t *local_handle,
40+
void *context, void *data, int status)
41+
{
42+
ompi_osc_rdma_pending_op_t *pending_op = (ompi_osc_rdma_pending_op_t *) context;
43+
44+
OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_INFO, "pending atomic %p complete with status %d", (void*)pending_op, status);
45+
46+
if (pending_op->op_result) {
47+
memmove (pending_op->op_result, pending_op->op_buffer, pending_op->op_size);
48+
}
49+
50+
if (NULL != pending_op->cbfunc) {
51+
pending_op->cbfunc (pending_op->cbdata, pending_op->cbcontext, status);
52+
}
53+
54+
if (NULL != pending_op->op_frag) {
55+
ompi_osc_rdma_frag_complete (pending_op->op_frag);
56+
pending_op->op_frag = NULL;
57+
}
58+
59+
pending_op->op_complete = true;
60+
OBJ_RELEASE(pending_op);
61+
}

ompi/mca/osc/rdma/osc_rdma_btl_comm.h

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* Copyright (c) 2014-2018 Los Alamos National Security, LLC. All rights
3+
* reserved.
4+
* Copyright (c) 2019 Triad National Security, LLC. All rights
5+
* reserved.
6+
* Copyright (c) 2021 Google, LLC. All rights reserved.
7+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
8+
* All Rights reserved.
9+
* $COPYRIGHT$
10+
*
11+
* Additional copyrights may follow
12+
*
13+
* $HEADER$
14+
*/
15+
16+
#ifndef OSC_RDMA_BTL_COMM_H
17+
#define OSC_RDMA_BTL_COMM_H
18+
19+
#include "osc_rdma_frag.h"
20+
21+
#include "opal/mca/btl/btl.h"
22+
23+
24+
void ompi_osc_rdma_atomic_complete(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
25+
void *local_address, mca_btl_base_registration_handle_t *local_handle,
26+
void *context, void *data, int status);
27+
28+
29+
static inline int
30+
ompi_osc_rdma_btl_fop(ompi_osc_rdma_module_t *module, uint8_t btl_index,
31+
struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
32+
mca_btl_base_registration_handle_t *address_handle, int op,
33+
int64_t operand, int flags, int64_t *result, const bool wait_for_completion,
34+
ompi_osc_rdma_pending_op_cb_fn_t cbfunc, void *cbdata, void *cbcontext)
35+
{
36+
ompi_osc_rdma_pending_op_t *pending_op;
37+
mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, btl_index);
38+
int ret = OPAL_ERROR;
39+
40+
pending_op = OBJ_NEW(ompi_osc_rdma_pending_op_t);
41+
assert (NULL != pending_op);
42+
43+
if (!wait_for_completion) {
44+
/* NTH: need to keep track of pending ops to avoid a potential teardown problem */
45+
pending_op->module = module;
46+
(void) opal_atomic_fetch_add_32 (&module->pending_ops, 1);
47+
}
48+
49+
pending_op->op_result = (void *) result;
50+
pending_op->op_size = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? 4 : 8;
51+
OBJ_RETAIN(pending_op);
52+
if (cbfunc) {
53+
pending_op->cbfunc = cbfunc;
54+
pending_op->cbdata = cbdata;
55+
pending_op->cbcontext = cbcontext;
56+
}
57+
58+
/* spin until the btl has accepted the operation */
59+
do {
60+
if (NULL == pending_op->op_frag) {
61+
ret = ompi_osc_rdma_frag_alloc (module, 8, &pending_op->op_frag, (char **) &pending_op->op_buffer);
62+
}
63+
64+
if (NULL != pending_op->op_frag) {
65+
ret = selected_btl->btl_atomic_fop (selected_btl, endpoint, pending_op->op_buffer,
66+
(intptr_t) address, pending_op->op_frag->handle, address_handle,
67+
op, operand, flags, MCA_BTL_NO_ORDER, ompi_osc_rdma_atomic_complete,
68+
(void *) pending_op, NULL);
69+
}
70+
71+
if (OPAL_LIKELY(!ompi_osc_rdma_oor(ret))) {
72+
break;
73+
}
74+
ompi_osc_rdma_progress (module);
75+
} while (1);
76+
77+
if (OPAL_SUCCESS != ret) {
78+
if (OPAL_LIKELY(1 == ret)) {
79+
*result = ((int64_t *) pending_op->op_buffer)[0];
80+
ret = OMPI_SUCCESS;
81+
ompi_osc_rdma_atomic_complete (selected_btl, endpoint, pending_op->op_buffer,
82+
pending_op->op_frag->handle, (void *) pending_op, NULL, OPAL_SUCCESS);
83+
} else {
84+
/* need to release here because ompi_osc_rdma_atomic_complete was not called */
85+
OBJ_RELEASE(pending_op);
86+
}
87+
} else if (wait_for_completion) {
88+
while (!pending_op->op_complete) {
89+
ompi_osc_rdma_progress (module);
90+
}
91+
}
92+
93+
OBJ_RELEASE(pending_op);
94+
95+
return ret;
96+
}
97+
98+
99+
static inline int
100+
ompi_osc_rdma_btl_op(ompi_osc_rdma_module_t *module, uint8_t btl_index,
101+
struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
102+
mca_btl_base_registration_handle_t *address_handle,
103+
int op, int64_t operand, int flags, const bool wait_for_completion,
104+
ompi_osc_rdma_pending_op_cb_fn_t cbfunc, void *cbdata, void *cbcontext)
105+
{
106+
ompi_osc_rdma_pending_op_t *pending_op;
107+
mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, btl_index);
108+
int ret;
109+
110+
if (!(selected_btl->btl_flags & MCA_BTL_FLAGS_ATOMIC_OPS)) {
111+
return ompi_osc_rdma_btl_fop (module, btl_index, endpoint, address, address_handle, op, operand, flags,
112+
NULL, wait_for_completion, cbfunc, cbdata, cbcontext);
113+
}
114+
115+
pending_op = OBJ_NEW(ompi_osc_rdma_pending_op_t);
116+
assert (NULL != pending_op);
117+
OBJ_RETAIN(pending_op);
118+
if (cbfunc) {
119+
pending_op->cbfunc = cbfunc;
120+
pending_op->cbdata = cbdata;
121+
pending_op->cbcontext = cbcontext;
122+
}
123+
124+
if (!wait_for_completion) {
125+
/* NTH: need to keep track of pending ops to avoid a potential teardown problem */
126+
pending_op->module = module;
127+
(void) opal_atomic_fetch_add_32 (&module->pending_ops, 1);
128+
}
129+
130+
/* spin until the btl has accepted the operation */
131+
do {
132+
ret = selected_btl->btl_atomic_op (selected_btl, endpoint, (intptr_t) address, address_handle,
133+
op, operand, flags, MCA_BTL_NO_ORDER, ompi_osc_rdma_atomic_complete,
134+
(void *) pending_op, NULL);
135+
136+
if (OPAL_LIKELY(!ompi_osc_rdma_oor(ret))) {
137+
break;
138+
}
139+
ompi_osc_rdma_progress (module);
140+
} while (1);
141+
142+
if (OPAL_SUCCESS != ret) {
143+
/* need to release here because ompi_osc_rdma_atomic_complete was not called */
144+
OBJ_RELEASE(pending_op);
145+
if (OPAL_LIKELY(1 == ret)) {
146+
if (cbfunc) {
147+
cbfunc (cbdata, cbcontext, OMPI_SUCCESS);
148+
}
149+
ret = OMPI_SUCCESS;
150+
}
151+
} else if (wait_for_completion) {
152+
while (!pending_op->op_complete) {
153+
ompi_osc_rdma_progress (module);
154+
}
155+
}
156+
157+
OBJ_RELEASE(pending_op);
158+
159+
return ret;
160+
}
161+
162+
163+
static inline int
164+
ompi_osc_rdma_btl_cswap(ompi_osc_rdma_module_t *module, uint8_t btl_index,
165+
struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
166+
mca_btl_base_registration_handle_t *address_handle,
167+
int64_t compare, int64_t value, int flags, int64_t *result)
168+
{
169+
ompi_osc_rdma_pending_op_t *pending_op;
170+
mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, btl_index);
171+
int ret;
172+
173+
pending_op = OBJ_NEW(ompi_osc_rdma_pending_op_t);
174+
assert (NULL != pending_op);
175+
176+
OBJ_RETAIN(pending_op);
177+
178+
pending_op->op_result = (void *) result;
179+
pending_op->op_size = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? 4 : 8;
180+
181+
/* spin until the btl has accepted the operation */
182+
do {
183+
if (NULL == pending_op->op_frag) {
184+
ret = ompi_osc_rdma_frag_alloc (module, 8, &pending_op->op_frag, (char **) &pending_op->op_buffer);
185+
}
186+
if (NULL != pending_op->op_frag) {
187+
ret = selected_btl->btl_atomic_cswap (selected_btl, endpoint, pending_op->op_buffer,
188+
address, pending_op->op_frag->handle, address_handle, compare,
189+
value, flags, 0, ompi_osc_rdma_atomic_complete, (void *) pending_op,
190+
NULL);
191+
}
192+
193+
if (OPAL_LIKELY(!ompi_osc_rdma_oor(ret))) {
194+
break;
195+
}
196+
ompi_osc_rdma_progress (module);
197+
} while (1);
198+
199+
if (OPAL_SUCCESS != ret) {
200+
if (OPAL_LIKELY(1 == ret)) {
201+
*result = ((int64_t *) pending_op->op_buffer)[0];
202+
ret = OMPI_SUCCESS;
203+
}
204+
205+
/* need to release here because ompi_osc_rdma_atomic_complete was not called */
206+
OBJ_RELEASE(pending_op);
207+
} else {
208+
while (!pending_op->op_complete) {
209+
ompi_osc_rdma_progress (module);
210+
}
211+
}
212+
213+
OBJ_RELEASE(pending_op);
214+
215+
return ret;
216+
}
217+
218+
#endif /* OSC_RDMA_BTL_COMM_H */

ompi/mca/osc/rdma/osc_rdma_comm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Copyright (c) 2017 Research Organization for Information Science
77
* and Technology (RIST). All rights reserved.
88
* Copyright (c) 2017 IBM Corporation. All rights reserved.
9+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
10+
* All Rights reserved.
911
* $COPYRIGHT$
1012
*
1113
* Additional copyrights may follow
@@ -14,6 +16,7 @@
1416
*/
1517

1618
#include "osc_rdma_comm.h"
19+
#include "osc_rdma_frag.h"
1720
#include "osc_rdma_sync.h"
1821
#include "osc_rdma_request.h"
1922
#include "osc_rdma_dynamic.h"

ompi/mca/osc/rdma/osc_rdma_comm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* reserved.
55
* Copyright (c) 2017 Research Organization for Information Science
66
* and Technology (RIST). All rights reserved.
7+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
8+
* All Rights reserved.
79
* $COPYRIGHT$
810
*
911
* Additional copyrights may follow
@@ -17,7 +19,6 @@
1719
#include "osc_rdma_dynamic.h"
1820
#include "osc_rdma_request.h"
1921
#include "osc_rdma_sync.h"
20-
#include "osc_rdma_lock.h"
2122

2223
#define OMPI_OSC_RDMA_DECODE_MAX 64
2324

0 commit comments

Comments
 (0)