public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Steve Baird <baird@adacore.com>
Subject: [COMMITTED] ada: Generate host-side CUDA_Register_Function calls for device's adainit/adafinal
Date: Fri,  4 Nov 2022 14:53:38 +0100	[thread overview]
Message-ID: <20221104135338.85230-1-poulhies@adacore.com> (raw)

From: Steve Baird <baird@adacore.com>

To invoke a device-side subprogram from the host (via a CUDA_execute pragma),
the subprogram also has to be registered by calling CUDA_Register_Function.
The host-side adainit and adafinal procedures need to invoke the corresponding
device-side procedures, so corresponding CUDA_Register_Function calls need
to be generated.

gcc/ada/

	* bindgen.adb
	(Gen_CUDA_Init): Move existing loop body into a new local
	procedure, Gen_CUDA_Register_Function_Call, and replace that loop
	body with a call to this procedure. This first part is just
	semantics-preserving refactoring. The second part is to add
	Gen_CUDA_Register_Function_Call calls after the loop for the
	device-side adainit and adafinal procedures.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/bindgen.adb | 66 +++++++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 17 deletions(-)

diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb
index f2aaa2dea92..1daa03dd7b8 100644
--- a/gcc/ada/bindgen.adb
+++ b/gcc/ada/bindgen.adb
@@ -1374,6 +1374,41 @@ package body Bindgen is
    -------------------
 
    procedure Gen_CUDA_Init is
+      --  Generate call to register one function
+      procedure Gen_CUDA_Register_Function_Call
+        (Kernel_Name   : String;
+         Kernel_String : String;
+         Kernel_Proc   : String);
+
+      -------------------------------------
+      -- Gen_CUDA_Register_Function_Call --
+      -------------------------------------
+
+      procedure Gen_CUDA_Register_Function_Call
+        (Kernel_Name   : String;
+         Kernel_String : String;
+         Kernel_Proc   : String) is
+      begin
+         WBI ("      " & Kernel_String & " :=");
+         WBI ("        Interfaces.C.Strings.New_Char_Array ("""
+               & Kernel_Name
+               & """);");
+
+         --  Generate call to CUDA runtime to register function.
+         WBI ("      CUDA_Register_Function (");
+         WBI ("        Fat_Binary_Handle, ");
+         WBI ("        " & Kernel_Proc & "'Address,");
+         WBI ("        " & Kernel_String & ",");
+         WBI ("        " & Kernel_String & ",");
+         WBI ("        -1,");
+         WBI ("        System.Null_Address,");
+         WBI ("        System.Null_Address,");
+         WBI ("        System.Null_Address,");
+         WBI ("        System.Null_Address,");
+         WBI ("        System.Null_Address);");
+         WBI ("");
+      end Gen_CUDA_Register_Function_Call;
+
    begin
       if not Enable_CUDA_Expansion then
          return;
@@ -1404,26 +1439,23 @@ package body Bindgen is
                Get_Name_String (CUDA_Kernels.Table (K).Kernel_Name);
             --  Kernel_Name is the name of the kernel, after package expansion.
          begin
-            WBI ("      " & Kernel_String & " :=");
-            WBI ("        Interfaces.C.Strings.New_Char_Array ("""
-                  & Kernel_Name
-                  & """);");
-            --  Generate call to CUDA runtime to register function.
-            WBI ("      CUDA_Register_Function (");
-            WBI ("        Fat_Binary_Handle, ");
-            WBI ("        " & Kernel_Proc & "'Address,");
-            WBI ("        " & Kernel_String & ",");
-            WBI ("        " & Kernel_String & ",");
-            WBI ("        -1,");
-            WBI ("        System.Null_Address,");
-            WBI ("        System.Null_Address,");
-            WBI ("        System.Null_Address,");
-            WBI ("        System.Null_Address,");
-            WBI ("        System.Null_Address);");
-            WBI ("");
+            Gen_CUDA_Register_Function_Call
+              (Kernel_Name   => Kernel_Name,
+               Kernel_String => Kernel_String,
+               Kernel_Proc   => Kernel_Proc);
          end;
       end loop;
 
+      --  Register device-side Adainit and Adafinal
+      Gen_CUDA_Register_Function_Call
+        (Kernel_Name   => Device_Ada_Init_Link_Name,
+         Kernel_String => "Adainit_Name_String",
+         Kernel_Proc   => Device_Ada_Init_Subp_Name);
+      Gen_CUDA_Register_Function_Call
+        (Kernel_Name   => Device_Ada_Final_Link_Name,
+         Kernel_String => "Adafinal_Name_String",
+         Kernel_Proc   => Device_Ada_Final_Subp_Name);
+
       WBI ("      CUDA_Register_Fat_Binary_End (Fat_Binary_Handle);");
 
       --  perform device (as opposed to host) elaboration
-- 
2.34.1


                 reply	other threads:[~2022-11-04 13:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221104135338.85230-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=baird@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).