From: Andrew Stubbs <ams@codesourcery.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [OG12][committed] amdgcn, libgomp: custom USM allocator
Date: Fri, 13 Jan 2023 17:52:34 +0000 [thread overview]
Message-ID: <cc74a2be-fe2b-22ce-fd52-4aeeb019d5c8@codesourcery.com> (raw)
In-Reply-To: <a8d5017a-8b63-3103-bad1-528a5b3723c3@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 1468 bytes --]
I changed it to use 128-byte alignment to match the GPU cache-lines.
Committed to OG12.
Andrew
On 11/01/2023 18:05, Andrew Stubbs wrote:
> This patch fixes a runtime issue I encountered with the AMD GCN Unified
> Shared Memory implementation.
>
> We were using regular malloc'd memory configured into USM mode, but
> there were random intermittent crashes. I can't be completely sure, but
> my best guess is that the HSA driver is using malloc internally from the
> same heap, and therefore using memory on the same page as the offload
> kernel. What I do know is that I could make the crashes go away by
> simply padding the USM allocations before and after.
>
> With this patch USM allocations are now completely separated from the
> system heap. The custom allocator is probably less optimal is some
> use-cases, but does have the advantage that all the metadata is stored
> in a side-table that won't ever cause any pages to migrate back to
> main-memory unnecessarily. It's still possible for the user program to
> use USM memory in a way that causes it to thrash, and this might have
> been the ultimate cause of the crashes, but there's not much we can do
> about that here.
>
> I've broken the allocator out into a new file because I anticipate it
> being needed in more than one place, but I didn't put full
> data-isolation on it yet.
>
> I'll rebase, merge, and repost all of the OpenMP memory patches sometime
> soonish.
>
> Andrew
[-- Attachment #2: 230113-usm-align-128.patch --]
[-- Type: text/plain, Size: 839 bytes --]
libgomp, amdgcn: Switch USM to 128-byte alignment
This should optimize cache-lines on the AMD GPUs somewhat.
libgomp/ChangeLog:
* usm-allocator.c (ALIGN): Use 128-byte alignment.
diff --git a/libgomp/usm-allocator.c b/libgomp/usm-allocator.c
index c45109169ca..68c1ebafec2 100644
--- a/libgomp/usm-allocator.c
+++ b/libgomp/usm-allocator.c
@@ -57,7 +57,8 @@ static int usm_lock = 0;
static struct usm_splay_tree_s usm_allocations = { NULL };
static struct usm_splay_tree_s usm_free_space = { NULL };
-#define ALIGN(VAR) (((VAR) + 7) & ~7) /* 8-byte granularity. */
+/* 128-byte granularity means GPU cache-line aligned. */
+#define ALIGN(VAR) (((VAR) + 127) & ~127)
/* Coalesce contiguous free space into one entry. This considers the entries
either side of the root node only, so it should be called each time a new
prev parent reply other threads:[~2023-01-13 17:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 18:05 Andrew Stubbs
2023-01-13 17:52 ` Andrew Stubbs [this message]
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=cc74a2be-fe2b-22ce-fd52-4aeeb019d5c8@codesourcery.com \
--to=ams@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
/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).