提交 66fdbd0c 编写于 作者: T tensor-tang

add some comment and simplify some code

上级 44acc751
...@@ -47,9 +47,9 @@ bool MKLDNNConvLayer::init(const LayerMap& layerMap, ...@@ -47,9 +47,9 @@ bool MKLDNNConvLayer::init(const LayerMap& layerMap,
sw_ = conf.stride(); sw_ = conf.stride();
sh_ = conf.stride_y(); sh_ = conf.stride_y();
gp_ = conf.groups(); gp_ = conf.groups();
oh_ = conf.has_output_y() ? conf.output_y() : conf.output_x(); oh_ = conf.output_y();
ow_ = conf.output_x(); 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(); iw_ = conf.img_size();
caffeMode_ = conf.caffe_mode(); caffeMode_ = conf.caffe_mode();
CHECK(caffeMode_) << "Only support caffe mode yet"; CHECK(caffeMode_) << "Only support caffe mode yet";
......
...@@ -37,38 +37,30 @@ protected: ...@@ -37,38 +37,30 @@ protected:
// group number // group number
int gp_; int gp_;
// in backward data the format is different with wgtVal_ // in resetBwdData, the format of wgtValBwdData_ is different with wgtVal_
MKLDNNMatrixPtr wgtValBwdData_; MKLDNNMatrixPtr wgtValBwdData_;
// convert handle from wgtVal_ to wgtValBwdData_
std::shared_ptr<mkldnn::reorder> cvtWgtVal_; std::shared_ptr<mkldnn::reorder> cvtWgtVal_;
// save forward primitive_desc use for backward // save forward primitive_desc, which can be used backward
std::shared_ptr<mkldnn::convolution_forward::primitive_desc> fwdPD_; std::shared_ptr<mkldnn::convolution_forward::primitive_desc> fwdPD_;
// MKLDNNMatrixPtr with cpu device for conversion between MKLDNN device // MKLDNNMatrixPtr which should be created from CPU Device
MKLDNNMatrixPtr cpuInVal_; MKLDNNMatrixPtr cpuInVal_;
MKLDNNMatrixPtr cpuInGrad_; MKLDNNMatrixPtr cpuInGrad_;
MKLDNNMatrixPtr cpuOutVal_; MKLDNNMatrixPtr cpuOutVal_;
MKLDNNMatrixPtr cpuOutGrad_; MKLDNNMatrixPtr cpuOutGrad_;
// convert handle between CPU device and MKLDNN device
std::shared_ptr<mkldnn::reorder> cvtInVal_; std::shared_ptr<mkldnn::reorder> cvtInVal_;
std::shared_ptr<mkldnn::reorder> cvtInGrad_; std::shared_ptr<mkldnn::reorder> cvtInGrad_;
std::shared_ptr<mkldnn::reorder> cvtOutVal_; std::shared_ptr<mkldnn::reorder> cvtOutVal_;
std::shared_ptr<mkldnn::reorder> cvtOutGrad_; std::shared_ptr<mkldnn::reorder> cvtOutGrad_;
// if has already init the weight // whether the weight has been init
bool hasInitedWgt_; bool hasInitedWgt_;
// True by default. This impact the calculation of output size. // true by default, which impact the calculation of output image size.
// For example: // details can refer to mathUtil.h
// - 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;
bool caffeMode_; bool caffeMode_;
// weight and bias // weight and bias
......
...@@ -52,11 +52,7 @@ MKLDNNMatrixPtr MKLDNNMatrix::create(MatrixPtr m, ...@@ -52,11 +52,7 @@ MKLDNNMatrixPtr MKLDNNMatrix::create(MatrixPtr m,
std::shared_ptr<reorder> MKLDNNMatrix::createReorder(const MKLDNNMatrixPtr& src, std::shared_ptr<reorder> MKLDNNMatrix::createReorder(const MKLDNNMatrixPtr& src,
const MKLDNNMatrixPtr& dst, const MKLDNNMatrixPtr& dst,
bool checkData) { bool checkData) {
if (src == dst) { if (src == dst || src->getPrimitiveDesc() == dst->getPrimitiveDesc()) {
return nullptr;
}
if (src->getPrimitiveDesc() == dst->getPrimitiveDesc()) {
return nullptr; return nullptr;
} }
......
...@@ -65,6 +65,12 @@ public: ...@@ -65,6 +65,12 @@ public:
/** /**
* Create reorder primitive. * 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<mkldnn::reorder> createReorder( static std::shared_ptr<mkldnn::reorder> createReorder(
const MKLDNNMatrixPtr& src, const MKLDNNMatrixPtr& src,
......
...@@ -2073,10 +2073,7 @@ class ConvLayerBase(LayerBase): ...@@ -2073,10 +2073,7 @@ class ConvLayerBase(LayerBase):
(parallel_nn == 0 or self.config.device > -1)): (parallel_nn == 0 or self.config.device > -1)):
self.layer_type = "cudnn_conv" self.layer_type = "cudnn_conv"
else: else:
if (use_mkldnn == 1): self.layer_type = "mkldnn_conv" if use_mkldnn else "exconv"
self.layer_type = "mkldnn_conv"
else:
self.layer_type = "exconv"
# need to specify layer in config # need to specify layer in config
self.config.type = self.layer_type self.config.type = self.layer_type
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册