Skip to content

Commit 49bafc0

Browse files
committed
fix comments and set name for trt layer and ITensor
1 parent df161e0 commit 49bafc0

File tree

9 files changed

+31
-16
lines changed

9 files changed

+31
-16
lines changed

paddle/fluid/inference/analysis/subgraph_splitter.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ struct BriefNode {
8585
std::vector<BriefNode *> outlinks;
8686
};
8787

88+
// Union two adjacent BriefNode.
89+
// Suppose we have two adjacent nodes src and dst.
90+
// We will perform the following operations:
91+
// 1. add all inputs(except src) of dst to src inlinks.
92+
// 2. add all outputs of dst to src outlinks.
93+
// 3. change all the dst's inputs and outputs
94+
// corresponding inlinks and outlinks to src node.
95+
// 4. delete all dst's inlinks and outlinks.
8896
void UnionContractedNodes(const std::unordered_map<int, BriefNode *> &node_map,
8997
int src_id, int dst_id) {
9098
// merge the two adjacent nodes into one node.
@@ -224,8 +232,8 @@ std::vector<std::vector<Node *>> SubGraphSplitter::ExtractSubGraphs() {
224232
// Our algorithm must guarantee that:
225233
// 1. The graph is always directed acyclic graph(DAG).
226234
// 2. If there is a path in the subgraph from X to Y (X and Y are both
227-
// nodes
228-
// in the subgraph), then all paths from X to Y are in the subgraph.
235+
// nodes in the subgraph), then all paths from X to Y are in the
236+
// subgraph.
229237
//
230238
// In order to achieve the above guarantee.
231239
// For adjacent nodes src -> dst.

paddle/fluid/inference/tensorrt/convert/activation_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class ReluOpConverter : public OpConverter {
3535
engine_, Activation, *const_cast<nvinfer1::ITensor*>(input_tensor),
3636
nvinfer1::ActivationType::kRELU);
3737
auto output_name = op_desc.Output("Out")[0];
38+
layer->setName(("relu (Output: " + output_name + ")").c_str());
39+
layer->getOutput(0)->setName(output_name.c_str());
3840
engine_->SetITensor(output_name, layer->getOutput(0));
3941
if (test_mode) { // the test framework can not determine which is the
4042
// output, so place the declaration inside.

paddle/fluid/inference/tensorrt/convert/batch_norm_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ class BatchNormOpConverter : public OpConverter {
116116
scale_weights.get(), power_weights.get());
117117

118118
auto output_name = op_desc.Output("Y").front();
119+
layer->setName(("batch_norm (Output: " + output_name + ")").c_str());
120+
layer->getOutput(0)->setName(output_name.c_str());
119121
engine_->weight_map[op_desc.Input("Bias").front()] =
120122
std::move(combile_bias_tensor);
121123
engine_->weight_map[op_desc.Input("Scale").front()] =

paddle/fluid/inference/tensorrt/convert/concat_op.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class ConcatOpConverter : public OpConverter {
3030
framework::OpDesc op_desc(op, nullptr);
3131
// Declare inputs
3232
std::vector<nvinfer1::ITensor*> itensors;
33+
std::cout << "Concat op: " << std::endl;
3334
for (auto& input_name : op_desc.Input("X")) {
35+
std::cout << input_name << std::endl;
3436
itensors.push_back(engine_->GetITensor(input_name));
3537
}
3638
int axis = boost::get<int>(op_desc.GetAttr("axis"));
@@ -42,6 +44,8 @@ class ConcatOpConverter : public OpConverter {
4244
axis = axis - 1; // Remove batch dim
4345
layer->setAxis(axis);
4446
auto output_name = op_desc.Output("Out")[0];
47+
layer->setName(("concat (Output: " + output_name + ")").c_str());
48+
layer->getOutput(0)->setName(output_name.c_str());
4549
engine_->SetITensor(output_name, layer->getOutput(0));
4650
if (test_mode) { // the test framework can not determine which is the
4751
// output, so place the declaration inside.

paddle/fluid/inference/tensorrt/convert/conv2d_op.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Conv2dOpConverter : public OpConverter {
2626
<< "convert a fluid conv2d op to tensorrt conv layer without bias";
2727

2828
framework::OpDesc op_desc(op, nullptr);
29+
std::cout << "Conv op: " << std::endl;
30+
std::cout << op_desc.Input("Input").front() << std::endl;
31+
std::cout << op_desc.Output("Output").front() << std::endl;
2932
PADDLE_ENFORCE_EQ(op_desc.Input("Input").size(), 1);
3033
PADDLE_ENFORCE_EQ(op_desc.Input("Filter").size(), 1); // Y is a weight
3134
PADDLE_ENFORCE_EQ(op_desc.Output("Output").size(), 1);
@@ -78,8 +81,10 @@ class Conv2dOpConverter : public OpConverter {
7881
layer->setNbGroups(groups);
7982

8083
auto output_name = op_desc.Output("Output").front();
84+
layer->setName(("conv2d (Output: " + output_name + ")").c_str());
8185
engine_->weight_map[op_desc.Input("Filter").front()] =
8286
std::move(weight_tensor);
87+
layer->getOutput(0)->setName(output_name.c_str());
8388
engine_->SetITensor(output_name, layer->getOutput(0));
8489
if (test_mode) {
8590
engine_->DeclareOutput(output_name);

paddle/fluid/inference/tensorrt/convert/elementwise_op.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class ElementwiseWeightOpConverter : public OpConverter {
8989
shift_weights.get(), scale_weights.get(), power_weights.get());
9090
auto output_name = op_desc.Output("Out")[0];
9191

92+
layer->setName(("elementwise_add (Output: " + output_name + ")").c_str());
93+
layer->getOutput(0)->setName(output_name.c_str());
9294
engine_->weight_map[op_desc.Input("Y").front()] = std::move(weight_tensor);
9395
engine_->SetITensor(output_name, layer->getOutput(0));
9496
if (test_mode) { // the test framework can not determine which is the
@@ -137,6 +139,8 @@ class ElementwiseTensorOpConverter : public OpConverter {
137139
*const_cast<nvinfer1::ITensor*>(Y), op_pair->second);
138140

139141
auto output_name = op_desc.Output("Out")[0];
142+
layer->setName(("elementwise (Output: " + output_name + ")").c_str());
143+
layer->getOutput(0)->setName(output_name.c_str());
140144
engine_->SetITensor(output_name, layer->getOutput(0));
141145
if (test_mode) { // the test framework can not determine which is the
142146
// output, so place the declaration inside.

paddle/fluid/inference/tensorrt/convert/fc_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class FcOpConverter : public OpConverter {
107107
n_output, tmp_weight.get(), bias.get());
108108

109109
auto output_name = op_desc.Output("Out").front();
110+
layer->setName(("fc (Output: " + output_name + ")").c_str());
111+
layer->getOutput(0)->setName(output_name.c_str());
110112
engine_->SetITensor(output_name, layer->getOutput(0));
111113
engine_->weight_map[op_desc.Input("Y").front()] = std::move(tmp);
112114
if (test_mode) {

paddle/fluid/inference/tensorrt/convert/pool2d_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class Pool2dOpConverter : public OpConverter {
7272
layer->setPadding(nv_paddings);
7373

7474
auto output_name = op_desc.Output("Out")[0];
75+
layer->setName(("pool2d (Output: " + output_name + ")").c_str());
76+
layer->getOutput(0)->setName(output_name.c_str());
7577
engine_->SetITensor(output_name, layer->getOutput(0));
7678
if (test_mode) {
7779
engine_->DeclareOutput(output_name);

paddle/fluid/operators/tensorrt_engine_op.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,6 @@ class TensorRTEngineKernel : public framework::OpKernel<T> {
161161
boost::get<platform::CUDAPlace>(context.GetPlace()).device)),
162162
size * sizeof(float));
163163

164-
// TODO(zhaolong) : delete it sometimes
165-
/* THIS CODE JUST FOR TEST
166-
std::cout << output_maps[output_index] << std::endl;
167-
platform::CPUPlace cpu_place;
168-
framework::LoDTensor temp_tensor;
169-
temp_tensor.Resize(framework::make_ddim(ddim));
170-
auto* temp_data = temp_tensor.mutable_data<float>(cpu_place);
171-
172-
TensorCopySync(*fluid_t, cpu_place ,&temp_tensor);
173-
for(int i = 0; i < size; i++) {
174-
std::cout << temp_data[i] << " " ;
175-
}
176-
std::cout << std::endl;
177-
*/
178164
output_index += 1;
179165
}
180166

0 commit comments

Comments
 (0)