MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / TEST_F

Function TEST_F

test/cpp/fluid/tensorrt/test_engine.cc:75–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73};
74
75TEST_F(TensorRTEngineTest, add_layer) {
76 const int size = 1;
77
78 std::vector<float> raw_weight = {2.}; // Weight in CPU memory.
79 std::vector<float> raw_bias = {3.};
80
81 std::vector<void *> buffers(2); // TRT binded inputs
82
83 LOG(INFO) << "create weights";
84 TensorRTEngine::Weight weight(
85 nvinfer1::DataType::kFLOAT, raw_weight.data(), size);
86 TensorRTEngine::Weight bias(
87 nvinfer1::DataType::kFLOAT, raw_bias.data(), size);
88 auto *x = engine_->DeclareInput(
89 "x", nvinfer1::DataType::kFLOAT, nvinfer1::Dims3{1, 1, 1});
90 auto *weight_layer = TRT_ENGINE_ADD_LAYER(
91 engine_, Constant, nvinfer1::Dims3{1, 1, 1}, weight.get());
92 auto *bias_layer = TRT_ENGINE_ADD_LAYER(
93 engine_, Constant, nvinfer1::Dims3{1, 1, 1}, bias.get());
94 auto *matmul_layer =
95 TRT_ENGINE_ADD_LAYER(engine_,
96 MatrixMultiply,
97 *x,
98 nvinfer1::MatrixOperation::kNONE,
99 *weight_layer->getOutput(0),
100 nvinfer1::MatrixOperation::kTRANSPOSE);
101 PADDLE_ENFORCE_NOT_NULL(
102 matmul_layer,
103 common::errors::InvalidArgument(
104 "The TRT MatrixMultiply layer cannot be null. There is something "
105 "wrong with the TRT network building and layer creation."));
106 auto *add_layer = TRT_ENGINE_ADD_LAYER(engine_,
107 ElementWise,
108 *matmul_layer->getOutput(0),
109 *bias_layer->getOutput(0),
110 nvinfer1::ElementWiseOperation::kSUM);
111 PADDLE_ENFORCE_NOT_NULL(
112 add_layer,
113 common::errors::InvalidArgument(
114 "The TRT elementwise layer cannot be null. There is something wrong "
115 "with the TRT network building and layer creation."));
116
117 engine_->DeclareOutput(add_layer, 0, "y");
118 LOG(INFO) << "freeze network";
119 engine_->FreezeNetwork();
120#if IS_TRT_VERSION_GE(8600)
121 ASSERT_EQ(engine_->engine()->getNbIOTensors(), 2);
122#else
123 ASSERT_EQ(engine_->engine()->getNbBindings(), 2);
124#endif
125
126 // fill in real data
127 std::vector<float> x_v = {1234};
128 std::vector<float> y_cpu;
129 PrepareInputOutput(x_v, {1});
130
131 auto *x_v_gpu_data = input_.mutable_data<float>(ctx_->GetPlace());
132 auto *y_gpu_data = output_.mutable_data<float>(ctx_->GetPlace());

Callers

nothing calls this directly

Calls 11

dataMethod · 0.45
DeclareInputMethod · 0.45
getMethod · 0.45
DeclareOutputMethod · 0.45
FreezeNetworkMethod · 0.45
engineMethod · 0.45
GetPlaceMethod · 0.45
ExecuteMethod · 0.45
streamMethod · 0.45
GetITensorMethod · 0.45
SetAllNodesLowerToTrtMethod · 0.45

Tested by

no test coverage detected