OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[CPU][REFACTORING] Align inference pipeline for all scenarios (#26211)
Egor Duplenskii50896e93d17b
diff --git a/src/plugins/intel_cpu/src/graph.cpp b/src/plugins/intel_cpu/src/graph.cppindex c286200d26a..0175ddfae1b 100644--- a/src/plugins/intel_cpu/src/graph.cpp+++ b/src/plugins/intel_cpu/src/graph.cpp@@ -474,19 +474,17 @@ void Graph::CreatePrimitivesAndExecConstants() const {continue;}- VERBOSE(node, getConfig().debugCaps.verbose);-if (context->getWeightsCache()) {auto sharedOutputs = acquireSharedOutputs(node);if (std::get<0>(sharedOutputs) || std::get<1>(sharedOutputs)) {- ExecuteNode(node, m_stream);+ ExecuteNodeWithCatch(node);for (auto & output : std::get<2>(sharedOutputs))output->valid(true);}} else {- ExecuteNode(node, m_stream);+ ExecuteNodeWithCatch(node);}}}@@ -1125,14 +1123,9 @@ void Graph::PullOutputData(std::unordered_map<std::size_t, ov::SoPtr<ITensor>>&}}-void Graph::InferStatic(SyncInferRequest* request) {+void Graph::InferStatic(SyncInferRequest* request, int numaId) {for (const auto& node : m_executableGraphNodes) {- VERBOSE(node, getConfig().debugCaps.verbose);- PERF(node, getConfig().collectPerfCounters);-- if (request)- request->throw_if_canceled();- ExecuteNode(node, m_stream);+ ExecuteNodeWithCatch(node, request, numaId);}}@@ -1337,47 +1330,52 @@ public:#endif} // namespace+/* group all the profiling macros into a single one+ * to avoid cluttering a core logic */+#define VERBOSE_PERF_DUMP_ITT_DEBUG_LOG(ittScope, node, config) \+ VERBOSE(node, config.debugCaps.verbose); \+ PERF(node, config.collectPerfCounters); \+ DUMP(node, config.debugCaps, infer_count); \+ OV_ITT_SCOPED_TASK(ittScope, node->profiling.execute); \+ DEBUG_LOG(*node);++inline void Graph::ExecuteNode(const NodePtr& node, SyncInferRequest* request, int numaId) const {+ if (request)+ request->throw_if_canceled();++ node->execute(m_stream, numaId);+}++inline void Graph::ExecuteNodeWithCatch(const NodePtr& node, SyncInferRequest* request, int numaId) const {+ VERBOSE_PERF_DUMP_ITT_DEBUG_LOG(itt::domains::intel_cpu, node, getConfig());++ try {+ ExecuteNode(node, request, numaId);+ } catch (const std::exception& exp) {+ OPENVINO_THROW(*node, exp.what());+ }+}+template<typename UpdateStrategy>-void Graph::InferDynamic(SyncInferRequest* request, UpdateStrategy&& update) {+void Graph::InferDynamic(SyncInferRequest* request, int numaId, UpdateStrategy&& update) {size_t inferCounter = 0;for (auto stopIndx : m_executableSyncNodesInds) {update(stopIndx);for (; inferCounter < stopIndx; ++inferCounter) {auto& node = m_executableGraphNodes[inferCounter];- VERBOSE(node, getConfig().debugCaps.verbose);- PERF(node, getConfig().collectPerfCounters);-- if (request)- request->throw_if_canceled();- try {- ExecuteNode(node, m_stream);- } catch (const std::exception& exp) {- OPENVINO_THROW(node, exp.what());- }- }- }-}-inline void Graph::ExecuteNode(const NodePtr& node, const dnnl::stream& stream) const {- DUMP(node, getConfig().debugCaps, infer_count);- OV_ITT_SCOPED_TASK(itt::domains::intel_cpu, node->profiling.execute);- DEBUG_LOG(*node);- // TODO: 132954 workaround for latency- int numaID = GetNumaNodeId();- if (node->isDynamicNode()) {- node->executeDynamic(stream, numaID);- } else {- node->executeStatic(stream, numaID);+ ExecuteNodeWithCatch(node, request, numaId);+ }}}-int Graph::GetNumaNodeId() const {+static int GetNumaNodeId(const GraphContext::CPtr& context) {int numaNodeId = -1;#if defined(__x86_64__) && defined(__linux__)- if ((getGraphContext()->getCPUStreamExecutor()) &&- (getConfig().hintPerfMode == ov::hint::PerformanceMode::LATENCY)) {- numaNodeId = getGraphContext()->getCPUStreamExecutor()->get_numa_node_id();+ if ((context->getCPUStreamExecutor()) &&+ (context->getConfig().hintPerfMode == ov::hint::PerformanceMode::LATENCY)) {+ numaNodeId = context->getCPUStreamExecutor()->get_numa_node_id();}#endifreturn numaNodeId;@@ -1385,16 +1383,17 @@ int Graph::GetNumaNodeId() const {void Graph::Infer(SyncInferRequest* request) {DEBUG_LOG("Infer graph: ", GetName(), ". Status: ", static_cast<int>(status));+ const int numaId = GetNumaNodeId(context);switch (status) {case Status::ReadyDynamic:- InferDynamic(request, UpdateNodes(m_executableGraphNodes));+ InferDynamic(request, numaId, UpdateNodes(m_executableGraphNodes));break;case Status::ReadyDynamicSeq:- InferDynamic(request, UpdateNodesSeq(m_executableGraphNodes));+ InferDynamic(request, numaId, UpdateNodesSeq(m_executableGraphNodes));break;case Status::ReadyStatic:- InferStatic(request);+ InferStatic(request, numaId);break;default:OPENVINO_ASSERT(IsReady(), "Wrong state of the ov::intel_cpu::Graph. Topology is not ready: ", static_cast<int>(status));diff --git a/src/plugins/intel_cpu/src/graph.h b/src/plugins/intel_cpu/src/graph.hindex f91275f399c..58dc9fd92fa 100644--- a/src/plugins/intel_cpu/src/graph.h+++ b/src/plugins/intel_cpu/src/graph.h@@ -225,12 +225,30 @@ protected:bool ProcessDynNodes();void Allocate(const std::vector<size_t>& syncNodesInds);void AllocateWithReuse(const std::vector<size_t>& syncNodesInds);- void ExecuteNode(const NodePtr& node, const dnnl::stream& stream) const;void CreatePrimitivesAndExecConstants() const;- void InferStatic(SyncInferRequest* request);+ /**+ * Execute a given \p node within \p request using \p numaId+ * and catch possible exceptions to include extra information+ *+ * @params node Node to execute+ * @params request Current inference request, which is checked for cancelation+ * @params numaId Numa Id to be used for an execution+ */+ void ExecuteNodeWithCatch(const NodePtr& node, SyncInferRequest* request = nullptr, int numaId = -1) const;++ /**+ * Execute a given \p node within \p request using \p numaId+ *+ * @params node Node to execute+ * @params request Current inference request, which is checked for cancelation+ * @params numaId Numa Id to be used for an execution+ */+ void ExecuteNode(const NodePtr& node, SyncInferRequest* request = nullptr, int numaId = -1) const;++ void InferStatic(SyncInferRequest* request, int numaId);template<typename UpdateStrategy>- void InferDynamic(SyncInferRequest* request, UpdateStrategy&& update);+ void InferDynamic(SyncInferRequest* request, int numaId, UpdateStrategy&& update);friend class intel_cpu::SyncInferRequest;friend std::shared_ptr<ov::Model> dump_graph_as_ie_ngraph_net(const Graph &graph);@@ -255,7 +273,6 @@ private:void EnforceBF16();void insertReorder(EdgePtr& edge, bool isOptimized, std::unordered_set<std::string>& uniqueLayerNames);void insertConvert(EdgePtr& edge);- int GetNumaNodeId() const;};using GraphPtr = std::shared_ptr<Graph>;diff --git a/src/plugins/intel_cpu/src/node.cpp b/src/plugins/intel_cpu/src/node.cppindex 5f9ca8f02ee..3ea8584884c 100644--- a/src/plugins/intel_cpu/src/node.cpp+++ b/src/plugins/intel_cpu/src/node.cpp@@ -584,18 +584,25 @@ void Node::updateDynamicParams() {}}+void Node::execute(const dnnl::stream strm, int numaId) {+ if (isDynamicNode()) {+ return executeDynamic(strm, numaId);+ } else {+ return executeStatic(strm, numaId);+ }+}+void Node::executeStatic(const dnnl::stream strm, int numaId) {- if (numaId >= 0)- toNumaNode(numaId);+ toNumaNode(numaId);execute(strm);}void Node::executeDynamic(dnnl::stream strm, int numaId) {if (isExecutable()) {- if (numaId >= 0)- toNumaNode(numaId);+ toNumaNode(numaId);executeDynamicImpl(strm);}+updateLastInputDims();}@@ -922,6 +929,9 @@ MemoryPtr Node::prepareWeightMemory(DnnlMemoryDescPtr dstWeightDesc, DnnlMemoryD}void Node::toNumaNode(int numaNodeID) {+ if (numaNodeID < 0)+ return;+return toNumaNodeImpl(numaNodeID);}diff --git a/src/plugins/intel_cpu/src/node.h b/src/plugins/intel_cpu/src/node.hindex a336e45c020..ff8bf87d993 100644--- a/src/plugins/intel_cpu/src/node.h+++ b/src/plugins/intel_cpu/src/node.h@@ -759,8 +759,10 @@ protected:virtual bool needShapeInfer() const;std::vector<VectorDims> shapeInferGeneric(const std::vector<Shape>& inputDims) const;virtual IShapeInfer::Result shapeInfer() const;++ void execute(dnnl::stream stream, int numaId);virtual void execute(dnnl::stream strm) = 0;- // TODO [DS] : make pure after all nodes will be support dynamic shapes+ // TODO [DS] : make pure after all nodes support dynamic shapesvirtual void executeDynamicImpl(dnnl::stream strm) {OPENVINO_THROW_NOT_IMPLEMENTED("[DS] executeDynamicImpl not implemented for node with type: ", getTypeStr());}