diff mbox

[1/5] OpenACC 2.0 support for libgomp - OpenACC runtime, NVidia PTX/CUDA plugin (repost)

Message ID 87egrry1on.fsf@kepler.schwinge.homeip.net
State New
Headers show

Commit Message

Thomas Schwinge Dec. 22, 2014, 6:33 p.m. UTC
Hi!

On Tue, 11 Nov 2014 13:53:23 +0000, Julian Brown <julian@codesourcery.com> wrote:
> On Tue, 23 Sep 2014 19:19:31 +0100
> Julian Brown <julian@codesourcery.com> wrote:
> 
> > This patch contains the bulk of the OpenACC 2.0 runtime support,
> > building around, or on top of, the OpenMP 4.0 support (as previously
> > posted or already extant upstream) where we could. [...]
> 
> Here is a new version of the OpenACC support patch for libgomp, [...]

> --- a/libgomp/target.c
> +++ b/libgomp/target.c

> @@ -920,6 +1111,43 @@ gomp_target_init (void)
>        }
>      while (next);
>  
> +  /* Prefer a device with TARGET_CAP_OPENMP_400 for ICV default-device-var.  */
> +  if (num_devices > 1)
> +    {
> +      int d = gomp_icv (false)->default_device_var;
> +
> +      if (!(devices[d].capabilities & TARGET_CAP_OPENMP_400))
> +	{
> +	  for (i = 0; i < num_devices; i++)
> +	    {
> +	      if (devices[i].capabilities & TARGET_CAP_OPENMP_400)
> +		{
> +		  struct gomp_device_descr device_tmp = devices[d];
> +		  devices[d] = devices[i];
> +		  devices[d].id = d + 1;
> +		  devices[i] = device_tmp;
> +		  devices[i].id = i + 1;
> +
> +		  break;
> +		}
> +	    }
> +	}
> +    }

A thinko of mine; committed to gomp-4_0-branch in r219029:

commit 806b4f5eed613a43bf52082816469268df0ed9a5
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Mon Dec 22 18:31:42 2014 +0000

    libgomp: For OpenMP offloading, only publicize GOMP_OFFLOAD_CAP_OPENMP_400 devices.
    
    	libgomp/
    	* target.c (num_devices_openmp): New variable.
    	(gomp_get_num_devices): Use it.
    	(gomp_target_init): Initialize it, and sort the devices array
    	appropriately.
    
    With Intel MIC offloading (emulation), this fixes:
    
        FAIL: libgomp.c/examples-4/e.57.2.c execution test
        FAIL: libgomp.fortran/examples-4/e.57.2.f90   -O0  execution test
        FAIL: libgomp.fortran/examples-4/e.57.2.f90   -O1  execution test
        FAIL: libgomp.fortran/examples-4/e.57.2.f90   -O2  execution test
        FAIL: libgomp.fortran/examples-4/e.57.2.f90   -O3 -fomit-frame-pointer  execution test
        FAIL: libgomp.fortran/examples-4/e.57.2.f90   -O3 -fomit-frame-pointer -funroll-loops  execution test
        FAIL: libgomp.fortran/examples-4/e.57.2.f90   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions  execution test
        FAIL: libgomp.fortran/examples-4/e.57.2.f90   -O3 -g  execution test
        FAIL: libgomp.fortran/examples-4/e.57.2.f90   -Os  execution test
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@219029 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog.gomp |  5 +++++
 libgomp/target.c       | 52 ++++++++++++++++++++++++++++----------------------
 2 files changed, 34 insertions(+), 23 deletions(-)



Grüße,
 Thomas
diff mbox

Patch

diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index eabf737..b9bd024 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,5 +1,10 @@ 
 2014-12-22  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* target.c (num_devices_openmp): New variable.
+	(gomp_get_num_devices): Use it.
+	(gomp_target_init): Initialize it, and sort the devices array
+	appropriately.
+
 	* libgomp.h (struct gomp_device_descr): Remove id member.  Update
 	all users.
 
diff --git libgomp/target.c libgomp/target.c
index 226b95b..bf6edd2 100644
--- libgomp/target.c
+++ libgomp/target.c
@@ -67,6 +67,9 @@  static struct gomp_device_descr *devices;
 /* Total number of available devices.  */
 static int num_devices;
 
+/* Number of GOMP_OFFLOAD_CAP_OPENMP_400 devices.  */
+static int num_devices_openmp;
+
 /* The comparison function.  */
 
 attribute_hidden int
@@ -94,7 +97,7 @@  attribute_hidden int
 gomp_get_num_devices (void)
 {
   gomp_init_targets_once ();
-  return num_devices;
+  return num_devices_openmp;
 }
 
 static struct gomp_device_descr *
@@ -1048,9 +1051,11 @@  gomp_register_image_for_device (struct gomp_device_descr *device,
 }
 
 /* This function initializes the runtime needed for offloading.
-   It parses the list of offload targets and tries to load the plugins for these
-   targets.  Result of the function is properly initialized variable NUM_DEVICES
-   and array DEVICES, containing descriptors for corresponding devices.  */
+   It parses the list of offload targets and tries to load the plugins for
+   these targets.  On return, the variables NUM_DEVICES and NUM_DEVICES_OPENMP
+   will be set, and the array DEVICES initialized, containing descriptors for
+   corresponding devices, first the GOMP_OFFLOAD_CAP_OPENMP_400 ones, follows
+   by the others.  */
 
 static void
 gomp_target_init (void)
@@ -1089,6 +1094,8 @@  gomp_target_init (void)
 	    new_num_devices = current_device.get_num_devices_func ();
 	    if (new_num_devices >= 1)
 	      {
+		/* Augment DEVICES and NUM_DEVICES.  */
+
 		devices = realloc (devices, (num_devices + new_num_devices)
 				   * sizeof (struct gomp_device_descr));
 		if (!devices)
@@ -1121,27 +1128,26 @@  gomp_target_init (void)
       }
     while (next);
 
-  /* Prefer a device with GOMP_OFFLOAD_CAP_OPENMP_400 for ICV
-     default-device-var.  */
-  if (num_devices > 1)
+  /* In DEVICES, sort the GOMP_OFFLOAD_CAP_OPENMP_400 ones first, and set
+     NUM_DEVICES_OPENMP.  */
+  struct gomp_device_descr *devices_s
+    = malloc (num_devices * sizeof (struct gomp_device_descr));
+  if (!devices_s)
     {
-      int d = gomp_icv (false)->default_device_var;
-
-      if (!(devices[d].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400))
-	{
-	  for (i = 0; i < num_devices; i++)
-	    {
-	      if (devices[i].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400)
-		{
-		  struct gomp_device_descr device_tmp = devices[d];
-		  devices[d] = devices[i];
-		  devices[i] = device_tmp;
-
-		  break;
-		}
-	    }
-	}
+      num_devices = 0;
+      free (devices);
+      devices = NULL;
     }
+  num_devices_openmp = 0;
+  for (i = 0; i < num_devices; i++)
+    if (devices[i].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400)
+      devices_s[num_devices_openmp++] = devices[i];
+  int num_devices_after_openmp = num_devices_openmp;
+  for (i = 0; i < num_devices; i++)
+    if (!(devices[i].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400))
+      devices_s[num_devices_after_openmp++] = devices[i];
+  free (devices);
+  devices = devices_s;
 
   for (i = 0; i < num_devices; i++)
     {