[libgomp,testsuite,nvptx] Limit recursion in declare_target-{1,2}.f90

Message ID 20220401112438.GA19247@delia
State Committed
Commit bfa9f660d25aef1513b1289d01c80b52090ef72a
Headers
Series [libgomp,testsuite,nvptx] Limit recursion in declare_target-{1,2}.f90 |

Commit Message

Tom de Vries April 1, 2022, 11:24 a.m. UTC
  Hi,

When running testcases libgomp.fortran/examples-4/declare_target-{1,2}.f90 on
an RTX A2000 (sm_86) with driver 510.60.02 and with GOMP_NVPTX_JIT=-O0 I run
into:
...
FAIL: libgomp.fortran/examples-4/declare_target-1.f90 -O0 \
  -DGOMP_NVPTX_JIT=-O0 execution test
FAIL: libgomp.fortran/examples-4/declare_target-2.f90 -O0 \
  -DGOMP_NVPTX_JIT=-O0 execution test
...

Fix this by further limiting recursion depth in the test-cases for nvptx.

Furthermore, make the recursion depth limiting nvptx-specific.

Tested on x86_64 with nvptx accelerator.

Any comments?

Thanks,
- Tom

[libgomp, testsuite, nvptx] Limit recursion in declare_target-{1,2}.f90

libgomp/ChangeLog:

2022-04-01  Tom de Vries  <tdevries@suse.de>

	* testsuite/libgomp.fortran/examples-4/declare_target-1.f90: Define
	and use REC_DEPTH.
	* testsuite/libgomp.fortran/examples-4/declare_target-2.f90: Same.

---
 .../libgomp.fortran/examples-4/declare_target-1.f90  | 18 +++++++++++++-----
 .../libgomp.fortran/examples-4/declare_target-2.f90  | 20 ++++++++++++++------
 2 files changed, 27 insertions(+), 11 deletions(-)
  

Comments

Jakub Jelinek April 1, 2022, 11:26 a.m. UTC | #1
On Fri, Apr 01, 2022 at 01:24:40PM +0200, Tom de Vries wrote:
> Hi,
> 
> When running testcases libgomp.fortran/examples-4/declare_target-{1,2}.f90 on
> an RTX A2000 (sm_86) with driver 510.60.02 and with GOMP_NVPTX_JIT=-O0 I run
> into:
> ...
> FAIL: libgomp.fortran/examples-4/declare_target-1.f90 -O0 \
>   -DGOMP_NVPTX_JIT=-O0 execution test
> FAIL: libgomp.fortran/examples-4/declare_target-2.f90 -O0 \
>   -DGOMP_NVPTX_JIT=-O0 execution test
> ...
> 
> Fix this by further limiting recursion depth in the test-cases for nvptx.
> 
> Furthermore, make the recursion depth limiting nvptx-specific.
> 
> Tested on x86_64 with nvptx accelerator.
> 
> Any comments?
> 
> Thanks,
> - Tom
> 
> [libgomp, testsuite, nvptx] Limit recursion in declare_target-{1,2}.f90
> 
> libgomp/ChangeLog:
> 
> 2022-04-01  Tom de Vries  <tdevries@suse.de>
> 
> 	* testsuite/libgomp.fortran/examples-4/declare_target-1.f90: Define
> 	and use REC_DEPTH.
> 	* testsuite/libgomp.fortran/examples-4/declare_target-2.f90: Same.

Ok.

	Jakub
  
Thomas Schwinge April 1, 2022, 12:28 p.m. UTC | #2
Hi Tom!

On 2022-04-01T13:24:40+0200, Tom de Vries <tdevries@suse.de> wrote:
> When running testcases libgomp.fortran/examples-4/declare_target-{1,2}.f90 on
> an RTX A2000 (sm_86) with driver 510.60.02 and with GOMP_NVPTX_JIT=-O0 I run
> into:
> ...
> FAIL: libgomp.fortran/examples-4/declare_target-1.f90 -O0 \
>   -DGOMP_NVPTX_JIT=-O0 execution test
> FAIL: libgomp.fortran/examples-4/declare_target-2.f90 -O0 \
>   -DGOMP_NVPTX_JIT=-O0 execution test
> ...
>
> Fix this by further limiting recursion depth in the test-cases for nvptx.
>
> Furthermore, make the recursion depth limiting nvptx-specific.

Careful:

> --- a/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90
> +++ b/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90
> @@ -1,4 +1,16 @@
>  ! { dg-do run }
> +! { dg-additional-options "-cpp" }
> +! Reduced from 25 to 23, otherwise execution runs out of thread stack on
> +! Nvidia Titan V.
> +! Reduced from 23 to 22, otherwise execution runs out of thread stack on
> +! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
> +! Reduced from 22 to 20, otherwise execution runs out of thread stack on
> +! Nvidia RTX A2000 (6GB variant), when run with GOMP_NVPTX_JIT=-O0.
> +! { dg-additional-options "-DREC_DEPTH=20" { target { offload_target_nvptx } } } */

'offload_target_nvptx' doesn't mean that offloading execution is done on
nvptx, but rather that we're "*compiling* for offload target nvptx"
(emphasis mine).  That means, with such a change we're now getting
different behavior in a system with an AMD GPU, when using a toolchain
that only has GCN offloading configured vs. a toolchain that has GCN and
nvptx offloading configured.  This isn't going to cause any real
problems, of course, but it's confusing, and a bad example of
'offload_target_nvptx'.

'offload_device_nvptx' ought to work: "using nvptx offload device".

But again, to keep things simple, I again suggest to unconditionally
reduce the recursion depth for all configurations, unless there exists an
actual rationale for the original value.


Grüße
 Thomas


> +
> +#ifndef REC_DEPTH
> +#define REC_DEPTH 25
> +#endif
>
>  module e_53_1_mod
>    integer :: THRESHOLD = 20
> @@ -27,9 +39,5 @@ end module
>  program e_53_1
>    use e_53_1_mod, only : fib, fib_wrapper
>    if (fib (15) /= fib_wrapper (15)) stop 1
> -  ! Reduced from 25 to 23, otherwise execution runs out of thread stack on
> -  ! Nvidia Titan V.
> -  ! Reduced from 23 to 22, otherwise execution runs out of thread stack on
> -  ! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
> -  if (fib (22) /= fib_wrapper (22)) stop 2
> +  if (fib (REC_DEPTH) /= fib_wrapper (REC_DEPTH)) stop 2
>  end program

> --- a/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90
> +++ b/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90
> @@ -1,16 +1,24 @@
>  ! { dg-do run }
> +! { dg-additional-options "-cpp" }
> +! Reduced from 25 to 23, otherwise execution runs out of thread stack on
> +! Nvidia Titan V.
> +! Reduced from 23 to 22, otherwise execution runs out of thread stack on
> +! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
> +! Reduced from 22 to 18, otherwise execution runs out of thread stack on
> +! Nvidia RTX A2000 (6GB variant), when run with GOMP_NVPTX_JIT=-O0.
> +! { dg-additional-options "-DREC_DEPTH=18" { target { offload_target_nvptx } } } */
> +
> +#ifndef REC_DEPTH
> +#define REC_DEPTH 25
> +#endif
>
>  program e_53_2
>    !$omp declare target (fib)
>    integer :: x, fib
>    !$omp target map(from: x)
> -    ! Reduced from 25 to 23, otherwise execution runs out of thread stack on
> -    ! Nvidia Titan V.
> -    ! Reduced from 23 to 22, otherwise execution runs out of thread stack on
> -    ! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
> -    x = fib (22)
> +    x = fib (REC_DEPTH)
>    !$omp end target
> -  if (x /= fib (22)) stop 1
> +  if (x /= fib (REC_DEPTH)) stop 1
>  end program
>
>  integer recursive function fib (n) result (f)
-----------------
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
  
Tom de Vries April 1, 2022, 3:34 p.m. UTC | #3
On 4/1/22 14:28, Thomas Schwinge wrote:
> Hi Tom!
> 
> On 2022-04-01T13:24:40+0200, Tom de Vries <tdevries@suse.de> wrote:
>> When running testcases libgomp.fortran/examples-4/declare_target-{1,2}.f90 on
>> an RTX A2000 (sm_86) with driver 510.60.02 and with GOMP_NVPTX_JIT=-O0 I run
>> into:
>> ...
>> FAIL: libgomp.fortran/examples-4/declare_target-1.f90 -O0 \
>>    -DGOMP_NVPTX_JIT=-O0 execution test
>> FAIL: libgomp.fortran/examples-4/declare_target-2.f90 -O0 \
>>    -DGOMP_NVPTX_JIT=-O0 execution test
>> ...
>>
>> Fix this by further limiting recursion depth in the test-cases for nvptx.
>>
>> Furthermore, make the recursion depth limiting nvptx-specific.
> 
> Careful:
> 
>> --- a/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90
>> +++ b/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90
>> @@ -1,4 +1,16 @@
>>   ! { dg-do run }
>> +! { dg-additional-options "-cpp" }
>> +! Reduced from 25 to 23, otherwise execution runs out of thread stack on
>> +! Nvidia Titan V.
>> +! Reduced from 23 to 22, otherwise execution runs out of thread stack on
>> +! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
>> +! Reduced from 22 to 20, otherwise execution runs out of thread stack on
>> +! Nvidia RTX A2000 (6GB variant), when run with GOMP_NVPTX_JIT=-O0.
>> +! { dg-additional-options "-DREC_DEPTH=20" { target { offload_target_nvptx } } } */
> 
> 'offload_target_nvptx' doesn't mean that offloading execution is done on
> nvptx, but rather that we're "*compiling* for offload target nvptx"
> (emphasis mine).  That means, with such a change we're now getting
> different behavior in a system with an AMD GPU, when using a toolchain
> that only has GCN offloading configured vs. a toolchain that has GCN and
> nvptx offloading configured.  This isn't going to cause any real
> problems, of course, but it's confusing, and a bad example of
> 'offload_target_nvptx'.
> 
> 'offload_device_nvptx' ought to work: "using nvptx offload device".
> 

Thanks for pointing that out.

I tried to understand this multiple offloading configuration a bit, and 
came up with the following mental model: it's possible to have a host 
with say an nvptx and amd offloading device, and then configure and 
build a toolchain that can generate a single executable that can offload 
to either device, depending on the value of appropriate openacc/openmp 
environment variables.

So, in principle the libgomp testsuite could have a mode in which it 
does that: run the same executable twice, once for each offloading 
device.  In that case, even using offload_device_nvptx would not be 
accurate enough, and we'd need to test for offload device type at 
runtime, as used to be done in 
libgomp/testsuite/libgomp.fortran/task-detach-6.f90.

I've tried to copy that setup to 
libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90, but 
that doesn't seem to work anymore.  I've also tried copying that 
test-case to 
libgomp/testsuite/libgomp.fortran/copy-of-declare_target-1.f90 to rule 
out any subdir-related problems, but no luck there either.

Attached is that copy approach, could you try it out and see if it works 
for you?

Do you perhaps have an idea why it's failing?

I can make a patch using offload_device_nvptx, but I'd prefer to 
understand first why the approach above isn't working.

Thanks,
- Tom
  
Jakub Jelinek April 1, 2022, 3:38 p.m. UTC | #4
On Fri, Apr 01, 2022 at 05:34:50PM +0200, Tom de Vries wrote:
> Do you perhaps have an idea why it's failing?

Because you call on_device_arch_nvptx () outside of
!$omp target region, so unless the host device is NVPTX,
it will not be true.

> +program e_53_1
> +  use e_53_1_mod, only : fib, fib_wrapper
> +  integer :: REC_DEPTH = 25
> +
> +  interface
> +    integer function on_device_arch_nvptx() bind(C)
> +    end function on_device_arch_nvptx
> +  end interface
> +
> +  if (on_device_arch_nvptx () /= 0) then
> +     ! Reduced from 25 to 23, otherwise execution runs out of thread stack on
> +     ! Nvidia Titan V.
> +     ! Reduced from 23 to 22, otherwise execution runs out of thread stack on
> +     ! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
> +     ! Reduced from 22 to 20, otherwise execution runs out of thread stack on
> +     ! Nvidia RTX A2000 (6GB variant), when run with GOMP_NVPTX_JIT=-O0.
> +     REC_DEPTH = 20
> +  end if
> +
> +  if (fib (15) /= fib_wrapper (15)) stop 1
> +  if (fib (REC_DEPTH) /= fib_wrapper (REC_DEPTH)) stop 2
> +end program

	Jakub
  
Tom de Vries April 1, 2022, 3:57 p.m. UTC | #5
On 4/1/22 17:38, Jakub Jelinek wrote:
> On Fri, Apr 01, 2022 at 05:34:50PM +0200, Tom de Vries wrote:
>> Do you perhaps have an idea why it's failing?
> 
> Because you call on_device_arch_nvptx () outside of
> !$omp target region, so unless the host device is NVPTX,
> it will not be true.
> 

That bit does works because on_device_arch_nvptx calls on_device_arch 
which contains the omp target bit:
...
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);
}
...

So I realized that I didn't do a good job of specifying the problem I 
encountered, and went looking at it, at which point I realized the error 
message had changed, and knew how to fix it ... So, my apologies, some 
confusion on my part.

Anyway, attached patch avoids any nvptx-related tcl directives (just for 
once test-case for now).  To me, this seems the most robust solution.

It this approach acceptable?

Thanks,
- Tom
  
Tom de Vries April 4, 2022, 11:05 a.m. UTC | #6
On 4/1/22 17:57, Tom de Vries wrote:
> On 4/1/22 17:38, Jakub Jelinek wrote:
>> On Fri, Apr 01, 2022 at 05:34:50PM +0200, Tom de Vries wrote:
>>> Do you perhaps have an idea why it's failing?
>>
>> Because you call on_device_arch_nvptx () outside of
>> !$omp target region, so unless the host device is NVPTX,
>> it will not be true.
>>
> 
> That bit does works because on_device_arch_nvptx calls on_device_arch 
> which contains the omp target bit:
> ...
> 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);
> }
> ...
> 
> So I realized that I didn't do a good job of specifying the problem I 
> encountered, and went looking at it, at which point I realized the error 
> message had changed, and knew how to fix it ... So, my apologies, some 
> confusion on my part.
> 
> Anyway, attached patch avoids any nvptx-related tcl directives (just for 
> once test-case for now).  To me, this seems the most robust solution.
> 
> It this approach acceptable?

I intend to commit this in a few days, unless there are objections.

Thanks,
- Tom
  
Jakub Jelinek April 4, 2022, 11:07 a.m. UTC | #7
On Mon, Apr 04, 2022 at 01:05:12PM +0200, Tom de Vries wrote:
> 2022-04-04  Tom de Vries  <tdevries@suse.de>
> 
> 	* testsuite/libgomp.fortran/examples-4/on_device_arch.c: Copy from
> 	parent dir.

Wouldn't just ! { dg-additional-sources ../on_device_arch.c }
work?

	Jakub
  
Tom de Vries April 4, 2022, 11:37 a.m. UTC | #8
On 4/4/22 13:07, Jakub Jelinek wrote:
> On Mon, Apr 04, 2022 at 01:05:12PM +0200, Tom de Vries wrote:
>> 2022-04-04  Tom de Vries  <tdevries@suse.de>
>>
>> 	* testsuite/libgomp.fortran/examples-4/on_device_arch.c: Copy from
>> 	parent dir.
> 
> Wouldn't just ! { dg-additional-sources ../on_device_arch.c }
> work?

I does, pushed with that update.

Thanks,
- Tom
  

Patch

diff --git a/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90 b/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90
index b761979ecde..03c5c53ed67 100644
--- a/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90
+++ b/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90
@@ -1,4 +1,16 @@ 
 ! { dg-do run }
+! { dg-additional-options "-cpp" }
+! Reduced from 25 to 23, otherwise execution runs out of thread stack on
+! Nvidia Titan V.
+! Reduced from 23 to 22, otherwise execution runs out of thread stack on
+! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
+! Reduced from 22 to 20, otherwise execution runs out of thread stack on
+! Nvidia RTX A2000 (6GB variant), when run with GOMP_NVPTX_JIT=-O0.
+! { dg-additional-options "-DREC_DEPTH=20" { target { offload_target_nvptx } } } */
+
+#ifndef REC_DEPTH
+#define REC_DEPTH 25
+#endif
 
 module e_53_1_mod
   integer :: THRESHOLD = 20
@@ -27,9 +39,5 @@  end module
 program e_53_1
   use e_53_1_mod, only : fib, fib_wrapper
   if (fib (15) /= fib_wrapper (15)) stop 1
-  ! Reduced from 25 to 23, otherwise execution runs out of thread stack on
-  ! Nvidia Titan V.
-  ! Reduced from 23 to 22, otherwise execution runs out of thread stack on
-  ! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
-  if (fib (22) /= fib_wrapper (22)) stop 2
+  if (fib (REC_DEPTH) /= fib_wrapper (REC_DEPTH)) stop 2
 end program
diff --git a/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90 b/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90
index f576c25ba39..0e8bea578a8 100644
--- a/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90
+++ b/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90
@@ -1,16 +1,24 @@ 
 ! { dg-do run }
+! { dg-additional-options "-cpp" }
+! Reduced from 25 to 23, otherwise execution runs out of thread stack on
+! Nvidia Titan V.
+! Reduced from 23 to 22, otherwise execution runs out of thread stack on
+! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
+! Reduced from 22 to 18, otherwise execution runs out of thread stack on
+! Nvidia RTX A2000 (6GB variant), when run with GOMP_NVPTX_JIT=-O0.
+! { dg-additional-options "-DREC_DEPTH=18" { target { offload_target_nvptx } } } */
+
+#ifndef REC_DEPTH
+#define REC_DEPTH 25
+#endif
 
 program e_53_2
   !$omp declare target (fib)
   integer :: x, fib
   !$omp target map(from: x)
-    ! Reduced from 25 to 23, otherwise execution runs out of thread stack on
-    ! Nvidia Titan V.
-    ! Reduced from 23 to 22, otherwise execution runs out of thread stack on
-    ! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
-    x = fib (22)
+    x = fib (REC_DEPTH)
   !$omp end target
-  if (x /= fib (22)) stop 1
+  if (x /= fib (REC_DEPTH)) stop 1
 end program
 
 integer recursive function fib (n) result (f)