1
1
# 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" )
2
4
3
5
package (default_visibility = ["//visibility:public" ])
4
6
@@ -12,6 +14,23 @@ config_setting(
12
14
constraint_values = ["@bazel_tools//platforms:windows" ],
13
15
)
14
16
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
+
15
34
py_library (
16
35
name = "ops" ,
17
36
srcs = ["__init__.py" ],
@@ -30,7 +49,10 @@ py_library(
30
49
"//tensorflow_quantum/core/ops/math_ops:inner_product_op_py" ,
31
50
"//tensorflow_quantum/core/ops/math_ops:fidelity_op_py" ,
32
51
"//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
+ ]),
34
56
)
35
57
36
58
cc_binary (
@@ -619,6 +641,198 @@ py_test(
619
641
],
620
642
)
621
643
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
+
622
836
py_library (
623
837
name = "load_module" ,
624
838
srcs = ["load_module.py" ],
0 commit comments