提交 115a6e64 编写于 作者: N nhzlx 提交者: Paddle CI

Merge Pull request from #12753 from NHZlX:add_benchmark

上级 249dca8b
...@@ -37,11 +37,11 @@ class Conv2dOpConverter : public OpConverter { ...@@ -37,11 +37,11 @@ class Conv2dOpConverter : public OpConverter {
auto* Y_t = Y_v->GetMutable<framework::LoDTensor>(); auto* Y_t = Y_v->GetMutable<framework::LoDTensor>();
platform::CPUPlace cpu_place; platform::CPUPlace cpu_place;
framework::LoDTensor* weight_tensor = new framework::LoDTensor(); std::unique_ptr<framework::LoDTensor> weight_tensor(
new framework::LoDTensor());
weight_tensor->Resize(Y_t->dims()); weight_tensor->Resize(Y_t->dims());
TensorCopySync((*Y_t), cpu_place, weight_tensor); TensorCopySync((*Y_t), cpu_place, weight_tensor.get());
engine_->weight_map[op_desc.Input("Filter").front()] =
std::move(std::unique_ptr<framework::Tensor>(weight_tensor));
auto* weight_data = auto* weight_data =
weight_tensor->mutable_data<float>(platform::CPUPlace()); weight_tensor->mutable_data<float>(platform::CPUPlace());
...@@ -78,6 +78,8 @@ class Conv2dOpConverter : public OpConverter { ...@@ -78,6 +78,8 @@ class Conv2dOpConverter : public OpConverter {
layer->setNbGroups(groups); layer->setNbGroups(groups);
auto output_name = op_desc.Output("Output").front(); auto output_name = op_desc.Output("Output").front();
engine_->weight_map[op_desc.Input("Filter").front()] =
std::move(weight_tensor);
engine_->SetITensor(output_name, layer->getOutput(0)); engine_->SetITensor(output_name, layer->getOutput(0));
if (test_mode) { if (test_mode) {
engine_->DeclareOutput(output_name); engine_->DeclareOutput(output_name);
......
...@@ -41,12 +41,10 @@ class ElementwiseWeightOpConverter : public OpConverter { ...@@ -41,12 +41,10 @@ class ElementwiseWeightOpConverter : public OpConverter {
auto* Y_t = Y_v->GetMutable<framework::LoDTensor>(); auto* Y_t = Y_v->GetMutable<framework::LoDTensor>();
platform::CPUPlace cpu_place; platform::CPUPlace cpu_place;
framework::LoDTensor* weight_tensor = new framework::LoDTensor(); std::unique_ptr<framework::LoDTensor> weight_tensor(
new framework::LoDTensor());
weight_tensor->Resize(Y_t->dims()); weight_tensor->Resize(Y_t->dims());
TensorCopySync((*Y_t), cpu_place, weight_tensor); TensorCopySync((*Y_t), cpu_place, weight_tensor.get());
engine_->weight_map[op_desc.Input("Y").front()] =
std::move(std::unique_ptr<framework::Tensor>(weight_tensor));
auto* weight_data = auto* weight_data =
weight_tensor->mutable_data<float>(platform::CPUPlace()); weight_tensor->mutable_data<float>(platform::CPUPlace());
auto scale_mode = nvinfer1::ScaleMode::kELEMENTWISE; auto scale_mode = nvinfer1::ScaleMode::kELEMENTWISE;
...@@ -90,6 +88,8 @@ class ElementwiseWeightOpConverter : public OpConverter { ...@@ -90,6 +88,8 @@ class ElementwiseWeightOpConverter : public OpConverter {
engine_, Scale, *const_cast<nvinfer1::ITensor*>(X), scale_mode, engine_, Scale, *const_cast<nvinfer1::ITensor*>(X), scale_mode,
shift_weights.get(), scale_weights.get(), power_weights.get()); shift_weights.get(), scale_weights.get(), power_weights.get());
auto output_name = op_desc.Output("Out")[0]; auto output_name = op_desc.Output("Out")[0];
engine_->weight_map[op_desc.Input("Y").front()] = std::move(weight_tensor);
engine_->SetITensor(output_name, layer->getOutput(0)); engine_->SetITensor(output_name, layer->getOutput(0));
if (test_mode) { // the test framework can not determine which is the if (test_mode) { // the test framework can not determine which is the
// output, so place the declaration inside. // output, so place the declaration inside.
......
...@@ -78,10 +78,8 @@ class FcOpConverter : public OpConverter { ...@@ -78,10 +78,8 @@ class FcOpConverter : public OpConverter {
PADDLE_ENFORCE_EQ(weight_tensor.dims().size(), 2UL); // a matrix PADDLE_ENFORCE_EQ(weight_tensor.dims().size(), 2UL); // a matrix
size_t n_output = weight_tensor.dims()[1]; size_t n_output = weight_tensor.dims()[1];
framework::LoDTensor* tmp = new framework::LoDTensor(); std::unique_ptr<framework::Tensor> tmp(new framework::LoDTensor());
tmp->Resize(weight_tensor.dims()); tmp->Resize(weight_tensor.dims());
engine_->weight_map[op_desc.Input("Y").front()] =
std::move(std::unique_ptr<framework::Tensor>(tmp));
memcpy(tmp->mutable_data<float>(platform::CPUPlace()), weight_data, memcpy(tmp->mutable_data<float>(platform::CPUPlace()), weight_data,
Y_t->dims()[0] * Y_t->dims()[1] * sizeof(float)); Y_t->dims()[0] * Y_t->dims()[1] * sizeof(float));
...@@ -110,6 +108,7 @@ class FcOpConverter : public OpConverter { ...@@ -110,6 +108,7 @@ class FcOpConverter : public OpConverter {
auto output_name = op_desc.Output("Out").front(); auto output_name = op_desc.Output("Out").front();
engine_->SetITensor(output_name, layer->getOutput(0)); engine_->SetITensor(output_name, layer->getOutput(0));
engine_->weight_map[op_desc.Input("Y").front()] = std::move(tmp);
if (test_mode) { if (test_mode) {
engine_->DeclareOutput(output_name); engine_->DeclareOutput(output_name);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册