From patchwork Wed Nov 17 16:03:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederik Harwath X-Patchwork-Id: 47824 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F47B385AC35 for ; Wed, 17 Nov 2021 16:16:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id C3EF5385AC35 for ; Wed, 17 Nov 2021 16:04:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C3EF5385AC35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: Jv2mBx3wxnX6ex/qmYiPWmalo3RYPFA1YSq1/4z6cPyS3qwUk/d5+G/D2xaLU/jbQV8z/v0daC tNAWKMLoo7ywwZvOESWjuNUuUEBnZ69z13T3stZZaXv2U4PEE+mKDw0INNeHTzeof/bhZfDghB buJhQsfY167X3p/LegI8+CEM+1RFpdpxEz0l4awWUh1GbsXGUaxLVTUbClUSlzKi8QoGp9NeRb 4q3EKt3YFBYaQF5koqx+v0Unyl34p4oAH7Ku+p0f/Vi6sqozrcPHd2fdkQjWNxW1hIQskkmG4r B1nLUeCbydLol71T0hWTrjvc X-IronPort-AV: E=Sophos;i="5.87,241,1631606400"; d="scan'208";a="68445352" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Nov 2021 08:04:24 -0800 IronPort-SDR: a913eyI0WQSZWMYU6UvVUJ8AAFcxNJeNy9eI8ucafcj9Vo1cd8Wtq2gDFqztfSKGbN2HiHdBWZ FnP9M2CuI/dErNjYBIsVc6POySyaSse0tZQzBzZUh3Sj7y1phksLtCkN2cnJUfTr2hvEk2vfJQ eKh1U8YEB57ETg0/Q2jt1l2Yyqc+GVFmYEYoYZfAfSEi9Z5XVXcwfqTEITxunPtNInSC3tuBXz uQGvcx4m72bi/zZcLSlgFTBzHR/Jw1xtBpEmBxjm6VESUSlL6AQNyiXsQ/UXOUDc6ksN7FI2qG XwA= From: Frederik Harwath To: Subject: [OG11][committed][PATCH 12/22] openacc: Remove unused partitioning in "kernels" regions Date: Wed, 17 Nov 2021 17:03:20 +0100 Message-ID: <20211117160330.20029-12-frederik@codesourcery.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211117160330.20029-1-frederik@codesourcery.com> References: <20211117160330.20029-1-frederik@codesourcery.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" With the old "kernels" handling, unparallelized regions would get executed with 1x1x1 partitioning even if the user provided explicit num_gangs, num_workers clauses etc. This commit restores this behavior by removing unused partitioning after assigning the parallelism dimensions to loops. gcc/ChangeLog: * omp-offload.c (oacc_remove_unused_partitioning): New function for removing partitioning that is not used by any loop. (oacc_validate_dims): Call oacc_remove_unused_partitioning and enable warnings about unused partitioning. libgomp/ChangeLog: * testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: Adjust expectations. --- gcc/omp-offload.c | 51 +++++++++++++++++-- .../acc_prof-kernels-1.c | 19 ++++--- 2 files changed, 59 insertions(+), 11 deletions(-) -- 2.33.0 ----------------- 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 diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c index f5cb222efd8c..68cc5a9d9e5d 100644 --- a/gcc/omp-offload.c +++ b/gcc/omp-offload.c @@ -1215,6 +1215,39 @@ oacc_parse_default_dims (const char *dims) targetm.goacc.validate_dims (NULL_TREE, oacc_min_dims, -2, 0); } +/* Remove parallelism dimensions below LEVEL which are not set in USED + from DIMS and emit a warning pointing to the location of FN. */ + +static void +oacc_remove_unused_partitioning (tree fn, int *dims, int level, unsigned used) +{ + + bool host_compiler = true; +#ifdef ACCEL_COMPILER + host_compiler = false; +#endif + + static char const *const axes[] = + /* Must be kept in sync with GOMP_DIM enumeration. */ + { "gang", "worker", "vector" }; + + char removed_partitions[20] = "\0"; + for (int ix = level >= 0 ? level : 0; ix != GOMP_DIM_MAX; ix++) + if (!(used & GOMP_DIM_MASK (ix)) && dims[ix] >= 0) + { + if (host_compiler) + { + strcat (removed_partitions, axes[ix]); + strcat (removed_partitions, " "); + } + dims[ix] = -1; + } + if (removed_partitions[0] != '\0') + warning_at (DECL_SOURCE_LOCATION (fn), OPT_Wopenacc_parallelism, + "removed %spartitioning from % region", + removed_partitions); +} + /* Validate and update the dimensions for offloaded FN. ATTRS is the raw attribute. DIMS is an array of dimensions, which is filled in. LEVEL is the partitioning level of a routine, or -1 for an offload @@ -1235,6 +1268,7 @@ oacc_validate_dims (tree fn, tree attrs, int *dims, int level, unsigned used) for (ix = 0; ix != GOMP_DIM_MAX; ix++) { purpose[ix] = TREE_PURPOSE (pos); + tree val = TREE_VALUE (pos); dims[ix] = val ? TREE_INT_CST_LOW (val) : -1; pos = TREE_CHAIN (pos); @@ -1244,14 +1278,15 @@ oacc_validate_dims (tree fn, tree attrs, int *dims, int level, unsigned used) #ifdef ACCEL_COMPILER check = false; #endif + + static char const *const axes[] = + /* Must be kept in sync with GOMP_DIM enumeration. */ + { "gang", "worker", "vector" }; + if (check && warn_openacc_parallelism - && !lookup_attribute ("oacc kernels", DECL_ATTRIBUTES (fn)) - && !lookup_attribute ("oacc parallel_kernels_graphite", DECL_ATTRIBUTES (fn))) + && !lookup_attribute ("oacc kernels", DECL_ATTRIBUTES (fn))) { - static char const *const axes[] = - /* Must be kept in sync with GOMP_DIM enumeration. */ - { "gang", "worker", "vector" }; for (ix = level >= 0 ? level : 0; ix != GOMP_DIM_MAX; ix++) if (dims[ix] < 0) ; /* Defaulting axis. */ @@ -1262,14 +1297,20 @@ oacc_validate_dims (tree fn, tree attrs, int *dims, int level, unsigned used) "region contains %s partitioned code but" " is not %s partitioned", axes[ix], axes[ix]); else if (!(used & GOMP_DIM_MASK (ix)) && dims[ix] != 1) + { /* The dimension is explicitly partitioned to non-unity, but no use is made within the region. */ warning_at (DECL_SOURCE_LOCATION (fn), OPT_Wopenacc_parallelism, "region is %s partitioned but" " does not contain %s partitioned code", axes[ix], axes[ix]); + } } + if (lookup_attribute ("oacc parallel_kernels_graphite", + DECL_ATTRIBUTES (fn))) + oacc_remove_unused_partitioning (fn, dims, level, used); + bool changed = targetm.goacc.validate_dims (fn, dims, level, used); /* Default anything left to 1 or a partitioned default. */ diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c index 4a9b11a3d3fe..d398b3463617 100644 --- a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c @@ -7,6 +7,8 @@ #include +/* { dg-skip-if "'kernels' not analyzed by Graphite at -O0" { *-*-* } { "-O0" } { "" } } */ +/* { dg-additional-options "-Wopenacc-parallelism" } */ /* Use explicit 'copyin' clauses, to work around "'firstprivate' optimizations", which will cause the value at the point of call to be used @@ -41,6 +43,7 @@ static int state = -1; static acc_device_t acc_device_type; static int acc_device_num; static int num_gangs, num_workers, vector_length; +static int real_num_workers; static int async; @@ -96,12 +99,8 @@ static void cb_enqueue_launch_start (acc_prof_info *prof_info, acc_event_info *e assert (event_info->launch_event.num_workers >= 1); else { -#ifdef __OPTIMIZE__ - assert (event_info->launch_event.num_workers == num_workers); -#else - /* See 'num_gangs' above. */ - assert (event_info->launch_event.num_workers == 1); -#endif + /* Unused partitioning levels get removed from "kernels" region. */ + assert (event_info->launch_event.num_workers == real_num_workers); } if (vector_length < 1) assert (event_info->launch_event.vector_length >= 1); @@ -186,6 +185,7 @@ int main() /* Parallelism dimensions: literal. */ num_gangs = 30; num_workers = 3; + real_num_workers = 1; vector_length = 5; { #define N 100 @@ -196,6 +196,8 @@ int main() /* { dg-prune-output "using vector_length \\(32\\), ignoring 5" } */ { for (int i = 0; i < N; ++i) + /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-1 } */ + /* { dg-warning "removed worker partitioning from 'kernels' region" "" { target *-*-* } .-2 } */ x[i] = i * i; } if (acc_device_type == acc_device_host) @@ -214,6 +216,9 @@ int main() /* Parallelism dimensions: variable. */ num_gangs = 22; num_workers = 5; + /* No worker loop and hence, in a kernels region, worker partitioning + should be removed. */ + real_num_workers = 1; vector_length = 7; { #define N 100 @@ -224,6 +229,8 @@ int main() /* { dg-prune-output "using vector_length \\(32\\), ignoring runtime setting" } */ { for (int i = 0; i < N; ++i) + /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-1 } */ + /* { dg-warning "removed worker partitioning from 'kernels' region" "" { target *-*-* } .-2 } */ x[i] = i * i; } if (acc_device_type == acc_device_host)