[committed] libgomp/testsuite: Improve omp_get_device_num() tests (was: Re: [PATCH, OpenMP, libgomp, committed] Fix GOMP_DEVICE_NUM_VAR stringification error)

Message ID 77fb4ef2-f2e8-5b79-aca4-085311d33a8b@codesourcery.com
State Committed
Headers
Series [committed] libgomp/testsuite: Improve omp_get_device_num() tests (was: Re: [PATCH, OpenMP, libgomp, committed] Fix GOMP_DEVICE_NUM_VAR stringification error) |

Commit Message

Tobias Burnus Jan. 4, 2022, 2:12 p.m. UTC
  On 04.01.22 10:28, Chung-Lin Tang wrote:

> In the patch that implemented omp_get_device_num(), there was an error
> where
> the stringification of GOMP_DEVICE_NUM_VAR, ...

... which caused that omp_get_device() == 0 (always) on nvptx/gcn.

That's fine if there is only a single non-host device (as often the
case), but not if there are multiples.

This commit r12-6209 now makes the testcases iterate over all devices
(including the initial/host device).

Hence, with multiple non-host devices and this test, the error had been
found before ... ;-)

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Comments

Thomas Schwinge Jan. 13, 2022, 12:22 p.m. UTC | #1
Hi!

On 2022-01-04T15:12:58+0100, Tobias Burnus <tobias@codesourcery.com> wrote:
> This commit r12-6209 now makes the testcases iterate over all devices
> (including the initial/host device).
>
> Hence, with multiple non-host devices and this test, the error had been
> found before ... ;-)

Yay for test cases!  :-)

... but we now run into issues if Intel MIC (emulated) offloading is
(additionally) enabled, because that one still doesn't properly implement
device-side 'omp_get_device_num'.  ;-)

Thus pushed to master branch
commit d97364aab1af361275b87713154c366ce2b9029a
"Improve Intel MIC offloading XFAILing for 'omp_get_device_num'", see
attached.

(It wasn't obvious to me how to implement that; very incomplete
"[WIP] Intel MIC 'omp_get_device_num'" attached, not planning on working
on this any further.)


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Patch

commit be661959a6b6d8f9c3c8608a746789e7b2ec3ca4
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Tue Jan 4 14:58:06 2022 +0100

    libgomp/testsuite: Improve omp_get_device_num() tests
    
    Related to r12-6208-gebc853deb7cc0487de9ef6e891a007ba853d1933
    "libgomp: Fix GOMP_DEVICE_NUM_VAR stringification during offload image load"
    
    That commit fixed an issue with omp_get_device_num() on gcn/nvptx that
    resulted in having always the value 0.
    This commit modifies the tests to iterate over all devices such that on a
    multi-nonhost-device system it had detected that always-zero issue.
    
    libgomp/ChangeLog:
    
            * testsuite/libgomp.c-c++-common/target-45.c: Iterate over all devices.
            * testsuite/libgomp.fortran/target10.f90: Likewise.

diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-45.c b/libgomp/testsuite/libgomp.c-c++-common/target-45.c
index 81acee81064..837503996d7 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/target-45.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-45.c
@@ -14,17 +14,23 @@  int main (void)
   int device_num;
   int initial_device;
 
-  #pragma omp target map(from: device_num, initial_device)
-  {
-    initial_device = omp_is_initial_device ();
-    device_num = omp_get_device_num ();
-  }
-
-  if (initial_device && host_device_num != device_num)
-    abort ();
-
-  if (!initial_device && host_device_num == device_num)
-    abort ();
+  for (int i = 0; i <= omp_get_num_devices (); i++)
+    {
+      #pragma omp target map(from: device_num, initial_device) device(i)
+	{
+	  initial_device = omp_is_initial_device ();
+	  device_num = omp_get_device_num ();
+	}
+
+      if (i != device_num)
+	abort ();
+
+      if (initial_device && host_device_num != device_num)
+	abort ();
+
+      if (!initial_device && host_device_num == device_num)
+	abort ();
+    }
 
   return 0;
 }
diff --git a/libgomp/testsuite/libgomp.fortran/target10.f90 b/libgomp/testsuite/libgomp.fortran/target10.f90
index f41a726de75..f6951fc9057 100644
--- a/libgomp/testsuite/libgomp.fortran/target10.f90
+++ b/libgomp/testsuite/libgomp.fortran/target10.f90
@@ -4,18 +4,20 @@ 
 program main
   use omp_lib
   implicit none
-  integer :: device_num, host_device_num
+  integer :: device_num, host_device_num, i
   logical :: initial_device
 
   host_device_num = omp_get_device_num ()
   if (host_device_num .ne. omp_get_initial_device ()) stop 1
 
-  !$omp target map(from: device_num, initial_device)
-  initial_device = omp_is_initial_device ()
-  device_num = omp_get_device_num ()
-  !$omp end target
-
-  if (initial_device .and. (host_device_num .ne. device_num)) stop 2
-  if ((.not. initial_device) .and. (host_device_num .eq. device_num)) stop 3
+  do i = 0, omp_get_num_devices ()
+    !$omp target map(from: device_num, initial_device) device(i)
+      initial_device = omp_is_initial_device ()
+      device_num = omp_get_device_num ()
+    !$omp end target
+    if (i /= device_num) stop 2
+    if (initial_device .and. (host_device_num .ne. device_num)) stop 3
+    if ((.not. initial_device) .and. (host_device_num .eq. device_num)) stop 4
+  end do
 
 end program main