From patchwork Fri Jun 30 16:06:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 782911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wzhHW1Zzyz9s3s for ; Sat, 1 Jul 2017 02:07:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cnyK6fF9"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=p/8KOE3s2+zTHOHFz 44lzX89IF672rGEEEtOc08K0IKX2n3hUMOUsn5WLZiSfHIGAPekG3GmMrrd/lXlO CUw+8qTdSCrFHTwfd3m6kGBKb34Q4emfaGfYcui3ahAYlhIHMmuKJCA1uu4r9tNu vIWq+wZVjZT5JU0PVKaqlDQnH8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=V87FwcTDoiTDMgcIGwnr4ao Z40M=; b=cnyK6fF9GdvM2TAOdxnwPLHq2ozEnzEX1m5htFKqKcj6iqNWev/TMd3 rsvwcNJmlLshToaSXl5wFA3y0HxcNrWsfWwks6KelCRDjutvqanT2HxNgxAtC93r QnihSKyF2Ux7DhtCZMyZL4sOqXjg1UpeBwpj4V8fuKKeEVKCNSlE= Received: (qmail 48127 invoked by alias); 30 Jun 2017 16:06:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 47820 invoked by uid 89); 30 Jun 2017 16:06:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Jun 2017 16:06:51 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1dQyRV-0006JU-RR from Tom_deVries@mentor.com ; Fri, 30 Jun 2017 09:06:49 -0700 Received: from [127.0.0.1] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Fri, 30 Jun 2017 17:06:45 +0100 Subject: [PATCH, 6/4] Handle GOMP_OPENACC_NVPTX_JIT=-arch= in libgomp nvptx plugin From: Tom de Vries To: Jakub Jelinek CC: GCC Patches , Thomas Schwinge References: <2413b0f6-9cb2-243f-d805-08323a9c9a0a@mentor.com> Message-ID: Date: Fri, 30 Jun 2017 18:06:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <2413b0f6-9cb2-243f-d805-08323a9c9a0a@mentor.com> X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) [ was: Re: [PATCH, 0/4] Handle GOMP_OPENACC_NVPTX_{DISASM,SAVE_TEMPS,JIT} in libgomp nvptx plugin ] On 06/26/2017 01:24 PM, Tom de Vries wrote: > Hi, > > I've written a patch series to facilitate debugging libgomp openacc > testcase failures on the nvptx accelerator. > > > When running an openacc test-case on an nvptx accelerator, the following > happens: > - the plugin obtains the ptx assembly for the acceleration kernels > - it calls the cuda jit to compile and link the ptx into a module > - it loads the module > - it starts an acceleration kernel > This patch adds handling of GOMP_OPENACC_NVPTX_JIT=-arch= in libgomp nvptx plugin. F.i. GOMP_OPENACC_NVPTX_JIT=-arch=60 for sm_60. Thanks, - Tom libgomp/ChangeLog: 2017-06-30 Tom de Vries * plugin/plugin-nvptx.c (parse_number): (process_GOMP_OPENACC_NVPTX_JIT): (link_ptx): Handle GOMP_OPENACC_NVPTX_JIT=-arch= in libgomp nvptx plugin --- libgomp/plugin/plugin-nvptx.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index 365c787..4cca0c7 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -983,9 +983,24 @@ debug_linkout (void *linkout, size_t linkoutsize) } } +static bool +parse_number (const char *c, unsigned long* resp, char **end) +{ + unsigned long res; + + errno = 0; + res = strtoul (c, end, 10); + if (errno) + return false; + + *resp = res; + return true; +} + static void process_GOMP_OPENACC_NVPTX_JIT (intptr_t *gomp_openacc_nvptx_o, - intptr_t *gomp_openacc_nvptx_ori) + intptr_t *gomp_openacc_nvptx_ori, + uintptr_t *gomp_openacc_nvptx_target) { const char *var_name = "GOMP_OPENACC_NVPTX_JIT"; const char *env_var = getenv (var_name); @@ -1019,6 +1034,19 @@ process_GOMP_OPENACC_NVPTX_JIT (intptr_t *gomp_openacc_nvptx_o, continue; } + if (c[0] == '-' && c[1] == 'a' && c[2] == 'r' && c[3] == 'c' + && c[4] == 'h' && c[5] == '=') + { + const char *end; + unsigned long val; + if (parse_number (&c[6], &val, (char**)&end)) + { + *gomp_openacc_nvptx_target = val; + c = end; + continue; + } + } + GOMP_PLUGIN_error ("Error parsing %s", var_name); break; } @@ -1183,9 +1211,11 @@ link_ptx (CUmodule *module, const struct targ_ptx_obj *ptx_objs, static intptr_t gomp_openacc_nvptx_o = -1; static intptr_t gomp_openacc_nvptx_ori = -1; + static uintptr_t gomp_openacc_nvptx_target = 0; if (gomp_openacc_nvptx_o == -1) process_GOMP_OPENACC_NVPTX_JIT (&gomp_openacc_nvptx_o, - &gomp_openacc_nvptx_ori); + &gomp_openacc_nvptx_ori, + &gomp_openacc_nvptx_target); opts[6] = CU_JIT_OPTIMIZATION_LEVEL; optvals[6] = (void *) gomp_openacc_nvptx_o; @@ -1197,6 +1227,12 @@ link_ptx (CUmodule *module, const struct targ_ptx_obj *ptx_objs, optvals[nopts] = (void *) gomp_openacc_nvptx_ori; nopts++; } + if (gomp_openacc_nvptx_target) + { + opts[nopts] = CU_JIT_TARGET; + optvals[nopts] = (void *) gomp_openacc_nvptx_target; + nopts++; + } CUDA_CALL (cuLinkCreate, nopts, opts, optvals, &linkstate);