diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp index a2c1c9818ea..4bb7253c3a1 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp @@ -317,6 +317,7 @@ void MKLDNNGraph::Replicate(const CNNNetwork &network, const MKLDNNExtensionMana void MKLDNNGraph::InitGraph() { MKLDNNGraphOptimizer optimizer; + ENABLE_CPU_DEBUG_CAP(initNodeDumper(config.debugCaps)); SortTopologically(); InitNodes(); @@ -398,19 +399,19 @@ void MKLDNNGraph::ExtractConstantNodes() { } } -void MKLDNNGraph::ExecuteConstantNodesOnly() { +void MKLDNNGraph::ExecuteConstantNodesOnly() const { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::MKLDNN_LT, "MKLDNNGraph::ExecuteConstantNodesOnly"); mkldnn::stream stream(eng); using shared_memory_ptr = MKLDNNWeightsSharing::MKLDNNSharedMemory::Ptr; - auto acquireSharedOutputs = [this](MKLDNNNodePtr & graphNode) { + auto acquireSharedOutputs = [this](const MKLDNNNodePtr & node) { std::vector outputs; bool hasLocalAllocatedEdges = false; bool hasExternalInvalidEdges = false; - for (size_t i = 0; i < graphNode->getChildEdges().size(); ++i) { - auto edgePtr = graphNode->getChildEdgeAt(i); + for (size_t i = 0; i < node->getChildEdges().size(); ++i) { + auto edgePtr = node->getChildEdgeAt(i); if (edgePtr) { if (edgePtr->isUseExternalMemory()) { auto ptr = weightsCache->get(edgePtr->name()); @@ -426,18 +427,18 @@ void MKLDNNGraph::ExecuteConstantNodesOnly() { return std::make_tuple(hasExternalInvalidEdges, hasLocalAllocatedEdges, outputs); }; - for (auto &graphNode : constantGraphNodes) { + for (const auto &node : constantGraphNodes) { if (weightsCache) { - auto sharedOutputs = acquireSharedOutputs(graphNode); + auto sharedOutputs = acquireSharedOutputs(node); if (std::get<0>(sharedOutputs) || std::get<1>(sharedOutputs)) { - graphNode->execute(stream); + ExecuteNode(node, stream); for (auto & output : std::get<2>(sharedOutputs)) output->valid(true); } } else { - graphNode->execute(stream); + ExecuteNode(node, stream); } } } @@ -809,6 +810,16 @@ void MKLDNNGraph::PullOutputData(BlobMap &out) { } } +inline void MKLDNNGraph::ExecuteNode(const MKLDNNNodePtr& node, const mkldnn::stream& stream) const { + DUMP(node, infer_count); + OV_ITT_SCOPED_TASK(itt::domains::MKLDNNPlugin, node->profiling.execute); + + if (node->isDynamicNode()) + node->executeDynamic(stream); + else + node->execute(stream); +} + void MKLDNNGraph::Infer(MKLDNNInferRequest* request, int batch) { if (!IsReady()) { IE_THROW() << "Wrong state. Topology is not ready."; @@ -816,33 +827,12 @@ void MKLDNNGraph::Infer(MKLDNNInferRequest* request, int batch) { mkldnn::stream stream(eng); - ENABLE_CPU_DEBUG_CAP(NodeDumper nd(config.debugCaps, infer_count)); - -#ifdef CPU_DEBUG_CAPS - for (const auto& node : constantGraphNodes) { - if (request != nullptr) - request->ThrowIfCanceled(); - - ENABLE_CPU_DEBUG_CAP(nd.dumpInputBlobs(node)); - ENABLE_CPU_DEBUG_CAP(nd.dumpOutputBlobs(node)); - } -#endif - for (const auto& node : mutableGraphNodes) { PERF(config.collectPerfCounters, node); - if (request != nullptr) + if (request) request->ThrowIfCanceled(); - ENABLE_CPU_DEBUG_CAP(nd.dumpInputBlobs(node)); - - OV_ITT_SCOPED_TASK(itt::domains::MKLDNNPlugin, node->profiling.execute); - if (node->isDynamicNode()) { - node->executeDynamic(stream); - } else { - node->execute(stream); - } - - ENABLE_CPU_DEBUG_CAP(nd.dumpOutputBlobs(node)); + ExecuteNode(node, stream); } if (infer_count != -1) infer_count++; diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph.h b/inference-engine/src/mkldnn_plugin/mkldnn_graph.h index 4d587b4afd5..cc87acd3eaf 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph.h +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph.h @@ -236,7 +236,8 @@ protected: void AllocateWithReuse(); void CreatePrimitives(); void ExtractConstantNodes(); - void ExecuteConstantNodesOnly(); + void ExecuteNode(const MKLDNNNodePtr& node, const mkldnn::stream& stream) const; + void ExecuteConstantNodesOnly() const; friend class MKLDNNInferRequest; friend class MKLDNNGraphlessInferRequest; diff --git a/inference-engine/src/mkldnn_plugin/utils/node_dumper.cpp b/inference-engine/src/mkldnn_plugin/utils/node_dumper.cpp index 256a55a7710..02a36f166c9 100644 --- a/inference-engine/src/mkldnn_plugin/utils/node_dumper.cpp +++ b/inference-engine/src/mkldnn_plugin/utils/node_dumper.cpp @@ -20,10 +20,9 @@ using namespace InferenceEngine; namespace MKLDNNPlugin { -NodeDumper::NodeDumper(const DebugCaps::Config& config, const int _count) +NodeDumper::NodeDumper(const DebugCaps::Config& config) : dumpFormat(FORMAT::BIN) - , dumpDirName("mkldnn_dump") - , count(_count) { + , dumpDirName("mkldnn_dump") { if (!config.blobDumpDir.empty()) dumpDirName = config.blobDumpDir; @@ -43,7 +42,7 @@ NodeDumper::NodeDumper(const DebugCaps::Config& config, const int _count) dumpFilters[FILTER::BY_NAME] = config.blobDumpNodeName; } -void NodeDumper::dumpInputBlobs(const MKLDNNNodePtr& node) const { +void NodeDumper::dumpInputBlobs(const MKLDNNNodePtr& node, int count) const { if (!shouldBeDumped(node, "IN")) return; @@ -77,7 +76,7 @@ void NodeDumper::dumpInputBlobs(const MKLDNNNodePtr& node) const { dumpInternalBlobs(node); } -void NodeDumper::dumpOutputBlobs(const MKLDNNNodePtr& node) const { +void NodeDumper::dumpOutputBlobs(const MKLDNNNodePtr& node, int count) const { if (!shouldBeDumped(node, "OUT")) return; @@ -210,5 +209,16 @@ void NodeDumper::formatNodeName(std::string& name) const { std::replace(name.begin(), name.end(), ':', '-'); } +std::unique_ptr nd; + +void initNodeDumper(const DebugCaps::Config& config) { + nd.reset(new NodeDumper(config)); +} + +const std::unique_ptr& getNodeDumper() { + assert(nd.get() != nullptr); + return nd; +} + } // namespace MKLDNNPlugin #endif // CPU_DEBUG_CAPS diff --git a/inference-engine/src/mkldnn_plugin/utils/node_dumper.h b/inference-engine/src/mkldnn_plugin/utils/node_dumper.h index bac237c8883..7f349a07cfe 100644 --- a/inference-engine/src/mkldnn_plugin/utils/node_dumper.h +++ b/inference-engine/src/mkldnn_plugin/utils/node_dumper.h @@ -23,10 +23,10 @@ namespace MKLDNNPlugin { */ class NodeDumper { public: - NodeDumper(const DebugCaps::Config& config, const int _count); + NodeDumper(const DebugCaps::Config& config); - void dumpInputBlobs(const MKLDNNNodePtr &node) const; - void dumpOutputBlobs(const MKLDNNNodePtr &node) const; + void dumpInputBlobs(const MKLDNNNodePtr &node, int count = -1) const; + void dumpOutputBlobs(const MKLDNNNodePtr &node, int count = -1) const; private: void dumpInternalBlobs(const MKLDNNNodePtr& node) const; @@ -55,5 +55,26 @@ private: // std::hash is necessary for Ubuntu-16.04 (gcc-5.4 and defect in C++11 standart) std::unordered_map> dumpFilters; }; + +void initNodeDumper(const DebugCaps::Config& config); +const std::unique_ptr& getNodeDumper(); + +class DumpHelper { + const MKLDNNNodePtr& node; + const int count; + +public: + explicit DumpHelper(const MKLDNNNodePtr& _node, int _count = -1): node(_node), count(_count) { + getNodeDumper()->dumpInputBlobs(node, count); + } + + ~DumpHelper() { + getNodeDumper()->dumpOutputBlobs(node, count); + } +}; + +#define DUMP(...) DumpHelper __helper##__node (__VA_ARGS__); } // namespace MKLDNNPlugin +#else // CPU_DEBUG_CAPS +#define DUMP(...) #endif // CPU_DEBUG_CAPS