[CPU] Dynamic shapes. Transpose node. (#7859)
This commit is contained in:
parent
d7fbd6f7ab
commit
2952ba70af
@ -57,6 +57,9 @@ public:
|
|||||||
|
|
||||||
void execute(const uint8_t* src_data, uint8_t* dst_data);
|
void execute(const uint8_t* src_data, uint8_t* dst_data);
|
||||||
void execute(const uint8_t* src_data, uint8_t* dst_data, const int mb);
|
void execute(const uint8_t* src_data, uint8_t* dst_data, const int mb);
|
||||||
|
const PermuteParams& getPermuteParams() const {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void prepareParams();
|
void prepareParams();
|
||||||
|
@ -3,37 +3,26 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "mkldnn_transpose_node.h"
|
#include "mkldnn_transpose_node.h"
|
||||||
|
#include "ie_parallel.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mkldnn_extension_utils.h>
|
|
||||||
#include <mkldnn_selective_build.h>
|
|
||||||
#include "ie_parallel.hpp"
|
|
||||||
#include "utils/bfloat16.hpp"
|
|
||||||
#include <utils/general_utils.h>
|
|
||||||
#include "utils/ngraph_utils.hpp"
|
|
||||||
|
|
||||||
using namespace mkldnn;
|
using namespace mkldnn;
|
||||||
using namespace MKLDNNPlugin;
|
using namespace MKLDNNPlugin;
|
||||||
using namespace InferenceEngine;
|
using namespace InferenceEngine;
|
||||||
|
|
||||||
|
|
||||||
bool MKLDNNTransposeNode::isSupportedOperation(const std::shared_ptr<const ngraph::Node>& op, std::string& errorMessage) noexcept {
|
bool MKLDNNTransposeNode::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept {
|
||||||
try {
|
try {
|
||||||
if (isDynamicNgraphNode(op)) {
|
if (!one_of(op->get_type_info(),
|
||||||
errorMessage = "Doesn't support op with dynamic shapes";
|
ov::op::v1::Transpose::type_info)) {
|
||||||
|
errorMessage = "Node is not an instance of the Transpose operation from opset1.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto transposeOp = ngraph::as_type_ptr<const ngraph::op::v1::Transpose>(op);
|
if (!isDynamicNgraphNode(op) && op->get_input_node_ptr(INPUT_ORDER_IDX)->get_type_info() != ov::op::v0::Constant::type_info) {
|
||||||
if (!transposeOp) {
|
errorMessage = "Constant expected as the second input for static shapes.";
|
||||||
errorMessage = "Node is not an instance of the Transpose operation.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto orderOp = ngraph::as_type_ptr<ngraph::op::Constant>(op->get_input_node_shared_ptr(1));
|
|
||||||
if (!orderOp) {
|
|
||||||
errorMessage = "Constant expected as the second input.";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -42,20 +31,22 @@ bool MKLDNNTransposeNode::isSupportedOperation(const std::shared_ptr<const ngrap
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MKLDNNTransposeNode::MKLDNNTransposeNode(const std::shared_ptr<ngraph::Node>& op, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache)
|
MKLDNNTransposeNode::MKLDNNTransposeNode(const std::shared_ptr<ov::Node>& op, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache)
|
||||||
: MKLDNNNode(op, eng, cache) {
|
: MKLDNNNode(op, eng, cache) {
|
||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
if (!isSupportedOperation(op, errorMessage)) {
|
if (!isSupportedOperation(op, errorMessage)) {
|
||||||
IE_THROW(NotImplemented) << errorMessage;
|
IE_THROW(NotImplemented) << errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto orderOp = ngraph::as_type_ptr<ngraph::op::Constant>(op->get_input_node_shared_ptr(1));
|
if (op->get_input_node_ptr(INPUT_ORDER_IDX)->get_type_info() == ov::op::v0::Constant::type_info) {
|
||||||
order = orderOp->cast_vector<size_t>();
|
constMap[INPUT_ORDER_IDX] = true;
|
||||||
|
order = ov::as_type<ov::op::v0::Constant>(op->get_input_node_ptr(INPUT_ORDER_IDX))->cast_vector<size_t>();
|
||||||
|
|
||||||
if (order.empty()) {
|
if (order.empty()) {
|
||||||
size_t rank = op->get_input_shape(0).size();
|
size_t rank = getInputShapeAtPort(INPUT_DATA_IDX).getRank();
|
||||||
for (size_t i = 1lu; i <= rank; ++i) {
|
for (size_t i = 1lu; i <= rank; ++i) {
|
||||||
order.emplace_back(rank - i);
|
order.emplace_back(rank - i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,24 +66,26 @@ void MKLDNNTransposeNode::initSupportedPrimitiveDescriptors() {
|
|||||||
config.dynBatchSupport = true;
|
config.dynBatchSupport = true;
|
||||||
config.inConfs.resize(2);
|
config.inConfs.resize(2);
|
||||||
config.outConfs.resize(1);
|
config.outConfs.resize(1);
|
||||||
config.inConfs[0].inPlace = -1;
|
config.inConfs[INPUT_DATA_IDX].inPlace = -1;
|
||||||
config.inConfs[0].constant = false;
|
config.inConfs[INPUT_DATA_IDX].constant = false;
|
||||||
|
config.inConfs[INPUT_ORDER_IDX].constant = constMap[INPUT_ORDER_IDX];
|
||||||
|
config.inConfs[INPUT_ORDER_IDX].desc = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(
|
||||||
|
getOriginalInputPrecisionAtPort(INPUT_ORDER_IDX), getInputShapeAtPort(INPUT_ORDER_IDX));
|
||||||
config.outConfs[0].inPlace = -1;
|
config.outConfs[0].inPlace = -1;
|
||||||
config.outConfs[0].constant = false;
|
config.outConfs[0].constant = false;
|
||||||
config.inConfs[1].desc = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(getOriginalInputPrecisionAtPort(1), getInputShapeAtPort(1));
|
|
||||||
|
|
||||||
if (getInputShapeAtPort(0).getRank() == 4 || getInputShapeAtPort(0).getRank() == 5) {
|
if (getInputShapeAtPort(0).getRank() == 4 || getInputShapeAtPort(0).getRank() == 5) {
|
||||||
config.inConfs[0].desc = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(prec, getInputShapeAtPort(0));
|
config.inConfs[0].desc = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(prec, getInputShapeAtPort(0));
|
||||||
config.outConfs[0].desc = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(prec, getOutputShapeAtPort(0));
|
config.outConfs[0].desc = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(prec, getOutputShapeAtPort(0));
|
||||||
supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown});
|
supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown});
|
||||||
|
|
||||||
auto srcDims = getInputShapeAtPort(0).getStaticDims();
|
auto srcDims = getInputShapeAtPort(0).getDims();
|
||||||
if (srcDims[1] % 8 == 0) {
|
if (srcDims[1] != Shape::UNDEFINED_DIM && srcDims[1] % 8 == 0) {
|
||||||
config.inConfs[0].desc = creatorsMap.at(LayoutType::nCsp8c)->createSharedDesc(prec, getInputShapeAtPort(0));
|
config.inConfs[0].desc = creatorsMap.at(LayoutType::nCsp8c)->createSharedDesc(prec, getInputShapeAtPort(0));
|
||||||
supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown});
|
supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (srcDims[1] % 16 == 0) {
|
if (srcDims[1] != Shape::UNDEFINED_DIM && srcDims[1] % 16 == 0) {
|
||||||
config.inConfs[0].desc = creatorsMap.at(LayoutType::nCsp16c)->createSharedDesc(prec, getInputShapeAtPort(0));
|
config.inConfs[0].desc = creatorsMap.at(LayoutType::nCsp16c)->createSharedDesc(prec, getInputShapeAtPort(0));
|
||||||
supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown});
|
supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown});
|
||||||
}
|
}
|
||||||
@ -110,34 +103,55 @@ void MKLDNNTransposeNode::initSupportedPrimitiveDescriptors() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MKLDNNTransposeNode::needPrepareParams() const {
|
||||||
|
if (isOptimized)
|
||||||
|
return false;
|
||||||
|
return MKLDNNNode::needPrepareParams();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MKLDNNTransposeNode::prepareParams() {
|
||||||
|
auto srcDesc = getParentEdgeAt(INPUT_DATA_IDX)->getMemory().GetDescWithType<BlockedMemoryDesc>();
|
||||||
|
params.src_block_dims = srcDesc->getBlockDims();
|
||||||
|
auto dstDesc = getChildEdgeAt(0)->getMemory().GetDescWithType<BlockedMemoryDesc>();
|
||||||
|
params.dst_block_dims = dstDesc->getBlockDims();
|
||||||
|
if (!constMap[INPUT_ORDER_IDX]) {
|
||||||
|
auto orderPtr = reinterpret_cast<const int32_t*>(getParentEdgeAt(0)->getMemoryPtr()->GetPtr());
|
||||||
|
auto orderLen = getParentEdgeAt(0)->getMemoryPtr()->GetSize();
|
||||||
|
params.order.assign(orderPtr, orderPtr + orderLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
execPtr = std::make_shared<TransposeJitExecutor>(params);
|
||||||
|
}
|
||||||
|
|
||||||
void MKLDNNTransposeNode::createPrimitive() {
|
void MKLDNNTransposeNode::createPrimitive() {
|
||||||
auto& dstMemPtr = getChildEdgeAt(0)->getMemoryPtr();
|
auto& dstMemPtr = getChildEdgeAt(0)->getMemoryPtr();
|
||||||
auto& srcMemPtr = getParentEdgeAt(0)->getMemoryPtr();
|
auto& srcMemPtr = getParentEdgeAt(INPUT_DATA_IDX)->getMemoryPtr();
|
||||||
if (!dstMemPtr || !dstMemPtr->GetPrimitivePtr())
|
if (!dstMemPtr || !dstMemPtr->GetPrimitivePtr())
|
||||||
IE_THROW() << "Destination memory didn't allocate.";
|
IE_THROW() << "Destination memory was not allocated.";
|
||||||
if (!srcMemPtr || !srcMemPtr->GetPrimitivePtr())
|
if (!srcMemPtr || !srcMemPtr->GetPrimitivePtr())
|
||||||
IE_THROW() << "Input memory didn't allocate.";
|
IE_THROW() << "Input memory was not allocated.";
|
||||||
if (getSelectedPrimitiveDescriptor() == nullptr)
|
if (getSelectedPrimitiveDescriptor() == nullptr)
|
||||||
IE_THROW() << "Preferable primitive descriptor is not set.";
|
IE_THROW() << "Preferable primitive descriptor was not set.";
|
||||||
|
|
||||||
if (getParentEdgeAt(0)->getMemory().getDesc().hasLayoutType(LayoutType::ncsp) &&
|
if (getParentEdgeAt(INPUT_DATA_IDX)->getMemory().getDesc().hasLayoutType(LayoutType::ncsp) &&
|
||||||
std::find(optimizedOrders.begin(), optimizedOrders.end(), order) != optimizedOrders.end()) {
|
std::find(optimizedOrders.begin(), optimizedOrders.end(), order) != optimizedOrders.end()) {
|
||||||
isOptimized = true;
|
isOptimized = true;
|
||||||
|
execPtr = std::make_shared<TransposeRefExecutor>();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PermuteParams params;
|
|
||||||
params.data_size = getSelectedPrimitiveDescriptor()->getConfig().inConfs[0].desc->getPrecision().size();
|
params.data_size = getSelectedPrimitiveDescriptor()->getConfig().inConfs[0].desc->getPrecision().size();
|
||||||
params.order = order;
|
if (constMap[INPUT_ORDER_IDX])
|
||||||
auto srcDesc = getParentEdgeAt(0)->getMemory().GetDescWithType<BlockedMemoryDesc>();
|
params.order = order;
|
||||||
params.src_block_dims = srcDesc->getBlockDims();
|
auto srcDesc = getParentEdgeAt(INPUT_DATA_IDX)->getMemory().GetDescWithType<BlockedMemoryDesc>();
|
||||||
params.src_block_order = srcDesc->getOrder();
|
params.src_block_order = srcDesc->getOrder();
|
||||||
|
|
||||||
auto dstDesc = getChildEdgeAt(0)->getMemory().GetDescWithType<BlockedMemoryDesc>();
|
auto dstDesc = getChildEdgeAt(0)->getMemory().GetDescWithType<BlockedMemoryDesc>();
|
||||||
params.dst_block_dims = dstDesc->getBlockDims();
|
|
||||||
params.dst_block_order = dstDesc->getOrder();
|
params.dst_block_order = dstDesc->getOrder();
|
||||||
|
|
||||||
permuteKernel = std::unique_ptr<PermuteKernel>(new PermuteKernel(params));
|
if (inputShapesDefined()) {
|
||||||
|
prepareParams();
|
||||||
|
updateLastInputDims();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -242,27 +256,52 @@ void MKLDNNTransposeNode::optimizedExecute(const int MB, const MKLDNNMemoryPtr&
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MKLDNNTransposeNode::execute(mkldnn::stream strm) {
|
void MKLDNNTransposeNode::execute(mkldnn::stream strm) {
|
||||||
auto &dstMemPtr = getChildEdgeAt(0)->getMemoryPtr();
|
if (execPtr) {
|
||||||
auto &srcMemPtr = getParentEdgeAt(0)->getMemoryPtr();
|
auto &dstMemPtr = getChildEdgeAt(0)->getMemoryPtr();
|
||||||
int MB = batchToProcess();
|
auto &srcMemPtr = getParentEdgeAt(INPUT_DATA_IDX)->getMemoryPtr();
|
||||||
|
|
||||||
if (isOptimized) {
|
int MB = 0;
|
||||||
const size_t dataSize = getParentEdgeAt(0)->getMemory().getDesc().getPrecision().size();
|
if (isDynamicNode()) {
|
||||||
TransposeContext ctx = {this, srcMemPtr, dstMemPtr, MB};
|
MB = srcMemPtr->getStaticDims()[0];
|
||||||
OV_SWITCH(MKLDNNPlugin, TransposeOptimizedEmitter, ctx, dataSize,
|
} else {
|
||||||
OV_CASE(1, PrecisionTrait<Precision::U8>::value_type),
|
MB = batchToProcess();
|
||||||
OV_CASE(2, PrecisionTrait<Precision::U16>::value_type),
|
}
|
||||||
OV_CASE(4, PrecisionTrait<Precision::I32>::value_type));
|
|
||||||
|
|
||||||
return;
|
execPtr->exec(this, srcMemPtr, dstMemPtr, MB);
|
||||||
|
} else {
|
||||||
|
IE_THROW() << "Could not execute Transpose node. Primitive was not created.";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MKLDNNTransposeNode::executeDynamicImpl(mkldnn::stream strm) {
|
||||||
|
execute(strm);
|
||||||
|
}
|
||||||
|
|
||||||
|
MKLDNNTransposeNode::TransposeJitExecutor::TransposeJitExecutor(const PermuteParams& params) {
|
||||||
|
pKernel = std::make_shared<PermuteKernel>(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MKLDNNTransposeNode::TransposeJitExecutor::exec(MKLDNNTransposeNode* node, MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr, const int MB) {
|
||||||
|
if (!pKernel)
|
||||||
|
IE_THROW() << "Could not execute. Kernel for Transpose node was not compiled.";
|
||||||
|
|
||||||
const uint8_t* srcData = reinterpret_cast<const uint8_t*>(srcMemPtr->GetPtr());
|
const uint8_t* srcData = reinterpret_cast<const uint8_t*>(srcMemPtr->GetPtr());
|
||||||
uint8_t* dstData = reinterpret_cast<uint8_t*>(dstMemPtr->GetPtr());
|
uint8_t* dstData = reinterpret_cast<uint8_t*>(dstMemPtr->GetPtr());
|
||||||
permuteKernel->execute(srcData, dstData, MB);
|
|
||||||
|
pKernel->execute(srcData, dstData, MB);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MKLDNNTransposeNode::TransposeRefExecutor::exec(MKLDNNTransposeNode* node, MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr, const int MB) {
|
||||||
|
const size_t dataSize = srcMemPtr->getDesc().getPrecision().size();
|
||||||
|
TransposeContext ctx = {node, srcMemPtr, dstMemPtr, MB};
|
||||||
|
OV_SWITCH(MKLDNNPlugin, TransposeOptimizedEmitter, ctx, dataSize,
|
||||||
|
OV_CASE(1, PrecisionTrait<Precision::U8>::value_type),
|
||||||
|
OV_CASE(2, PrecisionTrait<Precision::U16>::value_type),
|
||||||
|
OV_CASE(4, PrecisionTrait<Precision::I32>::value_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MKLDNNTransposeNode::created() const {
|
bool MKLDNNTransposeNode::created() const {
|
||||||
return getType() == Transpose;
|
return getType() == Transpose;
|
||||||
}
|
}
|
||||||
|
|
||||||
REG_MKLDNN_PRIM_FOR(MKLDNNTransposeNode, Transpose);
|
REG_MKLDNN_PRIM_FOR(MKLDNNTransposeNode, Transpose);
|
||||||
|
@ -4,15 +4,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ie_common.h>
|
|
||||||
#include <mkldnn_node.h>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <utility>
|
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
|
||||||
#include "common/permute_kernel.h"
|
#include "common/permute_kernel.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace MKLDNNPlugin {
|
namespace MKLDNNPlugin {
|
||||||
|
|
||||||
class MKLDNNTransposeNode : public MKLDNNNode {
|
class MKLDNNTransposeNode : public MKLDNNNode {
|
||||||
@ -33,7 +31,33 @@ public:
|
|||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool needPrepareParams() const override;
|
||||||
|
void prepareParams() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void executeDynamicImpl(mkldnn::stream strm) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct TransposeExecutor {
|
||||||
|
TransposeExecutor() = default;
|
||||||
|
virtual void exec(MKLDNNTransposeNode* node, MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr, const int MB) = 0;
|
||||||
|
virtual ~TransposeExecutor() = default;
|
||||||
|
};
|
||||||
|
using executorPtr = std::shared_ptr<TransposeExecutor>;
|
||||||
|
executorPtr execPtr = nullptr;
|
||||||
|
|
||||||
|
struct TransposeJitExecutor : public TransposeExecutor {
|
||||||
|
TransposeJitExecutor(const PermuteParams& params);
|
||||||
|
void exec(MKLDNNTransposeNode* node, MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr, const int MB) override;
|
||||||
|
|
||||||
|
std::shared_ptr<PermuteKernel> pKernel;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TransposeRefExecutor : public TransposeExecutor {
|
||||||
|
TransposeRefExecutor() = default;
|
||||||
|
void exec(MKLDNNTransposeNode* node, MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr, const int MB) override;
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T> void optimizedExecute(const int MB, const MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr);
|
template<typename T> void optimizedExecute(const int MB, const MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr);
|
||||||
|
|
||||||
InferenceEngine::SizeVector order;
|
InferenceEngine::SizeVector order;
|
||||||
@ -46,7 +70,7 @@ private:
|
|||||||
std::vector<size_t>{0, 5, 1, 2, 3, 4},
|
std::vector<size_t>{0, 5, 1, 2, 3, 4},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<PermuteKernel> permuteKernel;
|
PermuteParams params;
|
||||||
|
|
||||||
struct TransposeContext {
|
struct TransposeContext {
|
||||||
MKLDNNTransposeNode* nodePtr;
|
MKLDNNTransposeNode* nodePtr;
|
||||||
@ -61,7 +85,11 @@ private:
|
|||||||
ctx.nodePtr->optimizedExecute<T>(ctx.MB, ctx.srcMemPtr, ctx.dstMemPtr);
|
ctx.nodePtr->optimizedExecute<T>(ctx.MB, ctx.srcMemPtr, ctx.dstMemPtr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool constMap[3] = { false };
|
||||||
|
|
||||||
|
static constexpr size_t INPUT_DATA_IDX = 0lu;
|
||||||
|
static constexpr size_t INPUT_ORDER_IDX = 1lu;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace MKLDNNPlugin
|
} // namespace MKLDNNPlugin
|
||||||
|
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <shared_test_classes/single_layer/transpose.hpp>
|
|
||||||
#include "ngraph_functions/builders.hpp"
|
|
||||||
#include "test_utils/cpu_test_utils.hpp"
|
#include "test_utils/cpu_test_utils.hpp"
|
||||||
|
#include "ngraph_functions/builders.hpp"
|
||||||
|
|
||||||
// Since the Transpose ngraph operation is converted to the transpose node, we will use it in the transpose test
|
// Since the Transpose ngraph operation is converted to the transpose node, we will use it in the transpose test
|
||||||
|
|
||||||
@ -13,11 +12,13 @@ using namespace CPUTestUtils;
|
|||||||
|
|
||||||
namespace CPULayerTestsDefinitions {
|
namespace CPULayerTestsDefinitions {
|
||||||
|
|
||||||
|
using inputShapesPair = std::pair<std::vector<ov::PartialShape>, std::vector<std::vector<ov::Shape>>>;
|
||||||
|
|
||||||
typedef std::tuple<
|
typedef std::tuple<
|
||||||
std::vector<size_t>, // Input order
|
inputShapesPair, // Input shapes
|
||||||
InferenceEngine::Precision, // Net precision
|
std::vector<size_t>, // Input order
|
||||||
std::vector<size_t>, // Input shapes
|
InferenceEngine::Precision, // Net precision
|
||||||
std::string, // Target device name
|
std::string, // Target device name
|
||||||
std::map<std::string, std::string>, // Additional network configuration
|
std::map<std::string, std::string>, // Additional network configuration
|
||||||
CPUSpecificParams> TransposeLayerCPUTestParamSet;
|
CPUSpecificParams> TransposeLayerCPUTestParamSet;
|
||||||
|
|
||||||
@ -26,14 +27,16 @@ class TransposeLayerCPUTest : public testing::WithParamInterface<TransposeLayerC
|
|||||||
public:
|
public:
|
||||||
static std::string getTestCaseName(testing::TestParamInfo<TransposeLayerCPUTestParamSet> obj) {
|
static std::string getTestCaseName(testing::TestParamInfo<TransposeLayerCPUTestParamSet> obj) {
|
||||||
Precision netPrecision;
|
Precision netPrecision;
|
||||||
std::vector<size_t> inputShape, inputOrder;
|
inputShapesPair inputShapes;
|
||||||
|
std::vector<size_t> inputOrder;
|
||||||
std::string targetDevice;
|
std::string targetDevice;
|
||||||
CPUSpecificParams cpuParams;
|
CPUSpecificParams cpuParams;
|
||||||
std::map<std::string, std::string> additionalConfig;
|
std::map<std::string, std::string> additionalConfig;
|
||||||
std::tie(inputOrder, netPrecision, inputShape, targetDevice, additionalConfig, cpuParams) = obj.param;
|
std::tie(inputShapes, inputOrder, netPrecision, targetDevice, additionalConfig, cpuParams) = obj.param;
|
||||||
|
|
||||||
std::ostringstream result;
|
std::ostringstream result;
|
||||||
result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_";
|
result << "DynShapes=" << CommonTestUtils::partialShape2str(inputShapes.first) << "_";
|
||||||
|
result << "StatShapes=" << CommonTestUtils::vec2str(inputShapes.second) << "_";
|
||||||
result << "inputOrder=" << CommonTestUtils::vec2str(inputOrder) << "_";
|
result << "inputOrder=" << CommonTestUtils::vec2str(inputOrder) << "_";
|
||||||
result << "netPRC=" << netPrecision.name() << "_";
|
result << "netPRC=" << netPrecision.name() << "_";
|
||||||
result << "trgDev=" << targetDevice;
|
result << "trgDev=" << targetDevice;
|
||||||
@ -43,10 +46,11 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
Precision netPrecision;
|
Precision netPrecision;
|
||||||
std::vector<size_t> inputShape, inputOrder;
|
inputShapesPair inputShapes;
|
||||||
|
std::vector<size_t> inputOrder;
|
||||||
CPUSpecificParams cpuParams;
|
CPUSpecificParams cpuParams;
|
||||||
std::map<std::string, std::string> additionalConfig;
|
std::map<std::string, std::string> additionalConfig;
|
||||||
std::tie(inputOrder, netPrecision, inputShape, targetDevice, additionalConfig, cpuParams) = this->GetParam();
|
std::tie(inputShapes, inputOrder, netPrecision, targetDevice, additionalConfig, cpuParams) = this->GetParam();
|
||||||
configuration.insert(additionalConfig.begin(), additionalConfig.end());
|
configuration.insert(additionalConfig.begin(), additionalConfig.end());
|
||||||
inPrc = outPrc = netPrecision; // since the layer does not convert precisions
|
inPrc = outPrc = netPrecision; // since the layer does not convert precisions
|
||||||
|
|
||||||
@ -54,19 +58,27 @@ protected:
|
|||||||
|
|
||||||
selectedType = std::string("unknown_") + inPrc.name();
|
selectedType = std::string("unknown_") + inPrc.name();
|
||||||
|
|
||||||
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
|
targetStaticShapes.reserve(inputShapes.second.size());
|
||||||
auto params = ngraph::builder::makeParams(ngPrc, {inputShape});
|
for (const auto& staticShape : inputShapes.second) {
|
||||||
auto paramOuts = ngraph::helpers::convert2OutputVector(
|
targetStaticShapes.push_back({staticShape});
|
||||||
ngraph::helpers::castOps2Nodes<ngraph::op::Parameter>(params));
|
}
|
||||||
|
inputDynamicShapes = { inputShapes.first };
|
||||||
|
|
||||||
const auto inOrderShape = inputOrder.empty() ? ngraph::Shape({0}) : ngraph::Shape({inputShape.size()});
|
ov::Shape inputDataShape = targetStaticShapes.front().front();
|
||||||
const auto inputOrderOp = std::make_shared<ngraph::opset3::Constant>(ngraph::element::i64,
|
|
||||||
|
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
|
||||||
|
auto params = ngraph::builder::makeParams(ngPrc, {inputDataShape});
|
||||||
|
auto paramOuts = ngraph::helpers::convert2OutputVector(
|
||||||
|
ngraph::helpers::castOps2Nodes<ov::op::v0::Parameter>(params));
|
||||||
|
|
||||||
|
const auto inOrderShape = inputOrder.empty() ? ov::Shape({0}) : ov::Shape({inputDataShape.size()});
|
||||||
|
const auto inputOrderOp = std::make_shared<ov::op::v0::Constant>(ov::element::i64,
|
||||||
inOrderShape,
|
inOrderShape,
|
||||||
inputOrder);
|
inputOrder);
|
||||||
const auto transpose = std::make_shared<ngraph::opset3::Transpose>(paramOuts.at(0), inputOrderOp);
|
const auto transpose = std::make_shared<ov::op::v1::Transpose>(paramOuts.at(0), inputOrderOp);
|
||||||
transpose->get_rt_info() = getCPUInfo();
|
transpose->get_rt_info() = getCPUInfo();
|
||||||
const ngraph::ResultVector results{std::make_shared<ngraph::opset3::Result>(transpose)};
|
const ov::ResultVector results{std::make_shared<ov::op::v0::Result>(transpose)};
|
||||||
function = std::make_shared<ngraph::Function>(results, params, "Transpose");
|
function = std::make_shared<ov::Function>(results, params, "Transpose");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -103,8 +115,13 @@ const std::vector<InferenceEngine::Precision> netPrecisionsPerChannels = {
|
|||||||
Precision::FP32
|
Precision::FP32
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<std::vector<size_t>> inputShapes4D = {
|
const std::vector<inputShapesPair>
|
||||||
{2, 32, 10, 20}
|
staticInputShapes4D = {
|
||||||
|
{{}, {{{2, 32, 10, 20}}}}
|
||||||
|
};
|
||||||
|
const std::vector<inputShapesPair>
|
||||||
|
dynamicInputShapes4D = {
|
||||||
|
{{{2, ov::Dimension(20, 40), 10, 20}}, {{{2, 32, 10, 20}, {2, 10, 10, 20}}}}
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<std::vector<size_t>> inputOrder4D = {
|
const std::vector<std::vector<size_t>> inputOrder4D = {
|
||||||
@ -128,28 +145,53 @@ const std::vector<CPUSpecificParams> CPUParams4D = {
|
|||||||
cpuParams_nchw,
|
cpuParams_nchw,
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto params4D = ::testing::Combine(
|
INSTANTIATE_TEST_SUITE_P(smoke_staticShapes4D_Transpose, TransposeLayerCPUTest,
|
||||||
::testing::ValuesIn(inputOrder4D),
|
::testing::Combine(
|
||||||
::testing::ValuesIn(netPrecisions),
|
::testing::ValuesIn(staticInputShapes4D),
|
||||||
::testing::ValuesIn(inputShapes4D),
|
::testing::ValuesIn(inputOrder4D),
|
||||||
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
::testing::ValuesIn(netPrecisions),
|
||||||
::testing::Values(additional_config),
|
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
||||||
::testing::ValuesIn(CPUParams4D));
|
::testing::Values(additional_config),
|
||||||
|
::testing::ValuesIn(CPUParams4D)),
|
||||||
|
TransposeLayerCPUTest::getTestCaseName);
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(smoke_Transpose4D_CPU, TransposeLayerCPUTest, params4D, TransposeLayerCPUTest::getTestCaseName);
|
INSTANTIATE_TEST_SUITE_P(smoke_dynamicShapes4D_Transpose, TransposeLayerCPUTest,
|
||||||
|
::testing::Combine(
|
||||||
|
::testing::ValuesIn(dynamicInputShapes4D),
|
||||||
|
::testing::ValuesIn(inputOrder4D),
|
||||||
|
::testing::ValuesIn(netPrecisions),
|
||||||
|
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
||||||
|
::testing::Values(additional_config),
|
||||||
|
::testing::ValuesIn(std::vector<CPUSpecificParams>{})),
|
||||||
|
TransposeLayerCPUTest::getTestCaseName);
|
||||||
|
|
||||||
const auto paramsPerChannels4D = ::testing::Combine(
|
INSTANTIATE_TEST_SUITE_P(smoke_staticShapes4D_PermutePerChannels, TransposeLayerCPUTest,
|
||||||
::testing::ValuesIn(inputOrderPerChannels4D),
|
::testing::Combine(
|
||||||
::testing::ValuesIn(netPrecisionsPerChannels),
|
::testing::ValuesIn(staticInputShapes4D),
|
||||||
::testing::ValuesIn(inputShapes4D),
|
::testing::ValuesIn(inputOrderPerChannels4D),
|
||||||
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
::testing::ValuesIn(netPrecisionsPerChannels),
|
||||||
::testing::Values(additional_config),
|
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
||||||
::testing::Values(cpuParams_nhwc));
|
::testing::Values(additional_config),
|
||||||
|
::testing::Values(cpuParams_nhwc)),
|
||||||
|
TransposeLayerCPUTest::getTestCaseName);
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(smoke_PermutePerChannels4D_CPU, TransposeLayerCPUTest, paramsPerChannels4D, TransposeLayerCPUTest::getTestCaseName);
|
INSTANTIATE_TEST_SUITE_P(smoke_dynamicShapes4D_PermutePerChannels, TransposeLayerCPUTest,
|
||||||
|
::testing::Combine(
|
||||||
|
::testing::ValuesIn(dynamicInputShapes4D),
|
||||||
|
::testing::ValuesIn(inputOrderPerChannels4D),
|
||||||
|
::testing::ValuesIn(netPrecisionsPerChannels),
|
||||||
|
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
||||||
|
::testing::Values(additional_config),
|
||||||
|
::testing::Values(cpuParams_nhwc)),
|
||||||
|
TransposeLayerCPUTest::getTestCaseName);
|
||||||
|
|
||||||
const std::vector<std::vector<size_t>> inputShapes5D = {
|
const std::vector<inputShapesPair>
|
||||||
{2, 32, 5, 10, 20}
|
staticInputShapes5D = {
|
||||||
|
{{}, {{{2, 32, 5, 10, 20}}}}
|
||||||
|
};
|
||||||
|
const std::vector<inputShapesPair>
|
||||||
|
dynamicInputShapes5D = {
|
||||||
|
{{{2, ov::Dimension(20, 40), 5, 10, 20}}, {{{2, 32, 5, 10, 20}, {2, 20, 5, 10, 20}}}}
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<std::vector<size_t>> inputOrder5D = {
|
const std::vector<std::vector<size_t>> inputOrder5D = {
|
||||||
@ -181,25 +223,45 @@ const std::vector<CPUSpecificParams> CPUParams5D = {
|
|||||||
cpuParams_ncdhw,
|
cpuParams_ncdhw,
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto params5D = ::testing::Combine(
|
INSTANTIATE_TEST_SUITE_P(smoke_staticShapes5D_Transpose, TransposeLayerCPUTest,
|
||||||
::testing::ValuesIn(inputOrder5D),
|
::testing::Combine(
|
||||||
::testing::ValuesIn(netPrecisions),
|
::testing::ValuesIn(staticInputShapes5D),
|
||||||
::testing::ValuesIn(inputShapes5D),
|
::testing::ValuesIn(inputOrder5D),
|
||||||
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
::testing::ValuesIn(netPrecisions),
|
||||||
::testing::Values(additional_config),
|
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
||||||
::testing::ValuesIn(CPUParams5D));
|
::testing::Values(additional_config),
|
||||||
|
::testing::ValuesIn(CPUParams5D)),
|
||||||
|
TransposeLayerCPUTest::getTestCaseName);
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(smoke_Transpose5D_CPU, TransposeLayerCPUTest, params5D, TransposeLayerCPUTest::getTestCaseName);
|
INSTANTIATE_TEST_SUITE_P(smoke_dynamicShapes5D_Transpose, TransposeLayerCPUTest,
|
||||||
|
::testing::Combine(
|
||||||
|
::testing::ValuesIn(dynamicInputShapes5D),
|
||||||
|
::testing::ValuesIn(inputOrder5D),
|
||||||
|
::testing::ValuesIn(netPrecisions),
|
||||||
|
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
||||||
|
::testing::Values(additional_config),
|
||||||
|
::testing::ValuesIn(std::vector<CPUSpecificParams>{})),
|
||||||
|
TransposeLayerCPUTest::getTestCaseName);
|
||||||
|
|
||||||
const auto paramsPerChannels5D = ::testing::Combine(
|
INSTANTIATE_TEST_SUITE_P(smoke_staticShapes5D_PermutePerChannels, TransposeLayerCPUTest,
|
||||||
::testing::ValuesIn(inputOrderPerChannels5D),
|
::testing::Combine(
|
||||||
::testing::ValuesIn(netPrecisionsPerChannels),
|
::testing::ValuesIn(staticInputShapes5D),
|
||||||
::testing::ValuesIn(inputShapes5D),
|
::testing::ValuesIn(inputOrderPerChannels5D),
|
||||||
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
::testing::ValuesIn(netPrecisionsPerChannels),
|
||||||
::testing::Values(additional_config),
|
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
||||||
::testing::Values(cpuParams_ndhwc));
|
::testing::Values(additional_config),
|
||||||
|
::testing::Values(cpuParams_ndhwc)),
|
||||||
|
TransposeLayerCPUTest::getTestCaseName);
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(smoke_PermutePerChannels5D_CPU, TransposeLayerCPUTest, paramsPerChannels5D, TransposeLayerCPUTest::getTestCaseName);
|
INSTANTIATE_TEST_SUITE_P(smoke_dynamicShapes5D_PermutePerChannels, TransposeLayerCPUTest,
|
||||||
|
::testing::Combine(
|
||||||
|
::testing::ValuesIn(dynamicInputShapes5D),
|
||||||
|
::testing::ValuesIn(inputOrderPerChannels5D),
|
||||||
|
::testing::ValuesIn(netPrecisionsPerChannels),
|
||||||
|
::testing::Values(CommonTestUtils::DEVICE_CPU),
|
||||||
|
::testing::Values(additional_config),
|
||||||
|
::testing::Values(cpuParams_ndhwc)),
|
||||||
|
TransposeLayerCPUTest::getTestCaseName);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace CPULayerTestsDefinitions
|
} // namespace CPULayerTestsDefinitions
|
||||||
|
Loading…
Reference in New Issue
Block a user