Skip to content

Commit bebf0ad

Browse files
Merge pull request #600 from jaeyoo/custatevec_support_v6
Custatevec support v6
2 parents d747970 + f21e21d commit bebf0ad

File tree

15 files changed

+396
-14
lines changed

15 files changed

+396
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if(has_nvcc STREQUAL "")
66
else()
77
project(qsim LANGUAGES CXX CUDA)
88
ADD_SUBDIRECTORY(pybind_interface/cuda)
9-
if(DEFINED ENV{CUQUANTUM_DIR})
9+
if(DEFINED ENV{CUQUANTUM_ROOT})
1010
ADD_SUBDIRECTORY(pybind_interface/custatevec)
1111
endif()
1212
endif()

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ CXXFLAGS = -O3 -fopenmp
1111
ARCHFLAGS = -march=native
1212
NVCCFLAGS = -O3
1313

14-
# CUQUANTUM_DIR should be set.
15-
CUSTATEVECFLAGS = -I$(CUQUANTUM_DIR)/include -L${CUQUANTUM_DIR}/lib -L$(CUQUANTUM_DIR)/lib64 -lcustatevec -lcublas
14+
# CUQUANTUM_ROOT should be set.
15+
CUSTATEVECFLAGS = -I$(CUQUANTUM_ROOT)/include -L${CUQUANTUM_ROOT}/lib -L$(CUQUANTUM_ROOT)/lib64 -lcustatevec -lcublas
1616

1717
PYBIND11 = true
1818

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ cc_library(
6464
"https://gitlab.com/libeigen/eigen/-/archive/{commit}/eigen-{commit}.tar.gz".format(commit = EIGEN_COMMIT),
6565
],
6666
)
67+
68+
load("//third_party/cuquantum:cuquantum_configure.bzl", "cuquantum_configure")
69+
70+
cuquantum_configure(name = "local_config_cuquantum")

apps/make.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ g++ -O3 -march=native -fopenmp -o qsimh_amplitudes.x qsimh_amplitudes.cc
2626
nvcc -O3 -o qsim_base_cuda.x qsim_base_cuda.cu
2727
nvcc -O3 -o qsim_qtrajectory_cuda.x qsim_qtrajectory_cuda.cu
2828

29-
# CUQUANTUM_DIR should be set.
30-
CUSTATEVECFLAGS="-I${CUQUANTUM_DIR}/include -L${CUQUANTUM_DIR}/lib -L${CUQUANTUM_DIR}/lib64 -lcustatevec -lcublas"
29+
# CUQUANTUM_ROOT should be set.
30+
CUSTATEVECFLAGS="-I${CUQUANTUM_ROOT}/include -L${CUQUANTUM_ROOT}/lib -L${CUQUANTUM_ROOT}/lib64 -lcustatevec -lcublas"
3131
nvcc -O3 $CUSTATEVECFLAGS -o qsim_base_custatevec.x qsim_base_custatevec.cu

docs/cirq_interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ and run on a device with available NVIDIA GPUs.
180180
Compilation for GPU follows the same steps outlined in the
181181
[Compiling qsimcirq](./cirq_interface.md#compiling-qsimcirq) section.
182182
To compile with the NVIDIA cuStateVec library (v1.0.0 or higher is required),
183-
set the environmment variable `CUQUANTUM_DIR` to the path to the cuStateVec
183+
set the environmment variable `CUQUANTUM_ROOT` to the path to the cuStateVec
184184
library.
185185

186186
`QSimOptions` provides five parameters to configure GPU execution. `use_gpu`

docs/tutorials/gcp_gpu.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ installed (instructions are provided
182182
[here](https://docs.nvidia.com/cuda/cuquantum/custatevec/getting_started.html#installation-and-compilation),
183183
cuStateVec v1.0.0 or higher is required),
184184
you can use it with this tutorial. Before building qsim in step 5,
185-
set the `CUQUANTUM_DIR` environment variable from the command line:
185+
set the `CUQUANTUM_ROOT` environment variable from the command line:
186186

187187
```bash
188-
export CUQUANTUM_DIR=[PATH_TO_CUQUANTUM_SDK]
188+
export CUQUANTUM_ROOT=[PATH_TO_CUQUANTUM_SDK]
189189
```
190190

191191
Once you have built qsim, modify the `gpu_options` line like so:

lib/BUILD

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ cc_library(
6262
],
6363
)
6464

65+
cc_library(
66+
name = "cuda",
67+
data = [
68+
"@local_config_cuda//cuda:cudart",
69+
],
70+
linkopts = [
71+
"-Wl,-rpath,../local_config_cuda/cuda/lib64",
72+
"-Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib64",
73+
],
74+
deps = [
75+
"@local_config_cuda//cuda:cudart",
76+
],
77+
)
78+
6579
# Full qsim library, including CUDA
6680
cuda_library(
6781
name = "qsim_cuda_lib",
@@ -125,6 +139,81 @@ cuda_library(
125139
"vectorspace.h",
126140
"vectorspace_cuda.h",
127141
],
142+
deps = [
143+
":cuda",
144+
"@local_config_cuda//cuda:cuda_headers",
145+
]
146+
)
147+
148+
# Full qsim library, including cuQuantum
149+
cuda_library(
150+
name = "qsim_cuquantum_lib",
151+
hdrs = [
152+
"bits.h",
153+
"bitstring.h",
154+
"channel.h",
155+
"channels_cirq.h",
156+
"circuit_noisy.h",
157+
"circuit_qsim_parser.h",
158+
"circuit.h",
159+
"expect.h",
160+
"formux.h",
161+
"fuser.h",
162+
"fuser_basic.h",
163+
"fuser_mqubit.h",
164+
"gate.h",
165+
"gate_appl.h",
166+
"gates_cirq.h",
167+
"gates_qsim.h",
168+
"hybrid.h",
169+
"io_file.h",
170+
"io.h",
171+
"matrix.h",
172+
"mps_simulator.h",
173+
"mps_statespace.h",
174+
"parfor.h",
175+
"qtrajectory.h",
176+
"run_qsim.h",
177+
"run_qsimh.h",
178+
"seqfor.h",
179+
"simmux.h",
180+
"simmux_gpu.h",
181+
"simulator.h",
182+
"simulator_avx.h",
183+
"simulator_avx512.h",
184+
"simulator_basic.h",
185+
"simulator_sse.h",
186+
"simulator_custatevec.h",
187+
"statespace_avx.h",
188+
"statespace_avx512.h",
189+
"statespace_basic.h",
190+
"statespace_sse.h",
191+
"statespace_custatevec.h",
192+
"statespace.h",
193+
"umux.h",
194+
"unitaryspace.h",
195+
"unitaryspace_avx.h",
196+
"unitaryspace_avx512.h",
197+
"unitaryspace_basic.h",
198+
"unitaryspace_sse.h",
199+
"unitary_calculator_avx.h",
200+
"unitary_calculator_avx512.h",
201+
"unitary_calculator_basic.h",
202+
"unitary_calculator_sse.h",
203+
"util.h",
204+
"util_cpu.h",
205+
"util_cuda.h",
206+
"util_custatevec.h",
207+
"vectorspace.h",
208+
"vectorspace_cuda.h",
209+
],
210+
copts = ["-D__CUSTATEVEC__"],
211+
deps = [
212+
":cuda",
213+
"@local_config_cuda//cuda:cuda_headers",
214+
"@local_config_cuquantum//:cuquantum_headers",
215+
"@local_config_cuquantum//:libcuquantum",
216+
],
128217
)
129218

130219
# Library to run qsim with qsim circuit parser and parallel `for`
@@ -248,6 +337,11 @@ cuda_library(
248337
hdrs = ["util_cuda.h"],
249338
)
250339

340+
cuda_library(
341+
name = "util_custatevec",
342+
hdrs = ["util_custatevec.h"],
343+
)
344+
251345
### Input/output libraries ###
252346

253347
cc_library(
@@ -469,6 +563,18 @@ cuda_library(
469563
],
470564
)
471565

566+
cuda_library(
567+
name = "statespace_custatevec",
568+
hdrs = [
569+
"statespace_custatevec.h",
570+
],
571+
deps = [
572+
":statespace",
573+
":util_custatevec",
574+
":vectorspace_cuda",
575+
],
576+
)
577+
472578
### Simulator libraries ###
473579

474580
cc_library(
@@ -526,6 +632,19 @@ cuda_library(
526632
],
527633
)
528634

635+
cuda_library(
636+
name = "simulator_custatevec",
637+
hdrs = [
638+
"simulator_custatevec.h",
639+
"simulator_custatevec_kernels.h",
640+
],
641+
deps = [
642+
":bits",
643+
":statespace_custatevec",
644+
":util_custatevec",
645+
],
646+
)
647+
529648
# All three state-vector simulators with multiplexer
530649
cc_library(
531650
name = "simulator",

pybind_interface/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ifeq ($(shell which $(NVCC)),)
2424
pybind: pybind-cpu decide-cpu
2525
else
2626
# Check for the cuStateVec library.
27-
ifeq ($(CUQUANTUM_DIR),)
27+
ifeq ($(CUQUANTUM_ROOT),)
2828
pybind: pybind-cpu pybind-gpu decide-gpu
2929
else
3030
pybind: pybind-cpu pybind-gpu pybind-custatevec decide-custatevec

pybind_interface/custatevec/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ find_package(CUDA REQUIRED)
3333

3434
include_directories(${pybind11_INCLUDE_DIRS})
3535

36-
include_directories($ENV{CUQUANTUM_DIR}/include)
37-
link_directories($ENV{CUQUANTUM_DIR}/lib $ENV{CUQUANTUM_DIR}/lib64)
36+
include_directories($ENV{CUQUANTUM_ROOT}/include)
37+
link_directories($ENV{CUQUANTUM_ROOT}/lib $ENV{CUQUANTUM_ROOT}/lib64)
3838

3939
cuda_add_library(qsim_custatevec MODULE pybind_main_custatevec.cpp)
4040
target_link_libraries(qsim_custatevec -lcustatevec -lcublas)

pybind_interface/decide/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ else()
3131

3232
cuda_add_library(qsim_decide MODULE decide.cpp)
3333

34-
if(DEFINED ENV{CUQUANTUM_DIR})
34+
if(DEFINED ENV{CUQUANTUM_ROOT})
3535
target_compile_options(qsim_decide PRIVATE
3636
$<$<COMPILE_LANGUAGE:CUDA>:-D__CUSTATEVEC__>
3737
)

0 commit comments

Comments
 (0)