public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors
@ 2024-06-20 14:44 burnus at gcc dot gnu.org
  2024-06-20 15:15 ` [Bug fortran/115559] " burnus at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-06-20 14:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115559
           Summary: [OpenMP] 'link' clause of 'declare target' causes link
                    errors
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: openmp, rejects-valid, wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

A C version of the following program compiles — for Fortran, the offload-device
LTO fails with:

link.f90:3:16: error: variable 'aaa' has been referenced in offloaded code but
hasn't been marked to be included in the offloaded code


module m
  implicit none
  integer :: AAA, BBB(10)
  !$omp declare target link(AAA,BBB)
end module m

subroutine sub()
  !$omp declare target
  use m
  implicit none
  AAA = 1
  BBB(5) = 7
end

external sub
!$omp target
  call sub
!$omp end target
end


Same issue for the larger (and more proper) OpenMP examples testcase:

https://github.com/OpenMP/Examples/blob/main/devices/sources/declare_target.6.f90

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

* [Bug fortran/115559] [OpenMP] 'link' clause of 'declare target' causes link errors
  2024-06-20 14:44 [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors burnus at gcc dot gnu.org
@ 2024-06-20 15:15 ` burnus at gcc dot gnu.org
  2024-06-20 17:46 ` burnus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-06-20 15:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Looks as if offload_vars is empty in case of Fortran; the variables are tagged
as 'declare variant link' in the FE but varpool_node::get_create has:

  if ((flag_openacc || flag_openmp)
      && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
    {
      node->offloadable = 1;
      if (ENABLE_OFFLOADING && !DECL_EXTERNAL (decl))
        {
          g->have_offload = true;
          if (!in_lto_p)
            vec_safe_push (offload_vars, decl);
        }
    }

Thus, somewhere a "omp declare target" decl needs to exist.

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

* [Bug fortran/115559] [OpenMP] 'link' clause of 'declare target' causes link errors
  2024-06-20 14:44 [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors burnus at gcc dot gnu.org
  2024-06-20 15:15 ` [Bug fortran/115559] " burnus at gcc dot gnu.org
@ 2024-06-20 17:46 ` burnus at gcc dot gnu.org
  2024-06-20 18:47 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-06-20 17:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
For C, it is actually handled in the FE for

      tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t));
      tree at2 = lookup_attribute ("omp declare target link",
                                   DECL_ATTRIBUTES (t));
      only_device_type_or_indirect = false;
      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK)
        {   
          id = get_identifier ("omp declare target link");
          std::swap (at1, at2);
        }
...
      if (!at1)
        {
          DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
          if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
            continue;

          symtab_node *node = symtab_node::get (t);
          if (node != NULL)
            {
              node->offloadable = 1;
              if (ENABLE_OFFLOADING)
                {
                  g->have_offload = true;
                  if (is_a <varpool_node *> (node))
                    vec_safe_push (offload_vars, t);
                }
            }

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

* [Bug fortran/115559] [OpenMP] 'link' clause of 'declare target' causes link errors
  2024-06-20 14:44 [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors burnus at gcc dot gnu.org
  2024-06-20 15:15 ` [Bug fortran/115559] " burnus at gcc dot gnu.org
  2024-06-20 17:46 ` burnus at gcc dot gnu.org
@ 2024-06-20 18:47 ` burnus at gcc dot gnu.org
  2024-06-20 19:03 ` burnus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-06-20 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |burnus at gcc dot gnu.org
   Last reconfirmed|                            |2024-06-20
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 58472
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58472&action=edit
Patch that calls symtab_node::get_create in the FE

This patch does now likewise – calling symtab_node::get_create in the FE. Note:
It's get_create as 'get' returns NULL.

That seems to fix the issue for the example of comment 0. (Which obviously
fails at runtime as nothing is mapped).

For the OpenMP examples' testcase devices/sources/declare_target.6.f90 [marked
as compile-time only test; see link in comment 0] it fails during final linking
and shows messages like:
>  relocation truncated to fit: R_X86_64_32S against symbol `__m_dat_MOD_sv1' defined in .bss section in a-declare_target.6.o

and
>  undefined reference to `s_output

The latter is clear – as the file calls but does not provide those functions.

And the former as well:
   integer, parameter :: N=100000000
   real :: sp(N), sv1(N), sv2(N)
   double precision :: dp(N), dv1(N), dv2(N)

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

* [Bug fortran/115559] [OpenMP] 'link' clause of 'declare target' causes link errors
  2024-06-20 14:44 [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-06-20 18:47 ` burnus at gcc dot gnu.org
@ 2024-06-20 19:03 ` burnus at gcc dot gnu.org
  2024-06-21 16:08 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-06-20 19:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> ---
NOTE to self: This code now adds the attribute unconditionally. For COMMON and
MODULE it makes sense; but for programm/subroutine/function, it needs to be
rechecked whether that variable is actually used.

An example where the variable is in the main program and the user is in a
contained subroutine fails – i.e. simply excluding that case will not work. But
maybe the decl can be avoided at least in some cases.

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

* [Bug fortran/115559] [OpenMP] 'link' clause of 'declare target' causes link errors
  2024-06-20 14:44 [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-06-20 19:03 ` burnus at gcc dot gnu.org
@ 2024-06-21 16:08 ` burnus at gcc dot gnu.org
  2024-06-21 16:11 ` burnus at gcc dot gnu.org
  2024-06-25 10:47 ` burnus at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-06-21 16:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 58478
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58478&action=edit
COMMON block testcase

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

* [Bug fortran/115559] [OpenMP] 'link' clause of 'declare target' causes link errors
  2024-06-20 14:44 [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-06-21 16:08 ` burnus at gcc dot gnu.org
@ 2024-06-21 16:11 ` burnus at gcc dot gnu.org
  2024-06-25 10:47 ` burnus at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-06-21 16:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Fortran patch:
  https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655386.html

FOLLOW-UP ISSUES:

* OFFSET issues with LINK clause:
      arr = [(i, i=1,N)]
      map(arr(10:N)
  and then in a device function:
      print *, arr(10)
  → should print 10 but prints 19   (double offset?)
  TESTCASE: FIXME in the testcase of the posted patch

* VARIABLE not AVAILABLE on the device:
  For some
  TESTCASE: FIXME in the testcase of the posted patch

(B) Issues found when writing a testcase:

* COMMON blocks: Using map(a,b,c) instead of map(/mycommon/) fails with:
     error: undefined symbol: mycommon_
  TESTCASE: attachment 58478

* MAP issue: map(/mycommon/) is wrongly rejected for MAP
  → PR 115577

Issues found on the way:
  Similar problem for C with nested functions → PR 115574

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

* [Bug fortran/115559] [OpenMP] 'link' clause of 'declare target' causes link errors
  2024-06-20 14:44 [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2024-06-21 16:11 ` burnus at gcc dot gnu.org
@ 2024-06-25 10:47 ` burnus at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-06-25 10:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to Tobias Burnus from comment #6)
> FOLLOW-UP ISSUES:
> * VARIABLE not AVAILABLE on the device:

PR115637 - is an analysis of the 'arr2' issue.

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

end of thread, other threads:[~2024-06-25 10:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-20 14:44 [Bug fortran/115559] New: [OpenMP] 'link' clause of 'declare target' causes link errors burnus at gcc dot gnu.org
2024-06-20 15:15 ` [Bug fortran/115559] " burnus at gcc dot gnu.org
2024-06-20 17:46 ` burnus at gcc dot gnu.org
2024-06-20 18:47 ` burnus at gcc dot gnu.org
2024-06-20 19:03 ` burnus at gcc dot gnu.org
2024-06-21 16:08 ` burnus at gcc dot gnu.org
2024-06-21 16:11 ` burnus at gcc dot gnu.org
2024-06-25 10:47 ` 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).