Skip to content

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

[CPU] Split executor cache usage for different use cases (#31052)

Arseniy Obolenskiy90c96565f70b
diff --git a/src/plugins/intel_cpu/src/config.cpp b/src/plugins/intel_cpu/src/config.cpp
index 0ae72decc03..e1b7b96adc6 100644
--- a/src/plugins/intel_cpu/src/config.cpp
+++ b/src/plugins/intel_cpu/src/config.cpp
@@ -275,6 +275,7 @@ void Config::readProperties(const ov::AnyMap& prop, const ModelType modelType) {
// any negative value will be treated
// as zero that means disabling the cache
rtCacheCapacity = std::max(val_i, 0);
+ snippetsCacheCapacity = std::max(val_i, 0);
} else if (ov::intel_cpu::denormals_optimization.name() == key) {
try {
denormalsOptMode = val.as<bool>() ? DenormalsOptMode::DO_On : DenormalsOptMode::DO_Off;
diff --git a/src/plugins/intel_cpu/src/config.h b/src/plugins/intel_cpu/src/config.h
index d598c837ca1..8d893818640 100644
--- a/src/plugins/intel_cpu/src/config.h
+++ b/src/plugins/intel_cpu/src/config.h
@@ -65,17 +65,21 @@ struct Config {
#if defined(OV_CPU_WITH_ACL)
bool aclFastMath = false;
#endif
+#if defined(OV_CPU_WITH_ACL) || defined(OV_CPU_WITH_SHL)
+ // TODO: Executor cache may leads to incorrect behavior on oneDNN ACL primitives
+ size_t rtCacheCapacity = 0ul;
+#else
+ size_t rtCacheCapacity = 5000ul;
+#endif
+ size_t snippetsCacheCapacity = 5000ul;
#if defined(OPENVINO_ARCH_X86_64)
ov::element::Type kvCachePrecision = ov::element::u8;
ov::element::Type keyCachePrecision = ov::element::u8;
ov::element::Type valueCachePrecision = ov::element::u8;
- size_t rtCacheCapacity = 5000ul;
#else
ov::element::Type kvCachePrecision = ov::element::f16;
ov::element::Type keyCachePrecision = ov::element::f16;
ov::element::Type valueCachePrecision = ov::element::f16;
- // TODO: Executor cache may leads to incorrect behavior on oneDNN ACL primitives
- size_t rtCacheCapacity = 0ul;
#endif
size_t keyCacheGroupSize = 0ul;
size_t valueCacheGroupSize = 0ul;
diff --git a/src/plugins/intel_cpu/src/graph_context.cpp b/src/plugins/intel_cpu/src/graph_context.cpp
index ea388b37eca..458f0dddf41 100644
--- a/src/plugins/intel_cpu/src/graph_context.cpp
+++ b/src/plugins/intel_cpu/src/graph_context.cpp
@@ -29,6 +29,7 @@ GraphContext::GraphContext(Config config,
: m_config(std::move(config)),
m_weightsCache(std::move(w_cache)),
m_rtParamsCache(std::make_shared<MultiCache>(m_config.rtCacheCapacity)),
+ m_snippetsParamsCache(std::make_shared<MultiCache>(m_config.snippetsCacheCapacity)),
m_isGraphQuantizedFlag(isGraphQuantized),
m_streamExecutor(std::move(streamExecutor)),
m_subMemoryManager(std::move(sub_memory_manager)),
diff --git a/src/plugins/intel_cpu/src/graph_context.h b/src/plugins/intel_cpu/src/graph_context.h
index c0299fc6181..254762ca1c9 100644
--- a/src/plugins/intel_cpu/src/graph_context.h
+++ b/src/plugins/intel_cpu/src/graph_context.h
@@ -49,6 +49,10 @@ public:
return m_rtParamsCache;
}
+ [[nodiscard]] MultiCachePtr getSnippetsParamsCache() const {
+ return m_snippetsParamsCache;
+ }
+
[[nodiscard]] DnnlScratchPadPtr getScratchPad() const {
return m_rtScratchPads[m_numaNodeId];
}
@@ -106,6 +110,7 @@ private:
WeightsSharing::Ptr m_weightsCache;
// primitive cache
MultiCachePtr m_rtParamsCache;
+ MultiCachePtr m_snippetsParamsCache;
// global scratch pad
DnnlScratchPadPtr m_rtScratchPad;
diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.cpp b/src/plugins/intel_cpu/src/nodes/subgraph.cpp
index 0da65a3dbcd..906f1f49531 100644
--- a/src/plugins/intel_cpu/src/nodes/subgraph.cpp
+++ b/src/plugins/intel_cpu/src/nodes/subgraph.cpp
@@ -196,9 +196,9 @@ Subgraph::Subgraph(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr
#if defined(OPENVINO_ARCH_ARM64)
subgraph_attrs->snippet->set_generator(
- std::make_shared<aarch64::CPUGenerator>(host_isa, context->getParamsCache()));
+ std::make_shared<aarch64::CPUGenerator>(host_isa, context->getSnippetsParamsCache()));
#elif defined(OPENVINO_ARCH_X86_64)
- subgraph_attrs->snippet->set_generator(std::make_shared<CPUGenerator>(host_isa, context->getParamsCache()));
+ subgraph_attrs->snippet->set_generator(std::make_shared<CPUGenerator>(host_isa, context->getSnippetsParamsCache()));
#else
THROW_CPU_NODE_ERR("Subgraphs code-generator is not supported on non-x64 platforms");
#endif
@@ -644,7 +644,7 @@ Subgraph::ControlFlowPasses Subgraph::getControlFlowPasses() {
ov::intel_cpu::pass::InsertBrgemmCopyBuffers);
SNIPPETS_REGISTER_PASS_ABSOLUTE_X86_64(Place::PipelineEnd,
ov::intel_cpu::pass::InitRepackedConstantInputs,
- context->getParamsCache(),
+ context->getSnippetsParamsCache(),
repacked_constant_input_config);
SNIPPETS_REGISTER_PASS_RELATIVE_ARM64(Place::After,
ov::snippets::lowered::pass::MarkLoops,
@@ -767,7 +767,7 @@ void Subgraph::prepareWeights() {
void Subgraph::prepareParams() {
#if defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_ARM64)
- const auto& cache = context->getParamsCache();
+ const auto& cache = context->getSnippetsParamsCache();
auto builder = [this, &cache](const SubgraphKey& key) -> std::shared_ptr<SubgraphBaseExecutor> {
const auto& snippet = subgraph_attrs->snippet;
@@ -846,7 +846,7 @@ IShapeInfer::Result Subgraph::shapeInfer() const {
return std::make_shared<SubgraphShapeInferResult>(Node::shapeInfer());
};
- const auto cache = context->getParamsCache();
+ const auto cache = context->getSnippetsParamsCache();
const auto result = cache->getOrCreate(SubgraphShapeInferResultKey(in_shapes, subgraph_attrs->bodyHash), builder);
return result.first->result;
}
diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
index 491f911efe7..de64727afbf 100644
--- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
+++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
@@ -1151,7 +1151,7 @@ void Transformations::MainSnippets() {
// Runtime caching should be enabled in case of dynamic Subgraphs in CPU Plugin: to reduce overheads of
// ShapeInference and CodeGeneration If runtime cache capacity is zero, it means that rtCache won't be used and we
// shouldn't tokenize dynamic Subgraphs - it will lead to performance degradations
- bool is_dynamic_mha_token_enabled = config.rtCacheCapacity != 0;
+ bool is_dynamic_mha_token_enabled = config.snippetsCacheCapacity != 0;
#if defined(OPENVINO_ARCH_ARM64)
// ARM has 32 gprs. After excluding 2 registers for work amounts, 1 register for runtime parameters, 1 platform
// register, 3 registers for temporary use, and 2 stack related registers, it has 23 remaining registers.