From patchwork Wed Oct 12 16:52:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1962 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2710017wrs; Wed, 12 Oct 2022 09:53:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KzkjwJUZX02tir9wzmzM223LHcuLyNs5p61oi/x1XCMSeJFF91ufLhM1W645rQbj/xh2Y X-Received: by 2002:aa7:dd01:0:b0:45c:6453:d22e with SMTP id i1-20020aa7dd01000000b0045c6453d22emr9445766edv.120.1665593590917; Wed, 12 Oct 2022 09:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665593590; cv=none; d=google.com; s=arc-20160816; b=aahGtte+jYRCNUTe0rYiSbTEd1RL+5fXU5fD0V8kurnM/BqUTZVWXBUjRcEEJgLuhz KgddGMJzH4EihypqdkyFofbO4ph82LndkhHwI0J3ZIckLOxtKoqO+ixl7SbcD98r6nQZ zjWQ7GbubAoc8pcCQtXnBmmBH8BdlqnolP6bpJot0Ab974u27xhzZGzNdy2rTUe4EiDU 0bXv+adkoo/HK82tLTA+rz739OANYugYuSdBLKqIECZGw/ME2RPPVhTg86a3KixWjgAz uBtMExwTfwFvLZkEPzgzFIsCOvle2Yc3C0vdyLeYNmW9sb73a/Gr1503Uq++wbwSb7HQ o7hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=EUOMVj6bIzxitYhD16fbuE7iNbec+4Ytf/i1NXXe6r8=; b=0PjUH9Fay4eEwSWoqlZbjk87KugBedEYGy2qLzsrz5Y+d0AFhuzNBc7187zRG+p2eK 7wsACEfuQ+B8ur1Uz+biAa8KtGfoMkzr2gEO4eqFECzDvs34V5qR0gVpwJDGGSLvYGTe e5PK1+SQ6eReWA8wPRVKlMI7fFHDsLQ8UknvqwzWPue0arUhJBRVsdVgh5Pwf244Fmkj EK01L2rvMkYKnUne748kWOeMa/px/5kRA0HXtx3JWN7sOQ07FbaOMZ+av/g36j3zzFIQ AqlrE60IBVWhQBwlk45FcvyI+YJvgsmHy3+IyRYyOoft8L2bBlK+8MucQ644PVjKKnck VgzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=q6RTeehN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ne1-20020a1709077b8100b0078d770f363fsi16707472ejc.471.2022.10.12.09.53.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 09:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=q6RTeehN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E489F38582BF for ; Wed, 12 Oct 2022 16:53:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E489F38582BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665593589; bh=EUOMVj6bIzxitYhD16fbuE7iNbec+4Ytf/i1NXXe6r8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=q6RTeehNP56bMsnfMCrp1papxH8HOqTZ6XyUWdF/y6/VIuHVOEoTWFMIJ9YH/1swy m1qvBu8fr1cG+n0O/zL7463A99Tc/C8DQkVoFoUywNgl6LA4nG7MbCFnXVq2eqxGMW LnRikQjQzne4DwBckhcWpCSpRKMt6V5u+gCZVTEQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 55B9C3858401 for ; Wed, 12 Oct 2022 16:52:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55B9C3858401 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-315-orKp5z-DNyaLsm9yTpdfMA-1; Wed, 12 Oct 2022 12:52:20 -0400 X-MC-Unique: orKp5z-DNyaLsm9yTpdfMA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9184F185A794; Wed, 12 Oct 2022 16:52:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D8EC4A9254; Wed, 12 Oct 2022 16:52:19 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 29CGqGLe1109847 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 12 Oct 2022 18:52:17 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29CGqGEW1109846; Wed, 12 Oct 2022 18:52:16 +0200 Date: Wed, 12 Oct 2022 18:52:15 +0200 To: Tobias Burnus Subject: [committed] libgomp: Add omp_in_explicit_task support Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746501465129935072?= X-GMAIL-MSGID: =?utf-8?q?1746501465129935072?= 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 * 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. Jakub --- 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 +#include + +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 +#include + +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 +#include + +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; +}