diff --git a/paddle/gserver/layers/MKLDNNConvLayer.cpp b/paddle/gserver/layers/MKLDNNConvLayer.cpp index 617874defe74bd85b07c33de1c6bafdcadc768c4..19891043a1fa11c947118cf952171fec18294191 100644 --- a/paddle/gserver/layers/MKLDNNConvLayer.cpp +++ b/paddle/gserver/layers/MKLDNNConvLayer.cpp @@ -47,9 +47,9 @@ bool MKLDNNConvLayer::init(const LayerMap& layerMap, sw_ = conf.stride(); sh_ = conf.stride_y(); gp_ = conf.groups(); - oh_ = conf.has_output_y() ? conf.output_y() : conf.output_x(); + oh_ = conf.output_y(); ow_ = conf.output_x(); - ih_ = conf.has_img_size_y() ? conf.img_size_y() : conf.img_size(); + ih_ = conf.img_size_y(); iw_ = conf.img_size(); caffeMode_ = conf.caffe_mode(); CHECK(caffeMode_) << "Only support caffe mode yet"; diff --git a/paddle/gserver/layers/MKLDNNConvLayer.h b/paddle/gserver/layers/MKLDNNConvLayer.h index 58891ff5e1f5162dd1dadec9e45d72a6d0e5e1b9..d1a78ac1c0fd29f5e88511055c2b4e0d7cc91e88 100644 --- a/paddle/gserver/layers/MKLDNNConvLayer.h +++ b/paddle/gserver/layers/MKLDNNConvLayer.h @@ -37,38 +37,30 @@ protected: // group number int gp_; - // in backward data the format is different with wgtVal_ + // in resetBwdData, the format of wgtValBwdData_ is different with wgtVal_ MKLDNNMatrixPtr wgtValBwdData_; + // convert handle from wgtVal_ to wgtValBwdData_ std::shared_ptr cvtWgtVal_; - // save forward primitive_desc use for backward + // save forward primitive_desc, which can be used backward std::shared_ptr fwdPD_; - // MKLDNNMatrixPtr with cpu device for conversion between MKLDNN device + // MKLDNNMatrixPtr which should be created from CPU Device MKLDNNMatrixPtr cpuInVal_; MKLDNNMatrixPtr cpuInGrad_; MKLDNNMatrixPtr cpuOutVal_; MKLDNNMatrixPtr cpuOutGrad_; + // convert handle between CPU device and MKLDNN device std::shared_ptr cvtInVal_; std::shared_ptr cvtInGrad_; std::shared_ptr cvtOutVal_; std::shared_ptr cvtOutGrad_; - // if has already init the weight + // whether the weight has been init bool hasInitedWgt_; - // True by default. This impact the calculation of output size. - // For example: - // - input(+padding): 0123456789 - // - imageSize(+padding) = 10; - // - filterSize = 3; - // - stride = 2; - // - caffeMode_ is true: - // - output: (012), (234), (456), (678) - // - outputSize = 4; - // - caffeMode_ is false: - // - output: (012), (234), (456), (678), (9) - // - outputSize = 5; + // true by default, which impact the calculation of output image size. + // details can refer to mathUtil.h bool caffeMode_; // weight and bias diff --git a/paddle/math/MKLDNNMatrix.cpp b/paddle/math/MKLDNNMatrix.cpp index a71ac12afcea63bf2e543ff8ec55be6d33be8571..0778bb63b7b3bca9b3d2647ca43dad72d783950a 100644 --- a/paddle/math/MKLDNNMatrix.cpp +++ b/paddle/math/MKLDNNMatrix.cpp @@ -52,11 +52,7 @@ MKLDNNMatrixPtr MKLDNNMatrix::create(MatrixPtr m, std::shared_ptr MKLDNNMatrix::createReorder(const MKLDNNMatrixPtr& src, const MKLDNNMatrixPtr& dst, bool checkData) { - if (src == dst) { - return nullptr; - } - - if (src->getPrimitiveDesc() == dst->getPrimitiveDesc()) { + if (src == dst || src->getPrimitiveDesc() == dst->getPrimitiveDesc()) { return nullptr; } diff --git a/paddle/math/MKLDNNMatrix.h b/paddle/math/MKLDNNMatrix.h index c7765369c8571567a377e8603ab41850d80bba26..0aa130b4a0d458ad78d5d1330164af9e73b22a44 100644 --- a/paddle/math/MKLDNNMatrix.h +++ b/paddle/math/MKLDNNMatrix.h @@ -65,6 +65,12 @@ public: /** * Create reorder primitive. + * Create a mkldnn::reorder handle for converting src MKLDNNMatrix to dst. + * checkData: for whether to check the data handle of src and dst is the same. + * if true, means check it and do not want support inplace reorder; + * otherwise do not check data which means the created reorder + * maybe inplace buffer and do not guarantee the logical is correct + * since not all format or conversion support inplace. */ static std::shared_ptr createReorder( const MKLDNNMatrixPtr& src, diff --git a/python/paddle/trainer/config_parser.py b/python/paddle/trainer/config_parser.py index d633cae4aa178361adc376e31bcd4365599a702a..58ebcd1d8e01c6bcad5ef364709135a632e14c2d 100644 --- a/python/paddle/trainer/config_parser.py +++ b/python/paddle/trainer/config_parser.py @@ -2073,10 +2073,7 @@ class ConvLayerBase(LayerBase): (parallel_nn == 0 or self.config.device > -1)): self.layer_type = "cudnn_conv" else: - if (use_mkldnn == 1): - self.layer_type = "mkldnn_conv" - else: - self.layer_type = "exconv" + self.layer_type = "mkldnn_conv" if use_mkldnn else "exconv" # need to specify layer in config self.config.type = self.layer_type