[committed] openmp: Implement the error directive

Thomas Schwinge thomas@codesourcery.com
Fri Aug 20 13:54:34 GMT 2021


Hi Jakub!

On 2021-08-20T15:21:12+0200, Jakub Jelinek <jakub@redhat.com> wrote:
> On Fri, Aug 20, 2021 at 03:11:45PM +0200, Thomas Schwinge wrote:
>> > --- libgomp/error.c.jj        2021-08-19 12:53:44.693106618 +0200
>> > +++ libgomp/error.c   2021-08-19 17:58:55.633203432 +0200
>>
>> > +void
>> > +GOMP_warning (const char *msg, size_t msglen)
>> > +{
>> > +  if (msg && msglen == (size_t) -1)
>> > +    gomp_error ("error directive encountered: %s", msg);
>> > +  else if (msg)
>> > +    {
>> > +      fputs ("\nlibgomp: error directive encountered: ", stderr);
>> > +      fwrite (msg, 1, msglen, stderr);
>> > +      fputc ('\n', stderr);
>> > +    }
>> > +  else
>> > +    gomp_error ("error directive encountered");
>> > +}
>> > +
>> > +void
>> > +GOMP_error (const char *msg, size_t msglen)
>> > +{
>> > +  if (msg && msglen == (size_t) -1)
>> > +    gomp_fatal ("fatal error: error directive encountered: %s", msg);
>> > +  else if (msg)
>> > +    {
>> > +      fputs ("\nlibgomp: fatal error: error directive encountered: ", stderr);
>> > +      fwrite (msg, 1, msglen, stderr);
>> > +      fputc ('\n', stderr);
>> > +      exit (EXIT_FAILURE);
>> > +    }
>> > +  else
>> > +    gomp_fatal ("fatal error: error directive encountered");
>> > +}
>>
>> At least for nvptx offloading, and at least given the newlib sources I'm
>> using, the 'fputs'/'fwrite' calls here drag in 'isatty', which isn't
>> provided by my nvptx newlib at present, so we get, for example:
>
> fputs/fputc/vfprintf/exit/stderr have been in use by error.c already before,
> so this must be the fwrite call.

ACK.

> The above is for Fortran which doesn't have zero terminated strings.
> Initially I wanted to use instead ... encountered: %.*s", (int) msglen, stderr);
> which doesn't handle > 2GB messages, but with offloading who cares, nobody
> sane would be trying to print > 2GB messages from offloading regions.

(... likewise from the host...)  ;-)

> The question is if it should be achieved through copy of error.c in
> config/nvptx/, or just include_next there with say fwrite redefined as a
> macro that does fprintf ("%.*s", (int) msglen, msg, file)?

(Right, that was also my plan.)

| Ah, I just re-discovered 'libgomp/config/nvptx/error.c' -- I'll cook
| something up.

So, guess what this newlib 'printf ("%.*s", [...]);' prints?
Yes: literal '%.*s'...  Next try: a 'fputc' loop?

See attached "[WIP] Make the OpenMP 'error' directive work for nvptx
offloading".

>> Now, there are many ways of addressing this...  The most simple one:
>> conditionalize these 'GOMP_warning'/'GOMP_error' definitions on
>> '#ifndef LIBGOMP_OFFLOADED_ONLY' is not possible here, because it's
>> permissible to use the 'error' directive also inside 'target' regions, as
>> far as I can tell?
>
> !$omp error at(execution) message('whatever')
> can be used in offloading regions.

Yes, generally works, but at least for Fortran, 'severity (fatal)' seems
to cause a hang, so another thing to be looked into...


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-WIP-Make-the-OpenMP-error-directive-work-for-nvptx-o.patch
Type: text/x-diff
Size: 4771 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210820/072768c3/attachment-0001.bin>


More information about the Gcc-patches mailing list