Skip to content

Commit

Permalink
Merge branch 'master' into cuquantum_bazel_support_version_0.15.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyoo authored Apr 13, 2023
2 parents dc5f879 + bebf0ad commit dc59eb2
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(has_nvcc STREQUAL "")
else()
project(qsim LANGUAGES CXX CUDA)
ADD_SUBDIRECTORY(pybind_interface/cuda)
if(DEFINED ENV{CUQUANTUM_DIR})
if(DEFINED ENV{CUQUANTUM_ROOT})
ADD_SUBDIRECTORY(pybind_interface/custatevec)
endif()
endif()
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ CXXFLAGS = -O3 -fopenmp
ARCHFLAGS = -march=native
NVCCFLAGS = -O3

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

PYBIND11 = true

Expand Down
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ cc_library(
"https://gitlab.com/libeigen/eigen/-/archive/{commit}/eigen-{commit}.tar.gz".format(commit = EIGEN_COMMIT),
],
)

load("//third_party/cuquantum:cuquantum_configure.bzl", "cuquantum_configure")

cuquantum_configure(name = "local_config_cuquantum")
4 changes: 2 additions & 2 deletions apps/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ g++ -O3 -march=native -fopenmp -o qsimh_amplitudes.x qsimh_amplitudes.cc
nvcc -O3 -o qsim_base_cuda.x qsim_base_cuda.cu
nvcc -O3 -o qsim_qtrajectory_cuda.x qsim_qtrajectory_cuda.cu

# CUQUANTUM_DIR should be set.
CUSTATEVECFLAGS="-I${CUQUANTUM_DIR}/include -L${CUQUANTUM_DIR}/lib -L${CUQUANTUM_DIR}/lib64 -lcustatevec -lcublas"
# CUQUANTUM_ROOT should be set.
CUSTATEVECFLAGS="-I${CUQUANTUM_ROOT}/include -L${CUQUANTUM_ROOT}/lib -L${CUQUANTUM_ROOT}/lib64 -lcustatevec -lcublas"
nvcc -O3 $CUSTATEVECFLAGS -o qsim_base_custatevec.x qsim_base_custatevec.cu
2 changes: 1 addition & 1 deletion docs/cirq_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ and run on a device with available NVIDIA GPUs.
Compilation for GPU follows the same steps outlined in the
[Compiling qsimcirq](./cirq_interface.md#compiling-qsimcirq) section.
To compile with the NVIDIA cuStateVec library (v1.0.0 or higher is required),
set the environmment variable `CUQUANTUM_DIR` to the path to the cuStateVec
set the environmment variable `CUQUANTUM_ROOT` to the path to the cuStateVec
library.

`QSimOptions` provides five parameters to configure GPU execution. `use_gpu`
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/gcp_gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ installed (instructions are provided
[here](https://docs.nvidia.com/cuda/cuquantum/custatevec/getting_started.html#installation-and-compilation),
cuStateVec v1.0.0 or higher is required),
you can use it with this tutorial. Before building qsim in step 5,
set the `CUQUANTUM_DIR` environment variable from the command line:
set the `CUQUANTUM_ROOT` environment variable from the command line:

```bash
export CUQUANTUM_DIR=[PATH_TO_CUQUANTUM_SDK]
export CUQUANTUM_ROOT=[PATH_TO_CUQUANTUM_SDK]
```

Once you have built qsim, modify the `gpu_options` line like so:
Expand Down
119 changes: 119 additions & 0 deletions lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ cc_library(
],
)

cc_library(
name = "cuda",
data = [
"@local_config_cuda//cuda:cudart",
],
linkopts = [
"-Wl,-rpath,../local_config_cuda/cuda/lib64",
"-Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib64",
],
deps = [
"@local_config_cuda//cuda:cudart",
],
)

# Full qsim library, including CUDA
cuda_library(
name = "qsim_cuda_lib",
Expand Down Expand Up @@ -125,6 +139,81 @@ cuda_library(
"vectorspace.h",
"vectorspace_cuda.h",
],
deps = [
":cuda",
"@local_config_cuda//cuda:cuda_headers",
]
)

# Full qsim library, including cuQuantum
cuda_library(
name = "qsim_cuquantum_lib",
hdrs = [
"bits.h",
"bitstring.h",
"channel.h",
"channels_cirq.h",
"circuit_noisy.h",
"circuit_qsim_parser.h",
"circuit.h",
"expect.h",
"formux.h",
"fuser.h",
"fuser_basic.h",
"fuser_mqubit.h",
"gate.h",
"gate_appl.h",
"gates_cirq.h",
"gates_qsim.h",
"hybrid.h",
"io_file.h",
"io.h",
"matrix.h",
"mps_simulator.h",
"mps_statespace.h",
"parfor.h",
"qtrajectory.h",
"run_qsim.h",
"run_qsimh.h",
"seqfor.h",
"simmux.h",
"simmux_gpu.h",
"simulator.h",
"simulator_avx.h",
"simulator_avx512.h",
"simulator_basic.h",
"simulator_sse.h",
"simulator_custatevec.h",
"statespace_avx.h",
"statespace_avx512.h",
"statespace_basic.h",
"statespace_sse.h",
"statespace_custatevec.h",
"statespace.h",
"umux.h",
"unitaryspace.h",
"unitaryspace_avx.h",
"unitaryspace_avx512.h",
"unitaryspace_basic.h",
"unitaryspace_sse.h",
"unitary_calculator_avx.h",
"unitary_calculator_avx512.h",
"unitary_calculator_basic.h",
"unitary_calculator_sse.h",
"util.h",
"util_cpu.h",
"util_cuda.h",
"util_custatevec.h",
"vectorspace.h",
"vectorspace_cuda.h",
],
copts = ["-D__CUSTATEVEC__"],
deps = [
":cuda",
"@local_config_cuda//cuda:cuda_headers",
"@local_config_cuquantum//:cuquantum_headers",
"@local_config_cuquantum//:libcuquantum",
],
)

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

cuda_library(
name = "util_custatevec",
hdrs = ["util_custatevec.h"],
)

### Input/output libraries ###

cc_library(
Expand Down Expand Up @@ -469,6 +563,18 @@ cuda_library(
],
)

cuda_library(
name = "statespace_custatevec",
hdrs = [
"statespace_custatevec.h",
],
deps = [
":statespace",
":util_custatevec",
":vectorspace_cuda",
],
)

### Simulator libraries ###

cc_library(
Expand Down Expand Up @@ -526,6 +632,19 @@ cuda_library(
],
)

cuda_library(
name = "simulator_custatevec",
hdrs = [
"simulator_custatevec.h",
"simulator_custatevec_kernels.h",
],
deps = [
":bits",
":statespace_custatevec",
":util_custatevec",
],
)

# All three state-vector simulators with multiplexer
cc_library(
name = "simulator",
Expand Down
2 changes: 1 addition & 1 deletion pybind_interface/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ifeq ($(shell which $(NVCC)),)
pybind: pybind-cpu decide-cpu
else
# Check for the cuStateVec library.
ifeq ($(CUQUANTUM_DIR),)
ifeq ($(CUQUANTUM_ROOT),)
pybind: pybind-cpu pybind-gpu decide-gpu
else
pybind: pybind-cpu pybind-gpu pybind-custatevec decide-custatevec
Expand Down
4 changes: 2 additions & 2 deletions pybind_interface/custatevec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ find_package(CUDA REQUIRED)

include_directories(${pybind11_INCLUDE_DIRS})

include_directories($ENV{CUQUANTUM_DIR}/include)
link_directories($ENV{CUQUANTUM_DIR}/lib $ENV{CUQUANTUM_DIR}/lib64)
include_directories($ENV{CUQUANTUM_ROOT}/include)
link_directories($ENV{CUQUANTUM_ROOT}/lib $ENV{CUQUANTUM_ROOT}/lib64)

cuda_add_library(qsim_custatevec MODULE pybind_main_custatevec.cpp)
target_link_libraries(qsim_custatevec -lcustatevec -lcublas)
Expand Down
2 changes: 1 addition & 1 deletion pybind_interface/decide/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ else()

cuda_add_library(qsim_decide MODULE decide.cpp)

if(DEFINED ENV{CUQUANTUM_DIR})
if(DEFINED ENV{CUQUANTUM_ROOT})
target_compile_options(qsim_decide PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:-D__CUSTATEVEC__>
)
Expand Down
4 changes: 2 additions & 2 deletions tests/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ nvcc -O3 -I$path_to_include -L$path_to_lib -o qtrajectory_cuda_test.x qtrajector
nvcc -O3 -I$path_to_include -L$path_to_lib -o simulator_cuda_test.x simulator_cuda_test.cu -lgtest -lpthread
nvcc -O3 -I$path_to_include -L$path_to_lib -o statespace_cuda_test.x statespace_cuda_test.cu -lgtest -lpthread

# CUQUANTUM_DIR should be set.
CUSTATEVECFLAGS="-I${CUQUANTUM_DIR}/include -L${CUQUANTUM_DIR}/lib -L${CUQUANTUM_DIR}/lib64 -lcustatevec -lcublas"
# CUQUANTUM_ROOT should be set.
CUSTATEVECFLAGS="-I${CUQUANTUM_ROOT}/include -L${CUQUANTUM_ROOT}/lib -L${CUQUANTUM_ROOT}/lib64 -lcustatevec -lcublas"
nvcc -O3 $CUSTATEVECFLAGS -I$path_to_include -L$path_to_lib -o hybrid_custatevec_test.x hybrid_custatevec_test.cu -lgtest -lpthread
nvcc -O3 $CUSTATEVECFLAGS -I$path_to_include -L$path_to_lib -o qtrajectory_custatevec_test.x qtrajectory_custatevec_test.cu -lgtest -lpthread
nvcc -O3 $CUSTATEVECFLAGS -I$path_to_include -L$path_to_lib -o simulator_custatevec_test.x simulator_custatevec_test.cu -lgtest -lpthread
Expand Down
Empty file added third_party/BUILD
Empty file.
Empty file added third_party/cuquantum/BUILD
Empty file.
20 changes: 20 additions & 0 deletions third_party/cuquantum/BUILD.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "cuquantum_headers",
linkstatic = 1,
srcs = [":cuquantum_header_include"],
includes = ["include"],
visibility = ["//visibility:public"],
)

cc_library(
name = "libcuquantum",
srcs = [
":libcustatevec.so",
],
visibility = ["//visibility:public"],
)

%{CUQUANTUM_HEADER_GENRULE}
%{CUSTATEVEC_SHARED_LIBRARY_GENRULE}
Loading

0 comments on commit dc59eb2

Please sign in to comment.