public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: Julian Brown <julian@codesourcery.com>,
	Thomas Schwinge <thomas@codesourcery.com>
Cc: <gcc-patches@gcc.gnu.org>, <fortran@gcc.gnu.org>,
	<jakub@redhat.com>, Tom de Vries <tdevries@suse.de>
Subject: Re: [PATCH 1/5] OpenMP, NVPTX: memcpy[23]D bias correction
Date: Tue, 19 Dec 2023 21:45:39 +0100	[thread overview]
Message-ID: <0632c1f8-e869-45a0-96d7-5375895d53cd@codesourcery.com> (raw)
In-Reply-To: <20231002155359.3a44a582@squid.athome>

Hi Julian & Thomas,

the patch LGTM - and seemingly also Thomas is somewhat fine with it -
and it includes the stand-alone testcase.

* * *

I guess, you don't know the answer to Thomas question, i.e. whether
that's a bug in CUDA or in our use of the CUDA API?

CUDA's spec itself,
https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html has
for cuMemcpy2D

‎  void* Start = (void*)((char*)srcHost+srcY*srcPitch + srcXInBytes);

and for cuMemcpy3D

‎  void* Start = (void*)((char*)srcHost+(srcZ*srcHeight+srcY)*srcPitch + srcXInBytes);

Thus, I assume we use it "properly", except that the CUDA writers
probably assumed that one allocates a big chunk of memory and work with
that memory and not just maps a subset.

This might or might not be stated in the manual in the following:
"Memory regions spanning over allocations that are both registered and
not registered with CUDA are not supported and will return
CUDA_ERROR_INVALID_VALUE." – where the question is whether everything
until 'start' really counts as "spanning".

Tobias


On 02.10.23 16:53, Julian Brown wrote:
> On Wed, 27 Sep 2023 00:57:58 +0200
> Thomas Schwinge <thomas@codesourcery.com> wrote:
>
>> On 2023-09-06T02:34:30-0700, Julian Brown <julian@codesourcery.com>
>> wrote:
>>> This patch works around behaviour of the 2D and 3D memcpy
>>> operations in the CUDA driver runtime.  Particularly in Fortran,
>>> the "base pointer" of an array (used for either source or
>>> destination of a host/device copy) may lie outside of data that is
>>> actually stored on the device.  The fix is to make sure that we use
>>> the first element of data to be transferred instead, and adjust
>>> parameters accordingly.
>> Do you (a) have a stand-alone test case for this (that is, not
>> depending on your other pending patches, so that this could go in
>> directly -- together with the before-FAIL test case).
> Thanks for the reply! Here's a version with a stand-alone test case.
>
>> Do you (b)
>> know if is this a bug in our use of the CUDA Driver API or rather in
>> CUDA itself?  If the latter, have you reported this to Nvidia?
> I don't think the CUDA behaviour is *wrong*, as such -- at least to the
> C/C++ way of thinking (or indeed a graphics-oriented way of thinking),
> one would normally think of an array as having a zero-based origin, and
> these 2D/3D memory copies would be intended as a way of updating just a
> part of an array (or texture) that has full duplicate copies on both
> the host and device.  Our use-case just happens to be a bit different,
> both because Fortran (internally) represents an array by a zero-based
> origin but may use 1-based (or whatever-based) indices, and because we
> support partial mappings of host arrays on the device in all three
> supported languages -- which amounts to much the same thing, actually.
>
> That said, it *could* be fixed in CUDA, though probably not in all the
> versions currently deployed out there in the world.  So I guess we'd
> still need a patch like this anyway.
>
> Julian
-----------------
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

  reply	other threads:[~2023-12-19 20:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06  9:34 [PATCH 0/5] OpenMP: Array-shaping operator and strided/rectangular 'target update' support Julian Brown
2023-09-06  9:34 ` [PATCH 1/5] OpenMP, NVPTX: memcpy[23]D bias correction Julian Brown
2023-09-26 22:57   ` Thomas Schwinge
2023-10-02 14:53     ` Julian Brown
2023-12-19 20:45       ` Tobias Burnus [this message]
2023-09-06  9:34 ` [PATCH 2/5] OpenMP: Allow complete replacement of clause during map/to/from expansion Julian Brown
2023-09-06  9:34 ` [PATCH 3/5] OpenMP: Support strided and shaped-array updates for C++ Julian Brown
2023-09-06  9:34 ` [PATCH 4/5] OpenMP: Array shaping operator and strided "target update" for C Julian Brown
2023-09-06  9:34 ` [PATCH 5/5] OpenMP: Noncontiguous "target update" for Fortran Julian Brown

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=0632c1f8-e869-45a0-96d7-5375895d53cd@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=julian@codesourcery.com \
    --cc=tdevries@suse.de \
    --cc=thomas@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).