Skip to content

Commit 1ec66a3

Browse files
author
gaoyuan
committed
change resizeOrCreate to create
1 parent 25a525b commit 1ec66a3

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

paddle/gserver/layers/CostLayer.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,14 @@ bool SmoothL1CostLayer::init(const LayerMap& layerMap,
206206
void SmoothL1CostLayer::forwardImp(Matrix& output,
207207
Argument& label,
208208
Matrix& target) {
209-
MatrixPtr targetCpu, labelCpu, outputCpu;
209+
MatrixPtr targetCpu, outputCpu, labelCpu;
210210
if (useGpu_) {
211-
Matrix::resizeOrCreate(
212-
targetCpu, target.getHeight(), target.getWidth(), false, false);
213-
Matrix::resizeOrCreate(
214-
outputCpu, output.getHeight(), output.getWidth(), false, false);
215-
Matrix::resizeOrCreate(labelCpu,
216-
label.value->getHeight(),
217-
label.value->getWidth(),
218-
false,
219-
false);
211+
targetCpu =
212+
Matrix::create(target.getHeight(), target.getWidth(), false, false);
213+
outputCpu =
214+
Matrix::create(output.getHeight(), output.getWidth(), false, false);
215+
labelCpu = Matrix::create(
216+
label.value->getHeight(), label.value->getWidth(), false, false);
220217
targetCpu->copyFrom(target);
221218
outputCpu->copyFrom(output);
222219
labelCpu->copyFrom(*label.value);
@@ -230,17 +227,14 @@ void SmoothL1CostLayer::forwardImp(Matrix& output,
230227
void SmoothL1CostLayer::backwardImp(Matrix& output,
231228
Argument& label,
232229
Matrix& outputG) {
233-
MatrixPtr outputGCpu, labelCpu, outputCpu;
230+
MatrixPtr outputGCpu, outputCpu, labelCpu;
234231
if (useGpu_) {
235-
Matrix::resizeOrCreate(
236-
outputGCpu, outputG.getHeight(), outputG.getWidth(), false, false);
237-
Matrix::resizeOrCreate(
238-
outputCpu, output.getHeight(), output.getWidth(), false, false);
239-
Matrix::resizeOrCreate(labelCpu,
240-
label.value->getHeight(),
241-
label.value->getWidth(),
242-
false,
243-
false);
232+
outputGCpu =
233+
Matrix::create(outputG.getHeight(), outputG.getWidth(), false, false);
234+
outputCpu =
235+
Matrix::create(output.getHeight(), output.getWidth(), false, false);
236+
labelCpu = Matrix::create(
237+
label.value->getHeight(), label.value->getWidth(), false, false);
244238
outputGCpu->copyFrom(outputG);
245239
outputCpu->copyFrom(output);
246240
labelCpu->copyFrom(*label.value);

0 commit comments

Comments
 (0)