File: atomic.h

package info (click to toggle)
openmpi 5.0.8-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,692 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (324 lines) | stat: -rw-r--r-- 15,058 bytes parent folder | download | duplicates (4)
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
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2013      Mellanox Technologies, Inc.
 *                         All rights reserved.
 * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

/**
 * @file
 *
 * Atomic Operations Interface
 *
 */

#ifndef OSHMEM_MCA_ATOMIC_H
#define OSHMEM_MCA_ATOMIC_H

#include "oshmem_config.h"
#include "oshmem/types.h"
#include "oshmem/constants.h"

#include "opal/util/output.h"
#include "mpi.h"
#include "oshmem/mca/mca.h"
#include "opal/mca/base/base.h"
#include "oshmem/mca/atomic/base/base.h"

BEGIN_C_DECLS

#define OSHMEM_ATOMIC_PTR_2_INT(ptr, size) ((size) == 8 ? *(uint64_t*)(ptr) : *(uint32_t*)(ptr))

#define DO_SHMEM_TYPE_OP(ctx, type_name, type, op, target, value, pe) do {    \
        int rc = OSHMEM_SUCCESS;                                              \
        size_t size = 0;                                                      \
                                                                              \
        RUNTIME_CHECK_INIT();                                                 \
        RUNTIME_CHECK_PE(pe);                                                 \
        RUNTIME_CHECK_ADDR(target);                                           \
                                                                              \
        size = sizeof(value);                                                 \
        rc = MCA_ATOMIC_CALL(op(                                              \
            ctx,                                                              \
            (void*)target,                                                    \
            value,                                                            \
            size,                                                             \
            pe));                                                             \
        RUNTIME_CHECK_RC(rc);                                                 \
                                                                              \
        return;                                                               \
    } while (0)

#define OSHMEM_TYPE_OP(type_name, type, prefix, op)                           \
    void prefix##_##type_name##_atomic_##op(type *target, type value, int pe) \
    {                                                                         \
        DO_SHMEM_TYPE_OP(oshmem_ctx_default, type_name, type, op,             \
                         target, value, pe);                                  \
    }

#define OSHMEM_CTX_TYPE_OP(type_name, type, prefix, op)                       \
    void prefix##_ctx_##type_name##_atomic_##op(shmem_ctx_t ctx, type *target, type value, int pe) \
    {                                                                         \
        DO_SHMEM_TYPE_OP(ctx, type_name, type, op,                            \
                         target, value, pe);                                  \
    }

#define DO_OSHMEM_TYPE_FOP(ctx, type_name, type, op, target, value, pe) do {        \
        int rc = OSHMEM_SUCCESS;                                                    \
        size_t size = 0;                                                            \
        type out_value;                                                             \
                                                                                    \
        RUNTIME_CHECK_INIT();                                                       \
        RUNTIME_CHECK_PE(pe);                                                       \
        RUNTIME_CHECK_ADDR(target);                                                 \
                                                                                    \
        size = sizeof(out_value);                                                   \
        rc = MCA_ATOMIC_CALL(f##op(                                                 \
            ctx,                                                                    \
            (void*)target,                                                          \
            (void*)&out_value,                                                      \
            value,                                                                  \
            size,                                                                   \
            pe));                                                                   \
        RUNTIME_CHECK_RC(rc);                                                       \
                                                                                    \
        return out_value;                                                           \
    } while (0)

#define OSHMEM_TYPE_FOP(type_name, type, prefix, op)                                \
    type prefix##_##type_name##_atomic_fetch_##op(type *target, type value, int pe) \
    {                                                                               \
        DO_OSHMEM_TYPE_FOP(oshmem_ctx_default, type_name, type, op,                 \
                           target, value, pe);                                      \
    }

#define OSHMEM_CTX_TYPE_FOP(type_name, type, prefix, op)                   \
    type prefix##_ctx_##type_name##_atomic_fetch_##op(shmem_ctx_t ctx, type *target, type value, int pe) \
    {                                                                      \
        DO_OSHMEM_TYPE_FOP(ctx, type_name, type, op,                       \
                           target, value, pe);                             \
    }

#define DO_OSHMEM_TYPE_FOP_NBI(ctx, type_name, type, op, fetch, target, value, pe) do {        \
        int rc = OSHMEM_SUCCESS;                                                    \
        size_t size = 0;                                                            \
        type out_value;                                                             \
                                                                                    \
        RUNTIME_CHECK_INIT();                                                       \
        RUNTIME_CHECK_PE(pe);                                                       \
        RUNTIME_CHECK_ADDR(target);                                                 \
                                                                                    \
        size = sizeof(out_value);                                                   \
        rc = MCA_ATOMIC_CALL(f##op##_nb(                                            \
            ctx,                                                                    \
            fetch,                                                                  \
            (void*)target,                                                          \
            (void*)&out_value,                                                      \
            value,                                                                  \
            size,                                                                   \
            pe));                                                                   \
        RUNTIME_CHECK_RC(rc);                                                       \
                                                                                    \
        return ;                                                           	     \
    } while (0)

#define OSHMEM_TYPE_FOP_NBI(type_name, type, prefix, op)                                \
    void prefix##_##type_name##_atomic_fetch_##op##_nbi(type *fetch, type *target, type value, int pe) \
    {                                                                                   \
        DO_OSHMEM_TYPE_FOP_NBI(oshmem_ctx_default, type_name, type, op,                 \
                           fetch, target, value, pe);                                   \
    }

#define OSHMEM_CTX_TYPE_FOP_NBI(type_name, type, prefix, op)                            \
    void prefix##_ctx_##type_name##_atomic_fetch_##op##_nbi(shmem_ctx_t ctx, type *fetch, type *target, type value, int pe) \
    {                                                                                   \
        DO_OSHMEM_TYPE_FOP_NBI(ctx, type_name, type, op,                                \
                           fetch, target, value, pe);                                   \
    }
/* ******************************************************************** */

struct oshmem_op_t;

/* ******************************************************************** */

typedef int (*mca_atomic_base_component_init_fn_t)(bool enable_progress_threads,
                                                   bool enable_threads);

typedef int (*mca_atomic_base_component_finalize_fn_t)(void);

typedef struct mca_atomic_base_module_1_0_0_t* (*mca_atomic_base_component_query_fn_t)(int *priority);

/* ******************************************************************** */

/**
 * Atomic component interface
 *
 * Component interface for the atomic framework.  A public
 * instance of this structure, called
 * mca_atomic_[component_name]_component, must exist in any atomic
 * component.
 */
struct mca_atomic_base_component_1_0_0_t {
    /** Base component description */
    mca_base_component_t atomic_version;
    /** Base component data block */
    mca_base_component_data_t atomic_data;

    /** Component initialization function */
    mca_atomic_base_component_init_fn_t atomic_startup;
    mca_atomic_base_component_finalize_fn_t atomic_finalize;
    mca_atomic_base_component_query_fn_t atomic_query;

    /* priority for component */
    int priority;
};
typedef struct mca_atomic_base_component_1_0_0_t mca_atomic_base_component_1_0_0_t;

/** Per guidance in mca.h, use the unversioned struct name if you just
 want to always keep up with the most recent version of the
 interface. */
typedef struct mca_atomic_base_component_1_0_0_t mca_atomic_base_component_t;

/**
 * Atomic module interface
 *
 */
struct mca_atomic_base_module_1_0_0_t {
    /** Collective modules all inherit from opal_object */
    opal_object_t super;

    /* Collective function pointers */
    int (*atomic_add)(shmem_ctx_t ctx,
                      void *target,
                      uint64_t value,
                      size_t size,
                      int pe);
    int (*atomic_and)(shmem_ctx_t ctx,
                      void *target,
                      uint64_t value,
                      size_t size,
                      int pe);
    int (*atomic_or)(shmem_ctx_t ctx,
                     void *target,
                     uint64_t value,
                     size_t size,
                     int pe);
    int (*atomic_xor)(shmem_ctx_t ctx,
                      void *target,
                      uint64_t value,
                      size_t size,
                      int pe);
    int (*atomic_fadd)(shmem_ctx_t ctx,
                       void *target,
                       void *prev,
                       uint64_t value,
                       size_t size,
                       int pe);
    int (*atomic_fand)(shmem_ctx_t ctx,
                       void *target,
                       void *prev,
                       uint64_t value,
                       size_t size,
                       int pe);
    int (*atomic_for)(shmem_ctx_t ctx,
                      void *target,
                      void *prev,
                      uint64_t value,
                      size_t size,
                      int pe);
    int (*atomic_fxor)(shmem_ctx_t ctx,
                       void *target,
                       void *prev,
                       uint64_t value,
                       size_t size,
                       int pe);
    int (*atomic_swap)(shmem_ctx_t ctx,
                       void *target,
                       void *prev,
                       uint64_t value,
                       size_t size,
                       int pe);
    int (*atomic_cswap)(shmem_ctx_t ctx,
                        void *target,
                        uint64_t *prev, /* prev is used internally by wrapper, we may
                                           always use 64-bit value */
                        uint64_t cond,
                        uint64_t value,
                        size_t size,
                        int pe);
    int (*atomic_fadd_nb)(shmem_ctx_t ctx,
                       void *fetch,
                       void *target,
                       void *prev,
                       uint64_t value,
                       size_t size,
                       int pe);
    int (*atomic_cswap_nb)(shmem_ctx_t ctx,
                        void *fetch,
                        void *target,
                        uint64_t *prev, /* prev is used internally by wrapper, we may
                                           always use 64-bit value */
                        uint64_t cond,
                        uint64_t value,
                        size_t size,
                        int pe);
    int (*atomic_swap_nb)(shmem_ctx_t ctx,
                       void *fetch,
                       void *target,
                       void *prev,
                       uint64_t value,
                       size_t size,
                       int pe);
    int (*atomic_fand_nb)(shmem_ctx_t ctx,
                       void *fetch,
                       void *target,
                       void *prev,
                       uint64_t value,
                       size_t size,
                       int pe);
    int (*atomic_for_nb)(shmem_ctx_t ctx,
                       void *fetch,
                      void *target,
                      void *prev,
                      uint64_t value,
                      size_t size,
                      int pe);
    int (*atomic_fxor_nb)(shmem_ctx_t ctx,
                       void *fetch,
                       void *target,
                       void *prev,
                       uint64_t value,
                       size_t size,
                       int pe);
};
typedef struct mca_atomic_base_module_1_0_0_t mca_atomic_base_module_1_0_0_t;

/** Per guidance in mca.h, use the unversioned struct name if you just
 want to always keep up with the most recent version of the
 interface. */
typedef struct mca_atomic_base_module_1_0_0_t mca_atomic_base_module_t;
OSHMEM_DECLSPEC OBJ_CLASS_DECLARATION(mca_atomic_base_module_t);

/* ******************************************************************** */

/*
 * Macro for use in components
 */
#define MCA_ATOMIC_BASE_VERSION_2_0_0 \
    OSHMEM_MCA_BASE_VERSION_2_1_0("atomic", 1, 0, 0)

/* ******************************************************************** */

OSHMEM_DECLSPEC extern mca_atomic_base_component_t mca_atomic_base_selected_component;
OSHMEM_DECLSPEC extern mca_atomic_base_module_t mca_atomic;
#define MCA_ATOMIC_CALL(a) mca_atomic.atomic_ ## a

END_C_DECLS

#endif /* OSHMEM_MCA_ATOMIC_H */