Skip to content

Commit 7131f9e

Browse files
authored
Merge branch 'master' into master
2 parents 2c1e7fa + 79aae25 commit 7131f9e

9 files changed

+905
-9
lines changed

WORKSPACE

+29-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ cc_library(
2424
],
2525
)
2626

27+
# http_archive(
28+
# name = "qsim",
29+
# sha256 = "b9c1eba09a885a938b5e73dfc2e02f5231cf3b01d899415caa24769346a731d5",
30+
# strip_prefix = "qsim-0.13.3",
31+
# urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.13.3.zip"],
32+
# )
33+
34+
# TODO: After merging this patch later into qsim mainstream, remove this and uncomment the above.
2735
http_archive(
2836
name = "qsim",
29-
sha256 = "b9c1eba09a885a938b5e73dfc2e02f5231cf3b01d899415caa24769346a731d5",
30-
strip_prefix = "qsim-0.13.3",
31-
urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.13.3.zip"],
37+
sha256 = "",
38+
strip_prefix = "qsim-0.15.0-dev20230327_v3",
39+
urls = ["https://github.com/jaeyoo/qsim/archive/refs/tags/v0.15.0+dev20230327_v3.tar.gz"],
3240
)
3341

3442
http_archive(
@@ -73,3 +81,21 @@ bind(
7381
actual = "@six_archive//:six",
7482
)
7583

84+
new_local_repository(
85+
name = "cuquantum_libs",
86+
path = "/usr/local/google/home/jaeyoo/workspace/cuquantum-linux-x86_64-22.11.0.13-archive",
87+
build_file_content = """
88+
cc_library(
89+
name = "custatevec_headers",
90+
srcs = ["include/custatevec.h"],
91+
visibility = ["//visibility:public"],
92+
)
93+
94+
cc_library(
95+
name = "custatevec",
96+
srcs = ["lib/libcustatevec.so"],
97+
visibility = ["//visibility:public"],
98+
)
99+
""",
100+
)
101+

configure.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ while [[ "$TF_NEED_CUDA" == "" ]]; do
6262
done
6363

6464
while [[ "$TF_CUDA_VERSION" == "" ]]; do
65-
read -p "Are you building against TensorFlow 2.1(including RCs) or newer?[Y/n] " INPUT
65+
read -p "Are you building against TensorFlow 2.11(including RCs) or newer?[Y/n] " INPUT
6666
case $INPUT in
67-
[Yy]* ) echo "Build against TensorFlow 2.1 or newer."; TF_CUDA_VERSION=11;;
68-
[Nn]* ) echo "Build against TensorFlow <2.1."; TF_CUDA_VERSION=10.0;;
69-
"" ) echo "Build against TensorFlow 2.1 or newer."; TF_CUDA_VERSION=11;;
67+
[Yy]* ) echo "Build against TensorFlow 2.11 or newer."; TF_CUDA_VERSION=11;;
68+
[Nn]* ) echo "Build against TensorFlow <2.11."; TF_CUDA_VERSION=10.0;;
69+
"" ) echo "Build against TensorFlow 2.11 or newer."; TF_CUDA_VERSION=11;;
7070
* ) echo "Invalid selection: " $INPUT;;
7171
esac
7272
done

release/BUILD

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured")
2+
13
licenses(["notice"])
24

35
sh_binary(
@@ -66,5 +68,8 @@ sh_binary(
6668
"//tensorflow_quantum/python:util",
6769
"//tensorflow_quantum/python/optimizers:rotosolve_minimizer",
6870
"//tensorflow_quantum/python/optimizers:spsa_minimizer",
69-
],
71+
] + if_cuda_is_configured([
72+
"//tensorflow_quantum/core/ops:tfq_simulate_ops_cuda_py",
73+
"//tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_py",
74+
]),
7075
)

tensorflow_quantum/core/ops/BUILD

+215-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# load op_wrapper
2+
load("@org_tensorflow//tensorflow:tensorflow.bzl", "tf_gpu_kernel_library", "tf_gen_op_wrapper_py")
3+
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured", "if_cuda")
24

35
package(default_visibility = ["//visibility:public"])
46

@@ -12,6 +14,23 @@ config_setting(
1214
constraint_values = ["@bazel_tools//platforms:windows"],
1315
)
1416

17+
cc_library(
18+
name = "cuda",
19+
data = [
20+
"@local_config_cuda//cuda:cudart",
21+
],
22+
linkopts = select({
23+
":windows": [],
24+
"//conditions:default": [
25+
"-Wl,-rpath,../local_config_cuda/cuda/lib64",
26+
"-Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib64",
27+
],
28+
}),
29+
deps = [
30+
"@local_config_cuda//cuda:cudart",
31+
],
32+
)
33+
1534
py_library(
1635
name = "ops",
1736
srcs = ["__init__.py"],
@@ -30,7 +49,10 @@ py_library(
3049
"//tensorflow_quantum/core/ops/math_ops:inner_product_op_py",
3150
"//tensorflow_quantum/core/ops/math_ops:fidelity_op_py",
3251
"//tensorflow_quantum/core/ops/noise:noisy_expectation_op_py",
33-
],
52+
] + if_cuda_is_configured([
53+
":tfq_simulate_ops_cuda_py",
54+
":tfq_simulate_ops_cuquantum_py",
55+
]),
3456
)
3557

3658
cc_binary(
@@ -619,6 +641,198 @@ py_test(
619641
],
620642
)
621643

644+
py_library(
645+
name = "tfq_simulate_ops_cuda_py",
646+
srcs = ["tfq_simulate_ops_cuda.py"],
647+
data = [
648+
":_tfq_simulate_ops_cuda.so",
649+
],
650+
srcs_version = "PY3",
651+
deps = [
652+
# tensorflow framework for wrappers
653+
":load_module",
654+
],
655+
)
656+
657+
py_library(
658+
name = "tfq_simulate_ops_cuquantum_py",
659+
srcs = ["tfq_simulate_ops_cuquantum.py"],
660+
data = [
661+
":_tfq_simulate_ops_cuquantum.so",
662+
],
663+
srcs_version = "PY3",
664+
deps = [
665+
# tensorflow framework for wrappers
666+
":load_module",
667+
],
668+
)
669+
670+
py_test(
671+
name = "tfq_simulate_ops_gpu_test",
672+
srcs = ["tfq_simulate_ops_gpu_test.py"],
673+
deps = [
674+
":tfq_simulate_ops_cuda_py",
675+
":tfq_simulate_ops_cuquantum_py",
676+
":tfq_simulate_ops_py",
677+
"//tensorflow_quantum/python:util",
678+
],
679+
srcs_version = "PY3",
680+
)
681+
682+
cc_binary(
683+
name = "_tfq_simulate_ops_cuda.so",
684+
srcs = [
685+
"tfq_simulate_expectation_op_cuda.cu.cc",
686+
],
687+
linkshared = 1,
688+
features = select({
689+
":windows": ["windows_export_all_symbols"],
690+
"//conditions:default": [],
691+
}),
692+
copts = select({
693+
":windows": [
694+
"/D__CLANG_SUPPORT_DYN_ANNOTATION__",
695+
"/D_USE_MATH_DEFINES",
696+
"/DEIGEN_MPL2_ONLY",
697+
"/DEIGEN_MAX_ALIGN_BYTES=64",
698+
"/DEIGEN_HAS_TYPE_TRAITS=0",
699+
"/DTF_USE_SNAPPY",
700+
"/showIncludes",
701+
"/MD",
702+
"/O2",
703+
"/DNDEBUG",
704+
"/w",
705+
"-DWIN32_LEAN_AND_MEAN",
706+
"-DNOGDI",
707+
"/d2ReducedOptimizeHugeFunctions",
708+
"/arch:AVX",
709+
"/std:c++17",
710+
"-DTENSORFLOW_MONOLITHIC_BUILD",
711+
"/DPLATFORM_WINDOWS",
712+
"/DEIGEN_HAS_C99_MATH",
713+
"/DTENSORFLOW_USE_EIGEN_THREADPOOL",
714+
"/DEIGEN_AVOID_STL_ARRAY",
715+
"/Iexternal/gemmlowp",
716+
"/wd4018",
717+
"/wd4577",
718+
"/DNOGDI",
719+
"/UTF_COMPILE_LIBRARY",
720+
],
721+
"//conditions:default": [
722+
"-Iexternal/local_cuda/cuda/include",
723+
# "--cuda-gpu-arch=sm_86",
724+
# "-L/usr/local/cuda/lib64",
725+
# "-lcudart_static",
726+
# "-ldl",
727+
# "-lrt",
728+
"-pthread",
729+
"-std=c++17",
730+
"-D_GLIBCXX_USE_CXX11_ABI=1",
731+
"-O3",
732+
"-Iexternal/cuda_headers",
733+
"-DNV_CUDNN_DISABLE_EXCEPTION",
734+
# "-fpermissive",
735+
],
736+
}) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]),
737+
deps = [
738+
# cirq cc proto
739+
"//tensorflow_quantum/core/ops:parse_context",
740+
"//tensorflow_quantum/core/ops:tfq_simulate_utils",
741+
"//tensorflow_quantum/core/proto:pauli_sum_cc_proto",
742+
"//tensorflow_quantum/core/proto:program_cc_proto",
743+
"//tensorflow_quantum/core/src:circuit_parser_qsim",
744+
"//tensorflow_quantum/core/src:util_qsim",
745+
"@eigen//:eigen3",
746+
# "@local_cuda//:cuda_headers"
747+
# tensorflow core framework
748+
# tensorflow core lib
749+
# tensorflow core protos
750+
] + if_cuda_is_configured([
751+
":cuda",
752+
"@local_config_cuda//cuda:cuda_headers",
753+
"@qsim//lib:qsim_cuda_lib",
754+
]),
755+
# alwayslink=1,
756+
)
757+
758+
cc_binary(
759+
name = "_tfq_simulate_ops_cuquantum.so",
760+
srcs = [
761+
"tfq_simulate_expectation_op_cuquantum.cu.cc",
762+
],
763+
linkshared = 1,
764+
features = select({
765+
":windows": ["windows_export_all_symbols"],
766+
"//conditions:default": [],
767+
}),
768+
copts = select({
769+
":windows": [
770+
"/D__CLANG_SUPPORT_DYN_ANNOTATION__",
771+
"/D_USE_MATH_DEFINES",
772+
"/DEIGEN_MPL2_ONLY",
773+
"/DEIGEN_MAX_ALIGN_BYTES=64",
774+
"/DEIGEN_HAS_TYPE_TRAITS=0",
775+
"/DTF_USE_SNAPPY",
776+
"/showIncludes",
777+
"/MD",
778+
"/O2",
779+
"/DNDEBUG",
780+
"/w",
781+
"-DWIN32_LEAN_AND_MEAN",
782+
"-DNOGDI",
783+
"/d2ReducedOptimizeHugeFunctions",
784+
"/arch:AVX",
785+
"/std:c++17",
786+
"-DTENSORFLOW_MONOLITHIC_BUILD",
787+
"/DPLATFORM_WINDOWS",
788+
"/DEIGEN_HAS_C99_MATH",
789+
"/DTENSORFLOW_USE_EIGEN_THREADPOOL",
790+
"/DEIGEN_AVOID_STL_ARRAY",
791+
"/Iexternal/gemmlowp",
792+
"/wd4018",
793+
"/wd4577",
794+
"/DNOGDI",
795+
"/UTF_COMPILE_LIBRARY",
796+
],
797+
"//conditions:default": [
798+
"-Iexternal/local_cuda/cuda/include",
799+
# "--cuda-gpu-arch=sm_86",
800+
# "-L/usr/local/cuda/lib64",
801+
# "-lcudart_static",
802+
# "-ldl",
803+
# "-lrt",
804+
"-pthread",
805+
"-std=c++17",
806+
"-D_GLIBCXX_USE_CXX11_ABI=1",
807+
"-O3",
808+
"-Iexternal/cuda_headers",
809+
"-DNV_CUDNN_DISABLE_EXCEPTION",
810+
# "-fpermissive",
811+
],
812+
}) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]),
813+
deps = [
814+
# cirq cc proto
815+
"//tensorflow_quantum/core/ops:parse_context",
816+
"//tensorflow_quantum/core/ops:tfq_simulate_utils",
817+
"//tensorflow_quantum/core/proto:pauli_sum_cc_proto",
818+
"//tensorflow_quantum/core/proto:program_cc_proto",
819+
"//tensorflow_quantum/core/src:circuit_parser_qsim",
820+
"//tensorflow_quantum/core/src:util_qsim",
821+
"@eigen//:eigen3",
822+
# "@local_cuda//:cuda_headers"
823+
# tensorflow core framework
824+
# tensorflow core lib
825+
# tensorflow core protos
826+
] + if_cuda_is_configured([
827+
":cuda",
828+
"@cuquantum_libs//:custatevec",
829+
"@cuquantum_libs//:custatevec_headers",
830+
"@local_config_cuda//cuda:cuda_headers",
831+
"@qsim//lib:qsim_cuquantum_lib",
832+
]),
833+
# alwayslink=1,
834+
)
835+
622836
py_library(
623837
name = "load_module",
624838
srcs = ["load_module.py"],

0 commit comments

Comments
 (0)