diff --git a/src/inference/tests/functional/core_threading.cpp b/src/inference/tests/functional/core_threading.cpp index 1132d8dec00..12d83b591a0 100644 --- a/src/inference/tests/functional/core_threading.cpp +++ b/src/inference/tests/functional/core_threading.cpp @@ -24,9 +24,9 @@ # endif #endif -class CoreThreadingTests : public ::testing::Test { +class IECoreThreadingTests : public ::testing::Test { protected: - std::string modelName = "CoreThreadingTests.xml", weightsName = "CoreThreadingTests.bin"; + std::string modelName = "IECoreThreadingTests.xml", weightsName = "IECoreThreadingTests.bin"; public: void SetUp() override { @@ -72,7 +72,7 @@ public: }; // tested function: SetConfig -TEST_F(CoreThreadingTests, SetConfigPluginDoesNotExist) { +TEST_F(IECoreThreadingTests, SetConfigPluginDoesNotExist) { InferenceEngine::Core ie; std::map localConfig = { {CONFIG_KEY(PERF_COUNT), InferenceEngine::PluginConfigParams::YES}}; @@ -88,7 +88,7 @@ TEST_F(CoreThreadingTests, SetConfigPluginDoesNotExist) { #ifndef OPENVINO_STATIC_LIBRARY // tested function: RegisterPlugin -TEST_F(CoreThreadingTests, RegisterPlugin) { +TEST_F(IECoreThreadingTests, RegisterPlugin) { InferenceEngine::Core ie; std::atomic index{0}; runParallel( @@ -104,7 +104,7 @@ TEST_F(CoreThreadingTests, RegisterPlugin) { } // tested function: RegisterPlugins -TEST_F(CoreThreadingTests, RegisterPlugins) { +TEST_F(IECoreThreadingTests, RegisterPlugins) { InferenceEngine::Core ie; std::atomic index{0}; @@ -145,7 +145,7 @@ TEST_F(CoreThreadingTests, RegisterPlugins) { // tested function: GetAvailableDevices, UnregisterPlugin // TODO: some initialization (e.g. thread/dlopen) sporadically fails during such stress-test scenario -TEST_F(CoreThreadingTests, GetAvailableDevices) { +TEST_F(IECoreThreadingTests, GetAvailableDevices) { #ifdef OV_TEST_GLIBC_VERSION_LESS_2_34 GTEST_SKIP(); #endif @@ -170,7 +170,7 @@ TEST_F(CoreThreadingTests, GetAvailableDevices) { #if defined(ENABLE_OV_IR_FRONTEND) // tested function: ReadNetwork, AddExtension -TEST_F(CoreThreadingTests, ReadNetwork) { +TEST_F(IECoreThreadingTests, ReadNetwork) { InferenceEngine::Core ie; auto network = ie.ReadNetwork(modelName, weightsName); diff --git a/src/inference/tests/functional/local_test.cpp b/src/inference/tests/functional/local_test.cpp index f25407d198d..f4b170808f2 100644 --- a/src/inference/tests/functional/local_test.cpp +++ b/src/inference/tests/functional/local_test.cpp @@ -4,90 +4,89 @@ #include -#include - -#include "ngraph/ops.hpp" +#include "openvino/op/roi_align.hpp" +#include "openvino/op/util/rnn_cell_base.hpp" +#include "openvino/runtime/core.hpp" using namespace ::testing; using namespace std; -using namespace InferenceEngine; class LocaleTests : public ::testing::Test { std::string originalLocale; std::string _model = R"V0G0N( - - - - - - 1 - 256 - 200 - 272 - - - - - - - - 1000 - 4 - - - - - - - - 1000 - - - - - - - - 1 - 256 - 200 - 272 - - - 1000 - 4 - - - 1000 - - - - - 1000 - 256 - 7 - 7 - - - - - - - 1000 - 256 - 7 - 7 - - - - - - - - - - + + + + + + 1 + 256 + 200 + 272 + + + + + + + + 1000 + 4 + + + + + + + + 1000 + + + + + + + + 1 + 256 + 200 + 272 + + + 1000 + 4 + + + 1000 + + + + + 1000 + 256 + 7 + 7 + + + + + + + 1000 + 256 + 7 + 7 + + + + + + + + + + )V0G0N"; @@ -185,22 +184,22 @@ class LocaleTests : public ::testing::Test { - - - - 1 - 256 - - - - - - - 1 - 256 - - - + + + + 1 + 256 + + + + + + + 1 + 256 + + + @@ -224,19 +223,17 @@ protected: } void testBody(bool isLSTM = false) const { - InferenceEngine::Core core; + ov::Core core; - std::string model = isLSTM ? _model_LSTM : _model; - auto blob = make_shared_blob(TensorDesc(Precision::U8, {26000000}, Layout::C)); - blob->allocate(); - auto net = core.ReadNetwork(model, blob); + std::string model_str = isLSTM ? _model_LSTM : _model; + auto tensor = ov::Tensor(ov::element::u8, {26000000}); + auto model = core.read_model(model_str, tensor); - auto funcs = net.getFunction(); - - for (const auto& op : funcs->get_ops()) { + for (const auto& op : model->get_ops()) { if (!isLSTM) { if (op->get_friendly_name() == "output") { - const auto roi = std::dynamic_pointer_cast(op); + const auto roi = std::dynamic_pointer_cast(op); + ASSERT_TRUE(roi); ASSERT_EQ(roi->get_pooled_h(), 7); ASSERT_EQ(roi->get_pooled_w(), 7); ASSERT_EQ(roi->get_sampling_ratio(), 2); @@ -244,7 +241,8 @@ protected: } } else { if (op->get_friendly_name() == "LSTMCell") { - const auto lstm_seq = std::dynamic_pointer_cast(op); + const auto lstm_seq = std::dynamic_pointer_cast(op); + ASSERT_TRUE(lstm_seq); ASSERT_EQ(lstm_seq->get_clip(), 0.0f); ASSERT_EQ(lstm_seq->get_hidden_size(), 256); } diff --git a/src/inference/tests/functional/matmul_sr_tests.cpp b/src/inference/tests/functional/matmul_sr_tests.cpp index 5e669b94229..b4c0cd45e08 100644 --- a/src/inference/tests/functional/matmul_sr_tests.cpp +++ b/src/inference/tests/functional/matmul_sr_tests.cpp @@ -4,20 +4,25 @@ #include -#include #include #include -#include -#include -#include #include -#include -#include #include "cnn_network_ngraph_impl.hpp" +#include "common_test_utils/graph_comparator.hpp" +#include "common_test_utils/test_common.hpp" +#include "ie_common.h" +#include "openvino/op/constant.hpp" +#include "openvino/op/matmul.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/transpose.hpp" +#include "openvino/op/variadic_split.hpp" +#include "openvino/pass/manager.hpp" +#include "transformations/init_node_info.hpp" +#include "transformations/smart_reshape/matmul_sr.hpp" using namespace testing; -using namespace InferenceEngine; namespace { @@ -25,7 +30,7 @@ using reshape_map = std::map>; struct ReshapeMatMulTestCase { bool reshape_is_A_input; - ngraph::PartialShape A_shape, B_shape; + ov::PartialShape A_shape, B_shape; std::vector reshape_pattern; bool transpose_a, transpose_b; reshape_map new_shapes; @@ -66,46 +71,45 @@ public: void SetUp() override { const auto& test_case = std::get<0>(GetParam()); - std::shared_ptr ngraph; + std::shared_ptr model; { - auto input_A = std::make_shared(ngraph::element::f32, test_case.A_shape); + auto input_A = std::make_shared(ov::element::f32, test_case.A_shape); input_A->set_friendly_name("input_A"); - auto input_B = std::make_shared(ngraph::element::f32, test_case.B_shape); + auto input_B = std::make_shared(ov::element::f32, test_case.B_shape); input_B->set_friendly_name("input_B"); - auto reshape_pattern = - std::make_shared(ngraph::element::i64, - ngraph::Shape{test_case.reshape_pattern.size()}, - test_case.reshape_pattern); + auto reshape_pattern = std::make_shared(ov::element::i64, + ov::Shape{test_case.reshape_pattern.size()}, + test_case.reshape_pattern); reshape_pattern->set_friendly_name("reshape_pattern"); - auto reshape = std::make_shared(test_case.reshape_is_A_input ? input_A : input_B, - reshape_pattern, - true); + auto reshape = std::make_shared(test_case.reshape_is_A_input ? input_A : input_B, + reshape_pattern, + true); reshape->set_friendly_name("reshape"); - auto mat_mul = std::make_shared( + auto mat_mul = std::make_shared( test_case.reshape_is_A_input ? reshape->output(0) : input_A->output(0), test_case.reshape_is_A_input ? input_B->output(0) : reshape->output(0), test_case.transpose_a, test_case.transpose_b); reshape->set_friendly_name("matmul"); - auto result = std::make_shared(mat_mul); - ngraph::ParameterVector params = {input_A, input_B}; - ngraph::ResultVector results = {result}; - ngraph = std::make_shared(results, params); + auto result = std::make_shared(mat_mul); + ov::ParameterVector params = {input_A, input_B}; + ov::ResultVector results = {result}; + model = std::make_shared(results, params); } - InferenceEngine::details::CNNNetworkNGraphImpl network(ngraph); + InferenceEngine::details::CNNNetworkNGraphImpl network(model); const auto& resp = network.reshape(test_case.new_shapes, nullptr); - ASSERT_EQ(resp, StatusCode::OK); + ASSERT_EQ(resp, InferenceEngine::StatusCode::OK); } }; TEST_P(SmartReshapeMatMulTests, ReshapeMatMul) {} INSTANTIATE_TEST_SUITE_P( - NGraph, + OVModel, SmartReshapeMatMulTests, testing::Values( ReshapeMatMulTestCase{true, {1, 20, 30}, {30, 40}, {20, -1}, false, false, {{"input_A", {2, 20, 30}}}}, @@ -120,14 +124,14 @@ INSTANTIATE_TEST_SUITE_P( } // namespace TEST(SmartReshapeTransposeMatMulTests, TransposeAMatMulFuse) { - std::shared_ptr f(nullptr), f_ref(nullptr); + std::shared_ptr f(nullptr), f_ref(nullptr); { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 2}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 5}); - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); - auto transpose = std::make_shared(data_A, order); - auto matmul = std::make_shared(transpose, data_B, false, false); - f = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 3, 2}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 3, 5}); + auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 2, 1}); + auto transpose = std::make_shared(data_A, order); + auto matmul = std::make_shared(transpose, data_B, false, false); + f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); ov::pass::Manager m; m.register_pass(); @@ -136,10 +140,10 @@ TEST(SmartReshapeTransposeMatMulTests, TransposeAMatMulFuse) { ASSERT_NO_THROW(check_rt_info(f)); } { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 2}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 5}); - auto matmul = std::make_shared(data_A, data_B, true, false); - f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 3, 2}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 3, 5}); + auto matmul = std::make_shared(data_A, data_B, true, false); + f_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); } auto res = compare_functions(f, f_ref); @@ -147,26 +151,26 @@ TEST(SmartReshapeTransposeMatMulTests, TransposeAMatMulFuse) { } TEST(SmartReshapeTransposeMatMulTests, TransposeBMatMulFuse) { - std::shared_ptr f(nullptr), f_ref(nullptr); + std::shared_ptr f(nullptr), f_ref(nullptr); { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2, 3}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 5, 3}); - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); - auto transpose = std::make_shared(data_B, order); - auto matmul = std::make_shared(data_A, transpose, false, false); - f = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 2, 3}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 5, 3}); + auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 2, 1}); + auto transpose = std::make_shared(data_B, order); + auto matmul = std::make_shared(data_A, transpose, false, false); + f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); - ngraph::pass::Manager m; + ov::pass::Manager m; m.register_pass(); m.register_pass(); m.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2, 3}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 5, 3}); - auto matmul = std::make_shared(data_A, data_B, false, true); - f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 2, 3}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 5, 3}); + auto matmul = std::make_shared(data_A, data_B, false, true); + f_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); } auto res = compare_functions(f, f_ref); @@ -174,26 +178,26 @@ TEST(SmartReshapeTransposeMatMulTests, TransposeBMatMulFuse) { } TEST(SmartReshapeTransposeMatMulTests, TransposeAMatMulWithAttrFuse) { - std::shared_ptr f(nullptr), f_ref(nullptr); + std::shared_ptr f(nullptr), f_ref(nullptr); { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2, 3}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 5}); - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); - auto transpose = std::make_shared(data_A, order); - auto matmul = std::make_shared(transpose, data_B, true, false); - f = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 2, 3}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 3, 5}); + auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 2, 1}); + auto transpose = std::make_shared(data_A, order); + auto matmul = std::make_shared(transpose, data_B, true, false); + f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); - ngraph::pass::Manager m; + ov::pass::Manager m; m.register_pass(); m.register_pass(); m.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2, 3}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 5}); - auto matmul = std::make_shared(data_A, data_B, false, false); - f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 2, 3}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 3, 5}); + auto matmul = std::make_shared(data_A, data_B, false, false); + f_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); } auto res = compare_functions(f, f_ref); @@ -201,52 +205,52 @@ TEST(SmartReshapeTransposeMatMulTests, TransposeAMatMulWithAttrFuse) { } TEST(SmartReshapeTransposeMatMulTests, TransposeBMatMulWithAttrFuse) { - std::shared_ptr f(nullptr), f_ref(nullptr); + std::shared_ptr f(nullptr), f_ref(nullptr); { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2, 3}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 5}); - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); - auto transpose = std::make_shared(data_B, order); - auto matmul = std::make_shared(data_A, transpose, false, true); - f = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 2, 3}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 3, 5}); + auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 2, 1}); + auto transpose = std::make_shared(data_B, order); + auto matmul = std::make_shared(data_A, transpose, false, true); + f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); - ngraph::pass::Manager m; + ov::pass::Manager m; m.register_pass(); m.register_pass(); m.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2, 3}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 5}); - auto matmul = std::make_shared(data_A, data_B, false, false); - f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 2, 3}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 3, 5}); + auto matmul = std::make_shared(data_A, data_B, false, false); + f_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); } auto res = compare_functions(f, f_ref); ASSERT_TRUE(res.first) << res.second; } TEST(SmartReshapeTransposeMatMulTests, TransposeAMatMulSideAttrFuse) { - std::shared_ptr f(nullptr), f_ref(nullptr); + std::shared_ptr f(nullptr), f_ref(nullptr); { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2, 3}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 5, 3}); - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); - auto transpose = std::make_shared(data_A, order); - auto matmul = std::make_shared(transpose, data_B, true, true); - f = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 2, 3}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 5, 3}); + auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 2, 1}); + auto transpose = std::make_shared(data_A, order); + auto matmul = std::make_shared(transpose, data_B, true, true); + f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); - ngraph::pass::Manager m; + ov::pass::Manager m; m.register_pass(); m.register_pass(); m.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2, 3}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 5, 3}); - auto matmul = std::make_shared(data_A, data_B, false, true); - f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 2, 3}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 5, 3}); + auto matmul = std::make_shared(data_A, data_B, false, true); + f_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); } auto res = compare_functions(f, f_ref); @@ -254,26 +258,26 @@ TEST(SmartReshapeTransposeMatMulTests, TransposeAMatMulSideAttrFuse) { } TEST(SmartReshapeTransposeMatMulTests, TransposeBMatMulSideAttrFuse) { - std::shared_ptr f(nullptr), f_ref(nullptr); + std::shared_ptr f(nullptr), f_ref(nullptr); { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 2}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 5}); - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); - auto transpose = std::make_shared(data_B, order); - auto matmul = std::make_shared(data_A, transpose, true, true); - f = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 3, 2}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 3, 5}); + auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 2, 1}); + auto transpose = std::make_shared(data_B, order); + auto matmul = std::make_shared(data_A, transpose, true, true); + f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); - ngraph::pass::Manager m; + ov::pass::Manager m; m.register_pass(); m.register_pass(); m.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 2}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 5}); - auto matmul = std::make_shared(data_A, data_B, true, false); - f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 3, 2}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 3, 5}); + auto matmul = std::make_shared(data_A, data_B, true, false); + f_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); } auto res = compare_functions(f, f_ref); @@ -281,70 +285,70 @@ TEST(SmartReshapeTransposeMatMulTests, TransposeBMatMulSideAttrFuse) { } TEST(SmartReshapeTransposeMatMulTests, TransposeBothMatMulFuse) { - std::shared_ptr f(nullptr), f_ref(nullptr); + std::shared_ptr f(nullptr), f_ref(nullptr); { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 2}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 5, 3}); - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); - auto transpose_A = std::make_shared(data_A, order); - auto transpose_B = std::make_shared(data_B, order); - auto matmul = std::make_shared(transpose_A, transpose_B, false, false); - f = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 3, 2}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 5, 3}); + auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 2, 1}); + auto transpose_A = std::make_shared(data_A, order); + auto transpose_B = std::make_shared(data_B, order); + auto matmul = std::make_shared(transpose_A, transpose_B, false, false); + f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); - ngraph::pass::Manager m; + ov::pass::Manager m; m.register_pass(); m.register_pass(); m.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 2}); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 5, 3}); - auto matmul = std::make_shared(data_A, data_B, true, true); - f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + auto data_A = std::make_shared(ov::element::f32, ov::Shape{1, 3, 2}); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{1, 5, 3}); + auto matmul = std::make_shared(data_A, data_B, true, true); + f_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); } auto res = compare_functions(f, f_ref); ASSERT_TRUE(res.first) << res.second; } TEST(SmartReshapeTransposeMatMulTests, TransposeBothMatMulWithAttrFuse) { - std::shared_ptr f(nullptr), f_ref(nullptr); + std::shared_ptr f(nullptr), f_ref(nullptr); { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3, 2}); - auto split_A = std::make_shared( + auto data_A = std::make_shared(ov::element::f32, ov::Shape{2, 3, 2}); + auto split_A = std::make_shared( data_A, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3, 5}); - auto split_B = std::make_shared( + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0}), + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {1, 1})); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{2, 3, 5}); + auto split_B = std::make_shared( data_B, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); - auto transpose_A = std::make_shared(split_A->output(0), order); - auto transpose_B = std::make_shared(split_B->output(1), order); - auto matmul = std::make_shared(transpose_A, transpose_B, false, true); - f = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0}), + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {1, 1})); + auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 2, 1}); + auto transpose_A = std::make_shared(split_A->output(0), order); + auto transpose_B = std::make_shared(split_B->output(1), order); + auto matmul = std::make_shared(transpose_A, transpose_B, false, true); + f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); - ngraph::pass::Manager m; + ov::pass::Manager m; m.register_pass(); m.register_pass(); m.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3, 2}); - auto split_A = std::make_shared( + auto data_A = std::make_shared(ov::element::f32, ov::Shape{2, 3, 2}); + auto split_A = std::make_shared( data_A, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); - auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3, 5}); - auto split_B = std::make_shared( + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0}), + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {1, 1})); + auto data_B = std::make_shared(ov::element::f32, ov::Shape{2, 3, 5}); + auto split_B = std::make_shared( data_B, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); - auto matmul = std::make_shared(split_A->output(0), split_B->output(1), true, false); - f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0}), + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {1, 1})); + auto matmul = std::make_shared(split_A->output(0), split_B->output(1), true, false); + f_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{data_A, data_B}); } auto res = compare_functions(f, f_ref); diff --git a/src/inference/tests/functional/ov_core_threading.cpp b/src/inference/tests/functional/ov_core_threading.cpp new file mode 100644 index 00000000000..c03c1e453e9 --- /dev/null +++ b/src/inference/tests/functional/ov_core_threading.cpp @@ -0,0 +1,182 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include +#include +#include + +#include "common_test_utils/common_utils.hpp" +#include "common_test_utils/file_utils.hpp" +#include "common_test_utils/test_assertions.hpp" +#include "functional_test_utils/test_model/test_model.hpp" +#include "openvino/runtime/core.hpp" +#include "openvino/util/file_util.hpp" +#ifdef __GLIBC__ +# include +# if __GLIBC_MINOR__ < 34 +# define OV_TEST_GLIBC_VERSION_LESS_2_34 +# endif +#endif + +class CoreThreadingTests : public ::testing::Test { +protected: + std::string modelName = "CoreThreadingTests.xml", weightsName = "CoreThreadingTests.bin"; + +public: + void SetUp() override { + auto prefix = ov::test::utils::generateTestFilePrefix(); + modelName = prefix + modelName; + weightsName = prefix + weightsName; + FuncTestUtils::TestModel::generateTestModel(modelName, weightsName); + } + + void TearDown() override { + ov::test::utils::removeIRFiles(modelName, weightsName); + } + + void runParallel(std::function func, + const unsigned int iterations = 100, + const unsigned int threadsNum = 8) { + std::vector threads(threadsNum); + + for (auto& thread : threads) { + thread = std::thread([&]() { + for (unsigned int i = 0; i < iterations; ++i) { + func(); + } + }); + } + + for (auto& thread : threads) { + if (thread.joinable()) + thread.join(); + } + } + + void safeAddExtension(ov::Core& core) { + try { + auto extension = std::make_shared( + ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), + std::string("template_extension") + IE_BUILD_POSTFIX)); + core.add_extension(extension); + } catch (const ov::Exception& ex) { + ASSERT_STR_CONTAINS(ex.what(), "name: custom_opset. Opset"); + } + } +}; + +// tested function: SetConfig +TEST_F(CoreThreadingTests, SetConfigPluginDoesNotExist) { + ov::Core core; + + runParallel( + [&]() { + core.set_property(ov::enable_profiling(true)); + }, + 10000); +} + +// TODO: CVS-68982 +#ifndef OPENVINO_STATIC_LIBRARY + +// tested function: RegisterPlugin +TEST_F(CoreThreadingTests, RegisterPlugin) { + ov::Core core; + std::atomic index{0}; + runParallel( + [&]() { + const std::string deviceName = std::to_string(index++); + core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), + std::string("mock_engine") + IE_BUILD_POSTFIX), + deviceName); + core.get_versions(deviceName); + core.unload_plugin(deviceName); + }, + 4000); +} + +// tested function: RegisterPlugins +TEST_F(CoreThreadingTests, RegisterPlugins) { + ov::Core core; + std::atomic index{0}; + + auto getPluginXml = [&]() -> std::tuple { + std::string indexStr = std::to_string(index++); + std::string pluginsXML = "test_plugins" + indexStr + ".xml"; + std::ofstream file(pluginsXML); + + file << "::file_separator; + file << ov::util::FileTraits::library_prefix(); + file << "mock_engine"; + file << IE_BUILD_POSTFIX; + file << ov::util::FileTraits::dot_symbol; + file << ov::util::FileTraits::library_ext(); + file << "\" name=\""; + file << indexStr; + file << "\">"; + file.flush(); + file.close(); + + return std::tie(pluginsXML, indexStr); + }; + + runParallel( + [&]() { + std::string fileName, deviceName; + std::tie(fileName, deviceName) = getPluginXml(); + core.register_plugins(fileName); + core.get_versions(deviceName); + ASSERT_EQ(0, std::remove(fileName.c_str())); + }, + 1000); +} + +#endif // !OPENVINO_STATIC_LIBRARY + +// tested function: get_available_devices, unload_plugin +// TODO: some initialization (e.g. thread/dlopen) sporadically fails during such stress-test scenario +TEST_F(CoreThreadingTests, GetAvailableDevices) { +#ifdef OV_TEST_GLIBC_VERSION_LESS_2_34 + GTEST_SKIP(); +#endif + ov::Core core; + runParallel( + [&]() { + std::vector devices = core.get_available_devices(); + + // unregister all the devices + for (auto&& deviceName : devices) { + try { + core.unload_plugin(deviceName); + } catch (const ov::Exception& ex) { + // if several threads unload plugin at once, the first thread does this + // while all others will throw an exception that plugin is not registered + ASSERT_STR_CONTAINS(ex.what(), "name is not registered in the"); + } + } + }, + 30); +} + +#if defined(ENABLE_OV_IR_FRONTEND) +// tested function: read_model and add_legacy_extension +TEST_F(CoreThreadingTests, ReadModel) { + ov::Core core; + auto model = core.read_model(modelName, weightsName); + + runParallel( + [&]() { + safeAddExtension(core); + (void)core.read_model(modelName, weightsName); + }, + 100, + 12); +} +#endif // defined(ENABLE_OV_IR_FRONTEND)