public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/106316] New: [OpenMP] Auto "declare target" should honor  'declare variant'  kind(nohost)
Date: Fri, 15 Jul 2022 15:34:42 +0000	[thread overview]
Message-ID: <bug-106316-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2022-07-15 15:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-15 15:34 burnus at gcc dot gnu.org [this message]
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

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=bug-106316-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).