Skip to content

Commit 601ca12

Browse files
authored
Merge pull request #670 from NVIDIA/build_workspace
Include bin and headers to packaging and provide option to ensure tests can use precompiled trtorch libs
2 parents 04d7fa2 + 7d67da2 commit 601ca12

File tree

16 files changed

+156
-20
lines changed

16 files changed

+156
-20
lines changed

Diff for: BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pkg_tar(
6565
name = "libtrtorch",
6666
srcs = [
6767
"//:LICENSE",
68+
"//bzl_def:BUILD",
69+
"//bzl_def:WORKSPACE"
6870
],
6971
extension = "tar.gz",
7072
package_dir = "trtorch",

Diff for: WORKSPACE

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ git_repository(
3131
shallow_since = "1570114335 -0400",
3232
)
3333

34+
# External dependency for trtorch if you already have precompiled binaries.
35+
# This is currently used in pytorch NGC container CI testing.
36+
local_repository(
37+
name = "trtorch",
38+
path = "/opt/conda/lib/python3.8/site-packages/trtorch"
39+
)
40+
3441
# CUDA should be installed on the system locally
3542
new_local_repository(
3643
name = "cuda",

Diff for: bzl_def/BUILD

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
config_setting(
4+
name = "aarch64_linux",
5+
constraint_values = [
6+
"@platforms//cpu:aarch64",
7+
"@platforms//os:linux",
8+
],
9+
)
10+
11+
config_setting(
12+
name = "windows",
13+
constraint_values = [
14+
"@platforms//os:windows",
15+
],
16+
)
17+
18+
cc_library(
19+
name = "libtrtorch",
20+
srcs = select({
21+
":windows": [
22+
"lib/x64/trtorch.dll",
23+
],
24+
"//conditions:default": [
25+
"lib/libtrtorch.so",
26+
],
27+
}),
28+
hdrs = glob([
29+
"include/**/*.h",
30+
]),
31+
strip_include_prefix = "include",
32+
includes = ["include/"]
33+
)
34+
35+
cc_library(
36+
name = "libtrtorchrt",
37+
srcs = select({
38+
":windows": [
39+
"lib/x64/trtorchrt.dll"
40+
],
41+
"//conditions:default": [
42+
"lib/libtrtorchrt.so"
43+
]
44+
})
45+
)
46+
47+
cc_library(
48+
name = "libtrtorch_plugins",
49+
srcs = select({
50+
":windows": [
51+
"lib/x64/trtorch_plugins.dll"
52+
],
53+
"//conditions:default": [
54+
"lib/libtrtorch_plugins.so"
55+
]
56+
}),
57+
hdrs = glob([
58+
"include/trtorch/core/plugins/**/*.h",
59+
]),
60+
strip_include_prefix = "include",
61+
includes = ["include/"]
62+
)
63+
64+
cc_library(
65+
name = "trtorch_core_hdrs",
66+
hdrs = glob([
67+
"include/trtorch/core/**/*.h"
68+
]),
69+
strip_include_prefix = "include/trtorch",
70+
includes = ["include/trtorch/"]
71+
)
72+
73+
# Alias for ease of use
74+
cc_library(
75+
name = "trtorch",
76+
deps = [
77+
":libtrtorch",
78+
]
79+
)

Diff for: bzl_def/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
exports_files([
4+
"WORKSPACE",
5+
"BUILD"
6+
])

Diff for: bzl_def/WORKSPACE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workspace(name = "trtorch")

Diff for: py/setup.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def is_exe(fpath):
7272

7373
def build_libtrtorch_pre_cxx11_abi(develop=True, use_dist_dir=True, cxx11_abi=False):
7474
cmd = [BAZEL_EXE, "build"]
75-
cmd.append("//cpp/lib:libtrtorch.so")
75+
cmd.append("//:libtrtorch")
7676
if develop:
7777
cmd.append("--compilation_mode=dbg")
7878
else:
@@ -115,7 +115,7 @@ def copy_libtrtorch(multilinux=False):
115115
if multilinux:
116116
copyfile(dir_path + "/build/libtrtorch_build/libtrtorch.so", dir_path + '/trtorch/lib/libtrtorch.so')
117117
else:
118-
copyfile(dir_path + "/../bazel-bin/cpp/lib/libtrtorch.so", dir_path + '/trtorch/lib/libtrtorch.so')
118+
os.system("tar -xzf ../bazel-bin/libtrtorch.tar.gz --strip-components=2 -C " + dir_path + "/trtorch")
119119

120120

121121
class DevelopCommand(develop):
@@ -172,7 +172,8 @@ def run(self):
172172
class CleanCommand(Command):
173173
"""Custom clean command to tidy up the project root."""
174174
PY_CLEAN_FILES = [
175-
'./build', './dist', './trtorch/__pycache__', './trtorch/lib', './*.pyc', './*.tgz', './*.egg-info'
175+
'./build', './dist', './trtorch/__pycache__', './trtorch/lib', './trtorch/include', './trtorch/bin', './*.pyc',
176+
'./*.tgz', './*.egg-info'
176177
]
177178
description = "Command to tidy up the project root"
178179
user_options = []
@@ -258,9 +259,18 @@ def run(self):
258259
python_requires='>=3.6',
259260
include_package_data=True,
260261
package_data={
261-
'trtorch': ['lib/*.so'],
262+
'trtorch': [
263+
'lib/*', 'include/trtorch/*.h', 'include/trtorch/core/*.h', 'include/trtorch/core/conversion/*.h',
264+
'include/trtorch/core/conversion/conversionctx/*.h', 'include/trtorch/core/conversion/converters/*.h',
265+
'include/trtorch/core/conversion/evaluators/*.h', 'include/trtorch/core/conversion/tensorcontainer/*.h',
266+
'include/trtorch/core/conversion/var/*.h', 'include/trtorch/core/ir/*.h',
267+
'include/trtorch/core/lowering/*.h', 'include/trtorch/core/lowering/passes/*.h',
268+
'include/trtorch/core/partitioning/*.h', 'include/trtorch/core/plugins/*.h',
269+
'include/trtorch/core/plugins/impl/*.h', 'include/trtorch/core/runtime/*.h',
270+
'include/trtorch/core/util/*.h', 'include/trtorch/core/util/logging/*.h', 'bin/*', 'BUILD', 'WORKSPACE'
271+
],
262272
},
263273
exclude_package_data={
264-
'': ['*.cpp', '*.h'],
274+
'': ['*.cpp'],
265275
'trtorch': ['csrc/*.cpp'],
266276
})

Diff for: tests/BUILD

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
config_setting(
2+
name = "ci_build_testing",
3+
values = {
4+
"define": "trtorch_src=pre_built"
5+
}
6+
)
7+
18
test_suite(
29
name = "tests",
310
tests = [

Diff for: tests/README.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,37 @@ The goal of Converter tests are to tests individual converters againsts specific
66

77
Module tests are designed to test the compiler against common network architectures and verify the integration of converters together into a single engine.
88

9+
In addition to the above, we have lowering tests (`//core/lowering`) which test the functionality of lowering passes and partitioning tests (`//core/partitioning `) which test different cases of torch fallback on test networks.
10+
911
You can run the whole test suite with bazel. But be aware you may exhaust GPU memory (this may be seen as a cuDNN initialization error) running them naively, you therefore may need to limit the number of concurrent tests. Also because the inputs to tests are random it may make sense to run tests a few times.
1012

11-
Here are some settings that work well the current test suite on a TITAN V.
13+
Here are some settings that we usually test with:
1214

1315
```
1416
bazel test //tests --compilation_mode=dbg --test_output=errors --jobs=4 --runs_per_test=5
1517
```
18+
19+
`--runs_per_test` is optional and can be performed to check if numerical issues in outputs persist across multiple runs.
20+
21+
`--jobs=4` is useful and is sometimes required to prevent too many processes to use GPU memory and cause CUDA out of memory issues.
22+
23+
### Testing using pre-built TRTorch library
24+
25+
Currently, the default strategy when we run all the tests (`bazel test //tests`) is to build the testing scripts along with the full TRTorch library (`libtrtorch.so`) from scratch. This can lead to increased testing time and might not be needed incase you already have a pre-built TRTorch library that you want to link against.
26+
27+
In order to **not** build the entire TRTorch library and only build the test scripts, please use the following command.
28+
29+
```
30+
bazel test //tests --compilation_mode=dbg --test_output=summary --define trtorch_src=pre_built --jobs 2
31+
```
32+
33+
The flag `--define trtorch_src=pre_built` signals bazel to use pre-compiled library as an external dependency for tests. The pre-compiled library path is defined as a `local_repository` rule in root `WORKSPACE` file (`https://github.com/NVIDIA/TRTorch/blob/master/WORKSPACE`).
34+
35+
```
36+
# External dependency for trtorch if you already have precompiled binaries.
37+
# This is currently used in pytorch NGC container CI testing.
38+
local_repository(
39+
name = "trtorch",
40+
path = "/opt/pytorch/trtorch"
41+
)
42+
```

Diff for: tests/core/conversion/converters/converter_test.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ def converter_test(name, visibility = None):
55
visibility = visibility,
66
deps = [
77
"//tests/util",
8-
"//core",
98
"@googletest//:gtest_main",
109
] + select({
1110
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],

Diff for: tests/core/conversion/evaluators/evaluator_test.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ def evaluator_test(name, visibility = None):
55
visibility = visibility,
66
deps = [
77
"//tests/util",
8-
"//core",
98
"@googletest//:gtest_main",
109
] + select({
1110
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],

Diff for: tests/core/lowering/BUILD

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ cc_test(
1616
srcs = ["test_module_fallback_passes.cpp"],
1717
deps = [
1818
"//tests/util",
19-
"//core",
2019
"@googletest//:gtest_main",
2120
] + select({
2221
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],

Diff for: tests/core/lowering/lowering_test.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ def lowering_test(name, visibility = None):
55
visibility = visibility,
66
deps = [
77
"//tests/util",
8-
"//core",
98
"@googletest//:gtest_main",
109
] + select({
1110
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],

Diff for: tests/core/partitioning/BUILD

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ cc_test(
3737
srcs = ["test_fallback_graph_output.cpp"],
3838
deps = [
3939
"//tests/util",
40-
"//core",
4140
"@googletest//:gtest_main",
4241
] + select({
4342
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
@@ -69,7 +68,6 @@ cc_test(
6968
srcs = ["test_conditionals.cpp"],
7069
deps = [
7170
"//tests/util",
72-
"//core",
7371
"@googletest//:gtest_main",
7472
] + select({
7573
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
@@ -91,4 +89,4 @@ test_suite(
9189
":test_loop_fallback",
9290
":test_conditionals"
9391
]
94-
)
92+
)

Diff for: tests/core/partitioning/partitioning_test.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ def partitioning_test(name, visibility=None):
55
visibility = visibility,
66
deps = [
77
"//tests/util",
8-
"//core",
98
"@googletest//:gtest_main",
109
] + select({
1110
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],

Diff for: tests/cpp/BUILD

-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ cc_test(
7676
"//tests/modules:jit_models",
7777
],
7878
deps = [
79-
"//cpp:trtorch",
8079
"//tests/util",
8180
"@googletest//:gtest_main",
8281
] + select({
@@ -115,7 +114,6 @@ cc_test(
115114
"//tests/modules:jit_models",
116115
],
117116
deps = [
118-
"//cpp:trtorch",
119117
"//tests/util",
120118
"@googletest//:gtest_main",
121119
] + select({
@@ -150,7 +148,6 @@ cc_library(
150148
name = "cpp_api_test",
151149
hdrs = ["cpp_api_test.h"],
152150
deps = [
153-
"//cpp:trtorch",
154151
"//tests/util",
155152
"@googletest//:gtest_main",
156153
] + select({

Diff for: tests/util/BUILD

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ cc_library(
2020
"util.h",
2121
],
2222
deps = [
23-
"//core/conversion",
24-
"//core/util:prelude",
25-
"//cpp:trtorch",
2623
"@tensorrt//:nvinfer",
2724
] + select({
2825
":use_pre_cxx11_abi": [
@@ -33,5 +30,15 @@ cc_library(
3330
"@libtorch//:libtorch",
3431
"@libtorch//:caffe2",
3532
],
33+
}) + select({
34+
"//tests:ci_build_testing": [
35+
"@trtorch//:trtorch",
36+
"@trtorch//:trtorch_core_hdrs"
37+
],
38+
"//conditions:default": [
39+
"//cpp:trtorch",
40+
"//core/conversion",
41+
"//core/util:prelude"
42+
]
3643
}),
3744
)

0 commit comments

Comments
 (0)