]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Do USM transform for omp_target_alloc
authorAndrew Stubbs <ams@codesourcery.com>
Fri, 1 Apr 2022 15:12:16 +0000 (16:12 +0100)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 28 Jun 2022 20:55:24 +0000 (13:55 -0700)
OpenMP 5.0 says that omp_target_alloc should return USM addresses.

gcc/ChangeLog:

* omp-low.cc (usm_transform): Transform omp_target_alloc and
omp_target_free.

libgomp/ChangeLog:

* testsuite/libgomp.c/usm-6.c: Add omp_target_alloc.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/usm-2.c: Add omp_target_alloc.
* c-c++-common/gomp/usm-3.c: Add omp_target_alloc.

gcc/ChangeLog.omp
gcc/omp-low.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/usm-2.c
gcc/testsuite/c-c++-common/gomp/usm-3.c
libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.c/usm-6.c

index c419396e16fac1b306cc5b9934583569e0567625..a98d8b3cfedebb47176c3cbc4a8fef0553d2f205 100644 (file)
@@ -1,3 +1,8 @@
+2022-04-02  Andrew Stubbs  <ams@codesourcery.com>
+
+       * omp-low.cc (usm_transform): Transform omp_target_alloc and
+       omp_target_free.
+
 2022-03-31  Abid Qadeer  <abidh@codesourcery.com>
 
        * omp-low.cc (lower_omp_allocate): Move allocate declaration
index 8685a0b6abc796398031ef9fc0f668a4d7611cd5..0734a4e9743623cc4311165e0e16b2b780d3046b 100644 (file)
@@ -16143,7 +16143,8 @@ usm_transform (gimple_stmt_iterator *gsi_p, bool *,
            if ((strcmp (name, "malloc") == 0)
                 || (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
                     && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MALLOC)
-                || DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl))
+                || DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl)
+                || strcmp (name, "omp_target_alloc") == 0)
              {
                  tree omp_alloc_type
                    = build_function_type_list (ptr_type_node, size_type_node,
@@ -16215,7 +16216,8 @@ usm_transform (gimple_stmt_iterator *gsi_p, bool *,
                       || (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
                           && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FREE)
                       || (DECL_IS_OPERATOR_DELETE_P (fndecl)
-                          && DECL_IS_REPLACEABLE_OPERATOR (fndecl)))
+                          && DECL_IS_REPLACEABLE_OPERATOR (fndecl))
+                      || strcmp (name, "omp_target_free") == 0)
              {
                tree omp_free_type
                  = build_function_type_list (void_type_node, ptr_type_node,
index 6ff2e7339a884ad3c1ebe6a86fd96f37281c1193..9d8026e00065d90d5bb5e7cde3553c236f705e24 100644 (file)
@@ -1,3 +1,8 @@
+2022-04-02  Andrew Stubbs  <ams@codesourcery.com>
+
+       * c-c++-common/gomp/usm-2.c: Add omp_target_alloc.
+       * c-c++-common/gomp/usm-3.c: Add omp_target_alloc.
+
 2022-03-11  Andrew Stubbs <ams@codesourcery.com>
 
        Backport of the patch posted at
index 64dbb6be13150b7b6f4a681025f1ef54ac891abe..8c20ef94e69b8f9ba4ad0ba7fa051e8e6b26de33 100644 (file)
@@ -12,6 +12,8 @@ void *aligned_alloc (__SIZE_TYPE__, __SIZE_TYPE__);
 void *calloc(__SIZE_TYPE__, __SIZE_TYPE__);
 void *realloc(void *, __SIZE_TYPE__);
 void free (void *);
+void *omp_target_alloc (__SIZE_TYPE__, int);
+void omp_target_free (void *, int);
 
 #ifdef __cplusplus
 }
@@ -24,16 +26,21 @@ foo ()
   void *p2 = realloc(p1, 30);
   void *p3 = calloc(4, 15);
   void *p4 = aligned_alloc(16, 40);
+  void *p5 = omp_target_alloc(50, 1);
   free (p2);
   free (p3);
   free (p4);
+  omp_target_free (p5, 1);
 }
 
 /* { dg-final { scan-tree-dump-times "omp_alloc \\(20, 10\\)" 1 "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-times "omp_realloc \\(.*, 30, 10, 10\\)" 1 "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-times "omp_calloc \\(4, 15, 10\\)" 1 "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-times "omp_aligned_alloc \\(16, 40, 10\\)" 1 "usm_transform"  } } */
-/* { dg-final { scan-tree-dump-times "omp_free" 3 "usm_transform"  } } */
+/* { dg-final { scan-tree-dump-times "omp_alloc \\(50, 10\\)" 1 "usm_transform"  } } */
+/* { dg-final { scan-tree-dump-times "omp_free" 4 "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-not " free"  "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-not " aligned_alloc"  "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-not " malloc"  "usm_transform"  } } */
+/* { dg-final { scan-tree-dump-not " omp_target_alloc"  "usm_transform"  } } */
+/* { dg-final { scan-tree-dump-not " omp_target_free"  "usm_transform"  } } */
index 934582ea5fd11560ed9a9c51222864199e929162..2b0cbb45e27c7bf9ae6fa55e1c531b1c595161ab 100644 (file)
@@ -10,6 +10,8 @@ void *aligned_alloc (__SIZE_TYPE__, __SIZE_TYPE__);
 void *calloc(__SIZE_TYPE__, __SIZE_TYPE__);
 void *realloc(void *, __SIZE_TYPE__);
 void free (void *);
+void *omp_target_alloc (__SIZE_TYPE__, int);
+void omp_target_free (void *, int);
 
 #ifdef __cplusplus
 }
@@ -22,16 +24,21 @@ foo ()
   void *p2 = realloc(p1, 30);
   void *p3 = calloc(4, 15);
   void *p4 = aligned_alloc(16, 40);
+  void *p5 = omp_target_alloc(50, 1);
   free (p2);
   free (p3);
   free (p4);
+  omp_target_free (p5, 1);
 }
 
 /* { dg-final { scan-tree-dump-times "omp_alloc \\(20, 10\\)" 1 "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-times "omp_realloc \\(.*, 30, 10, 10\\)" 1 "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-times "omp_calloc \\(4, 15, 10\\)" 1 "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-times "omp_aligned_alloc \\(16, 40, 10\\)" 1 "usm_transform"  } } */
-/* { dg-final { scan-tree-dump-times "omp_free" 3 "usm_transform"  } } */
+/* { dg-final { scan-tree-dump-times "omp_alloc \\(50, 10\\)" 1 "usm_transform"  } } */
+/* { dg-final { scan-tree-dump-times "omp_free" 4 "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-not " free"  "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-not " aligned_alloc"  "usm_transform"  } } */
 /* { dg-final { scan-tree-dump-not " malloc"  "usm_transform"  } } */
+/* { dg-final { scan-tree-dump-not " omp_target_alloc"  "usm_transform"  } } */
+/* { dg-final { scan-tree-dump-not " omp_target_free"  "usm_transform"  } } */
index 888fc16bc030ed8b3c27cfe1800558cd6cebb8d5..1693c212a120e37f39ba547b4a4875bf1ba9f0fb 100644 (file)
@@ -1,3 +1,7 @@
+2022-04-02  Andrew Stubbs  <ams@codesourcery.com>
+
+       * testsuite/libgomp.c/usm-6.c: Add omp_target_alloc.
+
 2022-03-31  Abid Qadeer  <abidh@codesourcery.com>
 
        * testsuite/libgomp.fortran/allocate-2.f90: Remove commented lines.
index d2c828fdc9dcf13366a316e581cb9ed2fe435cf6..c207140092a7f0537b203b67c352506c9e27e8d1 100644 (file)
@@ -4,6 +4,8 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#include <omp.h>
+
 /* On old systems, the declaraition may not be present in stdlib.h which
    will generate a warning.  This function is going to be replaced with
    omp_aligned_alloc so the purpose of this declaration is to avoid that
@@ -19,7 +21,8 @@ main ()
   int *b = (int *) calloc(sizeof(int), 3);
   int *c = (int *) realloc(NULL, sizeof(int) * 4);
   int *d = (int *) aligned_alloc(32, sizeof(int));
-  if (!a || !b || !c || !d)
+  int *e = (int *) omp_target_alloc(sizeof(int), 1);
+  if (!a || !b || !c || !d || !e)
     __builtin_abort ();
 
   a[0] = 42;
@@ -36,6 +39,7 @@ main ()
   uintptr_t b_p = (uintptr_t)b;
   uintptr_t c_p = (uintptr_t)c;
   uintptr_t d_p = (uintptr_t)d;
+  uintptr_t e_p = (uintptr_t)e;
 
   if (d_p & 31 != 0)
     __builtin_abort ();
@@ -52,9 +56,12 @@ main ()
        __builtin_abort ();
       if (d_p != (uintptr_t)d)
        __builtin_abort ();
+      if (e_p != (uintptr_t)e)
+       __builtin_abort ();
       a[0] = 72;
       b[0] = 82;
       c[0] = 92;
+      e[0] = 102;
     }
 
 #pragma omp target
@@ -74,10 +81,12 @@ main ()
 
   if (a[0] != 72 || a[1] != 73
       || b[0] != 82 || b[1] != 83
-      || c[0] != 92 || c[1] != 93)
+      || c[0] != 92 || c[1] != 93
+      || e[0] != 102)
        __builtin_abort ();
   free(a);
   free(b);
   free(c);
+  omp_target_free(e, 1);
   return 0;
 }