I forgot to attach the patch.
Tobias Burnus wrote:
Hi all,
I have committed the attached patch to the Fortran-CAF branch. It
paves the road to CAF sending support by declaring caf_send - and
implementing it in libcaf_single.c (as memmove). Additionally, I
cleaned up the library by handling the token in a better way (more
readable - and permitting a cleaner implementation in the
implementation part). Additionally, it includes some fixes to my
recent branch patch.
The next step will be to add real sending support in the *compiler*,
for which I have a draft patch. Adding send support to the library is
a separate task and will be done by someone else.
Committed after building and regtesting on x86-64-gnu-linux as Rev.
208580.
Tobias
Index: libgfortran/ChangeLog.fortran-caf
===================================================================
--- libgfortran/ChangeLog.fortran-caf (Revision 208554)
+++ libgfortran/ChangeLog.fortran-caf (Arbeitskopie)
@@ -1,3 +1,17 @@
+2014-03-14 Tobias Burnus <bur...@net-b.de>
+
+ * caf/libcaf.h (caf_token_t): New typedef.
+ (caf_static_t, _gfortran_caf_register, _gfortran_caf_deregister):
+ Use it.
+ (_gfortran_send): New.
+ * caf/mpi.c (mpi_token_t, TOKEN): New.
+ (_gfortran_caf_register, _gfortran_caf_deregister): Update.
+ (_gfortran_caf_init): Fix prototype.
+ (_gfortran_caf_send): New stub implementation.
+ * caf/single.c (single_token_t, TOKEN): New.
+ (_gfortran_caf_register, _gfortran_caf_deregister): Update.
+ (_gfortran_caf_send): New; implement it.
+
2014-03-08 Tobias Burnus <bur...@net-b.de>
* caf/libcaf.h (_gfortran_caf_this_image, _gfortran_caf_num_images):
Index: libgfortran/caf/libcaf.h
===================================================================
--- libgfortran/caf/libcaf.h (Revision 208554)
+++ libgfortran/caf/libcaf.h (Arbeitskopie)
@@ -28,6 +28,7 @@
#include <stdint.h> /* For int32_t. */
#include <stddef.h> /* For size_t. */
+#include <stdbool.h>
#ifndef __GNUC__
#define __attribute__(x)
@@ -55,9 +56,11 @@
}
caf_register_t;
+typedef void* caf_token_t;
+
/* Linked list of static coarrays registered. */
typedef struct caf_static_t {
- void **token;
+ caf_token_t token;
struct caf_static_t *prev;
}
caf_static_t;
@@ -69,10 +72,11 @@
int _gfortran_caf_this_image (int);
int _gfortran_caf_num_images (int, int);
-void * _gfortran_caf_register (size_t, caf_register_t, void ***, int *,
- char *, int);
-void _gfortran_caf_deregister (void ***, int *, char *, int);
+void *_gfortran_caf_register (size_t, caf_register_t, caf_token_t *, int *,
+ char *, int);
+void _gfortran_caf_deregister (caf_token_t *, int *, char *, int);
+void _gfortran_send (caf_token_t, size_t, int, void *, size_t, bool);
void _gfortran_caf_sync_all (int *, char *, int);
void _gfortran_caf_sync_images (int, int[], int *, char *, int);
Index: libgfortran/caf/mpi.c
===================================================================
--- libgfortran/caf/mpi.c (Revision 208554)
+++ libgfortran/caf/mpi.c (Arbeitskopie)
@@ -34,6 +34,8 @@
/* Define GFC_CAF_CHECK to enable run-time checking. */
/* #define GFC_CAF_CHECK 1 */
+typedef void ** mpi_token_t;
+#define TOKEN(X) ((mpi_token_t) (X))
static void error_stop (int error) __attribute__ ((noreturn));
@@ -73,7 +75,7 @@
libaray is initialized. */
void
-_gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images)
+_gfortran_caf_init (int *argc, char ***argv)
{
if (caf_num_images == 0)
{
@@ -99,8 +101,8 @@
{
caf_static_t *tmp = caf_static_list->prev;
- free (caf_static_list->token[caf_this_image-1]);
- free (caf_static_list->token);
+ free (TOKEN(caf_static_list->token)[caf_this_image-1]);
+ free (TOKEN(caf_static_list->token));
free (caf_static_list);
caf_static_list = tmp;
}
@@ -128,7 +130,7 @@
void *
-_gfortran_caf_register (size_t size, caf_register_t type, void ***token,
+_gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token,
int *stat, char *errmsg, int errmsg_len)
{
void *local;
@@ -139,17 +141,17 @@
/* Start MPI if not already started. */
if (caf_num_images == 0)
- _gfortran_caf_init (NULL, NULL, NULL, NULL);
+ _gfortran_caf_init (NULL, NULL);
/* Token contains only a list of pointers. */
local = malloc (size);
- *token = malloc (sizeof (void*) * caf_num_images);
+ *token = malloc (sizeof (mpi_token_t) * caf_num_images);
if (unlikely (local == NULL || *token == NULL))
goto error;
/* token[img-1] is the address of the token in image "img". */
- err = MPI_Allgather (&local, sizeof (void*), MPI_BYTE, *token,
+ err = MPI_Allgather (&local, sizeof (void*), MPI_BYTE, TOKEN(*token),
sizeof (void*), MPI_BYTE, MPI_COMM_WORLD);
if (unlikely (err))
@@ -202,7 +204,7 @@
void
-_gfortran_caf_deregister (void ***token, int *stat, char *errmsg, int errmsg_len)
+_gfortran_caf_deregister (caf_token_t *token, int *stat, char *errmsg, int errmsg_len)
{
if (unlikely (caf_is_finalized))
{
@@ -230,11 +232,22 @@
if (stat)
*stat = 0;
- free ((*token)[caf_this_image-1]);
+ free (TOKEN(*token)[caf_this_image-1]);
free (*token);
}
+void
+_gfortran_caf_send (caf_token_t token __attribute__ ((unused)),
+ size_t offset __attribute__ ((unused)),
+ int image_id __attribute__ ((unused)),
+ void *buffer __attribute__ ((unused)),
+ size_t size __attribute__ ((unused)),
+ bool asyn __attribute__ ((unused)))
+{
+ /* FIXME: Not yet implemented. */
+}
+
void
_gfortran_caf_sync_all (int *stat, char *errmsg, int errmsg_len)
{
Index: libgfortran/caf/single.c
===================================================================
--- libgfortran/caf/single.c (Revision 208554)
+++ libgfortran/caf/single.c (Arbeitskopie)
@@ -32,6 +32,9 @@
/* Define GFC_CAF_CHECK to enable run-time checking. */
/* #define GFC_CAF_CHECK 1 */
+typedef void* single_token_t;
+#define TOKEN(X) ((single_token_t) (X))
+
/* Single-image implementation of the CAF library.
Note: For performance reasons -fcoarry=single should be used
rather than this library. */
@@ -68,7 +71,6 @@
while (caf_static_list != NULL)
{
caf_static_t *tmp = caf_static_list->prev;
- free (caf_static_list->token[0]);
free (caf_static_list->token);
free (caf_static_list);
caf_static_list = tmp;
@@ -92,14 +94,13 @@
void *
-_gfortran_caf_register (size_t size, caf_register_t type, void ***token,
+_gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token,
int *stat, char *errmsg, int errmsg_len)
{
void *local;
local = malloc (size);
- *token = malloc (sizeof (void*) * 1);
- (*token)[0] = local;
+ *token = malloc (sizeof (single_token_t));
if (unlikely (local == NULL || token == NULL))
{
@@ -121,6 +122,8 @@
caf_runtime_error (msg);
}
+ *token = local;
+
if (stat)
*stat = 0;
@@ -136,12 +139,11 @@
void
-_gfortran_caf_deregister (void ***token, int *stat,
+_gfortran_caf_deregister (caf_token_t *token, int *stat,
char *errmsg __attribute__ ((unused)),
int errmsg_len __attribute__ ((unused)))
{
- free ((*token)[0]);
- free (*token);
+ free (TOKEN(*token));
if (stat)
*stat = 0;
@@ -149,6 +151,17 @@
void
+_gfortran_caf_send (caf_token_t token, size_t offset,
+ int image_id __attribute__ ((unused)),
+ void *buffer, size_t size,
+ bool asyn __attribute__ ((unused)))
+{
+ void *dest = (void *)((char *) TOKEN(token) + offset);
+ memmove (dest, buffer, size);
+}
+
+
+void
_gfortran_caf_sync_all (int *stat,
char *errmsg __attribute__ ((unused)),
int errmsg_len __attribute__ ((unused)))
Index: gcc/fortran/ChangeLog.fortran-caf
===================================================================
--- gcc/fortran/ChangeLog.fortran-caf (Revision 208554)
+++ gcc/fortran/ChangeLog.fortran-caf (Arbeitskopie)
@@ -1,3 +1,14 @@
+2014-03-14 Tobias Burnus <bur...@net-b.de>
+
+ * trans.h (gfc_get_tree_for_caf_expr): Add prototype.
+ (gfor_fndecl_caf_send): Declare.
+ * trans-decl.c (gfor_fndecl_caf_send): Add.
+ (gfc_build_builtin_function_decls): Fix caf_num_image
+ decl bug. Build decl for gfor_fndecl_caf_send.
+ * trans-expr.c (gfc_get_tree_for_caf_expr): Renamed from
+ get_tree_for_caf_expr and made nonstatic.
+ (gfc_conv_procedure_call): Update call.
+
2014-03-08 Tobias Burnus <bur...@net-b.de>
* gfortran.h (gfc_init_coarray_decl): Remove.
Index: gcc/fortran/trans.h
===================================================================
--- gcc/fortran/trans.h (Revision 208554)
+++ gcc/fortran/trans.h (Arbeitskopie)
@@ -412,6 +412,7 @@
/* trans-expr.c */
void gfc_conv_scalar_char_value (gfc_symbol *sym, gfc_se *se, gfc_expr **expr);
tree gfc_string_to_single_character (tree len, tree str, int kind);
+tree gfc_get_tree_for_caf_expr (gfc_expr *);
/* Find the decl containing the auxiliary variables for assigned variables. */
void gfc_conv_label_variable (gfc_se * se, gfc_expr * expr);
@@ -698,6 +699,7 @@
extern GTY(()) tree gfor_fndecl_caf_num_images;
extern GTY(()) tree gfor_fndecl_caf_register;
extern GTY(()) tree gfor_fndecl_caf_deregister;
+extern GTY(()) tree gfor_fndecl_caf_send;
extern GTY(()) tree gfor_fndecl_caf_critical;
extern GTY(()) tree gfor_fndecl_caf_end_critical;
extern GTY(()) tree gfor_fndecl_caf_sync_all;
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c (Revision 208554)
+++ gcc/fortran/trans-decl.c (Arbeitskopie)
@@ -125,6 +125,7 @@
tree gfor_fndecl_caf_num_images;
tree gfor_fndecl_caf_register;
tree gfor_fndecl_caf_deregister;
+tree gfor_fndecl_caf_send;
tree gfor_fndecl_caf_critical;
tree gfor_fndecl_caf_end_critical;
tree gfor_fndecl_caf_sync_all;
@@ -3249,7 +3250,7 @@
1, integer_type_node);
gfor_fndecl_caf_num_images = gfc_build_library_function_decl (
- get_identifier (PREFIX("caf_this_image")), integer_type_node,
+ get_identifier (PREFIX("caf_num_images")), integer_type_node,
2, integer_type_node, boolean_type_node);
gfor_fndecl_caf_register = gfc_build_library_function_decl_with_spec (
@@ -3261,6 +3262,11 @@
get_identifier (PREFIX("caf_deregister")), ".WWW", void_type_node, 4,
ppvoid_type_node, pint_type, pchar_type_node, integer_type_node);
+ gfor_fndecl_caf_send = gfc_build_library_function_decl_with_spec (
+ get_identifier (PREFIX("caf_send")), "R..R..", void_type_node, 6,
+ ppvoid_type_node, size_type_node, integer_type_node, pvoid_type_node,
+ size_type_node, boolean_type_node);
+
gfor_fndecl_caf_critical = gfc_build_library_function_decl (
get_identifier (PREFIX("caf_critical")), void_type_node, 0);
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c (Revision 208554)
+++ gcc/fortran/trans-expr.c (Arbeitskopie)
@@ -1377,8 +1377,8 @@
/* Return for an expression the backend decl of the coarray. */
-static tree
-get_tree_for_caf_expr (gfc_expr *expr)
+tree
+gfc_get_tree_for_caf_expr (gfc_expr *expr)
{
tree caf_decl = NULL_TREE;
gfc_ref *ref;
@@ -4775,7 +4775,7 @@
tree caf_decl, caf_type;
tree offset, tmp2;
- caf_decl = get_tree_for_caf_expr (e);
+ caf_decl = gfc_get_tree_for_caf_expr (e);
caf_type = TREE_TYPE (caf_decl);
if (GFC_DESCRIPTOR_TYPE_P (caf_type)