public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Stubbs <ams@codesourcery.com>
To: Tobias Burnus <tobias@codesourcery.com>, <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v2 1/3] libgomp, nvptx: low-latency memory allocator
Date: Wed, 29 Nov 2023 16:25:54 +0000	[thread overview]
Message-ID: <63194e8d-e33e-4685-bfaf-bc6597f542b9@codesourcery.com> (raw)
In-Reply-To: <948bf726-530f-ef6c-54d4-d7f32ad19dcd@codesourcery.com>

On 08/09/2023 10:04, Tobias Burnus wrote:

> Regarding patch 2/3 and MEMSPACE_VALIDATE.
> 
> In general, I wonder how to handle memory spaces (and traits) that
> aren't supported. Namely, when to return 0L and when to silently use
> ignore the trait / use another memory space.
> 
> The current omp_init_allocator code only returns omp_null_allocator for
> invalid value – or for pinned memory (as it is unsupported). [RFC: Shall
> we keep doing so – or return omp_null_mem_alloc more often? →
> https://gcc.gnu.org/PR111044 for this question, improving libmemkind
> usage, and extending the allocator-related documentation.]
> 
> As we do it on the host, I think auto-fallback to omp_default_mem_space
> is is also find for nvptx (and gcn), but not as done in 2/3 but slightly
> different:
> 
> (a) In omp_init_allocator, there should be a check whether it is
> supported, if not, we can fallback to using default memory space. (In
> line with the current code host + 1/2+2/3 nvptx behaviour.)
> 
> Note: That's not the same as the current 2/3 patch. Currently, if
> MEMSPACE_VALIDATE fails, a retry is attempted – but the outcome depends
> on the value for 'fallback'. When changing the memory space during
> omp_init_allocator, only failed 'malloc' will give abort with abort_fb.
> 
> (b) For nvptx_memspace_validate, I think an additional check should be
> done based on the __PTX_ISA_VERSION* as it feels off if plugin first
> claims support for it but later unconditionally uses malloc at runtime.

I have looked at moving the MEMSPACE_VALIDATE call into 
omp_init_allocator so that we can't even create allocators that would be 
invalid, but that changes the semantics of the fall-back traits.  Here's 
the example from testcase omp_alloc-traits.c:

   omp_alloctrait_t traits_all[2]
     = { { omp_atk_fallback, omp_atv_null_fb },
         { omp_atk_access, omp_atv_all } };
   omp_allocator_handle_t lowlat_all
     = omp_init_allocator (omp_low_lat_mem_space, 2, traits_all);

   /* ... */

   void *b = omp_alloc (1, lowlat_all);

With my patch as proposed, "lowlat_all" is a valid allocator, but 
allocating low-latency memory fails in omp_alloc, so "b" ends up NULL 
(the fall-back setting).

With the proposed change, "lowlat_all" becomes omp_null_allocator, and 
"b" is non-NULL, pointing to default memory. This is probably surprising 
to the user because they thought they specified "low-latency or nothing".

Another option would be to create a custom allocator that goes straight 
to the fall-back somehow (we could invent an internal value 
"ompx_fallback_mem_space", or some such).

What is the desired behaviour in this case? I'm not sure that what the 
OpenMP spec actually says matches what the intention seems to have been 
with fallbacks.

> (c) We also need to handle omp_low_lat_mem_alloc. I think the spec
> implies access:all but nvptx/gcn only support cgroup (+ pteams +
> thread), potentially leading to wrong code.
If we're not allowed to default to "cgroup" then surely 
omp_low_lat_mem_alloc is useless on all GPU devices (that I am aware of) 
on all toolchains? There may be some use on some specialist NUMA host 
devices, but that's it.

Andrew

  reply	other threads:[~2023-11-29 16:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-02 17:00 [PATCH v2 0/3] libgomp: OpenMP low-latency omp_alloc Andrew Stubbs
2023-08-02 17:00 ` [PATCH v2 1/3] libgomp, nvptx: low-latency memory allocator Andrew Stubbs
2023-09-08  9:04   ` Tobias Burnus
2023-11-29 16:25     ` Andrew Stubbs [this message]
2023-11-30 11:59       ` Tobias Burnus
2023-08-02 17:00 ` [PATCH v2 2/3] openmp, nvptx: low-lat memory access traits Andrew Stubbs
2023-08-02 17:00 ` [PATCH v2 3/3] amdgcn, libgomp: low-latency allocator 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=63194e8d-e33e-4685-bfaf-bc6597f542b9@codesourcery.com \
    --to=ams@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tobias@codesourcery.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).