Skip to content

Commit 4609dd1

Browse files
authored
refactor: Upgrade bazel and move to MODULE.bazel (#3012)
1 parent 3215712 commit 4609dd1

19 files changed

+315
-58
lines changed

.bazelrc

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
# +------------------------------------------------------------+
2121
# | Build Configurations |
2222
# +------------------------------------------------------------+
23-
# Enable colorful output of GCC
24-
build:default --cxxopt="-fdiagnostics-color=always"
25-
build:default --cxxopt='-std=c++17'
26-
#build:default --linkopt="-Wl,--no-as-needed"
23+
24+
common --enable_platform_specific_config
25+
26+
build:linux --cxxopt="-std=c++17"
27+
build:linux --cxxopt="-fdiagnostics-color=always"
2728

2829
build:windows --cxxopt="/GS-" --cxxopt="/std:c++17" --cxxopt="/permissive-"
2930
build:windows --cxxopt="/wd4244" --cxxopt="/wd4267" --cxxopt="/wd4819"

.bazelversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.3.2
1+
7.2.1

WORKSPACE renamed to MODULE.bazel

+23-43
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
1-
workspace(name = "Torch-TensorRT")
2-
3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4-
5-
http_archive(
6-
name = "rules_python",
7-
sha256 = "863ba0fa944319f7e3d695711427d9ad80ba92c6edd0b7c7443b84e904689539",
8-
strip_prefix = "rules_python-0.22.0",
9-
url = "https://github.com/bazelbuild/rules_python/releases/download/0.22.0/rules_python-0.22.0.tar.gz",
1+
module(
2+
name = "torch_tensorrt",
3+
version = "2.5.0a0",
4+
repo_name = "org_pytorch_tensorrt",
105
)
116

12-
load("@rules_python//python:repositories.bzl", "py_repositories")
13-
14-
py_repositories()
7+
bazel_dep(name = "googletest", version = "1.14.0")
8+
bazel_dep(name = "platforms", version = "0.0.10")
9+
bazel_dep(name = "rules_cc", version = "0.0.9")
10+
bazel_dep(name = "rules_python", version = "0.34.0")
1511

16-
http_archive(
17-
name = "rules_pkg",
18-
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
19-
urls = [
20-
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
21-
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
22-
],
12+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
13+
python.toolchain(
14+
ignore_root_user_error = True,
15+
python_version = "3.11",
2316
)
2417

25-
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
26-
27-
rules_pkg_dependencies()
28-
29-
http_archive(
30-
name = "googletest",
31-
sha256 = "755f9a39bc7205f5a0c428e920ddad092c33c8a1b46997def3f1d4a82aded6e1",
32-
strip_prefix = "googletest-5ab508a01f9eb089207ee87fd547d290da39d015",
33-
urls = ["https://github.com/google/googletest/archive/5ab508a01f9eb089207ee87fd547d290da39d015.zip"],
18+
bazel_dep(name = "rules_pkg", version = "1.0.1")
19+
git_override(
20+
module_name = "rules_pkg",
21+
commit = "17c57f4",
22+
remote = "https://github.com/narendasan/rules_pkg",
3423
)
3524

25+
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
26+
3627
# External dependency for torch_tensorrt if you already have precompiled binaries.
3728
local_repository(
3829
name = "torch_tensorrt",
3930
path = "/opt/conda/lib/python3.8/site-packages/torch_tensorrt",
4031
)
4132

33+
new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
34+
4235
# CUDA should be installed on the system locally
4336
new_local_repository(
4437
name = "cuda",
@@ -52,6 +45,8 @@ new_local_repository(
5245
path = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/",
5346
)
5447

48+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
49+
5550
#############################################################################################################
5651
# Tarballs and fetched dependencies (default - use in cases when building from precompiled bin and tarballs)
5752
#############################################################################################################
@@ -129,18 +124,3 @@ http_archive(
129124
# path = "/usr/",
130125
# build_file = "@//third_party/tensorrt/local:BUILD"
131126
#)
132-
133-
#########################################################################
134-
# Development Dependencies (optional - comment out on aarch64)
135-
#########################################################################
136-
137-
load("@rules_python//python:pip.bzl", "pip_parse")
138-
139-
pip_parse(
140-
name = "devtools_deps",
141-
requirements = "//:requirements-dev.txt",
142-
)
143-
144-
load("@devtools_deps//:requirements.bzl", "install_deps")
145-
146-
install_deps()

MODULE.bazel.lock

+127
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpp/include/torch_tensorrt/macros.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define STR(x) XSTR(x)
2525

2626
#define TORCH_TENSORRT_MAJOR_VERSION 2
27-
#define TORCH_TENSORRT_MINOR_VERSION 4
27+
#define TORCH_TENSORRT_MINOR_VERSION 5
2828
#define TORCH_TENSORRT_PATCH_VERSION 0
2929
#define TORCH_TENSORRT_VERSION \
3030
STR(TORCH_TENSORRT_MAJOR_VERSION) \

packaging/pre_build_script.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ wget https://github.com/bazelbuild/bazelisk/releases/download/v1.17.0/bazelisk-l
88
&& chmod +x /usr/bin/bazel
99

1010
export TORCH_BUILD_NUMBER=$(python -c "import torch, urllib.parse as ul; print(ul.quote_plus(torch.__version__))")
11+
export TORCH_INSTALL_PATH=$(python -c "import torch, os; print(os.path.dirname(torch.__file__))")
1112

12-
cat toolchains/ci_workspaces/WORKSPACE.x86_64.release.rhel.tmpl | envsubst > WORKSPACE
13+
cat toolchains/ci_workspaces/MODULE.bazel.tmpl | envsubst > MODULE.bazel
1314
export CI_BUILD=1

packaging/pre_build_script_windows.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ pip install tensorrt==${TRT_VERSION} tensorrt-${CU_VERSION::4}-bindings==${TRT_V
88

99
choco install bazelisk -y
1010

11-
curl -Lo TensorRT.zip https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.1.0/zip/TensorRT-10.1.0.27.Windows.win10.cuda-12.4.zip
12-
unzip -o TensorRT.zip -d C:/
11+
#curl -Lo TensorRT.zip https://developer.download.nvidia.com/compute/machine-learning/tensorrt/10.0.1/zip/TensorRT-10.0.1.6.Windows10.win10.cuda-12.4.zip
12+
#unzip -o TensorRT.zip -d C:/
1313

1414
export CUDA_HOME="$(echo ${CUDA_PATH} | sed -e 's#\\#\/#g')"
1515

16-
cat toolchains/ci_workspaces/WORKSPACE.win.release.tmpl | envsubst > WORKSPACE
16+
cat toolchains/ci_workspaces/MODULE.bazel.tmpl | envsubst > MODULE.bazel
1717

1818
echo "RELEASE=1" >> ${GITHUB_ENV}

py/torch_tensorrt/dynamo/_compiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,6 @@ def convert_module_to_trt_engine(
651651

652652
with io.BytesIO() as engine_bytes:
653653
engine_bytes.write(interpreter_result.engine)
654-
engine_bytearray = engine_bytes.getvalue()
654+
engine_bytearray: bytes = engine_bytes.getvalue()
655655

656656
return engine_bytearray

setup.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def build_libtorchtrt_pre_cxx11_abi(
202202
if IS_WINDOWS:
203203
cmd.append("--config=windows")
204204
else:
205-
cmd.append("--config=default")
205+
cmd.append("--config=linux")
206206

207207
if JETPACK_VERSION == "4.5":
208208
cmd.append("--platforms=//toolchains:jetpack_4.5")
@@ -482,6 +482,23 @@ def run(self):
482482
package_data = {}
483483

484484
if not (PY_ONLY or NO_TS):
485+
tensorrt_linux_external_dir = (
486+
lambda: subprocess.check_output(
487+
["bazel", "query", "@tensorrt//:nvinfer", "--output", "location"]
488+
)
489+
.decode("ascii")
490+
.strip()
491+
.split("/BUILD.bazel")[0]
492+
)
493+
tensorrt_windows_external_dir = (
494+
lambda: subprocess.check_output(
495+
["bazel", "query", "@tensorrt_win//:nvinfer", "--output", "location"]
496+
)
497+
.decode("ascii")
498+
.strip()
499+
.split("/BUILD.bazel")[0]
500+
)
501+
485502
ext_modules += [
486503
CUDAExtension(
487504
"torch_tensorrt._C",
@@ -513,13 +530,15 @@ def run(self):
513530
+ "/../bazel-Torch-TensorRT/external/tensorrt_win/include",
514531
dir_path + "/../bazel-TensorRT/external/tensorrt_win/include",
515532
dir_path + "/../bazel-tensorrt/external/tensorrt_win/include",
533+
f"{tensorrt_windows_external_dir()}/include",
516534
]
517535
if IS_WINDOWS
518536
else [
519537
dir_path + "/../bazel-TRTorch/external/tensorrt/include",
520538
dir_path + "/../bazel-Torch-TensorRT/external/tensorrt/include",
521539
dir_path + "/../bazel-TensorRT/external/tensorrt/include",
522540
dir_path + "/../bazel-tensorrt/external/tensorrt/include",
541+
f"{tensorrt_linux_external_dir()}/include",
523542
]
524543
)
525544
),

0 commit comments

Comments
 (0)