Skip to content

Commit

Permalink
add layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
allnes committed Sep 24, 2024
1 parent c41e65f commit a16715a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "openvino/core/parallel.hpp"

void ov::intel_cpu::CommonMVNExecutor::execute(const ov::intel_cpu::MemoryArgs &memory) {
mvn_ref(reinterpret_cast<uint8_t *>(memory.at(ARG_SRC_0)->getData()),
mvn_ref(reinterpret_cast<uint8_t *>(memory.at(ARG_SRC)->getData()),
reinterpret_cast<uint8_t *>(memory.at(ARG_DST)->getData()),
refMVNAttrs.shape5D);
}
Expand Down
76 changes: 69 additions & 7 deletions src/plugins/intel_cpu/src/nodes/executors/mvn_implementations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ using namespace ov::element;
using namespace TypeMaskAlias;
using namespace executor;

enum TypeTensorLayout {
NCHW, NHWC
};

using LayoutConfig = std::vector<LayoutType>;
static const LayoutConfig jitMVNLayoutConfig{LayoutType::ncsp, LayoutType::ncsp, LayoutType::ncsp, LayoutType::ncsp};
static const LayoutConfig aclMVNLayoutConfig{LayoutType::ncsp, LayoutType::ncsp, LayoutType::ncsp, LayoutType::ncsp};
static const LayoutConfig refMVNLayoutConfig{LayoutType::ncsp, LayoutType::ncsp, LayoutType::ncsp, LayoutType::ncsp};
static const LayoutConfig jitMVNLayoutConfig{LayoutType::ncsp, LayoutType::ncsp};
static const std::vector<LayoutConfig> aclMVNLayoutListConfigs = {{LayoutType::ncsp, LayoutType::ncsp},
{LayoutType::nspc, LayoutType::nspc}};
static const std::vector<LayoutConfig> refMVNLayoutListConfigs = {{LayoutType::ncsp, LayoutType::ncsp},
{LayoutType::nspc, LayoutType::nspc}};

// clang-format off
static const TypeMapping aclMVNTypeMapping {
Expand Down Expand Up @@ -163,7 +169,35 @@ const std::vector<ExecutorImplementation<MVNAttrs>>& getImplementations() {
return std::make_shared<JITMVNExecutor>(attrs, postOps, memory, context);
})
OV_CPU_INSTANCE_ACL(
"mvn_acl",
"mvn_acl_nchw",
ExecutorType::Acl,
OperationType::MVN,
ShapeTolerance::Agnostic,
// supports
[](const MVNConfig& config) -> bool {
return ACLMVNExecutor::supports(config);
},
// requiresFallback
[](const MVNConfig& config) -> ov::optional<executor::Config<MVNAttrs>> {
return requiresFallbackCommon(config,
aclMVNTypeMapping,
aclMVNLayoutListConfigs[TypeTensorLayout::NCHW],
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<ACLMVNExecutor>(attrs, postOps, memory, context);
})
OV_CPU_INSTANCE_ACL(
"mvn_acl_nhwc",
ExecutorType::Acl,
OperationType::MVN,
ShapeTolerance::Agnostic,
Expand All @@ -175,7 +209,7 @@ const std::vector<ExecutorImplementation<MVNAttrs>>& getImplementations() {
[](const MVNConfig& config) -> ov::optional<executor::Config<MVNAttrs>> {
return requiresFallbackCommon(config,
aclMVNTypeMapping,
aclMVNLayoutConfig,
aclMVNLayoutListConfigs[TypeTensorLayout::NHWC],
mvnMappingNotation);
},
// acceptsShapes
Expand All @@ -191,7 +225,35 @@ const std::vector<ExecutorImplementation<MVNAttrs>>& getImplementations() {
return std::make_shared<ACLMVNExecutor>(attrs, postOps, memory, context);
})
OV_CPU_INSTANCE_COMMON(
"mvn_ref",
"mvn_ref_nchw",
ExecutorType::Common,
OperationType::MVN,
ShapeTolerance::Agnostic,
// supports
[](const MVNConfig& config) -> bool {
return CommonMVNExecutor::supports(config);
},
// requiresFallback
[](const MVNConfig& config) -> ov::optional<executor::Config<MVNAttrs>> {
return requiresFallbackCommon(config,
refMVNTypeMapping,
refMVNLayoutListConfigs[TypeTensorLayout::NCHW],
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<CommonMVNExecutor>(attrs, postOps, memory, context);
})
OV_CPU_INSTANCE_COMMON(
"mvn_ref_nhwc",
ExecutorType::Common,
OperationType::MVN,
ShapeTolerance::Agnostic,
Expand All @@ -203,7 +265,7 @@ const std::vector<ExecutorImplementation<MVNAttrs>>& getImplementations() {
[](const MVNConfig& config) -> ov::optional<executor::Config<MVNAttrs>> {
return requiresFallbackCommon(config,
refMVNTypeMapping,
refMVNLayoutConfig,
refMVNLayoutListConfigs[TypeTensorLayout::NHWC],
mvnMappingNotation);
},
// acceptsShapes
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/intel_cpu/src/nodes/mvn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ void MVN::initSupportedPrimitiveDescriptors() {
};

#if defined(OV_CPU_WITH_ACL)
pushDesc(LayoutType::nspc, undef, true);
pushDesc(LayoutType::ncsp, undef, true);
pushDesc(LayoutType::nspc, acl, true);
pushDesc(LayoutType::ncsp, acl, true);
canUseAclExecutor = !supportedPrimitiveDescriptors.empty();
if (canUseAclExecutor)
return;
Expand Down Expand Up @@ -316,9 +316,9 @@ void MVN::initSupportedPrimitiveDescriptors() {
}

ExecutorPtr MVN::createExecutor() {
const auto& executor = factory->make(memory);
getSelectedPrimitiveDescriptor()->setImplementationType(executor->implType());
return executor;
const auto& new_executor = factory->make(memory);
getSelectedPrimitiveDescriptor()->setImplementationType(new_executor->implType());
return new_executor;
}

void MVN::prepareParams() {
Expand Down

0 comments on commit a16715a

Please sign in to comment.