From: Tobias Burnus <tobias@codesourcery.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>
Subject: Re: [Patch] libgomp: Fix reverse offload issues
Date: Fri, 3 Feb 2023 11:38:29 +0100 [thread overview]
Message-ID: <b857ded9-7572-9ab3-8dff-3a6b8fc43571@codesourcery.com> (raw)
In-Reply-To: <4c058f14-c719-b66a-f556-9bda3a4c4556@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 1352 bytes --]
Now committed as obvious as
r13-5680-g0b1ce70a813b98ef2893779d14ad6c90c5d06a71.
I improved the wording in the commit comment a bit, compared to previous
attachment and I have verified that those features work with AMDGCN* and
without offloading.
Tobias
(* it seems as if there is still another issue with mapping, this time
for array-descriptor variables that do not exist on the host, i.e. that
have to be fully mapped to the host. I will look into this today or Monday.)
On 02.02.23 15:13, Tobias Burnus wrote:
> Found when testing AMD GCN offloading, the second issue came up with
> libgomp.fortran/reverse-offload-5.f90. (But oddly not with nvptx.)
>
> While the first one (new test: libgomp.fortran/reverse-offload-6.f90)
> came up when debugging the issue.
>
> Tobias
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße
> 201, 80634 München; Gesellschaft mit beschränkter Haftung;
> Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft:
> München; Registergericht München, HRB 106955
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: committed.diff --]
[-- Type: text/x-patch, Size: 3461 bytes --]
commit 0b1ce70a813b98ef2893779d14ad6c90c5d06a71
Author: Tobias Burnus <tobias@codesourcery.com>
Date: Fri Feb 3 11:31:53 2023 +0100
libgomp: Fix reverse offload issues
If there is nothing to map, skip the mapping and avoid attempting to
copy 0 bytes from addrs, sizes and kinds.
Additionally, it could happen that a non-allocated address was deallocated,
such as a pointer set, leading to a free for the actual data.
libgomp/
* target.c (gomp_target_rev): Handle mapnum == 0 and avoid
freeing not allocated memory.
* testsuite/libgomp.fortran/reverse-offload-6.f90: New test.
---
libgomp/target.c | 8 +++---
.../libgomp.fortran/reverse-offload-6.f90 | 32 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/libgomp/target.c b/libgomp/target.c
index b16ee761a95..c1682caea13 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -3324,7 +3324,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr,
gomp_fatal ("Cannot find reverse-offload function");
void (*host_fn)() = (void (*)()) n->k->host_start;
- if (devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
+ if ((devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) || mapnum == 0)
{
devaddrs = (uint64_t *) (uintptr_t) devaddrs_ptr;
sizes = (uint64_t *) (uintptr_t) sizes_ptr;
@@ -3402,7 +3402,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr,
}
}
- if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM))
+ if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) && mapnum > 0)
{
size_t j, struct_cpy = 0;
splay_tree_key n2;
@@ -3638,7 +3638,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr,
host_fn (devaddrs);
- if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM))
+ if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) && mapnum > 0)
{
uint64_t struct_cpy = 0;
bool clean_struct = false;
@@ -3680,7 +3680,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr,
clean_struct = true;
struct_cpy = sizes[i];
}
- else if (cdata[i].aligned)
+ else if (!cdata[i].present && cdata[i].aligned)
gomp_aligned_free ((void *) (uintptr_t) devaddrs[i]);
else if (!cdata[i].present)
free ((void *) (uintptr_t) devaddrs[i]);
diff --git a/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 b/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90
new file mode 100644
index 00000000000..04866edbba7
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90
@@ -0,0 +1,32 @@
+!
+! Ensure that a mapping with no argument works
+!
+
+module m
+ implicit none (type, external)
+ integer :: x = 32
+ integer :: dev_num2 = -1
+contains
+subroutine foo()
+ use omp_lib, only: omp_get_device_num
+ x = x + 10
+ dev_num2 = omp_get_device_num()
+end
+end module m
+
+use m
+use omp_lib
+!$omp requires reverse_offload
+implicit none (type, external)
+integer :: dev_num = -1
+!$omp target map(from:dev_num)
+ dev_num = omp_get_device_num()
+ ! This calls GOMP_target_ext with number of maps = 0
+ !$omp target device(ancestor:1)
+ call foo
+ !$omp end target
+!$omp end target
+
+if (omp_get_num_devices() > 0 .and. dev_num2 == dev_num) stop 1
+if (x /= 42) stop 2
+end
next prev parent reply other threads:[~2023-02-03 10:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 14:13 Tobias Burnus
2023-02-03 10:38 ` Tobias Burnus [this message]
2023-02-07 22:47 ` Fix 'libgomp.fortran/reverse-offload-6.f90' nvptx offloading compilation (was: [Patch] libgomp: Fix reverse offload issues) Thomas Schwinge
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=b857ded9-7572-9ab3-8dff-3a6b8fc43571@codesourcery.com \
--to=tobias@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/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).