From: Thomas Schwinge <thomas@codesourcery.com>
To: Andrew Stubbs <ams@codesourcery.com>, <gcc-patches@gcc.gnu.org>
Cc: Jakub Jelinek <jakub@redhat.com>
Subject: [og12] Clarify/verify OpenMP 'omp_calloc' zero-initialization for pinned memory (was: [PATCH] libgomp, openmp: pinned memory)
Date: Thu, 16 Feb 2023 22:39:44 +0100 [thread overview]
Message-ID: <87ttzlxpb3.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <a79567df-f061-8248-4281-63c74e724cb7@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 936 bytes --]
Hi!
On 2022-01-13T13:53:03+0000, Andrew Stubbs <ams@codesourcery.com> wrote:
> Pinned memory is allocated via mmap
> --- /dev/null
> +++ b/libgomp/config/linux/allocator.c
> +static void *
> +linux_memspace_calloc (omp_memspace_handle_t memspace, size_t size, int pin)
> +{
> + if (pin)
> + return linux_memspace_alloc (memspace, size, pin);
> +[...]
This confused me for a moment, why we don't have to manually
zero-initialize here. I've pushed to devel/omp/gcc-12 branch
commit 57b8f0600262566cd4f1ab12bf1bdafb29dbdc34
"Clarify/verify OpenMP 'omp_calloc' zero-initialization for pinned memory",
see attached.
Grüße
Thomas
-----------------
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Clarify-verify-OpenMP-omp_calloc-zero-initialization.patch --]
[-- Type: text/x-diff, Size: 5924 bytes --]
From 57b8f0600262566cd4f1ab12bf1bdafb29dbdc34 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Wed, 15 Feb 2023 10:23:03 +0100
Subject: [PATCH] Clarify/verify OpenMP 'omp_calloc' zero-initialization for
pinned memory
Clarification for og12 commit ab7520b3b4cd9fdabfd63652badde478955bd3b5
"libgomp: pinned memory". No functional change.
libgomp/
* config/linux/allocator.c (linux_memspace_alloc)
(linux_memspace_calloc): Clarify zero-initialization for pinned
memory.
* testsuite/libgomp.c/alloc-pinned-1.c: Verify zero-initialization
for pinned memory.
* testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-3.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-4.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
---
libgomp/ChangeLog.omp | 10 ++++++++++
libgomp/config/linux/allocator.c | 2 ++
libgomp/testsuite/libgomp.c/alloc-pinned-1.c | 10 ++++++++++
libgomp/testsuite/libgomp.c/alloc-pinned-2.c | 10 ++++++++++
libgomp/testsuite/libgomp.c/alloc-pinned-3.c | 9 +++++++++
libgomp/testsuite/libgomp.c/alloc-pinned-4.c | 9 +++++++++
libgomp/testsuite/libgomp.c/alloc-pinned-5.c | 10 ++++++++++
7 files changed, 60 insertions(+)
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 1c4b1833c0b..530f5c6acf6 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,15 @@
2023-02-16 Thomas Schwinge <thomas@codesourcery.com>
+ * config/linux/allocator.c (linux_memspace_alloc)
+ (linux_memspace_calloc): Clarify zero-initialization for pinned
+ memory.
+ * testsuite/libgomp.c/alloc-pinned-1.c: Verify zero-initialization
+ for pinned memory.
+ * testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
+ * testsuite/libgomp.c/alloc-pinned-3.c: Likewise.
+ * testsuite/libgomp.c/alloc-pinned-4.c: Likewise.
+ * testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
+
* config/linux/allocator.c (linux_memspace_calloc): Elide
(innocuous) duplicate 'if' condition.
* config/nvptx/allocator.c (nvptx_memspace_free): Explicitly
diff --git a/libgomp/config/linux/allocator.c b/libgomp/config/linux/allocator.c
index 8a9171c36df..f278e5cdf14 100644
--- a/libgomp/config/linux/allocator.c
+++ b/libgomp/config/linux/allocator.c
@@ -65,6 +65,7 @@ linux_memspace_alloc (omp_memspace_handle_t memspace, size_t size, int pin)
}
else if (pin)
{
+ /* 'mmap' zero-initializes, which 'linux_memspace_calloc' relies on. */
void *addr = mmap (NULL, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (addr == MAP_FAILED)
@@ -96,6 +97,7 @@ linux_memspace_calloc (omp_memspace_handle_t memspace, size_t size, int pin)
return ret;
}
else if (pin)
+ /* If PINned, 'linux_memspace_alloc' 'mmap's, which zero-initializes. */
return linux_memspace_alloc (memspace, size, pin);
else
return calloc (1, size);
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
index 79792b16d83..fb7ac8b0080 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
@@ -54,6 +54,14 @@ get_pinned_mem ()
}
#endif
+static void
+verify0 (char *p, size_t s)
+{
+ for (size_t i = 0; i < s; ++i)
+ if (p[i] != 0)
+ abort ();
+}
+
#include <omp.h>
int
@@ -91,5 +99,7 @@ main ()
if (get_pinned_mem () <= amount2)
abort ();
+ verify0 (p, SIZE);
+
return 0;
}
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
index 228c656b715..651b89fb42f 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
@@ -54,6 +54,14 @@ get_pinned_mem ()
}
#endif
+static void
+verify0 (char *p, size_t s)
+{
+ for (size_t i = 0; i < s; ++i)
+ if (p[i] != 0)
+ abort ();
+}
+
#include <omp.h>
int
@@ -97,5 +105,7 @@ main ()
if (get_pinned_mem () <= amount2)
abort ();
+ verify0 (p, SIZE);
+
return 0;
}
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-3.c b/libgomp/testsuite/libgomp.c/alloc-pinned-3.c
index 90539ffe3e0..f41797881ef 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-3.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-3.c
@@ -61,6 +61,14 @@ set_pin_limit ()
}
#endif
+static void
+verify0 (char *p, size_t s)
+{
+ for (size_t i = 0; i < s; ++i)
+ if (p[i] != 0)
+ abort ();
+}
+
#include <omp.h>
int
@@ -109,6 +117,7 @@ main ()
p = omp_calloc (1, SIZE, allocator2);
if (!p)
abort ();
+ verify0 (p, SIZE);
// Should fail to realloc
void *notpinned = omp_alloc (SIZE, omp_default_mem_alloc);
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-4.c b/libgomp/testsuite/libgomp.c/alloc-pinned-4.c
index 534e49eefc4..a878da8c558 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-4.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-4.c
@@ -61,6 +61,14 @@ set_pin_limit ()
}
#endif
+static void
+verify0 (char *p, size_t s)
+{
+ for (size_t i = 0; i < s; ++i)
+ if (p[i] != 0)
+ abort ();
+}
+
#include <omp.h>
int
@@ -111,6 +119,7 @@ main ()
p = omp_calloc (1, SIZE, allocator2);
if (!p)
abort ();
+ verify0 (p, SIZE);
// Should fail to realloc
void *notpinned = omp_alloc (SIZE, omp_default_mem_alloc);
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-5.c b/libgomp/testsuite/libgomp.c/alloc-pinned-5.c
index 315c7161a39..65983b3d03d 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-5.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-5.c
@@ -54,6 +54,14 @@ get_pinned_mem ()
}
#endif
+static void
+verify0 (char *p, size_t s)
+{
+ for (size_t i = 0; i < s; ++i)
+ if (p[i] != 0)
+ abort ();
+}
+
#include <omp.h>
int
@@ -86,5 +94,7 @@ main ()
if (get_pinned_mem () <= amount2)
abort ();
+ verify0 (p, SIZE);
+
return 0;
}
--
2.25.1
next prev parent reply other threads:[~2023-02-16 21:39 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-04 15:32 [PATCH] libgomp, openmp: pinned memory Andrew Stubbs
2022-01-04 15:55 ` Jakub Jelinek
2022-01-04 16:58 ` Andrew Stubbs
2022-01-04 18:28 ` Jakub Jelinek
2022-01-04 18:47 ` Jakub Jelinek
2022-01-05 17:07 ` Andrew Stubbs
2022-01-13 13:53 ` Andrew Stubbs
2022-06-07 11:05 ` Andrew Stubbs
2022-06-07 12:10 ` Jakub Jelinek
2022-06-07 12:28 ` Andrew Stubbs
2022-06-07 12:40 ` Jakub Jelinek
2022-06-09 9:38 ` Thomas Schwinge
2022-06-09 10:09 ` Tobias Burnus
2022-06-09 10:22 ` Stubbs, Andrew
2022-06-09 10:31 ` Stubbs, Andrew
2023-02-16 15:32 ` Attempt to register OpenMP pinned memory using a device instead of 'mlock' (was: [PATCH] libgomp, openmp: pinned memory) Thomas Schwinge
2023-02-16 16:17 ` Stubbs, Andrew
2023-02-16 22:06 ` [og12] " Thomas Schwinge
2023-02-17 8:12 ` Thomas Schwinge
2023-02-20 9:48 ` Andrew Stubbs
2023-02-20 13:53 ` [og12] Attempt to not just register but allocate OpenMP pinned memory using a device (was: [og12] Attempt to register OpenMP pinned memory using a device instead of 'mlock') Thomas Schwinge
2023-02-10 15:11 ` [PATCH] libgomp, openmp: pinned memory Thomas Schwinge
2023-02-10 15:55 ` Andrew Stubbs
2023-02-16 21:39 ` Thomas Schwinge [this message]
2023-03-24 15:49 ` [og12] libgomp: Document OpenMP 'pinned' memory (was: " Thomas Schwinge
2023-03-27 9:27 ` Stubbs, Andrew
2023-03-27 11:26 ` [og12] libgomp: Document OpenMP 'pinned' memory (was: [PATCH] libgomp, openmp: pinned memory) Thomas Schwinge
2023-03-27 12:01 ` Andrew Stubbs
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=87ttzlxpb3.fsf@euler.schwinge.homeip.net \
--to=thomas@codesourcery.com \
--cc=ams@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).