Bug 98476 - OpenMP offload syntax restriction
Summary: OpenMP offload syntax restriction
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 10.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: openmp
Depends on:
Blocks:
 
Reported: 2020-12-30 05:13 UTC by Ye Luo
Modified: 2021-01-20 07:35 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-01-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ye Luo 2020-12-30 05:13:38 UTC
C version code works. The corresponding Fortran version is blocked by the compiler errror.

C version:
#include <stdio.h>

int main()
{
  int a[1];
  int* b = a;
  a[0] = 0;
  #pragma omp target enter data map(to:b[:1])
  #pragma omp target data use_device_ptr(b)
  {
    #pragma omp target is_device_ptr(b)
    {
      b[0] = 1;
    }
  }
  printf("value before exit data %d\n", b[0]);
  #pragma omp target exit data map(from:b[:1])
  printf("value after exit data %d\n", b[0]);
  return 0;
}


Fortran version, XL fortran compiler works with this case.
program abc
  implicit none
  integer a

  a = 0
  call test(a)

contains
  subroutine test(a)
    implicit none
    integer a

  !$omp target enter data map(to:a)
  !$omp target data use_device_ptr(a)
  ! Error: TARGET DATA must contain at least one MAP clause at (1)
  ! after adding map(to: a), the second printout is still wrong.
  !$omp target is_device_ptr(a)
    a = 1
  !$omp end target
  !$omp end target data
  write(6,*) "before exit data a = ", a
  !$omp target exit data map(from:a)
  write(6,*) "after exit data a = ", a

  endsubroutine
end program
Comment 1 Jakub Jelinek 2020-12-30 07:09:17 UTC
The error is correct for OpenMP 4.5, !$omp target data there has the restriction:
At least one map clause must appear on the directive.
and OpenMP 4.5 is what GCC 10 implements in Fortran mostly.
OpenMP 5.0 and 5.1 changes that restriction to:
At least one map, use_device_addr or use_device_ptr clause must appear on the
directive.
which is what you can see in the C and C++ FEs.
GCC 11 is going to implement the 5.0 behavior here even in Fortran.
Comment 2 Ye Luo 2020-12-30 16:45:42 UTC
@jakub thanks for the quick reply. However, even if I add map(to: a) which is almost a no-op to satisfy the compiler for 4.5 spec. The printout result is still wrong. It should be 0 and 1 but the fortran case prints 0 and 0.
Comment 3 Ye Luo 2020-12-31 00:17:50 UTC
I verified that current master has removed the syntax restriction. However, the printout remains incorrect.
Comment 5 GCC Commits 2021-01-19 10:59:41 UTC
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:049bfd186fae9fb764a3ec04acb20d3eaacda7a3

commit r11-6787-g049bfd186fae9fb764a3ec04acb20d3eaacda7a3
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Tue Jan 19 11:57:34 2021 +0100

    OpenMP/Fortran: Fixes for {use,is}_device_ptr
    
    gcc/fortran/ChangeLog:
    
            PR fortran/98476
            * openmp.c (resolve_omp_clauses): Change use_device_ptr
            to use_device_addr for unless type(c_ptr); check all
            list item for is_device_ptr.
    
    gcc/ChangeLog:
    
            PR fortran/98476
            * omp-low.c (lower_omp_target): Handle nonpointer is_device_ptr.
    
    libgomp/ChangeLog:
    
            PR fortran/98476
            * testsuite/libgomp.fortran/is_device_ptr-1.f90: New test.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/98476
            * gfortran.dg/gomp/map-3.f90: Update expected scan-dump-tree.
            * gfortran.dg/gomp/is_device_ptr-2.f90: New test.
            * gfortran.dg/gomp/use_device_ptr-1.f90: New test.
Comment 6 Tobias Burnus 2021-01-19 11:00:59 UTC
Close as FIXED.

Thanks for the report, especially for checking already upcoming GCC 11, which helps to iron out issues before the release :-)
Comment 7 GCC Commits 2021-01-20 07:35:34 UTC
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:c05cdfb3f6335d55226cef7917a783498aa41244

commit r11-6809-gc05cdfb3f6335d55226cef7917a783498aa41244
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Wed Jan 20 08:31:30 2021 +0100

    OpenMP/Fortran: Fix gfortran.dg/gomp/is_device_ptr-2.f90
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/98757
            PR fortran/98476
            * gfortran.dg/gomp/is_device_ptr-2.f90: Fix dg-error.