From patchwork Wed Aug 5 08:59:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1341143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=xalCE0rO; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BM5D36lKlz9s1x for ; Wed, 5 Aug 2020 18:59:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14374386F83F; Wed, 5 Aug 2020 08:59:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14374386F83F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596617985; bh=6RMyhGU+lmDUBA7E90b8EkqfZ0jzUug+4Ws2Tc2ptto=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xalCE0rOrgK331Hb4oc4Bf0RvkCZsZQ+9Cu0LG4GOUgeoaaQq3NmwptRbsDcMP9AF yEqxKX6zkBKEAMlHJ9xsWMBEAxCOXhjqSaRwBLPRP23XNkXzoaNKk4BbpFPpMWk3+p eR8jtUxTY3tRwDMa2cW068USiul5iUpND3yj/STI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 630E8385700D for ; Wed, 5 Aug 2020 08:59:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 630E8385700D Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-XGLO0zaHPWadY3Em7VcEWg-1; Wed, 05 Aug 2020 04:59:39 -0400 X-MC-Unique: XGLO0zaHPWadY3Em7VcEWg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E99C958 for ; Wed, 5 Aug 2020 08:59:38 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-174.ams2.redhat.com [10.36.113.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 95EF860BF3 for ; Wed, 5 Aug 2020 08:59:38 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 0758xaq2028769 for ; Wed, 5 Aug 2020 10:59:36 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 0758xZFG028768 for gcc-patches@gcc.gnu.org; Wed, 5 Aug 2020 10:59:35 +0200 Date: Wed, 5 Aug 2020 10:59:35 +0200 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Handle reduction clauses on host teams construct [PR96459] Message-ID: <20200805085935.GR2375@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP, UNWANTED_LANGUAGE_BODY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: *** X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! As the new testcase shows, we weren't actually performing reductions on host teams construct. And fixing that revealed a flaw in the for-14.c testcase. The problem is that the tests perform also initialization and checking around the calls to the functions with the OpenMP constructs. In that testcase, all the tests have been spawned from a teams construct but only the tested loops were distribute, which means the initialization and checking has been performed redundantly and racily in each team. Fixed by performing the initialization and checking outside of host teams and only do the calls to functions with the tested constructs inside of host teams. 2020-08-05 Jakub Jelinek PR middle-end/96459 * omp-low.c (lower_omp_taskreg): Call lower_reduction_clauses even in for host teams. * testsuite/libgomp.c/teams-3.c: New test. * testsuite/libgomp.c-c++-common/for-2.h (OMPTEAMS): Define to nothing if not defined yet. (N(test)): Use it before all N(f*) calls. * testsuite/libgomp.c-c++-common/for-14.c (DO_PRAGMA, OMPTEAMS): Define. (main): Don't call all test_* functions from within #pragma omp teams reduction(|:err), call them directly. Jakub --- gcc/omp-low.c.jj 2020-08-03 22:54:51.433531450 +0200 +++ gcc/omp-low.c 2020-08-04 16:29:49.269885408 +0200 @@ -11236,7 +11236,7 @@ lower_omp_taskreg (gimple_stmt_iterator gimple_seq par_rlist = NULL; lower_rec_input_clauses (clauses, &par_ilist, &par_olist, ctx, NULL); lower_omp (&par_body, ctx); - if (gimple_code (stmt) == GIMPLE_OMP_PARALLEL) + if (gimple_code (stmt) != GIMPLE_OMP_TASK) lower_reduction_clauses (clauses, &par_rlist, NULL, ctx); /* Declare all the variables created by mapping and the variables --- libgomp/testsuite/libgomp.c/teams-3.c.jj 2020-08-04 16:44:54.063734515 +0200 +++ libgomp/testsuite/libgomp.c/teams-3.c 2020-08-04 16:52:38.961983329 +0200 @@ -0,0 +1,20 @@ +/* PR middle-end/96459 */ + +#include + +int +main () +{ + int niters = 0, i, j, k; + #pragma omp teams reduction(+:niters) + { + #pragma omp distribute collapse(3) + for (i = 0; i < 3; i++) + for (j = 0; j < 8; j += 2) + for (k = 0; k < 25; k += 3) + niters++; + } + if (niters != 108) + abort (); + return 0; +} --- libgomp/testsuite/libgomp.c-c++-common/for-2.h.jj 2020-01-12 11:54:39.027373971 +0100 +++ libgomp/testsuite/libgomp.c-c++-common/for-2.h 2020-08-05 10:19:05.171118863 +0200 @@ -14,6 +14,9 @@ noreturn (void) #ifndef OMPTGT #define OMPTGT #endif +#ifndef OMPTEAMS +#define OMPTEAMS +#endif #ifndef OMPTO #define OMPTO(v) do {} while (0) #endif @@ -214,31 +217,37 @@ N(test) (void) for (i = 0; i < 1500; i++) a[i] = i - 25; OMPTO (a); + OMPTEAMS N(f0) (); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 23) return 1; + OMPTEAMS N(f1) (); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 25) return 1; + OMPTEAMS N(f2) (); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 29) return 1; + OMPTEAMS N(f3) (1500LL - 1 - 23 - 48, -1LL + 25 - 48, 1LL); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 22) return 1; + OMPTEAMS N(f3) (1500LL - 1 - 23 - 48, 1500LL - 1, 7LL); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 22) return 1; + OMPTEAMS N(f4) (); OMPFROM (a); for (i = 0; i < 1500; i++) @@ -249,6 +258,7 @@ N(test) (void) for (k = 0; k < 10; k++) b[i][j][k] = i - 2.5 + 1.5 * j - 1.5 * k; OMPTO (b); + OMPTEAMS N(f5) (0, 10, 0, 15, 0, 10, 1, 1, 1); OMPFROM (b); for (i = 0; i < 10; i++) @@ -256,6 +266,7 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f5) (0, 10, 30, 15, 0, 10, 4, 5, 6); OMPFROM (b); for (i = 0; i < 10; i++) @@ -263,6 +274,7 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f6) (9, -1, 29, 0, 9, -1, -1, -2, -1); OMPFROM (b); for (i = 0; i < 10; i++) @@ -270,6 +282,7 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i - 4.5 + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f7) (); OMPFROM (b); for (i = 0; i < 10; i++) @@ -277,6 +290,7 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f8) (); OMPFROM (b); for (i = 0; i < 10; i++) @@ -284,9 +298,13 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f9) (); + OMPTEAMS N(f10) (); + OMPTEAMS N(f11) (10); + OMPTEAMS N(f12) (12); OMPFROM (a); OMPFROM (b); @@ -298,7 +316,9 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f13) (); + OMPTEAMS N(f14) (); OMPFROM (a); OMPFROM (b); @@ -507,26 +527,31 @@ N(test) (void) for (i = 0; i < 1500; i++) a[i] = i - 25; OMPTO (a); + OMPTEAMS N(f20) (); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 23) return 1; + OMPTEAMS N(f21) (); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 25) return 1; + OMPTEAMS N(f22) (); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 29) return 1; + OMPTEAMS N(f23) (1500LL - 1 - 23 - 48, -1LL + 25 - 48); OMPFROM (a); for (i = 0; i < 1500; i++) if (a[i] != i - 22) return 1; + OMPTEAMS N(f24) (); OMPFROM (a); for (i = 0; i < 1500; i++) @@ -537,6 +562,7 @@ N(test) (void) for (k = 0; k < 10; k++) b[i][j][k] = i - 2.5 + 1.5 * j - 1.5 * k; OMPTO (b); + OMPTEAMS N(f25) (0, 10, 0, 15, 0, 10, 1); OMPFROM (b); for (i = 0; i < 10; i++) @@ -544,6 +570,7 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f25) (0, 10, 30, 15, 0, 10, 5); OMPFROM (b); for (i = 0; i < 10; i++) @@ -551,6 +578,7 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f26) (9, -1, 29, 0, 9, -1, -2); OMPFROM (b); for (i = 0; i < 10; i++) @@ -558,6 +586,7 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i - 4.5 + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f27) (); OMPFROM (b); for (i = 0; i < 10; i++) @@ -565,6 +594,7 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f28) (); OMPFROM (b); for (i = 0; i < 10; i++) @@ -572,9 +602,13 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f29) (); + OMPTEAMS N(f30) (); + OMPTEAMS N(f31) (20); + OMPTEAMS N(f32) (12); OMPFROM (a); OMPFROM (b); @@ -586,7 +620,9 @@ N(test) (void) for (k = 0; k < 10; k++) if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k) return 1; + OMPTEAMS N(f33) (); + OMPTEAMS N(f34) (); OMPFROM (a); OMPFROM (b); --- libgomp/testsuite/libgomp.c-c++-common/for-14.c.jj 2020-01-12 11:54:39.027373971 +0100 +++ libgomp/testsuite/libgomp.c-c++-common/for-14.c 2020-08-05 10:20:26.034937370 +0200 @@ -6,6 +6,8 @@ extern #endif void abort (); +#define DO_PRAGMA(x) _Pragma (#x) +#define OMPTEAMS DO_PRAGMA (omp teams) #define M(x, y, z) O(x, y, z) #define O(x, y, z) x ## _ ## y ## _ ## z @@ -77,33 +79,30 @@ int main () { int err = 0; - #pragma omp teams reduction(|:err) - { - err |= test_d_normal (); - err |= test_d_ds128_normal (); - err |= test_ds_normal (); - err |= test_ds_ds128_normal (); - err |= test_dpf_static (); - err |= test_dpf_static32 (); - err |= test_dpf_auto (); - err |= test_dpf_guided32 (); - err |= test_dpf_runtime (); - err |= test_dpf_ds128_static (); - err |= test_dpf_ds128_static32 (); - err |= test_dpf_ds128_auto (); - err |= test_dpf_ds128_guided32 (); - err |= test_dpf_ds128_runtime (); - err |= test_dpfs_static (); - err |= test_dpfs_static32 (); - err |= test_dpfs_auto (); - err |= test_dpfs_guided32 (); - err |= test_dpfs_runtime (); - err |= test_dpfs_ds128_static (); - err |= test_dpfs_ds128_static32 (); - err |= test_dpfs_ds128_auto (); - err |= test_dpfs_ds128_guided32 (); - err |= test_dpfs_ds128_runtime (); - } + err |= test_d_normal (); + err |= test_d_ds128_normal (); + err |= test_ds_normal (); + err |= test_ds_ds128_normal (); + err |= test_dpf_static (); + err |= test_dpf_static32 (); + err |= test_dpf_auto (); + err |= test_dpf_guided32 (); + err |= test_dpf_runtime (); + err |= test_dpf_ds128_static (); + err |= test_dpf_ds128_static32 (); + err |= test_dpf_ds128_auto (); + err |= test_dpf_ds128_guided32 (); + err |= test_dpf_ds128_runtime (); + err |= test_dpfs_static (); + err |= test_dpfs_static32 (); + err |= test_dpfs_auto (); + err |= test_dpfs_guided32 (); + err |= test_dpfs_runtime (); + err |= test_dpfs_ds128_static (); + err |= test_dpfs_ds128_static32 (); + err |= test_dpfs_ds128_auto (); + err |= test_dpfs_ds128_guided32 (); + err |= test_dpfs_ds128_runtime (); if (err) abort (); return 0;