From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 97116 invoked by alias); 26 Aug 2015 12:29:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 97104 invoked by uid 89); 26 Aug 2015 12:29:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qg0-f41.google.com Received: from mail-qg0-f41.google.com (HELO mail-qg0-f41.google.com) (209.85.192.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 26 Aug 2015 12:29:11 +0000 Received: by qgj62 with SMTP id 62so124881364qgj.2 for ; Wed, 26 Aug 2015 05:29:09 -0700 (PDT) X-Received: by 10.140.236.194 with SMTP id h185mr82058740qhc.45.1440592149175; Wed, 26 Aug 2015 05:29:09 -0700 (PDT) Received: from ?IPv6:2601:181:c000:c497:a2a8:cdff:fe3e:b48? ([2601:181:c000:c497:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id g204sm16211740qhc.35.2015.08.26.05.29.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Aug 2015 05:29:08 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [gomp4] loop partition optimization Message-ID: <55DDB113.7050102@acm.org> Date: Wed, 26 Aug 2015 12:33:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040409000200060007010402" X-SW-Source: 2015-08/txt/msg01598.txt.bz2 This is a multi-part message in MIME format. --------------040409000200060007010402 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 681 I've committed this patch, which implements a simple partioned execution optimization. A loop over both worker and vector dimensions is emits separate FORK and JOIN markers for the two dimensions -- there may be reduction pieces between them, as Cesar will shortly be committing. However, if there aren't reductions, then we end up with one partitioned region sitting neatly entirely inside another region. This is inefficient, as it causes us to add separate worker and vector partitioning startup. This optimization looks for regions of this form, and if found consumes the inner retion into the outer region. Then we only emit a single setup block of code. nathan --------------040409000200060007010402 Content-Type: text/x-patch; name="gomp4-part-opt.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gomp4-part-opt.patch" Content-length: 4274 2015-08-26 Nathan Sidwell * config/nvptx/nvptx.opt (moptimize): New flag. * config/nvptx/nvptx.c (nvptx_option_override): Default nvptx_optimize. (nvptx_optimmize_inner): New. (nvptx_process_pars): Call it. * doc/invoke.txi (Nvptx options): Document moptimize. Index: gcc/config/nvptx/nvptx.c =================================================================== --- gcc/config/nvptx/nvptx.c (revision 227180) +++ gcc/config/nvptx/nvptx.c (working copy) @@ -178,6 +178,9 @@ nvptx_option_override (void) write_symbols = NO_DEBUG; debug_info_level = DINFO_LEVEL_NONE; + if (nvptx_optimize < 0) + nvptx_optimize = optimize > 0; + declared_fndecls_htab = hash_table::create_ggc (17); needed_fndecls_htab = hash_table::create_ggc (17); declared_libfuncs_htab @@ -3005,6 +3008,64 @@ nvptx_skip_par (unsigned mask, parallel nvptx_single (mask, par->forked_block, pre_tail); } +/* If PAR has a single inner parallel and PAR itself only contains + empty entry and exit blocks, swallow the inner PAR. */ + +static void +nvptx_optimize_inner (parallel *par) +{ + parallel *inner = par->inner; + + /* We mustn't be the outer dummy par. */ + if (!par->mask) + return; + + /* We must have a single inner par. */ + if (!inner || inner->next) + return; + + /* We must only contain 2 blocks ourselves -- the head and tail of + the inner par. */ + if (par->blocks.length () != 2) + return; + + /* We must be disjoint partitioning. As we only have vector and + worker partitioning, this is sufficient to guarantee the pars + have adjacent partitioning. */ + if ((par->mask & inner->mask) & (GOMP_DIM_MASK (GOMP_DIM_MAX) - 1)) + /* This indicates malformed code generation. */ + return; + + /* The outer forked insn should be the only one in its block. */ + rtx_insn *probe; + rtx_insn *forked = par->forked_insn; + for (probe = BB_END (par->forked_block); + probe != forked; probe = PREV_INSN (probe)) + if (INSN_P (probe)) + return; + + /* The outer joining insn, if any, must be in the same block as the inner + joined instruction, which must otherwise be empty of insns. */ + rtx_insn *joining = par->joining_insn; + rtx_insn *join = inner->join_insn; + for (probe = BB_END (inner->join_block); + probe != join; probe = PREV_INSN (probe)) + if (probe != joining && INSN_P (probe)) + return; + + /* Preconditions met. Swallow the inner par. */ + par->mask |= inner->mask & (GOMP_DIM_MASK (GOMP_DIM_MAX) - 1); + + par->blocks.reserve (inner->blocks.length ()); + while (inner->blocks.length ()) + par->blocks.quick_push (inner->blocks.pop ()); + + par->inner = inner->inner; + inner->inner = NULL; + + delete inner; +} + /* Process the parallel PAR and all its contained parallels. We do everything but the neutering. Return mask of partitioned modes used within this parallel. */ @@ -3012,8 +3073,11 @@ nvptx_skip_par (unsigned mask, parallel static unsigned nvptx_process_pars (parallel *par) { - unsigned inner_mask = par->mask; + if (nvptx_optimize) + nvptx_optimize_inner (par); + unsigned inner_mask = par->mask; + /* Do the inner parallels first. */ if (par->inner) { Index: gcc/config/nvptx/nvptx.opt =================================================================== --- gcc/config/nvptx/nvptx.opt (revision 227180) +++ gcc/config/nvptx/nvptx.opt (working copy) @@ -29,6 +29,10 @@ mmainkernel Target Report RejectNegative Link in code for a __main kernel. +moptimize +Target Report Var(nvptx_optimize) Init(-1) +Optimize partition neutering + Enum Name(ptx_isa) Type(int) Known PTX ISA versions (for use with the -misa= option): Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 227180) +++ gcc/doc/invoke.texi (working copy) @@ -18814,6 +18814,11 @@ Generate code for 32-bit or 64-bit ABI. Link in code for a __main kernel. This is for stand-alone instead of offloading execution. +@item -moptimize +@opindex moptimize +Apply partitioned execution optimizations. This is the default when any +level of optimization is selected. + @end table @node PDP-11 Options --------------040409000200060007010402--