[Ada] CUDA: use binder to generate kernel-registration code
commita2cff9e9af15b179ff7a2c7e147e88ec8ce52936
authorGhjuvan Lacambre <lacambre@adacore.com>
Tue, 14 Sep 2021 08:49:08 +0000 (14 10:49 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 13 May 2022 08:04:43 +0000 (13 08:04 +0000)
tree875ff769e9ec405dc2eaca642428b1b63b5009d8
parente3584606f5cb9bfc717a19e96731bc35ea11a40e
[Ada] CUDA: use binder to generate kernel-registration code

Compiling CUDA code requires compiling code for the host (= CPU) and for
the device (= GPU). Device code is embedded into the host code and must
be registered with the CUDA runtime by the host.

The original approach we took for registering CUDA kernels was to
generate the registration-code on a unit basis, i.e. each unit took care
of registering its own kernels. Unfortunately, this makes linking
kernels and device functions that belong to different units much harder.

We thus rework this approach in order to have GNAT generate kernel names
in ALI files. The binder reads the ALI files and generates kernel
registration code for each of the kernels found in ALI files.

gcc/ada/

* ali.adb: Introduce new 'K' line in ALI files, used to
represent CUDA kernel entries.
* ali.ads: Create new CUDA_Kernels table, which contains entries
of type CUDA_Kernel_Record. Each CUDA_Kernel_Record corresponds
to a K line in an ali file.
* bindgen.adb: Introduce new Gen_CUDA_Init procedure in the
binder, which generates CUDA kernel registration code.
* gnat_cuda.adb: Move Get_CUDA_Kernels spec to package spec to
make it available to bindgen.adb.
* gnat_cuda.ads: Likewise.
* lib-writ.adb: Introduce new Output_CUDA_Symbols procedure,
which generates one 'K' line in the ALI file per visible CUDA
kernel.
* opt.ads: Introduce Enable_CUDA_Expansion option, triggered by
using the -gnatd_c flag.
* switch-b.adb: Likewise.
* switch-c.adb: Likewise.
gcc/ada/ali.adb
gcc/ada/ali.ads
gcc/ada/bindgen.adb
gcc/ada/gnat_cuda.adb
gcc/ada/gnat_cuda.ads
gcc/ada/lib-writ.adb
gcc/ada/opt.ads
gcc/ada/switch-b.adb
gcc/ada/switch-c.adb