From 7291e119ea4e096ac6394cf453df123a780a2e1d Mon Sep 17 00:00:00 2001 From: Vikram Mulukutla Date: Sun, 8 Oct 2023 12:52:25 -0800 Subject: [PATCH] WINDOWS SUPPORT --- WORKSPACE | 103 ++++--------- WORKSPACEOLD | 139 ++++++++++++++++++ .../conversion/converters/impl/activation.cpp | 2 +- core/runtime/TRTEngine.h | 3 + cpp/include/torch_tensorrt/macros.h | 2 +- third_party/cudnn/local/BUILD | 2 +- third_party/tensorrt/local/BUILD | 7 +- 7 files changed, 175 insertions(+), 83 deletions(-) create mode 100644 WORKSPACEOLD diff --git a/WORKSPACE b/WORKSPACE index b24384df..e485a2f9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -33,97 +33,44 @@ http_archive( urls = ["https://github.com/google/googletest/archive/5ab508a01f9eb089207ee87fd547d290da39d015.zip"], ) -# External dependency for torch_tensorrt if you already have precompiled binaries. -local_repository( - name = "torch_tensorrt", - path = "/opt/conda/lib/python3.8/site-packages/torch_tensorrt", +new_local_repository( +name = "cuda", +build_file = "@//third_party/cuda:BUILD", +path = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8", ) -# CUDA should be installed on the system locally new_local_repository( - name = "cuda", - build_file = "@//third_party/cuda:BUILD", - path = "/usr/local/cuda-12.1/", +name = "cublas", +build_file = "@//third_party/cublas:BUILD", +path = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8", ) -############################################################################################################# -# Tarballs and fetched dependencies (default - use in cases when building from precompiled bin and tarballs) -############################################################################################################# - -http_archive( - name = "libtorch", - build_file = "@//third_party/libtorch:BUILD", - strip_prefix = "libtorch", - urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-cxx11-abi-shared-with-deps-latest.zip"], +new_local_repository( +name = "libtorch", +path = "C:/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch", +build_file = "third_party/libtorch/BUILD" ) -http_archive( - name = "libtorch_pre_cxx11_abi", - build_file = "@//third_party/libtorch:BUILD", - strip_prefix = "libtorch", - urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-shared-with-deps-latest.zip"], +new_local_repository( +name = "libtorch_pre_cxx11_abi", +path = "C:/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch", +build_file = "third_party/libtorch/BUILD" ) -# Download these tarballs manually from the NVIDIA website -# Either place them in the distdir directory in third_party and use the --distdir flag -# or modify the urls to "file:////.tar.gz - -http_archive( - name = "cudnn", - build_file = "@//third_party/cudnn/archive:BUILD", - sha256 = "79d77a769c7e7175abc7b5c2ed5c494148c0618a864138722c887f95c623777c", - strip_prefix = "cudnn-linux-x86_64-8.8.1.3_cuda12-archive", - urls = [ - "https://developer.nvidia.com/downloads/compute/cudnn/secure/8.8.1/local_installers/12.0/cudnn-linux-x86_64-8.8.1.3_cuda12-archive.tar.xz", - ], +new_local_repository( +name = "cudnn", +path = "C:/cudnn/cudnn-windows-x86_64-8.8.0.121_cuda11-archive/", +build_file = "@//third_party/cudnn/local:BUILD" ) -http_archive( - name = "tensorrt", - build_file = "@//third_party/tensorrt/archive:BUILD", - sha256 = "0f8157a5fc5329943b338b893591373350afa90ca81239cdadd7580cd1eba254", - strip_prefix = "TensorRT-8.6.1.6", - urls = [ - "https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/secure/8.6.1/tars/TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz", - ], +new_local_repository( +name = "tensorrt", +path = "C:/TensorRT-8.6.1.6.Windows10.x86_64.cuda-11.8/TensorRT-8.6.1.6", +build_file = "@//third_party/tensorrt/local:BUILD" ) -#################################################################################### -# Locally installed dependencies (use in cases of custom dependencies or aarch64) -#################################################################################### - -# NOTE: In the case you are using just the pre-cxx11-abi path or just the cxx11 abi path -# with your local libtorch, just point deps at the same path to satisfy bazel. - -# NOTE: NVIDIA's aarch64 PyTorch (python) wheel file uses the CXX11 ABI unlike PyTorch's standard -# x86_64 python distribution. If using NVIDIA's version just point to the root of the package -# for both versions here and do not use --config=pre-cxx11-abi - -#new_local_repository( -# name = "libtorch", -# path = "/usr/local/lib/python3.6/dist-packages/torch", -# build_file = "third_party/libtorch/BUILD" -#) - -#new_local_repository( -# name = "libtorch_pre_cxx11_abi", -# path = "/usr/local/lib/python3.6/dist-packages/torch", -# build_file = "third_party/libtorch/BUILD" -#) - -#new_local_repository( -# name = "cudnn", -# path = "/usr/", -# build_file = "@//third_party/cudnn/local:BUILD" -#) - -#new_local_repository( -# name = "tensorrt", -# path = "/usr/", -# build_file = "@//third_party/tensorrt/local:BUILD" -#) - ######################################################################### + # Development Dependencies (optional - comment out on aarch64) ######################################################################### @@ -136,4 +83,4 @@ pip_parse( load("@devtools_deps//:requirements.bzl", "install_deps") -install_deps() +install_deps() \ No newline at end of file diff --git a/WORKSPACEOLD b/WORKSPACEOLD new file mode 100644 index 00000000..b24384df --- /dev/null +++ b/WORKSPACEOLD @@ -0,0 +1,139 @@ +workspace(name = "Torch-TensorRT") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_python", + sha256 = "863ba0fa944319f7e3d695711427d9ad80ba92c6edd0b7c7443b84e904689539", + strip_prefix = "rules_python-0.22.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.22.0/rules_python-0.22.0.tar.gz", +) + +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + +http_archive( + name = "rules_pkg", + sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", + "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", + ], +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +rules_pkg_dependencies() + +http_archive( + name = "googletest", + sha256 = "755f9a39bc7205f5a0c428e920ddad092c33c8a1b46997def3f1d4a82aded6e1", + strip_prefix = "googletest-5ab508a01f9eb089207ee87fd547d290da39d015", + urls = ["https://github.com/google/googletest/archive/5ab508a01f9eb089207ee87fd547d290da39d015.zip"], +) + +# External dependency for torch_tensorrt if you already have precompiled binaries. +local_repository( + name = "torch_tensorrt", + path = "/opt/conda/lib/python3.8/site-packages/torch_tensorrt", +) + +# CUDA should be installed on the system locally +new_local_repository( + name = "cuda", + build_file = "@//third_party/cuda:BUILD", + path = "/usr/local/cuda-12.1/", +) + +############################################################################################################# +# Tarballs and fetched dependencies (default - use in cases when building from precompiled bin and tarballs) +############################################################################################################# + +http_archive( + name = "libtorch", + build_file = "@//third_party/libtorch:BUILD", + strip_prefix = "libtorch", + urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-cxx11-abi-shared-with-deps-latest.zip"], +) + +http_archive( + name = "libtorch_pre_cxx11_abi", + build_file = "@//third_party/libtorch:BUILD", + strip_prefix = "libtorch", + urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-shared-with-deps-latest.zip"], +) + +# Download these tarballs manually from the NVIDIA website +# Either place them in the distdir directory in third_party and use the --distdir flag +# or modify the urls to "file:////.tar.gz + +http_archive( + name = "cudnn", + build_file = "@//third_party/cudnn/archive:BUILD", + sha256 = "79d77a769c7e7175abc7b5c2ed5c494148c0618a864138722c887f95c623777c", + strip_prefix = "cudnn-linux-x86_64-8.8.1.3_cuda12-archive", + urls = [ + "https://developer.nvidia.com/downloads/compute/cudnn/secure/8.8.1/local_installers/12.0/cudnn-linux-x86_64-8.8.1.3_cuda12-archive.tar.xz", + ], +) + +http_archive( + name = "tensorrt", + build_file = "@//third_party/tensorrt/archive:BUILD", + sha256 = "0f8157a5fc5329943b338b893591373350afa90ca81239cdadd7580cd1eba254", + strip_prefix = "TensorRT-8.6.1.6", + urls = [ + "https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/secure/8.6.1/tars/TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz", + ], +) + +#################################################################################### +# Locally installed dependencies (use in cases of custom dependencies or aarch64) +#################################################################################### + +# NOTE: In the case you are using just the pre-cxx11-abi path or just the cxx11 abi path +# with your local libtorch, just point deps at the same path to satisfy bazel. + +# NOTE: NVIDIA's aarch64 PyTorch (python) wheel file uses the CXX11 ABI unlike PyTorch's standard +# x86_64 python distribution. If using NVIDIA's version just point to the root of the package +# for both versions here and do not use --config=pre-cxx11-abi + +#new_local_repository( +# name = "libtorch", +# path = "/usr/local/lib/python3.6/dist-packages/torch", +# build_file = "third_party/libtorch/BUILD" +#) + +#new_local_repository( +# name = "libtorch_pre_cxx11_abi", +# path = "/usr/local/lib/python3.6/dist-packages/torch", +# build_file = "third_party/libtorch/BUILD" +#) + +#new_local_repository( +# name = "cudnn", +# path = "/usr/", +# build_file = "@//third_party/cudnn/local:BUILD" +#) + +#new_local_repository( +# name = "tensorrt", +# path = "/usr/", +# build_file = "@//third_party/tensorrt/local:BUILD" +#) + +######################################################################### +# Development Dependencies (optional - comment out on aarch64) +######################################################################### + +load("@rules_python//python:pip.bzl", "pip_parse") + +pip_parse( + name = "devtools_deps", + requirements = "//:requirements-dev.txt", +) + +load("@devtools_deps//:requirements.bzl", "install_deps") + +install_deps() diff --git a/core/conversion/converters/impl/activation.cpp b/core/conversion/converters/impl/activation.cpp index 95be9b67..eb106c8a 100644 --- a/core/conversion/converters/impl/activation.cpp +++ b/core/conversion/converters/impl/activation.cpp @@ -91,7 +91,7 @@ auto acthardtanh TORCHTRT_UNUSED = // Out_tensor of ParametricReLU shape is all 0, when slopes nDims is not equal to in nDims. // Since make sure splopes nDims is equal to in nDims. - if (slopes.ndimension() == 1 and original_shape.nbDims != slopes.ndimension()) { + if (slopes.ndimension() == 1 && original_shape.nbDims != slopes.ndimension()) { std::vector slopes_new_shape(original_shape.nbDims, 1); auto first_inputs_allowed_formats = ctx->net->getInput(0)->getAllowedFormats(); for (size_t inputs_index = 1; inputs_index < ctx->num_inputs; inputs_index++) { diff --git a/core/runtime/TRTEngine.h b/core/runtime/TRTEngine.h index 3f165ee0..cf7cb02a 100644 --- a/core/runtime/TRTEngine.h +++ b/core/runtime/TRTEngine.h @@ -1,4 +1,7 @@ #pragma once + +// Necessary for VS2017 to compile +#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include #include #include diff --git a/cpp/include/torch_tensorrt/macros.h b/cpp/include/torch_tensorrt/macros.h index 1eb8c6fe..8ef02c59 100644 --- a/cpp/include/torch_tensorrt/macros.h +++ b/cpp/include/torch_tensorrt/macros.h @@ -14,7 +14,7 @@ #define TORCHTRT_API __attribute__((__visibility__("default"))) #define TORCHTRT_HIDDEN __attribute__((__visibility__("hidden"))) #else -#define TORCHTRT_API +#define TORCHTRT_API __declspec(dllexport) #define TORCHTRT_HIDDEN #endif // defined(__GNUC__) #endif // defined(USE_CMAKE_GENERATED_EXPORT_HEADER) diff --git a/third_party/cudnn/local/BUILD b/third_party/cudnn/local/BUILD index d83ac2ec..c49addab 100644 --- a/third_party/cudnn/local/BUILD +++ b/third_party/cudnn/local/BUILD @@ -40,7 +40,7 @@ cc_import( shared_library = select({ ":aarch64_linux": "lib/aarch64-linux-gnu/libcudnn.so", ":ci_rhel_x86_64_linux": "lib64/libcudnn.so", - ":windows": "bin/cudnn64_7.dll", #Need to configure specific version for windows + ":windows": "bin/cudnn64_8.dll", #Need to configure specific version for windows "//conditions:default": "lib/x86_64-linux-gnu/libcudnn.so", }), visibility = ["//visibility:private"], diff --git a/third_party/tensorrt/local/BUILD b/third_party/tensorrt/local/BUILD index 9cbe98a4..03e661ce 100644 --- a/third_party/tensorrt/local/BUILD +++ b/third_party/tensorrt/local/BUILD @@ -339,7 +339,7 @@ cc_library( srcs = select({ ":aarch64_linux": ["lib/aarch64-linux-gnu/libnvinfer_plugin.so"], ":ci_rhel_x86_64_linux": ["lib64/libnvinfer_plugin.so"], - ":windows": ["lib/nvinfer_plugin.dll"], + ":windows": ["lib/nvinfer_plugin.lib", "lib/nvinfer_plugin.dll"], "//conditions:default": ["lib/x86_64-linux-gnu/libnvinfer_plugin.so"], }), hdrs = select({ @@ -367,6 +367,9 @@ cc_library( "nvinfer", "@cuda//:cudart", "@cudnn", - ], + ] + select({ + ":windows": ["@cuda//:cublas", "nvinfer_static_lib"], + "//conditions:default": ["@cuda//:cublas"], + }), alwayslink = True, ) -- 2.35.3.windows.1