Skip to content

Commit 46aa1f0

Browse files
authored
Merge pull request #2 from jaeyoo/cuquantum_support
Cuquantum support
2 parents 2a5fd07 + f97c496 commit 46aa1f0

File tree

5 files changed

+501
-8
lines changed

5 files changed

+501
-8
lines changed

WORKSPACE

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ cc_library(
3434
# TODO: After merging this patch later into qsim mainstream, remove this and uncomment the above.
3535
http_archive(
3636
name = "qsim",
37-
sha256 = "97b26e1a8fe13cfa465611f2618ade00f539480c6a7849f020fbee3582686bbf",
38-
strip_prefix = "qsim-0.15.0-dev20230317",
39-
urls = ["https://github.com/jaeyoo/qsim/archive/refs/tags/v0.15.0+dev20230317.tar.gz"],
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"],
4040
)
4141

4242
http_archive(
@@ -81,3 +81,21 @@ bind(
8181
actual = "@six_archive//:six",
8282
)
8383

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+

tensorflow_quantum/core/ops/BUILD

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,11 +652,25 @@ py_library(
652652
],
653653
)
654654

655+
py_library(
656+
name = "tfq_simulate_ops_cuquantum_py",
657+
srcs = ["tfq_simulate_ops_cuquantum.py"],
658+
data = [
659+
":_tfq_simulate_ops_cuquantum.so",
660+
],
661+
srcs_version = "PY3",
662+
deps = [
663+
# tensorflow framework for wrappers
664+
":load_module",
665+
],
666+
)
667+
655668
py_test(
656-
name = "tfq_simulate_ops_cuda_test",
657-
srcs = ["tfq_simulate_ops_cuda_test.py"],
669+
name = "tfq_simulate_ops_gpu_test",
670+
srcs = ["tfq_simulate_ops_gpu_test.py"],
658671
deps = [
659672
":tfq_simulate_ops_cuda_py",
673+
":tfq_simulate_ops_cuquantum_py",
660674
":tfq_simulate_ops_py",
661675
"//tensorflow_quantum/python:util",
662676
],
@@ -726,13 +740,94 @@ cc_binary(
726740
"//tensorflow_quantum/core/proto:program_cc_proto",
727741
"//tensorflow_quantum/core/src:circuit_parser_qsim",
728742
"//tensorflow_quantum/core/src:util_qsim",
743+
"@eigen//:eigen3",
744+
# "@local_cuda//:cuda_headers"
745+
# tensorflow core framework
746+
# tensorflow core lib
747+
# tensorflow core protos
748+
] + if_cuda_is_configured([
749+
":cuda",
750+
"@local_config_cuda//cuda:cuda_headers",
729751
"@qsim//lib:qsim_cuda_lib",
752+
]),
753+
# alwayslink=1,
754+
)
755+
756+
cc_binary(
757+
name = "_tfq_simulate_ops_cuquantum.so",
758+
srcs = [
759+
"tfq_simulate_expectation_op_cuquantum.cu.cc",
760+
],
761+
linkshared = 1,
762+
features = select({
763+
":windows": ["windows_export_all_symbols"],
764+
"//conditions:default": [],
765+
}),
766+
copts = select({
767+
":windows": [
768+
"/D__CLANG_SUPPORT_DYN_ANNOTATION__",
769+
"/D_USE_MATH_DEFINES",
770+
"/DEIGEN_MPL2_ONLY",
771+
"/DEIGEN_MAX_ALIGN_BYTES=64",
772+
"/DEIGEN_HAS_TYPE_TRAITS=0",
773+
"/DTF_USE_SNAPPY",
774+
"/showIncludes",
775+
"/MD",
776+
"/O2",
777+
"/DNDEBUG",
778+
"/w",
779+
"-DWIN32_LEAN_AND_MEAN",
780+
"-DNOGDI",
781+
"/d2ReducedOptimizeHugeFunctions",
782+
"/arch:AVX",
783+
"/std:c++17",
784+
"-DTENSORFLOW_MONOLITHIC_BUILD",
785+
"/DPLATFORM_WINDOWS",
786+
"/DEIGEN_HAS_C99_MATH",
787+
"/DTENSORFLOW_USE_EIGEN_THREADPOOL",
788+
"/DEIGEN_AVOID_STL_ARRAY",
789+
"/Iexternal/gemmlowp",
790+
"/wd4018",
791+
"/wd4577",
792+
"/DNOGDI",
793+
"/UTF_COMPILE_LIBRARY",
794+
],
795+
"//conditions:default": [
796+
"-Iexternal/local_cuda/cuda/include",
797+
# "--cuda-gpu-arch=sm_86",
798+
# "-L/usr/local/cuda/lib64",
799+
# "-lcudart_static",
800+
# "-ldl",
801+
# "-lrt",
802+
"-pthread",
803+
"-std=c++17",
804+
"-D_GLIBCXX_USE_CXX11_ABI=1",
805+
"-O3",
806+
"-Iexternal/cuda_headers",
807+
"-DNV_CUDNN_DISABLE_EXCEPTION",
808+
# "-fpermissive",
809+
],
810+
}) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]),
811+
deps = [
812+
# cirq cc proto
813+
"//tensorflow_quantum/core/ops:parse_context",
814+
"//tensorflow_quantum/core/ops:tfq_simulate_utils",
815+
"//tensorflow_quantum/core/proto:pauli_sum_cc_proto",
816+
"//tensorflow_quantum/core/proto:program_cc_proto",
817+
"//tensorflow_quantum/core/src:circuit_parser_qsim",
818+
"//tensorflow_quantum/core/src:util_qsim",
730819
"@eigen//:eigen3",
731820
# "@local_cuda//:cuda_headers"
732821
# tensorflow core framework
733822
# tensorflow core lib
734823
# tensorflow core protos
735-
] + if_cuda_is_configured([":cuda", "@local_config_cuda//cuda:cuda_headers"]),
824+
] + if_cuda_is_configured([
825+
":cuda",
826+
"@cuquantum_libs//:custatevec",
827+
"@cuquantum_libs//:custatevec_headers",
828+
"@local_config_cuda//cuda:cuda_headers",
829+
"@qsim//lib:qsim_cuquantum_lib",
830+
]),
736831
# alwayslink=1,
737832
)
738833

0 commit comments

Comments
 (0)