Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU] Fix CNNs compilation time (#30679)

Egor Duplenskii05864e34c07e
diff --git a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_convolution_primitive.cpp b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_convolution_primitive.cpp
index b4fecff44a8..5bba4b3853d 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_convolution_primitive.cpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_convolution_primitive.cpp
@@ -293,27 +293,33 @@ static std::tuple<primitive_desc, size_t> selectPrimitiveDescWithMultipleAttribu
};
PrimitiveDescWithPriority prim_desc_w_priority{dnnl::primitive_desc(), 0, implPriorities.size()};
+ const bool first_match = implPriorities.front() == impl_desc_type::unknown;
// try all the provided attributes and select the one which results in a primitive desc with the highest priority
for (size_t attrId = 0; attrId < attrs.size(); attrId++) {
const auto& attr = attrs[attrId];
- for (size_t priorityId = 0; priorityId < implPriorities.size(); priorityId++) {
- const auto preferredImplType = implPriorities[priorityId];
- // the only way to fully reset primitive_desc after iterating over the implementations is to re-create it
- auto cur_desc = createPrimitiveDescriptor(attr);
- const bool found = DnnlExtensionUtils::find_implementation(cur_desc, preferredImplType);
-
- const size_t highestPriority = prim_desc_w_priority.priority;
- if (found && priorityId < highestPriority) {
- prim_desc_w_priority = {cur_desc, attrId, priorityId};
- }
- }
+ auto cur_desc = createPrimitiveDescriptor(attr);
+
+ DnnlExtensionUtils::for_each_implementation(
+ cur_desc,
+ first_match,
+ [&](impl_desc_type implType) { // is acceptable implementation
+ return contains(implPriorities, implType);
+ },
+ [&](dnnl::primitive_desc& desc) { // is implementation with highest priority
+ const impl_desc_type descImplType = parse_impl_name(desc.impl_info_str());
+ const auto it = std::find(implPriorities.begin(), implPriorities.end(), descImplType);
+ const size_t priorityId = std::distance(implPriorities.begin(), it);
+ const size_t highestPriority = prim_desc_w_priority.priority;
+ if (priorityId < highestPriority) {
+ auto desc_copy = dnnl::primitive_desc(DnnlExtensionUtils::clone_primitive_desc(desc.get(true)));
+ prim_desc_w_priority = {desc_copy, attrId, priorityId};
+ }
+ });
}
- auto prim_desc = prim_desc_w_priority.prim_desc;
-
- return {prim_desc, prim_desc_w_priority.attrId};
+ return {prim_desc_w_priority.prim_desc, prim_desc_w_priority.attrId};
}
static primitive_desc createPrimitiveDesc(const dnnl::memory::desc& inputDesc,