From patchwork Wed Aug 8 14:36:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 955087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483403-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NAMtiNuV"; dkim-atps=neutral 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 41lv8v0zxWz9ryt for ; Thu, 9 Aug 2018 00:36:46 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=DWNMh5Nr2XaroecSh RTqFfh/9wJJiITzL5qKirr0EI390LLjyp41GpaE75zbG89n134aHBgld5M7yiboz 8lKDSde7s3qZqpLx73dZTPshuKvMHjGZwrYR05qnJ9YX0u9L1e6P94XRAD9IwbQG HsfIOHME4tmxC8sItL4piFw/Yc= 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=SCe/UYYfkiQIMKm5mkNwXC+ H3YA=; b=NAMtiNuVIXEJMejBFyBFvm+9TMruuJIdcfDFfsqV9mfLaXabx8nasGD AwardCK27sMydmnnvjzUUTvn/pouMJMy9YaJJyI9Cz9THkHCPTe3+x4YLcxD8yI6 gAmj/pRR5kH0AR80YJ+1k2sLQba0FZvQ0lqeJhsTo5jZHhjzu0z4= Received: (qmail 53148 invoked by alias); 8 Aug 2018 14:36:40 -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 52666 invoked by uid 89); 8 Aug 2018 14:36:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.2 spammy=falling, Fall X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Aug 2018 14:36:37 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A69D7AE9D; Wed, 8 Aug 2018 14:36:35 +0000 (UTC) Date: Wed, 8 Aug 2018 16:36:35 +0200 From: Tom de Vries To: Cesar Philippidis Cc: "gcc-patches@gcc.gnu.org" , Thomas Schwinge , Jakub Jelinek Subject: [committed][libgomp, nvptx] Fall back to cuLinkAddData/cuLinkCreate if _v2 not found Message-ID: <20180808143635.GA22569@delia> References: <791625c9-911f-972d-ed4e-746dc5fe5f43@codesourcery.com> <539fa7c9-dbac-e6eb-f938-b8d036803f4b@codesourcery.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <539fa7c9-dbac-e6eb-f938-b8d036803f4b@codesourcery.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes On Tue, Aug 07, 2018 at 06:52:59AM -0700, Cesar Philippidis wrote: > I spotted an error > with the patch; I realized that the cuda.h that ships with libgomp > emulates version CUDA 8.0. That lead to problems using cuLinkAddData, > because that function gets remapped to cuLinkAddData_v2 in CUDA 6.5 and > newer. > Right. [ I found that problem is mentioned here already: ( https://gcc.gnu.org/ml/gcc-patches/2017-01/msg01670.html ). ] This patch should fix it. Committed. Thanks, - Tom [libgomp, nvptx] Fall back to cuLinkAddData/cuLinkCreate if _v2 not found Cuda driver api functions cuLinkAddData and cuLinkCreate are available starting version 5.5. In version 6.5, they are remapped onto _v2 versions. The dlopen interface of the libgomp nvptx plugin uses the _v2 versions, so it won't work with a cuda driver with driver api version lower than 6.5. This patch fixes the problem by testing for the presence of the _v2 versions, and falling back to the original versions in case of absence of the _v2 versions. Build on x86_64 with nvptx accelerator and reg-tested libgomp, both with and without --without-cuda-driver. 2018-08-08 Tom de Vries * plugin/cuda-lib.def (cuLinkAddData_v2, cuLinkCreate_v2): Declare using CUDA_ONE_CALL_MAYBE_NULL. * plugin/plugin-nvptx.c (cuLinkAddData, cuLinkCreate): Undef and declare. (cuLinkAddData_v2, cuLinkCreate_v2): Declare. (link_ptx): Fall back to cuLinkAddData/cuLinkCreate if the _v2 versions are not found. --- libgomp/plugin/cuda-lib.def | 2 ++ libgomp/plugin/plugin-nvptx.c | 28 ++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libgomp/plugin/cuda-lib.def b/libgomp/plugin/cuda-lib.def index 6365cdbfcbe4..29028b504a05 100644 --- a/libgomp/plugin/cuda-lib.def +++ b/libgomp/plugin/cuda-lib.def @@ -19,8 +19,10 @@ CUDA_ONE_CALL_MAYBE_NULL (cuGetErrorString) CUDA_ONE_CALL (cuInit) CUDA_ONE_CALL (cuLaunchKernel) CUDA_ONE_CALL (cuLinkAddData) +CUDA_ONE_CALL_MAYBE_NULL (cuLinkAddData_v2) CUDA_ONE_CALL (cuLinkComplete) CUDA_ONE_CALL (cuLinkCreate) +CUDA_ONE_CALL_MAYBE_NULL (cuLinkCreate_v2) CUDA_ONE_CALL (cuLinkDestroy) CUDA_ONE_CALL (cuMemAlloc) CUDA_ONE_CALL (cuMemAllocHost) diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index b549b7740039..6799a264976d 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -54,6 +54,18 @@ extern CUresult cuGetErrorString (CUresult, const char **); #define CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR 82 #endif +#if CUDA_VERSION >= 6050 +#undef cuLinkCreate +#undef cuLinkAddData +CUresult cuLinkAddData (CUlinkState, CUjitInputType, void *, size_t, + const char *, unsigned, CUjit_option *, void **); +CUresult cuLinkCreate (unsigned, CUjit_option *, void **, CUlinkState *); +#else +CUresult cuLinkAddData_v2 (CUlinkState, CUjitInputType, void *, size_t, + const char *, unsigned, CUjit_option *, void **); +CUresult cuLinkCreate_v2 (unsigned, CUjit_option *, void **, CUlinkState *); +#endif + #define DO_PRAGMA(x) _Pragma (#x) #if PLUGIN_NVPTX_DYNAMIC @@ -938,16 +950,24 @@ link_ptx (CUmodule *module, const struct targ_ptx_obj *ptx_objs, nopts++; } - CUDA_CALL (cuLinkCreate, nopts, opts, optvals, &linkstate); + if (CUDA_CALL_EXISTS (cuLinkCreate_v2)) + CUDA_CALL (cuLinkCreate_v2, nopts, opts, optvals, &linkstate); + else + CUDA_CALL (cuLinkCreate, nopts, opts, optvals, &linkstate); for (; num_objs--; ptx_objs++) { /* cuLinkAddData's 'data' argument erroneously omits the const qualifier. */ GOMP_PLUGIN_debug (0, "Loading:\n---\n%s\n---\n", ptx_objs->code); - r = CUDA_CALL_NOCHECK (cuLinkAddData, linkstate, CU_JIT_INPUT_PTX, - (char *) ptx_objs->code, ptx_objs->size, - 0, 0, 0, 0); + if (CUDA_CALL_EXISTS (cuLinkAddData_v2)) + r = CUDA_CALL_NOCHECK (cuLinkAddData_v2, linkstate, CU_JIT_INPUT_PTX, + (char *) ptx_objs->code, ptx_objs->size, + 0, 0, 0, 0); + else + r = CUDA_CALL_NOCHECK (cuLinkAddData, linkstate, CU_JIT_INPUT_PTX, + (char *) ptx_objs->code, ptx_objs->size, + 0, 0, 0, 0); if (r != CUDA_SUCCESS) { GOMP_PLUGIN_error ("Link error log %s\n", &elog[0]);