Browse Source

gcc: In task submission, pass raw pointers to `starpu_insert_task'.

* gcc-plugin/src/starpu.c (build_task_submission): Pass raw pointers.

* gcc-plugin/tests/Makefile.am (check_PROGRAMS): Add `pointers'.

* gcc-plugin/tests/lib.h (starpu_insert_task): Check pointer arguments.
  (starpu_data_lookup, starpu_handle_get_local_ptr): New functions.

* gcc-plugin/tests/pointers.c: New file.
Ludovic Courtès 14 years ago
parent
commit
1e153b7a83
4 changed files with 121 additions and 10 deletions
  1. 8 1
      gcc-plugin/src/starpu.c
  2. 4 1
      gcc-plugin/tests/Makefile.am
  3. 38 8
      gcc-plugin/tests/lib.h
  4. 71 0
      gcc-plugin/tests/pointers.c

+ 8 - 1
gcc-plugin/src/starpu.c

@@ -956,7 +956,14 @@ build_task_submission (tree task_decl, gimple call)
 	{
 	  /* A pointer: the arguments will be:
 	     `STARPU_RW, ptr' or similar.  */
-	  gcc_assert (!"not implemented yet");
+
+	  gcc_assert (TREE_CODE (arg) == VAR_DECL
+		      || TREE_CODE (arg) == ADDR_EXPR);
+
+	  VEC_safe_push (tree, heap, args,
+			 build_int_cst (integer_type_node, STARPU_RW));
+	  VEC_safe_push (tree, heap, args, arg);
+	  /* FIXME: Should pass the result of `starpu_data_lookup (ARG)'.  */
 	}
       else
 	{

+ 4 - 1
gcc-plugin/tests/Makefile.am

@@ -16,7 +16,10 @@
 
 TESTS = $(check_PROGRAMS)
 
-check_PROGRAMS = base scalar-tasks
+check_PROGRAMS =				\
+  base						\
+  pointers					\
+  scalar-tasks
 
 scalar_tasks_LDADD = $(top_builddir)/src/libstarpu.la
 

+ 38 - 8
gcc-plugin/tests/lib.h

@@ -70,17 +70,35 @@ starpu_insert_task (starpu_codelet *cl, ...)
        expected++)
     {
       int type;
-      void *arg;
-      size_t size;
 
       type = va_arg (args, int);
-      arg = va_arg (args, void *);
-      size = va_arg (args, size_t);
-
       assert (type == expected->type);
-      assert (size == expected->size);
-      assert (arg != NULL);
-      assert (!memcmp (arg, expected->pointer, size));
+
+      switch (type)
+	{
+	case STARPU_VALUE:
+	  {
+	    void *arg;
+	    size_t size;
+
+	    arg = va_arg (args, void *);
+	    size = va_arg (args, size_t);
+
+	    assert (size == expected->size);
+	    assert (arg != NULL);
+	    assert (!memcmp (arg, expected->pointer, size));
+	    break;
+	  }
+
+	case STARPU_RW:
+	case STARPU_R:
+	case STARPU_W:
+	  assert (va_arg (args, void *) == expected->pointer);
+	  break;
+
+	default:
+	  abort ();
+	}
     }
 
   va_end (args);
@@ -121,3 +139,15 @@ starpu_unpack_cl_args (void *cl_raw_arg, ...)
 
   va_end (args);
 }
+
+starpu_data_handle
+starpu_data_lookup (const void *ptr)
+{
+  return (starpu_data_handle) ptr;
+}
+
+void *
+starpu_handle_get_local_ptr (starpu_data_handle handle)
+{
+  return handle;
+}

+ 71 - 0
gcc-plugin/tests/pointers.c

@@ -0,0 +1,71 @@
+/* GCC-StarPU
+   Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
+
+   GCC-StarPU is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   GCC-StarPU is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC-StarPU.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#undef NDEBUG
+
+#include <lib.h>
+
+
+/* The task under test.  */
+
+static void my_pointer_task (int *x, long long *y) __attribute__ ((task));
+
+static void my_pointer_task_cpu (int *, long long *)
+  __attribute__ ((task_implementation ("cpu", my_pointer_task)));
+static void my_pointer_task_opencl (int *, long long *)
+  __attribute__ ((task_implementation ("opencl", my_pointer_task)));
+
+static void
+my_pointer_task_cpu (int *x, long long *y)
+{
+  printf ("%s: x = %p, y = %p\n", __func__, x, y);
+}
+
+static void
+my_pointer_task_opencl (int *x, long long *y)
+{
+  printf ("%s: x = %p, y = %p\n", __func__, x, y);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  int x[] = { 42 };
+  long long *y;
+
+  y = malloc (sizeof *y);
+  *y = 77;
+
+  struct insert_task_argument expected[] =
+    {
+      { STARPU_RW, x },
+      { STARPU_RW, y },
+      { 0, 0, 0 }
+    };
+
+  expected_insert_task_arguments = expected;
+
+  /* Invoke the task, which should make sure it gets called with
+     EXPECTED.  */
+  my_pointer_task (x, y);
+
+  assert (tasks_submitted == 1);
+
+  free (y);
+
+  return EXIT_SUCCESS;
+}