Skip to content

Commit 55712ab

Browse files
vehrezbeekman
authored andcommitted
Fixes to support gcc-7's caf-interface.
1 parent f6a091c commit 55712ab

File tree

2 files changed

+172
-11
lines changed

2 files changed

+172
-11
lines changed

src/libcaf.h

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,85 @@ typedef struct caf_vector_t {
101101
caf_vector_t;
102102

103103

104+
/* Keep in sync with gcc/libgfortran/caf/libcaf.h. */
105+
typedef enum caf_ref_type_t {
106+
/* Reference a component of a derived type, either regular one or an
107+
allocatable or pointer type. For regular ones idx in caf_reference_t is
108+
set to -1. */
109+
CAF_REF_COMPONENT,
110+
/* Reference an allocatable array. */
111+
CAF_REF_ARRAY,
112+
/* Reference a non-allocatable/non-pointer array. */
113+
CAF_REF_STATIC_ARRAY
114+
} caf_ref_type_t;
115+
116+
/* Keep in sync with gcc/libgfortran/caf/libcaf.h. */
117+
typedef enum caf_array_ref_t {
118+
/* No array ref. This terminates the array ref. */
119+
CAF_ARR_REF_NONE = 0,
120+
/* Reference array elements given by a vector. Only for this mode
121+
caf_reference_t.u.a.dim[i].v is valid. */
122+
CAF_ARR_REF_VECTOR,
123+
/* A full array ref (:). */
124+
CAF_ARR_REF_FULL,
125+
/* Reference a range on elements given by start, end and stride. */
126+
CAF_ARR_REF_RANGE,
127+
/* Only a single item is referenced given in the start member. */
128+
CAF_ARR_REF_SINGLE,
129+
/* An array ref of the kind (i:), where i is an arbitrary valid index in the
130+
array. The index i is given in the start member. */
131+
CAF_ARR_REF_OPEN_END,
132+
/* An array ref of the kind (:i), where the lower bound of the array ref
133+
is given by the remote side. The index i is given in the end member. */
134+
CAF_ARR_REF_OPEN_START
135+
} caf_array_ref_t;
136+
137+
/* References to remote components of a derived type.
138+
Keep in sync with gcc/libgfortran/caf/libcaf.h. */
139+
typedef struct caf_reference_t {
140+
/* A pointer to the next ref or NULL. */
141+
struct caf_reference_t *next;
142+
/* The type of the reference. */
143+
/* caf_ref_type_t, replaced by int to allow specification in fortran FE. */
144+
int type;
145+
/* The size of an item referenced in bytes. I.e. in an array ref this is
146+
the factor to advance the array pointer with to get to the next item.
147+
For component refs this gives just the size of the element referenced. */
148+
size_t item_size;
149+
union {
150+
struct {
151+
/* The offset (in bytes) of the component in the derived type. */
152+
ptrdiff_t offset;
153+
/* The offset (in bytes) to the caf_token associated with this
154+
component. NULL, when not allocatable/pointer ref. */
155+
ptrdiff_t caf_token_offset;
156+
} c;
157+
struct {
158+
/* The mode of the array ref. See CAF_ARR_REF_*. */
159+
/* caf_array_ref_t, replaced by unsigend char to allow specification in
160+
fortran FE. */
161+
unsigned char mode[GFC_MAX_DIMENSIONS];
162+
/* The type of a static array. Unset for array's with descriptors. */
163+
int static_array_type;
164+
/* Subscript refs (s) or vector refs (v). */
165+
union {
166+
struct {
167+
/* The start and end boundary of the ref and the stride. */
168+
ptrdiff_t start, end, stride;
169+
} s;
170+
struct {
171+
/* nvec entries of kind giving the elements to reference. */
172+
void *vector;
173+
/* The number of entries in vector. */
174+
size_t nvec;
175+
/* The integer kind used for the elements in vector. */
176+
int kind;
177+
} v;
178+
} dim[GFC_MAX_DIMENSIONS];
179+
} a;
180+
} u;
181+
} caf_reference_t;
182+
104183

105184
/* Common auxiliary functions: caf_auxiliary.c. */
106185

@@ -115,19 +194,32 @@ void PREFIX (finalize) (void);
115194
int PREFIX (this_image) (int);
116195
int PREFIX (num_images) (int, int);
117196

118-
void *PREFIX (register) (size_t, caf_register_t, caf_token_t *, int *, char *,
119-
int);
197+
void PREFIX (register) (size_t, caf_register_t, caf_token_t *,
198+
gfc_descriptor_t *, int *, char *, int);
120199
void PREFIX (deregister) (caf_token_t *, int *, char *, int);
121200

122201
void PREFIX (caf_get) (caf_token_t, size_t, int, gfc_descriptor_t *,
123-
caf_vector_t *, gfc_descriptor_t *, int, int);
202+
caf_vector_t *, gfc_descriptor_t *, int, int, int);
124203
void PREFIX (caf_send) (caf_token_t, size_t, int, gfc_descriptor_t *,
125204
caf_vector_t *, gfc_descriptor_t *, int, int);
126205

127206
void PREFIX (caf_sendget) (caf_token_t, size_t, int, gfc_descriptor_t *,
128207
caf_vector_t *, caf_token_t, size_t, int,
129208
gfc_descriptor_t *, caf_vector_t *, int, int);
130209

210+
void PREFIX(get_by_ref) (caf_token_t, int,
211+
gfc_descriptor_t *dst, caf_reference_t *refs,
212+
int dst_kind, int src_kind, bool may_require_tmp,
213+
bool dst_reallocatable, int *stat);
214+
void PREFIX(send_by_ref) (caf_token_t token, int image_index,
215+
gfc_descriptor_t *src, caf_reference_t *refs,
216+
int dst_kind, int src_kind, bool may_require_tmp,
217+
bool dst_reallocatable, int *stat);
218+
void PREFIX(sendget_by_ref) (caf_token_t dst_token, int dst_image_index,
219+
caf_reference_t *dst_refs, caf_token_t src_token, int src_image_index,
220+
caf_reference_t *src_refs, int dst_kind, int src_kind,
221+
bool may_require_tmp, int *dst_stat, int *src_stat);
222+
131223
void PREFIX (co_max) (gfc_descriptor_t *, int, int *, char *, int, int);
132224
void PREFIX (co_min) (gfc_descriptor_t *, int, int *, char *, int, int);
133225
void PREFIX (co_sum) (gfc_descriptor_t *, int, int *, char *, int);

src/mpi/mpi_caf.c

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void error_stop (int error) __attribute__ ((noreturn));
5454

5555
/* Global variables. */
5656
static int caf_this_image;
57-
static int caf_num_images;
57+
static int caf_num_images = 0;
5858
static int caf_is_finalized;
5959

6060
#if MPI_VERSION >= 3
@@ -466,13 +466,13 @@ PREFIX (num_images)(int distance __attribute__ ((unused)),
466466

467467

468468
#ifdef COMPILER_SUPPORTS_CAF_INTRINSICS
469-
void *
469+
void
470470
_gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token,
471-
int *stat, char *errmsg, int errmsg_len)
471+
gfc_descriptor_t *desc, int *stat, char *errmsg, int errmsg_len)
472472
#else
473-
void *
473+
void
474474
PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
475-
int *stat, char *errmsg, int errmsg_len)
475+
gfc_descriptor_t *desc, int *stat, char *errmsg, int errmsg_len)
476476
#endif
477477
{
478478
/* int ierr; */
@@ -553,7 +553,8 @@ void *
553553
if (stat)
554554
*stat = 0;
555555

556-
return mem;
556+
desc->base_addr = mem;
557+
return;
557558

558559
error:
559560
{
@@ -579,8 +580,6 @@ void *
579580
else
580581
caf_runtime_error (msg);
581582
}
582-
583-
return NULL;
584583
}
585584

586585

@@ -1596,6 +1595,76 @@ PREFIX (get) (caf_token_t token, size_t offset,
15961595
}
15971596

15981597

1598+
void
1599+
PREFIX(get_by_ref) (caf_token_t token, int image_idx,
1600+
gfc_descriptor_t *dst, caf_reference_t *refs,
1601+
int dst_kind, int src_kind, bool may_require_tmp,
1602+
bool dst_reallocatable, int *stat)
1603+
{
1604+
size_t offset = 0;
1605+
1606+
if (refs && refs->type == CAF_REF_COMPONENT)
1607+
{
1608+
offset = refs->u.c.offset;
1609+
refs = refs->next;
1610+
}
1611+
if (refs && refs->type == CAF_REF_ARRAY)
1612+
{
1613+
ptrdiff_t stride = 1;
1614+
for (int i = 0; refs->u.a.mode[i] != CAF_ARR_REF_NONE ; ++i)
1615+
{
1616+
switch (refs->u.a.mode[i])
1617+
{
1618+
case CAF_ARR_REF_FULL:
1619+
break;
1620+
case CAF_ARR_REF_RANGE:
1621+
case CAF_ARR_REF_SINGLE:
1622+
/* Hard code, that arrays start with lower_bound 1. */
1623+
offset += (refs->u.a.dim[i].s.start - 1) * stride
1624+
* refs->item_size;
1625+
break;
1626+
default:
1627+
fprintf (stderr, "COARRAY ERROR: caf_get_by_ref() CAF_ARR_REF not implemented yet ");
1628+
error_stop (1);
1629+
}
1630+
stride = dst->dim[i]._stride;
1631+
}
1632+
refs = refs->next;
1633+
}
1634+
if (!refs)
1635+
{
1636+
PREFIX (get) (token, offset, image_idx, dst, NULL, dst,
1637+
dst_kind, src_kind, may_require_tmp);
1638+
return;
1639+
}
1640+
1641+
fprintf (stderr, "COARRAY ERROR: caf_get_by_ref() not implemented yet ");
1642+
error_stop (1);
1643+
}
1644+
1645+
1646+
void
1647+
PREFIX(send_by_ref) (caf_token_t token, int image_index,
1648+
gfc_descriptor_t *src, caf_reference_t *refs,
1649+
int dst_kind, int src_kind, bool may_require_tmp,
1650+
bool dst_reallocatable, int *stat)
1651+
{
1652+
fprintf (stderr, "COARRAY ERROR: caf_send_by_ref() not implemented yet ");
1653+
error_stop (1);
1654+
}
1655+
1656+
1657+
void
1658+
PREFIX(sendget_by_ref) (caf_token_t dst_token, int dst_image_index,
1659+
caf_reference_t *dst_refs, caf_token_t src_token,
1660+
int src_image_index, caf_reference_t *src_refs,
1661+
int dst_kind, int src_kind,
1662+
bool may_require_tmp, int *dst_stat, int *src_stat)
1663+
{
1664+
fprintf (stderr, "COARRAY ERROR: caf_sendget_by_ref() not implemented yet ");
1665+
error_stop (1);
1666+
}
1667+
15991668
/* SYNC IMAGES. Note: SYNC IMAGES(*) is passed as count == -1 while
16001669
SYNC IMAGES([]) has count == 0. Note further that SYNC IMAGES(*)
16011670
is not equivalent to SYNC ALL. */

0 commit comments

Comments
 (0)