public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Thomas Schwinge <thomas@codesourcery.com>
Cc: Tobias Burnus <tobias@codesourcery.com>, gcc-patches@gcc.gnu.org
Subject: Re: [Patch] libgomp: Handle OpenMP's reverse offloads
Date: Thu, 15 Dec 2022 18:49:26 +0100	[thread overview]
Message-ID: <Y5teJt5jovrj8+W6@tucnak> (raw)
In-Reply-To: <87ilicfu55.fsf@euler.schwinge.homeip.net>

On Thu, Dec 15, 2022 at 06:34:30PM +0100, Thomas Schwinge wrote:
> --- a/libgomp/libgomp-plugin.c
> +++ b/libgomp/libgomp-plugin.c
> @@ -82,9 +82,9 @@ GOMP_PLUGIN_fatal (const char *msg, ...)
>  void
>  GOMP_PLUGIN_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr,
>  			uint64_t sizes_ptr, uint64_t kinds_ptr, int dev_num,
> -			void (*dev_to_host_cpy) (void *, const void *, size_t,
> +			bool (*dev_to_host_cpy) (void *, const void *, size_t,
>  						 void *),
> -			void (*host_to_dev_cpy) (void *, const void *, size_t,
> +			bool (*host_to_dev_cpy) (void *, const void *, size_t,
>  						 void *), void *token)
>  {
>    gomp_target_rev (fn_ptr, mapnum, devaddrs_ptr, sizes_ptr, kinds_ptr, dev_num,
> diff --git a/libgomp/libgomp-plugin.h b/libgomp/libgomp-plugin.h
> index ac3878289506..fb533164bf9b 100644
> --- a/libgomp/libgomp-plugin.h
> +++ b/libgomp/libgomp-plugin.h
> @@ -122,9 +122,9 @@ extern void GOMP_PLUGIN_fatal (const char *, ...)
>  
>  extern void GOMP_PLUGIN_target_rev (uint64_t, uint64_t, uint64_t, uint64_t,
>  				    uint64_t, int,
> -				    void (*) (void *, const void *, size_t,
> +				    bool (*) (void *, const void *, size_t,
>  					      void *),
> -				    void (*) (void *, const void *, size_t,
> +				    bool (*) (void *, const void *, size_t,
>  					      void *), void *);
>  
>  /* Prototypes for functions implemented by libgomp plugins.  */
> --- a/libgomp/libgomp.h
> +++ b/libgomp/libgomp.h
> @@ -1130,8 +1130,8 @@ extern int gomp_get_num_devices (void);
>  extern bool gomp_target_task_fn (void *);
>  extern void gomp_target_rev (uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
>  			     int,
> -			     void (*) (void *, const void *, size_t, void *),
> -			     void (*) (void *, const void *, size_t, void *),
> +			     bool (*) (void *, const void *, size_t, void *),
> +			     bool (*) (void *, const void *, size_t, void *),
>  			     void *);
>  
>  /* Splay tree definitions.  */

I think returning bool from those is fine.

> --- a/libgomp/plugin/plugin-nvptx.c
> +++ b/libgomp/plugin/plugin-nvptx.c
> @@ -1,3 +1,5 @@
> +#pragma GCC optimize "O0"

But the pragmas are not.

> --- a/libgomp/target.c
> +++ b/libgomp/target.c
> @@ -1,3 +1,5 @@
> +#pragma GCC optimize "O0"

Neither here.

> @@ -3340,12 +3342,21 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr,
>        kinds = (unsigned short *) gomp_malloc (mapnum * sizeof (unsigned short));
>        if (dev_to_host_cpy)
>         {
> -         dev_to_host_cpy (devaddrs, (const void *) (uintptr_t) devaddrs_ptr,
> -                          mapnum * sizeof (uint64_t), token);
> -         dev_to_host_cpy (sizes, (const void *) (uintptr_t) sizes_ptr,
> -                          mapnum * sizeof (uint64_t), token);
> -         dev_to_host_cpy (kinds, (const void *) (uintptr_t) kinds_ptr,
> -                          mapnum * sizeof (unsigned short), token);
> +         bool ok = true;
> +         ok = ok && dev_to_host_cpy (devaddrs,
> +                                     (const void *) (uintptr_t) devaddrs_ptr,
> +                                     mapnum * sizeof (uint64_t), token);
> +         ok = ok && dev_to_host_cpy (sizes,
> +                                     (const void *) (uintptr_t) sizes_ptr,
> +                                     mapnum * sizeof (uint64_t), token);
> +         ok = ok && dev_to_host_cpy (kinds,
> +                                     (const void *) (uintptr_t) kinds_ptr,
> +                                     mapnum * sizeof (unsigned short), token);

Why not just
	if (!dev_to_host_cpy (...)
	    || !dev_to_host_cpy (...)
	    || !dev_to_host_cpy (...))
?
	
> +         if (!ok)
> +           {
> +             /*TODO gomp_mutex_unlock (&devicep->lock); */

Why the comment?  That makes no sense, devicep->lock isn't locked here.

>  	    else if (dev_to_host_cpy)
> -	      dev_to_host_cpy (tgt + tgt_size, (void *) (uintptr_t) devaddrs[i],
> -			       (size_t) sizes[i], token);
> +	      {
> +		if (!dev_to_host_cpy (tgt + tgt_size,
> +				      (void *) (uintptr_t) devaddrs[i],
> +				      (size_t) sizes[i], token))
> +		  {
> +		    /*TODO gomp_mutex_unlock (&devicep->lock); */

Neither here.
> @@ -3662,9 +3692,15 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr,
>  	      case GOMP_MAP_FROM:
>  	      case GOMP_MAP_TOFROM:
>  		if (copy && host_to_dev_cpy)
> -		  host_to_dev_cpy ((void *) (uintptr_t) cdata[i].devaddr,
> -				   (void *) (uintptr_t) devaddrs[i],
> -				   sizes[i], token);
> +		  {
> +		    if (!host_to_dev_cpy ((void *) (uintptr_t) cdata[i].devaddr,
> +					  (void *) (uintptr_t) devaddrs[i],
> +					  sizes[i], token))
> +		      {
> +			/*TODO gomp_mutex_unlock (&devicep->lock); */

And neither here.
> +			exit (EXIT_FAILURE);
> +		      }
> +		  }

	Jakub


  reply	other threads:[~2022-12-15 17:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06  7:45 Tobias Burnus
2022-12-07  8:08 ` [Patch] libgomp.texi: Reverse-offload updates (was: [Patch] libgomp: Handle OpenMP's reverse offloads) Tobias Burnus
2022-12-10  8:18   ` Tobias Burnus
2023-01-31 12:21     ` Jakub Jelinek
2022-12-09 14:44 ` [Patch] libgomp: Handle OpenMP's reverse offloads Jakub Jelinek
2022-12-10  8:11   ` Tobias Burnus
2022-12-10  8:28     ` Jakub Jelinek
2022-12-15 17:34 ` Thomas Schwinge
2022-12-15 17:49   ` Jakub Jelinek [this message]
2022-12-15 19:42   ` Tobias Burnus
2022-12-15 20:13     ` Tobias Burnus

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=Y5teJt5jovrj8+W6@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=thomas@codesourcery.com \
    --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).