Don't use global objects during CPU plugin nodes registration (#8367)

* Load CPU plugin as extension as well

* Fixed linkage issues

* Added static linux build

* Disabled GPU

* Fix for CPU nodes registration

* Disabled GPU

* Disabled GPU

* Disabled GPU

* Disabled GPU

* Disabled HETERO synthetic tests in static case

* Fixed dependencies

* Proper fix
This commit is contained in:
Ilya Lavrenov authored and GitHub committed 2021-11-04 12:39:28 +03:00
1 parent 23c50323eb
commit e14ead8dd3
14 files changed
+208 -102

No files matched your search

@@ -11,6 +11,9 @@
namespace {
using namespace HeteroTests;
// this tests load plugin by library name: this is not available during static linkage
#ifndef OPENVINO_STATIC_LIBRARY
INSTANTIATE_TEST_SUITE_P(smoke_SingleMajorNode, HeteroSyntheticTest,
::testing::Combine(
::testing::Values(std::vector<PluginParameter>{{"TEMPLATE0", "templatePlugin"}, {"TEMPLATE1", "templatePlugin"}}),
@@ -69,4 +72,6 @@ INSTANTIATE_TEST_SUITE_P(nightly_RandomMajorNodes_dynamic_batch, HeteroSynthetic
dynamicBuilders, true))),
HeteroSyntheticTest::getTestCaseName);
#endif // !OPENVINO_STATIC_LIBRARY
} // namespace
+8 -4
View File
@@ -59,17 +59,21 @@ if(ENABLE_IR_V7_READER)
endif()
if(NGRAPH_IR_FRONTEND_ENABLE)
add_dependencies(ie_libraries ir_ngraph_frontend)
if(BUILD_SHARED_LIBS)
add_dependencies(ie_libraries ir_ngraph_frontend)
endif()
# use this one once CVS-69781 is fixed
# add_dependencies(inference_engine ir_ngraph_frontend)
endif()
if(NGRAPH_ONNX_FRONTEND_ENABLE)
add_dependencies(ie_libraries onnx_ngraph_frontend)
add_dependencies(inference_engine onnx_ngraph_frontend)
endif()
if(NGRAPH_PDPD_FRONTEND_ENABLE)
add_dependencies(ie_libraries paddlepaddle_ngraph_frontend)
add_dependencies(inference_engine paddlepaddle_ngraph_frontend)
endif()
if(NGRAPH_TF_FRONTEND_ENABLE)
add_dependencies(ie_libraries tensorflow_ngraph_frontend)
add_dependencies(inference_engine tensorflow_ngraph_frontend)
endif()
@@ -782,8 +782,7 @@ class MKLDNNNode::NodesFactory : public openvino::cc::Factory<Type,
const mkldnn::engine &,
MKLDNNWeightsSharing::Ptr &)> {
public:
NodesFactory()
: Factory("NodesFactory") {}
NodesFactory();
MKLDNNNode* create(const std::shared_ptr<ngraph::Node>& op, const mkldnn::engine& eng,
const MKLDNNExtensionManager::Ptr& extMgr, MKLDNNWeightsSharing::Ptr &w_cache);
@@ -797,15 +796,6 @@ struct MKLDNNNodeImpl : public MKLDNNNodeType {
}
};
#define REG_MKLDNN_CONCAT3_(X, Y, Z) X ## Y ## Z
#define REG_MKLDNN_CONCAT3(X, Y, Z) REG_MKLDNN_CONCAT3_(X, Y, Z)
#define REG_MKLDNN_PRIM_FOR(__prim, __type) \
static struct REG_MKLDNN_CONCAT3(Registrar4, __prim, __LINE__) { \
REG_MKLDNN_CONCAT3(Registrar4, __prim, __LINE__)() { \
MKLDNNNode::factory() \
.registerNodeIfRequired(MKLDNNPlugin, __prim, __type, MKLDNNNodeImpl<__prim>); \
} \
} REG_MKLDNN_CONCAT3(_reg_, __prim, __LINE__);
} // namespace MKLDNNPlugin
#define REG_MKLDNN_PRIM_FOR(__prim, __type)
@@ -0,0 +1,171 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "nodes/mkldnn_reference_node.h"
#include "nodes/mkldnn_shapeof.h"
#include "nodes/mkldnn_batch_to_space_node.h"
#include "nodes/mkldnn_multiclass_nms.hpp"
#include "nodes/mkldnn_adaptive_pooling.h"
#include "nodes/mkldnn_conv_node.h"
#include "nodes/mkldnn_roi_align_node.h"
#include "nodes/mkldnn_lrn_node.h"
#include "nodes/mkldnn_generic_node.h"
#include "nodes/mkldnn_experimental_detectron_roifeatureextractor_node.h"
#include "nodes/mkldnn_eltwise_node.h"
#include "nodes/mkldnn_reorg_yolo_node.h"
#include "nodes/mkldnn_pooling_node.h"
#include "nodes/mkldnn_transpose_node.h"
#include "nodes/mkldnn_grn_node.h"
#include "nodes/mkldnn_interpolate_node.h"
#include "nodes/mkldnn_experimental_detectron_detection_output_node.h"
#include "nodes/mkldnn_roll_node.h"
#include "nodes/mkldnn_fake_quantize_node.h"
#include "nodes/mkldnn_embedding_segments_sum_node.h"
#include "nodes/mkldnn_region_yolo_node.h"
#include "nodes/mkldnn_matmul_node.h"
#include "nodes/mkldnn_detection_output_node.h"
#include "nodes/mkldnn_reverse_sequence_node.h"
#include "nodes/mkldnn_pad_node.h"
#include "nodes/mkldnn_ctc_greedy_decoder_seq_len_node.h"
#include "nodes/mkldnn_reshape_node.h"
#include "nodes/mkldnn_psroi_pooling_node.h"
#include "nodes/mkldnn_memory_node.hpp"
#include "nodes/mkldnn_bin_conv_node.h"
#include "nodes/mkldnn_gather_elements_node.h"
#include "nodes/mkldnn_experimental_detectron_priorgridgenerator_node.h"
#include "nodes/mkldnn_tile_node.h"
#include "nodes/mkldnn_math_node.h"
#include "nodes/mkldnn_normalize_node.h"
#include "nodes/mkldnn_proposal_node.h"
#include "nodes/mkldnn_tensoriterator_node.h"
#include "nodes/mkldnn_fullyconnected_node.h"
#include "nodes/mkldnn_extract_image_patches_node.h"
#include "nodes/mkldnn_ctc_loss_node.h"
#include "nodes/mkldnn_reorder_node.h"
#include "nodes/mkldnn_gather_nd_node.h"
#include "nodes/mkldnn_shuffle_channels_node.h"
#include "nodes/mkldnn_bucketize_node.h"
#include "nodes/mkldnn_space_to_depth_node.h"
#include "nodes/mkldnn_concat_node.h"
#include "nodes/mkldnn_softmax_node.h"
#include "nodes/mkldnn_space_to_batch_node.h"
#include "nodes/mkldnn_select_node.h"
#include "nodes/mkldnn_topk_node.h"
#include "nodes/mkldnn_broadcast_node.h"
#include "nodes/mkldnn_matrix_nms_node.h"
#include "nodes/mkldnn_mvn_node.h"
#include "nodes/mkldnn_gather_node.h"
#include "nodes/mkldnn_scatter_update_node.h"
#include "nodes/mkldnn_gather_tree_node.h"
#include "nodes/mkldnn_def_conv_node.h"
#include "nodes/mkldnn_embedding_bag_offset_sum_node.h"
#include "nodes/mkldnn_deconv_node.h"
#include "nodes/mkldnn_roi_pooling_node.h"
#include "nodes/mkldnn_range_node.h"
#include "nodes/mkldnn_split_node.h"
#include "nodes/mkldnn_one_hot_node.h"
#include "nodes/mkldnn_log_softmax_node.h"
#include "nodes/mkldnn_strided_slice_node.h"
#include "nodes/mkldnn_dft_node.h"
#include "nodes/mkldnn_non_max_suppression_node.h"
#include "nodes/mkldnn_convert_node.h"
#include "nodes/mkldnn_rnn.h"
#include "nodes/mkldnn_experimental_detectron_topkrois_node.h"
#include "nodes/mkldnn_cum_sum_node.h"
#include "nodes/mkldnn_depth_to_space_node.h"
#include "nodes/mkldnn_input_node.h"
#include "nodes/mkldnn_experimental_detectron_generate_proposals_single_image_node.h"
#include "nodes/mkldnn_embedding_bag_packed_sum_node.h"
#include "nodes/mkldnn_reduce_node.h"
#include "nodes/mkldnn_if_node.h"
#include "nodes/mkldnn_ctc_greedy_decoder_node.h"
#define MKLDNN_NODE(__prim, __type) \
registerNodeIfRequired(MKLDNNPlugin, __prim, __type, MKLDNNNodeImpl<__prim>)
MKLDNNPlugin::MKLDNNNode::NodesFactory::NodesFactory()
: Factory("NodesFactory") {
MKLDNN_NODE(MKLDNNGenericNode, Generic);
MKLDNN_NODE(MKLDNNCumSumNode, CumSum);
MKLDNN_NODE(MKLDNNConvolutionNode, Convolution);
MKLDNN_NODE(MKLDNNSpaceToBatchNode, SpaceToBatch);
MKLDNN_NODE(MKLDNNLrnNode, Lrn);
MKLDNN_NODE(MKLDNNBatchToSpaceNode, BatchToSpace);
MKLDNN_NODE(MKLDNNNormalizeL2Node, NormalizeL2);
MKLDNN_NODE(MKLDNNIfNode, If);
MKLDNN_NODE(MKLDNNProposalNode, Proposal);
MKLDNN_NODE(MKLDNNBroadcastNode, Broadcast);
MKLDNN_NODE(MKLDNNExperimentalDetectronTopKROIsNode, ExperimentalDetectronTopKROIs);
MKLDNN_NODE(MKLDNNReorderNode, Reorder);
MKLDNN_NODE(MKLDNNBinaryConvolutionNode, BinaryConvolution);
MKLDNN_NODE(MKLDNNMatrixNmsNode, MatrixNms);
MKLDNN_NODE(MKLDNNAdaptivePoolingNode, AdaptivePooling);
MKLDNN_NODE(MKLDNNPoolingNode, Pooling);
MKLDNN_NODE(MKLDNNReduceNode, Reduce);
MKLDNN_NODE(MKLDNNEltwiseNode, Eltwise);
MKLDNN_NODE(MKLDNNSoftMaxNode, Softmax);
MKLDNN_NODE(MKLDNNEmbeddingBagPackedSumNode, EmbeddingBagPackedSum);
MKLDNN_NODE(MKLDNNInputNode, Input);
MKLDNN_NODE(MKLDNNInputNode, Output);
MKLDNN_NODE(MKLDNNMemoryInputNode, MemoryInput);
MKLDNN_NODE(MKLDNNMemoryOutputNode, MemoryOutput);
MKLDNN_NODE(MKLDNNTileNode, Tile);
MKLDNN_NODE(MKLDNNDFTNode, DFT);
MKLDNN_NODE(MKLDNNGatherTreeNode, GatherTree);
MKLDNN_NODE(MKLDNNSpaceToDepthNode, SpaceToDepth);
MKLDNN_NODE(MKLDNNFullyConnectedNode, FullyConnected);
MKLDNN_NODE(MKLDNNCTCGreedyDecoderNode, CTCGreedyDecoder);
MKLDNN_NODE(MKLDNNTransposeNode, Transpose);
MKLDNN_NODE(MKLDNNDeformableConvolutionNode, DeformableConvolution);
MKLDNN_NODE(MKLDNNReorgYoloNode, ReorgYolo);
MKLDNN_NODE(MKLDNNEmbeddingSegmentsSumNode, EmbeddingSegmentsSum);
MKLDNN_NODE(MKLDNNSelectNode, Select);
MKLDNN_NODE(MKLDNNShapeOfNode, ShapeOf);
MKLDNN_NODE(MKLDNNExperimentalDetectronGenerateProposalsSingleImageNode, ExperimentalDetectronGenerateProposalsSingleImage);
MKLDNN_NODE(MKLDNNReverseSequenceNode, ReverseSequence);
MKLDNN_NODE(MKLDNNFakeQuantizeNode, FakeQuantize);
MKLDNN_NODE(MKLDNNNonMaxSuppressionNode, NonMaxSuppression);
MKLDNN_NODE(MKLDNNExperimentalDetectronPriorGridGeneratorNode, ExperimentalDetectronPriorGridGenerator);
MKLDNN_NODE(MKLDNNGatherNDNode, GatherND);
MKLDNN_NODE(MKLDNNLogSoftmaxNode, LogSoftmax);
MKLDNN_NODE(MKLDNNPSROIPoolingNode, PSROIPooling);
MKLDNN_NODE(MKLDNNRNN, RNNCell);
MKLDNN_NODE(MKLDNNRNN, RNNSeq);
MKLDNN_NODE(MKLDNNCTCLossNode, CTCLoss);
MKLDNN_NODE(MKLDNNSplitNode, Split);
MKLDNN_NODE(MKLDNNDetectionOutputNode, DetectionOutput);
MKLDNN_NODE(MKLDNNGatherElementsNode, GatherElements);
MKLDNN_NODE(MKLDNNCTCGreedyDecoderSeqLenNode, CTCGreedyDecoderSeqLen);
MKLDNN_NODE(MKLDNNBucketizeNode, Bucketize);
MKLDNN_NODE(MKLDNNExperimentalDetectronROIFeatureExtractorNode, ExperimentalDetectronROIFeatureExtractor);
MKLDNN_NODE(MKLDNNMathNode, Math);
MKLDNN_NODE(MKLDNNMultiClassNmsNode, MulticlassNms);
MKLDNN_NODE(MKLDNNConvertNode, Convert);
MKLDNN_NODE(MKLDNNEmbeddingBagOffsetSumNode, EmbeddingBagOffsetsSum);
MKLDNN_NODE(MKLDNNRollNode, Roll);
MKLDNN_NODE(MKLDNNPadNode, Pad);
MKLDNN_NODE(MKLDNNReshapeNode, Reshape);
MKLDNN_NODE(MKLDNNMVNNode, MVN);
MKLDNN_NODE(MKLDNNMatMulNode, MatMul);
MKLDNN_NODE(MKLDNNScatterUpdateNode, ScatterUpdate);
MKLDNN_NODE(MKLDNNScatterUpdateNode, ScatterElementsUpdate);
MKLDNN_NODE(MKLDNNScatterUpdateNode, ScatterNDUpdate);
MKLDNN_NODE(MKLDNNInterpolateNode, Interpolate);
MKLDNN_NODE(MKLDNNROIPoolingNode, ROIPooling);
MKLDNN_NODE(MKLDNNTensorIteratorNode, TensorIterator);
MKLDNN_NODE(MKLDNNConcatNode, Concatenation);
MKLDNN_NODE(MKLDNNExtractImagePatchesNode, ExtractImagePatches);
MKLDNN_NODE(MKLDNNOneHotNode, OneHot);
MKLDNN_NODE(MKLDNNExperimentalDetectronDetectionOutputNode, ExperimentalDetectronDetectionOutput);
MKLDNN_NODE(MKLDNNROIAlignNode, ROIAlign);
MKLDNN_NODE(MKLDNNShuffleChannelsNode, ShuffleChannels);
MKLDNN_NODE(MKLDNNDepthToSpaceNode, DepthToSpace);
MKLDNN_NODE(MKLDNNDeconvolutionNode, Deconvolution);
MKLDNN_NODE(MKLDNNGatherNode, Gather);
MKLDNN_NODE(MKLDNNRegionYoloNode, RegionYolo);
MKLDNN_NODE(MKLDNNRangeNode, Range);
MKLDNN_NODE(MKLDNNTopKNode, TopK);
MKLDNN_NODE(MKLDNNStridedSliceNode, StridedSlice);
MKLDNN_NODE(MKLDNNGRNNode, GRN);
}
@@ -115,7 +115,6 @@ using namespace InferenceEngine;
Engine::Engine() {
_pluginName = "CPU";
extensionManager->AddExtension(std::make_shared<Extensions::Cpu::MKLDNNExtensions>());
}
Engine::~Engine() {
@@ -1,30 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "nodes/list.hpp"
namespace InferenceEngine {
namespace Extensions {
namespace Cpu {
#define FACTORY_DECLARATION(__prim, __type) \
void __prim ## __type(MKLDNNExtensions * extInstance)
#define FACTORY_CALL(__prim, __type) \
__prim ## __type(this)
#define MKLDNN_EXTENSION_NODE(__prim, __type) FACTORY_DECLARATION(__prim, __type)
# include "list_tbl.hpp"
#undef MKLDNN_EXTENSION_NODE
MKLDNNExtensions::MKLDNNExtensions()
: layersFactory("LayersFactory") {
#define MKLDNN_EXTENSION_NODE(__prim, __type) FACTORY_CALL(__prim, __type)
# include "list_tbl.hpp"
#undef MKLDNN_EXTENSION_NODE
}
} // namespace Cpu
} // namespace Extensions
} // namespace InferenceEngine
@@ -43,32 +43,14 @@ public:
namespace Extensions {
namespace Cpu {
using ext_factory = std::function<InferenceEngine::ILayerImplFactory*(const std::shared_ptr<ngraph::Node>& op)>;
struct ExtensionsHolder {
std::map<std::string, ext_factory> list;
};
// TODO: remove this
class MKLDNNExtensions : public IExtension {
public:
MKLDNNExtensions();
virtual StatusCode
getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept {
collectTypes(types, size);
return OK;
}
virtual StatusCode
getFactoryFor(ILayerImplFactory*& factory, const std::shared_ptr<ngraph::Node>& op, ResponseDesc* resp) noexcept {
using namespace MKLDNNPlugin;
factory = layersFactory.createNodeIfRegistered(MKLDNNPlugin, op->get_type_name(), op);
if (!factory) {
std::string errorMsg = std::string("Factory for ") + op->get_type_name() + " wasn't found!";
errorMsg.copy(resp->msg, sizeof(resp->msg) - 1);
return NOT_FOUND;
}
return OK;
return NOT_FOUND;
}
void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
@@ -82,24 +64,6 @@ public:
}
void Unload() noexcept override {}
using LayersFactory = openvino::cc::Factory<
std::string,
InferenceEngine::ILayerImplFactory*(const std::shared_ptr<ngraph::Node>& op)>;
LayersFactory layersFactory;
private:
void collectTypes(char**& types, unsigned int& size) const {
types = new char *[layersFactory.size()];
unsigned count = 0;
layersFactory.foreach([&](std::pair<std::string, LayersFactory::builder_t> const &builder) {
types[count] = new char[builder.first.size() + 1];
std::copy(builder.first.begin(), builder.first.end(), types[count]);
types[count][builder.first.size() ] = '\0';
});
size = count;
}
};
} // namespace Cpu
@@ -1,9 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#ifndef MKLDNN_EXTENSION_NODE
# warning "MKLDNN_EXTENSION_NODE is not defined"
# define MKLDNN_EXTENSION_NODE(__prim, __type)
#endif
@@ -13,7 +13,7 @@
namespace MKLDNNPlugin {
enum MatrixNmsSortResultType {
enum class MatrixNmsSortResultType {
CLASSID, // sort selected boxes by class id (ascending) in each batch element
SCORE, // sort selected boxes by score (descending) in each batch element
NONE // do not guarantee the order in each batch element
@@ -214,20 +214,20 @@ void MKLDNNMultiClassNmsNode::execute(mkldnn::stream strm) {
}
if (sort_result_across_batch) {
if (sort_result_type == SCORE) {
if (sort_result_type == MulticlassNmsSortResultType::SCORE) {
parallel_sort(filtBoxes.begin(), filtBoxes.begin() + startOffset, [](const filteredBoxes& l, const filteredBoxes& r) {
return (l.score > r.score) || (l.score == r.score && l.batch_index < r.batch_index) ||
(l.score == r.score && l.batch_index == r.batch_index && l.class_index < r.class_index) ||
(l.score == r.score && l.batch_index == r.batch_index && l.class_index == r.class_index && l.box_index < r.box_index);
});
} else if (sort_result_type == CLASSID) {
} else if (sort_result_type == MulticlassNmsSortResultType::CLASSID) {
parallel_sort(filtBoxes.begin(), filtBoxes.begin() + startOffset, [](const filteredBoxes& l, const filteredBoxes& r) {
return (l.class_index < r.class_index) || (l.class_index == r.class_index && l.batch_index < r.batch_index) ||
(l.class_index == r.class_index && l.batch_index == r.batch_index && l.score > r.score) ||
(l.class_index == r.class_index && l.batch_index == r.batch_index && l.score == r.score && l.box_index < r.box_index);
});
}
} else if (sort_result_type == CLASSID) {
} else if (sort_result_type == MulticlassNmsSortResultType::CLASSID) {
parallel_sort(filtBoxes.begin(), filtBoxes.begin() + startOffset, [](const filteredBoxes& l, const filteredBoxes& r) {
return ((l.batch_index < r.batch_index) ||
((l.batch_index == r.batch_index) &&
@@ -11,7 +11,7 @@
namespace MKLDNNPlugin {
enum MulticlassNmsSortResultType {
enum class MulticlassNmsSortResultType {
CLASSID, // sort selected boxes by class id (ascending) in each batch element
SCORE, // sort selected boxes by score (descending) in each batch element
NONE // do not guarantee the order in each batch element
@@ -40,7 +40,7 @@ private:
const size_t NMS_SELECTEDNUM = 2;
bool sort_result_across_batch = false;
MulticlassNmsSortResultType sort_result_type = NONE;
MulticlassNmsSortResultType sort_result_type = MulticlassNmsSortResultType::NONE;
size_t num_batches;
size_t num_boxes;
@@ -794,6 +794,7 @@ void MKLDNNRNN::execute(mkldnn::stream strm) {
(*prim).execute(strm, args);
}
} // namespace MKLDNNPlugin
REG_MKLDNN_PRIM_FOR(MKLDNNRNN, RNNCell);
REG_MKLDNN_PRIM_FOR(MKLDNNRNN, RNNSeq);
} // namespace MKLDNNPlugin
@@ -11,6 +11,9 @@
namespace {
using namespace HeteroTests;
// this tests load plugin by library name: this is not available during static linkage
#ifndef OPENVINO_STATIC_LIBRARY
INSTANTIATE_TEST_SUITE_P(smoke_SingleMajorNode, HeteroSyntheticTest,
::testing::Combine(
::testing::Values(std::vector<PluginParameter>{{"CPU0", "MKLDNNPlugin"}, {"CPU1", "MKLDNNPlugin"}}),
@@ -22,4 +25,7 @@ INSTANTIATE_TEST_SUITE_P(nightly_RandomMajorNodes, HeteroSyntheticTest,
::testing::Values(std::vector<PluginParameter>{{"CPU0", "MKLDNNPlugin"}, {"CPU1", "MKLDNNPlugin"}}),
::testing::ValuesIn(HeteroTests::HeteroSyntheticTest::_randomMajorNodeFunctions)),
HeteroSyntheticTest::getTestCaseName);
#endif // !OPENVINO_STATIC_LIBRARY
} // namespace
@@ -16,6 +16,11 @@ if(ENABLE_MULTI)
list(APPEND DEPENDENCIES MultiDevicePlugin)
endif()
# remove once CVS-69781 is fixed
if(NGRAPH_IR_FRONTEND_ENABLE)
list(APPEND DEPENDENCIES ir_ngraph_frontend)
endif()
if (NGRAPH_ONNX_FRONTEND_ENABLE)
list(APPEND DEPENDENCIES test_model_zoo)
list(APPEND DEFINES TEST_MODELS="${TEST_MODEL_ZOO}/func_tests/models/")