Skip to content

Commit 6a7b995

Browse files
committed
Refine commit message to enable ci, test=develop
1 parent 413f594 commit 6a7b995

File tree

5 files changed

+19
-36
lines changed

5 files changed

+19
-36
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PReluOpConverter : public OpConverter {
2626
public:
2727
void operator()(const framework::proto::OpDesc& op,
2828
const framework::Scope& scope, bool test_mode) override {
29-
VLOG(40) << "convert fluid prelu op to tensorrt prelu layer";
29+
VLOG(4) << "convert fluid prelu op to tensorrt prelu layer";
3030

3131
framework::OpDesc op_desc(op, nullptr);
3232
// Declare inputs
@@ -43,33 +43,31 @@ class PReluOpConverter : public OpConverter {
4343
PADDLE_ENFORCE_NOT_NULL(alpha_var);
4444
auto* alpha_tensor = alpha_var->GetMutable<framework::LoDTensor>();
4545

46-
platform::CPUPlace place;
47-
std::unique_ptr<framework::LoDTensor> alpha_tensor_host(
46+
platform::CUDAPlace place;
47+
std::unique_ptr<framework::LoDTensor> alpha_tensor_device(
4848
new framework::LoDTensor());
49-
alpha_tensor_host->Resize(alpha_tensor->dims());
50-
TensorCopySync(*alpha_tensor, place, alpha_tensor_host.get());
51-
float* alpha_data = alpha_tensor_host->mutable_data<float>(place);
49+
alpha_tensor_device->Resize(alpha_tensor->dims());
50+
TensorCopySync(*alpha_tensor, place, alpha_tensor_device.get());
51+
float* alpha_data = alpha_tensor_device->mutable_data<float>(place);
5252

5353
// Transform alpha to TensorRTEngine::Weight
5454
TensorRTEngine::Weight alpha_rt(nvinfer1::DataType::kFLOAT,
5555
static_cast<void*>(alpha_data),
56-
alpha_tensor_host->numel());
57-
engine_->weight_map[op_desc.Input("Alpha")[0]] =
58-
std::move(alpha_tensor_host);
59-
//
56+
alpha_tensor_device->numel());
6057
PReluPlugin* plugin = new PReluPlugin(alpha_rt, mode);
6158
nvinfer1::IPluginLayer* layer =
6259
engine_->AddPlugin(&input, input_num, plugin);
60+
// keep alpha tensor to avoid release it's memory
61+
engine_->weight_map[op_desc.Input("Alpha")[0]] =
62+
std::move(alpha_tensor_device);
6363

6464
std::string layer_name = "prelu (Output: ";
65-
for (size_t i = 0; i < output_num; i++) {
66-
auto output_name = op_desc.Output("Out")[i];
67-
layer->getOutput(i)->setName(output_name.c_str());
68-
engine_->SetITensor(output_name, layer->getOutput(i));
69-
layer_name += output_name;
70-
if (test_mode) {
71-
engine_->DeclareOutput(output_name);
72-
}
65+
auto output_name = op_desc.Output("Out")[0];
66+
layer->getOutput(0)->setName(output_name.c_str());
67+
engine_->SetITensor(output_name, layer->getOutput(0));
68+
layer_name += output_name;
69+
if (test_mode) {
70+
engine_->DeclareOutput(output_name);
7371
}
7472
layer->setName((layer_name + ")").c_str());
7573
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SplitOpConverter : public OpConverter {
2626
public:
2727
void operator()(const framework::proto::OpDesc& op,
2828
const framework::Scope& scope, bool test_mode) override {
29-
VLOG(40) << "convert a fluid split op to tensorrt split layer";
29+
VLOG(4) << "convert a fluid split op to tensorrt split layer";
3030

3131
framework::OpDesc op_desc(op, nullptr);
3232
// Declare inputs

paddle/fluid/inference/tensorrt/engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TensorRTEngine : public EngineBase {
4646
w_.values = value;
4747
w_.count = num_elem;
4848
}
49-
nvinfer1::Weights& get() { return w_; }
49+
const nvinfer1::Weights& get() { return w_; }
5050

5151
std::vector<int64_t> dims;
5252

paddle/fluid/inference/tensorrt/plugin/prelu_op_plugin.cu

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,12 @@ nvinfer1::Dims PReluPlugin::getOutputDimensions(int index,
109109
return output_dims;
110110
}
111111

112-
int PReluPlugin::initialize() {
113-
nvinfer1::Weights &alpha = cuda_alpha_.get();
114-
alpha.type = alpha_.get().type;
115-
alpha.count = alpha_.get().count;
116-
117-
CHECK_EQ(cudaMalloc(&alpha.values, alpha.count * sizeof(float)), cudaSuccess);
118-
CHECK_EQ(cudaMemcpy(const_cast<void *>(alpha.values), alpha_.get().values,
119-
alpha.count * sizeof(float), cudaMemcpyHostToDevice),
120-
cudaSuccess);
121-
return 0;
122-
}
123-
124112
int PReluPlugin::enqueue(int batchSize, const void *const *inputs,
125113
void **outputs, void *workspace, cudaStream_t stream) {
126114
// input dims is CHW.
127115
const auto &input_dims = this->getInputDims(0);
128116
const float *input = reinterpret_cast<const float *>(inputs[0]);
129-
const float *alpha =
130-
reinterpret_cast<const float *>(cuda_alpha_.get().values);
117+
const float *alpha = reinterpret_cast<const float *>(alpha_.get().values);
131118
float *output = reinterpret_cast<float **>(outputs)[0];
132119
if (mode_ == "channel") {
133120
PReluChannelWise(stream, input, alpha, output, batchSize, input_dims);

paddle/fluid/inference/tensorrt/plugin/prelu_op_plugin.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace tensorrt {
2424

2525
class PReluPlugin : public PluginTensorRT {
2626
TensorRTEngine::Weight alpha_;
27-
TensorRTEngine::Weight cuda_alpha_;
2827
std::string mode_;
2928

3029
protected:
@@ -60,7 +59,6 @@ class PReluPlugin : public PluginTensorRT {
6059
int getNbOutputs() const override { return 1; }
6160
nvinfer1::Dims getOutputDimensions(int index, const nvinfer1::Dims *inputs,
6261
int nbInputDims) override;
63-
int initialize() override;
6462
int enqueue(int batchSize, const void *const *inputs, void **outputs,
6563
void *workspace, cudaStream_t stream) override;
6664
};

0 commit comments

Comments
 (0)