public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/106316] New: [OpenMP] Auto "declare target" should honor  'declare variant'  kind(nohost)
@ 2022-07-15 15:34 burnus at gcc dot gnu.org
  2022-07-26 12:18 ` [Bug middle-end/106316] " jakub at gcc dot gnu.org
  2022-11-03 16:10 ` burnus at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2022-07-15 15:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106316

            Bug ID: 106316
           Summary: [OpenMP] Auto "declare target" should honor  'declare
                    variant'  kind(nohost)
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: openmp
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

The following fails during device lto1 with:

ld: error: undefined symbol: external
>>> referenced by decl-var.c:3
>>>               /tmp/cc6C3J6T.o:(onhost)

However, 'external' is never executed on the device.

This seems to be more a 'declare variant' tagging issue than a symbol issue
as it works when keeping only
  int onhost(void);  /* Only declaration, no definition */
in the second file (and having the definition alongside 'external' in the
first).
→ omp_discover_declare_target_tgt_fn_r, omp_discover_declare_target_fn_r
functions.

---- First file. Compile with 'gcc -c first.c' ------
void external(void)
{
  __builtin_printf("Hello World\n");
}

/* See remark:
   int onhost(void) { external(); return 5; }  */
-----------------------------------------------------

---- Second file. Compile with 'gcc -fopenmp second.c first.o' ------
void external(void);

int onhost(void) { external(); return 5; }
int ondevice(void) { return 7; }

#pragma omp declare variant (onhost) match (device={kind(host)})
#pragma omp declare variant (ondevice) match (device={kind(nohost)})
int stub (void) { return 9; }

#pragma omp declare target
int
caller(void)
{
  return stub();
}
#pragma omp end declare target

int
main()
{
  __builtin_printf("On host: %d (expected: 5)\n", caller());
  #pragma omp target
    __builtin_printf("On device: %d (expected: 7)\n", caller());
  return 0;
}
---------------------------------------------------------------------

 *  *  *

A variant would be:
  #pragma omp declare variant (ondevice) match (device={kind(nohost)})
  int stub (void) { external(); return 9; }

where the 'stub();' is called in the target region but is still unreachable
because of the 'nohost'.

 *  *  *

While some generic solution would be good - i.e. if offload host is only GCN,
it would be nice if the following works - even if it will fail once
-foffload=nvptx is used
  #pragma omp declare variant (ondevice) match
(construct={target},device={arch(gcn)})
  int stub (void) { external(); return 9; }
handling an explicit 'kind(host)' is very useful.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/106316] [OpenMP] Auto "declare target" should honor  'declare variant'  kind(nohost)
  2022-07-15 15:34 [Bug middle-end/106316] New: [OpenMP] Auto "declare target" should honor 'declare variant' kind(nohost) burnus at gcc dot gnu.org
@ 2022-07-26 12:18 ` jakub at gcc dot gnu.org
  2022-11-03 16:10 ` burnus at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-07-26 12:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106316

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The declare variant directive is just on stub, it doesn't add properties to the
variant function.
I think you need #pragma omp declare target device(host) to (onhost) to make
sure onhost isn't defined for the offloading target.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/106316] [OpenMP] Auto "declare target" should honor  'declare variant'  kind(nohost)
  2022-07-15 15:34 [Bug middle-end/106316] New: [OpenMP] Auto "declare target" should honor 'declare variant' kind(nohost) burnus at gcc dot gnu.org
  2022-07-26 12:18 ` [Bug middle-end/106316] " jakub at gcc dot gnu.org
@ 2022-11-03 16:10 ` burnus at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2022-11-03 16:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106316

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
I note that the OpenMP example document has a similar example at
  https://github.com/OpenMP/examples-internal/pull/329
for OpenMP-Examples Issue https://github.com/OpenMP/spec/issues/3332
For that example, GCC produces device code, which according to the testcase it
shouldn't.

Result: The Fortran example currently fails with nvptx as Fortran 'print' is
not yet supported. (Scheduled to become available. The C 'printf' is available
and AMDGCN also has both.)

Note: Issue/PR is unfortunately not publicly accessible. The example is not in
the 5.2.1 example document, scheduled to be released really soon (for SC22,
i.e. mid-Nov 22). It might become publicly available next year for SC23.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-03 16:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 15:34 [Bug middle-end/106316] New: [OpenMP] Auto "declare target" should honor 'declare variant' kind(nohost) burnus at gcc dot gnu.org
2022-07-26 12:18 ` [Bug middle-end/106316] " jakub at gcc dot gnu.org
2022-11-03 16:10 ` burnus at gcc dot gnu.org

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).