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

add some comment and simplify some code

上级 44acc751
......@@ -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";
......
......@@ -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<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_;
// 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<mkldnn::reorder> cvtInVal_;
std::shared_ptr<mkldnn::reorder> cvtInGrad_;
std::shared_ptr<mkldnn::reorder> cvtOutVal_;
std::shared_ptr<mkldnn::reorder> 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
......
......@@ -52,11 +52,7 @@ MKLDNNMatrixPtr MKLDNNMatrix::create(MatrixPtr m,
std::shared_ptr<reorder> 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;
}
......
......@@ -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<mkldnn::reorder> createReorder(
const MKLDNNMatrixPtr& src,
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册