DASH  0.3.0
dart_globmem.h
Go to the documentation of this file.
1 #ifndef DART_GLOBMEM_H_INCLUDED
2 #define DART_GLOBMEM_H_INCLUDED
3 
15 #include <dash/dart/if/dart_util.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
24 #define DART_INTERFACE_ON
25 
27 /*
28  --- DART global pointers ---
29 
30  There are multiple options for representing the global
31  pointer that come to mind:
32 
33  1) struct with pre-defined members (say, unit id
34  and local address)
35  2) an opaque object that leaves the details to a specific
36  implementation and is manipulated only through pointers
37  3) a fixed size integer data type (say 64 bit or 128 bit),
38  manipulated through c macros that packs all the
39  relevant information
40 
41  There are pros and cons to each option...
42 
43  Another question is that of offsets vs. addresses: Either a local
44  virtual address is directly included and one in which the pointer
45  holds something like a segment ID and an offset within that segment.
46 
47  If we want to support virtual addresses then 64 bits is not enough to
48  represent the pointer. If we only support segment offsets, 64 bit
49  could be sufficient
50 
51  Yet another question is what kind of operations are supported on
52  global pointers. For example UPC global pointers keep "phase"
53  information that allows pointer arithmetic (the phase is needed for
54  knowing when you have to move to the next node).
55 
56  PROPOSAL: Don't include phase information with pointers on the DART
57  level, but don't preclude support the same concept on the DASH level.
58 
59  */
60 
61  /*
62  PROPOSAL: use 128 bit global pointers with the following layout:
63 
64 
65  0 1 2 3 4 5 6 7
66  0123456701234567012345670123456701234567012345670123456701234567
67  |----<24 bit unit id>---|-flags-|-<segment id>--|---<team id>--|
68  |-----------<64 bit virtual address or offset>-----------------|
69 
70  */
71 
77 typedef struct
78 {
85  unsigned int flags : 8;
87  int16_t segid;
89  int16_t teamid;
91  union
92  {
93  uint64_t offset;
94  void* addr;
95  } addr_or_offs;
96 } dart_gptr_t;
97 
102 #ifdef __cplusplus
103 #define DART_GPTR_NULL (dart_gptr_t { -1, 0, 0, DART_TEAM_NULL, { 0 } })
104 #else
105 #define DART_GPTR_NULL \
106 (dart_gptr_t){ .unitid = -1, \
107  .flags = 0, \
108  .segid = 0, \
109  .teamid = DART_TEAM_NULL, \
110  .addr_or_offs.offset = 0 }
111 #endif
112 
118 #define DART_GPTR_ISNULL(gptr_) \
119  (gptr_.unitid<0 && gptr_.segid==0 && \
120  gptr_.teamid==DART_TEAM_NULL && \
121  gptr_.addr_or_offs.addr==0)
122 
128 #define DART_GPTR_EQUAL(gptr1_, gptr2_ ) \
129  ((gptr1_.unitid == gptr2_.unitid) && \
130  (gptr1_.segid == gptr2_.segid) && \
131  (gptr1_.teamid == gptr2_.teamid) && \
132  (gptr1_.addr_or_offs.offset == \
133  gptr2_.addr_or_offs.offset) )
134 
135 
142 #define DART_SEGMENT_LOCAL ((int16_t)0)
143 
144 
160  const dart_gptr_t gptr,
161  void ** addr) DART_NOTHROW;
162 
176  dart_gptr_t * gptr,
177  void * addr) DART_NOTHROW;
178 
190 DART_INLINE DART_NOTHROW
192 dart_gptr_incaddr(
193  dart_gptr_t * gptr,
194  int64_t offs)
195 {
196  gptr->addr_or_offs.offset += offs;
197  return DART_OK;
198 }
199 
211 DART_INLINE DART_NOTHROW
212 dart_ret_t dart_gptr_setunit(
213  dart_gptr_t * gptr,
214  dart_team_unit_t unit)
215 {
216  gptr->unitid = unit.id;
217  return DART_OK;
218 }
219 
232  dart_gptr_t gptr,
233  uint16_t * flags) DART_NOTHROW;
234 
235 
252  dart_gptr_t * gptr,
253  uint16_t flags) DART_NOTHROW;
254 
265 typedef struct dart_allocator_struct * dart_allocator_t;
266 
288  size_t pool_size,
289  dart_team_t team,
290  dart_allocator_t * new_allocator);
291 
310  size_t nelem,
311  dart_datatype_t dtype,
312  dart_gptr_t * gptr,
313  dart_allocator_t allocator);
314 
329  dart_gptr_t * gptr,
330  dart_allocator_t allocator);
331 
343 dart_ret_t dart_allocator_destroy(dart_allocator_t *allocator);
344 
362  size_t nelem,
363  dart_datatype_t dtype,
364  dart_gptr_t * gptr) DART_NOTHROW;
365 
378 dart_ret_t dart_memfree(dart_gptr_t gptr) DART_NOTHROW;
379 
411  dart_team_t teamid,
412  size_t nelem,
413  dart_datatype_t dtype,
414  dart_gptr_t * gptr) DART_NOTHROW;
415 
434  dart_gptr_t gptr) DART_NOTHROW;
435 
455  dart_team_t teamid,
456  size_t nelem,
457  dart_datatype_t dtype,
458  void * addr,
459  dart_gptr_t * gptr) DART_NOTHROW;
460 
479  dart_team_t teamid,
480  size_t nlelem,
481  dart_datatype_t dtype,
482  void * addr,
483  dart_gptr_t * gptr) DART_NOTHROW;
484 
501 
502 
504 #define DART_INTERFACE_OFF
505 
507 #ifdef __cplusplus
508 }
509 #endif
510 
511 #endif /* DART_GLOBMEM_H_INCLUDED */
512 
dart_ret_t dart_team_memregister(dart_team_t teamid, size_t nlelem, dart_datatype_t dtype, void *addr, dart_gptr_t *gptr)
Collective function, attaches external memory previously allocated by the user.
int16_t teamid
The team associated with the allocation.
Definition: dart_globmem.h:89
Signals success.
Definition: dart_types.h:33
union dart_gptr_t::@0 addr_or_offs
Absolute address or relative offset.
dart_ret_t dart_gptr_setflags(dart_gptr_t *gptr, uint16_t flags)
Set the flags field for the segment specified by the global pointer.
intptr_t dart_datatype_t
Raw data types supported by the DART interface.
Definition: dart_types.h:121
int32_t dart_unit_t
Data type for storing a unit ID.
Definition: dart_types.h:154
dart_ret_t dart_memfree(dart_gptr_t gptr)
Frees memory in the global address space allocated by a previous call of dart_memalloc.
dart_ret_t dart_memalloc(size_t nelem, dart_datatype_t dtype, dart_gptr_t *gptr)
Allocates memory for nelem elements of type dtype in the global address space of the calling unit and...
dart_unit_t unitid
The unit holding the memory element.
Definition: dart_globmem.h:83
dart_ret_t dart_allocator_free(dart_gptr_t *gptr, dart_allocator_t allocator)
Free memory allocated through dart_allocator_alloc.
Data type for storing a unit ID relative to a team.
Definition: dart_types.h:180
dart_ret_t dart_allocator_alloc(size_t nelem, dart_datatype_t dtype, dart_gptr_t *gptr, dart_allocator_t allocator)
Allocate global memory from a DART allocator instance created using dart_allocator_new.
dart_ret_t dart_allocator_new(size_t pool_size, dart_team_t team, dart_allocator_t *new_allocator)
Create a new allocator for non-collective global memory allocations.
dart_ret_t dart_team_memfree(dart_gptr_t gptr)
Collective function to free global memory previously allocated using dart_team_memalloc_aligned.
DART Global pointer type.
Definition: dart_globmem.h:77
dart_ret_t dart_gptr_getflags(dart_gptr_t gptr, uint16_t *flags)
Get the flags field for the segment specified by the global pointer.
dart_ret_t dart_gptr_getaddr(const dart_gptr_t gptr, void **addr)
Get the local memory address for the specified global pointer gptr.
int16_t segid
The segment ID of the allocation.
Definition: dart_globmem.h:87
dart_ret_t
Return values of functions in the DART interface.
Definition: dart_types.h:30
int16_t dart_team_t
Data type for storing a team ID.
Definition: dart_types.h:252
dart_ret_t dart_team_memderegister(dart_gptr_t gptr)
Collective function similar to dart_team_memfree() but on previously externally allocated memory...
struct dart_allocator_struct * dart_allocator_t
DART allocator used for non-collective global memory allocations using dart_allocator_alloc similar t...
Definition: dart_globmem.h:265
dart_ret_t dart_gptr_setaddr(dart_gptr_t *gptr, void *addr)
Set the local memory address for the specified global pointer such the the specified address...
dart_ret_t dart_team_memalloc_aligned(dart_team_t teamid, size_t nelem, dart_datatype_t dtype, dart_gptr_t *gptr)
Collective function on the specified team to allocate nelem elements of type dtype of memory in each ...
dart_ret_t dart_allocator_destroy(dart_allocator_t *allocator)
Destroy an allocator created through dart_allocator_new.
unsigned int flags
Reserved.
Definition: dart_globmem.h:85
dart_ret_t dart_team_memregister_aligned(dart_team_t teamid, size_t nelem, dart_datatype_t dtype, void *addr, dart_gptr_t *gptr)
Collective function similar to dart_team_memalloc_aligned but on previously externally allocated memo...