From patchwork Fri Dec 16 16:19:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 34001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1060176wrn; Fri, 16 Dec 2022 08:19:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7dFPtJ2QBf7jNDvJ09C3lY3kLmDBR4xlzuBZQTxpiWisl0zJ0Jd0sfbSi9k7XpFWwi5BUp X-Received: by 2002:a05:6402:370a:b0:461:2505:832d with SMTP id ek10-20020a056402370a00b004612505832dmr39598714edb.10.1671207584898; Fri, 16 Dec 2022 08:19:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671207584; cv=none; d=google.com; s=arc-20160816; b=EVCQ6TnbfUv0LKeikw/GBZlLm5SvWHHpb97yePFIVH5fFiVv5EY9YquvopiKFsFTvL 1flyfylIdZKwH1U1CKtj/PsTtIAMKqpF7lDrYT0SCfkvCAdvMagCy2OBwzxPRKqHXAQR Ful+NVuZ8aynMwyxRJEBKD6QQUgZT6//k0CRUxgt0rDf1RXMIHBp76aiV6MvXRXyA+fe zCmrJv/QX6oJd+D8ZydfJC4gudGlAyIMjyAkKwMfjfl0wa0VkDwWGL75glcFHZzR6vVK mx4zOWT6yyIXLCpUclLhpYE06heJc5POpYiy2Zle3rrPPKyDwYG4+Fmqp37Y1iRJ1taN rubg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:to :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=ASmT/new9K3gU6+mZiILX7B57/JI1j6uZdkUxMXXD1s=; b=L0MHoYVmgoUvhRhd3x/+E+10uhg/UFvf1bf0Kd0Yd3evd4oGkozZbdp2Wcvdn+P37/ SqOKHfc8ppCaevlj2fQw1nW7jEWMXXmaROvclNqKiWUIpyBYUL+h+++XPR6CZ7R7GEV2 Ur66MrN8lLOceOSHIkiOQoQNVJS+ekRCmbHvB40lYS2ENBQw3Z67VT+HM9BaoKMHyFfv KKH7NxvkjwhxcvNAfukaq0J/tVaYz66BTNAr1Uua3+GJjqPoy1SClZarDkjYDnHqo0f9 M6m3hh65EWReOb+2OneLGAg4pYg5V13+FdNc/GztWC+l2bu89E2gElXMJqxhxrzr3Tl0 E8kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fj27-20020a0564022b9b00b0046ffcd4df07si2510158edb.569.2022.12.16.08.19.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 08:19:44 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2456A3836799 for ; Fri, 16 Dec 2022 16:19:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 921D9384F964 for ; Fri, 16 Dec 2022 16:19:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 921D9384F964 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.96,249,1665475200"; d="diff'?scan'208";a="90522464" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 16 Dec 2022 08:19:06 -0800 IronPort-SDR: lhm0jz1mDJ5bXLvz8qmY7uGJpOexYI66sEQTkExUOc837aWRtxBiLXAPuyw9M5b9xOcRV8lPEW 6e8nFdL4e26G3XMW5GXDtwLeisaYGzrQt0AZwRGlkQF+RcmljBtjyD4V9Wx7Z8V4ZQGN45lHvh cAs0AoXQmXIN1od28iZ/qGXml6G3Q09tU5RcHtFE6pujkDAm8BkcNJALN6skEgmoMQQdMmMWW3 Uaq/Q+bCTlzOQXVGdlQAXNK/2BI7JwBf5wT8pst5aPl/E4qKIOmz0GufzrR5kyd1vmGpbGiQJ2 hzM= Message-ID: Date: Fri, 16 Dec 2022 17:19:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Content-Language: en-US To: gcc-patches , Thomas Schwinge , Tom de Vries , Jakub Jelinek From: Tobias Burnus Subject: [Patch] nvptx/mkoffload.cc: Add dummy proc for OpenMP rev-offload table [PR108098] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752388164745940915?= X-GMAIL-MSGID: =?utf-8?q?1752388164745940915?= Seems to be a CUDA JIT issue - which is fixed by adding a dummy procedure. Lightly tested with 4 systems at hand, where 2 failed before. One had 10.2 and the other had some ancient CUDA where 'nvptx-smi' did not print a CUDA version and requires -mptx=3.1. (I did check that offloading indeed happened and no hostfallback was done.) OK for mainline? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 nvptx/mkoffload.cc: Add dummy proc for OpenMP rev-offload table [PR108098] Seemingly, the ptx JIT of CUDA <= 10.2 replaces function pointers in global variables by NULL if a translation does not contain any executable code. It works with CUDA 11.1. The code of this commit is about reverse offload; having NULL values disables the side of reverse offload during image load. Solution is the same as found by Thomas for a related issue: Adding a dummy procedure. Cf. the PR of this issue and Thomas' patch "nvptx: Support global constructors/destructors via 'collect2'" https://gcc.gnu.org/pipermail/gcc-patches/2022-December/607749.html As that approach also works here: Co-authored-by: Thomas Schwinge gcc/ PR libgomp/108098 * config/nvptx/mkoffload.cc (process): Emit dummy procedure alongside reverse-offload function table to prevent NULL values of the function addresses. --- gcc/config/nvptx/mkoffload.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc index 5d89ba8..8306aa0 100644 --- a/gcc/config/nvptx/mkoffload.cc +++ b/gcc/config/nvptx/mkoffload.cc @@ -357,6 +357,20 @@ process (FILE *in, FILE *out, uint32_t omp_requires) fputc (sm_ver2[i], out); fprintf (out, "\"\n\t\".file 1 \\\"\\\"\"\n"); + /* WORKAROUND - see PR 108098 + It seems as if older CUDA JIT compiler optimizes the function pointers + in offload_func_table to NULL, which can be prevented by adding a + dummy procedure. With CUDA 11.1, it seems to work fine without + workaround while CUDA 10.2 as some ancient version have need the + workaround. Assuming CUDA 11.0 fixes it, emitting it could be + restricted to 'if (sm_ver2[0] < 8 && version2[0] < 7)' as sm_80 and + PTX ISA 7.0 are new in CUDA 11.0; for 11.1 it would be sm_86 and + PTX ISA 7.1. */ + fprintf (out, "\n\t\".func __dummy$func ( );\"\n"); + fprintf (out, "\t\".func __dummy$func ( )\"\n"); + fprintf (out, "\t\"{\"\n"); + fprintf (out, "\t\"}\"\n"); + size_t fidx = 0; for (id = func_ids; id; id = id->next) {