File: osc_rdma_peer.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 (252 lines) | stat: -rw-r--r-- 7,224 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
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2014-2018 Los Alamos National Security, LLC.  All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#ifndef OMPI_OSC_RDMA_PEER_H
#define OMPI_OSC_RDMA_PEER_H

#include "osc_rdma_types.h"

struct ompi_osc_rdma_module_t;

/**
 * @brief osc rdma peer object
 *
 * This object is used as a cache for information associated with a peer.
 */
struct ompi_osc_rdma_peer_t {
    opal_list_item_t super;

    /** rdma data endpoint for this peer */
    struct mca_btl_base_endpoint_t *data_endpoint;

    /** endpoint for reading/modifying peer state */
    struct mca_btl_base_endpoint_t *state_endpoint;

    /** remote peer's state pointer */
    osc_rdma_base_t state;

    /** registration handle associated with the state */
    mca_btl_base_registration_handle_t *state_handle;

    /** lock to protect peer structure */
    opal_mutex_t lock;

    /** rank of this peer in the window */
    int rank;

    /** peer flags */
    opal_atomic_int32_t flags;

    /** index into BTL array */
    uint8_t data_btl_index;

    /** index into BTL array */
    uint8_t state_btl_index;
};
typedef struct ompi_osc_rdma_peer_t ompi_osc_rdma_peer_t;

/**
 * @brief peer object used when using dynamic windows
 */
struct ompi_osc_rdma_peer_dynamic_t {
    ompi_osc_rdma_peer_t super;

    /** last region id seen for this peer */
    uint32_t region_id;

    /** number of regions in the regions array */
    uint32_t region_count;

    /** cached array of attached regions for this peer */
    struct ompi_osc_rdma_region_t *regions;
};

typedef struct ompi_osc_rdma_peer_dynamic_t ompi_osc_rdma_peer_dynamic_t;

/**
 * @brief basic peer object for non-dynamic windows used when all peers
 *        have the same displacement unit and size
 */
struct ompi_osc_rdma_peer_basic_t {
    ompi_osc_rdma_peer_t super;

    /** remote peer's base pointer */
    osc_rdma_base_t base;

    /** local pointer to peer's base */
    osc_rdma_base_t local_base;

    /** registration handle associated with the base */
    mca_btl_base_registration_handle_t *base_handle;
};

typedef struct ompi_osc_rdma_peer_basic_t ompi_osc_rdma_peer_basic_t;

/**
 * @brief peer object used when no assumption can be made about the
 *        peer's displacement unit or size
 */
struct ompi_osc_rdma_peer_extended_t {
    ompi_osc_rdma_peer_basic_t super;

    /** remote peer's region size */
    osc_rdma_size_t size;

    /** displacement unit */
    int disp_unit;
};

typedef struct ompi_osc_rdma_peer_extended_t ompi_osc_rdma_peer_extended_t;

/**
 * @brief object class declarations
 */
OBJ_CLASS_DECLARATION(ompi_osc_rdma_peer_t);
OBJ_CLASS_DECLARATION(ompi_osc_rdma_peer_dynamic_t);
OBJ_CLASS_DECLARATION(ompi_osc_rdma_peer_basic_t);
OBJ_CLASS_DECLARATION(ompi_osc_rdma_peer_extended_t);

/**
 * @brief used to identify the node and local rank of a peer
 */
struct ompi_osc_rdma_rank_data_t {
    /** index of none in none_comm_info array */
    unsigned int node_id;
    /** local rank of process */
    unsigned int rank;
};
typedef struct ompi_osc_rdma_rank_data_t ompi_osc_rdma_rank_data_t;

enum {
    /** peer is locked for exclusive access */
    OMPI_OSC_RDMA_PEER_EXCLUSIVE            = 0x01,
    /** peer's base is accessible with direct loads/stores */
    OMPI_OSC_RDMA_PEER_LOCAL_BASE           = 0x02,
    /** peer state is local */
    OMPI_OSC_RDMA_PEER_LOCAL_STATE          = 0x04,
    /** currently accumulating on peer */
    OMPI_OSC_RDMA_PEER_ACCUMULATING         = 0x08,
    /** peer is in an active access epoch (pscw) */
    OMPI_OSC_RDMA_PEER_ACCESS_ACTIVE_EPOCH  = 0x10,
    /** peer state handle should be freed */
    OMPI_OSC_RDMA_PEER_STATE_FREE           = 0x20,
    /** peer base handle should be freed */
    OMPI_OSC_RDMA_PEER_BASE_FREE            = 0x40,
    /** peer was demand locked as part of lock-all (when in demand locking mode) */
    OMPI_OSC_RDMA_PEER_DEMAND_LOCKED        = 0x80,
};

/**
 * @brief allocate a peer object and initialize some of it structures
 *
 * @param[in]  module         osc rdma module
 * @param[in]  peer_id        peer's rank in the communicator
 * @param[out] peer_out       new peer object
 *
 * The type of the object returned depends on the window settings. For example for a dynamic window
 * this will return a peer of type \ref ompi_osc_rdma_peer_dynamic_t.
 */
int ompi_osc_rdma_new_peer (struct ompi_osc_rdma_module_t *module, int peer_id, ompi_osc_rdma_peer_t **peer_out);

/**
 * @brief lookup (or allocate) a peer
 *
 * @param[in]  module         osc rdma module
 * @param[in]  peer_id        peer's rank in the communicator
 *
 * This function is used by the ompi_osc_rdma_module_peer() inline function to allocate a peer object. It is not
 * intended to be called from anywhere else.
 */
struct ompi_osc_rdma_peer_t *ompi_osc_rdma_peer_lookup (struct ompi_osc_rdma_module_t *module, int peer_id);

/**
 * @brief check if this process holds an exclusive lock on a peer
 *
 * @param[in] peer            peer object to check
 */
static inline bool ompi_osc_rdma_peer_is_exclusive (ompi_osc_rdma_peer_t *peer)
{
    return !!(peer->flags & OMPI_OSC_RDMA_PEER_EXCLUSIVE);
}

/**
 * @brief try to set a flag on a peer object
 *
 * @param[in] peer            peer object to modify
 * @param[in] flag            flag to set
 *
 * @returns true if the flag was not already set
 * @returns flase otherwise
 */
static inline bool ompi_osc_rdma_peer_test_set_flag (ompi_osc_rdma_peer_t *peer, int flag)
{
    int32_t flags;

    opal_atomic_mb ();
    flags = peer->flags;

    do {
        if (flags & flag) {
            return false;
        }
    } while (!OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 (&peer->flags, &flags, flags | flag));

    return true;
}

/**
 * @brief clear a flag from a peer object
 *
 * @param[in] peer            peer object to modify
 * @param[in] flag            flag to set
 */
static inline void ompi_osc_rdma_peer_clear_flag (ompi_osc_rdma_peer_t *peer, int flag)
{
    OPAL_ATOMIC_AND_FETCH32(&peer->flags, ~flag);
    opal_atomic_mb ();
}

/**
 * @brief check if the peer's base pointer is local to this process
 *
 * @param[in] peer            peer object to check
 */
static inline bool ompi_osc_rdma_peer_local_base (ompi_osc_rdma_peer_t *peer)
{
    return !!(peer->flags & OMPI_OSC_RDMA_PEER_LOCAL_BASE);
}

/**
 * @brief check if the peer's state pointer is local to this process
 *
 * @param[in] peer            peer object to check
 *
 * The OMPI_OSC_RDMA_PEER_LOCAL_STATE flag will only be set if either 1) we
 * will not be mixing btl atomics and cpu atomics, or 2) it is safe to mix
 * btl and cpu atomics.
 */
static inline bool ompi_osc_rdma_peer_local_state (ompi_osc_rdma_peer_t *peer)
{
    return !!(peer->flags & OMPI_OSC_RDMA_PEER_LOCAL_STATE);
}

/**
 * @brief check if the peer has been demand locked as part of the current epoch
 *
 * @param[in] peer            peer object to check
 *
 */
static inline bool ompi_osc_rdma_peer_is_demand_locked (ompi_osc_rdma_peer_t *peer)
{
    return !!(peer->flags & OMPI_OSC_RDMA_PEER_DEMAND_LOCKED);
}

#endif /* OMPI_OSC_RDMA_PEER_H */