diff --git a/src/plugins/intel_cpu/src/nodes/executors/debug_messages.hpp b/src/plugins/intel_cpu/src/nodes/executors/debug_messages.hpp index 26ae6ace59631b..6bb267204ed6a6 100644 --- a/src/plugins/intel_cpu/src/nodes/executors/debug_messages.hpp +++ b/src/plugins/intel_cpu/src/nodes/executors/debug_messages.hpp @@ -7,6 +7,7 @@ #define UNSUPPORTED_SPARSE_WEIGHTS " sparse weights are not supported" #define UNSUPPORTED_WEIGHTS_DECOMPRESSION " weights decompression is not supported" #define UNSUPPORTED_POST_OPS " post ops are not supported" +#define UNSUPPORTED_LAYOUT " layout are not supported" #define UNSUPPORTED_NUMBER_OF_POSTOPS " the number of post ops is not supported" #define UNSUPPORTED_TYPE_OF_POSTOPS " the type of post ops is not supported" #define UNSUPPORTED_SRC_PRECISIONS " unsupported src precisions" diff --git a/src/plugins/intel_cpu/src/nodes/executors/mvn_implementations.cpp b/src/plugins/intel_cpu/src/nodes/executors/mvn_implementations.cpp index a159bd89d2ea57..806be6af126ad3 100644 --- a/src/plugins/intel_cpu/src/nodes/executors/mvn_implementations.cpp +++ b/src/plugins/intel_cpu/src/nodes/executors/mvn_implementations.cpp @@ -124,27 +124,29 @@ ov::optional> requiresFallbackCommon(const executor::Con return ov::optional>(MVNConfig {optimalDescriptors, config.attrs, config.postOps}); } -OV_CPU_MAYBE_UNUSED_FUNCTION static inline bool noPostOps(const MVNConfig& config) { - return config.postOps.empty(); +OV_CPU_MAYBE_UNUSED_FUNCTION static inline bool noLayout(const MVNConfig& config, const LayoutType& layoutType) { + return config.descs.at(ARG_SRC)->hasLayoutType(layoutType); } template <> const std::vector>& getImplementations() { static const std::vector> mvnImplementations { OV_CPU_INSTANCE_X64( - "mvn_jit_x64_ncsp", + "mvn_jit_x64_nspc", ExecutorType::jit_x64, OperationType::MVN, ShapeTolerance::Agnostic, // supports [](const MVNConfig& config) -> bool { + VERIFY(noLayout(config, LayoutType::nspc), UNSUPPORTED_LAYOUT); + VERIFY(one_of(srcRank(config), 4lu, 5lu), UNSUPPORTED_SRC_RANK); return JITMVNExecutor::supports(config); }, // requiresFallback [](const MVNConfig& config) -> ov::optional> { return requiresFallbackCommon(config, jitMVNTypeMapping, - {LayoutType::ncsp, LayoutType::ncsp}, + {LayoutType::nspc, LayoutType::nspc}, mvnMappingNotation); }, // acceptsShapes @@ -160,19 +162,82 @@ const std::vector>& getImplementations() { return std::make_shared(attrs, postOps, memory, context); }) OV_CPU_INSTANCE_X64( - "mvn_jit_x64_nspc", + "mvn_jit_x64_nCsp16c", + ExecutorType::jit_x64, + OperationType::MVN, + ShapeTolerance::Agnostic, + // supports + [](const MVNConfig& config) -> bool { + VERIFY(noLayout(config, LayoutType::nCsp16c), UNSUPPORTED_LAYOUT); + VERIFY(one_of(srcRank(config), 4lu, 5lu), UNSUPPORTED_SRC_RANK); + VERIFY(mayiuse(cpu::x64::avx512_core), UNSUPPORTED_ISA); + return JITMVNExecutor::supports(config); + }, + // requiresFallback + [](const MVNConfig& config) -> ov::optional> { + return requiresFallbackCommon(config, + jitMVNTypeMapping, + {LayoutType::nCsp16c, LayoutType::nCsp16c}, + mvnMappingNotation); + }, + // acceptsShapes + [](const MemoryArgs& memory) -> bool { + // @todo create syntactic sugar (functor) for shape agnostic lambda + return true; + }, + // create + [](const MVNAttrs& attrs, + const PostOps& postOps, + const MemoryArgs& memory, + const ExecutorContext::CPtr context) { + return std::make_shared(attrs, postOps, memory, context); + }) + OV_CPU_INSTANCE_X64( + "mvn_jit_x64_nCsp8c", ExecutorType::jit_x64, OperationType::MVN, ShapeTolerance::Agnostic, // supports [](const MVNConfig& config) -> bool { + VERIFY(noLayout(config, LayoutType::nCsp8c), UNSUPPORTED_LAYOUT); + VERIFY(one_of(srcRank(config), 4lu, 5lu), UNSUPPORTED_SRC_RANK); + VERIFY(mayiuse(cpu::x64::avx2) || mayiuse(cpu::x64::sse41), UNSUPPORTED_ISA); return JITMVNExecutor::supports(config); }, // requiresFallback [](const MVNConfig& config) -> ov::optional> { return requiresFallbackCommon(config, jitMVNTypeMapping, - {LayoutType::nspc, LayoutType::nspc}, + {LayoutType::nCsp8c, LayoutType::nCsp8c}, + mvnMappingNotation); + }, + // acceptsShapes + [](const MemoryArgs& memory) -> bool { + // @todo create syntactic sugar (functor) for shape agnostic lambda + return true; + }, + // create + [](const MVNAttrs& attrs, + const PostOps& postOps, + const MemoryArgs& memory, + const ExecutorContext::CPtr context) { + return std::make_shared(attrs, postOps, memory, context); + }) + OV_CPU_INSTANCE_X64( + "mvn_jit_x64_ncsp", + ExecutorType::jit_x64, + OperationType::MVN, + ShapeTolerance::Agnostic, + // supports + [](const MVNConfig& config) -> bool { + VERIFY(noLayout(config, LayoutType::ncsp), UNSUPPORTED_LAYOUT); + return JITMVNExecutor::supports(config); + }, + // requiresFallback + [](const MVNConfig& config) -> ov::optional> { + return requiresFallbackCommon(config, + jitMVNTypeMapping, + {LayoutType::ncsp, LayoutType::ncsp}, mvnMappingNotation); }, // acceptsShapes @@ -194,7 +259,7 @@ const std::vector>& getImplementations() { ShapeTolerance::Agnostic, // supports [](const MVNConfig& config) -> bool { - if (!config.descs.at(ARG_SRC)->hasLayoutType(LayoutType::nspc)) return false; + VERIFY(noLayout(config, LayoutType::nspc), UNSUPPORTED_LAYOUT); return ACLMVNExecutor::supports(config); }, // requiresFallback @@ -223,7 +288,7 @@ const std::vector>& getImplementations() { ShapeTolerance::Agnostic, // supports [](const MVNConfig& config) -> bool { - if (!config.descs.at(ARG_SRC)->hasLayoutType(LayoutType::ncsp)) return false; + VERIFY(noLayout(config, LayoutType::ncsp), UNSUPPORTED_LAYOUT); return ACLMVNExecutor::supports(config); }, // requiresFallback @@ -252,7 +317,7 @@ const std::vector>& getImplementations() { ShapeTolerance::Agnostic, // supports [](const MVNConfig& config) -> bool { - if (!config.descs.at(ARG_SRC)->hasLayoutType(LayoutType::ncsp)) return false; + VERIFY(noLayout(config, LayoutType::ncsp), UNSUPPORTED_LAYOUT); return CommonMVNExecutor::supports(config); }, // requiresFallback @@ -281,7 +346,7 @@ const std::vector>& getImplementations() { ShapeTolerance::Agnostic, // supports [](const MVNConfig& config) -> bool { - if (!config.descs.at(ARG_SRC)->hasLayoutType(LayoutType::nspc)) return false; + VERIFY(noLayout(config, LayoutType::nspc), UNSUPPORTED_LAYOUT); return CommonMVNExecutor::supports(config); }, // requiresFallback diff --git a/src/plugins/intel_cpu/src/nodes/mvn.cpp b/src/plugins/intel_cpu/src/nodes/mvn.cpp index 61d1860ae0ca5e..11ed9ee3bac3aa 100644 --- a/src/plugins/intel_cpu/src/nodes/mvn.cpp +++ b/src/plugins/intel_cpu/src/nodes/mvn.cpp @@ -221,6 +221,7 @@ void MVN::initSupportedPrimitiveDescriptors() { if (!fusedWith.empty()) dstTypes = fusedWith.back()->getOriginalOutputPrecisions(); + VecMemoryDescs srcDescs; const auto& creatorsMap = BlockedDescCreator::getCommonCreators(); for (size_t i = 0; i < srcTypes.size(); i++) { @@ -239,6 +240,10 @@ void MVN::initSupportedPrimitiveDescriptors() { {ARG_DST, dstDescs[0]}, }; + if (one_of(descs.at(ARG_SRC)->getShape().getRank(), 1lu, 2lu) && mvnAttrs.initAcrossChannels_) { + mvnAttrs.execAcrossChannels_ = false; + } + mvnAttrs.srcIsNHWC = descs.at(ARG_SRC)->hasLayoutType(LayoutType::nspc); mvnAttrs.src_prc = descs.at(ARG_SRC)->getPrecision(); mvnAttrs.dst_prc = descs.at(ARG_DST)->getPrecision(); @@ -270,53 +275,11 @@ void MVN::initSupportedPrimitiveDescriptors() { } // planar - if (canBeInplace) + if (descs.at(ARG_SRC)->hasLayoutType(LayoutType::nspc) && canBeInplace) nodeConfig.inConfs[0].inPlace(0); supportedPrimitiveDescriptors.emplace_back(nodeConfig, impl_desc_type::undef); } - return; - - auto pushDesc = [&](LayoutType format, impl_desc_type impl_type, bool useAclExecutor = false) {}; - -#if defined(OV_CPU_WITH_ACL) - pushDesc(LayoutType::nspc, acl, true); - pushDesc(LayoutType::ncsp, acl, true); - if (!supportedPrimitiveDescriptors.empty()) - return; - else - // Reference MVN implementation does not support fp16, so set fp32 explicitly - inputPrecision = outputPrecision = ov::element::f32; -#endif // OV_CPU_WITH_ACL - - impl_desc_type impl_type; - if (mayiuse(cpu::x64::avx512_core)) { - impl_type = impl_desc_type::jit_avx512; - } else if (mayiuse(cpu::x64::avx2)) { - impl_type = impl_desc_type::jit_avx2; - } else if (mayiuse(cpu::x64::sse41)) { - impl_type = impl_desc_type::jit_sse42; - } else { - impl_type = impl_desc_type::ref; - } - - if (mayiuse(cpu::x64::sse41)) { - // nspc - if (getInputShapeAtPort(0).getRank() == 4 || getInputShapeAtPort(0).getRank() == 5) { - pushDesc(LayoutType::nspc, impl_type); - } - // blk - if (impl_desc_type::jit_avx512 == impl_type) { - if (getInputShapeAtPort(0).getRank() == 4 || getInputShapeAtPort(0).getRank() == 5) { - pushDesc(LayoutType::nCsp16c, impl_type); - } - } else if (impl_desc_type::jit_avx2 == impl_type || impl_desc_type::jit_sse42 == impl_type) { - if (getInputShapeAtPort(0).getRank() == 4 || getInputShapeAtPort(0).getRank() == 5) { - pushDesc(LayoutType::nCsp8c, impl_type); - } - } - } - pushDesc(LayoutType::ncsp, impl_type); } ExecutorPtr MVN::createExecutor() { @@ -335,23 +298,8 @@ void MVN::prepareParams() { if (getSelectedPrimitiveDescriptor() == nullptr) OPENVINO_THROW("Preferable primitive descriptor is not set."); - const VectorDims in_dims = srcMemPtr->getStaticDims(); - transformTo5DCase(in_dims); - -#if defined(OPENVINO_ARCH_X86_64) - // New shape5D always need prepare via transformTo5DCase(), which is need in exec(). - // MVN itself and unary post ops is totally shape agnostic, execPtr can be reused directly w/o recompilation and setPostOps when shape is changed. - // As key have not shape, if shape changes and new post ops attr is also the same, execPtr can still hit. - // If new shape(channel changes) impact post ops attr, such as entry.quantization.offset, entry.depthwise.offset, entry.quantization.per_channel, - // which is participate in compilation, even postOpsData is passed in runtime, still need recompilation. - if (executor != nullptr && (fusedWith.empty() || onlyUnaryPostOps)) { - return; - } -#endif + transformTo5DCase(srcMemPtr->getStaticDims()); - auto selectedPD = getSelectedPrimitiveDescriptor(); - mvnAttrs.src_prc = selectedPD->getConfig().inConfs[0].getMemDesc()->getPrecision(); - mvnAttrs.dst_prc = selectedPD->getConfig().outConfs[0].getMemDesc()->getPrecision(); if (getParentEdgeAt(0)->getMemory().getDesc().hasLayoutType(LayoutType::ncsp)) { mvnAttrs.layout = MVNLayoutType::mvn_planar; } else if (getParentEdgeAt(0)->getMemory().getDesc().hasLayoutType(LayoutType::nspc)) {