public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards
       [not found]       ` <87vbnaph0d.fsf@schwinge.name>
@ 2015-05-13 22:46         ` Thomas Schwinge
  2015-05-14  8:10           ` Jakub Jelinek
       [not found]           ` <55A6652D.4090004@mentor.com>
  0 siblings, 2 replies; 7+ messages in thread
From: Thomas Schwinge @ 2015-05-13 22:46 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 20293 bytes --]

Hi!

On Fri, 24 Oct 2014 00:18:10 +0200, I wrote:
> On Thu, 23 Oct 2014 17:02:20 +0200, I wrote:
> > On Fri, 16 May 2014 20:01:47 +0200, I wrote:
> > > On Fri, 16 May 2014 19:02:41 +0200, Tom de Vries <Tom_deVries@mentor.com> wrote:
> > > > Essentially I want to run the set of testcases in libgomp.oacc-c, similar to how
> > > > it is done in libgomp.oacc-c/c.exp, with the environment variable
> > > > ACC_DEVICE_TYPE set to host for the executable.
> > > 
> > > Thanks for working on this; indeed the idea is that we run the libgomp
> > > execution tests is as many configurations as possible -- sort of how
> > > certain classes of GCC tests are run for many different compiler options
> > > (optimization levels).  I suggest this to be implemented in the existing
> > > libgomp.*/*.exp files, by setting up some suitable looping over all
> > > supported accelerator targets (currently just the one GCC has been
> > > configured with) as well as host fallback, with suitable tags being added
> > > to the PASS/FAIL lines.  It appears to make sense to first separate any
> > > libgomp tests that test "traditional" OpenMP shared-memory, so don't run
> > > on acceleration devices; these of course only need to be run once.
> > > 
> > > > I'm not sure setenv is guaranteed to work.
> > 
> > Indeed that does not work for non-native testing, which is what we're
> > doing [...]...  That means, we can't do any testing of
> > offloading -- which is "a bit" unfortunate.

> > > > I found this related discussion:
> > > > http://marc.info/?t=121622718700001&r=1&w=2 .
> > > 
> > > Is it just the shell quoting issue that remains?  That's fixable.
> > 
> > Instead of going this route (the approach has later been disputed
> > upstream), I cooked up something else.  This is clearly a hack, and I
> > hope to get rid of that as soon as possible.  But it works.
> 
> Here it is.  Don't look closely -- you've been warned.  My hope is that
> we'll be able to get rid of that rather sooner than later:
> [...] for this use of ACC_DEVICE_TYPE, I hope that soon we'll
> get a compiler option to specify the default offloading device.  (Intel
> are working into this direction, upstream, -foffload=[...].)

(That -foffload=[...] option exists, but we're not yet (able) to use it
as desired.)  See also the discussion in
<http://news.gmane.org/find-root.php?message_id=%3C87sic2zpsz.fsf%40schwinge.name%3E>,
<http://news.gmane.org/find-root.php?message_id=%3C8761ekpu1h.fsf%40schwinge.name%3E>,
and so on.

> Until then: committed [...], with disgust.

Until then: committed to gomp-4_0-branch in r223185, with disgust.

commit 5803a3376041706672baede225a2dc47d70dd9a1
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed May 13 22:07:27 2015 +0000

    libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards
    
    No doubt, looking forward to the day, when this can be reverted.
    
    	libgomp/
            * env.c (initialize_env): Remove static attribute.
    	* libgomp.map (INTERNAL): Export initialize_env.
    	* testsuite/lib/libgomp.exp (libgomp_init): Build a few object
    	files to pre-set environment variables.
    	(ALWAYS_CFLAGS): Add constructor-setenv-defaults.o to ldflags.
    	(libgomp_target_compile): Don't set the compiler.
    	* testsuite/libgomp.c++/c++.exp (GXX_UNDER_TEST): Provide default.
    	(libgomp_compile_options): Set the compiler.
    	* testsuite/libgomp.c/c.exp (libgomp_compile_options): Set the
    	compiler.
    	* testsuite/libgomp.fortran/fortran.exp (GFORTRAN_UNDER_TEST):
    	Provide default.
    	(libgomp_compile_options): Set the compiler.
    	* testsuite/libgomp.graphite/graphite.exp
    	(libgomp_compile_options): Set the compiler.
    	* testsuite/libgomp.oacc-c++/c++.exp (SAVE_GCC_UNDER_TEST)
    	(GCC_UNDER_TEST): Don't set.
    	(GXX_UNDER_TEST): Provide default.
    	(libgomp_compile_options): Set the compiler.
    	(ALWAYS_CFLAGS): Add the respective
    	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
    	ldflags.
    	(ACC_DEVICE_TYPE): Don't set.
    	* testsuite/libgomp.oacc-c/c.exp (libgomp_compile_options): Set
    	the compiler.
    	(ALWAYS_CFLAGS): Add the respective
    	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
    	ldflags.
    	(ACC_DEVICE_TYPE): Don't set.
    	* testsuite/libgomp.oacc-fortran/fortran.exp
    	(libgomp_compile_options): Set the compiler.
    	(ALWAYS_CFLAGS): Add the respective
    	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
    	ldflags.
    	(ACC_DEVICE_TYPE): Don't set.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@223185 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog.gomp                             | 38 +++++++++++++++
 libgomp/env.c                                      |  6 ++-
 libgomp/libgomp.map                                |  6 +++
 libgomp/testsuite/lib/libgomp.exp                  | 56 ++++++++++++++++++++--
 libgomp/testsuite/libgomp.c++/c++.exp              | 13 +++++
 libgomp/testsuite/libgomp.c/c.exp                  |  2 +
 libgomp/testsuite/libgomp.fortran/fortran.exp      |  5 ++
 libgomp/testsuite/libgomp.graphite/graphite.exp    |  2 +
 libgomp/testsuite/libgomp.oacc-c++/c++.exp         | 26 ++++++----
 libgomp/testsuite/libgomp.oacc-c/c.exp             |  8 ++--
 libgomp/testsuite/libgomp.oacc-fortran/fortran.exp | 13 +++--
 11 files changed, 155 insertions(+), 20 deletions(-)

diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index 1d7d9da..0dbda49 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,3 +1,41 @@
+2015-05-13  Thomas Schwinge  <thomas@codesourcery.com>
+
+        * env.c (initialize_env): Remove static attribute.
+	* libgomp.map (INTERNAL): Export initialize_env.
+	* testsuite/lib/libgomp.exp (libgomp_init): Build a few object
+	files to pre-set environment variables.
+	(ALWAYS_CFLAGS): Add constructor-setenv-defaults.o to ldflags.
+	(libgomp_target_compile): Don't set the compiler.
+	* testsuite/libgomp.c++/c++.exp (GXX_UNDER_TEST): Provide default.
+	(libgomp_compile_options): Set the compiler.
+	* testsuite/libgomp.c/c.exp (libgomp_compile_options): Set the
+	compiler.
+	* testsuite/libgomp.fortran/fortran.exp (GFORTRAN_UNDER_TEST):
+	Provide default.
+	(libgomp_compile_options): Set the compiler.
+	* testsuite/libgomp.graphite/graphite.exp
+	(libgomp_compile_options): Set the compiler.
+	* testsuite/libgomp.oacc-c++/c++.exp (SAVE_GCC_UNDER_TEST)
+	(GCC_UNDER_TEST): Don't set.
+	(GXX_UNDER_TEST): Provide default.
+	(libgomp_compile_options): Set the compiler.
+	(ALWAYS_CFLAGS): Add the respective
+	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
+	ldflags.
+	(ACC_DEVICE_TYPE): Don't set.
+	* testsuite/libgomp.oacc-c/c.exp (libgomp_compile_options): Set
+	the compiler.
+	(ALWAYS_CFLAGS): Add the respective
+	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
+	ldflags.
+	(ACC_DEVICE_TYPE): Don't set.
+	* testsuite/libgomp.oacc-fortran/fortran.exp
+	(libgomp_compile_options): Set the compiler.
+	(ALWAYS_CFLAGS): Add the respective
+	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
+	ldflags.
+	(ACC_DEVICE_TYPE): Don't set.
+
 2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
 
 	* testsuite/libgomp.oacc-c-c++-common/routine-1.c: Remove
diff --git libgomp/env.c libgomp/env.c
index 6b5e963..1811bf5 100644
--- libgomp/env.c
+++ libgomp/env.c
@@ -1175,7 +1175,11 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy)
 }
 
 
-static void __attribute__((constructor))
+/* TODO.  See testsuite/lib/libgomp.exp:libgomp_init.  */
+#if 0
+static
+#endif
+void __attribute__((constructor))
 initialize_env (void)
 {
   unsigned long thread_limit_var, stacksize;
diff --git libgomp/libgomp.map libgomp/libgomp.map
index 45ad66f..fe38dc6 100644
--- libgomp/libgomp.map
+++ libgomp/libgomp.map
@@ -344,3 +344,9 @@ GOMP_PLUGIN_1.0 {
 	GOMP_PLUGIN_async_unmap_vars;
 	GOMP_PLUGIN_acc_thread;
 };
+
+# TODO.  See testsuite/lib/libgomp.exp:libgomp_init.
+INTERNAL {
+  global:
+	initialize_env;
+};
diff --git libgomp/testsuite/lib/libgomp.exp libgomp/testsuite/lib/libgomp.exp
index 0b65ed4..06bab54 100644
--- libgomp/testsuite/lib/libgomp.exp
+++ libgomp/testsuite/lib/libgomp.exp
@@ -235,6 +235,57 @@ proc libgomp_init { args } {
     if { $offload_additional_options != "" } {
 	lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
     }
+
+    # TODO.  Evil hack.  DejaGnu doesn't have a mechanism for setting
+    # environment variables on remote boards.  Thus, we have to fake it, using
+    # GCC's constructor attributes to create object files that install the
+    # desired environment variables.
+    set e_list [list \
+		    [list defaults DUMMY=dummy ] \
+		    [list ACC_DEVICE_TYPE-host ACC_DEVICE_TYPE=host ] \
+		    [list ACC_DEVICE_TYPE-host_nonshm ACC_DEVICE_TYPE=host_nonshm ] \
+		    [list ACC_DEVICE_TYPE-nvidia ACC_DEVICE_TYPE=nvidia ] ]
+    foreach e $e_list {
+	set v [lindex $e 0]
+	set s [lindex $e 1]
+	verbose "creating constructor-setenv: $v: $s"
+	set src constructor-setenv-$v.c
+	set obj constructor-setenv-$v.o
+	set f_src [open $src "w"]
+	puts $f_src "static void __attribute__((constructor(1000)))"
+	puts $f_src "init_env(void) {"
+	puts $f_src "  int putenv(char *);"
+	puts $f_src "  putenv(\"$s\");"
+	puts $f_src "}"
+	if { $v == "defaults" } {
+	    # TODO.  We want libgomp to initialize after the putenv calls.
+	    # But: shared libraries' constructors (and thus
+	    # env.c:initialize_env) will be called before the executable's
+	    # (init_env functions created above), so it will already have been
+	    # initialized (and has to be, in case we're not linking in this
+	    # gunk).  Assuming no execution of other libgomp functionality in
+	    # between (which we're not doing during initialization),
+	    # initialize_env's effects are idempotent when calling it again, so
+	    # we'll do that now, after the putenv calls have been executed.
+	    puts $f_src "static void __attribute__((constructor(1001)))"
+	    puts $f_src "init_libgomp(void) {"
+	    # Some test cases specify -fno-openmp, so libgomp isn't linked in.
+	    puts $f_src "  void initialize_env(void) __attribute__((weak));"
+	    puts $f_src "  if (initialize_env)"
+	    puts $f_src "    initialize_env();"
+	    puts $f_src "}"
+	}
+	close $f_src
+	# TODO.  Using whichever compiler is currently configured...  At least
+	# switch it into C mode.
+	set lines [libgomp_target_compile $src $obj object "additional_flags=-xc"]
+	# TODO.  Error checking.
+	file delete $src
+    }
+    # When adding constructor-setenv-*.o files, make sure to cancel any -x flag
+    # that may have been set before.
+    lappend ALWAYS_CFLAGS "ldflags=-x none"
+    lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-defaults.o"
 }
 
 #
@@ -246,7 +297,6 @@ proc libgomp_target_compile { source dest type options } {
     global libgomp_compile_options
     global gluefile wrap_flags
     global ALWAYS_CFLAGS
-    global GCC_UNDER_TEST
     global lang_test_file
     global lang_library_path
     global lang_link_flags
@@ -274,7 +324,6 @@ proc libgomp_target_compile { source dest type options } {
 
     lappend options "additional_flags=[libio_include_flags]"
     lappend options "timeout=[timeout_value]"
-    lappend options "compiler=$GCC_UNDER_TEST"
 
     set options [concat $libgomp_compile_options $options]
 
@@ -332,8 +381,7 @@ proc check_effective_target_openacc_nvidia_accel_present { } {
 }
 
 # Return 1 if at least one nvidia board is present, and the nvidia device type
-# is selected by default by means of setting the environment variable
-# ACC_DEVICE_TYPE.
+# is selected by default.
 
 proc check_effective_target_openacc_nvidia_accel_selected { } {
     if { ![check_effective_target_openacc_nvidia_accel_present] } {
diff --git libgomp/testsuite/libgomp.c++/c++.exp libgomp/testsuite/libgomp.c++/c++.exp
index da42e62..b88da93 100644
--- libgomp/testsuite/libgomp.c++/c++.exp
+++ libgomp/testsuite/libgomp.c++/c++.exp
@@ -4,6 +4,7 @@ load_gcc_lib gcc-dg.exp
 global shlib_ext
 
 set shlib_ext [get_shlib_extension]
+#TODO
 set lang_link_flags "-lstdc++"
 set lang_test_file_found 0
 set lang_library_path "../libstdc++-v3/src/.libs"
@@ -41,6 +42,13 @@ if { $blddir != "" } {
 }
 
 if { $lang_test_file_found } {
+    if ![info exists GXX_UNDER_TEST] then {
+	# TODO.  See libgomp.oacc-c++/c++.exp.
+	set HAVE_SET_GXX_UNDER_TEST ""
+	set GXX_UNDER_TEST "$GCC_UNDER_TEST"
+    }
+    lappend libgomp_compile_options "compiler=$GXX_UNDER_TEST"
+
     # Gather a list of all tests.
     set tests [lsort [find $srcdir/$subdir *.C]]
 
@@ -63,5 +71,10 @@ if { $lang_test_file_found } {
     dg-runtest $tests "" $libstdcxx_includes
 }
 
+# TODO.  See above.
+if { [info exists HAVE_SET_GXX_UNDER_TEST] } {
+    unset GXX_UNDER_TEST
+}
+
 # All done.
 dg-finish
diff --git libgomp/testsuite/libgomp.c/c.exp libgomp/testsuite/libgomp.c/c.exp
index 300b921..25f347b 100644
--- libgomp/testsuite/libgomp.c/c.exp
+++ libgomp/testsuite/libgomp.c/c.exp
@@ -23,6 +23,8 @@ dg-init
 # Turn on OpenMP.
 lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
 
+lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST"
+
 # Gather a list of all tests.
 set tests [lsort [find $srcdir/$subdir *.c]]
 
diff --git libgomp/testsuite/libgomp.fortran/fortran.exp libgomp/testsuite/libgomp.fortran/fortran.exp
index f684abc..883c416 100644
--- libgomp/testsuite/libgomp.fortran/fortran.exp
+++ libgomp/testsuite/libgomp.fortran/fortran.exp
@@ -47,6 +47,11 @@ if { $blddir != "" } {
 }
 
 if { $lang_test_file_found } {
+    if ![info exists GFORTRAN_UNDER_TEST] then {
+	set GFORTRAN_UNDER_TEST $GCC_UNDER_TEST
+    }
+    lappend libgomp_compile_options "compiler=$GFORTRAN_UNDER_TEST"
+
     # Gather a list of all tests.
     set tests [lsort [find $srcdir/$subdir *.\[fF\]{,90,95,03,08}]]
 
diff --git libgomp/testsuite/libgomp.graphite/graphite.exp libgomp/testsuite/libgomp.graphite/graphite.exp
index d737c85..716cdc3 100644
--- libgomp/testsuite/libgomp.graphite/graphite.exp
+++ libgomp/testsuite/libgomp.graphite/graphite.exp
@@ -48,6 +48,8 @@ dg-init
 # Turn on OpenMP.
 lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
 
+lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST"
+
 # Gather a list of all tests.
 set tests [lsort [find $srcdir/$subdir *.c]]
 
diff --git libgomp/testsuite/libgomp.oacc-c++/c++.exp libgomp/testsuite/libgomp.oacc-c++/c++.exp
index 81d445c..8d8f4ff 100644
--- libgomp/testsuite/libgomp.oacc-c++/c++.exp
+++ libgomp/testsuite/libgomp.oacc-c++/c++.exp
@@ -6,6 +6,7 @@ load_gcc_lib gcc-dg.exp
 global shlib_ext
 
 set shlib_ext [get_shlib_extension]
+#TODO
 set lang_link_flags "-lstdc++"
 set lang_test_file_found 0
 set lang_library_path "../libstdc++-v3/src/.libs"
@@ -19,11 +20,6 @@ dg-init
 # Turn on OpenACC.
 lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
 
-# Switch into C++ mode.  Otherwise, the libgomp.oacc-c-c++-common/*.c
-# files would be compiled as C files.
-set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST"
-set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++"
-
 set blddir [lookfor_file [get_multilibs] libgomp]
 
 
@@ -48,6 +44,14 @@ if { $blddir != "" } {
 }
 
 if { $lang_test_file_found } {
+    if ![info exists GXX_UNDER_TEST] then {
+	# Use GCC_UNDER_TEST, but switch into C++ mode, as otherwise the
+	# libgomp.oacc-c-c++-common/*.c files would be compiled as C files.
+	set HAVE_SET_GXX_UNDER_TEST ""
+	set GXX_UNDER_TEST "$GCC_UNDER_TEST -x c++"
+    }
+    lappend libgomp_compile_options "compiler=$GXX_UNDER_TEST"
+
     # Gather a list of all tests.
     set tests [lsort [concat \
 			  [find $srcdir/$subdir *.C] \
@@ -69,8 +73,13 @@ if { $lang_test_file_found } {
     }
 
     # Test OpenACC with available accelerators.
+    set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
     foreach offload_target_openacc $offload_targets_s_openacc {
+	set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
 	set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
+	# Set $ACC_DEVICE_TYPE.  See the comments in
+	# ../lib/libgomp.exp:libgomp_init.
+	lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o"
 
 	# Todo: Determine shared memory or not using run-time test.
 	switch $offload_target_openacc {
@@ -95,15 +104,14 @@ if { $lang_test_file_found } {
 	}
 	set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
 
-	# Todo: Verify that this works for both local and remote testing.
-	setenv ACC_DEVICE_TYPE $offload_target_openacc
-
 	dg-runtest $tests "$tagopt" $libstdcxx_includes
     }
 }
 
 # See above.
-set GCC_UNDER_TEST "$SAVE_GCC_UNDER_TEST"
+if { [info exists HAVE_SET_GXX_UNDER_TEST] } {
+    unset GXX_UNDER_TEST
+}
 
 # All done.
 dg-finish
diff --git libgomp/testsuite/libgomp.oacc-c/c.exp libgomp/testsuite/libgomp.oacc-c/c.exp
index 85943f0..8d54815 100644
--- libgomp/testsuite/libgomp.oacc-c/c.exp
+++ libgomp/testsuite/libgomp.oacc-c/c.exp
@@ -25,6 +25,8 @@ dg-init
 # Turn on OpenACC.
 lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
 
+lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST"
+
 # Gather a list of all tests.
 set tests [lsort [concat \
 		      [find $srcdir/$subdir *.c] \
@@ -39,6 +41,9 @@ set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
 foreach offload_target_openacc $offload_targets_s_openacc {
     set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
     set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
+    # Set $ACC_DEVICE_TYPE.  See the comments in
+    # ../lib/libgomp.exp:libgomp_init.
+    lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o"
 
     # Todo: Determine shared memory or not using run-time test.
     switch $offload_target_openacc {
@@ -63,9 +68,6 @@ foreach offload_target_openacc $offload_targets_s_openacc {
     }
     set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
 
-    # Todo: Verify that this works for both local and remote testing.
-    setenv ACC_DEVICE_TYPE $offload_target_openacc
-
     dg-runtest $tests "$tagopt" $DEFAULT_CFLAGS
 }
 
diff --git libgomp/testsuite/libgomp.oacc-fortran/fortran.exp libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
index 11655a1..07695e7 100644
--- libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
+++ libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
@@ -49,6 +49,11 @@ if { $blddir != "" } {
 }
 
 if { $lang_test_file_found } {
+    if ![info exists GFORTRAN_UNDER_TEST] then {
+	set GFORTRAN_UNDER_TEST $GCC_UNDER_TEST
+    }
+    lappend libgomp_compile_options "compiler=$GFORTRAN_UNDER_TEST"
+
     # Gather a list of all tests.
     set tests [lsort [find $srcdir/$subdir *.\[fF\]{,90,95,03,08}]]
 
@@ -69,8 +74,13 @@ if { $lang_test_file_found } {
     set_ld_library_path_env_vars
 
     # Test OpenACC with available accelerators.
+    set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
     foreach offload_target_openacc $offload_targets_s_openacc {
+	set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
 	set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
+	# Set $ACC_DEVICE_TYPE.  See the comments in
+	# ../lib/libgomp.exp:libgomp_init.
+	lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o"
 
 	# Todo: Determine shared memory or not using run-time test.
 	switch $offload_target_openacc {
@@ -89,9 +99,6 @@ if { $lang_test_file_found } {
 	}
 	set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
 
-	# Todo: Verify that this works for both local and remote testing.
-	setenv ACC_DEVICE_TYPE $offload_target_openacc
-
 	# For Fortran we're doing torture testing, as Fortran has far more tests
 	# with arrays etc. that testing just -O0 or -O2 is insufficient, that is
 	# typically not the case for C/C++.


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards
  2015-05-13 22:46         ` [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards Thomas Schwinge
@ 2015-05-14  8:10           ` Jakub Jelinek
  2015-05-14  9:00             ` Jakub Jelinek
       [not found]           ` <55A6652D.4090004@mentor.com>
  1 sibling, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2015-05-14  8:10 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: gcc-patches

On Thu, May 14, 2015 at 12:10:50AM +0200, Thomas Schwinge wrote:
>     No doubt, looking forward to the day, when this can be reverted.
>     
>     	libgomp/
>             * env.c (initialize_env): Remove static attribute.
>     	* libgomp.map (INTERNAL): Export initialize_env.

Ugh.  While you achieve what you want for the remote board cases,
doesn't this completely break all OpenMP and OpenACC programs not built
as part of the testsuite, because initialize_env won't be called in that case?

	Jakub

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards
  2015-05-14  8:10           ` Jakub Jelinek
@ 2015-05-14  9:00             ` Jakub Jelinek
  2015-05-14  9:39               ` Jakub Jelinek
  2015-07-22  8:48               ` [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards Thomas Schwinge
  0 siblings, 2 replies; 7+ messages in thread
From: Jakub Jelinek @ 2015-05-14  9:00 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: gcc-patches

On Thu, May 14, 2015 at 10:05:36AM +0200, Jakub Jelinek wrote:
> On Thu, May 14, 2015 at 12:10:50AM +0200, Thomas Schwinge wrote:
> >     No doubt, looking forward to the day, when this can be reverted.
> >     
> >     	libgomp/
> >             * env.c (initialize_env): Remove static attribute.
> >     	* libgomp.map (INTERNAL): Export initialize_env.
> 
> Ugh.  While you achieve what you want for the remote board cases,
> doesn't this completely break all OpenMP and OpenACC programs not built
> as part of the testsuite, because initialize_env won't be called in that case?

Can't you just tweak *.exp files so that if dg-set-target-env-var is used
or some forced env var is added to the same list through other means,
you invoke on the remove side env VAR1=val1 VAR2=val2 program arguments
instead of program arguments ?

	Jakub

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards
  2015-05-14  9:00             ` Jakub Jelinek
@ 2015-05-14  9:39               ` Jakub Jelinek
  2015-07-22  9:08                 ` libgomp testing, RUNTESTFLAGS (was: [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards) Thomas Schwinge
  2015-07-22  8:48               ` [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards Thomas Schwinge
  1 sibling, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2015-05-14  9:39 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: gcc-patches

On Thu, May 14, 2015 at 10:54:07AM +0200, Jakub Jelinek wrote:
> On Thu, May 14, 2015 at 10:05:36AM +0200, Jakub Jelinek wrote:
> > On Thu, May 14, 2015 at 12:10:50AM +0200, Thomas Schwinge wrote:
> > >     No doubt, looking forward to the day, when this can be reverted.
> > >     
> > >     	libgomp/
> > >             * env.c (initialize_env): Remove static attribute.
> > >     	* libgomp.map (INTERNAL): Export initialize_env.
> > 
> > Ugh.  While you achieve what you want for the remote board cases,
> > doesn't this completely break all OpenMP and OpenACC programs not built
> > as part of the testsuite, because initialize_env won't be called in that case?
> 
> Can't you just tweak *.exp files so that if dg-set-target-env-var is used
> or some forced env var is added to the same list through other means,
> you invoke on the remove side env VAR1=val1 VAR2=val2 program arguments
> instead of program arguments ?

Talking about the libgomp testsuite, can we rename the
libgomp/testsuite/libgomp-oacc-*/*.exp files to something unique?
I mean, trying to run say just the OpenMP C tests is impossible since
the OpenACC merge, because RUNTESTFLAGS=c.exp runs both OpenMP and OpenACC.
If it was say acc-c.exp, then you can choose if you want to test just
OpenACC, or just OpenMP, both, and which particular tests more accurately.

	Jakub

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards
       [not found]           ` <55A6652D.4090004@mentor.com>
@ 2015-07-15 14:40             ` Thomas Schwinge
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Schwinge @ 2015-07-15 14:40 UTC (permalink / raw)
  To: Nathan Sidwell, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 18590 bytes --]

Hi!

(CCed to gcc-patches in case this is useful for anyone else, too.)

Nathan noticed that the following patch ("hack") no longer applies
cleanly to GCC trunk:

On Thu, 14 May 2015 00:10:50 +0200, I wrote:
> On Fri, 24 Oct 2014 00:18:10 +0200, I wrote:
> > On Thu, 23 Oct 2014 17:02:20 +0200, I wrote:
> > > On Fri, 16 May 2014 20:01:47 +0200, I wrote:
> > > > On Fri, 16 May 2014 19:02:41 +0200, Tom de Vries <Tom_deVries@mentor.com> wrote:
> > > > > Essentially I want to run the set of testcases in libgomp.oacc-c, similar to how
> > > > > it is done in libgomp.oacc-c/c.exp, with the environment variable
> > > > > ACC_DEVICE_TYPE set to host for the executable.
> > > > 
> > > > Thanks for working on this; indeed the idea is that we run the libgomp
> > > > execution tests is as many configurations as possible -- sort of how
> > > > certain classes of GCC tests are run for many different compiler options
> > > > (optimization levels).  I suggest this to be implemented in the existing
> > > > libgomp.*/*.exp files, by setting up some suitable looping over all
> > > > supported accelerator targets (currently just the one GCC has been
> > > > configured with) as well as host fallback, with suitable tags being added
> > > > to the PASS/FAIL lines.  It appears to make sense to first separate any
> > > > libgomp tests that test "traditional" OpenMP shared-memory, so don't run
> > > > on acceleration devices; these of course only need to be run once.
> > > > 
> > > > > I'm not sure setenv is guaranteed to work.
> > > 
> > > Indeed that does not work for non-native testing, which is what we're
> > > doing [...]...  That means, we can't do any testing of
> > > offloading -- which is "a bit" unfortunate.
> 
> > > > > I found this related discussion:
> > > > > http://marc.info/?t=121622718700001&r=1&w=2 .
> > > > 
> > > > Is it just the shell quoting issue that remains?  That's fixable.
> > > 
> > > Instead of going this route (the approach has later been disputed
> > > upstream), I cooked up something else.  This is clearly a hack, and I
> > > hope to get rid of that as soon as possible.  But it works.
> > 
> > Here it is.  Don't look closely -- you've been warned.  My hope is that
> > we'll be able to get rid of that rather sooner than later:
> > [...] for this use of ACC_DEVICE_TYPE, I hope that soon we'll
> > get a compiler option to specify the default offloading device.  (Intel
> > are working into this direction, upstream, -foffload=[...].)
> 
> (That -foffload=[...] option exists, but we're not yet (able) to use it
> as desired.)  See also the discussion in
> <http://news.gmane.org/find-root.php?message_id=%3C87sic2zpsz.fsf%40schwinge.name%3E>,
> <http://news.gmane.org/find-root.php?message_id=%3C8761ekpu1h.fsf%40schwinge.name%3E>,
> and so on.
> 
> > Until then: committed [...], with disgust.
> 
> Until then: committed to gomp-4_0-branch in r223185, with disgust.
> 
> commit 5803a3376041706672baede225a2dc47d70dd9a1
> Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
> Date:   Wed May 13 22:07:27 2015 +0000
> 
>     libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards

..., so I resolved the merge conflicts; here is the patch (untested, but
should be fine) rebased onto current trunk r225829:

commit 31d8e05087bf129c1afe7be6593311d204393c09
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Wed Jul 15 16:11:23 2015 +0200

    libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards
    
    No doubt, looking forward to the day, when this can be reverted.
    
    Port gomp-4_0-branch r223185:
    
    	libgomp/
    	* env.c (initialize_env): Remove static attribute.
    	* libgomp.map (INTERNAL): Export initialize_env.
    	* testsuite/lib/libgomp.exp (libgomp_init): Build a few object
    	files to pre-set environment variables.
    	(ALWAYS_CFLAGS): Add constructor-setenv-defaults.o to ldflags.
    	(libgomp_target_compile): Don't set the compiler.
    	* testsuite/libgomp.c++/c++.exp (GXX_UNDER_TEST): Provide default.
    	(libgomp_compile_options): Set the compiler.
    	* testsuite/libgomp.c/c.exp (libgomp_compile_options): Set the
    	compiler.
    	* testsuite/libgomp.fortran/fortran.exp (GFORTRAN_UNDER_TEST):
    	Provide default.
    	(libgomp_compile_options): Set the compiler.
    	* testsuite/libgomp.graphite/graphite.exp
    	(libgomp_compile_options): Set the compiler.
    	* testsuite/libgomp.oacc-c++/c++.exp (SAVE_GCC_UNDER_TEST)
    	(GCC_UNDER_TEST): Don't set.
    	(GXX_UNDER_TEST): Provide default.
    	(libgomp_compile_options): Set the compiler.
    	(ALWAYS_CFLAGS): Add the respective
    	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
    	ldflags.
    	(ACC_DEVICE_TYPE): Don't set.
    	* testsuite/libgomp.oacc-c/c.exp (libgomp_compile_options): Set
    	the compiler.
    	(ALWAYS_CFLAGS): Add the respective
    	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
    	ldflags.
    	(ACC_DEVICE_TYPE): Don't set.
    	* testsuite/libgomp.oacc-fortran/fortran.exp
    	(libgomp_compile_options): Set the compiler.
    	(ALWAYS_CFLAGS): Add the respective
    	constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o to
    	ldflags.
    	(ACC_DEVICE_TYPE): Don't set.
---
 libgomp/env.c                                      |    6 ++-
 libgomp/libgomp.map                                |    6 +++
 libgomp/testsuite/lib/libgomp.exp                  |   56 ++++++++++++++++++--
 libgomp/testsuite/libgomp.c++/c++.exp              |   13 +++++
 libgomp/testsuite/libgomp.c/c.exp                  |    2 +
 libgomp/testsuite/libgomp.fortran/fortran.exp      |    5 ++
 libgomp/testsuite/libgomp.graphite/graphite.exp    |    2 +
 libgomp/testsuite/libgomp.oacc-c++/c++.exp         |   25 ++++++---
 libgomp/testsuite/libgomp.oacc-c/c.exp             |    7 ++-
 libgomp/testsuite/libgomp.oacc-fortran/fortran.exp |   12 ++++-
 10 files changed, 117 insertions(+), 17 deletions(-)

diff --git libgomp/env.c libgomp/env.c
index 6b5e963..1811bf5 100644
--- libgomp/env.c
+++ libgomp/env.c
@@ -1175,7 +1175,11 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy)
 }
 
 
-static void __attribute__((constructor))
+/* TODO.  See testsuite/lib/libgomp.exp:libgomp_init.  */
+#if 0
+static
+#endif
+void __attribute__((constructor))
 initialize_env (void)
 {
   unsigned long thread_limit_var, stacksize;
diff --git libgomp/libgomp.map libgomp/libgomp.map
index 2b2b953..a3e80b4 100644
--- libgomp/libgomp.map
+++ libgomp/libgomp.map
@@ -337,3 +337,9 @@ GOMP_PLUGIN_1.0 {
 	GOMP_PLUGIN_async_unmap_vars;
 	GOMP_PLUGIN_acc_thread;
 };
+
+# TODO.  See testsuite/lib/libgomp.exp:libgomp_init.
+INTERNAL {
+  global:
+	initialize_env;
+};
diff --git libgomp/testsuite/lib/libgomp.exp libgomp/testsuite/lib/libgomp.exp
index 438777f..982d25e 100644
--- libgomp/testsuite/lib/libgomp.exp
+++ libgomp/testsuite/lib/libgomp.exp
@@ -235,6 +235,57 @@ proc libgomp_init { args } {
     if { $offload_additional_options != "" } {
 	lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
     }
+
+    # TODO.  Evil hack.  DejaGnu doesn't have a mechanism for setting
+    # environment variables on remote boards.  Thus, we have to fake it, using
+    # GCC's constructor attributes to create object files that install the
+    # desired environment variables.
+    set e_list [list \
+		    [list defaults DUMMY=dummy ] \
+		    [list ACC_DEVICE_TYPE-host ACC_DEVICE_TYPE=host ] \
+		    [list ACC_DEVICE_TYPE-host_nonshm ACC_DEVICE_TYPE=host_nonshm ] \
+		    [list ACC_DEVICE_TYPE-nvidia ACC_DEVICE_TYPE=nvidia ] ]
+    foreach e $e_list {
+	set v [lindex $e 0]
+	set s [lindex $e 1]
+	verbose "creating constructor-setenv: $v: $s"
+	set src constructor-setenv-$v.c
+	set obj constructor-setenv-$v.o
+	set f_src [open $src "w"]
+	puts $f_src "static void __attribute__((constructor(1000)))"
+	puts $f_src "init_env(void) {"
+	puts $f_src "  int putenv(char *);"
+	puts $f_src "  putenv(\"$s\");"
+	puts $f_src "}"
+	if { $v == "defaults" } {
+	    # TODO.  We want libgomp to initialize after the putenv calls.
+	    # But: shared libraries' constructors (and thus
+	    # env.c:initialize_env) will be called before the executable's
+	    # (init_env functions created above), so it will already have been
+	    # initialized (and has to be, in case we're not linking in this
+	    # gunk).  Assuming no execution of other libgomp functionality in
+	    # between (which we're not doing during initialization),
+	    # initialize_env's effects are idempotent when calling it again, so
+	    # we'll do that now, after the putenv calls have been executed.
+	    puts $f_src "static void __attribute__((constructor(1001)))"
+	    puts $f_src "init_libgomp(void) {"
+	    # Some test cases specify -fno-openmp, so libgomp isn't linked in.
+	    puts $f_src "  void initialize_env(void) __attribute__((weak));"
+	    puts $f_src "  if (initialize_env)"
+	    puts $f_src "    initialize_env();"
+	    puts $f_src "}"
+	}
+	close $f_src
+	# TODO.  Using whichever compiler is currently configured...  At least
+	# switch it into C mode.
+	set lines [libgomp_target_compile $src $obj object "additional_flags=-xc"]
+	# TODO.  Error checking.
+	file delete $src
+    }
+    # When adding constructor-setenv-*.o files, make sure to cancel any -x flag
+    # that may have been set before.
+    lappend ALWAYS_CFLAGS "ldflags=-x none"
+    lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-defaults.o"
 }
 
 #
@@ -246,7 +297,6 @@ proc libgomp_target_compile { source dest type options } {
     global libgomp_compile_options
     global gluefile wrap_flags
     global ALWAYS_CFLAGS
-    global GCC_UNDER_TEST
     global lang_test_file
     global lang_library_path
     global lang_link_flags
@@ -274,7 +324,6 @@ proc libgomp_target_compile { source dest type options } {
 
     lappend options "additional_flags=[libio_include_flags]"
     lappend options "timeout=[timeout_value]"
-    lappend options "compiler=$GCC_UNDER_TEST"
 
     set options [concat $libgomp_compile_options $options]
 
@@ -332,8 +381,7 @@ proc check_effective_target_openacc_nvidia_accel_present { } {
 }
 
 # Return 1 if at least one nvidia board is present, and the nvidia device type
-# is selected by default by means of setting the environment variable
-# ACC_DEVICE_TYPE.
+# is selected by default.
 
 proc check_effective_target_openacc_nvidia_accel_selected { } {
     if { ![check_effective_target_openacc_nvidia_accel_present] } {
diff --git libgomp/testsuite/libgomp.c++/c++.exp libgomp/testsuite/libgomp.c++/c++.exp
index 0454f95..d6d525a 100644
--- libgomp/testsuite/libgomp.c++/c++.exp
+++ libgomp/testsuite/libgomp.c++/c++.exp
@@ -4,6 +4,7 @@ load_gcc_lib gcc-dg.exp
 global shlib_ext
 
 set shlib_ext [get_shlib_extension]
+#TODO
 set lang_link_flags "-lstdc++"
 set lang_test_file_found 0
 set lang_library_path "../libstdc++-v3/src/.libs"
@@ -46,6 +47,13 @@ if { $blddir != "" } {
 }
 
 if { $lang_test_file_found } {
+    if ![info exists GXX_UNDER_TEST] then {
+	# TODO.  See libgomp.oacc-c++/c++.exp.
+	set HAVE_SET_GXX_UNDER_TEST ""
+	set GXX_UNDER_TEST "$GCC_UNDER_TEST"
+    }
+    lappend libgomp_compile_options "compiler=$GXX_UNDER_TEST"
+
     # Gather a list of all tests.
     set tests [lsort [find $srcdir/$subdir *.C]]
 
@@ -68,5 +76,10 @@ if { $lang_test_file_found } {
     dg-runtest $tests "" "$libstdcxx_includes $DEFAULT_CFLAGS"
 }
 
+# TODO.  See above.
+if { [info exists HAVE_SET_GXX_UNDER_TEST] } {
+    unset GXX_UNDER_TEST
+}
+
 # All done.
 dg-finish
diff --git libgomp/testsuite/libgomp.c/c.exp libgomp/testsuite/libgomp.c/c.exp
index 300b921..25f347b 100644
--- libgomp/testsuite/libgomp.c/c.exp
+++ libgomp/testsuite/libgomp.c/c.exp
@@ -23,6 +23,8 @@ dg-init
 # Turn on OpenMP.
 lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
 
+lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST"
+
 # Gather a list of all tests.
 set tests [lsort [find $srcdir/$subdir *.c]]
 
diff --git libgomp/testsuite/libgomp.fortran/fortran.exp libgomp/testsuite/libgomp.fortran/fortran.exp
index 9e6b643..38ed30a 100644
--- libgomp/testsuite/libgomp.fortran/fortran.exp
+++ libgomp/testsuite/libgomp.fortran/fortran.exp
@@ -44,6 +44,11 @@ if { $blddir != "" } {
 }
 
 if { $lang_test_file_found } {
+    if ![info exists GFORTRAN_UNDER_TEST] then {
+	set GFORTRAN_UNDER_TEST $GCC_UNDER_TEST
+    }
+    lappend libgomp_compile_options "compiler=$GFORTRAN_UNDER_TEST"
+
     # Gather a list of all tests.
     set tests [lsort [find $srcdir/$subdir *.\[fF\]{,90,95,03,08}]]
 
diff --git libgomp/testsuite/libgomp.graphite/graphite.exp libgomp/testsuite/libgomp.graphite/graphite.exp
index d737c85..716cdc3 100644
--- libgomp/testsuite/libgomp.graphite/graphite.exp
+++ libgomp/testsuite/libgomp.graphite/graphite.exp
@@ -48,6 +48,8 @@ dg-init
 # Turn on OpenMP.
 lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
 
+lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST"
+
 # Gather a list of all tests.
 set tests [lsort [find $srcdir/$subdir *.c]]
 
diff --git libgomp/testsuite/libgomp.oacc-c++/c++.exp libgomp/testsuite/libgomp.oacc-c++/c++.exp
index 3b97024..0272b98 100644
--- libgomp/testsuite/libgomp.oacc-c++/c++.exp
+++ libgomp/testsuite/libgomp.oacc-c++/c++.exp
@@ -6,6 +6,7 @@ load_gcc_lib gcc-dg.exp
 global shlib_ext
 
 set shlib_ext [get_shlib_extension]
+#TODO
 set lang_link_flags "-lstdc++"
 set lang_test_file_found 0
 set lang_library_path "../libstdc++-v3/src/.libs"
@@ -24,11 +25,6 @@ dg-init
 # Turn on OpenACC.
 lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
 
-# Switch into C++ mode.  Otherwise, the libgomp.oacc-c-c++-common/*.c
-# files would be compiled as C files.
-set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST"
-set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++"
-
 set blddir [lookfor_file [get_multilibs] libgomp]
 
 
@@ -53,6 +49,14 @@ if { $blddir != "" } {
 }
 
 if { $lang_test_file_found } {
+    if ![info exists GXX_UNDER_TEST] then {
+	# Use GCC_UNDER_TEST, but switch into C++ mode, as otherwise the
+	# libgomp.oacc-c-c++-common/*.c files would be compiled as C files.
+	set HAVE_SET_GXX_UNDER_TEST ""
+	set GXX_UNDER_TEST "$GCC_UNDER_TEST -x c++"
+    }
+    lappend libgomp_compile_options "compiler=$GXX_UNDER_TEST"
+
     # Gather a list of all tests.
     set tests [lsort [concat \
 			  [find $srcdir/$subdir *.C] \
@@ -74,8 +78,13 @@ if { $lang_test_file_found } {
     }
 
     # Test OpenACC with available accelerators.
+    set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
     foreach offload_target_openacc $offload_targets_s_openacc {
+	set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
 	set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
+	# Set $ACC_DEVICE_TYPE.  See the comments in
+	# ../lib/libgomp.exp:libgomp_init.
+	lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o"
 
 	switch $offload_target_openacc {
 	    host {
@@ -105,14 +114,14 @@ if { $lang_test_file_found } {
 	}
 	set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
 
-	setenv ACC_DEVICE_TYPE $offload_target_openacc
-
 	dg-runtest $tests "$tagopt" "$libstdcxx_includes $DEFAULT_CFLAGS"
     }
 }
 
 # See above.
-set GCC_UNDER_TEST "$SAVE_GCC_UNDER_TEST"
+if { [info exists HAVE_SET_GXX_UNDER_TEST] } {
+    unset GXX_UNDER_TEST
+}
 
 # All done.
 dg-finish
diff --git libgomp/testsuite/libgomp.oacc-c/c.exp libgomp/testsuite/libgomp.oacc-c/c.exp
index 326b988..03946a6 100644
--- libgomp/testsuite/libgomp.oacc-c/c.exp
+++ libgomp/testsuite/libgomp.oacc-c/c.exp
@@ -25,6 +25,8 @@ dg-init
 # Turn on OpenACC.
 lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
 
+lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST"
+
 # Gather a list of all tests.
 set tests [lsort [concat \
 		      [find $srcdir/$subdir *.c] \
@@ -39,6 +41,9 @@ set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
 foreach offload_target_openacc $offload_targets_s_openacc {
     set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
     set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
+    # Set $ACC_DEVICE_TYPE.  See the comments in
+    # ../lib/libgomp.exp:libgomp_init.
+    lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o"
 
     switch $offload_target_openacc {
 	host {
@@ -68,8 +73,6 @@ foreach offload_target_openacc $offload_targets_s_openacc {
     }
     set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
 
-    setenv ACC_DEVICE_TYPE $offload_target_openacc
-
     dg-runtest $tests "$tagopt" $DEFAULT_CFLAGS
 }
 
diff --git libgomp/testsuite/libgomp.oacc-fortran/fortran.exp libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
index a8aaff0..0814426 100644
--- libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
+++ libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
@@ -46,6 +46,11 @@ if { $blddir != "" } {
 }
 
 if { $lang_test_file_found } {
+    if ![info exists GFORTRAN_UNDER_TEST] then {
+	set GFORTRAN_UNDER_TEST $GCC_UNDER_TEST
+    }
+    lappend libgomp_compile_options "compiler=$GFORTRAN_UNDER_TEST"
+
     # Gather a list of all tests.
     set tests [lsort [find $srcdir/$subdir *.\[fF\]{,90,95,03,08}]]
 
@@ -66,8 +71,13 @@ if { $lang_test_file_found } {
     set_ld_library_path_env_vars
 
     # Test OpenACC with available accelerators.
+    set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
     foreach offload_target_openacc $offload_targets_s_openacc {
+	set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
 	set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
+	# Set $ACC_DEVICE_TYPE.  See the comments in
+	# ../lib/libgomp.exp:libgomp_init.
+	lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o"
 
 	switch $offload_target_openacc {
 	    host {
@@ -91,8 +101,6 @@ if { $lang_test_file_found } {
 	}
 	set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
 
-	setenv ACC_DEVICE_TYPE $offload_target_openacc
-
 	# For Fortran we're doing torture testing, as Fortran has far more tests
 	# with arrays etc. that testing just -O0 or -O2 is insufficient, that is
 	# typically not the case for C/C++.


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards
  2015-05-14  9:00             ` Jakub Jelinek
  2015-05-14  9:39               ` Jakub Jelinek
@ 2015-07-22  8:48               ` Thomas Schwinge
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Schwinge @ 2015-07-22  8:48 UTC (permalink / raw)
  To: Jakub Jelinek, Mike Stump; +Cc: gcc-patches, nathan

[-- Attachment #1: Type: text/plain, Size: 4176 bytes --]

Hi!

This is about communicating environment variables to the target for use
in (libgomp) execution testing.  In particular, the ACC_DEVICE_TYPE
environment variable to select at runtime which offloading device to use.
I had an ugly hack for that particular case,
<http://news.gmane.org/find-root.php?message_id=%3C87iobwjfh1.fsf%40schwinge.name%3E>,
but this is clearly not acceptable for commit.

On Thu, 14 May 2015 10:54:07 +0200, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, May 14, 2015 at 10:05:36AM +0200, Jakub Jelinek wrote:
> > On Thu, May 14, 2015 at 12:10:50AM +0200, Thomas Schwinge wrote:
> > >     No doubt, looking forward to the day, when this can be reverted.
> > >     
> > >     	libgomp/
> > >             * env.c (initialize_env): Remove static attribute.
> > >     	* libgomp.map (INTERNAL): Export initialize_env.
> > 
> > Ugh.  While you achieve what you want for the remote board cases,
> > doesn't this completely break all OpenMP and OpenACC programs not built
> > as part of the testsuite, because initialize_env won't be called in that case?

(No, it doesn't break them; initialize_env is still called as before.)

> Can't you just tweak *.exp files so that if dg-set-target-env-var is used
> or some forced env var is added to the same list through other means,

The patch adding that machinery,
<http://news.gmane.org/find-root.php?message_id=%3C20121203193645.GD2315%40tucnak.redhat.com%3E>
and thereabouts, just bails out for remote testing: the wrapper
gcc/testsuite/lib/gcc-dg.exp:${tool}_load does »if { [is_remote target] }
{ return [list "unsupported" ""]« if environment variables are to be set,
so test cases using dg-set-target-env-var are currently UNSUPPORTED in
case of remote testing.

> you invoke on the remo[t]e side env VAR1=val1 VAR2=val2 program arguments
> instead of program arguments ?

Yes, using a wrapper for the program invocation is an idea I had before,
and also what Mike suggested in
<http://news.gmane.org/find-root.php?message_id=%3C3147BE85-53E5-4E23-8887-6CA3D780431E%40comcast.net%3E>,
but implementing that is not exactly trivial as far as I can tell.

First, such a "env wrapper" is appropriate only for a certain class of
target systems (only for "Unix" systems, or something like that), so we
need a way (perferably automatic) to determine that property of the
target.

We can't do the wrapping in gcc/testsuite/lib/gcc-dg.exp:${tool}_load
because when that invokes the original *_load routine
(save_${tool}_load), its program argument will be checked for existence,
to be downloaded to the target, which in our case then would be the
wrapper executable (/usr/bin/env), which doesn't make sense/is not
correct/won't work.

Leaving aside the option of DejaGnu modifications as mentioned by Mike
(difficult to coordinate, deploy...), it seems that we can achieve what
we want by wrapping DejaGnu's remote_exec and remote_spawn procedures in
gcc/testsuite/lib/gcc-dg.exp, where we then can prepend the "env wrapper"
to the program and commandline strings, respectively.  But probably,
doing such wrapping if not exactly elegant, and apart from the question
whether it is appropriate to use an "env wrapper" for the execution at
stake (only for "Unix" systems), there is also a new problem: these
procedures are also invoked for host compilation, for example, in which
case we also don't want to set the "env wrapper".

Any clever ideas?


I can also back out, and follow the other idea that I had,
<http://news.gmane.org/find-root.php?message_id=%3C87sic2zpsz.fsf%40schwinge.name%3E>,
<http://news.gmane.org/find-root.php?message_id=%3C8761ekpu1h.fsf%40schwinge.name%3E>,
about ditching usage of the ACC_DEVICE_TYPE environment variable during
testing, and instead use -foffload=[...] during compilation to only
include offloading code in the executable for one particular device, so
that the runtime then only can offload to this particular device.  But of
course, that won't solve the general problem (other execution tests that
currently are UNSUPPORTED because of dg-set-target-env-var usage).


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* libgomp testing, RUNTESTFLAGS (was: [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards)
  2015-05-14  9:39               ` Jakub Jelinek
@ 2015-07-22  9:08                 ` Thomas Schwinge
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Schwinge @ 2015-07-22  9:08 UTC (permalink / raw)
  To: Jakub Jelinek, Cesar Philippidis; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 840 bytes --]

Hi!

(Cesar, you had the same question.)

On Thu, 14 May 2015 11:26:15 +0200, Jakub Jelinek <jakub@redhat.com> wrote:
> Talking about the libgomp testsuite, can we rename the
> libgomp/testsuite/libgomp-oacc-*/*.exp files to something unique?
> I mean, trying to run say just the OpenMP C tests is impossible since
> the OpenACC merge, because RUNTESTFLAGS=c.exp runs both OpenMP and OpenACC.

Hmm, I like it that c.exp in fact does run all C language tests, and so
on.

> If it was say acc-c.exp, then you can choose if you want to test just
> OpenACC, or just OpenMP, both, and which particular tests more accurately.

You can use RUNTESTFLAGS='libgomp.c/c.exp', or use runtest's --directory
option to restrict it to libgomp.c only, for example:
RUNTESTFLAGS='--directory libgomp.c c.exp=[...]'.


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-07-22  8:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5375D239.40605@mentor.com>
     [not found] ` <537644B1.6090600@mentor.com>
     [not found]   ` <87ppjd61ro.fsf@schwinge.name>
     [not found]     ` <87lho6rfr7.fsf@schwinge.name>
     [not found]       ` <87vbnaph0d.fsf@schwinge.name>
2015-05-13 22:46         ` [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards Thomas Schwinge
2015-05-14  8:10           ` Jakub Jelinek
2015-05-14  9:00             ` Jakub Jelinek
2015-05-14  9:39               ` Jakub Jelinek
2015-07-22  9:08                 ` libgomp testing, RUNTESTFLAGS (was: [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards) Thomas Schwinge
2015-07-22  8:48               ` [gomp4] libgomp: Cope with DejaGnu having no mechanism to transfer environment variables to remote boards Thomas Schwinge
     [not found]           ` <55A6652D.4090004@mentor.com>
2015-07-15 14:40             ` Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).