diff --git a/.bazelrc b/.bazelrc index 4925e58e2b..7fa47bbae7 100644 --- a/.bazelrc +++ b/.bazelrc @@ -14,7 +14,7 @@ # limitations under the License. # # File: DL4AGX/.bazelrc -# Description: Default bazel settings and toolchain configuration +# Description: Default bazel settings and toolchain configuration ########################################################################## # +------------------------------------------------------------+ @@ -24,3 +24,8 @@ build --cxxopt="-fdiagnostics-color=always" build --cxxopt='-std=c++14' #build --linkopt="-Wl,--no-as-needed" + + +build:python --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" +build:python --linkopt="-D_GLIBCXX_USE_CXX11_ABI=0" +build:python --define=api=python \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8518b34a75..68de0cd9ae 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,7 @@ tests/accuracy/datasets/data/* *.tgz docsrc/_build docsrc/_api -docsrc/_tmp \ No newline at end of file +docsrc/_tmp +*.so +__pycache__ +*.egg-info \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE index f93c2f7e1c..1f765e6337 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,6 +4,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + + http_archive( name = "rules_python", url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz", @@ -32,6 +34,14 @@ new_local_repository( build_file = "@//third_party/cuda:BUILD", ) +http_archive( + name = "libtorch_non_cxx11_abi", + build_file = "@//third_party/libtorch:BUILD", + strip_prefix = "libtorch", + sha256 = "ea8de17c5f70015583f3a7a43c7a5cdf91a1d4bd19a6a7bc11f074ef6cd69e27", + urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-shared-with-deps-1.5.0.zip"], +) + http_archive( name = "libtorch", build_file = "@//third_party/libtorch:BUILD", @@ -43,8 +53,7 @@ http_archive( # Downloaded distributions to use with --distdir http_archive( name = "cudnn", - urls = ["https://developer.nvidia.com/compute/machine-learning/cudnn/secure/7.6.5.32/Production/10.2_20191118/cudnn-10.2-linux-x64-v7.6.5.32.tgz",], - + urls = ["https://developer.nvidia.com/compute/machine-learning/cudnn/secure/7.6.5.32/Production/10.2_20191118/cudnn-10.2-linux-x64-v7.6.5.32.tgz"], build_file = "@//third_party/cudnn/archive:BUILD", sha256 = "600267f2caaed2fd58eb214ba669d8ea35f396a7d19b94822e6b36f9f7088c20", strip_prefix = "cuda" @@ -52,8 +61,7 @@ http_archive( http_archive( name = "tensorrt", - urls = ["https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.0/7.0.0.11/tars/TensorRT-7.0.0.11.Ubuntu-18.04.x86_64-gnu.cuda-10.2.cudnn7.6.tar.gz",], - + urls = ["https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.0/7.0.0.11/tars/TensorRT-7.0.0.11.Ubuntu-18.04.x86_64-gnu.cuda-10.2.cudnn7.6.tar.gz"], build_file = "@//third_party/tensorrt/archive:BUILD", sha256 = "c7d73b2585b18aae68b740249efa8c8ba5ae852abe9a023720595432a8eb4efd", strip_prefix = "TensorRT-7.0.0.11" diff --git a/core/BUILD b/core/BUILD index be3937aa64..a318d3a690 100644 --- a/core/BUILD +++ b/core/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "core", hdrs = [ @@ -13,9 +20,11 @@ cc_library( "//core/execution", "//core/lowering", "//core/util/logging", - "@libtorch//:libtorch", "@tensorrt//:nvinfer" - ], + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }), alwayslink=True, ) diff --git a/core/conversion/BUILD b/core/conversion/BUILD index ea3b77d4d0..58ec5dbf4c 100644 --- a/core/conversion/BUILD +++ b/core/conversion/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "conversion", hdrs = [ @@ -13,12 +20,14 @@ cc_library( ], deps = [ "@tensorrt//:nvinfer", - "@libtorch//:libtorch", "//core/conversion/conversionctx", "//core/conversion/converters", "//core/conversion/evaluators", "//core/util:prelude" - ] + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }) ) load("@rules_pkg//:pkg.bzl", "pkg_tar") diff --git a/core/conversion/conversionctx/BUILD b/core/conversion/conversionctx/BUILD index 2d9e3dd34b..86407d8a81 100644 --- a/core/conversion/conversionctx/BUILD +++ b/core/conversion/conversionctx/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "conversionctx", hdrs = [ @@ -10,9 +17,11 @@ cc_library( ], deps = [ "@tensorrt//:nvinfer", - "@libtorch//:libtorch", "//core/util:prelude", - ] + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }) ) load("@rules_pkg//:pkg.bzl", "pkg_tar") diff --git a/core/conversion/converters/BUILD b/core/conversion/converters/BUILD index 464ad44550..5a31456f40 100644 --- a/core/conversion/converters/BUILD +++ b/core/conversion/converters/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "converters", hdrs = [ @@ -24,11 +31,13 @@ cc_library( "impl/unary.cpp", ], deps = [ - "@libtorch//:libtorch", "@tensorrt//:nvinfer", "//core/util:prelude", - "//core/conversion/conversionctx" - ], + "//core/conversion/conversionctx", + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }), alwayslink = True, ) diff --git a/core/conversion/evaluators/BUILD b/core/conversion/evaluators/BUILD index 639fc0fc39..b32c7f333a 100644 --- a/core/conversion/evaluators/BUILD +++ b/core/conversion/evaluators/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "evaluators", hdrs = [ @@ -10,9 +17,11 @@ cc_library( "prim.cpp", ], deps = [ - "@libtorch//:libtorch", "//core/util:prelude", - ], + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }), alwayslink = True, ) diff --git a/core/execution/BUILD b/core/execution/BUILD index ed53cdefcf..7ff0359c78 100644 --- a/core/execution/BUILD +++ b/core/execution/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "execution", hdrs = [ @@ -12,9 +19,11 @@ cc_library( ], deps = [ "@tensorrt//:nvinfer", - "@libtorch//:libtorch", "//core/util:prelude" - ], + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }), alwayslink = True, ) diff --git a/core/lowering/BUILD b/core/lowering/BUILD index 4d4822a2a9..24c4fa4dc4 100644 --- a/core/lowering/BUILD +++ b/core/lowering/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "lowering", hdrs = [ @@ -11,10 +18,12 @@ cc_library( "register_const_op.cpp" ], deps = [ - "@libtorch//:libtorch", "//core/lowering/passes", "//core/util:prelude" - ], + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }), alwayslink = True ) diff --git a/core/lowering/passes/BUILD b/core/lowering/passes/BUILD index 3c61be66a4..87a3d5f08c 100644 --- a/core/lowering/passes/BUILD +++ b/core/lowering/passes/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "passes", hdrs = [ @@ -16,8 +23,10 @@ cc_library( ], deps = [ "//core/util:prelude", - "@libtorch//:libtorch", - ] + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }) ) load("@rules_pkg//:pkg.bzl", "pkg_tar") diff --git a/core/util/BUILD b/core/util/BUILD index 952e45e54a..4a3c5d5389 100644 --- a/core/util/BUILD +++ b/core/util/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "prelude", hdrs = [ @@ -20,9 +27,10 @@ cc_library( hdrs = [ "jit_util.h", ], - deps = [ - "@libtorch//:libtorch", - ] + deps = select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }) ) cc_library( @@ -51,9 +59,11 @@ cc_library( "build_info.h", ], deps = [ - "@libtorch//:libtorch", "@tensorrt//:nvinfer" - ] + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }) ) cc_library( @@ -65,11 +75,13 @@ cc_library( "trt_util.cpp" ], deps = [ - "@libtorch//:libtorch", "@tensorrt//:nvinfer", "//core/util/logging", ":macros" - ] + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }) ) @@ -79,7 +91,7 @@ pkg_tar( name = "include", package_dir = "core/util/", srcs = [ - "//core/util:build_info.h", + "//core/util:build_info.h", "//core/util:macros.h", "//core/util:Exception.h", "//core/util:prelude.h", diff --git a/core/util/logging/BUILD b/core/util/logging/BUILD index 0a5930d7dd..5e8e65c65d 100644 --- a/core/util/logging/BUILD +++ b/core/util/logging/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +config_setting( + name = "dont_use_cxx11_abi", + values = { + "define": "api=python", + } +) + cc_library( name = "logging", hdrs = [ @@ -10,7 +17,10 @@ cc_library( ], deps = [ "@tensorrt//:nvinfer" - ] + ] + select({ + ":dont_use_cxx11_abi": ["@libtorch_non_cxx11_abi//:libtorch"], + "//conditions:default": ["@libtorch//:libtorch"], + }) ) load("@rules_pkg//:pkg.bzl", "pkg_tar") diff --git a/third_party/libtorch/BUILD b/third_party/libtorch/BUILD index 9da5da47c0..1b2be8d83e 100644 --- a/third_party/libtorch/BUILD +++ b/third_party/libtorch/BUILD @@ -26,7 +26,6 @@ cc_library( ], deps = [ ":ATen", - ":torch_deps", ":c10_cuda", ":caffe2" ], @@ -36,14 +35,6 @@ cc_library( ] ) -cc_library( - name = 'torch_deps', - srcs = [ - 'lib/libnvToolsExt-3965bdd0.so.1', - "lib/libcudart-80664282.so.10.2", - ] -) - cc_library( name = 'c10_cuda', hdrs = glob([ @@ -63,17 +54,6 @@ cc_library( ]), srcs = ["lib/libc10.so"], strip_include_prefix = "include", - deps = [ - ":c10_deps", - "@cuda//:cudart", - ] -) - -cc_library( - name = "c10_deps", - srcs = [ - "lib/libcudart-80664282.so.10.2", - ] ) cc_library( @@ -96,14 +76,4 @@ cc_library( 'lib/libcaffe2_module_test_dynamic.so' ], strip_include_prefix = "include", - deps = [ - ":caffe2_deps" - ] -) - -cc_library( - name = 'caffe2_deps', - srcs = [ - 'lib/libnvToolsExt-3965bdd0.so.1', - ] -) +) \ No newline at end of file