From patchwork Mon Nov 7 08:40:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 16310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1920897wru; Mon, 7 Nov 2022 00:47:29 -0800 (PST) X-Google-Smtp-Source: AMsMyM4gLQxbJoX86s2ZmphBkMzzW5DiFOfs55UgAjIxlkqHjiUF/Vbzpdz8W3gTSyhZO6Asqx6t X-Received: by 2002:a05:6402:42c6:b0:462:1abc:e576 with SMTP id i6-20020a05640242c600b004621abce576mr49203273edc.223.1667810849514; Mon, 07 Nov 2022 00:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667810849; cv=none; d=google.com; s=arc-20160816; b=aUObRG5JzQteuV1mEGV5oz3K6PiYSCBqQUNFyMRI2kg8LdWHXDxcfRrvex9CGS0Kh3 /WmYT8gw8AHOUeoU/1setqhtmU4OgDxf8eWm7zB2/FdF30+JuW9wC6GnOMI+zWFIBT2t izDaRlf3cYccn89agvEUr4PJUJz2CnpfgCOa6iVC7fG5dAtuOiUb2B1hPgkr6WLGe15k xNTq5qDY3ew4pjreSELUztsPVf3d4HbPGchkuQHsGzUAkJ9Bc3lipY054TdPY4E1i/d8 r8CMH7HnXOuKC05yhSSpXxYsVm9MhgFvB3M5xQjUfB47mv6OBiFL02lokdL591188My/ hbPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=UrEnLE9v1xe6JGspI99MtYRwkufRDsyeXouUc31S7Zc=; b=hQlqaXCL7PevPunJxETg6KatUEu0XBJyehNB86rP0eobDsaOpiWeJScj4bSbb4MM2g K91F4nLfdTbm+aJca7D/8UYbw5Wc2On9XgZfGbodfRXfvTnQxpzx+2fbZDTZ34BQy9YI C5So4W3POsOYjLrI80UH6CUst4/lrJrTKd+NDCiUCdoaX79RrSI1CfRcwpQVGr2XOdXX dhOxtWOA/6eKeR7X5GSNVcsbXdL3jUmNQcpdDC2R0QtskEO8ibwrSKeWz69sV51sD7x1 inZYOUf964V5OM6u2oEu/0wMTaaGZQG9ALGdQBxvYzP3F5YuWVe2AzOp1AXweKvjVtyM k8yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hkpI2ZKt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h20-20020aa7de14000000b0046314dd20a0si8812685edv.3.2022.11.07.00.47.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 00:47:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hkpI2ZKt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 433553857038 for ; Mon, 7 Nov 2022 08:43:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 433553857038 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667810615; bh=UrEnLE9v1xe6JGspI99MtYRwkufRDsyeXouUc31S7Zc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hkpI2ZKt56ooP3bhfKIiiSUSHPwmj7gpk7v/NqcKLmN8RgWS71xNY2UhkuD9JCipr OXu6XMg4/2wAq32UZKS+C7BvjhyprjgMa061YJpV70Y8w3vksJ1VoH6rGyNX/n/IWe ypzN8nWp6fn5AymMfmuEtot5l7zoyxVCQEAU2McI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id A2E12385C308 for ; Mon, 7 Nov 2022 08:41:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A2E12385C308 Received: by mail-wr1-x434.google.com with SMTP id a14so15046899wru.5 for ; Mon, 07 Nov 2022 00:41:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UrEnLE9v1xe6JGspI99MtYRwkufRDsyeXouUc31S7Zc=; b=zryTEEbZeNPKdxzG2IRbBw9eRYBIy2Yv8/fnKb3p7Himh760wkdUCeID5rgb1Z6aIA Iq3hi1+MLvL6W3ygeCaVBkPJrn+IUYSa6QI87M1NImkTr3Tko0qnSCsmwaZhfaqynfJP bEdH6eu+JXsd4JH2ei+FXZIuZOtmuHWCPm9xvMY2X3+i05q8vKIq8ATR8+g5XSDtGiNP +xZBducrfVqHmrXDkNaIx60OKVWodfikzHhH3c6o44QVSyiTL+vIOM6+rFLpP2UMcojg q/GOet0bBJ2bKuBZ8/CKO3t2PLUNKhEIucYw2SgdEkKpYlQ6EBSoI93bVw8FO+viTCrf PonQ== X-Gm-Message-State: ACrzQf2gmTD1SkXrcEdo9Hka6ea/w64fbAs3T2mOTGOADBqEpsLH+quw WqErfAGNW3zJlWUB2h5eYMD9aKXYdOVJqw== X-Received: by 2002:a5d:5081:0:b0:236:75cc:be26 with SMTP id a1-20020a5d5081000000b0023675ccbe26mr31613993wrt.379.1667810462507; Mon, 07 Nov 2022 00:41:02 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id bk28-20020a0560001d9c00b002365b759b65sm6670416wrb.86.2022.11.07.00.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 00:41:02 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED] ada: Rework CUDA host-side invocation of device-side elaboration code Date: Mon, 7 Nov 2022 09:40:59 +0100 Message-Id: <20221107084059.151565-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= 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?1748826429095556197?= X-GMAIL-MSGID: =?utf-8?q?1748826429095556197?= From: Steve Baird When the binder is invoked with a "-d_c" switch, add an argument to that switch which is the library name on the device side; so "-d_c" becomes "-d_c=some_library_name". This does not effect the case where "-d_c" is specified as a switch for compilation (as opposed to binding). Use this new piece of information in the code generated by the binder to invoke elaboration code on the device side from the host side. gcc/ada/ * opt.ads: Declare new string pointer variable, CUDA_Device_Library_Name. Modify comments for existing Boolean variable Enable_CUDA_Device_Expansion. * switch-b.adb: When "-d_c" switch is encountered, check that the next character is an "'='; use the remaining characters to initialize Opt.CUDA_Device_Library_Name. * bindgen.adb: Remove (for now) most support for host-side invocation of device-side finalization. Make use of the new CUDA_Device_Library_Name in determining the string used to refer (on the host side) to the device-side initialization procedure. Declare the placeholder routine that is named in the CUDA_Execute pragma (and the CUDA_Register_Function call) as an exported null procedure, rather than as an imported procedure. It is not clear whether it is really necessary to specify the link-name for this should-never-be-called subprogram on the host side, but for now it shouldn't hurt to do so. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/bindgen.adb | 53 +++++++++++++++++--------------------------- gcc/ada/opt.ads | 8 ++++--- gcc/ada/switch-b.adb | 9 ++++++++ 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb index 4e89918b51d..b942985b2e8 100644 --- a/gcc/ada/bindgen.adb +++ b/gcc/ada/bindgen.adb @@ -114,27 +114,25 @@ package body Bindgen is -- For CodePeer, introduce a wrapper subprogram which calls the -- user-defined main subprogram. - -- Names for local C-String variables + -- Name for local C-String variable Adainit_String_Obj_Name : constant String := "Adainit_Name_C_String"; - Adafinal_String_Obj_Name : constant String := "Adafinal_Name_C_String"; - -- Names and link_names for CUDA device adainit/adafinal procs. + -- Name and link_name for CUDA device initialization procedure - Device_Subp_Name_Prefix : constant String := "imported_device_"; + Device_Ada_Init_Subp_Name : constant String := "Device_Initialization"; Device_Link_Name_Prefix : constant String := "__device_"; - function Device_Ada_Final_Link_Name return String is - (Device_Link_Name_Prefix & Ada_Final_Name.all); + function Device_Link_Name (Suffix : String) return String is + (Device_Link_Name_Prefix & + (if CUDA_Device_Library_Name = null + then "ada" -- is this an error path? + else CUDA_Device_Library_Name.all) & Suffix); - function Device_Ada_Final_Subp_Name return String is - (Device_Subp_Name_Prefix & Ada_Final_Name.all); - - function Device_Ada_Init_Link_Name return String is - (Device_Link_Name_Prefix & Ada_Init_Name.all); - - function Device_Ada_Init_Subp_Name return String is - (Device_Subp_Name_Prefix & Ada_Init_Name.all); + function Device_Ada_Init_Link_Name return String + is (Device_Link_Name (Suffix => "init")); + function Device_Ada_Final_Link_Name return String + is (Device_Link_Name (Suffix => "final")); ---------------------------------- -- Interface_State Pragma Table -- @@ -523,12 +521,6 @@ package body Bindgen is WBI (" System.Standard_Library.Adafinal;"); end if; - -- perform device (as opposed to host) finalization - if Enable_CUDA_Expansion then - WBI (" pragma CUDA_Execute (" & - Device_Ada_Final_Subp_Name & ", 1, 1);"); - end if; - WBI (" end " & Ada_Final_Name.all & ";"); WBI (""); end Gen_Adafinal; @@ -1362,17 +1354,17 @@ package body Bindgen is end loop; WBI (" procedure " & Device_Ada_Init_Subp_Name & ";"); - WBI (" pragma Import (C, " & Device_Ada_Init_Subp_Name & + WBI (" pragma Export (C, " & Device_Ada_Init_Subp_Name & ", Link_Name => """ & Device_Ada_Init_Link_Name & """);"); - WBI (" procedure " & Device_Ada_Final_Subp_Name & ";"); - WBI (" pragma Import (C, " & Device_Ada_Final_Subp_Name & - ", Link_Name => """ & Device_Ada_Final_Link_Name & """);"); - -- C-string declarations for adainit and adafinal + -- It would be nice to declare a real body that raises P_E, but + -- generating a subprogram body at the right point is harder + -- than generating a null procedure here. + WBI (" procedure " & Device_Ada_Init_Subp_Name & " is null;"); + + -- C-string declaration for adainit WBI (" " & Adainit_String_Obj_Name & " : Interfaces.C.Strings.Chars_Ptr;"); - WBI (" " & Adafinal_String_Obj_Name - & " : Interfaces.C.Strings.Chars_Ptr;"); WBI (""); WBI (""); @@ -1455,15 +1447,11 @@ package body Bindgen is end; end loop; - -- Register device-side Adainit and Adafinal + -- Register device-side Adainit Gen_CUDA_Register_Function_Call (Kernel_Name => Device_Ada_Init_Link_Name, Kernel_String => Adainit_String_Obj_Name, Kernel_Proc => Device_Ada_Init_Subp_Name); - Gen_CUDA_Register_Function_Call - (Kernel_Name => Device_Ada_Final_Link_Name, - Kernel_String => Adafinal_String_Obj_Name, - Kernel_Proc => Device_Ada_Final_Subp_Name); WBI (" CUDA_Register_Fat_Binary_End (Fat_Binary_Handle);"); @@ -2702,7 +2690,6 @@ package body Bindgen is if not Cumulative_Restrictions.Set (No_Finalization) then WBI (""); WBI (" procedure " & Ada_Final_Name.all & ";"); - if Enable_CUDA_Device_Expansion then WBI (" pragma Export (C, " & Ada_Final_Name.all & ", Link_Name => """ & Device_Ada_Final_Link_Name & """);"); diff --git a/gcc/ada/opt.ads b/gcc/ada/opt.ads index 9eb792e281c..6f3ced295e5 100644 --- a/gcc/ada/opt.ads +++ b/gcc/ada/opt.ads @@ -395,6 +395,10 @@ package Opt is -- Set to True (-C switch) to indicate that the compiler will be invoked -- with a mapping file (-gnatem compiler switch). + CUDA_Device_Library_Name : String_Ptr := null; + -- GNATBIND + -- Non-null only if Enable_CUDA_Expansion is True. + subtype Debug_Level_Value is Nat range 0 .. 3; Debugger_Level : Debug_Level_Value := 0; -- GNAT, GNATBIND @@ -549,9 +553,7 @@ package Opt is Enable_CUDA_Device_Expansion : Boolean := False; -- GNATBIND - -- Set to True to enable CUDA device (as opposed to host) expansion: - -- - Binder generates elaboration/finalization code that can be - -- invoked from corresponding binder-generated host-side code. + -- Set to True to enable CUDA device (as opposed to host) expansion. Error_Msg_Line_Length : Nat := 0; -- GNAT diff --git a/gcc/ada/switch-b.adb b/gcc/ada/switch-b.adb index c40cb970bef..7a732ae3122 100644 --- a/gcc/ada/switch-b.adb +++ b/gcc/ada/switch-b.adb @@ -168,6 +168,15 @@ package body Switch.B is if Enable_CUDA_Expansion and Enable_CUDA_Device_Expansion then Bad_Switch (Switch_Chars); + elsif C = 'c' then + -- specify device library name + if Ptr >= Max or else Switch_Chars (Ptr + 1) /= '=' then + Bad_Switch (Switch_Chars); + else + CUDA_Device_Library_Name := + new String'(Switch_Chars (Ptr + 2 .. Max)); + Ptr := Max; + end if; end if; Underscore := False;