]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Move Build_And_Insert_Cuda_Initialization to Expand_CUDA_Package
authorGhjuvan Lacambre <lacambre@adacore.com>
Wed, 16 Jun 2021 13:17:13 +0000 (15:17 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 20 Sep 2021 12:31:28 +0000 (12:31 +0000)
gcc/ada/

* exp_ch7.adb (Expand_N_Package_Body): Replace
Build_And_Insert_Cuda_Initialization with Expand_CUDA_Package.
* gnat_cuda.adb (Expand_CUDA_Package): New procedure.
(Build_And_Insert_Cuda_Initialization): Make internal.
* gnat_cuda.ads (Expand_CUDA_Package): New procedure.
(Build_And_Insert_Cuda_Initialization): Remove from spec.

gcc/ada/exp_ch7.adb
gcc/ada/gnat_cuda.adb
gcc/ada/gnat_cuda.ads

index f7807acd298610f34fdb7d8c30af86acb2e20972..3cc9b3c4127eb627c890b1f33f4763a4d3df6c73 100644 (file)
@@ -5918,12 +5918,7 @@ package body Exp_Ch7 is
             Build_Static_Dispatch_Tables (N);
          end if;
 
-         --  If procedures marked with CUDA_Global have been defined within N,
-         --  we need to register them with the CUDA runtime at program startup.
-         --  This requires multiple declarations and function calls which need
-         --  to be appended to N's declarations.
-
-         Build_And_Insert_CUDA_Initialization (N);
+         Expand_CUDA_Package (N);
 
          Build_Task_Activation_Call (N);
 
index b7ce953e7855e1c05507a3af5cfada74f0241a32..6273a5dd5c61b90c82c7986b7051647e74fb7844 100644 (file)
@@ -66,6 +66,25 @@ package body GNAT_CUDA is
    --  least one procedure marked with aspect CUDA_Global. The values are
    --  Elists of the marked procedures.
 
+   procedure Build_And_Insert_CUDA_Initialization (N : Node_Id);
+   --  Builds declarations necessary for CUDA initialization and inserts them
+   --  in N, the package body that contains CUDA_Global nodes. These
+   --  declarations are:
+   --
+   --    * A symbol to hold the pointer P to the CUDA fat binary.
+   --
+   --    * A type definition T for a wrapper that contains the pointer to the
+   --      CUDA fat binary.
+   --
+   --    * An object of the aforementioned type to hold the aforementioned
+   --      pointer.
+   --
+   --    * For each CUDA_Global procedure in the package, a declaration of a C
+   --      string containing the function's name.
+   --
+   --    * A procedure that takes care of calling CUDA functions that register
+   --      CUDA_Global procedures with the runtime.
+
    function Get_CUDA_Kernels (Pack_Id : Entity_Id) return Elist_Id;
    --  Returns an Elist of all procedures marked with pragma CUDA_Global that
    --  are declared within package body Pack_Body. Returns No_Elist if Pack_Id
@@ -94,6 +113,23 @@ package body GNAT_CUDA is
       Append_Elmt (Kernel, Kernels);
    end Add_CUDA_Kernel;
 
+   procedure Expand_CUDA_Package (N : Node_Id) is
+   begin
+
+      --  If not compiling for the host, do not do anything.
+
+      if not Debug_Flag_Underscore_C then
+         return;
+      end if;
+
+      --  If procedures marked with CUDA_Global have been defined within N,
+      --  we need to register them with the CUDA runtime at program startup.
+      --  This requires multiple declarations and function calls which need
+      --  to be appended to N's declarations.
+
+      Build_And_Insert_CUDA_Initialization (N);
+   end Expand_CUDA_Package;
+
    ----------
    -- Hash --
    ----------
@@ -524,7 +560,7 @@ package body GNAT_CUDA is
    --  Start of processing for Build_And_Insert_CUDA_Initialization
 
    begin
-      if CUDA_Node_List = No_Elist or not Debug_Flag_Underscore_C then
+      if CUDA_Node_List = No_Elist then
          return;
       end if;
 
index 200aeeb3b4e8b157be4d24daeedcfd2ac4dd692c..d35bc8aca253726c9b7c023e93be2b4522e2cedd 100644 (file)
@@ -82,26 +82,8 @@ package GNAT_CUDA is
    --  Kernel is a procedure entity marked with CUDA_Global, Pack_Id is the
    --  entity of its parent package body.
 
-   procedure Build_And_Insert_CUDA_Initialization (N : Node_Id);
-   --  Builds declarations necessary for CUDA initialization and inserts them
-   --  in N, the package body that contains CUDA_Global nodes. These
-   --  declarations are:
-   --
-   --    * A symbol to hold the pointer to the CUDA fat binary
-   --
-   --    * A type definition for a wrapper that contains the pointer to the
-   --      CUDA fat binary
-   --
-   --    * An object of the aforementioned type to hold the aforementioned
-   --      pointer.
-   --
-   --    * For each CUDA_Global procedure in the package, a declaration of a C
-   --      string containing the function's name.
-   --
-   --    * A function that takes care of calling CUDA functions that register
-   --      CUDA_Global procedures with the runtime.
-   --
-   --    * A boolean that holds the result of the call to the aforementioned
-   --      function.
+   procedure Expand_CUDA_Package (N : Node_Id);
+   --  When compiling for the host, generate code to register kernels with the
+   --  CUDA runtime and post-process kernels.
 
 end GNAT_CUDA;