diff --git a/paddle/gserver/layers/CostLayer.cpp b/paddle/gserver/layers/CostLayer.cpp index e2a4153bad72d236c6a64fa4ef2311a0b218abf7..4ae5b828707eb8412e98cbefcf3949d62e81ad1e 100644 --- a/paddle/gserver/layers/CostLayer.cpp +++ b/paddle/gserver/layers/CostLayer.cpp @@ -206,17 +206,14 @@ bool SmoothL1CostLayer::init(const LayerMap& layerMap, void SmoothL1CostLayer::forwardImp(Matrix& output, Argument& label, Matrix& target) { - MatrixPtr targetCpu, labelCpu, outputCpu; + MatrixPtr targetCpu, outputCpu, labelCpu; if (useGpu_) { - Matrix::resizeOrCreate( - targetCpu, target.getHeight(), target.getWidth(), false, false); - Matrix::resizeOrCreate( - outputCpu, output.getHeight(), output.getWidth(), false, false); - Matrix::resizeOrCreate(labelCpu, - label.value->getHeight(), - label.value->getWidth(), - false, - false); + targetCpu = + Matrix::create(target.getHeight(), target.getWidth(), false, false); + outputCpu = + Matrix::create(output.getHeight(), output.getWidth(), false, false); + labelCpu = Matrix::create( + label.value->getHeight(), label.value->getWidth(), false, false); targetCpu->copyFrom(target); outputCpu->copyFrom(output); labelCpu->copyFrom(*label.value); @@ -230,17 +227,14 @@ void SmoothL1CostLayer::forwardImp(Matrix& output, void SmoothL1CostLayer::backwardImp(Matrix& output, Argument& label, Matrix& outputG) { - MatrixPtr outputGCpu, labelCpu, outputCpu; + MatrixPtr outputGCpu, outputCpu, labelCpu; if (useGpu_) { - Matrix::resizeOrCreate( - outputGCpu, outputG.getHeight(), outputG.getWidth(), false, false); - Matrix::resizeOrCreate( - outputCpu, output.getHeight(), output.getWidth(), false, false); - Matrix::resizeOrCreate(labelCpu, - label.value->getHeight(), - label.value->getWidth(), - false, - false); + outputGCpu = + Matrix::create(outputG.getHeight(), outputG.getWidth(), false, false); + outputCpu = + Matrix::create(output.getHeight(), output.getWidth(), false, false); + labelCpu = Matrix::create( + label.value->getHeight(), label.value->getWidth(), false, false); outputGCpu->copyFrom(outputG); outputCpu->copyFrom(output); labelCpu->copyFrom(*label.value);