File: osc_rdma_btl_comm.h

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 202,312 kB
  • sloc: ansic: 612,441; makefile: 42,495; sh: 11,230; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,154; python: 1,856; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (338 lines) | stat: -rw-r--r-- 14,034 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
 * Copyright (c) 2014-2018 Los Alamos National Security, LLC.  All rights
 *                         reserved.
 * Copyright (c) 2019      Triad National Security, LLC. All rights
 *                         reserved.
 * Copyright (c) 2021      Google, LLC. All rights reserved.
 * Copyright (c) 2022      Amazon.com, Inc. or its affiliates.
 *                         All Rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#ifndef OSC_RDMA_BTL_COMM_H
#define OSC_RDMA_BTL_COMM_H

#include "osc_rdma_frag.h"

#include "opal/mca/btl/btl.h"


void ompi_osc_rdma_atomic_complete(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
                                    void *local_address, mca_btl_base_registration_handle_t *local_handle,
                                    void *context, void *data, int status);


static inline int
ompi_osc_rdma_btl_put(ompi_osc_rdma_module_t *module, uint8_t btl_index,
		      struct mca_btl_base_endpoint_t *endpoint,
		      void *local_address, uint64_t remote_address,
		      struct mca_btl_base_registration_handle_t *local_handle,
		      struct mca_btl_base_registration_handle_t *remote_handle,
		      size_t size, int flags, int order,
		      mca_btl_base_rdma_completion_fn_t cbfunc,
		      void *cbcontext, void *cbdata)
{
    if (module->use_accelerated_btl) {
        mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl(module, btl_index);
        return btl->btl_put(btl, endpoint, local_address, remote_address,
                            local_handle, remote_handle, size, flags, order,
                            cbfunc, cbcontext, cbdata);
    } else {
        mca_btl_base_am_rdma_module_t *am_rdma = ompi_osc_rdma_selected_am_rdma(module, btl_index);
        return am_rdma->am_btl_put(am_rdma, endpoint, local_address, remote_address,
                                   local_handle, remote_handle, size, flags, order,
                                   cbfunc, cbcontext, cbdata);
    }
}


static inline int
ompi_osc_rdma_btl_get(ompi_osc_rdma_module_t *module, uint8_t btl_index,
		      struct mca_btl_base_endpoint_t *endpoint,
                      void *local_address, uint64_t remote_address,
		      struct mca_btl_base_registration_handle_t *local_handle,
		      struct mca_btl_base_registration_handle_t *remote_handle,
		      size_t size, int flags, int order,
		      mca_btl_base_rdma_completion_fn_t cbfunc,
		      void *cbcontext, void *cbdata)
{

    if (module->use_accelerated_btl) {
        mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl(module, btl_index);
        return btl->btl_get(btl, endpoint, local_address, remote_address,
                            local_handle, remote_handle, size, flags, order,
                            cbfunc, cbcontext, cbdata);
    } else {
        mca_btl_base_am_rdma_module_t *am_rdma = ompi_osc_rdma_selected_am_rdma(module, btl_index);
        return am_rdma->am_btl_get(am_rdma, endpoint, local_address, remote_address,
                                   local_handle, remote_handle, size, flags, order,
                                   cbfunc, cbcontext, cbdata);
    }
}


static inline int
ompi_osc_rdma_btl_atomic_op(ompi_osc_rdma_module_t *module, uint8_t btl_index,
                            struct mca_btl_base_endpoint_t *endpoint,
                            uint64_t remote_address, struct mca_btl_base_registration_handle_t *remote_handle,
                            mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order,
                            mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
{
    mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl(module, btl_index);

    /* the AM BTL interface does not currently support op calls */
    assert(module->use_accelerated_btl);

    return btl->btl_atomic_op(btl, endpoint, remote_address, remote_handle,
                              op, operand, flags, order,
                              cbfunc, cbcontext, cbdata);
}


static inline int
ompi_osc_rdma_btl_atomic_fop(ompi_osc_rdma_module_t *module, uint8_t btl_index,
                             struct mca_btl_base_endpoint_t *endpoint,
                             void *local_address, uint64_t remote_address,
                             struct mca_btl_base_registration_handle_t *local_handle,
                             struct mca_btl_base_registration_handle_t *remote_handle,
                             mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order,
                             mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)

{
    if (module->use_accelerated_btl) {
        mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl(module, btl_index);
        return btl->btl_atomic_fop(btl, endpoint, local_address, remote_address,
                                   local_handle, remote_handle,
                                   op, operand, flags, order,
                                   cbfunc, cbcontext, cbdata);
    } else {
        mca_btl_base_am_rdma_module_t *am_rdma = ompi_osc_rdma_selected_am_rdma(module, btl_index);
        return am_rdma->am_btl_atomic_fop(am_rdma, endpoint, local_address, remote_address,
                                          local_handle, remote_handle,
                                          op, operand, flags, order,
                                          cbfunc, cbcontext, cbdata);
    }
}


static inline int
ompi_osc_rdma_btl_atomic_cswap(ompi_osc_rdma_module_t *module, uint8_t btl_index,
                               struct mca_btl_base_endpoint_t *endpoint,
                               void *local_address, uint64_t remote_address,
                               struct mca_btl_base_registration_handle_t *local_handle,
                               struct mca_btl_base_registration_handle_t *remote_handle,
                               uint64_t compare, uint64_t value, int flags, int order,
                               mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
{
    if (module->use_accelerated_btl) {
        mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl(module, btl_index);
        return btl->btl_atomic_cswap(btl, endpoint, local_address, remote_address,
                                     local_handle, remote_handle,
                                     compare, value, flags, order,
                                     cbfunc, cbcontext, cbdata);
    } else {
        mca_btl_base_am_rdma_module_t *am_rdma = ompi_osc_rdma_selected_am_rdma(module, btl_index);
        return am_rdma->am_btl_atomic_cswap(am_rdma, endpoint, local_address, remote_address,
                                            local_handle, remote_handle,
                                            compare, value, flags, order,
                                            cbfunc, cbcontext, cbdata);
    }
}


static inline int
ompi_osc_rdma_btl_fop(ompi_osc_rdma_module_t *module, uint8_t btl_index,
		      struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
		      mca_btl_base_registration_handle_t *address_handle, int op,
		      int64_t operand, int flags, int64_t *result, const bool wait_for_completion,
		      ompi_osc_rdma_pending_op_cb_fn_t cbfunc, void *cbdata, void *cbcontext)
{
    ompi_osc_rdma_pending_op_t *pending_op;
    mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, btl_index);
    int ret = OPAL_ERROR;

    pending_op = OBJ_NEW(ompi_osc_rdma_pending_op_t);
    assert (NULL != pending_op);

    if (!wait_for_completion) {
        /* NTH: need to keep track of pending ops to avoid a potential teardown problem */
        pending_op->module = module;
        (void) opal_atomic_fetch_add_32 (&module->pending_ops, 1);
    }

    pending_op->op_result = (void *) result;
    pending_op->op_size = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? 4 : 8;
    OBJ_RETAIN(pending_op);
    if (cbfunc) {
        pending_op->cbfunc = cbfunc;
        pending_op->cbdata = cbdata;
        pending_op->cbcontext = cbcontext;
    }

    /* spin until the btl has accepted the operation */
    do {
        if (NULL == pending_op->op_frag) {
            ret = ompi_osc_rdma_frag_alloc (module, 8, &pending_op->op_frag, (char **) &pending_op->op_buffer);
        }

        if (NULL != pending_op->op_frag) {
            ret = ompi_osc_rdma_btl_atomic_fop(module, btl_index, endpoint, pending_op->op_buffer,
                                               (intptr_t) address, pending_op->op_frag->handle, address_handle,
                                               op, operand, flags, MCA_BTL_NO_ORDER, ompi_osc_rdma_atomic_complete,
                                               (void *) pending_op, NULL);
        }

        if (OPAL_LIKELY(!ompi_osc_rdma_oor(ret))) {
            break;
        }
        ompi_osc_rdma_progress (module);
    } while (1);

    if (OPAL_SUCCESS != ret) {
        if (OPAL_LIKELY(1 == ret)) {
            *result = ((int64_t *) pending_op->op_buffer)[0];
            ret = OMPI_SUCCESS;
            ompi_osc_rdma_atomic_complete (selected_btl, endpoint, pending_op->op_buffer,
                                           pending_op->op_frag->handle, (void *) pending_op, NULL, OPAL_SUCCESS);
        } else {
            /* need to release here because ompi_osc_rdma_atomic_complete was not called */
            OBJ_RELEASE(pending_op);
        }
    } else if (wait_for_completion) {
        while (!pending_op->op_complete) {
            ompi_osc_rdma_progress (module);
        }
    }

    OBJ_RELEASE(pending_op);

    return ret;
}


static inline int
ompi_osc_rdma_btl_op(ompi_osc_rdma_module_t *module, uint8_t btl_index,
		     struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
		     mca_btl_base_registration_handle_t *address_handle,
		     int op, int64_t operand, int flags, const bool wait_for_completion,
		     ompi_osc_rdma_pending_op_cb_fn_t cbfunc, void *cbdata, void *cbcontext)
{
    ompi_osc_rdma_pending_op_t *pending_op;
    mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, btl_index);
    int ret;

    /* if using the AM RDMA interface with alternate BTLs or if the
       accelerated BTL does not support atomic ops, emulate the atomic
       op over a fetch and atomic op */
    if (!module->use_accelerated_btl || !(selected_btl->btl_flags & MCA_BTL_FLAGS_ATOMIC_OPS)) {
        return ompi_osc_rdma_btl_fop (module, btl_index, endpoint, address, address_handle, op, operand, flags,
                                      NULL, wait_for_completion, cbfunc, cbdata, cbcontext);
    }

    pending_op = OBJ_NEW(ompi_osc_rdma_pending_op_t);
    assert (NULL != pending_op);
    OBJ_RETAIN(pending_op);
    if (cbfunc) {
        pending_op->cbfunc = cbfunc;
        pending_op->cbdata = cbdata;
        pending_op->cbcontext = cbcontext;
    }

    if (!wait_for_completion) {
        /* NTH: need to keep track of pending ops to avoid a potential teardown problem */
        pending_op->module = module;
        (void) opal_atomic_fetch_add_32 (&module->pending_ops, 1);
    }

    /* spin until the btl has accepted the operation */
    do {
        ret = ompi_osc_rdma_btl_atomic_op(module, btl_index, endpoint, (intptr_t) address, address_handle,
                                          op, operand, flags, MCA_BTL_NO_ORDER, ompi_osc_rdma_atomic_complete,
                                          (void *) pending_op, NULL);

        if (OPAL_LIKELY(!ompi_osc_rdma_oor(ret))) {
            break;
        }
        ompi_osc_rdma_progress (module);
    } while (1);

    if (OPAL_SUCCESS != ret) {
        /* need to release here because ompi_osc_rdma_atomic_complete was not called */
        OBJ_RELEASE(pending_op);
        if (OPAL_LIKELY(1 == ret)) {
            if (cbfunc) {
                cbfunc (cbdata, cbcontext, OMPI_SUCCESS);
            }
            ret = OMPI_SUCCESS;
        }
    } else if (wait_for_completion) {
        while (!pending_op->op_complete) {
            ompi_osc_rdma_progress (module);
        }
    }

    OBJ_RELEASE(pending_op);

    return ret;
}


static inline int
ompi_osc_rdma_btl_cswap(ompi_osc_rdma_module_t *module, uint8_t btl_index,
			struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
			mca_btl_base_registration_handle_t *address_handle,
			int64_t compare, int64_t value, int flags, int64_t *result)
{
    ompi_osc_rdma_pending_op_t *pending_op;
    int ret;

    pending_op = OBJ_NEW(ompi_osc_rdma_pending_op_t);
    assert (NULL != pending_op);

    OBJ_RETAIN(pending_op);

    pending_op->op_result = (void *) result;
    pending_op->op_size = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? 4 : 8;

    /* spin until the btl has accepted the operation */
    do {
        if (NULL == pending_op->op_frag) {
            ret = ompi_osc_rdma_frag_alloc (module, 8, &pending_op->op_frag, (char **) &pending_op->op_buffer);
        }
        if (NULL != pending_op->op_frag) {
            ret = ompi_osc_rdma_btl_atomic_cswap(module, btl_index, endpoint, pending_op->op_buffer,
                                                  address, pending_op->op_frag->handle, address_handle, compare,
                                                  value, flags, 0, ompi_osc_rdma_atomic_complete, (void *) pending_op,
                                                  NULL);
        }

        if (OPAL_LIKELY(!ompi_osc_rdma_oor(ret))) {
            break;
        }
        ompi_osc_rdma_progress (module);
    } while (1);

    if (OPAL_SUCCESS != ret) {
        if (OPAL_LIKELY(1 == ret)) {
            *result = ((int64_t *) pending_op->op_buffer)[0];
            ret = OMPI_SUCCESS;
        }

        /* need to release here because ompi_osc_rdma_atomic_complete was not called */
        OBJ_RELEASE(pending_op);
    } else {
        while (!pending_op->op_complete) {
            ompi_osc_rdma_progress (module);
        }
    }

    OBJ_RELEASE(pending_op);

    return ret;
}

#endif /* OSC_RDMA_BTL_COMM_H */