Hi Jakub,

great suggestion – I did now as proposed.

On 26.03.21 15:46, Jakub Jelinek via Gcc-patches wrote:
On Fri, Mar 26, 2021 at 03:42:22PM +0100, Tobias Burnus wrote:
How about the following patch? It moves the aux function to 
libgomp.c-c++-common/on_device_arch.c
and #includes it in the new wrapper files libgomp.{c,fortran}/on_device_arch.c.
(Based on the observation that #include with relative paths always works,
while dg-additional-sources may not, depending how the testsuite it run.) [...]
For C/C++, why do we call it on_device_arch.c at all?  Can't be just
on_device_arch.h that is #included in each test instead of additional
sources?  If we don't like inlining, just use noinline attribute, but I
don't see why inlining would hurt.
For Fortran, sure, we can't include it, so let's add
libgomp.fortran/on_device_arch.c that #includes that header.

OK?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf
libgomp: Fix on_device_arch.c aux-file handling [PR99555]

libgomp/ChangeLog:

	PR target/99555
        * testsuite/lib/on_device_arch.c: Move to ...
        * testsuite/libgomp.c-c++-common/on_device_arch.h: ... here.
        * testsuite/libgomp.fortran/on_device_arch.c: New file;
	#include on_device_arch.h.
        * testsuite/libgomp.c-c++-common/task-detach-6.c: #include
	on_device_arch.h instead of using dg-additional-source.
        * testsuite/libgomp.c/pr99555-1.c: Likewise.
        * testsuite/libgomp.fortran/task-detach-6.f90: Update to use
	on_device_arch.c without relative paths.

 libgomp/testsuite/lib/on_device_arch.c             | 30 ----------------------
 .../libgomp.c-c++-common/on_device_arch.h          | 30 ++++++++++++++++++++++
 .../testsuite/libgomp.c-c++-common/task-detach-6.c |  4 +--
 libgomp/testsuite/libgomp.c/pr99555-1.c            |  3 +--
 libgomp/testsuite/libgomp.fortran/on_device_arch.c |  3 +++
 .../testsuite/libgomp.fortran/task-detach-6.f90    |  2 +-
 6 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/libgomp/testsuite/lib/on_device_arch.c b/libgomp/testsuite/lib/on_device_arch.c
deleted file mode 100644
index 1c0753c..0000000
--- a/libgomp/testsuite/lib/on_device_arch.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <gomp-constants.h>
-
-/* static */ int
-device_arch_nvptx (void)
-{
-  return GOMP_DEVICE_NVIDIA_PTX;
-}
-
-#pragma omp declare variant (device_arch_nvptx) match(construct={target},device={arch(nvptx)})
-/* static */ int
-device_arch (void)
-{
-  return GOMP_DEVICE_DEFAULT;
-}
-
-static int
-on_device_arch (int d)
-{
-  int d_cur;
-  #pragma omp target map(from:d_cur)
-  d_cur = device_arch ();
-
-  return d_cur == d;
-}
-
-int
-on_device_arch_nvptx ()
-{
-  return on_device_arch (GOMP_DEVICE_NVIDIA_PTX);
-}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/on_device_arch.h b/libgomp/testsuite/libgomp.c-c++-common/on_device_arch.h
new file mode 100644
index 0000000..1c0753c
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/on_device_arch.h
@@ -0,0 +1,30 @@
+#include <gomp-constants.h>
+
+/* static */ int
+device_arch_nvptx (void)
+{
+  return GOMP_DEVICE_NVIDIA_PTX;
+}
+
+#pragma omp declare variant (device_arch_nvptx) match(construct={target},device={arch(nvptx)})
+/* static */ int
+device_arch (void)
+{
+  return GOMP_DEVICE_DEFAULT;
+}
+
+static int
+on_device_arch (int d)
+{
+  int d_cur;
+  #pragma omp target map(from:d_cur)
+  d_cur = device_arch ();
+
+  return d_cur == d;
+}
+
+int
+on_device_arch_nvptx ()
+{
+  return on_device_arch (GOMP_DEVICE_NVIDIA_PTX);
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-detach-6.c b/libgomp/testsuite/libgomp.c-c++-common/task-detach-6.c
index 4a3e4a2..119d7f5 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/task-detach-6.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/task-detach-6.c
@@ -1,10 +1,8 @@
 /* { dg-do run } */
 
-/* { dg-additional-sources "../lib/on_device_arch.c" } */
-extern int on_device_arch_nvptx ();
-
 #include <omp.h>
 #include <assert.h>
+#include "on_device_arch.h"
 
 /* Test tasks with detach clause on an offload device.  Each device
    thread spawns off a chain of tasks, that can then be executed by
diff --git a/libgomp/testsuite/libgomp.c/pr99555-1.c b/libgomp/testsuite/libgomp.c/pr99555-1.c
index 9ba3309..0dc17bf 100644
--- a/libgomp/testsuite/libgomp.c/pr99555-1.c
+++ b/libgomp/testsuite/libgomp.c/pr99555-1.c
@@ -2,8 +2,7 @@
 
 // { dg-additional-options "-O0" }
 
-// { dg-additional-sources "../lib/on_device_arch.c" }
-extern int on_device_arch_nvptx ();
+#include "../libgomp.c-c++-common/on_device_arch.h"
 
 int main (void)
 {
diff --git a/libgomp/testsuite/libgomp.fortran/on_device_arch.c b/libgomp/testsuite/libgomp.fortran/on_device_arch.c
new file mode 100644
index 0000000..98822c4
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/on_device_arch.c
@@ -0,0 +1,3 @@
+/* Auxiliar file.  */
+/* { dg-do compile  { target skip-all-targets } } */
+#include "../libgomp.c-c++-common/on_device_arch.h"
diff --git a/libgomp/testsuite/libgomp.fortran/task-detach-6.f90 b/libgomp/testsuite/libgomp.fortran/task-detach-6.f90
index eda20e7..bd0beb6 100644
--- a/libgomp/testsuite/libgomp.fortran/task-detach-6.f90
+++ b/libgomp/testsuite/libgomp.fortran/task-detach-6.f90
@@ -1,6 +1,6 @@
 ! { dg-do run }
 
-! { dg-additional-sources ../lib/on_device_arch.c }
+! { dg-additional-sources on_device_arch.c }
   ! { dg-prune-output "command-line option '-fintrinsic-modules-path=.*' is valid for Fortran but not for C" }
 
 ! Test tasks with detach clause on an offload device.  Each device

Reply via email to