From patchwork Fri Jun 30 15:49:22 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: 782905 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 3wzgvZ3mSmz9sRS for ; Sat, 1 Jul 2017 01:49:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="p7R8Orrd"; 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=P5ckyAwsEuPTG1Pd+ ZtwLy1P4YmMlZIQ96MWdZDSaHk4RPhARfmqopLSH/T1WWRyA9ttQe8yyYWuIm749 GA0iYCNCnQLKFERdHvVZZNKI7s3ovtF+6n6r2Cs7fXobZTvhKQ0phzQeb0xo/+Wk oUxTBoeFuSSOv0F+Yut0gZS5B0= 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=QXcEfxc9NAkFLi2lJZhGu3+ xCAs=; b=p7R8OrrdCW929ja1k3hYtpbZQMartwJDkq1v7jHKxFly0H4+CLVxHHD vyqkcm32LoJkJyKmJ7TKYbn+EScxnzYEHTuPHNO2dvJIYHE8nvRQlQjPsefJF1UF UjNmjc1OfwiJHTWSczwH+SxNnOzpKkqzQL/MuZKDs0zReaEqE2YE= Received: (qmail 19443 invoked by alias); 30 Jun 2017 15:49:38 -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 19427 invoked by uid 89); 30 Jun 2017 15:49:37 -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=7.5, ptx 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 15:49:35 +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 1dQyAm-0002aW-2x from Tom_deVries@mentor.com ; Fri, 30 Jun 2017 08:49:32 -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 16:49:27 +0100 Subject: Re: [PATCH, 4/4] Handle GOMP_OPENACC_NVPTX_JIT=-ori in libgomp nvptx plugin From: Tom de Vries To: Jakub Jelinek CC: GCC Patches , Thomas Schwinge References: <2413b0f6-9cb2-243f-d805-08323a9c9a0a@mentor.com> <6be00643-da2e-99fa-2887-dd578baa8858@mentor.com> Message-ID: Date: Fri, 30 Jun 2017 17:49:22 +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: <6be00643-da2e-99fa-2887-dd578baa8858@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) On 06/26/2017 01:44 PM, Tom de Vries wrote: > 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 >> >> The patch series adds these environment variables: >> - GOMP_OPENACC_NVPTX_SAVE_TEMPS: a means to save the resulting module >> such that it can be investigated using nvdisasm and cuobjdump. >> - GOMP_OPENACC_NVPTX_DISASM: a means to see the resulting module in >> the debug output, by writing it into a file and calling nvdisasm on >> it >> - GOMP_OPENACC_NVPTX_JIT: a means to set parameters of the >> compilation/linking process, currently supporting: >> * -O[0-4], mapping onto CU_JIT_OPTIMIZATION_LEVEL >> * -ori, mapping onto CU_JIT_NEW_SM3X_OPT >> >> >> The patch series consists of these patches: >> >> 4. Handle GOMP_OPENACC_NVPTX_JIT=-ori in libgomp nvptx plugin > > This patch adds handling of GOMP_OPENACC_NVPTX_JIT=-ori. > > Thanks, > - Tom > > 0004-Handle-GOMP_OPENACC_NVPTX_JIT-ori-in-libgomp-nvptx-plugin.patch > > - CU_JIT_LOG_VERBOSE = 12 > + CU_JIT_LOG_VERBOSE = 12, > + CU_JIT_NEW_SM3X_OPT = 15 > } CUjit_option; Adding the constant to plugin/cuda/cuda.h makes sure the constant is available when not linking the plugin against cuda. But when linking against cuda 7.5 and earlier, this still fails because the constant is not available yet in cuda.h. Fixed by hardcoding the constant if not available in the cuda version. Thanks, - Tom Handle GOMP_OPENACC_NVPTX_JIT=-ori in libgomp nvptx plugin 2017-06-26 Tom de Vries * plugin/cuda/cuda.h (enum CUjit_option): Add CU_JIT_NEW_SM3X_OPT. * plugin/plugin-nvptx.c (process_GOMP_OPENACC_NVPTX_JIT): Add gomp_openacc_nvptx_ori parameter. Handle -ori. (link_ptx): Add CU_JIT_NEW_SM3X_OPT to opts. --- libgomp/plugin/cuda/cuda.h | 3 ++- libgomp/plugin/plugin-nvptx.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/libgomp/plugin/cuda/cuda.h b/libgomp/plugin/cuda/cuda.h index 75dfe3d..4644870 100644 --- a/libgomp/plugin/cuda/cuda.h +++ b/libgomp/plugin/cuda/cuda.h @@ -89,7 +89,8 @@ typedef enum { CU_JIT_ERROR_LOG_BUFFER = 5, CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES = 6, CU_JIT_OPTIMIZATION_LEVEL = 7, - CU_JIT_LOG_VERBOSE = 12 + CU_JIT_LOG_VERBOSE = 12, + CU_JIT_NEW_SM3X_OPT = 15 } CUjit_option; typedef enum { diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index 594ca39..41ecfec 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -143,6 +143,10 @@ init_cuda_lib (void) #include "secure_getenv.h" +#if CUDA_VERSION < 8000 +#define CU_JIT_NEW_SM3X_OPT 15 +#endif + /* Convenience macros for the frequently used CUDA library call and error handling sequence as well as CUDA library calls that do the error checking themselves or don't do it at all. */ @@ -980,13 +984,15 @@ debug_linkout (void *linkout, size_t linkoutsize) } static void -process_GOMP_OPENACC_NVPTX_JIT (intptr_t *gomp_openacc_nvptx_o) +process_GOMP_OPENACC_NVPTX_JIT (intptr_t *gomp_openacc_nvptx_o, + intptr_t *gomp_openacc_nvptx_ori) { const char *var_name = "GOMP_OPENACC_NVPTX_JIT"; const char *env_var = getenv (var_name); notify_var (var_name, env_var); *gomp_openacc_nvptx_o = 4; + *gomp_openacc_nvptx_ori = 0; if (env_var == NULL) return; @@ -1005,6 +1011,14 @@ process_GOMP_OPENACC_NVPTX_JIT (intptr_t *gomp_openacc_nvptx_o) continue; } + if (c[0] == '-' && c[1] == 'o' && c[2] == 'r' && c[3] == 'i' + && (c[4] == '\0' || c[4] == ' ')) + { + *gomp_openacc_nvptx_ori = 1; + c += 4; + continue; + } + GOMP_PLUGIN_error ("Error parsing %s", var_name); break; } @@ -1014,8 +1028,8 @@ static bool link_ptx (CUmodule *module, const struct targ_ptx_obj *ptx_objs, unsigned num_objs) { - CUjit_option opts[7]; - void *optvals[7]; + CUjit_option opts[8]; + void *optvals[8]; float elapsed = 0.0; char elog[1024]; char ilog[16384]; @@ -1043,13 +1057,23 @@ link_ptx (CUmodule *module, const struct targ_ptx_obj *ptx_objs, optvals[5] = (void *) 1; static intptr_t gomp_openacc_nvptx_o = -1; + static intptr_t gomp_openacc_nvptx_ori = -1; if (gomp_openacc_nvptx_o == -1) - process_GOMP_OPENACC_NVPTX_JIT (&gomp_openacc_nvptx_o); + process_GOMP_OPENACC_NVPTX_JIT (&gomp_openacc_nvptx_o, + &gomp_openacc_nvptx_ori); opts[6] = CU_JIT_OPTIMIZATION_LEVEL; optvals[6] = (void *) gomp_openacc_nvptx_o; - CUDA_CALL (cuLinkCreate, 7, opts, optvals, &linkstate); + int nopts = 7; + if (gomp_openacc_nvptx_ori) + { + opts[nopts] = CU_JIT_NEW_SM3X_OPT; + optvals[nopts] = (void *) gomp_openacc_nvptx_ori; + nopts++; + } + + CUDA_CALL (cuLinkCreate, nopts, opts, optvals, &linkstate); for (; num_objs--; ptx_objs++) {