diff --git a/paddle/gserver/layers/MKLDNNConcatLayer.cpp b/paddle/gserver/layers/MKLDNNConcatLayer.cpp index 64946508d2031c0be78d399f9354f5af36402830..c9099297cc5c741fbae0b42f21b988e6c561ef11 100644 --- a/paddle/gserver/layers/MKLDNNConcatLayer.cpp +++ b/paddle/gserver/layers/MKLDNNConcatLayer.cpp @@ -40,7 +40,9 @@ void MKLDNNConcatLayer::reshape( CHECK_GT(inputLayers_.size(), 1UL); channels_.resize(inputLayers_.size()); channels_[0] = ic; - oc = ic; + // need change the output channel, so use oc_ instead + // TODO(TJ): change API, use &oc + oc_ = ic; for (size_t i = 1; i < inputLayers_.size(); i++) { int batchsize, height, witdh; reshapeInput(batchsize, height, witdh, i); @@ -50,12 +52,12 @@ void MKLDNNConcatLayer::reshape( channels_[i] = inputLayers_[i]->getSize() / height / witdh; CHECK_EQ((size_t)channels_[i] * height * witdh, inputLayers_[i]->getSize()); - oc += channels_[i]; + oc_ += channels_[i]; } oh = ih; ow = iw; reshapeOutput(oh, ow); - resizeOutput(bs, oc * oh * ow); + resizeOutput(bs, oc_ * oh * ow); } void MKLDNNConcatLayer::resetFwd(std::vector& pipeline, @@ -88,6 +90,9 @@ void MKLDNNConcatLayer::resetFwdBuffers(std::vector& inputs, inputs.resize(inputLayers_.size()); bool has8c = false, has16c = false, hasnc = false; for (size_t i = 0; i < inputs.size(); i++) { + // resetInValue will use ic_ so temporary change as current input's channel + // TODO(TJ): change ic_ as vector then can remove channels_ + ic_ = channels_[i]; resetInValue(inputs[i], nullptr, i); CHECK(inputs[i]); auto dm = inputs[i]->getDims(); @@ -109,6 +114,8 @@ void MKLDNNConcatLayer::resetFwdBuffers(std::vector& inputs, has16c = true; } } + // change back, ic_ always save the input 0 size + ic_ = channels_[0]; format outFmt; if (has16c && oc_ % 16 == 0) { @@ -161,9 +168,14 @@ void MKLDNNConcatLayer::resetBwdBuffers(std::vector& inputs, inputs.resize(inputLayers_.size()); for (size_t i = 0; i < inputs.size(); i++) { CHECK(inVals_[i]); + // resetInGrad will use inVal_ + // TODO(TJ): change move inVals_ to MKLDNNLayer ans remove inVal_ + inVal_ = inVals_[i]; resetInGrad(inputs[i], inVals_[i]->getPrimitiveDesc(), i); CHECK_PRIMITIVE_DESC_EQ(inputs[i], inVals_[i]->getPrimitiveDesc()); } + // change back, inVal_ always save the input 0 + inVal_ = inVals_[0]; } void MKLDNNConcatLayer::resetBwdPipeline( diff --git a/paddle/gserver/layers/MKLDNNConcatLayer.h b/paddle/gserver/layers/MKLDNNConcatLayer.h index ad70ec0ceb4839d0f509617c0170375ce1bc77fa..d5749d327e4259b81541a234f48a4538ab035fe4 100644 --- a/paddle/gserver/layers/MKLDNNConcatLayer.h +++ b/paddle/gserver/layers/MKLDNNConcatLayer.h @@ -74,8 +74,8 @@ public: void printValueFormat() override { for (size_t i = 0; i < inVals_.size(); ++i) { - VLOG(MKLDNN_FMTS) << "Input " << i << inputLayers_[i]->getName() << ": " - << inVals_[i]->getFormat() << " >>>"; + VLOG(MKLDNN_FMTS) << "Input " << i << ", " << inputLayers_[i]->getName() + << ": " << inVals_[i]->getFormat() << " >>>"; } if (outVal_) { VLOG(MKLDNN_FMTS) << outVal_->getFormat() << " >>> "; @@ -93,8 +93,8 @@ public: VLOG(MKLDNN_FMTS) << outGrad_->getFormat() << " <<< "; } for (size_t i = 0; i < inGrads_.size(); ++i) { - VLOG(MKLDNN_FMTS) << "Input " << i << inputLayers_[i]->getName() << ": " - << inGrads_[i]->getFormat() << "<<<"; + VLOG(MKLDNN_FMTS) << "Input " << i << ", " << inputLayers_[i]->getName() + << ": " << inGrads_[i]->getFormat() << "<<<"; } }