Skip to content

Commit

Permalink
tests fixes + windows build (#7)
Browse files Browse the repository at this point in the history
* scalar fix

* int8 fix

* windows build fix

* transpose + small fixes
  • Loading branch information
Maxim Andronov committed Jul 20, 2021
1 parent 3819fe5 commit 7c3865d
Show file tree
Hide file tree
Showing 36 changed files with 178 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BlockedMemoryDesc : public MemoryDesc {
const std::vector<size_t>& strides = {});

MemoryDescPtr clone() const override {
return make_unique<BlockedMemoryDesc>(*this);
return MKLDNNPlugin::make_unique<BlockedMemoryDesc>(*this);
}

bool isDefined() const override;
Expand Down
25 changes: 20 additions & 5 deletions inference-engine/src/mkldnn_plugin/cpu_memory_desc_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ MKLDNNMemoryDesc MemoryDescUtils::convertToMKLDNNMemoryDesc(const MemoryDesc& de

MKLDNNMemoryDesc MemoryDescUtils::convertToMKLDNNMemoryDesc(const BlockedMemoryDesc& desc) {
dnnl_memory_desc_t mkldnnDesc;

// scalar case
if (desc.getShape().getRank() == 0) {
mkldnn::memory::desc convertedDesc;
convertedDesc.data.format_kind = dnnl_blocked;
convertedDesc.data.data_type = memory::convert_to_c(MKLDNNMemory::convertToDataType(desc.getPrecision()));
convertedDesc.data.ndims = 1;
convertedDesc.data.dims[0] = 1;
convertedDesc.data.padded_dims[0] = 1;
convertedDesc.data.format_desc.blocking.strides[0] = 1;
convertedDesc.data.padded_offsets[0] = 0;
convertedDesc.data.offset0 = desc.getOffsetPadding();
return MKLDNNMemoryDesc(convertedDesc);
}

auto dims = desc.getShape().getStaticDims();

auto ie_blkdDims = desc.getBlockDims();
Expand Down Expand Up @@ -332,11 +347,11 @@ BlockedMemoryDesc MemoryDescUtils::convertToBlockedDescriptor(const MemoryDesc &

MemoryDescPtr MemoryDescUtils::applyUndefinedOffset(const MKLDNNMemoryDesc& desc) {
if (desc.getFormatKind() != dnnl_format_kind_t::dnnl_blocked)
return make_unique<MKLDNNMemoryDesc>(desc);
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(desc);

mkldnn::memory::desc retDesc = desc;
retDesc.data.offset0 = Shape::UNDEFINED_DIM;
return make_unique<MKLDNNMemoryDesc>(retDesc);
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(retDesc);
}

MemoryDescPtr MemoryDescUtils::applyUndefinedOffset(const BlockedMemoryDesc &desc) {
Expand All @@ -347,20 +362,20 @@ MemoryDescPtr MemoryDescUtils::applyUndefinedOffset(const BlockedMemoryDesc &des
offsetPaddingToData.resize(desc.getBlockDims().size(), 0);
size_t offsetPadding = Shape::UNDEFINED_DIM;

return make_unique<BlockedMemoryDesc>(desc.getPrecision(), desc.getShape().getDims(), desc.getBlockDims(),
return MKLDNNPlugin::make_unique<BlockedMemoryDesc>(desc.getPrecision(), desc.getShape().getDims(), desc.getBlockDims(),
desc.getOrder(), offsetPadding, offsetPaddingToData, strides);
}

MemoryDescPtr MemoryDescUtils::resetOffset(const MemoryDesc* desc) {
if (MemoryDescType::Blocked == desc->getType()) {
auto blockedDesc = desc->as<BlockedMemoryDesc>();
return make_unique<BlockedMemoryDesc>(blockedDesc->getPrecision(), blockedDesc->getShape().getDims(),
return MKLDNNPlugin::make_unique<BlockedMemoryDesc>(blockedDesc->getPrecision(), blockedDesc->getShape().getDims(),
blockedDesc->getBlockDims(), blockedDesc->getOrder());
} else if (MemoryDescType::Mkldnn == desc->getType()) {
auto mkldnnDesc = desc->as<MKLDNNMemoryDesc>();
mkldnn::memory::desc retDesc = *mkldnnDesc;
retDesc.data.offset0 = 0;
return make_unique<MKLDNNMemoryDesc>(retDesc);
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(retDesc);
}
return desc->clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ void MKLDNNGraphOptimizer::MergeTransposeAndReorder(MKLDNNGraph &graph) {
}

auto& transposeOrder = transposeNode->getOrder();
auto &layoutOrder = MemoryDescUtils::convertToBlockedDescriptor(
auto layoutOrder = MemoryDescUtils::convertToBlockedDescriptor(
*transposeNode->getSelectedPrimitiveDescriptor()->getConfig().outConfs[0].desc).getOrder();

auto inBlockedDesc = MemoryDescUtils::convertToBlockedDescriptor(*reorderNode->getSelectedPrimitiveDescriptor()->getConfig().inConfs[0].desc);
Expand Down
2 changes: 1 addition & 1 deletion inference-engine/src/mkldnn_plugin/mkldnn_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MKLDNNMemoryDesc : public MemoryDesc {
}

std::unique_ptr<MemoryDesc> clone() const override {
return make_unique<MKLDNNMemoryDesc>(*this);
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(*this);
}

bool checkGeneralLayout(GeneralLayout layoutType) const override;
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/src/mkldnn_plugin/mkldnn_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ bool MKLDNNNode::isConfigDefined(const NodeConfig &config) const {
}

std::unique_ptr<MKLDNNMemoryDesc> MKLDNNNode::getSrcMemDesc(mkldnn::primitive_desc_iterator &primitive_desc_it, size_t idx) {
return make_unique<MKLDNNMemoryDesc>(primitive_desc_it.src_desc(idx));
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(primitive_desc_it.src_desc(idx));
// TODO [DS]: uncomment or remove
// InferenceEngine::TensorDesc desc = MKLDNNMemoryDesc(primitive_desc_it.src_desc(idx));
// if (desc.getLayout() == InferenceEngine::Layout::ANY)
Expand All @@ -1055,7 +1055,7 @@ std::unique_ptr<MKLDNNMemoryDesc> MKLDNNNode::getSrcMemDesc(mkldnn::primitive_de
}

std::unique_ptr<MKLDNNMemoryDesc> MKLDNNNode::getDstMemDesc(mkldnn::primitive_desc_iterator &primitive_desc_it, size_t idx) {
return make_unique<MKLDNNMemoryDesc>(primitive_desc_it.dst_desc(idx));
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(primitive_desc_it.dst_desc(idx));
// TODO [DS]: uncomment or remove
// InferenceEngine::TensorDesc desc = MKLDNNMemoryDesc(primitive_desc_it.dst_desc(idx));
// if (desc.getLayout() == InferenceEngine::Layout::ANY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BlockedDescCreator {
makeFilteredRange(const CreatorsMap& map, Predicate predicate);
virtual BlockedMemoryDesc createDesc(const InferenceEngine::Precision& precision, const InferenceEngine::SizeVector& srcDims) const = 0;
std::unique_ptr<BlockedMemoryDesc> createUniqueDesc(const InferenceEngine::Precision& precision, const InferenceEngine::SizeVector& srcDims) const {
return make_unique<BlockedMemoryDesc>(createDesc(precision, srcDims));
return MKLDNNPlugin::make_unique<BlockedMemoryDesc>(createDesc(precision, srcDims));
}
virtual size_t getMinimalRank() const = 0;
virtual ~BlockedDescCreator() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ void MKLDNNBinaryConvolutionNode::initSupportedPrimitiveDescriptors() {
weiDims[2], weiDims[3], weiFirstDimBlockSize, 32};
std::vector<size_t> weiOrder = {0, 1, 2, 3, 0, 1};

config.inConfs[1].desc = make_unique<BlockedMemoryDesc>(Precision::BIN, weiDims, weiBlockDims, weiOrder);
config.inConfs[1].desc = MKLDNNPlugin::make_unique<BlockedMemoryDesc>(Precision::BIN, weiDims, weiBlockDims, weiOrder);

//result
auto outputPrecision = withBinarization ? Precision::BIN : Precision::FP32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ void MKLDNNConcatNode::initSupportedPrimitiveDescriptors() {
}
}

config.outConfs[0].desc = make_unique<BlockedMemoryDesc>(outputPrecision, dstDims, blkDims, order, offset, offsets, strides);
config.outConfs[0].desc = MKLDNNPlugin::make_unique<BlockedMemoryDesc>(outputPrecision, dstDims, blkDims, order, offset, offsets, strides);

for (size_t i = 0; i < getParentEdges().size(); i++) {
const auto& srcBlkDims = refConfig.inConfs[i].desc->as<BlockedMemoryDesc>()->getBlockDims();
const auto& dims = refConfig.inConfs[i].desc->getShape().getStaticDims();

config.inConfs[i].inPlace = 0;
config.inConfs[i].desc = make_unique<BlockedMemoryDesc>(inputPrecision, dims, srcBlkDims, order, offset, offsets, strides);
config.inConfs[i].desc = MKLDNNPlugin::make_unique<BlockedMemoryDesc>(inputPrecision, dims, srcBlkDims, order, offset, offsets, strides);
}
supportedPrimitiveDescriptors.emplace_back(config, impl_desc_type::unknown);
}
Expand Down Expand Up @@ -432,7 +432,7 @@ void MKLDNNConcatNode::initOptimalPrimitiveDescriptor() {
size_t offset = 0;
for (size_t i = 0; i < config.inConfs.size(); i++) {
auto inpBlockingDesc = MemoryDescUtils::convertToBlockedDescriptor(*config.inConfs[i].desc);
config.inConfs[i].desc = make_unique<BlockedMemoryDesc>(inpBlockingDesc.getPrecision(),
config.inConfs[i].desc = MKLDNNPlugin::make_unique<BlockedMemoryDesc>(inpBlockingDesc.getPrecision(),
inpBlockingDesc.getShape().getStaticDims(),
inpBlockingDesc.getBlockDims(),
inpBlockingDesc.getOrder(),
Expand Down
42 changes: 21 additions & 21 deletions inference-engine/src/mkldnn_plugin/nodes/mkldnn_conv_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ void MKLDNNConvolutionNode::getSupportedDescriptors() {
outputDataType = memory::data_type::f32;
if (eltwisePrecision == Precision::BF16)
eltwisePrecision = Precision::FP32;
in_candidate = make_unique<MKLDNNMemoryDesc>(getParentEdgeAt(0)->getShape().getStaticMklDims(),
in_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(getParentEdgeAt(0)->getShape().getStaticMklDims(),
inputDataType, ndims == 5 ? memory::format_tag::ndhwc : memory::format_tag::nhwc);
out_candidate = make_unique<MKLDNNMemoryDesc>(getChildEdgeAt(0)->getShape().getStaticMklDims(),
out_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(getChildEdgeAt(0)->getShape().getStaticMklDims(),
outputDataType, ndims == 5 ? memory::format_tag::ndhwc : memory::format_tag::nhwc);
createDescriptor({ in_candidate.get() }, { out_candidate.get() });
} else {
Expand Down Expand Up @@ -288,31 +288,31 @@ void MKLDNNConvolutionNode::getSupportedDescriptors() {
auto outputDims = getChildEdgeAt(0)->getShape().getStaticMklDims();

if (IC == 1 && groupOC == 1) {
in_candidate = make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, ncsp);
out_candidate = make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, ncsp);
in_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, ncsp);
out_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, ncsp);
createDescriptor({ in_candidate.get() }, { out_candidate.get() });
} else if (IC < 4) {
in_candidate = make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, ncsp);
out_candidate = make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nCsp16c);
in_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, ncsp);
out_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nCsp16c);
createDescriptor({ in_candidate.get() }, { out_candidate.get() });
out_candidate = make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nCsp8c);
out_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nCsp8c);
createDescriptor({ in_candidate.get() }, { out_candidate.get() });
} else {
in_candidate = make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, nCsp16c);
out_candidate = make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nCsp16c);
in_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, nCsp16c);
out_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nCsp16c);
createDescriptor({ in_candidate.get() }, { out_candidate.get() });
in_candidate = make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, nCsp8c);
out_candidate = make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nCsp8c);
in_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, nCsp8c);
out_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nCsp8c);
createDescriptor({ in_candidate.get() }, { out_candidate.get() });
}

in_candidate = make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, ncsp);
out_candidate = make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, ncsp);
in_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, ncsp);
out_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, ncsp);
createDescriptor({ in_candidate.get() }, { out_candidate.get() });

if (inputDataType != memory::data_type::bf16 && isNspcAvailable()) {
in_candidate = make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, nspc);
out_candidate = make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nspc);
in_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(inputDims, inputDataType, nspc);
out_candidate = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(outputDims, outputDataType, nspc);
createDescriptor({ in_candidate.get() }, { out_candidate.get() });
}
}
Expand Down Expand Up @@ -412,10 +412,10 @@ void MKLDNNConvolutionNode::initSupportedPrimitiveDescriptors() {
PortConfig dataConfig;
dataConfig.inPlace = -1;
dataConfig.constant = false;
dataConfig.desc = make_unique<MKLDNNMemoryDesc>(dwWeightsDims, weightsPrc, memory::format_tag::Goihw8g);
dataConfig.desc = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(dwWeightsDims, weightsPrc, memory::format_tag::Goihw8g);
config.inConfs.push_back(dataConfig);

dataConfig.desc = make_unique<MKLDNNMemoryDesc>(dwBiasesDims, biasPrc, memory::format_tag::x);
dataConfig.desc = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(dwBiasesDims, biasPrc, memory::format_tag::x);
config.inConfs.push_back(dataConfig);
}

Expand Down Expand Up @@ -597,10 +597,10 @@ void MKLDNNConvolutionNode::initDescriptor(const NodeConfig& config) {
PortConfig dataConfig;
dataConfig.inPlace = -1;
dataConfig.constant = false;
dataConfig.desc = make_unique<MKLDNNMemoryDesc>(dwWeightsDims, weightsPrc, memory::format_tag::Goihw8g);
dataConfig.desc = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(dwWeightsDims, weightsPrc, memory::format_tag::Goihw8g);
cfg.inConfs.push_back(dataConfig);

dataConfig.desc = make_unique<MKLDNNMemoryDesc>(dwBiasesDims, biasPrc, memory::format_tag::x);
dataConfig.desc = MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(dwBiasesDims, biasPrc, memory::format_tag::x);
cfg.inConfs.push_back(dataConfig);
}

Expand Down Expand Up @@ -717,9 +717,9 @@ std::unique_ptr<MKLDNNMemoryDesc> MKLDNNConvolutionNode::getSrcMemDesc(mkldnn::p
new_dims.push_back(old_dims[i]);
}

return make_unique<MKLDNNMemoryDesc>(MKLDNNDims(new_dims), desc.getDataType(), desc.getFormat());
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(MKLDNNDims(new_dims), desc.getDataType(), desc.getFormat());
} else {
return make_unique<MKLDNNMemoryDesc>(std::move(desc));
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(std::move(desc));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ void MKLDNNConvertNode::initSupportedPrimitiveDescriptors() {
auto range = BlockedDescCreator::makeFilteredRange(creators, insShape.getRank());

for (auto itr = range.first; itr != range.second; ++itr) {
config.inConfs[0].desc = make_unique<BlockedMemoryDesc>(itr->second->createDesc(insPrecision, insShape.getDims()));
config.outConfs[0].desc = make_unique<BlockedMemoryDesc>(itr->second->createDesc(outPrecision, outputShape.getDims()));
config.inConfs[0].desc = MKLDNNPlugin::make_unique<BlockedMemoryDesc>(itr->second->createDesc(insPrecision, insShape.getDims()));
config.outConfs[0].desc = MKLDNNPlugin::make_unique<BlockedMemoryDesc>(itr->second->createDesc(outPrecision, outputShape.getDims()));

supportedPrimitiveDescriptors.emplace_back(config, impl_desc_type::unknown);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,24 +403,24 @@ void MKLDNNDeconvolutionNode::createDescriptor(const std::vector<const MemoryDes
std::unique_ptr<MKLDNNMemoryDesc> MKLDNNDeconvolutionNode::getSrcMemDesc(mkldnn::primitive_desc_iterator &primitive_desc_it, size_t idx) {
if (idx == 2) {
auto dataType = MKLDNNExtensionUtils::IEPrecisionToDataType(getOriginalInputPrecisionAtPort(2));
return make_unique<MKLDNNMemoryDesc>(getParentEdgeAt(2)->getShape().getStaticMklDims(), dataType,
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(getParentEdgeAt(2)->getShape().getStaticMklDims(), dataType,
MKLDNNMemory::GetPlainFormatByRank(getParentEdgeAt(2)->getShape().getRank()));
}

MKLDNNMemoryDesc desc = idx > 0 ? MKLDNNMemoryDesc(primitive_desc_it.weights_desc(idx - 1))
: isInt8 ? MKLDNNMemoryDesc(primitive_desc_it.src_desc(idx)) : MKLDNNMemoryDesc(primitive_desc_it.diff_dst_desc(idx));

if (getParentEdgeAt(idx)->getShape().getRank() != desc.getShape().getRank()) {
return make_unique<MKLDNNMemoryDesc>(MKLDNNDims(weightDims), desc.getDataType(), desc.getFormat());
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(MKLDNNDims(weightDims), desc.getDataType(), desc.getFormat());
} else {
return make_unique<MKLDNNMemoryDesc>(std::move(desc));
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(std::move(desc));
}
}

std::unique_ptr<MKLDNNMemoryDesc> MKLDNNDeconvolutionNode::getDstMemDesc(mkldnn::primitive_desc_iterator &primitive_desc_it, size_t idx) {
MKLDNNMemoryDesc desc = isInt8 ? MKLDNNMemoryDesc(primitive_desc_it.dst_desc(idx))
: MKLDNNMemoryDesc(primitive_desc_it.diff_src_desc(idx));
return make_unique<MKLDNNMemoryDesc>(getChildEdgeAt(idx)->getShape().getStaticMklDims(), desc.getDataType(), desc.getFormat());
return MKLDNNPlugin::make_unique<MKLDNNMemoryDesc>(getChildEdgeAt(idx)->getShape().getStaticMklDims(), desc.getDataType(), desc.getFormat());
}

InferenceEngine::Precision MKLDNNDeconvolutionNode::getRuntimePrecision() const {
Expand Down
Loading

0 comments on commit 7c3865d

Please sign in to comment.