-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdart_globmem.h
421 lines (378 loc) · 11.9 KB
/
dart_globmem.h
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#ifndef DART_GLOBMEM_H_INCLUDED
#define DART_GLOBMEM_H_INCLUDED
/**
* \file dart_globmem.h
*
* \defgroup DartGlobMem Global memory and PGAS address semantics
* \ingroup DartInterface
*
* Routines for allocation and reclamation of global memory regions and
* local address resolution in partitioned global address space.
*
*/
#include <dash/dart/if/dart_util.h>
#include <dash/dart/if/dart_types.h>
#ifdef __cplusplus
extern "C" {
#endif
/** \cond DART_HIDDEN_SYMBOLS */
#define DART_INTERFACE_ON
/** \endcond */
/*
--- DART global pointers ---
There are multiple options for representing the global
pointer that come to mind:
1) struct with pre-defined members (say, unit id
and local address)
2) an opaque object that leaves the details to a specific
implementation and is manipulated only through pointers
3) a fixed size integer data type (say 64 bit or 128 bit),
manipulated through c macros that packs all the
relevant information
There are pros and cons to each option...
Another question is that of offsets vs. addresses: Either a local
virtual address is directly included and one in which the pointer
holds something like a segment ID and an offset within that segment.
If we want to support virtual addresses then 64 bits is not enough to
represent the pointer. If we only support segment offsets, 64 bit
could be sufficient
Yet another question is what kind of operations are supported on
global pointers. For example UPC global pointers keep "phase"
information that allows pointer arithmetic (the phase is needed for
knowing when you have to move to the next node).
PROPOSAL: Don't include phase information with pointers on the DART
level, but don't preclude support the same concept on the DASH level.
*/
/*
PROPOSAL: use 128 bit global pointers with the following layout:
0 1 2 3 4 5 6 7
0123456701234567012345670123456701234567012345670123456701234567
|----<24 bit unit id>---|-flags-|-<segment id>--|---<team id>--|
|-----------<64 bit virtual address or offset>-----------------|
*/
/**
* DART Global pointer type.
*
* \ingroup DartGlobMem
*/
typedef struct
{
/**
* The unit holding the memory element.
* The ID is relative to the team identified by \c teamid.
*/
dart_unit_t unitid : 24;
/** Reserved */
unsigned int flags : 8;
/** The segment ID of the allocation. */
int16_t segid;
/** The team associated with the allocation. */
int16_t teamid;
/** Absolute address or relative offset. */
union
{
uint64_t offset;
void* addr;
} addr_or_offs;
} dart_gptr_t;
/**
* A NULL global pointer
* \ingroup DartGlobMem
*/
#ifdef __cplusplus
#define DART_GPTR_NULL (dart_gptr_t { -1, 0, 0, DART_TEAM_NULL, { 0 } })
#else
#define DART_GPTR_NULL \
(dart_gptr_t){ .unitid = -1, \
.flags = 0, \
.segid = 0, \
.teamid = DART_TEAM_NULL, \
.addr_or_offs.offset = 0 }
#endif
/**
* Test for NULL global pointer
*
* \ingroup DartGlobMem
*/
#define DART_GPTR_ISNULL(gptr_) \
(gptr_.unitid<0 && gptr_.segid==0 && \
gptr_.teamid==DART_TEAM_NULL && \
gptr_.addr_or_offs.addr==0)
/**
* Compare two global pointers
*
* \ingroup DartGlobMem
*/
#define DART_GPTR_EQUAL(gptr1_, gptr2_ ) \
((gptr1_.unitid == gptr2_.unitid) && \
(gptr1_.segid == gptr2_.segid) && \
(gptr1_.teamid == gptr2_.teamid) && \
(gptr1_.addr_or_offs.offset == \
gptr2_.addr_or_offs.offset) )
/**
* Segment ID identifying unaligned allocations.
*
* \sa dart_memalloc
* \sa dart_memfree
*/
#define DART_SEGMENT_LOCAL ((int16_t)0)
/**
* Get the local memory address for the specified global pointer
* gptr. I.e., if the global pointer has affinity to the local unit,
* return the local memory address.
*
* \param gptr Global pointer
* \param[out] addr Pointer to a pointer that will hold the local
* address if the \c gptr points to a local memory element.
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe
* \ingroup DartGlobMem
*/
dart_ret_t dart_gptr_getaddr(
const dart_gptr_t gptr,
void ** addr) DART_NOTHROW;
/**
* Set the local memory address for the specified global pointer such
* the the specified address.
*
* \param gptr Global pointer
* \param addr Pointer holding the local address to set in \c gptr.
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe
* \ingroup DartGlobMem
*/
dart_ret_t dart_gptr_setaddr(
dart_gptr_t * gptr,
void * addr) DART_NOTHROW;
/**
* Add 'offs' to the address specified by the global pointer
*
* \param gptr Global pointer
* \param offs Offset by which to increment \c gptr
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe
* \ingroup DartGlobMem
*/
DART_INLINE DART_NOTHROW
dart_ret_t
dart_gptr_incaddr(
dart_gptr_t * gptr,
int64_t offs)
{
gptr->addr_or_offs.offset += offs;
return DART_OK;
}
/**
* Set the unit information for the specified global pointer.
*
* \param gptr Global Pointer
* \param unit The global unit to set in \c gptr
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe
* \ingroup DartGlobMem
*/
DART_INLINE DART_NOTHROW
dart_ret_t dart_gptr_setunit(
dart_gptr_t * gptr,
dart_team_unit_t unit)
{
gptr->unitid = unit.id;
return DART_OK;
}
/**
* Get the flags field for the segment specified by the global pointer.
*
* \param gptr Global Pointer describing a segment.
* \param flags The flags to get for segment in \c gptr
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe
* \ingroup DartGlobMem
*/
dart_ret_t dart_gptr_getflags(
dart_gptr_t gptr,
uint16_t * flags) DART_NOTHROW;
/**
* Set the flags field for the segment specified by the global pointer.
* The flags are stored in the segment's meta data. The lower 8 bit of
* the flags are stored in the \c .flags field of the \c gptr for
* fast access. The remaining flags can be queried through
* \ref dart_gptr_getflags.
*
* \param gptr Global Pointer describing a segment.
* \param flags The flags to set for segment in \c gptr
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe
* \ingroup DartGlobMem
*/
dart_ret_t dart_gptr_setflags(
dart_gptr_t * gptr,
uint16_t flags) DART_NOTHROW;
/**
* Allocates memory for \c nelem elements of type \c dtype in the global
* address space of the calling unit and returns a global pointer to it.
* This is *not* a collective function.
*
* \param nelem The number of elements of type \c dtype to allocate.
* \param dtype The type to use.
* \param[out] gptr Global Pointer to hold the allocation
*
* \todo Does dart_memalloc really allocate in _global_ memory?
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe
* \ingroup DartGlobMem
*/
dart_ret_t dart_memalloc(
size_t nelem,
dart_datatype_t dtype,
dart_gptr_t * gptr) DART_NOTHROW;
/**
* Frees memory in the global address space allocated by a previous call
* of \ref dart_memalloc.
* This is *not* a collective function.
*
* \param gptr Global pointer to the memory allocation to free
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe
* \ingroup DartGlobMem
*/
dart_ret_t dart_memfree(dart_gptr_t gptr) DART_NOTHROW;
/**
* Collective function on the specified team to allocate \c nelem elements
* of type \c dtype of memory in each unit's global address space with a
* local displacement of the specified type.
* The allocated memory is team-aligned, i.e., a global pointer to
* anywhere in the allocation can easily be formed locally. The global
* pointer to the beginning of the allocation is returned in \c gptr on
* each participating unit. Each participating unit has to call
* \c dart_team_memalloc_aligned with the same specification of \c teamid,
* \c dtype and \c nelem.
* Each unit will receive the a global pointer to the beginning
* of the allocation (on unit 0) in \c gptr.
* Accessibility of memory allocated with this function is limited to
* those units that are part of the team allocating the memory. I.e.,
* if unit X was not part of the team that allocated the memory M, then
* X may not be able to access a memory location in M.
*
* \param teamid The team participating in the collective memory
* allocation.
* \param nelem The number of elements to allocate per unit.
* \param dtype The data type of elements in \c addr.
*
* \param[out] gptr Global pointer to store information on the allocation.
*
* \return \c DART_OK on success,
* any other of \ref dart_ret_t otherwise.
*
* \threadsafe_data{team}
* \ingroup DartGlobMem
*/
dart_ret_t dart_team_memalloc_aligned(
dart_team_t teamid,
size_t nelem,
dart_datatype_t dtype,
dart_gptr_t * gptr) DART_NOTHROW;
/**
* Collective function to free global memory previously allocated
* using \ref dart_team_memalloc_aligned.
* After this operation, the global pointer should not be used in any
* communication unless re-used in another allocation.
* After this operation, the global pointer can be reset using
* \ref DART_GPTR_NULL.
*
* \param gptr Global pointer pointing to the memory to deallocate.
*
* \see DART_GPTR_NULL
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe_data{team}
* \ingroup DartGlobMem
*/
dart_ret_t dart_team_memfree(
dart_gptr_t gptr) DART_NOTHROW;
/**
* Collective function similar to \ref dart_team_memalloc_aligned but on
* previously externally allocated memory.
* Does not perform any memory allocation.
*
* \param teamid The team to participate in the collective operation.
* \param nelem The number of elements already allocated in \c addr.
* \param dtype The data type of elements in \c addr.
* \param addr Pointer to pre-allocated memory to be registered.
* \param gptr Pointer to a global pointer object to set up.
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \see dart_team_memalloc_aligned
*
* \threadsafe_data{team}
* \ingroup DartGlobMem
*/
dart_ret_t dart_team_memregister_aligned(
dart_team_t teamid,
size_t nelem,
dart_datatype_t dtype,
void * addr,
dart_gptr_t * gptr) DART_NOTHROW;
/**
* Collective function, attaches external memory previously allocated by
* the user.
* Does not perform any memory allocation.
*
* \param teamid The team to participate in the collective operation.
* \param nlelem The number of local elements allocated in \c addr to
* attach.
* \param dtype The data type of elements in \c addr.
* \param addr Pointer to pre-allocated memory to be registered.
* \param gptr Pointer to a global pointer object to set up.
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \threadsafe_none
* \ingroup DartGlobMem
*/
dart_ret_t dart_team_memregister(
dart_team_t teamid,
size_t nlelem,
dart_datatype_t dtype,
void * addr,
dart_gptr_t * gptr) DART_NOTHROW;
/**
* Collective function similar to dart_team_memfree() but on previously
* externally allocated memory.
* Does not de-allocate memory.
*
* \param gptr Pointer to a global pointer object to set up.
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
* \see dart_team_memregister
* \see dart_team_memregister_aligned
*
* \threadsafe_none
* \ingroup DartGlobMem
*/
dart_ret_t dart_team_memderegister(dart_gptr_t gptr) DART_NOTHROW;
/** \cond DART_HIDDEN_SYMBOLS */
#define DART_INTERFACE_OFF
/** \endcond */
#ifdef __cplusplus
}
#endif
#endif /* DART_GLOBMEM_H_INCLUDED */