* [PATCH, OpenMP] Fix nested use_device_ptr
@ 2022-04-01 9:02 Chung-Lin Tang
2022-04-01 9:07 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Chung-Lin Tang @ 2022-04-01 9:02 UTC (permalink / raw)
To: Jakub Jelinek, gcc-patches, Tobias Burnus, Catherine Moore
[-- Attachment #1: Type: text/plain, Size: 997 bytes --]
Hi Jakub,
this patch fixes a bug in lower_omp_target, where for Fortran arrays,
the expanded sender assignment is wrongly using the variable in the
current ctx, instead of the one looked-up outside, which is causing
use_device_ptr/addr to fail to work when used inside an omp-parallel
(where the omp child_fn is split away from the original).
Just a one-character change to fix this.
The fix is inside omp-low.cc, though because the omp_array_data langhook
is used only by Fortran, this is essentially Fortran-specific.
Tested on x86_64-linux + nvptx offloading without regressions.
This is probably not a regression, but seeking to commit when stage1 opens.
Thanks,
Chung-Lin
2022-04-01 Chung-Lin Tang <cltang@codesourcery.com>
gcc/ChangeLog:
* omp-low.cc (lower_omp_target): Use outer context looked-up 'var' as
argument to lang_hooks.decls.omp_array_data, instead of 'ovar' from
current clause.
libgomp/ChangeLog:
* testsuite/libgomp.fortran/use_device_ptr-4.f90: New testcase.
[-- Attachment #2: omp101.patch --]
[-- Type: text/plain, Size: 1824 bytes --]
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 392bb18..bf5779b 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -13405,7 +13405,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
type = TREE_TYPE (ovar);
if (lang_hooks.decls.omp_array_data (ovar, true))
- var = lang_hooks.decls.omp_array_data (ovar, false);
+ var = lang_hooks.decls.omp_array_data (var, false);
else if (((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_ADDR
|| OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
&& !omp_privatize_by_reference (ovar)
diff --git a/libgomp/testsuite/libgomp.fortran/use_device_ptr-4.f90 b/libgomp/testsuite/libgomp.fortran/use_device_ptr-4.f90
new file mode 100644
index 0000000..8c361d1
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/use_device_ptr-4.f90
@@ -0,0 +1,41 @@
+! { dg-do run }
+!
+! Test user_device_ptr nested within another parallel
+! construct
+!
+program test_nested_use_device_ptr
+ use iso_c_binding, only: c_loc, c_ptr
+ implicit none
+ real, allocatable, target :: arr(:,:)
+ integer :: width = 1024, height = 1024, i
+ type(c_ptr) :: devptr
+
+ allocate(arr(width,height))
+
+ !$omp target enter data map(alloc: arr)
+
+ !$omp target data use_device_ptr(arr)
+ devptr = c_loc(arr(1,1))
+ !$omp end target data
+
+ !$omp parallel default(none) shared(arr, devptr)
+ !$omp single
+
+ !$omp target data use_device_ptr(arr)
+ call thing(c_loc(arr), devptr)
+ !$omp end target data
+
+ !$omp end single
+ !$omp end parallel
+ !$omp target exit data map(delete: arr)
+
+contains
+
+ subroutine thing(myarr, devptr)
+ use iso_c_binding, only: c_ptr, c_associated
+ implicit none
+ type(c_ptr) :: myarr, devptr
+ if (.not.c_associated(myarr, devptr)) stop 1
+ end subroutine thing
+
+end program
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH, OpenMP] Fix nested use_device_ptr
2022-04-01 9:02 [PATCH, OpenMP] Fix nested use_device_ptr Chung-Lin Tang
@ 2022-04-01 9:07 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2022-04-01 9:07 UTC (permalink / raw)
To: Chung-Lin Tang; +Cc: gcc-patches, Tobias Burnus, Catherine Moore
On Fri, Apr 01, 2022 at 05:02:36PM +0800, Chung-Lin Tang wrote:
> this patch fixes a bug in lower_omp_target, where for Fortran arrays,
> the expanded sender assignment is wrongly using the variable in the
> current ctx, instead of the one looked-up outside, which is causing
> use_device_ptr/addr to fail to work when used inside an omp-parallel
> (where the omp child_fn is split away from the original).
> Just a one-character change to fix this.
>
> The fix is inside omp-low.cc, though because the omp_array_data langhook
> is used only by Fortran, this is essentially Fortran-specific.
>
> Tested on x86_64-linux + nvptx offloading without regressions.
> This is probably not a regression, but seeking to commit when stage1 opens.
>
> Thanks,
> Chung-Lin
>
> 2022-04-01 Chung-Lin Tang <cltang@codesourcery.com>
>
> gcc/ChangeLog:
>
> * omp-low.cc (lower_omp_target): Use outer context looked-up 'var' as
> argument to lang_hooks.decls.omp_array_data, instead of 'ovar' from
> current clause.
>
> libgomp/ChangeLog:
>
> * testsuite/libgomp.fortran/use_device_ptr-4.f90: New testcase.
Ok, thanks.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-01 9:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 9:02 [PATCH, OpenMP] Fix nested use_device_ptr Chung-Lin Tang
2022-04-01 9:07 ` Jakub Jelinek
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).