public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Tobias Burnus <tobias@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [committed] libgomp: Add omp_in_explicit_task support
Date: Wed, 12 Oct 2022 18:52:15 +0200	[thread overview]
Message-ID: <Y0bwv5mXC2V8Hu1s@tucnak> (raw)

Hi!

This is pretty straightforward, if gomp_thread ()->task is NULL,
it can't be explicit task, otherwise if
gomp_thread ()->task->kind == GOMP_TASK_IMPLICIT, it is an implicit
task, otherwise explicit task.

Regtested on x86_64-linux and i686-linux, committed to trunk.

2022-10-12  Jakub Jelinek  <jakub@redhat.com>

	* omp.h.in (omp_in_explicit_task): Declare.
	* omp_lib.h.in (omp_in_explicit_task): Likewise.
	* omp_lib.f90.in (omp_in_explicit_task): New interface.
	* libgomp.map (OMP_5.2): New symbol version, export
	omp_in_explicit_task and omp_in_explicit_task_.
	* task.c (omp_in_explicit_task): New function.
	* fortran.c (omp_in_explicit_task): Add ialias_redirect.
	(omp_in_explicit_task_): New function.
	* libgomp.texi (OpenMP 5.2): Mark omp_in_explicit_task as implemented.
	* testsuite/libgomp.c-c++-common/task-in-explicit-1.c: New test.
	* testsuite/libgomp.c-c++-common/task-in-explicit-2.c: New test.
	* testsuite/libgomp.c-c++-common/task-in-explicit-3.c: New test.

--- libgomp/omp.h.in.jj	2022-06-13 14:02:37.231566968 +0200
+++ libgomp/omp.h.in	2022-10-12 13:30:00.414777439 +0200
@@ -244,6 +244,7 @@ extern int omp_get_team_size (int) __GOM
 extern int omp_get_active_level (void) __GOMP_NOTHROW;
 
 extern int omp_in_final (void) __GOMP_NOTHROW;
+extern int omp_in_explicit_task (void) __GOMP_NOTHROW;
 
 extern int omp_get_cancellation (void) __GOMP_NOTHROW;
 extern omp_proc_bind_t omp_get_proc_bind (void) __GOMP_NOTHROW;
--- libgomp/omp_lib.h.in.jj	2022-06-13 14:02:37.232566958 +0200
+++ libgomp/omp_lib.h.in	2022-10-12 13:30:58.761972700 +0200
@@ -220,6 +220,8 @@
 
       external omp_in_final
       logical(4) omp_in_final
+      external omp_in_explicit_task
+      logical(4) omp_in_explicit_task
 
       external omp_get_cancellation
       logical(4) omp_get_cancellation
--- libgomp/omp_lib.f90.in.jj	2022-06-13 14:02:37.231566968 +0200
+++ libgomp/omp_lib.f90.in	2022-10-12 13:30:37.134271001 +0200
@@ -445,6 +445,12 @@
         end interface
 
         interface
+          function omp_in_explicit_task ()
+            logical (4) :: omp_in_explicit_task
+          end function omp_in_explicit_task
+        end interface
+
+        interface
           function omp_get_cancellation ()
             logical (4) :: omp_get_cancellation
           end function omp_get_cancellation
--- libgomp/libgomp.map.jj	2022-05-24 09:12:34.689470538 +0200
+++ libgomp/libgomp.map	2022-10-12 13:36:46.847171857 +0200
@@ -234,6 +234,12 @@ OMP_5.1.1 {
 	omp_target_memcpy_rect_async;
 } OMP_5.1;
 
+OMP_5.2 {
+  global:
+	omp_in_explicit_task;
+	omp_in_explicit_task_;
+} OMP_5.1.1;
+
 GOMP_1.0 {
   global:
 	GOMP_atomic_end;
--- libgomp/task.c.jj	2022-05-25 11:10:32.543261788 +0200
+++ libgomp/task.c	2022-10-12 16:49:03.342493229 +0200
@@ -2678,6 +2678,16 @@ omp_in_final (void)
 
 ialias (omp_in_final)
 
+int
+omp_in_explicit_task (void)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_task *task = thr->task;
+  return task && task->kind != GOMP_TASK_IMPLICIT;
+}
+
+ialias (omp_in_explicit_task)
+
 void
 omp_fulfill_event (omp_event_handle_t event)
 {
--- libgomp/fortran.c.jj	2022-03-16 16:26:46.236198146 +0100
+++ libgomp/fortran.c	2022-10-12 14:25:03.072193607 +0200
@@ -76,6 +76,7 @@ ialias_redirect (omp_get_ancestor_thread
 ialias_redirect (omp_get_team_size)
 ialias_redirect (omp_get_active_level)
 ialias_redirect (omp_in_final)
+ialias_redirect (omp_in_explicit_task)
 ialias_redirect (omp_get_cancellation)
 ialias_redirect (omp_get_proc_bind)
 ialias_redirect (omp_get_num_places)
@@ -482,6 +483,12 @@ omp_in_final_ (void)
   return omp_in_final ();
 }
 
+int32_t
+omp_in_explicit_task_ (void)
+{
+  return omp_in_explicit_task ();
+}
+
 void
 omp_set_num_teams_ (const int32_t *num_teams)
 {
--- libgomp/libgomp.texi.jj	2022-10-06 08:55:02.776290479 +0200
+++ libgomp/libgomp.texi	2022-10-12 17:16:21.809127181 +0200
@@ -360,8 +360,8 @@ to address of matching mapped list item
 
 @multitable @columnfractions .60 .10 .25
 @headitem Description @tab Status @tab Comments
-@item @code{omp_in_explicit_task} routine and @emph{implicit-task-var} ICV
-      @tab N @tab
+@item @code{omp_in_explicit_task} routine and @emph{explicit-task-var} ICV
+      @tab Y @tab
 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
       namespaces @tab N/A
       @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
--- libgomp/testsuite/libgomp.c-c++-common/task-in-explicit-1.c.jj	2022-10-12 14:50:34.515132245 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/task-in-explicit-1.c	2022-10-12 15:26:56.086277744 +0200
@@ -0,0 +1,106 @@
+/* { dg-do run } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+  if (omp_in_explicit_task ())
+    abort ();
+  #pragma omp task
+  if (!omp_in_explicit_task ())
+    abort ();
+  #pragma omp task final (1)
+  {
+    if (!omp_in_explicit_task ())
+      abort ();
+    #pragma omp task 
+    if (!omp_in_explicit_task ())
+      abort ();
+  }
+  #pragma omp parallel
+  {
+    if (omp_in_explicit_task ())
+      abort ();
+    #pragma omp task if (0)
+      {
+	if (!omp_in_explicit_task ())
+	  abort ();
+	#pragma omp task if (0)
+	  if (!omp_in_explicit_task ())
+	    abort ();
+      }
+    #pragma omp task final (1)
+      if (!omp_in_explicit_task ())
+	abort ();
+    #pragma omp barrier
+    if (omp_in_explicit_task ())
+      abort ();
+    #pragma omp taskloop num_tasks (24)
+    for (int i = 0; i < 32; ++i)
+      if (!omp_in_explicit_task ())
+	abort ();
+    #pragma omp masked
+    #pragma omp task
+    if (!omp_in_explicit_task ())
+      abort ();
+    #pragma omp barrier
+    if (omp_in_explicit_task ())
+      abort ();
+  }
+  #pragma omp target
+  {
+    if (omp_in_explicit_task ())
+      abort ();
+    #pragma omp task if (0)
+    if (!omp_in_explicit_task ())
+      abort ();
+    #pragma omp task
+    if (!omp_in_explicit_task ())
+      abort ();
+  }
+  #pragma omp target teams
+  {
+    #pragma omp distribute
+    for (int i = 0; i < 4; ++i)
+      if (omp_in_explicit_task ())
+	abort ();
+      else
+	{
+	  #pragma omp parallel
+	  {
+	    if (omp_in_explicit_task ())
+	      abort ();
+	    #pragma omp task
+	    if (!omp_in_explicit_task ())
+	      abort ();
+	    #pragma omp barrier
+	    if (omp_in_explicit_task ())
+	      abort ();
+	  }
+	}
+  }
+  #pragma omp teams
+  {
+    #pragma omp distribute
+    for (int i = 0; i < 4; ++i)
+      if (omp_in_explicit_task ())
+	abort ();
+      else
+	{
+	  #pragma omp parallel
+	  {
+	    if (omp_in_explicit_task ())
+	      abort ();
+	    #pragma omp task
+	    if (!omp_in_explicit_task ())
+	      abort ();
+	    #pragma omp barrier
+	    if (omp_in_explicit_task ())
+	      abort ();
+	  }
+	}
+  }
+  return 0;
+}
--- libgomp/testsuite/libgomp.c-c++-common/task-in-explicit-2.c.jj	2022-10-12 15:35:51.050014559 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/task-in-explicit-2.c	2022-10-12 16:03:21.340767797 +0200
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+  #pragma omp task
+  {
+    if (!omp_in_explicit_task ())
+      abort ();
+    #pragma omp task
+    {
+      if (!omp_in_explicit_task ())
+	abort ();
+      #pragma omp target nowait
+      if (omp_in_explicit_task ())
+	abort ();
+      if (!omp_in_explicit_task ())
+	abort ();
+      #pragma omp taskwait
+    }
+  }
+  return 0;
+}
--- libgomp/testsuite/libgomp.c-c++-common/task-in-explicit-3.c.jj	2022-10-12 17:11:15.896291053 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/task-in-explicit-3.c	2022-10-12 17:12:04.218631254 +0200
@@ -0,0 +1,36 @@
+/* { dg-do run } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+int a;
+
+int
+main ()
+{
+  #pragma omp task
+  {
+    if (!omp_in_explicit_task ())
+      abort ();
+    #pragma omp task
+    {
+      if (!omp_in_explicit_task ())
+	abort ();
+      #pragma omp taskgroup task_reduction (+: a)
+      {
+	if (!omp_in_explicit_task ())
+	  abort ();
+	#pragma omp task in_reduction (+: a)
+	{
+	  ++a;
+	  if (!omp_in_explicit_task ())
+	    abort ();
+	}
+      }
+      if (!omp_in_explicit_task ())
+	abort ();
+      #pragma omp taskwait
+    }
+  }
+  return 0;
+}

	Jakub


                 reply	other threads:[~2022-10-12 16:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=Y0bwv5mXC2V8Hu1s@tucnak \
    --to=jakub@redhat.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).