Skip to content

Commit

Permalink
Revert "[CPU] Reduce overhead of the executor storage (openvinotoolki…
Browse files Browse the repository at this point in the history
…t#23307)"

This reverts commit baf1c9d.
  • Loading branch information
maxnick committed Apr 2, 2024
1 parent e2c6ae9 commit 4cacd5a
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions src/plugins/intel_cpu/src/nodes/executors/executor_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class ExecutorFactory {
m_postOps(postOps),
m_context(context),
m_suitableImplementations(filter(m_attrs, m_postOps, descriptors, implementationPriority)),
m_implementationRequiresFallback(m_suitableImplementations.size(), true),
m_executors(m_suitableImplementations.size()) {}
m_implementationRequiresFallback(m_suitableImplementations.size(), true) {}

/**
* @brief Retrieves the proper memory descriptors based on the provided memory descriptors.
Expand Down Expand Up @@ -109,8 +108,12 @@ class ExecutorFactory {
*/
void preconfigure(const MemoryArgs& memory) {
executor::Config<Attrs> config{memoryDescsFromMemory(memory), m_attrs, m_postOps};

cacheFallbackStatus(config);
std::transform(m_suitableImplementations.begin(),
m_suitableImplementations.end(),
m_implementationRequiresFallback.begin(),
[&config](const std::reference_wrapper<const ExecutorImplementation<Attrs>>& impl) {
return impl.get().requiresFallback(config);
});

const size_t implId = select(memory, 0);
const auto& impl = m_suitableImplementations[implId].get();
Expand All @@ -122,7 +125,7 @@ class ExecutorFactory {
}
}

(void)create(implId, memory, m_context);
(void)create(impl, memory, m_context);
}

/**
Expand Down Expand Up @@ -153,7 +156,7 @@ class ExecutorFactory {
return fallback<Attrs, NodeT>(config, *fallbackConfig, memory, m_context, impl.name());
}
}
const auto executor = create(implId, memory, m_context);
const auto executor = create(impl, memory, m_context);
if (!executor->update(memory)) {
return nullptr;
}
Expand Down Expand Up @@ -181,18 +184,6 @@ class ExecutorFactory {
return memoryDescs;
}

/**
* @brief Caches the fallback status for each suitable implementation.
*/
void cacheFallbackStatus(const executor::Config<Attrs>& config) {
std::transform(m_suitableImplementations.begin(),
m_suitableImplementations.end(),
m_implementationRequiresFallback.begin(),
[&config](const ExecutorImplementationRef& impl) {
return impl.get().requiresFallback(config);
});
}

/**
* @brief Filters and retrieves suitable implementations based on the provided executor configuration.
*
Expand Down Expand Up @@ -261,17 +252,18 @@ class ExecutorFactory {
return std::distance(m_suitableImplementations.begin(), selectedImplementation);
}

ExecutorPtr create(const size_t implId,
ExecutorPtr create(const ExecutorImplementation<Attrs>& impl,
const MemoryArgs& memory,
const ExecutorContext::CPtr context) {
assert(implId < m_executors.size() && implId < m_suitableImplementations.size());

if (!m_executors[implId]) {
const auto& impl = m_suitableImplementations[implId].get();
m_executors[implId] = impl.create(m_attrs, m_postOps, memory, context);
DEBUG_LOG("Creating executor using implementation: ", impl.name());
const auto& executorId = std::make_pair(impl.type(), impl.operationType());
auto factoryIt = m_executors.find(executorId);
if (factoryIt == m_executors.end()) {
factoryIt =
m_executors.insert(std::make_pair(executorId, impl.create(m_attrs, m_postOps, memory, context))).first;
}

return m_executors[implId];
return factoryIt->second;
}

const Attrs& m_attrs;
Expand All @@ -280,8 +272,7 @@ class ExecutorFactory {
std::vector<ExecutorImplementationRef> m_suitableImplementations;
// stores fallback status to avoid performing the check for every make() call
std::vector<bool> m_implementationRequiresFallback;
// executors cache
std::vector<ExecutorPtr> m_executors;
std::map<std::pair<ExecutorType, OperationType>, ExecutorPtr> m_executors;
};

template <typename Attrs, typename NodeT>
Expand Down

0 comments on commit 4cacd5a

Please sign in to comment.