NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
473 stars 172 forks source link

[RFC] Reimplement the nvq++ driver #505

Open schweitzpgi opened 1 year ago

schweitzpgi commented 1 year ago

Currently the nvq++ driver is a skeletal bash shell script that runs the various components that comprise the logical, piecewise steps of a nvq++ compilation. The bash script is very easy to update and experiment with, since a shell language is convenient for running subprocesses, assembling strings into command line option lists, etc.

There are alternatives:

1tnguyen commented 11 months ago

Thanks for all the details, @schweitzpgi :-)

Some comments w.r.t. the first bullet point.

It's fairly easy: we just need to construct a clang::driver::Command and ask the clang::driver::Compilation instance to execute it.

Fiddling around the nvcc compiler, there is a feasible workflow to compile a single source file containing both __global__ and __qpu__ kernels, as follows:

(1) Perform CUDA compilation phase (--cuda option)

nvcc -ccbin <host compiler, e.g., clang>  -std=c++20 -I/repos/cuda-quantum/runtime -I /repos/cuda-quantum/tpls/fmt/include --cuda <source file>

We add CUDA Quantum compile options (C++20, include dirs, etc., as usual)

The result of this step is a .cpp.ii file which has all the CUDA kernels (__global__) resolved + fatbin embedded (intended for further processing by a host compiler).

(2) Perform usual nvq++ compilation of this file (e.g., with the bridge)

(3) Add necessary link options (e.g., -lcudadevrt, -lcudart_static, etc.) for CUDA along our CUDA Quantum link flags.