public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas@codesourcery.com>
To: Tobias Burnus <tobias@codesourcery.com>, <gcc-patches@gcc.gnu.org>
Cc: Jakub Jelinek <jakub@redhat.com>
Subject: Re: Enhance 'libgomp.c-c++-common/requires-4.c', 'libgomp.c-c++-common/requires-5.c' testing (was: [Patch][v4] OpenMP: Move omp requires checks to libgomp)
Date: Thu, 7 Jul 2022 12:42:20 +0200	[thread overview]
Message-ID: <87wncp5hmb.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <92609eba-2c1b-99b4-c44d-99c438fabb59@codesourcery.com>

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

Hi Tobias!

On 2022-07-07T11:36:34+0200, Tobias Burnus <tobias@codesourcery.com> wrote:
> On 07.07.22 10:42, Thomas Schwinge wrote:
>> In preparation for other changes:
> ...
>> On 2022-06-29T16:33:02+0200, Tobias Burnus<tobias@codesourcery.com>  wrote:
>>> +/* { dg-output "devices present but 'omp requires unified_address, unified_shared_memory, reverse_offload' cannot be fulfilled" } */
>> (The latter diagnostic later got conditionalized by 'GOMP_DEBUG=1'.)
>> OK to push the attached "Enhance 'libgomp.c-c++-common/requires-4.c',
>> 'libgomp.c-c++-common/requires-5.c' testing"?
> ...
>>      libgomp/
>>      * testsuite/libgomp.c-c++-common/requires-4.c: Enhance testing.
>>      * testsuite/libgomp.c-c++-common/requires-5.c: Likewise.
> ...
>> --- a/libgomp/testsuite/libgomp.c-c++-common/requires-4.c
>> +++ b/libgomp/testsuite/libgomp.c-c++-common/requires-4.c
>> @@ -1,22 +1,29 @@
>> -/* { dg-do link { target offloading_enabled } } */
>>   /* { dg-additional-options "-flto" } */
>>   /* { dg-additional-sources requires-4-aux.c } */
>>
>> -/* Check diagnostic by device-compiler's or host compiler's lto1.
>> +/* Check no diagnostic by device-compiler's or host compiler's lto1.
>
> I note that without ENABLE_OFFLOADING that there is never any lto1
> diagnostic.
>
> However, given that no diagnostic is expected, it also works for "!
> offloading_enabled".
>
> Thus, the change fine.

ACK.

>>      Other file uses: 'requires reverse_offload', but that's inactive as
>>      there are no declare target directives, device constructs nor device routines  */
>>
>> +/* For actual offload execution, prints the following (only) if GOMP_DEBUG=1:
>> +   "devices present but 'omp requires unified_address, unified_shared_memory, reverse_offload' cannot be fulfilled"
>> +   and does host-fallback execution.  */
>
> The latter is only true when also device code is produced – and a device
> is available for that/those device types. I think that's what you imply
> by "For actual offload execution"

ACK.

> but it is a bit hidden.
>
> Maybe s/For actual offload execution, prints/It may print/ is clearer?

I've settled on:

    /* Depending on offload device capabilities, it may print something like the
       following (only) if GOMP_DEBUG=1:
       "devices present but 'omp requires unified_address, unified_shared_memory, reverse_offload' cannot be fulfilled"
       and in that case does host-fallback execution.  */

> In principle, it would be nice if we could test for the output, but
> currently setting an env var for remote execution does not work, yet.
> Cf. https://gcc.gnu.org/pipermail/gcc-patches/2022-July/597773.html

Right, I'm aware of that issue with remote testing, and that's why I
didn't propose such output verification.  (In a few other test cases, we
do have 'dg-set-target-env-var GOMP_DEBUG "1"', which then at present are
UNSUPPORTED for remote testing.)

> When set, we could use offload_target_nvptx etc. (..._amdgcn, ..._any)
> to test – as this guarantees that it is compiled for that device + the
> device is available.

Use 'target offload_device_nvptx', not 'target offload_target_nvptx',
etc.  ;-)

>> +
>>   #pragma omp requires unified_address,unified_shared_memory
>>
>> -int a[10];
>> +int a[10] = { 0 };
>>   extern void foo (void);
>>
>>   int
>>   main (void)
>>   {
>> -  #pragma omp target
>> +  #pragma omp target map(to: a)
>
> Hmm, I wonder whether I like it or not. Without, there is an implicit
> "map(tofrom:a)". On the other hand, OpenMP permits that – even with
> unified-shared memory – the implementation my copy the data to the
> device. (For instance, to permit faster access to "a".)
>
> Thus, ...
>
>> +  for (int i = 0; i < 10; i++)
>> +    a[i] = i;
>> +
>>     for (int i = 0; i < 10; i++)
>> -    a[i] = 0;
>> +    if (a[i] != i)
>> +      __builtin_abort ();
> ... this condition (back on the host) could also fail with USM. However,
> given that to my knowledge no USM implementation actually copies the
> data, I believe it is fine.

Right, this is meant to describe/test the current GCC master branch
behavior, where USM isn't supported, so I didn't consider that.  But I
agree, a source code comment should be added:

       As no offload devices support USM at present, we may verify host-fallback
       execution by absence of separate memory spaces.  */

> (Disclaimer: I have not checked what OG12,
> but I guess it also does not copy it.)

>> --- a/libgomp/testsuite/libgomp.c-c++-common/requires-5.c
>> +++ b/libgomp/testsuite/libgomp.c-c++-common/requires-5.c
>> @@ -1,21 +1,25 @@
>> -/* { dg-do run { target { offload_target_nvptx || offload_target_amdgcn } } } */
>>   /* { dg-additional-sources requires-5-aux.c } */
>>
>> +/* For actual offload execution, prints the following (only) if GOMP_DEBUG=1:
>> +   "devices present but 'omp requires unified_address, unified_shared_memory, reverse_offload' cannot be fulfilled"
>> +   and does host-fallback execution.  */
>> +
> This wording is correct with the now-removed check – but if you remove
> the offload_target..., it only "might" print it, depending, well, on the
> conditions set by offload_target...
>>   #pragma omp requires unified_shared_memory, unified_address, reverse_offload
>>
>> -int a[10];
>> +int a[10] = { 0 };
>>   extern void foo (void);
>>
>>   int
>>   main (void)
>>   {
>> -  #pragma omp target
>> +  #pragma omp target map(to: a)
>> +  for (int i = 0; i < 10; i++)
>> +    a[i] = i;
>> +
>>     for (int i = 0; i < 10; i++)
>> -    a[i] = 0;
>> +    if (a[i] != i)
>> +      __builtin_abort ();
>>
>>     foo ();
>>     return 0;
>>   }
>
> Thus: LGTM, if you update the GOMP_DEBUG=... wording, either using
> "might" (etc.) or by being more explicit.

Used the wording as in 'libgomp.c-c++-common/requires-4.c'.

Thanks for the review!  Pushed to master branch
commit 5647e2c3853cbd51a6536a84b8eb0eb3c210dfbf
"Enhance 'libgomp.c-c++-common/requires-4.c',
'libgomp.c-c++-common/requires-5.c' testing", see attached.


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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Enhance-libgomp.c-c-common-requires-4.c-libgomp.c-c-.patch --]
[-- Type: text/x-diff, Size: 3791 bytes --]

From 5647e2c3853cbd51a6536a84b8eb0eb3c210dfbf Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 7 Jul 2022 09:45:42 +0200
Subject: [PATCH] Enhance 'libgomp.c-c++-common/requires-4.c',
 'libgomp.c-c++-common/requires-5.c' testing

These should compile and link and execute in all configurations; host-fallback
execution, which we may actually verify.

Follow-up to recent commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0
"OpenMP: Move omp requires checks to libgomp".

	libgomp/
	* testsuite/libgomp.c-c++-common/requires-4.c: Enhance testing.
	* testsuite/libgomp.c-c++-common/requires-5.c: Likewise.
---
 .../libgomp.c-c++-common/requires-4.c         | 21 +++++++++++++-----
 .../libgomp.c-c++-common/requires-5.c         | 22 +++++++++++++------
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/libgomp/testsuite/libgomp.c-c++-common/requires-4.c b/libgomp/testsuite/libgomp.c-c++-common/requires-4.c
index 128fdbb8463..6ed5a5f647a 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/requires-4.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/requires-4.c
@@ -1,22 +1,33 @@
-/* { dg-do link { target offloading_enabled } } */
 /* { dg-additional-options "-flto" } */
 /* { dg-additional-sources requires-4-aux.c } */
 
-/* Check diagnostic by device-compiler's or host compiler's lto1.
+/* Check no diagnostic by device-compiler's or host compiler's lto1.
    Other file uses: 'requires reverse_offload', but that's inactive as
    there are no declare target directives, device constructs nor device routines  */
 
+/* Depending on offload device capabilities, it may print something like the
+   following (only) if GOMP_DEBUG=1:
+   "devices present but 'omp requires unified_address, unified_shared_memory, reverse_offload' cannot be fulfilled"
+   and in that case does host-fallback execution.
+
+   No offload devices support USM at present, so we may verify host-fallback
+   execution by presence of separate memory spaces.  */
+
 #pragma omp requires unified_address,unified_shared_memory
 
-int a[10];
+int a[10] = { 0 };
 extern void foo (void);
 
 int
 main (void)
 {
-  #pragma omp target
+  #pragma omp target map(to: a)
+  for (int i = 0; i < 10; i++)
+    a[i] = i;
+
   for (int i = 0; i < 10; i++)
-    a[i] = 0;
+    if (a[i] != i)
+      __builtin_abort ();
 
   foo ();
   return 0;
diff --git a/libgomp/testsuite/libgomp.c-c++-common/requires-5.c b/libgomp/testsuite/libgomp.c-c++-common/requires-5.c
index c1e5540cfc5..7fe0c735d27 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/requires-5.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/requires-5.c
@@ -1,21 +1,29 @@
-/* { dg-do run { target { offload_target_nvptx || offload_target_amdgcn } } } */
 /* { dg-additional-sources requires-5-aux.c } */
 
+/* Depending on offload device capabilities, it may print something like the
+   following (only) if GOMP_DEBUG=1:
+   "devices present but 'omp requires unified_address, unified_shared_memory, reverse_offload' cannot be fulfilled"
+   and in that case does host-fallback execution.
+
+   As no offload devices support USM at present, we may verify host-fallback
+   execution by absence of separate memory spaces.  */
+
 #pragma omp requires unified_shared_memory, unified_address, reverse_offload
 
-int a[10];
+int a[10] = { 0 };
 extern void foo (void);
 
 int
 main (void)
 {
-  #pragma omp target
+  #pragma omp target map(to: a)
   for (int i = 0; i < 10; i++)
-    a[i] = 0;
+    a[i] = i;
+
+  for (int i = 0; i < 10; i++)
+    if (a[i] != i)
+      __builtin_abort ();
 
   foo ();
   return 0;
 }
-
-/* (Only) if GOMP_DEBUG=1, should print at runtime the following:
-   "devices present but 'omp requires unified_address, unified_shared_memory, reverse_offload' cannot be fulfilled" */
-- 
2.35.1


  reply	other threads:[~2022-07-07 10:42 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 15:07 [PATCH, OpenMP 5.0] More implementation of the requires directive Chung-Lin Tang
2021-01-13 15:27 ` Jakub Jelinek
2021-03-25 11:18 ` Thomas Schwinge
2022-03-29 13:42 ` Andrew Stubbs
2022-06-08  3:56 ` [Patch] OpenMP: Move omp requires checks to libgomp Tobias Burnus
2022-06-09 11:40   ` Jakub Jelinek
2022-06-09 12:46     ` Tobias Burnus
2022-06-09 14:19       ` Jakub Jelinek
2022-06-29 14:33         ` [Patch][v4] " Tobias Burnus
2022-06-29 17:02           ` Jakub Jelinek
2022-06-29 18:10             ` Tobias Burnus
2022-06-29 20:18               ` Jakub Jelinek
2022-07-01 13:06                 ` [Patch][v5] " Tobias Burnus
2022-07-01 14:34                   ` Jakub Jelinek
2022-07-01 16:31                     ` Tobias Burnus
2022-07-01 16:55                       ` Jakub Jelinek
2022-07-01 21:08                         ` Tobias Burnus
2022-07-04  8:31                           ` Jakub Jelinek
2022-07-07 13:26                           ` Fix one issue in OpenMP 'requires' directive diagnostics (was: [Patch][v5] OpenMP: Move omp requires checks to libgomp) Thomas Schwinge
2022-07-07 13:56                             ` Tobias Burnus
2022-07-08  6:59                               ` Thomas Schwinge
2022-07-06 10:42                   ` Restore 'GOMP_offload_unregister_ver' functionality " Thomas Schwinge
2022-07-06 13:59                     ` Tobias Burnus
2022-07-06 21:08                       ` Thomas Schwinge
2022-08-17 11:45                       ` Jakub Jelinek
2023-09-15  9:41                   ` [Patch][v5] OpenMP: Move omp requires checks to libgomp Thomas Schwinge
2022-07-07  8:37           ` Adjust 'libgomp.c-c++-common/requires-3.c' (was: [Patch][v4] OpenMP: Move omp requires checks to libgomp) Thomas Schwinge
2022-07-07  9:02             ` Tobias Burnus
2022-07-07  8:42           ` Enhance 'libgomp.c-c++-common/requires-4.c', 'libgomp.c-c++-common/requires-5.c' testing " Thomas Schwinge
2022-07-07  9:36             ` Tobias Burnus
2022-07-07 10:42               ` Thomas Schwinge [this message]
2022-07-06 10:30   ` Define 'OMP_REQUIRES_[...]', 'GOMP_REQUIRES_[...]' in a single place (was: [Patch] " Thomas Schwinge
2022-07-06 13:40     ` Tobias Burnus
2022-07-06 11:04   ` Fix Intel MIC 'mkoffload' for OpenMP 'requires' " Thomas Schwinge
2022-07-06 11:29     ` Tobias Burnus
2022-07-06 12:38       ` Thomas Schwinge
2022-07-06 13:30         ` Tobias Burnus
2022-07-07 10:46           ` Thomas Schwinge
2022-07-06 14:19     ` Tobias Burnus
2024-03-07 12:38   ` nvptx: 'cuDeviceGetCount' failure is fatal " Thomas Schwinge
2024-03-07 14:28     ` nvptx: 'cuDeviceGetCount' failure is fatal Tobias Burnus
2024-03-08 15:58       ` Thomas Schwinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wncp5hmb.fsf@euler.schwinge.homeip.net \
    --to=thomas@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=tobias@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).