Skip to content

Commit 5771d22

Browse files
committed
Port to custatevecEx
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
1 parent 8b33ff8 commit 5771d22

62 files changed

Lines changed: 11459 additions & 1511 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ endif()
845845

846846
# cuQuantum / cuTensor component discovery
847847
if (CUDA_FOUND)
848-
find_package(cuStateVec)
848+
find_package(cuStateVec 1.14)
849849
find_package(cuTensor)
850850
find_package(cuTensorNet)
851851
find_package(cuDensityMat)

cmake/modules/CUDAQConfig.cmake

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,67 +63,53 @@ if (NOT CUDAQ_LIBRARY_MODE)
6363
endif()
6464

6565
# ---- TARGET EXPORTS ----
66-
# Prefer cusvsim libraries if they are present
67-
set (__base_nvtarget_name "custatevec")
68-
find_library(CUDAQ_CUSVSIM_PATH NAMES cusvsim-fp32 HINTS ${CUDAQ_LIBRARY_DIR})
69-
if (CUDAQ_CUSVSIM_PATH)
70-
set(__base_nvtarget_name "cusvsim")
71-
endif()
72-
7366
# Default Target
7467
add_library(cudaq::cudaq-default-target SHARED IMPORTED)
7568
set_target_properties(cudaq::cudaq-default-target PROPERTIES
76-
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-${__base_nvtarget_name}-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
77-
IMPORTED_SONAME "libnvqir-${__base_nvtarget_name}-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
69+
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-custatevec-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
70+
IMPORTED_SONAME "libnvqir-custatevec-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
7871
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-default;cudaq::cudaq-em-default")
7972

8073
# NVIDIA Target
8174
add_library(cudaq::cudaq-nvidia-target SHARED IMPORTED)
8275
set_target_properties(cudaq::cudaq-nvidia-target PROPERTIES
83-
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-${__base_nvtarget_name}-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
84-
IMPORTED_SONAME "libnvqir-${__base_nvtarget_name}-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
85-
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-default;cudaq::cudaq-em-default")
86-
87-
# NVIDIA Legacy Target
88-
add_library(cudaq::cudaq-nvidia-legacy-target SHARED IMPORTED)
89-
set_target_properties(cudaq::cudaq-nvidia-legacy-target PROPERTIES
9076
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-custatevec-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
9177
IMPORTED_SONAME "libnvqir-custatevec-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
9278
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-default;cudaq::cudaq-em-default")
9379

9480
# NVIDIA FP64 Target
9581
add_library(cudaq::cudaq-nvidia-fp64-target SHARED IMPORTED)
9682
set_target_properties(cudaq::cudaq-nvidia-fp64-target PROPERTIES
97-
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-${__base_nvtarget_name}-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
98-
IMPORTED_SONAME "libnvqir-${__base_nvtarget_name}-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
83+
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-custatevec-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
84+
IMPORTED_SONAME "libnvqir-custatevec-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
9985
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-default;cudaq::cudaq-em-default")
10086

10187
# NVIDIA MGPU Target
10288
add_library(cudaq::cudaq-nvidia-mgpu-target SHARED IMPORTED)
10389
set_target_properties(cudaq::cudaq-nvidia-mgpu-target PROPERTIES
104-
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-mgpu-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
105-
IMPORTED_SONAME "libnvqir-mgpu-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
90+
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-nvidia-mgpu-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
91+
IMPORTED_SONAME "libnvqir-nvidia-mgpu-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
10692
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-default;cudaq::cudaq-em-default")
10793

10894
# NVIDIA MGPU-FP64 Target
10995
add_library(cudaq::cudaq-nvidia-mgpu-fp64-target SHARED IMPORTED)
11096
set_target_properties(cudaq::cudaq-nvidia-mgpu-fp64-target PROPERTIES
111-
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-mgpu-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
112-
IMPORTED_SONAME "libnvqir-mgpu-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
97+
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-nvidia-mgpu${CMAKE_SHARED_LIBRARY_SUFFIX}"
98+
IMPORTED_SONAME "libnvqir-nvidia-mgpu${CMAKE_SHARED_LIBRARY_SUFFIX}"
11399
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-default;cudaq::cudaq-em-default")
114100

115101
# NVIDIA MQPU Target
116102
add_library(cudaq::cudaq-nvidia-mqpu-target SHARED IMPORTED)
117103
set_target_properties(cudaq::cudaq-nvidia-mqpu-target PROPERTIES
118-
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-${__base_nvtarget_name}${CMAKE_SHARED_LIBRARY_SUFFIX}"
119-
IMPORTED_SONAME "libnvqir-${__base_nvtarget_name}${CMAKE_SHARED_LIBRARY_SUFFIX}"
104+
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-custatevec-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
105+
IMPORTED_SONAME "libnvqir-custatevec-fp32${CMAKE_SHARED_LIBRARY_SUFFIX}"
120106
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-mqpu;cudaq::cudaq-em-default")
121107

122108
# NVIDIA MQPU FP64 Target
123109
add_library(cudaq::cudaq-nvidia-mqpu-fp64-target SHARED IMPORTED)
124110
set_target_properties(cudaq::cudaq-nvidia-mqpu-fp64-target PROPERTIES
125-
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-${__base_nvtarget_name}-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
126-
IMPORTED_SONAME "libnvqir-${__base_nvtarget_name}-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
111+
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-custatevec-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
112+
IMPORTED_SONAME "libnvqir-custatevec-fp64${CMAKE_SHARED_LIBRARY_SUFFIX}"
127113
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-mqpu;cudaq::cudaq-em-default")
128114

129115
# QPP CPU Target

docs/sphinx/using/backends/sims/svsims.rst

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ It is worth drawing attention to gate fusion, a powerful tool for improving simu
106106
- Value
107107
- Description
108108
* - ``CUDAQ_FUSION_MAX_QUBITS``
109-
- positive integer
110-
- The max number of qubits used for gate fusion. The default value depends on `GPU Compute Capability <https://developer.nvidia.com/cuda-gpus>`__ (CC) and the floating point precision selected for the simulator as specified :ref:`here <gate-fusion-table>`.
109+
- integer (maximum effective value: 10)
110+
- The max number of qubits used for gate fusion. Values greater than 10 are clamped to 10, while a non-positive value disables gate fusion. The default value depends on `GPU Compute Capability <https://developer.nvidia.com/cuda-gpus>`__ (CC) and the floating point precision selected for the simulator as specified :ref:`here <gate-fusion-table>`.
111111
* - ``CUDAQ_FUSION_DIAGONAL_GATE_MAX_QUBITS``
112-
- integer greater than or equal to -1
113-
- The max number of qubits used for diagonal gate fusion. The default value is set to `-1` and the fusion size will be automatically adjusted for the better performance. If 0, the gate fusion for diagonal gates is disabled.
112+
- integer greater than or equal to -1 (maximum effective value: 20)
113+
- The max number of qubits used for diagonal gate fusion. Values greater than 20 are clamped to 20. The default value is set to `-1` and the fusion size will be automatically adjusted for better performance. If 0, gate fusion for diagonal gates is disabled.
114114
* - ``CUDAQ_FUSION_NUM_HOST_THREADS``
115-
- positive integer
116-
- Number of CPU threads used for circuit processing. The default value is `8`.
115+
- positive integer (maximum effective value: 32)
116+
- Number of CPU threads used for circuit processing. Values greater than 32 are clamped to 32. The default value is `8`.
117117
* - ``CUDAQ_MAX_CPU_MEMORY_GB``
118118
- non-negative integer, or `NONE`
119119
- CPU memory size (in GB) allowed for state-vector migration. `NONE` means unlimited (up to physical memory constraints). Default is 0GB (disabled, variable is not set to any value).
@@ -123,6 +123,9 @@ It is worth drawing attention to gate fusion, a powerful tool for improving simu
123123
* - ``CUDAQ_ALLOW_FP32_EMULATED``
124124
- `TRUE` (`1`, `ON`) or `FALSE` (`0`, `OFF`)
125125
- [Blackwell (compute capability 10.0+) only] Enable or disable floating point math emulation. If enabled, allows `FP32` emulation kernels using `BFloat16` (`BF16`) whenever possible. Enabled by default.
126+
* - ``CUDAQ_GPU_RNG_THRESHOLD``
127+
- non-negative integer
128+
- The minimum random-number count that uses GPU generation. The default is 100,000; 0 selects GPU generation for every request.
126129
* - ``CUDAQ_ENABLE_MEMPOOL``
127130
- `TRUE` (`1`, `ON`) or `FALSE` (`0`, `OFF`)
128131
- Enable or disable `CUDA memory pool <https://developer.nvidia.com/blog/using-cuda-stream-ordered-memory-allocator-part-1/#memory_pools>`__ for state vector allocation/deallocation. Enabled by default.
@@ -134,14 +137,10 @@ It is worth drawing attention to gate fusion, a powerful tool for improving simu
134137

135138
.. note::
136139

137-
In host-device simulation, `CUDAQ_MAX_CPU_MEMORY_GB` is not 0, the backend automatically switching between inner product (default) and operator matrix-based
138-
methods for expectation calculations (`cudaq::observe`) depending on whether a clone of the state can be allocated or not.
139-
140-
For example, when `CUDAQ_MAX_GPU_MEMORY_GB` is unconstrained, the quantum state vector would consume all device memory before utilizing host memory.
141-
Thus, the backend would fall back to the operator matrix-based approach as cloning the state is not possible.
142-
For performance reason, only Pauli operator matrices of up to 8 qubits (identity padding not included) are allowed in this mode.
143-
This constrain can be relaxed by setting the `CUDAQ_MATRIX_EXP_VAL_MAX_SIZE` environment variable.
144-
Users would need to take into account the full operator matrix size when increasing this setting.
140+
The ``CUDAQ_MATRIX_EXP_VAL_MAX_SIZE`` environment variable has been removed.
141+
The ``nvidia`` state-vector backend now evaluates Pauli expectations directly
142+
on host-migrated states without a dense-matrix fallback, so migrated Pauli
143+
terms no longer require a separate width limit.
145144

146145

147146
Multi-GPU multi-node
@@ -240,17 +239,17 @@ the multi-node multi-GPU configuration. Any environment variables must be set pr
240239
- string
241240
- The shared library name for inter-process communication. The default value is `libmpi.so`.
242241
* - ``CUDAQ_MGPU_COMM_PLUGIN_TYPE``
243-
- `AUTO`, `EXTERNAL`, `OpenMPI`, or `MPICH`
244-
- Selecting :code:`cuStateVec` `CommPlugin` for inter-process communication. The default is `AUTO`. If `EXTERNAL` is selected, `CUDAQ_MGPU_LIB_MPI` should point to an implementation of :code:`cuStateVec` `CommPlugin` interface.
242+
- `AUTO`, `SELF`, `EXTERNAL`, `OpenMPI`, or `MPICH`
243+
- Select the communicator provider. The default `AUTO` uses activated CUDA-Q MPI when available and otherwise detects OpenMPI or MPICH from `CUDAQ_MGPU_LIB_MPI`. `SELF` requires and uses activated CUDA-Q MPI across all ranks. `OpenMPI`, `MPICH`, and `EXTERNAL` always use the corresponding ``cuStateVecEx`` provider and bypass CUDA-Q MPI. If `EXTERNAL` is selected, `CUDAQ_MGPU_LIB_MPI` must point to a ``cuStateVecEx`` communicator module. Custom communicators set with :code:`cudaq::mpi::set_communicator` are supported only by CUDA-Q-backed `AUTO` and `SELF`.
245244
* - ``CUDAQ_MGPU_NQUBITS_THRESH``
246245
- positive integer
247246
- The qubit count threshold where state vector distribution is activated. Below this threshold, simulation is performed as independent (non-distributed) tasks across all MPI processes for optimal performance. Default is 25.
248247
* - ``CUDAQ_MGPU_FUSE``
249-
- positive integer
250-
- The max number of qubits used for gate fusion. The default value depends on `GPU Compute Capability <https://developer.nvidia.com/cuda-gpus>`__ (CC) and the floating point precision selected for the simulator as specified :ref:`here <gate-fusion-table>`.
248+
- integer (maximum effective value: 10)
249+
- The max number of qubits used for gate fusion. Values greater than 10 are clamped to 10, while a non-positive value disables gate fusion. The default value depends on `GPU Compute Capability <https://developer.nvidia.com/cuda-gpus>`__ (CC) and the floating point precision selected for the simulator as specified :ref:`here <gate-fusion-table>`.
251250
* - ``CUDAQ_MGPU_P2P_DEVICE_BITS``
252-
- positive integer
253-
- Specify the number of GPUs that can communicate by using GPUDirect P2P. Default value is 0 (P2P communication is disabled).
251+
- non-negative integer
252+
- Specify the number of global device-index bits that use GPUDirect P2P communication. A value of 0 disables P2P communication.
254253
* - ``CUDAQ_GPU_FABRIC``
255254
- `MNNVL`, `NVL`, `NONE`, or NVLink domain size (power of 2 integer)
256255
- Automatically set the number of P2P device bits based on the total number of processes when multi-node NVLink (`MNNVL`) is selected; or the number of processes per node when NVLink (`NVL`) is selected; or disable P2P (with `NONE`); or a specific NVLink domain size.
@@ -327,4 +326,4 @@ environment variable to another integer value as shown below.
327326
.. note::
328327

329328
On multi-node systems without `MNNVL` support, the `nvidia` target in `mgpu` mode may fail to allocate memory.
330-
Users can disable `MNNVL` fabric-based memory sharing by setting the environment variable `UBACKEND_USE_FABRIC_HANDLE=0`.
329+
Users can disable GPU-fabric P2P memory sharing by setting the environment variable `CUDAQ_GPU_FABRIC=NONE`.

docs/sphinx/using/backends/simulators.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ technical details and code examples for using each circuit simulator.
3838
- multi-GPU multi-node
3939
- single (default) / double
4040
- 33+
41-
* - `nvidia-legacy`
42-
- State Vector
43-
- Legacy state vector simulator that does not support multi-GPU, gate fusion, or trajectory sampling. Can perform better at low qubit counts.
44-
- Single GPU
45-
- single (default) / double
46-
- < 33 / 32 (64 GB)
4741
* - `tensornet` *
4842
- Tensor Network
4943
- Shallow-depth (low-entanglement) and high width circuits (exact)

docs/sphinx/using/extending/nvqir_simulator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This is the type that downstream simulation developers should extend.
2929

3030
The actual definition of the quantum state data structure, and its overall evolution are
3131
left as tasks for :code:`CircuitSimulatorBase` subclasses. Examples of simulation subtypes can be found
32-
in :code:`runtime/nvqir/qpp/QppCircuitSimulator.cpp` or :code:`runtime/nvqir/custatevec/CuStateVecCircuitSimulator.cpp`.
32+
in :code:`runtime/nvqir/qpp/QppCircuitSimulator.cpp` or :code:`runtime/nvqir/custatevec/CuStateVecCircuitSimulatorEx.h`.
3333
The :code:`QppCircuitSimulator` models the state vector using the `Q++ <https://github.com/softwareqinc/qpp>`_ library, which
3434
leverages the :code:`Eigen::Matrix` type and OpenMP threading for matrix-vector operations.
3535
The :code:`CuStateVecCircuitSimulator` type models the state vector on an NVIDIA GPU device

python/tests/custom/test_custom_operations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def test_toffoli():
111111

112112
# NOTE: Ref - https://github.com/NVIDIA/cuda-quantum/issues/1925
113113
@pytest.mark.parametrize("target", [
114-
'density-matrix-cpu', 'nvidia', 'nvidia-legacy', 'nvidia-fp64',
115-
'nvidia-mqpu', 'nvidia-mqpu-fp64', 'qpp-cpu'
114+
'density-matrix-cpu', 'nvidia', 'nvidia-fp64', 'nvidia-mqpu',
115+
'nvidia-mqpu-fp64', 'qpp-cpu'
116116
])
117117
def test_simulators(target):
118118
"""Test simulation of custom operation on all available simulation targets."""

runtime/cudaq/distributed/builtin/mpi_comm_impl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,20 @@ MPI_Datatype convertType(DataType dataType) {
4040
switch (dataType) {
4141
case INT_8:
4242
return MPI_INT8_T;
43+
case UINT_8:
44+
return MPI_UINT8_T;
4345
case INT_16:
4446
return MPI_INT16_T;
47+
case UINT_16:
48+
return MPI_UINT16_T;
4549
case INT_32:
4650
return MPI_INT32_T;
51+
case UINT_32:
52+
return MPI_UINT32_T;
4753
case INT_64:
4854
return MPI_INT64_T;
55+
case UINT_64:
56+
return MPI_UINT64_T;
4957
case FLOAT_32:
5058
return MPI_FLOAT;
5159
case FLOAT_64:

runtime/cudaq/distributed/distributed_capi.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ enum DataType {
4242
FLOAT_32,
4343
FLOAT_64,
4444
FLOAT_COMPLEX,
45-
DOUBLE_COMPLEX
45+
DOUBLE_COMPLEX,
46+
UINT_8,
47+
UINT_16,
48+
UINT_32,
49+
UINT_64
4650
};
4751

4852
/// @brief Type of MPI reduce ops that we support

runtime/cudaq/platform/default/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@ add_target_config(compiler-bench-ftqc-logical)
5454

5555
if (cuStateVec_FOUND)
5656
add_target_config(nvidia)
57-
add_target_config(nvidia-legacy)
5857
add_target_config(nvidia-fp64)
5958
endif()

runtime/cudaq/platform/default/nvidia-fp64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ warning: "This target is deprecating. Please use the 'nvidia' target with option
1212
gpu-requirements: true
1313

1414
config:
15-
nvqir-simulation-backend: cusvsim-fp64, custatevec-fp64
15+
nvqir-simulation-backend: custatevec-fp64
1616
preprocessor-defines: ["-D CUDAQ_SIMULATION_SCALAR_FP64"]
1717

0 commit comments

Comments
 (0)