Skip to content

Commit 8992a1a

Browse files
committed
merge: merge and resolve the conficts from fallback branch
Signed-off-by: Bo Wang <[email protected]>
2 parents d00627f + ff89059 commit 8992a1a

File tree

66 files changed

+1174
-1039
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1174
-1039
lines changed

BUILD

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,28 @@ pkg_tar(
1515
"//core/conversion:include",
1616
"//core/conversion/conversionctx:include",
1717
"//core/conversion/converters:include",
18-
"//core/conversion/var:include",
19-
"//core/conversion/tensorcontainer:include",
20-
"//core/conversion/evaluators:include",
2118
"//core/conversion/converters/impl/plugins:include",
22-
"//core/runtime:include",
19+
"//core/conversion/evaluators:include",
20+
"//core/conversion/tensorcontainer:include",
21+
"//core/conversion/var:include",
2322
"//core/lowering:include",
2423
"//core/lowering/passes:include",
24+
"//core/runtime:include",
2525
"//core/util:include",
26-
"//core/util/logging:include"
26+
"//core/util/logging:include",
2727
],
2828
)
2929

3030
pkg_tar(
3131
name = "include",
32-
package_dir = "include/trtorch/",
3332
srcs = [
3433
"//cpp/api:api_headers",
3534
],
35+
package_dir = "include/trtorch/",
3636
)
3737

3838
pkg_tar(
3939
name = "lib",
40-
package_dir = "lib/",
4140
srcs = select({
4241
":windows": ["//cpp/api/lib:trtorch.dll"],
4342
"//conditions:default": [
@@ -46,26 +45,25 @@ pkg_tar(
4645
],
4746
}),
4847
mode = "0755",
48+
package_dir = "lib/",
4949
)
5050

51-
5251
pkg_tar(
5352
name = "bin",
54-
package_dir = "bin/",
5553
srcs = [
56-
"//cpp/trtorchc:trtorchc",
54+
"//cpp/trtorchc",
5755
],
5856
mode = "0755",
57+
package_dir = "bin/",
5958
)
6059

61-
6260
pkg_tar(
6361
name = "libtrtorch",
64-
extension = "tar.gz",
65-
package_dir = "trtorch",
6662
srcs = [
67-
"//:LICENSE"
63+
"//:LICENSE",
6864
],
65+
extension = "tar.gz",
66+
package_dir = "trtorch",
6967
deps = [
7068
":lib",
7169
":include",

WORKSPACE

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,38 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
55

66
http_archive(
7-
name = "rules_python",
8-
url = "https://github.com/bazelbuild/rules_python/releases/download/0.2.0/rules_python-0.2.0.tar.gz",
9-
sha256 = "778197e26c5fbeb07ac2a2c5ae405b30f6cb7ad1f5510ea6fdac03bded96cc6f",
10-
)
7+
name = "rules_python",
8+
sha256 = "778197e26c5fbeb07ac2a2c5ae405b30f6cb7ad1f5510ea6fdac03bded96cc6f",
9+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.2.0/rules_python-0.2.0.tar.gz",
10+
)
1111

1212
load("@rules_python//python:pip.bzl", "pip_install")
1313

1414
http_archive(
1515
name = "rules_pkg",
16+
sha256 = "038f1caa773a7e35b3663865ffb003169c6a71dc995e39bf4815792f385d837d",
1617
urls = [
17-
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
18-
"https://github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
18+
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
19+
"https://github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
1920
],
20-
sha256 = "038f1caa773a7e35b3663865ffb003169c6a71dc995e39bf4815792f385d837d",
2121
)
2222

2323
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
24+
2425
rules_pkg_dependencies()
2526

2627
git_repository(
2728
name = "googletest",
28-
remote = "https://github.com/google/googletest",
2929
commit = "703bd9caab50b139428cea1aaff9974ebee5742e",
30-
shallow_since = "1570114335 -0400"
30+
remote = "https://github.com/google/googletest",
31+
shallow_since = "1570114335 -0400",
3132
)
3233

3334
# CUDA should be installed on the system locally
3435
new_local_repository(
3536
name = "cuda",
36-
path = "/usr/local/cuda-11.1/",
3737
build_file = "@//third_party/cuda:BUILD",
38+
path = "/usr/local/cuda-11.1/",
3839
)
3940

4041
#############################################################################################################
@@ -44,16 +45,16 @@ new_local_repository(
4445
http_archive(
4546
name = "libtorch",
4647
build_file = "@//third_party/libtorch:BUILD",
47-
strip_prefix = "libtorch",
4848
sha256 = "1f8aec376f9343538bd7c2fd3abb81ed3af11f575efe3aa72777c4d62044b832",
49+
strip_prefix = "libtorch",
4950
urls = ["https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-1.8.1%2Bcu111.zip"],
5051
)
5152

5253
http_archive(
5354
name = "libtorch_pre_cxx11_abi",
5455
build_file = "@//third_party/libtorch:BUILD",
55-
strip_prefix = "libtorch",
5656
sha256 = "3a6e0dc11859111e75caa640c8ce9bf904fbb6e9992b4345e444ed5410e4d77e",
57+
strip_prefix = "libtorch",
5758
urls = ["https://download.pytorch.org/libtorch/cu111/libtorch-shared-with-deps-1.8.1%2Bcu111.zip"],
5859
)
5960

@@ -63,22 +64,22 @@ http_archive(
6364

6465
http_archive(
6566
name = "cudnn",
67+
build_file = "@//third_party/cudnn/archive:BUILD",
68+
sha256 = "98a8784e92862f20018d20c281b30d4a0cd951f93694f6433ccf4ae9c502ba6a",
69+
strip_prefix = "cuda",
6670
urls = [
6771
"https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.1.1.33/11.2_20210301/cudnn-11.2-linux-x64-v8.1.1.33.tgz",
6872
],
69-
build_file = "@//third_party/cudnn/archive:BUILD",
70-
sha256 = "98a8784e92862f20018d20c281b30d4a0cd951f93694f6433ccf4ae9c502ba6a",
71-
strip_prefix = "cuda"
7273
)
7374

7475
http_archive(
7576
name = "tensorrt",
77+
build_file = "@//third_party/tensorrt/archive:BUILD",
78+
sha256 = "d3a1f478e304b48878604fac70ce7920fece71f9cac62f925c9c59c197f5d087",
79+
strip_prefix = "TensorRT-7.2.3.4",
7680
urls = [
7781
"https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.2.3/tars/TensorRT-7.2.3.4.Ubuntu-18.04.x86_64-gnu.cuda-11.1.cudnn8.1.tar.gz",
7882
],
79-
build_file = "@//third_party/tensorrt/archive:BUILD",
80-
strip_prefix = "TensorRT-7.2.3.4",
81-
sha256 = "d3a1f478e304b48878604fac70ce7920fece71f9cac62f925c9c59c197f5d087"
8283
)
8384

8485
####################################################################################

core/BUILD

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@ config_setting(
44
name = "use_pre_cxx11_abi",
55
values = {
66
"define": "abi=pre_cxx11_abi",
7-
}
7+
},
88
)
99

1010
config_setting(
1111
name = "python_core",
1212
values = {
13-
"define": "target_lang=python"
14-
}
13+
"define": "target_lang=python",
14+
},
1515
)
1616

1717
cc_library(
1818
name = "core",
19-
hdrs = [
20-
"compiler.h",
21-
],
2219
srcs = [
2320
"compiler.cpp",
2421
],
22+
hdrs = [
23+
"compiler.h",
24+
],
2525
deps = [
2626
"//core/conversion",
2727
"//core/runtime",
2828
"//core/lowering",
2929
"//core/partitioning",
3030
"//core/util/logging",
31-
"@tensorrt//:nvinfer"
31+
"@tensorrt//:nvinfer",
3232
] + select({
33-
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
34-
"//conditions:default": ["@libtorch//:libtorch"],
33+
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
34+
"//conditions:default": ["@libtorch//:libtorch"],
3535
}),
36-
alwayslink=True,
36+
alwayslink = True,
3737
)
3838

3939
load("@rules_pkg//:pkg.bzl", "pkg_tar")
4040

4141
pkg_tar(
4242
name = "include",
43-
package_dir = "core/",
4443
srcs = [
4544
"compiler.h",
4645
],
46+
package_dir = "core/",
4747
)

core/compiler.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "torch/csrc/jit/ir/ir.h"
1414
#include "torch/csrc/jit/ir/ir_views.h"
1515
#include "torch/csrc/jit/passes/graph_fuser.h"
16+
#include "torch/csrc/jit/passes/loop_unrolling.h"
1617
#include "torch/csrc/jit/passes/lower_graph.h"
1718
#include "torch/csrc/jit/passes/pass_manager.h"
1819
#include "torch/custom_class.h"
@@ -31,10 +32,9 @@ void AddEngineToGraph(
3132
torch::jit::script::Module mod,
3233
std::shared_ptr<torch::jit::Graph>& g,
3334
const std::string& serialized_engine,
34-
int engine_id = 0,
35+
std::string engine_id = "",
3536
bool fallback = false) {
36-
auto engine_ptr =
37-
c10::make_intrusive<runtime::TRTEngine>(mod._ivalue()->name() + std::to_string(engine_id), serialized_engine);
37+
auto engine_ptr = c10::make_intrusive<runtime::TRTEngine>(mod._ivalue()->name() + engine_id, serialized_engine);
3838
// Get required metadata about the engine out
3939
auto num_io = engine_ptr->num_io;
4040
auto name = engine_ptr->name;
@@ -237,7 +237,6 @@ GraphAndMapping ConstructFallbackGraph(
237237
torch::jit::Block* block,
238238
std::unordered_map<torch::jit::Value*, torch::jit::IValue> input_ivalues_map,
239239
CompileSpec cfg,
240-
int& trt_engine_id,
241240
conversion::GraphParams named_params) {
242241
auto convert_cfg = cfg.convert_info;
243242
auto partition_info = cfg.partition_info;
@@ -254,6 +253,8 @@ GraphAndMapping ConstructFallbackGraph(
254253

255254
for (auto& seg_block : segmented_blocks) {
256255
LOG_INFO(*seg_block.g() << "(GraphInSegmentedBlock)\n");
256+
std::ostringstream trt_engine_id;
257+
trt_engine_id << reinterpret_cast<const int*>(&seg_block);
257258

258259
if (seg_block.target() == partitioning::SegmentedBlock::kTensorRT) {
259260
std::vector<ir::InputRange> input_ranges;
@@ -264,7 +265,7 @@ GraphAndMapping ConstructFallbackGraph(
264265
convert_cfg.input_ranges = input_ranges;
265266
auto engine = conversion::ConvertBlockToEngine(seg_block.block(), convert_cfg, named_params);
266267
auto temp_g = std::make_shared<torch::jit::Graph>();
267-
AddEngineToGraph(new_mod, temp_g, engine, trt_engine_id++, true);
268+
AddEngineToGraph(new_mod, temp_g, engine, trt_engine_id.str(), true);
268269

269270
seg_block.update_graph(temp_g);
270271
AddSegmentedBlockToGraph(new_g, seg_block, old_to_new_g);
@@ -276,7 +277,7 @@ GraphAndMapping ConstructFallbackGraph(
276277
std::vector<GraphAndMapping> graph_and_mappings;
277278
for (auto cur_block : if_node->blocks()) {
278279
graph_and_mappings.push_back(
279-
ConstructFallbackGraph(new_mod, cur_block, input_ivalues_map, cfg, trt_engine_id, named_params));
280+
ConstructFallbackGraph(new_mod, cur_block, input_ivalues_map, cfg, named_params));
280281
}
281282
AddIfBlockToGraph(new_g, if_node, graph_and_mappings, old_to_new_g);
282283

@@ -311,14 +312,13 @@ torch::jit::script::Module CompileGraphWithFallback(const torch::jit::script::Mo
311312
auto named_params = conversion::get_named_params(g->inputs(), params);
312313
LOG_INFO(*g << "(LoweringGraph)\n");
313314

314-
int trt_engine_id = 0;
315315
std::unordered_map<torch::jit::Value*, ir::InputRange> input_ranges;
316316
for (size_t i = 0; i < g->inputs().size(); ++i) {
317317
input_ranges.insert({g->inputs()[i], cfg.convert_info.input_ranges[i]});
318318
}
319319
auto input_ivalues_map = partitioning::generateRandomInputs(input_ranges);
320320
auto graph_and_mapping =
321-
ConstructFallbackGraph(new_mod, g->block(), input_ivalues_map, cfg, trt_engine_id, named_params);
321+
ConstructFallbackGraph(new_mod, g->block(), input_ivalues_map, cfg, named_params);
322322
new_g = graph_and_mapping.first;
323323
LOG_INFO(*new_g << "(FallbackGraph)\n");
324324

core/conversion/BUILD

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@ config_setting(
44
name = "use_pre_cxx11_abi",
55
values = {
66
"define": "abi=pre_cxx11_abi",
7-
}
7+
},
88
)
99

1010
cc_library(
1111
name = "conversion",
12-
hdrs = [
13-
"conversion.h",
14-
],
1512
srcs = [
13+
"InterfaceTypes.cpp",
1614
"conversion.cpp",
1715
"conversion_ignorelist.cpp",
18-
"InterfaceTypes.cpp"
16+
],
17+
hdrs = [
18+
"conversion.h",
1919
],
2020
deps = [
2121
"@tensorrt//:nvinfer",
2222
"//core/conversion/var",
2323
"//core/conversion/conversionctx",
2424
"//core/conversion/converters",
2525
"//core/conversion/evaluators",
26-
"//core/util:prelude",
2726
"//core/ir",
27+
"//core/util:prelude",
2828
] + select({
29-
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
30-
"//conditions:default": ["@libtorch//:libtorch"],
29+
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
30+
"//conditions:default": ["@libtorch//:libtorch"],
3131
}),
3232
)
3333

3434
load("@rules_pkg//:pkg.bzl", "pkg_tar")
3535

3636
pkg_tar(
3737
name = "include",
38-
package_dir = "core/conversion/",
3938
srcs = ["conversion.h"],
39+
package_dir = "core/conversion/",
4040
)

core/conversion/conversionctx/BUILD

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ config_setting(
44
name = "use_pre_cxx11_abi",
55
values = {
66
"define": "abi=pre_cxx11_abi",
7-
}
7+
},
88
)
99

1010
cc_library(
1111
name = "conversionctx",
12-
hdrs = [
13-
"ConversionCtx.h",
14-
],
1512
srcs = [
1613
"ConversionCtx.cpp",
1714
],
15+
hdrs = [
16+
"ConversionCtx.h",
17+
],
1818
deps = [
1919
"@tensorrt//:nvinfer",
2020
"//core/util:prelude",
2121
] + select({
22-
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
23-
"//conditions:default": ["@libtorch//:libtorch"],
22+
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
23+
"//conditions:default": ["@libtorch//:libtorch"],
2424
}),
2525
)
2626

2727
load("@rules_pkg//:pkg.bzl", "pkg_tar")
2828

2929
pkg_tar(
3030
name = "include",
31-
package_dir = "core/conversion/conversionctx/",
3231
srcs = ["ConversionCtx.h"],
32+
package_dir = "core/conversion/conversionctx/",
3333
)

0 commit comments

Comments
 (0)