Skip to content

Commit c9e504d

Browse files
committed
chore: reorg in prep for state centralizing
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent d00240e commit c9e504d

18 files changed

+179
-88
lines changed

core/compiler.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ GraphAndMapping ConstructFallbackGraph(
227227
ir::StaticParams static_params,
228228
std::unordered_map<torch::jit::Node*, int>& fallback_nodes) {
229229
auto convert_cfg = cfg.convert_info;
230-
auto partition_info = cfg.partition_info;
230+
auto partitioning_info = cfg.partitioning_info;
231231

232232
auto new_g = std::make_shared<torch::jit::Graph>();
233233

234-
auto segmented_blocks = partitioning::Partition(block, example_tensor_map, partition_info, fallback_nodes);
234+
auto segmented_blocks = partitioning::Partition(block, example_tensor_map, partitioning_info, fallback_nodes);
235235

236236
// the mapping from lowering graph => fallback global graph
237237
std::unordered_map<torch::jit::Value*, torch::jit::Value*> old_to_new_g;
@@ -339,7 +339,7 @@ void MapInputsAndDetermineDTypes(
339339
"Cannot infer input type from calcuations in graph for input "
340340
<< in->debugName() << ". Assuming it is Float32. If not, specify input type explicity");
341341
spec[i].dtype = nvinfer1::DataType::kFLOAT;
342-
} else if (spec[i].dtype_is_user_defined && cfg.partition_info.enabled) {
342+
} else if (spec[i].dtype_is_user_defined && cfg.partitioning_info.enabled) {
343343
if (!est_type_opt[i]) {
344344
LOG_INFO("Cannot infer input tensor dtype in graph, compiler is going to use the user setting");
345345
std::stringstream ss;
@@ -424,15 +424,15 @@ torch::jit::Module CompileGraph(const torch::jit::Module& mod, CompileSpec cfg)
424424
MapInputsAndDetermineDTypes(cfg, g, static_params, first_use_types);
425425
auto isBlockConvertible = conversion::VerifyConverterSupportForBlock(g->block(), true);
426426
auto outputIsCollection = conversion::OutputIsCollection(g->block());
427-
if (cfg.partition_info.enabled &&
427+
if (cfg.partitioning_info.enabled &&
428428
(cfg.lower_info.forced_fallback_modules.size() == 0 &&
429-
cfg.partition_info.forced_fallback_operators.size() == 0 && isBlockConvertible)) {
429+
cfg.partitioning_info.forced_fallback_operators.size() == 0 && isBlockConvertible)) {
430430
LOG_INFO("Skipping partitioning since model is fully supported");
431431
}
432432

433-
if (cfg.partition_info.enabled &&
433+
if (cfg.partitioning_info.enabled &&
434434
(!(cfg.lower_info.forced_fallback_modules.size() == 0 &&
435-
cfg.partition_info.forced_fallback_operators.size() == 0 && isBlockConvertible) ||
435+
cfg.partitioning_info.forced_fallback_operators.size() == 0 && isBlockConvertible) ||
436436
outputIsCollection)) {
437437
std::unordered_map<torch::jit::Node*, int> fallback_nodes;
438438
auto collection_input_ivalues_map =

core/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct CompileSpec {
1919
ir::GraphInputs graph_inputs;
2020
conversion::ConversionInfo convert_info;
2121
lowering::LowerInfo lower_info;
22-
partitioning::PartitionInfo partition_info;
22+
partitioning::PartitioningInfo partitioning_info;
2323
};
2424

2525
bool CheckMethodOperatorSupport(const torch::jit::script::Module& mod, std::string method_name);

core/lowering/passes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ target_sources(${lib_name}
1717
"${CMAKE_CURRENT_SOURCE_DIR}/silu_to_sigmoid_multiplication.cpp"
1818
"${CMAKE_CURRENT_SOURCE_DIR}/unpack_addmm.cpp"
1919
"${CMAKE_CURRENT_SOURCE_DIR}/unpack_batch_norm.cpp"
20+
"${CMAKE_CURRENT_SOURCE_DIR}/unpack_hardsigmoid.cpp"
2021
"${CMAKE_CURRENT_SOURCE_DIR}/unpack_hardswish.cpp"
2122
"${CMAKE_CURRENT_SOURCE_DIR}/unpack_log_softmax.cpp"
2223
"${CMAKE_CURRENT_SOURCE_DIR}/unpack_std.cpp"

core/partitioning/BUILD

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ config_setting(
1313
cc_library(
1414
name = "partitioning",
1515
srcs = [
16-
"PartitionInfo.cpp",
17-
"SegmentedBlock.cpp",
1816
"partitioning.cpp",
1917
"shape_analysis.cpp",
2018
],
2119
hdrs = [
22-
"PartitionInfo.h",
23-
"SegmentedBlock.h",
2420
"partitioning.h",
25-
"shape_analysis.h",
2621
],
2722
deps = [
2823
"//core/util:prelude",
2924
"//core/ir",
3025
"//core/conversion",
3126
"//core/lowering",
27+
"//core/partitioning/partitioninginfo",
28+
"//core/partitioning/segmentedblock",
3229
] + select({
3330
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
3431
"//conditions:default": ["@libtorch//:libtorch"],
@@ -39,10 +36,7 @@ cc_library(
3936
pkg_tar(
4037
name = "include",
4138
srcs = [
42-
"PartitionInfo.h",
43-
"SegmentedBlock.h",
4439
"partitioning.h",
45-
"shape_analysis.h",
4640
],
4741
package_dir = "core/partitioning/",
4842
)

core/partitioning/CMakeLists.txt

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
set(lib_name "core_partitioning")
22
add_library(${lib_name} OBJECT)
33

4-
target_sources(${lib_name}
5-
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/SegmentedBlock.cpp"
6-
"${CMAKE_CURRENT_SOURCE_DIR}/shape_analysis.cpp"
7-
"${CMAKE_CURRENT_SOURCE_DIR}/partitioning.cpp"
8-
"${CMAKE_CURRENT_SOURCE_DIR}/PartitionInfo.cpp"
9-
$<TARGET_OBJECTS:core_conversion>
10-
PUBLIC $<TARGET_OBJECTS:core_ir>
11-
$<TARGET_OBJECTS:core_util>
4+
set(CXX_SRCS
5+
"${CMAKE_CURRENT_SOURCE_DIR}/partitioning.cpp"
6+
"${CMAKE_CURRENT_SOURCE_DIR}/shape_analysis.cpp"
127
)
138

149
set(HEADER_FILES
15-
"${CMAKE_CURRENT_SOURCE_DIR}/SegmentedBlock.h"
16-
"${CMAKE_CURRENT_SOURCE_DIR}/shape_analysis.h"
17-
"${CMAKE_CURRENT_SOURCE_DIR}/PartitionInfo.h"
1810
"${CMAKE_CURRENT_SOURCE_DIR}/partitioning.h"
1911
)
2012

21-
target_include_directories(${lib_name} PUBLIC "$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>")
13+
target_sources(${lib_name}
14+
PRIVATE
15+
${CXX_SRCS}
16+
PUBLIC
17+
$<TARGET_OBJECTS:core_conversion>
18+
$<TARGET_OBJECTS:core_ir>
19+
$<TARGET_OBJECTS:core_util>
20+
)
21+
2222
target_link_libraries(${lib_name}
2323
PUBLIC
24-
torch
2524
TensorRT::nvinfer
25+
torch
2626
core_ir
2727
core_util
28-
PRIVATE
2928
core_conversion
3029
)
3130

32-
# Install headers
33-
install(FILES ${HEADER_FILES} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/torch_tensorrt/core/partitioning/")
31+
target_include_directories(${lib_name}
32+
PUBLIC "$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
33+
)
34+
35+
add_subdirectory(partitioninginfo)
36+
add_subdirectory(segmentedblock)
37+
38+
install(FILES ${HEADER_FILES} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/torch_tensorrt/core/partitioning")

core/partitioning/partitioning.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#include "partitioning.h"
2-
31
#include <queue>
4-
#include "core/conversion/conversion.h"
5-
#include "core/conversion/evaluators/evaluators.h"
6-
#include "core/partitioning/shape_analysis.h"
2+
73
#include "torch/csrc/jit/passes/constant_pooling.h"
84
#include "torch/csrc/jit/passes/dead_code_elimination.h"
95

6+
#include "core/conversion/conversion.h"
7+
#include "core/conversion/evaluators/evaluators.h"
8+
#include "core/partitioning/partitioning.h"
9+
1010
namespace torch_tensorrt {
1111
namespace core {
1212
namespace partitioning {
@@ -357,11 +357,11 @@ void find_min_block_size_fallback_nodes(
357357

358358
PartitionedGraph segment_graph(
359359
torch::jit::Block* block,
360-
const PartitionInfo& partition_info,
360+
const PartitioningInfo& partitioning_info,
361361
std::unordered_map<torch::jit::Node*, int>& global_fallback_nodes) {
362-
auto min_block_size = partition_info.min_block_size;
362+
auto min_block_size = partitioning_info.min_block_size;
363363
std::unordered_set<std::string> forced_fallback_ops(
364-
partition_info.forced_fallback_operators.begin(), partition_info.forced_fallback_operators.end());
364+
partitioning_info.forced_fallback_operators.begin(), partitioning_info.forced_fallback_operators.end());
365365

366366
// get the initial fallback nodes (nodes that are unsupported or forced fallback)
367367
get_fallback_nodes(block, forced_fallback_ops, global_fallback_nodes);
@@ -450,16 +450,16 @@ PartitionedGraph segment_graph(
450450
PartitionedGraph Partition(
451451
torch::jit::Block* block,
452452
std::unordered_map<const torch::jit::Value*, torch::jit::IValue>& example_tensor_map,
453-
const PartitionInfo& partition_info,
453+
const PartitioningInfo& partitioning_info,
454454
std::unordered_map<torch::jit::Node*, int>& global_fallback_nodes) {
455-
LOG_DEBUG(partition_info);
455+
LOG_DEBUG(partitioning_info);
456456
// if there is nonTensor input/output for the entire graph, fallback the node that consumes/produces this nonTensor
457457
// output
458458
fallback_graph_nontensor_in_out(block, global_fallback_nodes);
459459

460460
// segment lowering global graph into blocks
461461
LOG_DEBUG("Parititioning source module into PyTorch and TensorRT sub blocks");
462-
PartitionedGraph segmented_blocks = segment_graph(block, partition_info, global_fallback_nodes);
462+
PartitionedGraph segmented_blocks = segment_graph(block, partitioning_info, global_fallback_nodes);
463463

464464
// It's possible that some TensorRT blocks have nonTensor inputs/output because they are interleaved by Torch blocks
465465

@@ -471,7 +471,7 @@ PartitionedGraph Partition(
471471
registerSegmentsOutputs(segmented_blocks, block);
472472

473473
// run shape analysis on each segmented block
474-
runShapeAnalysis(segmented_blocks, example_tensor_map, partition_info);
474+
runShapeAnalysis(segmented_blocks, example_tensor_map, partitioning_info);
475475

476476
for (uint64_t i = 0; i < segmented_blocks.size(); i++) {
477477
segmented_blocks[i].update_id(i);

core/partitioning/partitioning.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <iostream>
44
#include <vector>
55

6+
#include "torch/csrc/jit/ir/ir.h"
7+
68
#include "core/ir/ir.h"
7-
#include "core/partitioning/PartitionInfo.h"
8-
#include "core/partitioning/SegmentedBlock.h"
9-
#include "core/partitioning/shape_analysis.h"
9+
#include "core/partitioning/partitioninginfo/PartitioningInfo.h"
10+
#include "core/partitioning/segmentedblock/SegmentedBlock.h"
1011
#include "core/util/prelude.h"
11-
#include "torch/csrc/jit/ir/ir.h"
1212

1313
namespace torch_tensorrt {
1414
namespace core {
@@ -30,15 +30,24 @@ enum FallbackNodeType {
3030
kNON_TENSOR,
3131
};
3232

33+
std::unordered_map<const torch::jit::Value*, torch::jit::IValue> generateRandomInputs(
34+
std::unordered_map<const torch::jit::Value*, std::vector<ir::Input>>& input_ranges,
35+
std::unordered_map<const torch::jit::Value*, std::vector<c10::optional<at::ScalarType>>>& input_types);
36+
37+
void runShapeAnalysis(
38+
std::vector<SegmentedBlock>& segmented_blocks,
39+
std::unordered_map<const torch::jit::Value*, torch::jit::IValue>& ivalues_maps,
40+
const PartitioningInfo& partitioning_info);
41+
3342
PartitionedGraph segment_graph(
3443
torch::jit::Block* block,
35-
const PartitionInfo& partition_info,
44+
const PartitioningInfo& partitioning_info,
3645
std::unordered_map<torch::jit::Node*, int>& fallback_nodes);
3746

3847
PartitionedGraph Partition(
3948
torch::jit::Block* block,
4049
std::unordered_map<const torch::jit::Value*, torch::jit::IValue>& example_tensor_map,
41-
const PartitionInfo& partition_info,
50+
const PartitioningInfo& partitioning_info,
4251
std::unordered_map<torch::jit::Node*, int>& fallback_nodes);
4352

4453
std::ostream& operator<<(std::ostream& os, const PartitionedGraph& g);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
load("@rules_pkg//:pkg.bzl", "pkg_tar")
3+
4+
package(default_visibility = ["//visibility:public"])
5+
6+
config_setting(
7+
name = "use_pre_cxx11_abi",
8+
values = {
9+
"define": "abi=pre_cxx11_abi",
10+
},
11+
)
12+
13+
cc_library(
14+
name = "partitioninginfo",
15+
srcs = [
16+
"PartitioningInfo.cpp",
17+
],
18+
hdrs = [
19+
"PartitioningInfo.h",
20+
],
21+
deps = [
22+
"//core/util:prelude",
23+
"//core/ir",
24+
"//core/conversion",
25+
"//core/lowering",
26+
] + select({
27+
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
28+
"//conditions:default": ["@libtorch//:libtorch"],
29+
}),
30+
alwayslink = True,
31+
)
32+
33+
pkg_tar(
34+
name = "include",
35+
srcs = [
36+
"PartitioningInfo.h",
37+
],
38+
package_dir = "core/partitioning/partitioninginfo",
39+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(sub_lib_name "partitioninginfo")
2+
3+
target_sources(${lib_name}
4+
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/PartitioningInfo.cpp"
5+
)
6+
7+
set(HEADER_FILES
8+
"${CMAKE_CURRENT_SOURCE_DIR}/PartitioningInfo.h"
9+
)
10+
11+
# Install headers
12+
install(FILES ${HEADER_FILES} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/torch_tensorrt/core/partitioning/${sub_lib_name}")

core/partitioning/PartitionInfo.cpp renamed to core/partitioning/partitioninginfo/PartitioningInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#include <sstream>
33
#include <utility>
44

5-
#include "core/partitioning/PartitionInfo.h"
5+
#include "core/partitioning/partitioninginfo/PartitioningInfo.h"
66

77
namespace torch_tensorrt {
88
namespace core {
99
namespace partitioning {
1010
// clang-format off
11-
std::ostream& operator<<(std::ostream& os, const PartitionInfo& s) {
11+
std::ostream& operator<<(std::ostream& os, const PartitioningInfo& s) {
1212
os << "Settings requested for Torch Fallback:" \
1313
<< "\n \"enabled\": ";
1414
if (s.enabled) {

0 commit comments

Comments
 (0)