From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 8848F385840F for ; Fri, 12 Nov 2021 19:16:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8848F385840F Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id 6B4E340D403D; Fri, 12 Nov 2021 19:16:11 +0000 (UTC) Date: Fri, 12 Nov 2021 22:16:11 +0300 (MSK) From: Alexander Monakov To: Jakub Jelinek cc: Tom de Vries , Tobias Burnus , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] libgomp, nvptx, v3: Honor OpenMP 5.1 num_teams lower bound In-Reply-To: <20211112175804.GJ2710@tucnak> Message-ID: References: <20211112132023.GC2710@tucnak> <20211112132716.GD2710@tucnak> <20211112175804.GJ2710@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, 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: , X-List-Received-Date: Fri, 12 Nov 2021 19:16:17 -0000 Hello Jakub, On Fri, 12 Nov 2021, Jakub Jelinek via Gcc-patches wrote: > On Fri, Nov 12, 2021 at 02:27:16PM +0100, Jakub Jelinek via Gcc-patches wrote: > > On Fri, Nov 12, 2021 at 02:20:23PM +0100, Jakub Jelinek via Gcc-patches wrote: > > > This patch assumes that .shared variables are initialized to 0, > > > https://docs.nvidia.com/cuda/parallel-thread-execution/index.html lists > > > in Table 7. .shared as non-initializable. If that isn't the case, > > > we need to initialize it somewhere for the case of #pragma omp target > > > without #pragma omp teams in it, maybe in libgcc/config/nvptx/crt0.c ? > > > > A quick look at libgcc/config/nvptx/crt0.c shows the target supports > > __attribute__((shared)), so perhaps either following instead, or, if > > .shared isn't preinitialized to zero, defining the variable in > > libgcc/config/nvptx/crt0.c , adding there __gomp_team_num = 0; > > and adding extern keyword before int __gomp_team_num __attribute__((shared)); > > in libgomp/config/nvptx/target.c. > > And finally here is a third version, which fixes a typo in the previous > patch (in instead of int) and actually initializes the shared var because > PTX documentation doesn't say anything about how the shared vars are > initialized. > > Tested on x86_64-linux with nvptx-none offloading, ok for trunk? I suspect there may be a misunderstanding here, or maybe your explanation is incomplete. I don't think the intention of the standard was to force such complexity. You can launch as many blocks on the GPU as you like, limited only by the bitwidth of the indexing register used in hardware, NVIDIA guarantees at least INT_MAX blocks (in fact almost 1<<63 blocks if you launch a three-dimensional grid with INT_MAX x 65535 x 65535 blocks). The hardware will schedule blocks automatically (so for example if the hardware can run 40 blocks simultaneously and you launch 100, the hardware may launch blocks 0 to 39, then when one of those finishes it will launch the 40'th block and so on). So isn't the solution simply to adjust the logic around nvptx_adjust_launch_bounds in GOMP_OFFLOAD_run, that is, if there's a lower bound specified, use it instead of what adjust_launch_bounds is computing as max_blocks? Yours, Alexander