From 3fe7f2081a84b0c91fdaaea4e6bdb58f3f8f4eb8 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Thu, 19 Aug 2021 07:22:40 +0300 Subject: [PATCH 001/102] . --- .../precommit_configs/desktop_test_config.xml | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml index 12cd28c0c8cd7c..7e9169bf4a7ac7 100644 --- a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml @@ -1,18 +1,8 @@ - - - 1 - - - 1 - - - 30 - - - CPU - GPU - - + + - - \ No newline at end of file + + + + + \ No newline at end of file From 0f183b5d4390c360fd6a95e1ee4d4536dd252ddb Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Thu, 19 Aug 2021 12:34:36 +0300 Subject: [PATCH 002/102] . --- tests/stress_tests/common/tests_utils.cpp | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 82cd7c5ab68bff..94b155933c895b 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -75,6 +75,48 @@ std::vector generateTestsParams(std::initializer_list fie for (auto &device : devices) for (int i = 0; i < models.size(); i++) tests_cases.push_back(TestCase(numprocesses, numthreads, numiters, device, models[i], models_names[i], precisions[i])); + return tests_cases; +} + +std::vector generateTestsParamsMemLeaks(std::initializer_list fields) { + std::vector tests_cases; + const pugi::xml_document & test_config = Environment::Instance().getTestConfig(); + + int numprocesses = 1, numthreads = 1, numiterations = 1; + std::string device = "NULL"; + + + pugi::xml_node models; + pugi::xml_node cases; + cases = test_config.child("cases").child("device"); + + for (pugi::xml_node device = cases.first_child(); device; device = device.next_sibling()) { + name = device.attribute("name").as_string(); + numprocesses = device.attribute("processes").as_int(); + numthreads = device.attribute("threads").as_int(); + numiterations = device.attribute("iterations").as_int(); + + std::vector models, models_names, precisions; + for (pugi::xml_node model = device.first_child(); model; model = model.next_sibling()){ + std::string full_path = model.attribute("full_path").as_string(); + std::string path = model.attribute("path").as_string(); + if (full_path.empty() || path.empty()) + throw std::logic_error("One of the 'model' records from test config doesn't contain 'full_path' or 'path' attributes"); + else { + models.push_back(full_path); + models_names.push_back(path); + } + std::string precision = model.attribute("precision").as_string(); + precisions.push_back(precision); + } + // Initialize variables with default value if it weren't filled + models = !models.empty() ? models : std::vector{"NULL"}; + precisions = !precisions.empty() ? precisions : std::vector{"NULL"}; + models_names = !models_names.empty() ? models_names : std::vector{"NULL"}; + + tests_cases.push_back(TestCase(numprocesses, numthreads, numiters, device, models, models_names, precisions)) + } + return tests_cases; } From 6efbce2276f5a3e0812c8dc0ec881dc745cac036 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Fri, 20 Aug 2021 15:46:43 +0300 Subject: [PATCH 003/102] . --- tests/stress_tests/common/tests_utils.cpp | 18 ++++++------ tests/stress_tests/common/tests_utils.h | 31 +++++++++++++++++++++ tests/stress_tests/memleaks_tests/tests.cpp | 7 ++--- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 94b155933c895b..b51eb267754462 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -78,23 +78,21 @@ std::vector generateTestsParams(std::initializer_list fie return tests_cases; } -std::vector generateTestsParamsMemLeaks(std::initializer_list fields) { +std::vector generateTestsParamsMemLeaks() { std::vector tests_cases; const pugi::xml_document & test_config = Environment::Instance().getTestConfig(); - int numprocesses = 1, numthreads = 1, numiterations = 1; - std::string device = "NULL"; + int numprocesses, numthreads, numiteration, + std::string device; - - pugi::xml_node models; pugi::xml_node cases; cases = test_config.child("cases").child("device"); for (pugi::xml_node device = cases.first_child(); device; device = device.next_sibling()) { - name = device.attribute("name").as_string(); - numprocesses = device.attribute("processes").as_int(); - numthreads = device.attribute("threads").as_int(); - numiterations = device.attribute("iterations").as_int(); + device_name = device.attribute("name").as_string("NULL"); + numprocesses = device.attribute("processes").as_int(1); + numthreads = device.attribute("threads").as_int(1); + numiterations = device.attribute("iterations").as_int(1); std::vector models, models_names, precisions; for (pugi::xml_node model = device.first_child(); model; model = model.next_sibling()){ @@ -114,7 +112,7 @@ std::vector generateTestsParamsMemLeaks(std::initializer_list{"NULL"}; models_names = !models_names.empty() ? models_names : std::vector{"NULL"}; - tests_cases.push_back(TestCase(numprocesses, numthreads, numiters, device, models, models_names, precisions)) + tests_cases.push_back(TestCase(numprocesses, numthreads, numiters, device_name, models, models_names, precisions)) } return tests_cases; diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 42cb40fcdf0300..9ceb7c7aa6df37 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -52,6 +52,36 @@ class TestCase { } }; +class TestCaseMemLeaks { +public: + int numprocesses; + int numthreads; + int numiters; + std::string device; + std::vector models_names; + std::vector models; + std::vector precision;| + std::string test_case_name; + + TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string& _model, const std::string& _model_name, const std::string& _precision) { + numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, model_name = _model_name, precision = _precision; + test_case_name = + "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + + "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + "_Precision_" + + update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); + } + +private: + std::string update_item_for_name(const std::string &item) { + std::string _item(item); + for (std::string::size_type index = 0; index < _item.size(); ++index) { + if (!isalnum(_item[index]) && _item[index] != '_') + _item[index] = '_'; + } + return _item; + } +}; + class Environment { private: pugi::xml_document _test_config; @@ -71,6 +101,7 @@ class Environment { }; std::vector generateTestsParams(std::initializer_list items); +std::vector generateTestsParamsMemLeaks(std::initializer_list items); std::string getTestCaseName(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 7eedd5d541cabf..4f22ad27c09237 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -131,15 +131,14 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { // tests_pipelines/tests_pipelines.cpp INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoModel, - ::testing::ValuesIn(generateTestsParams({"processes", "threads", "iterations", "devices"})), + ::testing::ValuesIn(generateTestsParamsMemLeaks()), getTestCaseName); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoDevice, - ::testing::ValuesIn(generateTestsParams({"processes", "threads", "iterations", "models"})), + ::testing::ValuesIn(generateTestsParamsMemLeaks()), getTestCaseName); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuite, - ::testing::ValuesIn( - generateTestsParams({"processes", "threads", "iterations", "devices", "models"})), + ::testing::ValuesIn(generateTestsParamsMemLeaks()), getTestCaseName); From a808353e8cc576fe8205fbe51530ef2054bc2987 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Wed, 25 Aug 2021 16:45:19 +0300 Subject: [PATCH 004/102] add multimodel memleaks test runner --- tests/stress_tests/common/tests_utils.cpp | 19 +++-- tests/stress_tests/common/tests_utils.h | 20 +++--- tests/stress_tests/memleaks_tests/tests.cpp | 71 ++++++++++++++---- .../tests_pipelines/tests_pipelines.cpp | 72 +------------------ .../tests_pipelines/tests_pipelines.h | 11 +-- 5 files changed, 80 insertions(+), 113 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index b51eb267754462..c49af7536a011a 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #define DEBUG_MODE false @@ -94,25 +95,23 @@ std::vector generateTestsParamsMemLeaks() { numthreads = device.attribute("threads").as_int(1); numiterations = device.attribute("iterations").as_int(1); - std::vector models, models_names, precisions; + std::vector> models; + for (pugi::xml_node model = device.first_child(); model; model = model.next_sibling()){ + std::map models; std::string full_path = model.attribute("full_path").as_string(); std::string path = model.attribute("path").as_string(); if (full_path.empty() || path.empty()) throw std::logic_error("One of the 'model' records from test config doesn't contain 'full_path' or 'path' attributes"); else { - models.push_back(full_path); - models_names.push_back(path); + model["path"] = full_path; + model["name"] = path; } std::string precision = model.attribute("precision").as_string(); - precisions.push_back(precision); + model["precision"] = precision; + models.push_back(model); } - // Initialize variables with default value if it weren't filled - models = !models.empty() ? models : std::vector{"NULL"}; - precisions = !precisions.empty() ? precisions : std::vector{"NULL"}; - models_names = !models_names.empty() ? models_names : std::vector{"NULL"}; - - tests_cases.push_back(TestCase(numprocesses, numthreads, numiters, device_name, models, models_names, precisions)) + tests_cases.push_back(TestCaseMemLeaks(numprocesses, numthreads, numiters, device_name, models)) } return tests_cases; diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 9ceb7c7aa6df37..16ad8c1aca6b45 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -58,17 +58,21 @@ class TestCaseMemLeaks { int numthreads; int numiters; std::string device; - std::vector models_names; - std::vector models; - std::vector precision;| + std::vector> models; std::string test_case_name; + std::string models_names; - TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string& _model, const std::string& _model_name, const std::string& _precision) { - numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, model_name = _model_name, precision = _precision; + TestCaseMemLeaks(int _numprocesses, int _numthreads, int _numiters, std::string _device, std::vector> _models) { + numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, models = _models; test_case_name = "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + - "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + "_Precision_" + - update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); + "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device); + int i = 1; + for (auto model: models){ + test_case_name += "_Model" + std::to_string(i) + "_" + update_item_for_name(model["name"]) "_Precision_" + update_item_for_name(model["precision"]); + models_names += update_item_for_name(model["path"]) + "\n"; + i += 1; + } } private: @@ -101,7 +105,7 @@ class Environment { }; std::vector generateTestsParams(std::initializer_list items); -std::vector generateTestsParamsMemLeaks(std::initializer_list items); +std::vector generateTestsParamsMemLeaks(); std::string getTestCaseName(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 4f22ad27c09237..92b81bcd512678 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -42,32 +42,43 @@ inline void test_runner(int numthreads, const std::function &test_ // tests_pipelines/tests_pipelines.cpp TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { auto test_params = GetParam(); + std::vector pipeline {load_unload_plugin(test_params.device)}; auto test = [&] { - return test_load_unload_plugin(test_params.device, test_params.numiters); + log_info("Load/unload plugin for device: " << test_params.device << " for " << test_params.numiters << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } TEST_P(MemLeaksTestSuiteNoDevice, read_network) { auto test_params = GetParam(); + std::vector pipeline; + for (auto model: test_params.models) pipeline.push_back(read_cnnnetwork(model["path"])); auto test = [&] { - return test_read_network(test_params.model, test_params.numiters); + log_info("Read network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { auto test_params = GetParam(); + std::vector pipeline; + for (auto model: test_params.models) pipeline.push_back(cnnnetwork_reshape_batch_x2(model["path"])); auto test = [&] { - return test_cnnnetwork_reshape_batch_x2(test_params.model, test_params.numiters); + log_info("Reshape to batch*=2 of CNNNetwork created from network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { auto test_params = GetParam(); + std::vector pipeline; + for (auto model: test_params.models) pipeline.push_back(set_input_params(model["path"])); auto test = [&] { - return test_set_input_params(test_params.model, test_params.numiters); + log_info("Apply preprocessing for CNNNetwork from network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } @@ -75,8 +86,12 @@ TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { TEST_P(MemLeaksTestSuite, recreate_exenetwork) { auto test_params = GetParam(); Core ie; + std::vector pipeline; + for (auto model: test_params.models) pipeline.push_back(recreate_exenetwork(ie, model["path"], test_params.device)); auto test = [&] { - return test_recreate_exenetwork(ie, test_params.model, test_params.device, test_params.numiters); + log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: \"" + << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } @@ -84,19 +99,27 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { TEST_P(MemLeaksTestSuite, recreate_infer_request) { auto test_params = GetParam(); Core ie; - CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.model); - ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); + std::vector pipeline; + for (auto model: test_params.models){ + CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); + ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); + + pipeline.push_back(recreate_infer_request(exeNetwork)); + } auto test = [&] { - return test_recreate_infer_request(exeNetwork, test_params.model, test_params.device, test_params.numiters); + log_info("Create InferRequest from network: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " << test_params.numiters + << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } TEST_P(MemLeaksTestSuite, reinfer_request_inference) { auto test_params = GetParam(); - auto test = [&] { - Core ie; - CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.model); + Core ie; + std::vector pipeline; + for (auto model: test_params.models){ + CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); InferRequest infer_request = exeNetwork.CreateInferRequest(); @@ -106,24 +129,42 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { const InferenceEngine::ConstInputsDataMap inputsInfo(exeNetwork.GetInputsInfo()); fillBlobs(infer_request, inputsInfo, batchSize); - return test_reinfer_request_inference(infer_request, output_info, test_params.model, test_params.device, test_params.numiters); + pipeline.push_back(reinfer_request_inference(infer_request, output_info)); + } + auto test = [&] { + log_info("Inference of InferRequest from networks: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " + << test_params.numiters << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } TEST_P(MemLeaksTestSuite, infer_request_inference) { auto test_params = GetParam(); + std::vector pipeline; + for (auto model: test_params.models){ + pipeline.push_back(infer_request_inference(model["path"], test_params.device)); + } auto test = [&] { - return test_infer_request_inference(test_params.model, test_params.device, test_params.numiters); + log_info("Inference of InferRequest from networks: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " + << n << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } TEST_P(MemLeaksTestSuite, inference_with_streams) { - const auto nstreams = 2; auto test_params = GetParam(); + const auto nstreams = 2; + std::vector pipeline; + for (auto model: test_params.models){ + pipeline.push_back(inference_with_streams(model["path"], test_params.device, nstreams)); + } auto test = [&] { - return test_inference_with_streams(test_params.model, test_params.device, nstreams, test_params.numiters); + log_info("Inference of InferRequest from networks: \"" << test_params.models_names + << "\" for device: \"" << test_params.device + << "\" with streams: " << nstreams << " for " << test_params.numiters << " times"); + return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); } diff --git a/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.cpp b/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.cpp index a4e4aeed190b42..37f4f7241560ab 100644 --- a/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.cpp +++ b/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.cpp @@ -42,7 +42,7 @@ void transform(const In1& in1, const In2& in2, Out& out, const Func& func) { } } // namespace util -TestResult common_test_pipeline(const std::function& test_pipeline, const int& n) { +TestResult common_test_pipeline(std::vector> test_pipeline, const int& n) { if (AVERAGE_NUM > n) return TestResult(TestStatus::TEST_FAILED, "Test failed: number of iterations less than defined AVERAGE_NUM"); @@ -65,7 +65,7 @@ TestResult common_test_pipeline(const std::function& test_pipeline, cons for (size_t iteration = 1, measure_count = n / AVERAGE_NUM; ; iteration++) { // run test pipeline and collect metrics - test_pipeline(); + for (auto step: test_pipeline) step(); getVmValues(cur[VMSIZE], cur[VMPEAK], cur[VMRSS], cur[VMHWM]); cur[THREADS] = getThreadsNum(); @@ -147,71 +147,3 @@ TestResult common_test_pipeline(const std::function& test_pipeline, cons return TestResult(TestStatus::TEST_OK, ""); } - -TestResult test_load_unload_plugin(const std::string& target_device, const int& n) { - log_info("Load/unload plugin for device: " << target_device << " for " << n << " times"); - return common_test_pipeline(load_unload_plugin(target_device), n); -} - -TestResult test_read_network(const std::string& model, const int& n) { - log_info("Read network: \"" << model << "\" for " << n << " times"); - return common_test_pipeline(read_cnnnetwork(model), n); -} - -TestResult test_cnnnetwork_reshape_batch_x2(const std::string& model, const int& n) { - log_info("Reshape to batch*=2 of CNNNetwork created from network: \"" << model << "\" for " << n << " times"); - return common_test_pipeline(cnnnetwork_reshape_batch_x2(model), n); -} - -TestResult test_set_input_params(const std::string& model, const int& n) { - log_info("Apply preprocessing for CNNNetwork from network: \"" << model << "\" for " << n << " times"); - return common_test_pipeline(set_input_params(model), n); -} - -TestResult test_create_exenetwork(const std::string& model, const std::string& target_device, const int& n) { - log_info("Create ExecutableNetwork from network: \"" << model << "\" for device: \"" << target_device << "\" for " - << n << " times"); - return common_test_pipeline(create_exenetwork(model, target_device), n); -} - -TestResult test_recreate_exenetwork(InferenceEngine::Core& ie, const std::string& model, - const std::string& target_device, const int& n) { - log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: \"" - << model << "\" for device: \"" << target_device << "\" for " << n << " times"); - return common_test_pipeline(recreate_exenetwork(ie, model, target_device), n); -} - -TestResult test_create_infer_request(const std::string& model, const std::string& target_device, const int& n) { - log_info("Create InferRequest from network: \"" << model << "\" for device: \"" << target_device << "\" for " << n - << " times"); - return common_test_pipeline(create_infer_request(model, target_device), n); -} - -TestResult test_recreate_infer_request(ExecutableNetwork& network, const std::string& model, - const std::string& target_device, const int& n) { - log_info("Create InferRequest from network: \"" << model << "\" for device: \"" << target_device << "\" for " << n - << " times"); - return common_test_pipeline(recreate_infer_request(network), n); -} - -TestResult test_infer_request_inference(const std::string& model, const std::string& target_device, const int& n) { - log_info("Inference of InferRequest from network: \"" << model << "\" for device: \"" << target_device << "\" for " - << n << " times"); - return common_test_pipeline(infer_request_inference(model, target_device), n); -} - -TestResult test_reinfer_request_inference(InferenceEngine::InferRequest& infer_request, - InferenceEngine::OutputsDataMap& output_info, const std::string& model, - const std::string& target_device, const int& n) { - log_info("Inference of InferRequest from network: \"" << model << "\" for device: \"" << target_device << "\" for " - << n << " times"); - return common_test_pipeline(reinfer_request_inference(infer_request, output_info), n); -} - -TestResult test_inference_with_streams(const std::string& model, const std::string& target_device, - const int& nstreams, const int& n) { - log_info("Inference of InferRequest from network: \"" << model - << "\" for device: \"" << target_device - << "\" with streams: " << nstreams << " for " << n << " times"); - return common_test_pipeline(inference_with_streams(model, target_device, nstreams), n); -} diff --git a/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.h b/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.h index 64aee91640061a..cf5e83c485f131 100644 --- a/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.h +++ b/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.h @@ -13,14 +13,5 @@ #include // tests_pipelines/tests_pipelines.cpp -TestResult test_load_unload_plugin(const std::string &target_device, const int &n); -TestResult test_read_network(const std::string &model, const int &n); -TestResult test_cnnnetwork_reshape_batch_x2(const std::string &model, const int &n); -TestResult test_set_input_params(const std::string &model, const int &n); -TestResult test_recreate_exenetwork(InferenceEngine::Core &ie, const std::string &model, const std::string &target_device, const int &n); -TestResult test_create_infer_request(const std::string &model, const std::string &target_device, const int &n); -TestResult test_recreate_infer_request(InferenceEngine::ExecutableNetwork& network, const std::string &model, const std::string &target_device, const int &n); -TestResult test_infer_request_inference(const std::string &model, const std::string &target_device, const int &n); -TestResult test_reinfer_request_inference(InferenceEngine::InferRequest& infer_request, InferenceEngine::OutputsDataMap& output_info, const std::string &model, const std::string &target_device, const int &n); -TestResult test_inference_with_streams(const std::string &model, const std::string &target_device, const int &nstreams, const int &n); +TestResult common_test_pipeline(std::vector> test_pipeline, const int& n); // tests_pipelines/tests_pipelines.cpp From cf390cf92ff1031dee6a6c8520ce92912bf84168 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 30 Aug 2021 18:02:43 +0300 Subject: [PATCH 005/102] . --- .../precommit_configs/desktop_test_config.xml | 8 +- tests/stress_tests/common/tests_utils.cpp | 25 ++-- tests/stress_tests/common/tests_utils.h | 3 +- tests/stress_tests/memleaks_tests/tests.cpp | 32 ++--- tests/stress_tests/scripts/get_testdata.py | 120 +++++++++--------- 5 files changed, 96 insertions(+), 92 deletions(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml index 7e9169bf4a7ac7..11ae1ca2d4cd96 100644 --- a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml @@ -1,8 +1,8 @@ - - + + - - + + \ No newline at end of file diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index c49af7536a011a..97271354b9a795 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -80,14 +80,14 @@ std::vector generateTestsParams(std::initializer_list fie } std::vector generateTestsParamsMemLeaks() { - std::vector tests_cases; + std::vector tests_cases; const pugi::xml_document & test_config = Environment::Instance().getTestConfig(); - int numprocesses, numthreads, numiteration, - std::string device; + int numprocesses, numthreads, numiterations; + std::string device_name; pugi::xml_node cases; - cases = test_config.child("cases").child("device"); + cases = test_config.child("cases"); for (pugi::xml_node device = cases.first_child(); device; device = device.next_sibling()) { device_name = device.attribute("name").as_string("NULL"); @@ -95,23 +95,18 @@ std::vector generateTestsParamsMemLeaks() { numthreads = device.attribute("threads").as_int(1); numiterations = device.attribute("iterations").as_int(1); - std::vector> models; + std::vector > models; for (pugi::xml_node model = device.first_child(); model; model = model.next_sibling()){ - std::map models; std::string full_path = model.attribute("full_path").as_string(); std::string path = model.attribute("path").as_string(); if (full_path.empty() || path.empty()) throw std::logic_error("One of the 'model' records from test config doesn't contain 'full_path' or 'path' attributes"); - else { - model["path"] = full_path; - model["name"] = path; - } std::string precision = model.attribute("precision").as_string(); - model["precision"] = precision; - models.push_back(model); + std::map model_map { {"name", path}, {"path", full_path}, {"path", precision} }; + models.push_back(model_map); } - tests_cases.push_back(TestCaseMemLeaks(numprocesses, numthreads, numiters, device_name, models)) + tests_cases.push_back(TestCaseMemLeaks(numprocesses, numthreads, numiterations, device_name, models)); } return tests_cases; @@ -121,6 +116,10 @@ std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj) { + return obj.param.test_case_name; +} + void test_wrapper(const std::function &tests_pipeline, const TestCase ¶ms) { tests_pipeline(params.model, params.device, params.numiters); } diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 16ad8c1aca6b45..eb933a74dc3813 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -69,7 +69,7 @@ class TestCaseMemLeaks { "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device); int i = 1; for (auto model: models){ - test_case_name += "_Model" + std::to_string(i) + "_" + update_item_for_name(model["name"]) "_Precision_" + update_item_for_name(model["precision"]); + test_case_name += "_Model" + std::to_string(i) + "_" + update_item_for_name(model["name"]) + "_Precision_" + update_item_for_name(model["precision"]); models_names += update_item_for_name(model["path"]) + "\n"; i += 1; } @@ -107,6 +107,7 @@ class Environment { std::vector generateTestsParams(std::initializer_list items); std::vector generateTestsParamsMemLeaks(); std::string getTestCaseName(const testing::TestParamInfo &obj); +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); void _runTest(const std::function &tests_pipeline, const TestCase ¶ms); diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 92b81bcd512678..e9bf9663e42ed5 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -13,13 +13,13 @@ using namespace InferenceEngine; -class MemLeaksTestSuiteNoModel : public ::testing::TestWithParam { +class MemLeaksTestSuiteNoModel : public ::testing::TestWithParam { }; -class MemLeaksTestSuiteNoDevice : public ::testing::TestWithParam { +class MemLeaksTestSuiteNoDevice : public ::testing::TestWithParam { }; -class MemLeaksTestSuite : public ::testing::TestWithParam { +class MemLeaksTestSuite : public ::testing::TestWithParam { }; inline void test_runner(int numthreads, const std::function &test_function) { @@ -42,7 +42,7 @@ inline void test_runner(int numthreads, const std::function &test_ // tests_pipelines/tests_pipelines.cpp TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { auto test_params = GetParam(); - std::vector pipeline {load_unload_plugin(test_params.device)}; + std::vector> pipeline = { load_unload_plugin(test_params.device) }; auto test = [&] { log_info("Load/unload plugin for device: " << test_params.device << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); @@ -52,7 +52,7 @@ TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { TEST_P(MemLeaksTestSuiteNoDevice, read_network) { auto test_params = GetParam(); - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models) pipeline.push_back(read_cnnnetwork(model["path"])); auto test = [&] { log_info("Read network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); @@ -63,7 +63,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, read_network) { TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { auto test_params = GetParam(); - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models) pipeline.push_back(cnnnetwork_reshape_batch_x2(model["path"])); auto test = [&] { log_info("Reshape to batch*=2 of CNNNetwork created from network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); @@ -74,7 +74,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { auto test_params = GetParam(); - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models) pipeline.push_back(set_input_params(model["path"])); auto test = [&] { log_info("Apply preprocessing for CNNNetwork from network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); @@ -86,7 +86,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { TEST_P(MemLeaksTestSuite, recreate_exenetwork) { auto test_params = GetParam(); Core ie; - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models) pipeline.push_back(recreate_exenetwork(ie, model["path"], test_params.device)); auto test = [&] { log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: \"" @@ -99,7 +99,7 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { TEST_P(MemLeaksTestSuite, recreate_infer_request) { auto test_params = GetParam(); Core ie; - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models){ CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); @@ -117,7 +117,7 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { TEST_P(MemLeaksTestSuite, reinfer_request_inference) { auto test_params = GetParam(); Core ie; - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models){ CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); @@ -141,13 +141,13 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { TEST_P(MemLeaksTestSuite, infer_request_inference) { auto test_params = GetParam(); - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models){ pipeline.push_back(infer_request_inference(model["path"], test_params.device)); } auto test = [&] { log_info("Inference of InferRequest from networks: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " - << n << " times"); + << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -156,7 +156,7 @@ TEST_P(MemLeaksTestSuite, infer_request_inference) { TEST_P(MemLeaksTestSuite, inference_with_streams) { auto test_params = GetParam(); const auto nstreams = 2; - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models){ pipeline.push_back(inference_with_streams(model["path"], test_params.device, nstreams)); } @@ -173,13 +173,13 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoModel, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoDevice, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuite, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index cae9de7bec032a..239666f6d6fa34 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -95,6 +95,9 @@ def main(): parser.add_argument('--test_conf', required=True, type=Path, help='Path to a test config .xml file containing models ' 'which will be downloaded and converted to IRs via OMZ.') + parser.add_argument('--mode', + default="", + help='help me') parser.add_argument('--omz_repo', required=False, help='Path to Open Model Zoo (OMZ) repository. It will be used to skip cloning step.') parser.add_argument('--mo_tool', type=Path, @@ -144,64 +147,65 @@ def main(): # parse models from test config test_conf_obj = ET.parse(str(args.test_conf)) test_conf_root = test_conf_obj.getroot() - for model_rec in test_conf_root.find("models"): - if "name" not in model_rec.attrib or model_rec.attrib.get("source") != "omz": - continue - model_name = model_rec.attrib["name"] - precision = model_rec.attrib["precision"] - - info_dumper_path = omz_path / "tools" / "downloader" / "info_dumper.py" - cmd = '"{executable}" "{info_dumper_path}" --name {model_name}'.format(executable=sys.executable, - info_dumper_path=info_dumper_path, - model_name=model_name) - try: - out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True, universal_newlines=True) - except subprocess.CalledProcessError as exc: - log.warning(exc.output) - continue - - model_info = json.loads(out)[0] - - # update model record from test config with Open Model Zoo info - fields_to_add = ["framework", "subdirectory"] - info_to_add = {key: model_info[key] for key in fields_to_add} - # check selected precision with model info from Open Model Zoo - if precision not in model_info['precisions']: - log.warning("Please specify precision for the model " - "{model_name} from the list: {model_info}".format(model_name=model_name, - model_info=model_info['precisions'])) - continue - model_rec.attrib.update(info_to_add) - model_rec.attrib["path"] = str( - Path(model_rec.attrib["subdirectory"]) / precision / (model_rec.attrib["name"] + ".xml")) - model_rec.attrib["full_path"] = str( - args.omz_irs_out_dir / model_rec.attrib["subdirectory"] / precision / (model_rec.attrib["name"] + ".xml")) - - # prepare models - downloader_path = omz_path / "tools" / "downloader" / "downloader.py" - cmd = '{downloader_path} --name {model_name}' \ - ' --precisions={precision}' \ - ' --num_attempts {num_attempts}' \ - ' --output_dir {models_dir}' \ - ' --cache_dir {cache_dir}'.format(downloader_path=downloader_path, model_name=model_name, - precision=precision, num_attempts=OMZ_NUM_ATTEMPTS, - models_dir=args.omz_models_out_dir, cache_dir=args.omz_cache_dir) - - run_in_subprocess(cmd, check_call=not args.skip_omz_errors) - - # convert models to IRs - converter_path = omz_path / "tools" / "downloader" / "converter.py" - # NOTE: remove --precisions if both precisions (FP32 & FP16) required - cmd = '{executable} {converter_path} --name {model_name}' \ - ' -p {executable}' \ - ' --precisions={precision}' \ - ' --output_dir {irs_dir}' \ - ' --download_dir {models_dir}' \ - ' --mo {mo_tool}'.format(executable=python_executable, precision=precision, - converter_path=converter_path, - model_name=model_name, irs_dir=args.omz_irs_out_dir, - models_dir=args.omz_models_out_dir, mo_tool=args.mo_tool) - run_in_subprocess(cmd, check_call=not args.skip_omz_errors) + for device_rec in test_conf_root.findall("device"): + for model_rec in device_rec.findall("model"): + if "name" not in model_rec.attrib or model_rec.attrib.get("source") != "omz": + continue + model_name = model_rec.attrib["name"] + precision = model_rec.attrib["precision"] + + info_dumper_path = omz_path / "tools" / "downloader" / "info_dumper.py" + cmd = '"{executable}" "{info_dumper_path}" --name {model_name}'.format(executable=sys.executable, + info_dumper_path=info_dumper_path, + model_name=model_name) + try: + out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True, universal_newlines=True) + except subprocess.CalledProcessError as exc: + log.warning(exc.output) + continue + + model_info = json.loads(out)[0] + + # update model record from test config with Open Model Zoo info + fields_to_add = ["framework", "subdirectory"] + info_to_add = {key: model_info[key] for key in fields_to_add} + # check selected precision with model info from Open Model Zoo + if precision not in model_info['precisions']: + log.warning("Please specify precision for the model " + "{model_name} from the list: {model_info}".format(model_name=model_name, + model_info=model_info['precisions'])) + continue + model_rec.attrib.update(info_to_add) + model_rec.attrib["path"] = str( + Path(model_rec.attrib["subdirectory"]) / precision / (model_rec.attrib["name"] + ".xml")) + model_rec.attrib["full_path"] = str( + args.omz_irs_out_dir / model_rec.attrib["subdirectory"] / precision / (model_rec.attrib["name"] + ".xml")) + + # prepare models + downloader_path = omz_path / "tools" / "downloader" / "downloader.py" + cmd = '{downloader_path} --name {model_name}' \ + ' --precisions={precision}' \ + ' --num_attempts {num_attempts}' \ + ' --output_dir {models_dir}' \ + ' --cache_dir {cache_dir}'.format(downloader_path=downloader_path, model_name=model_name, + precision=precision, num_attempts=OMZ_NUM_ATTEMPTS, + models_dir=args.omz_models_out_dir, cache_dir=args.omz_cache_dir) + + run_in_subprocess(cmd, check_call=not args.skip_omz_errors) + + # convert models to IRs + converter_path = omz_path / "tools" / "downloader" / "converter.py" + # NOTE: remove --precisions if both precisions (FP32 & FP16) required + cmd = '{executable} {converter_path} --name {model_name}' \ + ' -p {executable}' \ + ' --precisions={precision}' \ + ' --output_dir {irs_dir}' \ + ' --download_dir {models_dir}' \ + ' --mo {mo_tool}'.format(executable=python_executable, precision=precision, + converter_path=converter_path, + model_name=model_name, irs_dir=args.omz_irs_out_dir, + models_dir=args.omz_models_out_dir, mo_tool=args.mo_tool) + run_in_subprocess(cmd, check_call=not args.skip_omz_errors) # rewrite test config with updated records test_conf_obj.write(args.test_conf) From 1cf863fbeadea713e2ba5faaa54e7a7232c8202f Mon Sep 17 00:00:00 2001 From: Mateusz Bencer Date: Tue, 17 Aug 2021 13:14:11 +0200 Subject: [PATCH 006/102] Add support for is_equal_data, get_source_tensor, get_target_tensor methods in ONNX FE API (#6991) --- .../onnx/frontend/src/edge_mapper.cpp | 50 +++++++------- .../onnx/frontend/src/edge_mapper.hpp | 15 +++-- ngraph/frontend/onnx/frontend/src/editor.cpp | 24 ++++--- ngraph/frontend/onnx/frontend/src/editor.hpp | 12 ++++ ngraph/frontend/onnx/frontend/src/place.cpp | 31 +++++++++ ngraph/frontend/onnx/frontend/src/place.hpp | 10 +++ .../test_frontend_onnx_editor.py | 66 ++++++++++++++++--- ngraph/test/onnx/onnx_editor.cpp | 34 ++++++++++ 8 files changed, 196 insertions(+), 46 deletions(-) diff --git a/ngraph/frontend/onnx/frontend/src/edge_mapper.cpp b/ngraph/frontend/onnx/frontend/src/edge_mapper.cpp index 8615469f10d8cb..ee2bb58d5b67c4 100644 --- a/ngraph/frontend/onnx/frontend/src/edge_mapper.cpp +++ b/ngraph/frontend/onnx/frontend/src/edge_mapper.cpp @@ -72,25 +72,26 @@ int onnx_editor::EdgeMapper::get_node_output_idx(int node_index, const std::stri return (out_port_idx - std::begin(node_outputs)); } -int onnx_editor::EdgeMapper::get_node_input_idx(int node_index, const std::string& input_name) const { +std::vector onnx_editor::EdgeMapper::get_node_input_indexes(int node_index, const std::string& input_name) const { NGRAPH_CHECK(node_index >= 0 && node_index < static_cast(m_node_inputs.size()), "Node with index: ", std::to_string(node_index), "is out of scope outputs list"); const auto& node_inputs = m_node_inputs[node_index]; - const auto matched_inputs = std::count(std::begin(node_inputs), std::end(node_inputs), input_name); - if (matched_inputs == 0) { + std::vector node_inputs_indexes; + int index = 0; + for (const auto& in : node_inputs) { + if (in == input_name) { + node_inputs_indexes.push_back(index); + } + ++index; + } + if (node_inputs_indexes.size() == 0) { throw ngraph_error("Node with index: " + std::to_string(node_index) + " has not input with name: " + input_name); } - if (matched_inputs > 1) // more indexes with the same name - { - throw ngraph_error("Node with index: " + std::to_string(node_index) + " has more than one inputs with name: " + - input_name + ". You should use port indexes to distinguish them."); - } - const auto in_port_idx = std::find(std::begin(node_inputs), std::end(node_inputs), input_name); - return (in_port_idx - std::begin(node_inputs)); + return node_inputs_indexes; } InputEdge onnx_editor::EdgeMapper::find_input_edge(const EditorNode& node, const EditorInput& in) const { @@ -131,8 +132,14 @@ InputEdge onnx_editor::EdgeMapper::find_input_edge(const EditorNode& node, const return InputEdge{node_index, in.m_input_index, in.m_new_input_name}; } if (!in.m_input_name.empty()) { - const auto input_idx = get_node_input_idx(node_index, in.m_input_name); - return InputEdge{node_index, input_idx, in.m_new_input_name}; + const auto input_indexes = get_node_input_indexes(node_index, in.m_input_name); + if (input_indexes.size() > 1) // more indexes with the same name + { + throw ngraph_error("Node with index: " + std::to_string(node_index) + + " has more than one inputs with name: " + in.m_input_name + + ". You should use port indexes to distinguish them."); + } + return InputEdge{node_index, input_indexes[0], in.m_new_input_name}; } else { throw ngraph_error("Not enough information to determine input edge"); } @@ -186,14 +193,13 @@ OutputEdge onnx_editor::EdgeMapper::find_output_edge(const std::string& output_n std::vector onnx_editor::EdgeMapper::find_output_consumers(const std::string& output_name) const { const auto matched_nodes_range = m_output_consumers_index.equal_range(output_name); std::vector input_edges; - std::transform(matched_nodes_range.first, - matched_nodes_range.second, - std::back_inserter(input_edges), - [&output_name, this](const std::pair& iter) { - const auto node_idx = iter.second; - const auto port_idx = this->get_node_input_idx(node_idx, output_name); - return InputEdge{node_idx, port_idx}; - }); + for (auto it = matched_nodes_range.first; it != matched_nodes_range.second; ++it) { + const auto node_idx = it->second; + const auto port_indexes = get_node_input_indexes(node_idx, output_name); + for (const auto& idx : port_indexes) { + input_edges.push_back(InputEdge{node_idx, idx}); + } + } return input_edges; } @@ -211,7 +217,7 @@ bool onnx_editor::EdgeMapper::is_correct_tensor_name(const std::string& name) co return false; } -std::string onnx_editor::EdgeMapper::get_input_port_name(const InputEdge& edge) const { +std::string onnx_editor::EdgeMapper::get_source_tensor_name(const InputEdge& edge) const { if (edge.m_node_idx >= 0 && edge.m_node_idx < static_cast(m_node_inputs.size()) && edge.m_port_idx >= 0 && edge.m_port_idx < static_cast(m_node_inputs[edge.m_node_idx].size())) { return m_node_inputs[edge.m_node_idx][edge.m_port_idx]; @@ -219,7 +225,7 @@ std::string onnx_editor::EdgeMapper::get_input_port_name(const InputEdge& edge) return ""; } -std::string onnx_editor::EdgeMapper::get_output_port_name(const OutputEdge& edge) const { +std::string onnx_editor::EdgeMapper::get_target_tensor_name(const OutputEdge& edge) const { if (edge.m_node_idx >= 0 && edge.m_node_idx < static_cast(m_node_outputs.size()) && edge.m_port_idx >= 0 && edge.m_port_idx < static_cast(m_node_outputs[edge.m_node_idx].size())) { return m_node_outputs[edge.m_node_idx][edge.m_port_idx]; diff --git a/ngraph/frontend/onnx/frontend/src/edge_mapper.hpp b/ngraph/frontend/onnx/frontend/src/edge_mapper.hpp index 43911d6c2a654e..df57fbe87b4756 100644 --- a/ngraph/frontend/onnx/frontend/src/edge_mapper.hpp +++ b/ngraph/frontend/onnx/frontend/src/edge_mapper.hpp @@ -98,22 +98,23 @@ class EdgeMapper { /// bool is_correct_tensor_name(const std::string& name) const; - /// \brief Get name of input port indicated by the input edge. + /// \brief Get name of the tensor which is the source of the input edge. /// - /// \note Empty string is returned if the port name is not found. + /// \note Empty string is returned if the tensor name is not found. /// - std::string get_input_port_name(const InputEdge& edge) const; + std::string get_source_tensor_name(const InputEdge& edge) const; - /// \brief Get name of output port indicated by the input edge. + /// \brief Get name of the tensor which is the target of the output edge. /// - /// \note Empty string is returned if the port name is not found. + /// \note Empty string is returned if the tensor name is not found. /// - std::string get_output_port_name(const OutputEdge& edge) const; + std::string get_target_tensor_name(const OutputEdge& edge) const; private: std::vector find_node_indexes(const std::string& node_name, const std::string& output_name) const; - int get_node_input_idx(int node_index, const std::string& input_name) const; + // note: a single node can have more than one inputs with the same name + std::vector get_node_input_indexes(int node_index, const std::string& input_name) const; int get_node_output_idx(int node_index, const std::string& output_name) const; std::vector> m_node_inputs; diff --git a/ngraph/frontend/onnx/frontend/src/editor.cpp b/ngraph/frontend/onnx/frontend/src/editor.cpp index 45efa1b87c5d99..ccbd18b0e1dcfb 100644 --- a/ngraph/frontend/onnx/frontend/src/editor.cpp +++ b/ngraph/frontend/onnx/frontend/src/editor.cpp @@ -325,25 +325,33 @@ std::vector onnx_editor::ONNXModelEditor::model_outputs() const { return outputs; } -bool onnx_editor::ONNXModelEditor::is_input(const InputEdge& edge) const { +std::string onnx_editor::ONNXModelEditor::get_source_tensor_name(const InputEdge& edge) const { update_mapper_if_needed(); - const auto& port_name = m_pimpl->m_edge_mapper.get_input_port_name(edge); - if (port_name.empty()) { + return m_pimpl->m_edge_mapper.get_source_tensor_name(edge); +} + +bool onnx_editor::ONNXModelEditor::is_input(const InputEdge& edge) const { + const auto& tensor_name = get_source_tensor_name(edge); + if (tensor_name.empty()) { return false; } else { const auto& inputs = model_inputs(); - return std::count(std::begin(inputs), std::end(inputs), port_name) > 0; + return std::count(std::begin(inputs), std::end(inputs), tensor_name) > 0; } } -bool onnx_editor::ONNXModelEditor::is_output(const OutputEdge& edge) const { +std::string onnx_editor::ONNXModelEditor::get_target_tensor_name(const OutputEdge& edge) const { update_mapper_if_needed(); - const auto& port_name = m_pimpl->m_edge_mapper.get_output_port_name(edge); - if (port_name.empty()) { + return m_pimpl->m_edge_mapper.get_target_tensor_name(edge); +} + +bool onnx_editor::ONNXModelEditor::is_output(const OutputEdge& edge) const { + const auto& tensor_name = get_target_tensor_name(edge); + if (tensor_name.empty()) { return false; } else { const auto& outputs = model_outputs(); - return std::count(std::begin(outputs), std::end(outputs), port_name) > 0; + return std::count(std::begin(outputs), std::end(outputs), tensor_name) > 0; } } diff --git a/ngraph/frontend/onnx/frontend/src/editor.hpp b/ngraph/frontend/onnx/frontend/src/editor.hpp index b714c4174b2e1a..bec2f1b47e1aa7 100644 --- a/ngraph/frontend/onnx/frontend/src/editor.hpp +++ b/ngraph/frontend/onnx/frontend/src/editor.hpp @@ -100,9 +100,21 @@ class ONNX_IMPORTER_API ONNXModelEditor final { /// instance of the model editor. std::vector model_outputs() const; + /// \brief Get name of the tensor which is the source of the input edge. + /// + /// \note Empty string is returned if the tensor name is not found. + /// + std::string get_source_tensor_name(const InputEdge& edge) const; + /// \brief Returns true if input edge is input of the model. Otherwise false. bool is_input(const InputEdge& edge) const; + /// \brief Get name of the tensor which is the target of the output edge. + /// + /// \note Empty string is returned if the tensor name is not found. + /// + std::string get_target_tensor_name(const OutputEdge& edge) const; + /// \brief Returns true if output edge is input of the model. Otherwise false. bool is_output(const OutputEdge& edge) const; diff --git a/ngraph/frontend/onnx/frontend/src/place.cpp b/ngraph/frontend/onnx/frontend/src/place.cpp index 8c18f6446639c7..64c623c2957083 100644 --- a/ngraph/frontend/onnx/frontend/src/place.cpp +++ b/ngraph/frontend/onnx/frontend/src/place.cpp @@ -34,6 +34,15 @@ bool PlaceInputEdgeONNX::is_equal(Place::Ptr another) const { return false; } +bool PlaceInputEdgeONNX::is_equal_data(Place::Ptr another) const { + return get_source_tensor()->is_equal_data(another); +} + +Place::Ptr PlaceInputEdgeONNX::get_source_tensor() const { + const auto tensor_name = m_editor->get_source_tensor_name(m_edge); + return std::make_shared(tensor_name, m_editor); +} + PlaceOutputEdgeONNX::PlaceOutputEdgeONNX(const onnx_editor::OutputEdge& edge, std::shared_ptr editor) : m_edge{edge}, @@ -59,6 +68,15 @@ bool PlaceOutputEdgeONNX::is_equal(Place::Ptr another) const { return false; } +bool PlaceOutputEdgeONNX::is_equal_data(Place::Ptr another) const { + return get_target_tensor()->is_equal_data(another); +} + +Place::Ptr PlaceOutputEdgeONNX::get_target_tensor() const { + const auto tensor_name = m_editor->get_target_tensor_name(m_edge); + return std::make_shared(tensor_name, m_editor); +} + PlaceTensorONNX::PlaceTensorONNX(const std::string& name, std::shared_ptr editor) : m_name(name), m_editor(editor) {} @@ -68,6 +86,8 @@ std::vector PlaceTensorONNX::get_names() const { } Place::Ptr PlaceTensorONNX::get_producing_port() const { + FRONT_END_GENERAL_CHECK(!is_input(), + "Tensor: " + m_name + " is an input of the model and doesn't have producing port."); return std::make_shared(m_editor->find_output_edge(m_name), m_editor); } @@ -102,3 +122,14 @@ bool PlaceTensorONNX::is_equal(Place::Ptr another) const { } return false; } + +bool PlaceTensorONNX::is_equal_data(Place::Ptr another) const { + const auto consuming_ports = get_consuming_ports(); + const auto eq_to_consuming_port = [&consuming_ports](const Ptr& another) { + return std::any_of(consuming_ports.begin(), consuming_ports.end(), [&another](const Ptr& place) { + return place->is_equal(another); + }); + }; + return is_equal(another) || (is_input() ? false : get_producing_port()->is_equal(another)) || + eq_to_consuming_port(another); +} diff --git a/ngraph/frontend/onnx/frontend/src/place.hpp b/ngraph/frontend/onnx/frontend/src/place.hpp index 20501f32f456c6..a236d8506e9174 100644 --- a/ngraph/frontend/onnx/frontend/src/place.hpp +++ b/ngraph/frontend/onnx/frontend/src/place.hpp @@ -22,6 +22,10 @@ class PlaceInputEdgeONNX : public Place { bool is_equal(Place::Ptr another) const override; + bool is_equal_data(Place::Ptr another) const override; + + Place::Ptr get_source_tensor() const override; + private: onnx_editor::InputEdge m_edge; const std::shared_ptr m_editor; @@ -39,6 +43,10 @@ class PlaceOutputEdgeONNX : public Place { bool is_equal(Place::Ptr another) const override; + bool is_equal_data(Place::Ptr another) const override; + + Place::Ptr get_target_tensor() const override; + private: onnx_editor::OutputEdge m_edge; std::shared_ptr m_editor; @@ -62,6 +70,8 @@ class PlaceTensorONNX : public Place { bool is_equal(Place::Ptr another) const override; + bool is_equal_data(Place::Ptr another) const override; + private: std::string m_name; std::shared_ptr m_editor; diff --git a/ngraph/python/tests/test_frontend/test_frontend_onnx_editor.py b/ngraph/python/tests/test_frontend/test_frontend_onnx_editor.py index ad5acbeb686515..3542a20ef19ba2 100644 --- a/ngraph/python/tests/test_frontend/test_frontend_onnx_editor.py +++ b/ngraph/python/tests/test_frontend/test_frontend_onnx_editor.py @@ -45,7 +45,8 @@ def create_test_onnx_models(): make_tensor_value_info("out4", onnx.TensorProto.FLOAT, (2, 2)), ] graph = make_graph([add, split, relu, mul], "test_graph", input_tensors, output_tensors) - models["input_model.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["input_model.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) # Expected for extract_subgraph input_tensors = [ @@ -56,7 +57,8 @@ def create_test_onnx_models(): make_tensor_value_info("add_out", onnx.TensorProto.FLOAT, (2, 2)), ] graph = make_graph([add], "test_graph", input_tensors, output_tensors) - models["extract_subgraph.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["extract_subgraph.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) # Expected for extract_subgraph 2 input_tensors = [ @@ -69,7 +71,8 @@ def create_test_onnx_models(): make_tensor_value_info("add_out", onnx.TensorProto.FLOAT, (2, 2)), ] graph = make_graph([add, relu], "test_graph", input_tensors, output_tensors) - models["extract_subgraph_2.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["extract_subgraph_2.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) # Expected for extract_subgraph 3 input_tensors = [ @@ -82,7 +85,8 @@ def create_test_onnx_models(): expected_split = onnx.helper.make_node("Split", inputs=["out1/placeholder_port_0"], outputs=["out1", "out2"], name="split1", axis=0) graph = make_graph([expected_split], "test_graph", input_tensors, output_tensors) - models["extract_subgraph_3.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["extract_subgraph_3.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) # Expected for extract_subgraph 4 input_tensors = [ @@ -100,7 +104,8 @@ def create_test_onnx_models(): expected_mul = onnx.helper.make_node("Mul", inputs=["out4/placeholder_port_0", "out4/placeholder_port_1"], outputs=["out4"]) graph = make_graph([expected_split, expected_mul], "test_graph", input_tensors, output_tensors) - models["extract_subgraph_4.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["extract_subgraph_4.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) # Expected for test_override_all_outputs input_tensors = [ @@ -113,7 +118,8 @@ def create_test_onnx_models(): make_tensor_value_info("add_out", onnx.TensorProto.FLOAT, (2, 2)), ] graph = make_graph([add, relu], "test_graph", input_tensors, output_tensors) - models["test_override_all_outputs.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["test_override_all_outputs.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) # Expected for test_override_all_outputs 2 input_tensors = [ @@ -124,7 +130,8 @@ def create_test_onnx_models(): make_tensor_value_info("out4", onnx.TensorProto.FLOAT, (2, 2)), ] graph = make_graph([add, mul], "test_graph", input_tensors, output_tensors) - models["test_override_all_outputs_2.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["test_override_all_outputs_2.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) # Expected for test_override_all_inputs input_tensors = [ @@ -144,7 +151,8 @@ def create_test_onnx_models(): expected_mul = onnx.helper.make_node("Mul", inputs=["out4/placeholder_port_0", "out4/placeholder_port_1"], outputs=["out4"]) graph = make_graph([expected_split, relu, expected_mul], "test_graph", input_tensors, output_tensors) - models["test_override_all_inputs.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["test_override_all_inputs.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) # test partial shape input_tensors = [ @@ -159,7 +167,8 @@ def create_test_onnx_models(): make_tensor_value_info("out4", onnx.TensorProto.FLOAT, (8, 16)), ] graph = make_graph([add, split, relu, mul], "test_graph", input_tensors, output_tensors) - models["test_partial_shape.onnx"] = make_model(graph, producer_name="ONNX Importer") + models["test_partial_shape.onnx"] = make_model(graph, producer_name="ONNX Importer", + opset_imports=[onnx.helper.make_opsetid("", 13)]) return models @@ -530,6 +539,45 @@ def test_is_equal(): assert not place8.is_equal(place2) +def test_is_equal_data(): + skip_if_onnx_frontend_is_disabled() + fe = fem.load_by_framework(framework=ONNX_FRONTEND_NAME) + assert fe + + model = fe.load("input_model.onnx") + assert model + + place1 = model.get_place_by_tensor_name(tensorName="in1") + assert place1.is_equal_data(place1) + + place2 = model.get_place_by_tensor_name(tensorName="add_out") + assert place2.is_equal_data(place2) + + place3 = model.get_place_by_tensor_name(tensorName="in2") + assert not place1.is_equal_data(place3) + assert not place2.is_equal_data(place1) + + place4 = place2.get_producing_port() + assert place2.is_equal_data(place4) + + place5 = model.get_place_by_tensor_name(tensorName="out4").get_input_port(inputPortIndex=0) + assert place2.is_equal_data(place5) + assert place4.is_equal_data(place5) + + place6 = model.get_place_by_tensor_name(tensorName="out4").get_input_port(inputPortIndex=1) + assert place6.is_equal_data(place5) + + place7 = model.get_place_by_operation_name_and_input_port(operationName="split1", inputPortIndex=0) + assert place7.is_equal_data(place7) + + place8 = model.get_place_by_tensor_name(tensorName="out1") + place9 = model.get_place_by_tensor_name(tensorName="out2") + place10 = place8.get_producing_port() + assert not place8.is_equal_data(place9) + assert not place9.is_equal_data(place10) + assert place8.is_equal_data(place10) + + def test_get_place_by_tensor_name(): skip_if_onnx_frontend_is_disabled() fe = fem.load_by_framework(framework=ONNX_FRONTEND_NAME) diff --git a/ngraph/test/onnx/onnx_editor.cpp b/ngraph/test/onnx/onnx_editor.cpp index 3123ab21e34d76..1e7e36f5dc5e45 100644 --- a/ngraph/test/onnx/onnx_editor.cpp +++ b/ngraph/test/onnx/onnx_editor.cpp @@ -1019,6 +1019,16 @@ NGRAPH_TEST(onnx_editor, editor_api_find_output_consumers_empty_result) { EXPECT_EQ(output_consumers.size(), 0); } +NGRAPH_TEST(onnx_editor, editor_api_inputs_with_the_same_name) { + ONNXModelEditor editor{file_util::path_join(SERIALIZED_ZOO, "onnx/model_editor/add_ab.onnx")}; + + std::vector output_consumers = editor.find_output_consumers("X"); + EXPECT_EQ(output_consumers[0].m_node_idx, 1); + EXPECT_EQ(output_consumers[0].m_port_idx, 0); + EXPECT_EQ(output_consumers[1].m_node_idx, 1); + EXPECT_EQ(output_consumers[1].m_port_idx, 1); +} + NGRAPH_TEST(onnx_editor, editor_api_is_correct_and_unambiguous_node) { ONNXModelEditor editor{file_util::path_join(SERIALIZED_ZOO, "onnx/model_editor/subgraph_extraction_tests.onnx")}; @@ -1204,6 +1214,19 @@ NGRAPH_TEST(onnx_editor, cut_operator_with_no_schema) { EXPECT_TRUE(result.is_ok) << result.error_message; } +NGRAPH_TEST(onnx_editor, get_source_tensor_name) { + ONNXModelEditor editor{file_util::path_join(SERIALIZED_ZOO, "onnx/model_editor/subgraph_extraction_tests.onnx")}; + + EXPECT_EQ(editor.get_source_tensor_name(InputEdge{0, 0}), "in1"); + EXPECT_EQ(editor.get_source_tensor_name(InputEdge{1, 0}), "relu1"); + EXPECT_EQ(editor.get_source_tensor_name(InputEdge{1, 1}), "in2"); + const auto edge1 = editor.find_input_edge(EditorOutput{"conv1"}, 1); + EXPECT_EQ(editor.get_source_tensor_name(edge1), "in4"); + const auto edge2 = editor.find_input_edge(EditorOutput{"split2"}, 0); + EXPECT_EQ(editor.get_source_tensor_name(edge2), "add2"); + EXPECT_EQ(editor.get_source_tensor_name(InputEdge{999, 999}), ""); +} + NGRAPH_TEST(onnx_editor, is_model_input) { ONNXModelEditor editor{file_util::path_join(SERIALIZED_ZOO, "onnx/model_editor/subgraph_extraction_tests.onnx")}; @@ -1221,6 +1244,17 @@ NGRAPH_TEST(onnx_editor, is_model_input) { EXPECT_FALSE(editor.is_input(edge3)); } +NGRAPH_TEST(onnx_editor, get_target_tensor_name) { + ONNXModelEditor editor{file_util::path_join(SERIALIZED_ZOO, "onnx/model_editor/subgraph_extraction_tests.onnx")}; + + EXPECT_EQ(editor.get_target_tensor_name(OutputEdge{0, 0}), "relu1"); + EXPECT_EQ(editor.get_target_tensor_name(OutputEdge{1, 0}), "add1"); + EXPECT_EQ(editor.get_target_tensor_name(OutputEdge{4, 0}), "mul2"); + const auto edge1 = editor.find_output_edge("split1"); + EXPECT_EQ(editor.get_target_tensor_name(edge1), "split1"); + EXPECT_EQ(editor.get_target_tensor_name(OutputEdge{999, 999}), ""); +} + NGRAPH_TEST(onnx_editor, is_model_output) { ONNXModelEditor editor{file_util::path_join(SERIALIZED_ZOO, "onnx/model_editor/subgraph_extraction_tests.onnx")}; From e35aa44555e12bcb1b3c6408a086ceb4a2d01797 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Tue, 17 Aug 2021 15:27:06 +0300 Subject: [PATCH 007/102] Change ngraph public api (#6920) * Moved nGraph function * Added legacy nGraph function * Moved export API * Moved variant * Added old header for backward compatibility * Fixed build * Introduce define * Fixed code style * Fixed comments --- .../include/openvino/runtime/core.hpp | 21 +- ...avg_pool_precision_preserved_attribute.hpp | 12 +- .../rt_info/intervals_alignment_attribute.hpp | 18 +- .../per_tensor_quantization_attribute.hpp | 10 +- .../rt_info/precision_preserved_attribute.hpp | 13 +- .../rt_info/precisions_attribute.hpp | 16 +- .../quantization_alignment_attribute.hpp | 17 +- ...avg_pool_precision_preserved_attribute.cpp | 1 + .../rt_info/intervals_alignment_attribute.cpp | 1 + .../per_tensor_quantization_attribute.cpp | 3 +- .../rt_info/precision_preserved_attribute.cpp | 1 + .../src/rt_info/precisions_attribute.cpp | 1 + .../quantization_alignment_attribute.cpp | 1 + .../rt_info/memory_formats_attribute.cpp | 12 +- .../rt_info/memory_formats_attribute.hpp | 60 ++-- .../include/mask_attribute.hpp | 26 +- .../src/pruning/mask_attribute.cpp | 12 +- .../src/readers/ir_reader/ie_ir_reader.hpp | 4 - .../include/snippets/register_info.hpp | 14 +- .../rt_info/dequantization_attribute.hpp | 23 +- .../rt_info/disable_constant_folding.hpp | 11 +- .../rt_info/fused_names_attribute.hpp | 39 +-- .../rt_info/primitives_priority_attribute.hpp | 27 +- .../rt_info/strides_property.hpp | 6 +- .../rt_info/dequantization_attribute.cpp | 36 ++- .../rt_info/disable_constant_folding.cpp | 6 +- .../rt_info/fused_names_attribute.cpp | 50 ++- .../rt_info/primitives_priority_attribute.cpp | 35 ++- .../cpu/test_utils/fusing_test_utils.cpp | 2 +- .../core/include/ngraph/attribute_visitor.hpp | 6 +- ngraph/core/include/ngraph/function.hpp | 270 +--------------- .../core/include/ngraph/ngraph_visibility.hpp | 30 +- ngraph/core/include/ngraph/node.hpp | 2 - ngraph/core/include/ngraph/op/parameter.hpp | 3 +- .../ngraph/op/util/multi_subgraph_base.hpp | 1 + .../ngraph/op/util/variable_context.hpp | 11 +- ngraph/core/include/ngraph/util.hpp | 1 - ngraph/core/include/ngraph/variant.hpp | 78 +---- ngraph/core/include/ngraph/visibility.hpp | 20 +- .../include/openvino/core/core_visibility.hpp | 35 +++ .../core/include/openvino/core/function.hpp | 289 ++++++++++++++++++ ngraph/core/include/openvino/core/variant.hpp | 98 ++++++ .../core/include/openvino/core/visibility.hpp | 19 ++ ngraph/core/src/attribute_visitor.cpp | 1 + .../frontend_manager/frontend_manager.hpp | 5 +- .../frontend/onnx/frontend/src/core/graph.hpp | 1 + .../paddlepaddle/src/node_context.cpp | 5 +- .../paddlepaddle/src/node_context.hpp | 4 +- .../src/pyngraph/dict_attribute_visitor.hpp | 3 +- ngraph/test/op.cpp | 4 +- ngraph/test/util/test_tools.hpp | 3 +- 51 files changed, 745 insertions(+), 622 deletions(-) create mode 100644 ngraph/core/include/openvino/core/core_visibility.hpp create mode 100644 ngraph/core/include/openvino/core/function.hpp create mode 100644 ngraph/core/include/openvino/core/variant.hpp create mode 100644 ngraph/core/include/openvino/core/visibility.hpp diff --git a/inference-engine/src/inference_engine/include/openvino/runtime/core.hpp b/inference-engine/src/inference_engine/include/openvino/runtime/core.hpp index 9bc3504b69af11..0ececc87aa5b95 100644 --- a/inference-engine/src/inference_engine/include/openvino/runtime/core.hpp +++ b/inference-engine/src/inference_engine/include/openvino/runtime/core.hpp @@ -19,10 +19,6 @@ #include "ie_plugin_config.hpp" #include "ie_version.hpp" -namespace ngraph { -class Function; -} // namespace ngraph - namespace InferenceEngine { class IExtension; class Blob; @@ -30,6 +26,9 @@ class RemoteContext; } // namespace InferenceEngine namespace ov { + +class Function; + namespace runtime { /** @@ -72,7 +71,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * * binPath parameter is not used. * @return Function */ - std::shared_ptr read_model(const std::wstring& modelPath, const std::wstring& binPath = {}) const; + std::shared_ptr read_model(const std::wstring& modelPath, const std::wstring& binPath = {}) const; #endif /** @@ -86,7 +85,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * * binPath parameter is not used. * @return Function */ - std::shared_ptr read_model(const std::string& modelPath, const std::string& binPath = {}) const; + std::shared_ptr read_model(const std::string& modelPath, const std::string& binPath = {}) const; /** * @brief Reads models from IR and ONNX formats * @param model string with model in IR or ONNX format @@ -101,8 +100,8 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * constant data becomes to point to invalid memory. * @return Function */ - std::shared_ptr read_model(const std::string& model, - const std::shared_ptr& weights) const; + std::shared_ptr read_model(const std::string& model, + const std::shared_ptr& weights) const; /** * @brief Creates an executable network from a network object. @@ -116,7 +115,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * operation * @return An executable network reference */ - InferenceEngine::ExecutableNetwork compile_model(const std::shared_ptr& network, + InferenceEngine::ExecutableNetwork compile_model(const std::shared_ptr& network, const std::string& deviceName, const std::map& config = {}); @@ -145,7 +144,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * operation * @return An executable network object */ - InferenceEngine::ExecutableNetwork compile_model(const std::shared_ptr& network, + InferenceEngine::ExecutableNetwork compile_model(const std::shared_ptr& network, const std::shared_ptr& context, const std::map& config = {}); @@ -189,7 +188,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * @param config Optional map of pairs: (config parameter name, config parameter value) * @return An object containing a map of pairs a layer name -> a device name supporting this layer. */ - InferenceEngine::QueryNetworkResult query_model(const std::shared_ptr& network, + InferenceEngine::QueryNetworkResult query_model(const std::shared_ptr& network, const std::string& deviceName, const std::map& config = {}) const; diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/avg_pool_precision_preserved_attribute.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/avg_pool_precision_preserved_attribute.hpp index b8aabf3718db4b..1e8794c5d5bc6a 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/avg_pool_precision_preserved_attribute.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/avg_pool_precision_preserved_attribute.hpp @@ -17,11 +17,13 @@ class LP_TRANSFORMATIONS_API AvgPoolPrecisionPreservedAttribute : public Precisi }; using AvgPoolPrecisionPreservedAttributePtr = std::shared_ptr; +} // namespace ngraph -extern template class LP_TRANSFORMATIONS_API VariantImpl; +namespace ov { +extern template class LP_TRANSFORMATIONS_API VariantImpl; template<> -class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { +class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info{ "LowPrecision::AvgPoolPrecisionPreserved", 0 }; @@ -31,9 +33,9 @@ class LP_TRANSFORMATIONS_API VariantWrapper(value) {} - AvgPoolPrecisionPreservedAttributePtr get() { return this->m_value; } + ngraph::AvgPoolPrecisionPreservedAttributePtr get() { return this->m_value; } - void merge(std::vector>>>& attributes); + void merge(std::vector>>>& attributes); std::string to_string() override; }; -} // namespace ngraph +} // namespace ov diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/intervals_alignment_attribute.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/intervals_alignment_attribute.hpp index 3c723a444055c4..964989a04ecd7e 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/intervals_alignment_attribute.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/intervals_alignment_attribute.hpp @@ -62,12 +62,15 @@ class LP_TRANSFORMATIONS_API IntervalsAlignmentAttribute : public SharedValueAtt }; using IntervalsAlignmentAttributePtr = std::shared_ptr; +} // namespace ngraph + +namespace ov { -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; +extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; template<> -class LP_TRANSFORMATIONS_API VariantWrapper> : - public VariantImpl> { +class LP_TRANSFORMATIONS_API VariantWrapper> : + public VariantImpl> { public: static constexpr VariantTypeInfo type_info{ "LowPrecision::IntervalsAlignment", 0 }; @@ -77,12 +80,13 @@ class LP_TRANSFORMATIONS_API VariantWrapper(value) {} - std::shared_ptr get() const { return this->m_value; } + std::shared_ptr get() const { return this->m_value; } - static std::shared_ptr>> create( + static std::shared_ptr>> create( const std::shared_ptr& node, const AttributeParameters& params); - void merge(std::vector>>>& attributes); + void merge(std::vector>>>& attributes); std::string to_string() override; }; -} // namespace ngraph + +} // namespace ov diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/per_tensor_quantization_attribute.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/per_tensor_quantization_attribute.hpp index 1001df8bffeaf7..84f5216bda72c9 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/per_tensor_quantization_attribute.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/per_tensor_quantization_attribute.hpp @@ -16,11 +16,14 @@ namespace ngraph { class LP_TRANSFORMATIONS_API PerTensorQuantizationAttribute { }; +} // namespace ngraph + +namespace ov { -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; +extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; template<> -class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { +class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info { "LowPrecision::PerTensorQuantization", 0 }; @@ -30,4 +33,5 @@ class LP_TRANSFORMATIONS_API VariantWrapper : pu return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/precision_preserved_attribute.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/precision_preserved_attribute.hpp index bf109407d008e9..08a4e213586e17 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/precision_preserved_attribute.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/precision_preserved_attribute.hpp @@ -31,10 +31,14 @@ class LP_TRANSFORMATIONS_API PrecisionPreservedAttribute : public SharedValueAtt using PrecisionPreservedAttributePtr = std::shared_ptr; -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; +} // namespace ngraph + +namespace ov { + +extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; template<> -class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { +class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info{ "LowPrecision::PrecisionPreserved", 0 }; @@ -44,8 +48,9 @@ class LP_TRANSFORMATIONS_API VariantWrapper : pu VariantWrapper(const value_type& value) : VariantImpl(value) {} - PrecisionPreservedAttributePtr get() { return this->m_value; } + ngraph::PrecisionPreservedAttributePtr get() { return this->m_value; } std::string to_string() override; }; -} // namespace ngraph + +} // namespace ov diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/precisions_attribute.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/precisions_attribute.hpp index 5fc08c17926a98..329ee2cb22e2f5 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/precisions_attribute.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/precisions_attribute.hpp @@ -34,11 +34,14 @@ class LP_TRANSFORMATIONS_API PrecisionsAttribute : public SharedValueAttribute

defaultPrecisions; PrecisionsAttribute(const std::vector& precisions = defaultPrecisions); }; +} // namespace ngraph + +namespace ov { -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl>; +extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl>; template<> -class LP_TRANSFORMATIONS_API VariantWrapper> : public VariantImpl> { +class LP_TRANSFORMATIONS_API VariantWrapper> : public VariantImpl> { public: static constexpr VariantTypeInfo type_info{ "LowPrecision::Precisions", 0 }; @@ -50,15 +53,16 @@ class LP_TRANSFORMATIONS_API VariantWrapper std::shared_ptr init(const std::shared_ptr& node) override; - std::shared_ptr get() { return this->m_value; } + std::shared_ptr get() { return this->m_value; } // create attribute instance for node - static std::shared_ptr>> create( + static std::shared_ptr>> create( const std::shared_ptr& node, const AttributeParameters& params); // merge attribute instances which can be got from different sources: node, input port or output port - void merge(std::vector>>>& attributes); + void merge(std::vector>>>& attributes); // vizualize shared attributes details in VizualizeTree pass std::string to_string() override; }; -} // namespace ngraph + +} // namespace ov diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/quantization_alignment_attribute.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/quantization_alignment_attribute.hpp index 198301a9c4aef2..28503344f23ad2 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/quantization_alignment_attribute.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/rt_info/quantization_alignment_attribute.hpp @@ -32,12 +32,15 @@ class LP_TRANSFORMATIONS_API QuantizationAlignmentAttribute : public SharedValue }; using QuantizationAlignmentAttributePtr = std::shared_ptr; +} // namespace ngraph + +namespace ov { -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; +extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; template<> -class LP_TRANSFORMATIONS_API VariantWrapper> : - public VariantImpl> { +class LP_TRANSFORMATIONS_API VariantWrapper> : + public VariantImpl> { public: static constexpr VariantTypeInfo type_info{ "LowPrecision::QuantizationAlignment", 0 }; @@ -49,12 +52,12 @@ class LP_TRANSFORMATIONS_API VariantWrapper init(const std::shared_ptr& node) override; - std::shared_ptr get() { return this->m_value; } + std::shared_ptr get() { return this->m_value; } - static std::shared_ptr>> create( + static std::shared_ptr>> create( const std::shared_ptr& node, const AttributeParameters& params); - void merge(std::vector>>>& attributes); + void merge(std::vector>>>& attributes); std::string to_string() override; }; -} // namespace ngraph +} // namespace ov diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/avg_pool_precision_preserved_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/avg_pool_precision_preserved_attribute.cpp index 3bafe518a91b01..aba2aa578e52fd 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/avg_pool_precision_preserved_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/avg_pool_precision_preserved_attribute.cpp @@ -9,6 +9,7 @@ #include using namespace ngraph; +using namespace ov; template class ngraph::VariantImpl; diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp index cb786a8af36e05..2425b3f1e12b89 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp @@ -12,6 +12,7 @@ #include "low_precision/network_helper.hpp" using namespace ngraph; +using namespace ov; using namespace ngraph::pass::low_precision; IntervalsAlignmentAttribute::IntervalsAlignmentAttribute( diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/per_tensor_quantization_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/per_tensor_quantization_attribute.cpp index fe418173f2c524..0036e9e378ae97 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/per_tensor_quantization_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/per_tensor_quantization_attribute.cpp @@ -5,6 +5,7 @@ #include "low_precision/rt_info/per_tensor_quantization_attribute.hpp" using namespace ngraph; +using namespace ov; template class ngraph::VariantImpl; -constexpr VariantTypeInfo VariantWrapper::type_info; \ No newline at end of file +constexpr VariantTypeInfo VariantWrapper::type_info; diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/precision_preserved_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/precision_preserved_attribute.cpp index 8e8a9b0b62f04e..c2b94e425b0626 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/precision_preserved_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/precision_preserved_attribute.cpp @@ -8,6 +8,7 @@ #include using namespace ngraph; +using namespace ov; PrecisionPreservedAttribute::PrecisionPreservedAttribute(const bool value) { sharedValue->value = value; diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/precisions_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/precisions_attribute.cpp index c69fc1d9b690d2..334f3a3eae37f9 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/precisions_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/precisions_attribute.cpp @@ -14,6 +14,7 @@ #include "low_precision/network_helper.hpp" using namespace ngraph; +using namespace ov; // order defines default precision const std::vector PrecisionsAttribute::defaultPrecisions = { ngraph::element::u8, ngraph::element::i8 }; diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp index e02c8153b2c0d5..b95a9567a3e6d9 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp @@ -12,6 +12,7 @@ #include #include "low_precision/network_helper.hpp" +using namespace ov; using namespace ngraph; using namespace ngraph::pass::low_precision; diff --git a/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.cpp b/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.cpp index 859515fd75e6aa..f61ae9d6d11dd6 100644 --- a/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.cpp +++ b/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.cpp @@ -8,20 +8,20 @@ #include "memory_formats_attribute.hpp" -namespace ngraph { +using namespace ngraph; +using namespace ov; -template class ngraph::MLKDNNMemoryFormatsHelper; +template class ov::MLKDNNMemoryFormatsHelper; constexpr VariantTypeInfo VariantWrapper::type_info; -std::string getMLKDNNInputMemoryFormats(const std::shared_ptr & node) { +std::string ngraph::getMLKDNNInputMemoryFormats(const std::shared_ptr & node) { return MLKDNNMemoryFormatsHelper::getMemoryFormats(node); } -template class ngraph::MLKDNNMemoryFormatsHelper; +template class ov::MLKDNNMemoryFormatsHelper; constexpr VariantTypeInfo VariantWrapper::type_info; -std::string getMLKDNNOutputMemoryFormats(const std::shared_ptr & node) { +std::string ngraph::getMLKDNNOutputMemoryFormats(const std::shared_ptr & node) { return MLKDNNMemoryFormatsHelper::getMemoryFormats(node); } -} // namespace ngraph diff --git a/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.hpp b/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.hpp index 0e9edbe55c5d7a..5962f6f196ccc2 100644 --- a/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.hpp +++ b/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.hpp @@ -25,6 +25,25 @@ class MLKDNNMemoryFormats { std::string getMemoryFormats() const { return memory_format; } }; + +class MLKDNNInputMemoryFormats : public MLKDNNMemoryFormats { +public: + MLKDNNInputMemoryFormats() = default; + explicit MLKDNNInputMemoryFormats(const std::string &_memory_format) : MLKDNNMemoryFormats(_memory_format) {} +}; + +std::string getMLKDNNInputMemoryFormats(const std::shared_ptr& node); + +class MLKDNNOutputMemoryFormats : public MLKDNNMemoryFormats { +public: + MLKDNNOutputMemoryFormats() = default; + explicit MLKDNNOutputMemoryFormats(const std::string &_memory_format) : MLKDNNMemoryFormats(_memory_format) {} +}; +std::string getMLKDNNOutputMemoryFormats(const std::shared_ptr& node); + +} // namespace ngraph + +namespace ov { template class MLKDNNMemoryFormatsHelper : public VariantImpl { public: @@ -35,7 +54,7 @@ class MLKDNNMemoryFormatsHelper : public VariantImpl { using MemoryFormatsWrapper = VariantWrapper; if (!rtInfo.count(MemoryFormatsWrapper::type_info.name)) return ""; const auto &attr = rtInfo.at(MemoryFormatsWrapper::type_info.name); - MemoryFormatsType mem_format = as_type_ptr(attr)->get(); + MemoryFormatsType mem_format = ngraph::as_type_ptr(attr)->get(); return mem_format.getMemoryFormats(); } @@ -48,7 +67,7 @@ class MLKDNNMemoryFormatsHelper : public VariantImpl { } if (unique_mem_format.size() > 1) { - throw ngraph_error(std::string(VariantWrapper::type_info.name) + " no rule defined for multiple values."); + throw ngraph::ngraph_error(std::string(VariantWrapper::type_info.name) + " no rule defined for multiple values."); } std::string final_mem_format; @@ -59,46 +78,29 @@ class MLKDNNMemoryFormatsHelper : public VariantImpl { } std::shared_ptr init(const std::shared_ptr & node) override { - throw ngraph_error(std::string(VariantWrapper::type_info.name) + " has no default initialization."); + throw ngraph::ngraph_error(std::string(VariantWrapper::type_info.name) + " has no default initialization."); } }; - -class MLKDNNInputMemoryFormats : public MLKDNNMemoryFormats { -public: - MLKDNNInputMemoryFormats() = default; - explicit MLKDNNInputMemoryFormats(const std::string &_memory_format) : MLKDNNMemoryFormats(_memory_format) {} -}; - -extern template class MLKDNNMemoryFormatsHelper; +extern template class MLKDNNMemoryFormatsHelper; template<> -class VariantWrapper : public MLKDNNMemoryFormatsHelper { +class VariantWrapper : public MLKDNNMemoryFormatsHelper { public: - static constexpr VariantTypeInfo type_info{MLKDNNInputMemoryFormatsAttr, 0}; + static constexpr VariantTypeInfo type_info{ngraph::MLKDNNInputMemoryFormatsAttr, 0}; const VariantTypeInfo &get_type_info() const override { return type_info; } - VariantWrapper(const MLKDNNInputMemoryFormats &value) : MLKDNNMemoryFormatsHelper(value) {} -}; - -std::string getMLKDNNInputMemoryFormats(const std::shared_ptr& node); - -class MLKDNNOutputMemoryFormats : public MLKDNNMemoryFormats { -public: - MLKDNNOutputMemoryFormats() = default; - explicit MLKDNNOutputMemoryFormats(const std::string &_memory_format) : MLKDNNMemoryFormats(_memory_format) {} + VariantWrapper(const ngraph::MLKDNNInputMemoryFormats &value) : MLKDNNMemoryFormatsHelper(value) {} }; -extern template class MLKDNNMemoryFormatsHelper; +extern template class MLKDNNMemoryFormatsHelper; template<> -class VariantWrapper : public MLKDNNMemoryFormatsHelper { +class VariantWrapper : public MLKDNNMemoryFormatsHelper { public: - static constexpr VariantTypeInfo type_info{MLKDNNOutputMemoryFormatsAttr, 0}; + static constexpr VariantTypeInfo type_info{ngraph::MLKDNNOutputMemoryFormatsAttr, 0}; const VariantTypeInfo &get_type_info() const override { return type_info; } - VariantWrapper(const MLKDNNOutputMemoryFormats &value) : MLKDNNMemoryFormatsHelper(value) {} + VariantWrapper(const ngraph::MLKDNNOutputMemoryFormats &value) : MLKDNNMemoryFormatsHelper(value) {} }; -std::string getMLKDNNOutputMemoryFormats(const std::shared_ptr& node); - -} // namespace ngraph +} // namespace ov diff --git a/inference-engine/src/offline_transformations/include/mask_attribute.hpp b/inference-engine/src/offline_transformations/include/mask_attribute.hpp index 282f81b054e9f3..29d90bb341d173 100644 --- a/inference-engine/src/offline_transformations/include/mask_attribute.hpp +++ b/inference-engine/src/offline_transformations/include/mask_attribute.hpp @@ -192,10 +192,20 @@ class Mask : public std::vector>, std::ostream & operator<< (std::ostream & out, const Mask & mask); -extern template class VariantImpl; +Mask::Ptr getMask(const Output & output); + +Mask::Ptr getMask(const Output & output); + +void setMask(Output output, const Mask::Ptr & mask); + +} // namespace ngraph + +namespace ov { + +extern template class VariantImpl; template<> -class VariantWrapper : public VariantImpl { +class VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info{"Variant::RuntimeAttribute::Mask", 0}; @@ -203,17 +213,11 @@ class VariantWrapper : public VariantImpl { return type_info; } - static std::shared_ptr> create(const value_type & value) { - return std::make_shared>(value); + static std::shared_ptr> create(const value_type & value) { + return std::make_shared>(value); } explicit VariantWrapper(const value_type &value) : VariantImpl(value) {} }; -Mask::Ptr getMask(const Output & output); - -Mask::Ptr getMask(const Output & output); - -void setMask(Output output, const Mask::Ptr & mask); - -} // namespace ngraph +} // namespace ov diff --git a/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp b/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp index 7e0de45a0936e0..42fa47a3eb6cc6 100644 --- a/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp +++ b/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp @@ -12,10 +12,6 @@ namespace ngraph { -template class ngraph::VariantImpl; - -constexpr VariantTypeInfo VariantWrapper::type_info; - Mask::Ptr getMask(const Output & output) { auto &rtInfo = output.get_rt_info(); using MaskWrapper = VariantWrapper; @@ -57,6 +53,12 @@ std::ostream & operator<< (std::ostream & out, const Mask & mask) { return out; } +} // namespace ngraph + +namespace ov { +template class ngraph::VariantImpl; -} // namespace ngraph +constexpr VariantTypeInfo VariantWrapper::type_info; + +} // namespace ov diff --git a/inference-engine/src/readers/ir_reader/ie_ir_reader.hpp b/inference-engine/src/readers/ir_reader/ie_ir_reader.hpp index 6e1c092bc79176..ad72c1e52d3dfb 100644 --- a/inference-engine/src/readers/ir_reader/ie_ir_reader.hpp +++ b/inference-engine/src/readers/ir_reader/ie_ir_reader.hpp @@ -20,10 +20,6 @@ class xml_node; class xml_document; } // namespace pugi -namespace ngraph { -class Function; -} // namespace ngraph - namespace InferenceEngine { /** diff --git a/inference-engine/src/snippets/include/snippets/register_info.hpp b/inference-engine/src/snippets/include/snippets/register_info.hpp index 23f5a14036c946..4a37b6c27a49fe 100644 --- a/inference-engine/src/snippets/include/snippets/register_info.hpp +++ b/inference-engine/src/snippets/include/snippets/register_info.hpp @@ -4,21 +4,21 @@ #pragma once -#include -#include #include +#include +#include -namespace ngraph { +namespace ov { template <> class TRANSFORMATIONS_API VariantWrapper> : public VariantImpl> { public: static constexpr VariantTypeInfo type_info{"Variant::RegInfo|Variant::RuntimeAttribute::AxisVector", 0}; - const VariantTypeInfo& get_type_info() const override { return type_info; } - VariantWrapper(const value_type& value) - : VariantImpl(value) { + const VariantTypeInfo& get_type_info() const override { + return type_info; } + VariantWrapper(const value_type& value) : VariantImpl(value) {} }; -} // namespace ngraph \ No newline at end of file +} // namespace ov diff --git a/inference-engine/src/transformations/include/transformations/rt_info/dequantization_attribute.hpp b/inference-engine/src/transformations/include/transformations/rt_info/dequantization_attribute.hpp index 8b75663f7e3819..9b9b0747bc9ada 100644 --- a/inference-engine/src/transformations/include/transformations/rt_info/dequantization_attribute.hpp +++ b/inference-engine/src/transformations/include/transformations/rt_info/dequantization_attribute.hpp @@ -46,11 +46,21 @@ class TRANSFORMATIONS_API DequantizationAttr { */ std::string getDequantizationAttr() const; }; +/** + * @ingroup ie_runtime_attr_api + * @brief getDequantization return string with dequantization value + * @param[in] node The node will be used to get Dequantization attribute + */ +TRANSFORMATIONS_API std::string getDequantization(const std::shared_ptr& node); + +} // namespace ngraph + +namespace ov { -extern template class TRANSFORMATIONS_API VariantImpl; +extern template class TRANSFORMATIONS_API VariantImpl; template<> -class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { +class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info{"DEQUANTIZATION", 0}; @@ -65,11 +75,4 @@ class TRANSFORMATIONS_API VariantWrapper : public VariantImp std::shared_ptr init(const std::shared_ptr & node) override; }; -/** - * @ingroup ie_runtime_attr_api - * @brief getDequantization return string with dequantization value - * @param[in] node The node will be used to get Dequantization attribute - */ -TRANSFORMATIONS_API std::string getDequantization(const std::shared_ptr& node); - -} // namespace ngraph +} // namespace ov diff --git a/inference-engine/src/transformations/include/transformations/rt_info/disable_constant_folding.hpp b/inference-engine/src/transformations/include/transformations/rt_info/disable_constant_folding.hpp index 1e04ce22dccb1e..26bbe5e40104e9 100644 --- a/inference-engine/src/transformations/include/transformations/rt_info/disable_constant_folding.hpp +++ b/inference-engine/src/transformations/include/transformations/rt_info/disable_constant_folding.hpp @@ -24,10 +24,14 @@ class TRANSFORMATIONS_API DisableConstantFolding { DisableConstantFolding() = default; }; -extern template class TRANSFORMATIONS_API VariantImpl; +TRANSFORMATIONS_API void disable_constant_folding(const std::shared_ptr& node); +} // namespace ngraph + +namespace ov { +extern template class TRANSFORMATIONS_API VariantImpl; template<> -class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { +class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info{"DISABLED_CONSTANT_FOLDING", 0}; @@ -40,5 +44,4 @@ class TRANSFORMATIONS_API VariantWrapper : public Varian bool is_copyable() const override { return false; } }; -TRANSFORMATIONS_API void disable_constant_folding(const std::shared_ptr& node); -} // namespace ngraph +} // namespace ov diff --git a/inference-engine/src/transformations/include/transformations/rt_info/fused_names_attribute.hpp b/inference-engine/src/transformations/include/transformations/rt_info/fused_names_attribute.hpp index 20a4946127fbb0..95e6fae96a85d8 100644 --- a/inference-engine/src/transformations/include/transformations/rt_info/fused_names_attribute.hpp +++ b/inference-engine/src/transformations/include/transformations/rt_info/fused_names_attribute.hpp @@ -61,24 +61,6 @@ class TRANSFORMATIONS_API FusedNames { std::vector getVectorNames() const; }; -extern template class TRANSFORMATIONS_API VariantImpl; - -template<> -class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { -public: - static constexpr VariantTypeInfo type_info{"Variant::RuntimeAttribute::FusedNames", 0}; - - const VariantTypeInfo &get_type_info() const override { - return type_info; - } - - VariantWrapper(const value_type &value) : VariantImpl(value) {} - - std::shared_ptr merge(const ngraph::NodeVector & nodes) override; - - std::shared_ptr init(const std::shared_ptr & node) override; -}; - /** * @ingroup ie_runtime_attr_api * @brief getFusedNames return string with operation names separated by coma in alphabetical order @@ -95,3 +77,24 @@ TRANSFORMATIONS_API std::string getFusedNames(const std::shared_ptr getFusedNamesVector(const std::shared_ptr & node); } // namespace ngraph + +namespace ov { + +extern template class TRANSFORMATIONS_API VariantImpl; + +template<> +class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { +public: + static constexpr VariantTypeInfo type_info{"Variant::RuntimeAttribute::FusedNames", 0}; + + const VariantTypeInfo &get_type_info() const override { + return type_info; + } + + VariantWrapper(const value_type &value) : VariantImpl(value) {} + + std::shared_ptr merge(const ngraph::NodeVector & nodes) override; + + std::shared_ptr init(const std::shared_ptr & node) override; +}; +} // namespace ov diff --git a/inference-engine/src/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp b/inference-engine/src/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp index eeff9dab29c911..d2af91b58e8b13 100644 --- a/inference-engine/src/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp +++ b/inference-engine/src/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp @@ -47,11 +47,21 @@ class TRANSFORMATIONS_API PrimitivesPriority { */ std::string getPrimitivesPriority() const; }; +/** + * @ingroup ie_runtime_attr_api + * @brief getPrimitivesPriority return string with primitive priorities value + * @param[in] node The node will be used to get PrimitivesPriority attribute + */ +TRANSFORMATIONS_API std::string getPrimitivesPriority(const std::shared_ptr & node); + +} // namespace ngraph + +namespace ov { -extern template class TRANSFORMATIONS_API VariantImpl; +extern template class TRANSFORMATIONS_API VariantImpl; template<> -class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { +class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info{"Variant::RuntimeAttribute::PrimitivesPriority", 0}; @@ -61,16 +71,9 @@ class TRANSFORMATIONS_API VariantWrapper : public VariantImp VariantWrapper(const value_type &value) : VariantImpl(value) {} - std::shared_ptr merge(const ngraph::NodeVector & nodes) override; + std::shared_ptr merge(const ngraph::NodeVector & nodes) override; - std::shared_ptr init(const std::shared_ptr & node) override; + std::shared_ptr init(const std::shared_ptr & node) override; }; -/** - * @ingroup ie_runtime_attr_api - * @brief getPrimitivesPriority return string with primitive priorities value - * @param[in] node The node will be used to get PrimitivesPriority attribute - */ -TRANSFORMATIONS_API std::string getPrimitivesPriority(const std::shared_ptr & node); - -} // namespace ngraph +} // namespace ov diff --git a/inference-engine/src/transformations/include/transformations/rt_info/strides_property.hpp b/inference-engine/src/transformations/include/transformations/rt_info/strides_property.hpp index 2ec78ce68928d8..41ac9b6f0aea4f 100644 --- a/inference-engine/src/transformations/include/transformations/rt_info/strides_property.hpp +++ b/inference-engine/src/transformations/include/transformations/rt_info/strides_property.hpp @@ -10,9 +10,9 @@ #include -namespace ngraph { +namespace ov { template <> -class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { +class TRANSFORMATIONS_API VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info{"Variant::Strides", 0}; const VariantTypeInfo& get_type_info() const override { return type_info; } @@ -21,7 +21,7 @@ class TRANSFORMATIONS_API VariantWrapper : public VariantImpl } }; -} // namespace ngraph +} // namespace ov TRANSFORMATIONS_API bool has_strides_prop(const ngraph::Input& node); TRANSFORMATIONS_API ngraph::Strides get_strides_prop(const ngraph::Input& node); diff --git a/inference-engine/src/transformations/src/transformations/rt_info/dequantization_attribute.cpp b/inference-engine/src/transformations/src/transformations/rt_info/dequantization_attribute.cpp index 67bfc8de3f631b..829f5a0d85b5e2 100644 --- a/inference-engine/src/transformations/src/transformations/rt_info/dequantization_attribute.cpp +++ b/inference-engine/src/transformations/src/transformations/rt_info/dequantization_attribute.cpp @@ -13,16 +13,28 @@ #include "transformations/rt_info/dequantization_attribute.hpp" -namespace ngraph { - -template class ngraph::VariantImpl; - -constexpr VariantTypeInfo VariantWrapper::type_info; +using namespace ov; +using namespace ngraph; std::string DequantizationAttr::getDequantizationAttr() const { return dequantization_attribute; } +std::string ngraph::getDequantization(const std::shared_ptr& node) { + const auto& rtInfo = node->get_rt_info(); + using getDequantizationWrapper = VariantWrapper; + + if (!rtInfo.count(getDequantizationWrapper::type_info.name)) return ""; + + const auto& attr = rtInfo.at(getDequantizationWrapper::type_info.name); + DequantizationAttr pp = as_type_ptr(attr)->get(); + return pp.getDequantizationAttr(); +} + +template class ov::VariantImpl; + +constexpr VariantTypeInfo VariantWrapper::type_info; + std::shared_ptr VariantWrapper::merge(const ngraph::NodeVector & nodes) { std::set dequantizations; @@ -43,17 +55,3 @@ std::shared_ptr VariantWrapper::merge(const std::shared_ptr VariantWrapper::init(const std::shared_ptr & node) { return std::make_shared>(DequantizationAttr(node->get_friendly_name())); } - -std::string getDequantization(const std::shared_ptr& node) { - const auto& rtInfo = node->get_rt_info(); - using getDequantizationWrapper = VariantWrapper; - - if (!rtInfo.count(getDequantizationWrapper::type_info.name)) return ""; - - const auto& attr = rtInfo.at(getDequantizationWrapper::type_info.name); - DequantizationAttr pp = as_type_ptr(attr)->get(); - return pp.getDequantizationAttr(); -} - - -} // namespace ngraph diff --git a/inference-engine/src/transformations/src/transformations/rt_info/disable_constant_folding.cpp b/inference-engine/src/transformations/src/transformations/rt_info/disable_constant_folding.cpp index 791102ed1f4de3..696f02bf52137f 100644 --- a/inference-engine/src/transformations/src/transformations/rt_info/disable_constant_folding.cpp +++ b/inference-engine/src/transformations/src/transformations/rt_info/disable_constant_folding.cpp @@ -4,11 +4,11 @@ #include "transformations/rt_info/disable_constant_folding.hpp" -template class ngraph::VariantImpl; +template class ov::VariantImpl; -constexpr ngraph::VariantTypeInfo ngraph::VariantWrapper::type_info; +constexpr ov::VariantTypeInfo ov::VariantWrapper::type_info; void ngraph::disable_constant_folding(const std::shared_ptr& node) { auto & rt_info = node->get_rt_info(); rt_info[VariantWrapper::type_info.name] = make_variant({}); -} \ No newline at end of file +} diff --git a/inference-engine/src/transformations/src/transformations/rt_info/fused_names_attribute.cpp b/inference-engine/src/transformations/src/transformations/rt_info/fused_names_attribute.cpp index cf60bc39573af6..01af6fc50d468e 100644 --- a/inference-engine/src/transformations/src/transformations/rt_info/fused_names_attribute.cpp +++ b/inference-engine/src/transformations/src/transformations/rt_info/fused_names_attribute.cpp @@ -13,11 +13,8 @@ #include "transformations/rt_info/fused_names_attribute.hpp" -namespace ngraph { - -template class ngraph::VariantImpl; - -constexpr VariantTypeInfo VariantWrapper::type_info; +using namespace ngraph; +using namespace ov; std::string FusedNames::getNames() const { std::string res; @@ -37,25 +34,7 @@ void FusedNames::fuseWith(const FusedNames &names) { } } -std::shared_ptr VariantWrapper::merge(const ngraph::NodeVector & nodes) { - FusedNames mergedNames; - for (auto &node : nodes) { - const auto &rtInfo = node->get_rt_info(); - if (!rtInfo.count(VariantWrapper::type_info.name)) continue; - - const auto attr = rtInfo.at(VariantWrapper::type_info.name); - if (auto fusedNames = std::dynamic_pointer_cast >(attr)) { - mergedNames.fuseWith(fusedNames->get()); - } - } - return std::make_shared >(mergedNames); -} - -std::shared_ptr VariantWrapper::init(const std::shared_ptr & node) { - return std::make_shared > (FusedNames(node->get_friendly_name())); -} - -std::string getFusedNames(const std::shared_ptr &node) { +std::string ngraph::getFusedNames(const std::shared_ptr &node) { const auto &rtInfo = node->get_rt_info(); using FusedNamesWrapper = VariantWrapper; @@ -66,7 +45,7 @@ std::string getFusedNames(const std::shared_ptr &node) { return fusedNames.getNames(); } -std::vector getFusedNamesVector(const std::shared_ptr &node) { +std::vector ngraph::getFusedNamesVector(const std::shared_ptr &node) { if (!node) return {}; const auto &rtInfo = node->get_rt_info(); @@ -79,5 +58,24 @@ std::vector getFusedNamesVector(const std::shared_ptr return fusedNames.getVectorNames(); } +template class ov::VariantImpl; + +constexpr VariantTypeInfo VariantWrapper::type_info; + +std::shared_ptr VariantWrapper::merge(const ngraph::NodeVector & nodes) { + FusedNames mergedNames; + for (auto &node : nodes) { + const auto &rtInfo = node->get_rt_info(); + if (!rtInfo.count(VariantWrapper::type_info.name)) continue; + + const auto attr = rtInfo.at(VariantWrapper::type_info.name); + if (auto fusedNames = std::dynamic_pointer_cast >(attr)) { + mergedNames.fuseWith(fusedNames->get()); + } + } + return std::make_shared >(mergedNames); +} -} // namespace ngraph +std::shared_ptr VariantWrapper::init(const std::shared_ptr & node) { + return std::make_shared > (FusedNames(node->get_friendly_name())); +} diff --git a/inference-engine/src/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp b/inference-engine/src/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp index 82aa589223058a..86244edd94daa2 100644 --- a/inference-engine/src/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp +++ b/inference-engine/src/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp @@ -16,16 +16,28 @@ #include "ngraph_ops/convolution_ie.hpp" #include "ngraph_ops/deconvolution_ie.hpp" -namespace ngraph { - -template class ngraph::VariantImpl; - -constexpr VariantTypeInfo VariantWrapper::type_info; +using namespace ov; +using namespace ngraph; std::string PrimitivesPriority::getPrimitivesPriority() const { return primitives_priority; } +std::string ngraph::getPrimitivesPriority(const std::shared_ptr &node) { + const auto &rtInfo = node->get_rt_info(); + using PrimitivesPriorityWrapper = VariantWrapper; + + if (!rtInfo.count(PrimitivesPriorityWrapper::type_info.name)) return ""; + + const auto &attr = rtInfo.at(PrimitivesPriorityWrapper::type_info.name); + PrimitivesPriority pp = as_type_ptr(attr)->get(); + return pp.getPrimitivesPriority(); +} + +template class ov::VariantImpl; + +constexpr VariantTypeInfo VariantWrapper::type_info; + std::shared_ptr VariantWrapper::merge(const ngraph::NodeVector & nodes) { auto isConvolutionBased = [](const std::shared_ptr & node) -> bool { if (std::dynamic_pointer_cast(node) || @@ -62,16 +74,3 @@ std::shared_ptr VariantWrapper::merge(const std::shared_ptr VariantWrapper::init(const std::shared_ptr & node) { throw ngraph_error(std::string(type_info.name) + " has no default initialization."); } - -std::string getPrimitivesPriority(const std::shared_ptr &node) { - const auto &rtInfo = node->get_rt_info(); - using PrimitivesPriorityWrapper = VariantWrapper; - - if (!rtInfo.count(PrimitivesPriorityWrapper::type_info.name)) return ""; - - const auto &attr = rtInfo.at(PrimitivesPriorityWrapper::type_info.name); - PrimitivesPriority pp = as_type_ptr(attr)->get(); - return pp.getPrimitivesPriority(); -} - -} // namespace ngraph diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.cpp b/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.cpp index 6f24854affb712..d0b4441dfdf81e 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.cpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.cpp @@ -76,7 +76,7 @@ void CpuTestWithFusing::CheckPluginRelatedResults(InferenceEngine::ExecutableNet std::shared_ptr postFunctionMgr::addPostOps(const ngraph::element::Type &ngPrc, ngraph::ParameterVector ¶ms, const std::shared_ptr &lastNode) const { - auto clonedPostFunction = clone_function(*_pFunction); + auto clonedPostFunction = ngraph::clone_function(*_pFunction); clonedPostFunction->set_friendly_name(_pFunction->get_friendly_name()); clonedPostFunction->replace_node(clonedPostFunction->get_parameters()[0], lastNode); return clonedPostFunction->get_result()->get_input_node_shared_ptr(0); diff --git a/ngraph/core/include/ngraph/attribute_visitor.hpp b/ngraph/core/include/ngraph/attribute_visitor.hpp index 9599457920925e..5fd9a62a2ef54e 100644 --- a/ngraph/core/include/ngraph/attribute_visitor.hpp +++ b/ngraph/core/include/ngraph/attribute_visitor.hpp @@ -12,12 +12,14 @@ #include "ngraph/type.hpp" #include "ngraph/type/element_type.hpp" +namespace ov { +class Function; +} namespace ngraph { template class ValueAccessor; class VisitorAdapter; class Node; -class Function; /// \brief Visits the attributes of a node, primarily for serialization-like tasks. /// @@ -95,7 +97,7 @@ class NGRAPH_API AttributeVisitor { /// \brief Provides API to handle nGraph Function attribute type, accessed as ValueAccessor /// \param name attribute name /// \param adapter reference to a Function ValueAccessor - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); /// The generic visitor. There must be a definition of AttributeAdapter that can convert /// to a ValueAccessor for one of the on_adpater methods. diff --git a/ngraph/core/include/ngraph/function.hpp b/ngraph/core/include/ngraph/function.hpp index 9c391a7bf88fbf..2bc16a37b62cde 100644 --- a/ngraph/core/include/ngraph/function.hpp +++ b/ngraph/core/include/ngraph/function.hpp @@ -4,274 +4,8 @@ #pragma once -#include -#include -#include -#include -#include -#include - -#include "ngraph/ngraph_visibility.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/assign.hpp" -#include "ngraph/op/parameter.hpp" -#include "ngraph/op/read_value.hpp" -#include "ngraph/op/result.hpp" -#include "ngraph/op/sink.hpp" -#include "ngraph/op/util/variable.hpp" +#include "openvino/core/function.hpp" namespace ngraph { -/// A user-defined function. -class NGRAPH_API Function { -public: - static constexpr DiscreteTypeInfo type_info{"Function", 0}; - const DiscreteTypeInfo& get_type_info() const { - return type_info; - } - Function(const NodeVector& results, const ParameterVector& parameters, const std::string& name = ""); - - Function(const OutputVector& results, const ParameterVector& parameters, const std::string& name = ""); - - Function(const std::shared_ptr& result, const ParameterVector& parameters, const std::string& name = ""); - - Function(const ResultVector& results, const ParameterVector& parameters, const std::string& name = ""); - - Function(const ResultVector& results, - const SinkVector& sinks, - const ParameterVector& parameters, - const std::string& name = ""); - - Function(const OutputVector& results, - const SinkVector& sinks, - const ParameterVector& parameters, - const std::string& name = ""); - - Function(const ResultVector& results, - const SinkVector& sinks, - const ParameterVector& parameters, - const VariableVector& variables, - const std::string& name = ""); - - Function(const OutputVector& results, - const SinkVector& sinks, - const ParameterVector& parameters, - const VariableVector& variables, - const std::string& name = ""); - - Function(const ResultVector& results, - const ParameterVector& parameters, - const VariableVector& variables, - const std::string& name = ""); - - Function(const OutputVector& results, - const ParameterVector& parameters, - const VariableVector& variables, - const std::string& name = ""); - - /// Constructs a Function. Lists of parameters and variables will be generated automatically - /// based on traversing the graph from the results. - explicit Function(const OutputVector& results, const std::string& name = ""); - - /// Constructs a Function. Lists of parameters and variables will be generated automatically - /// based on traversing the graph from the results and the sinks. - Function(const OutputVector& results, const SinkVector& sinks, const std::string& name = ""); - - virtual ~Function() = default; - /// Return the number of outputs for this function. - size_t get_output_size() const; - - /// Return the op that generates output i - std::shared_ptr get_output_op(size_t i) const; - - Output output(size_t i) const; - - /// Return the element type of output i - const element::Type& get_output_element_type(size_t i) const; - - /// Return the shape of element i - const Shape& get_output_shape(size_t i) const; - - /// Return the partial shape of element i - const PartialShape& get_output_partial_shape(size_t i) const; - - /// Check that there is a single result and return it. - std::shared_ptr get_result() const; - - /// \brief Get the unique name of the function. - /// \returns A const reference to the function's unique name. - const std::string& get_name() const; - - /// \brief Sets a friendly name for a function. This does not overwrite the unique name - /// of the function and is retrieved via get_friendly_name(). Used mainly for - /// debugging. - /// \param name is the friendly name to set - void set_friendly_name(const std::string& name); - - /// \brief Gets the friendly name for a function. If no friendly name has been set via - /// set_friendly_name then the function's unique name is returned. - /// \returns A const reference to the function's friendly name. - const std::string& get_friendly_name() const; - - std::vector> get_ops() const; - std::vector> get_ordered_ops() const; - void map_unordered_ops(std::function f) const; - - friend std::ostream& operator<<(std::ostream&, const Function&); - // updates graph and m_results list - void replace_node(std::shared_ptr old, std::shared_ptr repl); - - void validate_nodes_and_infer_types() const; - - /// \brief Returns the sum of the size of all nodes in the graph plus the size of - /// all constant data. This has little value beyond comparing the relative size of - /// graphs and should not be considered the actual memory consumption of a graph. - size_t get_graph_size() const; - - /// \brief Returns true if any of the op's defined in the function contains partial shape - bool is_dynamic() const; - - /// \brief Replace the `parameter_index`th parameter of the function with `parameter`. - /// - /// All users of the `parameter_index`th parameter are redirected to `parameter`, and the - /// `parameter_index`th entry in the function parameter list is replaced with `parameter`. - /// - /// \param parameter_index The index of the parameter to replace. - /// \param parameter The parameter to substitute for the `parameter_index`th parameter. - void replace_parameter(size_t parameter_index, const std::shared_ptr& parameter); - - using topological_sort_t = - std::function>(const std::vector>& root_nodes)>; - void set_topological_sort(topological_sort_t); - - virtual bool visit_attributes(AttributeVisitor& visitor); - - /// Return the function parameters - const ParameterVector& get_parameters() const { - return m_parameters; - }; - /// Return a list of function's outputs - const ResultVector& get_results() const { - return m_results; - }; - /// Index for parameter, or -1 - int64_t get_parameter_index(const std::shared_ptr& parameter) const; - - /// Index for value or result referencing it, or -1 - int64_t get_result_index(const Output& value) const; - - /// \brief Evaluate the function on inputs, putting results in outputs. - /// \param output_tensors Tensors for the outputs to compute. One for each result - /// \param input_tensors Tensors for the inputs. One for each inputs. - /// \param evaluation_context Storage of additional settings and attributes that can be used - /// when evaluating the function. This additional information can be shared across nodes. - bool evaluate(const HostTensorVector& output_tensors, - const HostTensorVector& input_tensors, - EvaluationContext evaluation_context = EvaluationContext()) const; - - /// \brief Return a list of function's sinks. - const SinkVector& get_sinks() const { - return m_sinks; - } - /// \brief Add new sink nodes to the list. Method doesn't validate graph, it should be done - /// manually after all changes. - /// \param sinks new sink nodes - void add_sinks(const SinkVector& sinks); - - /// \brief Delete sink node from the list of sinks. Method doesn't delete node from graph. - /// \param sink Sink to delete - void remove_sink(const std::shared_ptr& sink); - - /// \brief Add new Result nodes to the list. Method doesn't validate graph, it should be - /// done manually after all changes. - /// \param results new Result nodes - void add_results(const ResultVector& results); - - /// \brief Delete Result node from the list of results. Method will not delete node from - /// graph. - /// \param result Result node to delete - void remove_result(const std::shared_ptr& result); - - /// \brief Add new Parameter nodes to the list. - /// - /// Method doesn't change or validate graph, it should be done manually. - /// For example, if you want to replace `ReadValue` node by `Parameter`, you should do the - /// following steps: - /// * replace node `ReadValue` by `Parameter` in graph - /// * call add_parameter() to add new input to the list - /// * call graph validation to check correctness of changes - /// - /// \param params new Parameter nodes - void add_parameters(const ParameterVector& params); - - /// \brief Delete Parameter node from the list of parameters. Method will not delete node - /// from graph. You need to replace Parameter with other operation manually. - /// Attention: Indexing of parameters can be changed. - /// - /// Possible use of method is to replace input by variable. For it the following steps - /// should be done: - /// * `Parameter` node should be replaced by `ReadValue` - /// * call remove_parameter(param) to remove input from the list - /// * check if any parameter indexes are saved/used somewhere, update it for all inputs - /// because indexes can be changed - /// * call graph validation to check all changes - /// - /// \param param Parameter node to delete - void remove_parameter(const std::shared_ptr& param); - - /// \brief Add new variables to the list. Method doesn't validate graph, it should be done - /// manually after all changes. - /// \param variables new variables to add - void add_variables(const VariableVector& variables); - - /// \brief Delete variable from the list of variables. - /// Method doesn't delete nodes that used this variable from the graph. - /// \param variable Variable to delete - void remove_variable(const VariablePtr& variable); - - /// \brief Return a list of function's variables. - const VariableVector& get_variables() const { - return m_variables; - } - - /// \brief Return a variable by specified variable_id. - VariablePtr get_variable_by_id(const std::string& variable_id) const; - -private: - Function(const Function&) = delete; - Function(const Function&&) = delete; - Function& operator=(const Function&) = delete; - - /// \brief Depending on the options selected, - /// checks all the Parameter/Variables are registered in the list of Function - /// parameters/variables or finds all Parameters/Variables in a function and registers them. - /// \param detect_variables If this flag is true, then it finds all Variables in a function - /// and registers them, otherwise checks all the Variables are registered. - /// \param detect_parameters If this flag is true, then it finds all Parameters in a - /// function and registers them, otherwise checks all the Parameters are registered. - void prerequirements(bool detect_variables, bool detect_parameters); - - static std::atomic m_next_instance_id; - std::string m_name; - const std::string m_unique_name; - size_t m_placement{0}; - topological_sort_t m_topological_sorter; - - ResultVector m_results; - // List of the nodes with side effect in graph. - // These nodes are not outputs of graph but should not be removed even if have no children. - SinkVector m_sinks; - ParameterVector m_parameters; - VariableVector m_variables; -}; - -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::shared_ptr& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; +using ov::Function; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/ngraph_visibility.hpp b/ngraph/core/include/ngraph/ngraph_visibility.hpp index 685aa2014a5068..caeaa3f3bcea48 100644 --- a/ngraph/core/include/ngraph/ngraph_visibility.hpp +++ b/ngraph/core/include/ngraph/ngraph_visibility.hpp @@ -3,32 +3,6 @@ // #include "ngraph/visibility.hpp" +#include "openvino/core/core_visibility.hpp" -// Now we use the generic helper definitions above to define NGRAPH_API -// NGRAPH_API is used for the public API symbols. It either DLL imports or DLL exports -// (or does nothing for static build) - -#ifdef _WIN32 -# pragma warning(disable : 4251) -# pragma warning(disable : 4275) -#endif - -#ifdef NGRAPH_STATIC_LIBRARY // defined if we are building or calling NGRAPH as a static library -# define NGRAPH_API -#else -# ifdef ngraph_EXPORTS // defined if we are building the NGRAPH DLL (instead of using it) -# define NGRAPH_API NGRAPH_HELPER_DLL_EXPORT -# else -# define NGRAPH_API NGRAPH_HELPER_DLL_IMPORT -# endif // ngraph_EXPORTS -#endif // NGRAPH_STATIC_LIBRARY - -#ifndef ENABLE_UNICODE_PATH_SUPPORT -# ifdef _WIN32 -# if defined __INTEL_COMPILER || defined _MSC_VER -# define ENABLE_UNICODE_PATH_SUPPORT -# endif -# elif defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 2)) || defined(__clang__) -# define ENABLE_UNICODE_PATH_SUPPORT -# endif -#endif +#define NGRAPH_API OPENVINO_API diff --git a/ngraph/core/include/ngraph/node.hpp b/ngraph/core/include/ngraph/node.hpp index f91570e9b96d46..e3c4b1a39e4193 100644 --- a/ngraph/core/include/ngraph/node.hpp +++ b/ngraph/core/include/ngraph/node.hpp @@ -47,8 +47,6 @@ class Output; class AttributeVisitor; class Node; -class Function; - namespace runtime { class HostTensor; } diff --git a/ngraph/core/include/ngraph/op/parameter.hpp b/ngraph/core/include/ngraph/op/parameter.hpp index f2c6cb9cfa18ff..0795cc5cc7f215 100644 --- a/ngraph/core/include/ngraph/op/parameter.hpp +++ b/ngraph/core/include/ngraph/op/parameter.hpp @@ -7,7 +7,6 @@ #include "ngraph/op/op.hpp" namespace ngraph { -class Function; namespace op { namespace v0 { /// \brief A function parameter. @@ -30,7 +29,7 @@ class NGRAPH_API Parameter : public op::Op { void validate_and_infer_types() override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; bool is_relevant_to_shapes() const; void set_is_relevant_to_shapes(bool is_relevant); diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 1b335a2d45746e..0cc89d9c387825 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -4,6 +4,7 @@ #pragma once +#include #include #include "ngraph/op/op.hpp" diff --git a/ngraph/core/include/ngraph/op/util/variable_context.hpp b/ngraph/core/include/ngraph/op/util/variable_context.hpp index 9deda94f4fc2c2..71253347123f33 100644 --- a/ngraph/core/include/ngraph/op/util/variable_context.hpp +++ b/ngraph/core/include/ngraph/op/util/variable_context.hpp @@ -5,12 +5,12 @@ #pragma once #include -#include -#include #include #include "ngraph/op/util/variable.hpp" #include "ngraph/op/util/variable_value.hpp" +#include "ngraph/output_vector.hpp" +#include "ngraph/variant.hpp" namespace ngraph { using VariableValuePtr = std::shared_ptr; @@ -70,9 +70,11 @@ class NGRAPH_API VariableContext { /// The values associated with a particular Variable. VariableMap m_variable_values; }; +} // namespace ngraph +namespace ov { template <> -class NGRAPH_API VariantWrapper : public VariantImpl { +class NGRAPH_API VariantWrapper : public VariantImpl { public: static constexpr VariantTypeInfo type_info{"Variant::EvaluationContext::VariableContext", 0}; @@ -86,5 +88,4 @@ class NGRAPH_API VariantWrapper : public VariantImpl #include -#include "ngraph/ngraph_visibility.hpp" -#include "ngraph/output_vector.hpp" -#include "ngraph/type.hpp" +#include "openvino/core/variant.hpp" namespace ngraph { -class Node; -using VariantTypeInfo = DiscreteTypeInfo; +using ov::VariantTypeInfo; -class NGRAPH_API Variant { -public: - virtual ~Variant(); - virtual const VariantTypeInfo& get_type_info() const = 0; - - virtual std::shared_ptr init(const std::shared_ptr& node); - virtual std::shared_ptr merge(const ngraph::NodeVector& nodes); - virtual bool is_copyable() const; - virtual std::string to_string() { - return ""; - } -}; - -template -class VariantImpl : public Variant { -public: - using value_type = VT; - - VariantImpl(const value_type& value) : m_value(value) {} - - const value_type& get() const { - return m_value; - } - value_type& get() { - return m_value; - } - void set(const value_type& value) { - m_value = value; - } - -protected: - value_type m_value; -}; - -extern template class NGRAPH_API VariantImpl; -extern template class NGRAPH_API VariantImpl; - -template -class VariantWrapper {}; - -template <> -class NGRAPH_API VariantWrapper : public VariantImpl { -public: - static constexpr VariantTypeInfo type_info{"Variant::std::string", 0}; - const VariantTypeInfo& get_type_info() const override { - return type_info; - } - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -template <> -class NGRAPH_API VariantWrapper : public VariantImpl { -public: - static constexpr VariantTypeInfo type_info{"Variant::int64_t", 0}; - const VariantTypeInfo& get_type_info() const override { - return type_info; - } - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; +using ov::Variant; +using ov::VariantImpl; +using ov::VariantWrapper; template inline std::shared_ptr make_variant(const T& p) { - return std::dynamic_pointer_cast>(std::make_shared>(p)); + return ov::make_variant(p); } - template inline std::shared_ptr make_variant(const char (&s)[N]) { - return std::dynamic_pointer_cast>(std::make_shared>(s)); + return ov::make_variant(s); } #if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) template inline std::shared_ptr make_variant(const wchar_t (&s)[N]) { - return std::dynamic_pointer_cast>(std::make_shared>(s)); + return ov::make_variant(s); } #endif -using RTMap = std::map>; +using ov::RTMap; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/visibility.hpp b/ngraph/core/include/ngraph/visibility.hpp index 99ce1d7631951b..af6a1451bf1fd4 100644 --- a/ngraph/core/include/ngraph/visibility.hpp +++ b/ngraph/core/include/ngraph/visibility.hpp @@ -2,18 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // -// https://gcc.gnu.org/wiki/Visibility -// Generic helper definitions for shared library support -#if defined _WIN32 || defined __CYGWIN__ -# define NGRAPH_HELPER_DLL_IMPORT __declspec(dllimport) -# define NGRAPH_HELPER_DLL_EXPORT __declspec(dllexport) -# define NGRAPH_HELPER_DLL_LOCAL -#elif defined(__GNUC__) && __GNUC__ >= 4 -# define NGRAPH_HELPER_DLL_IMPORT __attribute__((visibility("default"))) -# define NGRAPH_HELPER_DLL_EXPORT __attribute__((visibility("default"))) -# define NGRAPH_HELPER_DLL_LOCAL __attribute__((visibility("hidden"))) -#else -# define NGRAPH_HELPER_DLL_IMPORT -# define NGRAPH_HELPER_DLL_EXPORT -# define NGRAPH_HELPER_DLL_LOCAL -#endif +#include + +#define NGRAPH_HELPER_DLL_IMPORT CORE_HELPER_DLL_IMPORT +#define NGRAPH_HELPER_DLL_EXPORT CORE_HELPER_DLL_EXPORT +#define NGRAPH_HELPER_DLL_LOCAL CORE_HELPER_DLL_LOCAL diff --git a/ngraph/core/include/openvino/core/core_visibility.hpp b/ngraph/core/include/openvino/core/core_visibility.hpp new file mode 100644 index 00000000000000..85adf6c1307e0d --- /dev/null +++ b/ngraph/core/include/openvino/core/core_visibility.hpp @@ -0,0 +1,35 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/visibility.hpp" + +#define OV_NEW_API 1 +// Now we use the generic helper definitions above to define NGRAPH_API +// NGRAPH_API is used for the public API symbols. It either DLL imports or DLL exports +// (or does nothing for static build) + +#ifdef _WIN32 +# pragma warning(disable : 4251) +# pragma warning(disable : 4275) +#endif + +#ifdef NGRAPH_STATIC_LIBRARY // defined if we are building or calling NGRAPH as a static library +# define OPENVINO_API +#else +# ifdef ngraph_EXPORTS // defined if we are building the NGRAPH DLL (instead of using it) +# define OPENVINO_API CORE_HELPER_DLL_EXPORT +# else +# define OPENVINO_API CORE_HELPER_DLL_IMPORT +# endif // ngraph_EXPORTS +#endif // NGRAPH_STATIC_LIBRARY + +#ifndef ENABLE_UNICODE_PATH_SUPPORT +# ifdef _WIN32 +# if defined __INTEL_COMPILER || defined _MSC_VER +# define ENABLE_UNICODE_PATH_SUPPORT +# endif +# elif defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 2)) || defined(__clang__) +# define ENABLE_UNICODE_PATH_SUPPORT +# endif +#endif diff --git a/ngraph/core/include/openvino/core/function.hpp b/ngraph/core/include/openvino/core/function.hpp new file mode 100644 index 00000000000000..81607040deae82 --- /dev/null +++ b/ngraph/core/include/openvino/core/function.hpp @@ -0,0 +1,289 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "ngraph/node.hpp" +#include "ngraph/op/assign.hpp" +#include "ngraph/op/parameter.hpp" +#include "ngraph/op/read_value.hpp" +#include "ngraph/op/result.hpp" +#include "ngraph/op/sink.hpp" +#include "ngraph/op/util/variable.hpp" +#include "openvino/core/core_visibility.hpp" + +namespace ov { +/// A user-defined function. +class OPENVINO_API Function { +public: + static constexpr ngraph::DiscreteTypeInfo type_info{"Function", 0}; + const ngraph::DiscreteTypeInfo& get_type_info() const { + return type_info; + } + Function(const ngraph::NodeVector& results, + const ngraph::ParameterVector& parameters, + const std::string& name = ""); + + Function(const ngraph::OutputVector& results, + const ngraph::ParameterVector& parameters, + const std::string& name = ""); + + Function(const std::shared_ptr& result, + const ngraph::ParameterVector& parameters, + const std::string& name = ""); + + Function(const ngraph::ResultVector& results, + const ngraph::ParameterVector& parameters, + const std::string& name = ""); + + Function(const ngraph::ResultVector& results, + const ngraph::SinkVector& sinks, + const ngraph::ParameterVector& parameters, + const std::string& name = ""); + + Function(const ngraph::OutputVector& results, + const ngraph::SinkVector& sinks, + const ngraph::ParameterVector& parameters, + const std::string& name = ""); + + Function(const ngraph::ResultVector& results, + const ngraph::SinkVector& sinks, + const ngraph::ParameterVector& parameters, + const ngraph::VariableVector& variables, + const std::string& name = ""); + + Function(const ngraph::OutputVector& results, + const ngraph::SinkVector& sinks, + const ngraph::ParameterVector& parameters, + const ngraph::VariableVector& variables, + const std::string& name = ""); + + Function(const ngraph::ResultVector& results, + const ngraph::ParameterVector& parameters, + const ngraph::VariableVector& variables, + const std::string& name = ""); + + Function(const ngraph::OutputVector& results, + const ngraph::ParameterVector& parameters, + const ngraph::VariableVector& variables, + const std::string& name = ""); + + /// Constructs a Function. Lists of parameters and variables will be generated automatically + /// based on traversing the graph from the results. + explicit Function(const ngraph::OutputVector& results, const std::string& name = ""); + + /// Constructs a Function. Lists of parameters and variables will be generated automatically + /// based on traversing the graph from the results and the sinks. + Function(const ngraph::OutputVector& results, const ngraph::SinkVector& sinks, const std::string& name = ""); + + virtual ~Function() = default; + /// Return the number of outputs for this function. + size_t get_output_size() const; + + /// Return the op that generates output i + std::shared_ptr get_output_op(size_t i) const; + + ngraph::Output output(size_t i) const; + + /// Return the element type of output i + const ngraph::element::Type& get_output_element_type(size_t i) const; + + /// Return the shape of element i + const ngraph::Shape& get_output_shape(size_t i) const; + + /// Return the partial shape of element i + const ngraph::PartialShape& get_output_partial_shape(size_t i) const; + + /// Check that there is a single result and return it. + std::shared_ptr get_result() const; + + /// \brief Get the unique name of the function. + /// \returns A const reference to the function's unique name. + const std::string& get_name() const; + + /// \brief Sets a friendly name for a function. This does not overwrite the unique name + /// of the function and is retrieved via get_friendly_name(). Used mainly for + /// debugging. + /// \param name is the friendly name to set + void set_friendly_name(const std::string& name); + + /// \brief Gets the friendly name for a function. If no friendly name has been set via + /// set_friendly_name then the function's unique name is returned. + /// \returns A const reference to the function's friendly name. + const std::string& get_friendly_name() const; + + std::vector> get_ops() const; + std::vector> get_ordered_ops() const; + void map_unordered_ops(std::function f) const; + + friend std::ostream& operator<<(std::ostream&, const Function&); + // updates graph and m_results list + void replace_node(std::shared_ptr old, std::shared_ptr repl); + + void validate_nodes_and_infer_types() const; + + /// \brief Returns the sum of the size of all nodes in the graph plus the size of + /// all constant data. This has little value beyond comparing the relative size of + /// graphs and should not be considered the actual memory consumption of a graph. + size_t get_graph_size() const; + + /// \brief Returns true if any of the op's defined in the function contains partial shape + bool is_dynamic() const; + + /// \brief Replace the `parameter_index`th parameter of the function with `parameter`. + /// + /// All users of the `parameter_index`th parameter are redirected to `parameter`, and the + /// `parameter_index`th entry in the function parameter list is replaced with `parameter`. + /// + /// \param parameter_index The index of the parameter to replace. + /// \param parameter The parameter to substitute for the `parameter_index`th parameter. + void replace_parameter(size_t parameter_index, const std::shared_ptr& parameter); + + using topological_sort_t = std::function>( + const std::vector>& root_nodes)>; + void set_topological_sort(topological_sort_t); + + virtual bool visit_attributes(ngraph::AttributeVisitor& visitor); + + /// Return the function parameters + const ngraph::ParameterVector& get_parameters() const { + return m_parameters; + }; + /// Return a list of function's outputs + const ngraph::ResultVector& get_results() const { + return m_results; + }; + /// Index for parameter, or -1 + int64_t get_parameter_index(const std::shared_ptr& parameter) const; + + /// Index for value or result referencing it, or -1 + int64_t get_result_index(const ngraph::Output& value) const; + + /// \brief Evaluate the function on inputs, putting results in outputs. + /// \param output_tensors Tensors for the outputs to compute. One for each result + /// \param input_tensors Tensors for the inputs. One for each inputs. + /// \param evaluation_context Storage of additional settings and attributes that can be used + /// when evaluating the function. This additional information can be shared across nodes. + bool evaluate(const ngraph::HostTensorVector& output_tensors, + const ngraph::HostTensorVector& input_tensors, + ngraph::EvaluationContext evaluation_context = ngraph::EvaluationContext()) const; + + /// \brief Return a list of function's sinks. + const ngraph::SinkVector& get_sinks() const { + return m_sinks; + } + /// \brief Add new sink nodes to the list. Method doesn't validate graph, it should be done + /// manually after all changes. + /// \param sinks new sink nodes + void add_sinks(const ngraph::SinkVector& sinks); + + /// \brief Delete sink node from the list of sinks. Method doesn't delete node from graph. + /// \param sink Sink to delete + void remove_sink(const std::shared_ptr& sink); + + /// \brief Add new Result nodes to the list. Method doesn't validate graph, it should be + /// done manually after all changes. + /// \param results new Result nodes + void add_results(const ngraph::ResultVector& results); + + /// \brief Delete Result node from the list of results. Method will not delete node from + /// graph. + /// \param result Result node to delete + void remove_result(const std::shared_ptr& result); + + /// \brief Add new Parameter nodes to the list. + /// + /// Method doesn't change or validate graph, it should be done manually. + /// For example, if you want to replace `ReadValue` node by `Parameter`, you should do the + /// following steps: + /// * replace node `ReadValue` by `Parameter` in graph + /// * call add_parameter() to add new input to the list + /// * call graph validation to check correctness of changes + /// + /// \param params new Parameter nodes + void add_parameters(const ngraph::ParameterVector& params); + + /// \brief Delete Parameter node from the list of parameters. Method will not delete node + /// from graph. You need to replace Parameter with other operation manually. + /// Attention: Indexing of parameters can be changed. + /// + /// Possible use of method is to replace input by variable. For it the following steps + /// should be done: + /// * `Parameter` node should be replaced by `ReadValue` + /// * call remove_parameter(param) to remove input from the list + /// * check if any parameter indexes are saved/used somewhere, update it for all inputs + /// because indexes can be changed + /// * call graph validation to check all changes + /// + /// \param param Parameter node to delete + void remove_parameter(const std::shared_ptr& param); + + /// \brief Add new variables to the list. Method doesn't validate graph, it should be done + /// manually after all changes. + /// \param variables new variables to add + void add_variables(const ngraph::VariableVector& variables); + + /// \brief Delete variable from the list of variables. + /// Method doesn't delete nodes that used this variable from the graph. + /// \param variable Variable to delete + void remove_variable(const ngraph::VariablePtr& variable); + + /// \brief Return a list of function's variables. + const ngraph::VariableVector& get_variables() const { + return m_variables; + } + + /// \brief Return a variable by specified variable_id. + ngraph::VariablePtr get_variable_by_id(const std::string& variable_id) const; + +private: + Function(const Function&) = delete; + Function(const Function&&) = delete; + Function& operator=(const Function&) = delete; + + /// \brief Depending on the options selected, + /// checks all the Parameter/Variables are registered in the list of Function + /// parameters/variables or finds all Parameters/Variables in a function and registers them. + /// \param detect_variables If this flag is true, then it finds all Variables in a function + /// and registers them, otherwise checks all the Variables are registered. + /// \param detect_parameters If this flag is true, then it finds all Parameters in a + /// function and registers them, otherwise checks all the Parameters are registered. + void prerequirements(bool detect_variables, bool detect_parameters); + + static std::atomic m_next_instance_id; + std::string m_name; + const std::string m_unique_name; + size_t m_placement{0}; + topological_sort_t m_topological_sorter; + + ngraph::ResultVector m_results; + // List of the nodes with side effect in graph. + // These nodes are not outputs of graph but should not be removed even if have no children. + ngraph::SinkVector m_sinks; + ngraph::ParameterVector m_parameters; + ngraph::VariableVector m_variables; +}; + +} // namespace ov +namespace ngraph { +template <> +class NGRAPH_API AttributeAdapter> + : public DirectValueAccessor> { +public: + AttributeAdapter(std::shared_ptr& value) + : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; +} // namespace ngraph diff --git a/ngraph/core/include/openvino/core/variant.hpp b/ngraph/core/include/openvino/core/variant.hpp new file mode 100644 index 00000000000000..b7bcc03a0386ea --- /dev/null +++ b/ngraph/core/include/openvino/core/variant.hpp @@ -0,0 +1,98 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "ngraph/output_vector.hpp" +#include "ngraph/type.hpp" +#include "openvino/core/core_visibility.hpp" + +namespace ngraph { +class Node; +} +namespace ov { +using VariantTypeInfo = ngraph::DiscreteTypeInfo; + +class OPENVINO_API Variant { +public: + virtual ~Variant(); + virtual const VariantTypeInfo& get_type_info() const = 0; + + virtual bool is_copyable() const; + virtual std::shared_ptr init(const std::shared_ptr& node); + virtual std::shared_ptr merge(const ngraph::NodeVector& nodes); + virtual std::string to_string() { + return ""; + } +}; + +template +class VariantImpl : public Variant { +public: + using value_type = VT; + + VariantImpl(const value_type& value) : m_value(value) {} + + const value_type& get() const { + return m_value; + } + value_type& get() { + return m_value; + } + void set(const value_type& value) { + m_value = value; + } + +protected: + value_type m_value; +}; + +extern template class OPENVINO_API VariantImpl; +extern template class OPENVINO_API VariantImpl; + +template +class VariantWrapper {}; + +template <> +class OPENVINO_API VariantWrapper : public VariantImpl { +public: + static constexpr VariantTypeInfo type_info{"Variant::std::string", 0}; + const VariantTypeInfo& get_type_info() const override { + return type_info; + } + VariantWrapper(const value_type& value) : VariantImpl(value) {} +}; + +template <> +class OPENVINO_API VariantWrapper : public VariantImpl { +public: + static constexpr VariantTypeInfo type_info{"Variant::int64_t", 0}; + const VariantTypeInfo& get_type_info() const override { + return type_info; + } + VariantWrapper(const value_type& value) : VariantImpl(value) {} +}; + +template +inline std::shared_ptr make_variant(const T& p) { + return std::dynamic_pointer_cast>(std::make_shared>(p)); +} + +template +inline std::shared_ptr make_variant(const char (&s)[N]) { + return std::dynamic_pointer_cast>(std::make_shared>(s)); +} + +#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) +template +inline std::shared_ptr make_variant(const wchar_t (&s)[N]) { + return std::dynamic_pointer_cast>(std::make_shared>(s)); +} +#endif + +using RTMap = std::map>; +} // namespace ov diff --git a/ngraph/core/include/openvino/core/visibility.hpp b/ngraph/core/include/openvino/core/visibility.hpp new file mode 100644 index 00000000000000..44cd9f4001e91d --- /dev/null +++ b/ngraph/core/include/openvino/core/visibility.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +// https://gcc.gnu.org/wiki/Visibility +// Generic helper definitions for shared library support +#if defined _WIN32 || defined __CYGWIN__ +# define CORE_HELPER_DLL_IMPORT __declspec(dllimport) +# define CORE_HELPER_DLL_EXPORT __declspec(dllexport) +# define CORE_HELPER_DLL_LOCAL +#elif defined(__GNUC__) && __GNUC__ >= 4 +# define CORE_HELPER_DLL_IMPORT __attribute__((visibility("default"))) +# define CORE_HELPER_DLL_EXPORT __attribute__((visibility("default"))) +# define CORE_HELPER_DLL_LOCAL __attribute__((visibility("hidden"))) +#else +# define CORE_HELPER_DLL_IMPORT +# define CORE_HELPER_DLL_EXPORT +# define CORE_HELPER_DLL_LOCAL +#endif diff --git a/ngraph/core/src/attribute_visitor.cpp b/ngraph/core/src/attribute_visitor.cpp index a5a62a38ff70fe..9beec812c2bae0 100644 --- a/ngraph/core/src/attribute_visitor.cpp +++ b/ngraph/core/src/attribute_visitor.cpp @@ -5,6 +5,7 @@ #include "ngraph/attribute_visitor.hpp" #include "ngraph/attribute_adapter.hpp" +#include "ngraph/function.hpp" #include "ngraph/node.hpp" using namespace std; diff --git a/ngraph/frontend/frontend_manager/include/frontend_manager/frontend_manager.hpp b/ngraph/frontend/frontend_manager/include/frontend_manager/frontend_manager.hpp index 3d406b6e3ecab7..5cc181935efb74 100644 --- a/ngraph/frontend/frontend_manager/include/frontend_manager/frontend_manager.hpp +++ b/ngraph/frontend/frontend_manager/include/frontend_manager/frontend_manager.hpp @@ -93,6 +93,9 @@ struct FrontEndPluginInfo { }; } // namespace frontend +} // namespace ngraph + +namespace ov { template <> class FRONTEND_API VariantWrapper : public VariantImpl { @@ -116,4 +119,4 @@ class FRONTEND_API VariantWrapper : public VariantImpl::type_info; \ template class ngraph::VariantImpl; -namespace ngraph { +namespace ov { NGRAPH_VARIANT_DEFINITION(int32_t) NGRAPH_VARIANT_DEFINITION(std::vector) NGRAPH_VARIANT_DEFINITION(float) @@ -16,5 +16,4 @@ NGRAPH_VARIANT_DEFINITION(std::vector) NGRAPH_VARIANT_DEFINITION(bool) NGRAPH_VARIANT_DEFINITION(ngraph::element::Type) NGRAPH_VARIANT_DEFINITION(std::vector) - -} // namespace ngraph \ No newline at end of file +} // namespace ov diff --git a/ngraph/frontend/paddlepaddle/src/node_context.hpp b/ngraph/frontend/paddlepaddle/src/node_context.hpp index ef079ea4f1e3f1..cc1adc8cc67a51 100644 --- a/ngraph/frontend/paddlepaddle/src/node_context.hpp +++ b/ngraph/frontend/paddlepaddle/src/node_context.hpp @@ -18,7 +18,7 @@ VariantWrapper(const value_type& value) : VariantImpl(value) {} \ } -namespace ngraph { +namespace ov { NGRAPH_VARIANT_DECLARATION(int32_t, "Variant::int32"); NGRAPH_VARIANT_DECLARATION(std::vector, "Variant::int32_vector"); NGRAPH_VARIANT_DECLARATION(float, "Variant::float"); @@ -26,7 +26,9 @@ NGRAPH_VARIANT_DECLARATION(std::vector, "Variant::float_vector"); NGRAPH_VARIANT_DECLARATION(bool, "Variant::bool"); NGRAPH_VARIANT_DECLARATION(ngraph::element::Type, "Variant::element_type"); NGRAPH_VARIANT_DECLARATION(std::vector, "Variant::int64_vector"); +} // namespace ov +namespace ngraph { namespace frontend { namespace pdpd { using InPortName = std::string; diff --git a/ngraph/python/src/pyngraph/dict_attribute_visitor.hpp b/ngraph/python/src/pyngraph/dict_attribute_visitor.hpp index 7905ff2eeb0954..aa94e692a7f1e9 100644 --- a/ngraph/python/src/pyngraph/dict_attribute_visitor.hpp +++ b/ngraph/python/src/pyngraph/dict_attribute_visitor.hpp @@ -9,6 +9,7 @@ #include #include "ngraph/attribute_visitor.hpp" +#include "ngraph/function.hpp" #include "ngraph/node.hpp" #include "ngraph/op/util/variable.hpp" @@ -127,4 +128,4 @@ namespace util protected: py::dict m_attributes; }; -} +} // namespace util diff --git a/ngraph/test/op.cpp b/ngraph/test/op.cpp index 91b89a4192b7b9..7529b586b32e5d 100644 --- a/ngraph/test/op.cpp +++ b/ngraph/test/op.cpp @@ -83,7 +83,7 @@ struct Ship { int16_t y; }; -namespace ngraph { +namespace ov { template <> class VariantWrapper : public VariantImpl { public: @@ -95,7 +95,7 @@ class VariantWrapper : public VariantImpl { }; constexpr VariantTypeInfo VariantWrapper::type_info; -} // namespace ngraph +} // namespace ov TEST(op, variant) { shared_ptr var_std_string = make_variant("My string"); diff --git a/ngraph/test/util/test_tools.hpp b/ngraph/test/util/test_tools.hpp index 67d1eb6df078c7..6f1260717d56a8 100644 --- a/ngraph/test/util/test_tools.hpp +++ b/ngraph/test/util/test_tools.hpp @@ -25,7 +25,6 @@ namespace ngraph { class Node; - class Function; class TestOpMultiOut : public op::Op { public: @@ -53,7 +52,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; -} +} // namespace ngraph bool validate_list(const std::vector>& nodes); std::shared_ptr make_test_graph(); From 2ef0bf7037e78270df1391383b847abee596045b Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Tue, 17 Aug 2021 16:51:15 +0300 Subject: [PATCH 008/102] [LPT] LP Transformations refactoring after dynamic shapes support (#6950) * [LPT] Transformations refactoring after dynamic shapes support * [LPT] ReshapeTransformation: 2D->2D fix * [LPT] fixes after review --- .../include/low_precision/network_helper.hpp | 2 +- .../src/convolution.cpp | 51 ++++++------ .../src/convolution_backprop_data.cpp | 34 ++++---- .../src/fake_quantize.cpp | 28 ++++--- .../src/fake_quantize_dequantization.cpp | 4 +- .../src/fuse_fake_quantize.cpp | 35 +++++--- .../src/mat_mul.cpp | 11 ++- .../src/multiply_to_group_convolution.cpp | 10 +-- .../src/network_helper.cpp | 35 +++++--- .../src/normalize_l2.cpp | 6 +- .../src/transpose.cpp | 69 +++++++--------- .../src/weightable_layer_transformation.cpp | 82 ++++++++++--------- .../fuse_fake_quantize_transformation.cpp | 6 +- ...ltiply_to_fake_quantize_transformation.cpp | 32 +------- ...btract_to_fake_quantize_transformation.cpp | 34 +------- 15 files changed, 204 insertions(+), 235 deletions(-) diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/network_helper.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/network_helper.hpp index 3229c9814f0bb3..93c80161deb4fd 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/network_helper.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/network_helper.hpp @@ -131,7 +131,7 @@ class LP_TRANSFORMATIONS_API NetworkHelper { const float dequantizationMul, const float dequantizationSub, const ngraph::element::Type originalPrecision, - const ngraph::PartialShape dataNodeOutputShape, + const ngraph::PartialShape& dataNodeOutputShape, element::Type precision, const element::Type deqPrecision = element::f32, std::shared_ptr input = nullptr); diff --git a/inference-engine/src/low_precision_transformations/src/convolution.cpp b/inference-engine/src/low_precision_transformations/src/convolution.cpp index 889315678e9704..cb05b00d141b1e 100644 --- a/inference-engine/src/low_precision_transformations/src/convolution.cpp +++ b/inference-engine/src/low_precision_transformations/src/convolution.cpp @@ -55,8 +55,8 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph auto convolution = m.get_match_root(); if (!canConvolutionBeTransformed(context, convolution)) { - auto weightInput = convolution->get_input_node_shared_ptr(1); - std::shared_ptr reshapeFromWeights = as_type_ptr(weightInput); + const auto weightInput = convolution->get_input_node_shared_ptr(1); + const auto reshapeFromWeights = as_type_ptr(weightInput); FakeQuantizeDequantization dequantization = reshapeFromWeights == nullptr ? NetworkHelper::getDequantization(convolution, 1ul) : NetworkHelper::getDequantization(reshapeFromWeights); @@ -69,7 +69,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph reshapeFromWeights->input_value(1), false); } - if (as_type_ptr(resultConstant)) { + if (is_type(resultConstant)) { replace_node(weightInput, resultConstant); } } else { @@ -84,10 +84,9 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph { std::shared_ptr subtract; if (dequantization.subtract != nullptr) { - std::shared_ptr layer = dequantization.subtract; - ngraph::pass::low_precision::NetworkHelper::cleanRunTimeInfo(layer); - + NetworkHelper::cleanRunTimeInfo(dequantization.subtract->shared_from_this()); auto optimizedSubtract = NetworkHelper::optimizeSubtract(dequantization.subtract); + if (optimizedSubtract == nullptr) { optimizedSubtract = dequantization.subtract; } @@ -99,7 +98,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph size_t length = subtract->get_output_partial_shape(0).rank().get_length(); // Insert explicit broadcast for channel dimension [1] and immediately fold it - Shape broadcastShape(subtract->get_output_partial_shape(0).rank().get_length(), 1); + Shape broadcastShape(length, 1); broadcastShape[1] = subtract->get_output_partial_shape(0)[1].get_length(); std::shared_ptr newShift = fold( @@ -122,11 +121,9 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph const size_t groupsCount = NetworkHelper::getGroupsCount(convolution); std::shared_ptr newMultiplyAfterConst; if (groupsCount > 1ul) { - std::shared_ptr multiplyConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); - - const std::vector scales = multiplyConst->cast_vector(); + const std::vector scales = dequantization.multiplyConstant->cast_vector(); if (scales.size() == 1ul) { - newMultiplyAfterConst = dequantization.multiply->input_value(1).get_node_shared_ptr()->clone_with_new_inputs({}); + newMultiplyAfterConst = dequantization.multiplyConstant->clone_with_new_inputs({}); } else { const ngraph::PartialShape inputPShape = convolution->get_input_partial_shape(0); const size_t inputChannelsInGroup = inputPShape[1].get_length() / groupsCount; @@ -150,17 +147,15 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph } newMultiplyAfterConst = std::make_shared( - dequantization.multiply->get_input_element_type(1), + dequantization.multiplyConstant->get_element_type(), newMulShape, outputScales); } } else { - std::shared_ptr reducedConstant = as_type_ptr( - dequantization.multiply->input_value(1).get_node_shared_ptr()); newMultiplyAfterConst = std::make_shared( - reducedConstant->get_output_element_type(0), + dequantization.multiplyConstant->get_element_type(), Shape{ 1 }, - reducedConstant->cast_vector()[0]); + dequantization.multiplyConstant->cast_vector()[0]); } const auto copyNode = convolution->clone_with_new_inputs({ dequantization.multiply->input_value(0), convolution->input_value(1) }); @@ -190,7 +185,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph if (is_type(convolution->get_input_node_ptr(0))) { auto newConvolution = convolution->clone_with_new_inputs({ - convolution->get_input_node_ptr(0)->get_input_source_output(0), + convolution->get_input_node_ptr(0)->input_value(0), convolution->input_value(1)}); replace_node(convolution, newConvolution); NetworkHelper::copyInfo(convolution, newConvolution); @@ -206,7 +201,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph return false; } - std::shared_ptr reshapeFromWeights = as_type_ptr(convolution->input_value(1).get_node_shared_ptr()); + std::shared_ptr reshapeFromWeights = as_type_ptr(convolution->get_input_node_shared_ptr(1)); dequantization = reshapeFromWeights == nullptr ? NetworkHelper::getDequantization(convolution, 1ul) : @@ -221,12 +216,15 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph std::shared_ptr multiplyFromWeights = as_type_ptr( reshapeFromWeights == nullptr ? - convolution->input_value(1).get_node_shared_ptr() : + convolution->get_input_node_shared_ptr(1) : convolution->get_input_node_ptr(1)->get_input_node_shared_ptr(0)); std::shared_ptr subtractFromWeights = as_type_ptr(multiplyFromWeights->get_input_node_shared_ptr(0)); { - Shape newScaleShape = multiplyFromWeights->get_input_shape(1); + const auto newScalePShape = multiplyFromWeights->get_input_partial_shape(1); + assert(newScalePShape.is_static()); + Shape newScaleShape = newScalePShape.to_shape(); + if (!newScaleShape.empty()) { // that's all we need: [C, 1, 1, 1] => [C, 1, 1] newScaleShape.pop_back(); @@ -268,9 +266,12 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph } else { subtractFromWeights = as_type_ptr(optimizedSubtract); - const Shape weightsShape = subtractFromWeights->input(0).get_shape(); - Shape zeroPointShape(weightsShape.size(), 1ul); - zeroPointShape[0] = weightsShape[0]; + const auto weightsPShape = subtractFromWeights->get_input_partial_shape(0); + assert(weightsPShape.is_static()); + + const size_t weightsRankValue = weightsPShape.rank().get_length(); + Shape zeroPointShape(weightsRankValue, 1ul); + zeroPointShape[0] = static_cast(weightsPShape[0].get_length()); auto zeroPointConstant = fold( subtractFromWeights->input_value(1), @@ -288,7 +289,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph std::shared_ptr childNode = reshapeFromWeights == nullptr ? convolution : reshapeFromWeights; auto newConvolution = convolution->clone_with_new_inputs({ - convolution->get_input_source_output(0), + convolution->input_value(0), childNode.get() == convolution.get() ? convolution->get_input_node_ptr(1)->input_value(0) : childNode->copy_with_new_inputs({convertFromWeights->input_value(0), childNode->input_value(1)})}); @@ -311,7 +312,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph std::shared_ptr finalDequantization = NetworkHelper::optimizeMultipliesAfter( convolution->output(0).get_target_inputs().begin()->get_node()->shared_from_this()); - ngraph::copy_runtime_info({ convolution, finalDequantization }, finalDequantization); + copy_runtime_info({ convolution, finalDequantization }, finalDequantization); updateOutput(context, finalDequantization, convolution); // [C, 1, 1] -> [1, C, 1, 1] diff --git a/inference-engine/src/low_precision_transformations/src/convolution_backprop_data.cpp b/inference-engine/src/low_precision_transformations/src/convolution_backprop_data.cpp index 54e010d3a84a7b..680ed16eb1759b 100644 --- a/inference-engine/src/low_precision_transformations/src/convolution_backprop_data.cpp +++ b/inference-engine/src/low_precision_transformations/src/convolution_backprop_data.cpp @@ -87,7 +87,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con reshapeFromWeights->input_value(1), false); } - if (as_type_ptr(resultConstant)) { + if (is_type(resultConstant)) { replace_node(weightsInput, resultConstant); } } else { @@ -100,16 +100,14 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(convolutionBackpropData); { if (dequantization.subtract != nullptr) { - std::shared_ptr layer = dequantization.subtract; - ngraph::pass::low_precision::NetworkHelper::cleanRunTimeInfo(layer); - + NetworkHelper::cleanRunTimeInfo(dequantization.subtract->shared_from_this()); NetworkHelper::optimizeSubtract(dequantization.subtract); } - std::shared_ptr reducedConstant = as_type_ptr(dequantization.multiplyConstant); + std::shared_ptr newMultiplyAfterConst = std::make_shared( - reducedConstant->get_output_element_type(0), - Shape{ 1 }, - reducedConstant->cast_vector()[0]); + dequantization.multiplyConstant->get_element_type(), + Shape{ 1 }, + dequantization.multiplyConstant->cast_vector()[0]); auto inputs = convolutionBackpropData->input_values(); inputs[0] = dequantization.multiply->input_value(0); const auto copyNode = convolutionBackpropData->copy_with_new_inputs(inputs); @@ -126,7 +124,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con ngraph::op::TemporaryReplaceOutputType(newMultiplyAfterConst, deqPrecision).get()); replace_node(convolutionBackpropData, newMultiplyAfter); - convolutionBackpropData = newMultiplyAfter->input_value(0).get_node_shared_ptr(); + convolutionBackpropData = newMultiplyAfter->get_input_node_shared_ptr(0); inputs[0] = convolutionBackpropData->get_input_node_ptr(0)->input_value(0); if (is_type(convolutionBackpropData->get_input_node_ptr(0))) { auto newConvolution = convolutionBackpropData->copy_with_new_inputs(inputs); @@ -137,7 +135,6 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con { decomposeFakeQuantizeForWeightsPath(convolutionBackpropData, 1ul); - dequantization = NetworkHelper::getDequantization(convolutionBackpropData, 1ul); if (is_type(dequantization.data.get_node())) { @@ -152,7 +149,10 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con std::shared_ptr subtractFromWeights = as_type_ptr(multiplyFromWeights->get_input_node_shared_ptr(0)); { - Shape newScaleShape = multiplyFromWeights->get_input_shape(1); + const auto newScalePShape = multiplyFromWeights->get_input_partial_shape(1); + assert(newScalePShape.is_static()); + Shape newScaleShape = newScalePShape.to_shape(); + auto inputs = convolutionBackpropData->input_values(); inputs[1] = multiplyFromWeights->input_value(0); auto newMultiplyAfter = std::make_shared( @@ -164,7 +164,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con false), convolutionBackpropData->get_output_element_type(0))); replace_node(convolutionBackpropData, newMultiplyAfter); - convolutionBackpropData = newMultiplyAfter->input_value(0).get_node_shared_ptr(); + convolutionBackpropData = newMultiplyAfter->get_input_node_shared_ptr(0); } if (subtractFromWeights != nullptr) { @@ -175,9 +175,12 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con } else { subtractFromWeights = as_type_ptr(optimizedSubtract); - const Shape weightsShape = subtractFromWeights->input(0).get_shape(); - Shape zeroPointShape(weightsShape.size(), 1ul); - zeroPointShape[1] = weightsShape[1]; + const auto weightsPShape = subtractFromWeights->get_input_partial_shape(0); + assert(weightsPShape.is_static()); + + const size_t weightsRankValue = weightsPShape.rank().get_length(); + Shape zeroPointShape(weightsRankValue, 1ul); + zeroPointShape[1] = static_cast(weightsPShape[1].get_length()); auto zeroPointConstant = fold( subtractFromWeights->get_input_node_shared_ptr(1), @@ -215,7 +218,6 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con rt["DISABLED_CONSTANT_FOLDING"] = std::make_shared>(""); } - return true; } diff --git a/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp index 93e6aa813c1cbb..405e8fca87a9d9 100644 --- a/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp @@ -56,8 +56,10 @@ bool FakeQuantizeTransformation::transform(TransformationContext& context, ngrap namespace fq { static std::shared_ptr updateShape(std::shared_ptr constantOp, const PartialShape& targetShape) { + assert(constantOp->get_output_partial_shape(0).is_static()); const Shape shape = constantOp->get_output_shape(0); - if ((shape.size() < static_cast(targetShape.rank().get_length())) && (shape.size() > 1ul)) { + + if ((shape.size() > 1ul) && (shape.size() < static_cast(targetShape.rank().get_length()))) { constantOp = fold( constantOp, std::make_shared(ngraph::element::i32, Shape{ 1 }, std::vector({ 0ul }))); @@ -93,19 +95,19 @@ static std::shared_ptr getConstant(const std::shared_ptr } // namespace fq bool FakeQuantizeTransformation::checkElementwise(const std::shared_ptr& eltwise) { - const auto eltwiseInputPShape = eltwise->get_input_partial_shape(0); - const auto eltwiseOutputPShape = eltwise->get_output_partial_shape(0); - if (eltwiseInputPShape != eltwiseOutputPShape || eltwiseInputPShape.rank().is_dynamic() || eltwiseOutputPShape.rank().is_dynamic()) { - return false; - } - - std::shared_ptr constant = fq::getConstant(eltwise); + const std::shared_ptr constant = fq::getConstant(eltwise); if (constant == nullptr) { return false; } - Shape shape = constant->get_output_shape(0); - if ((!shape.empty()) && (shape_size(shape) != 1ul)) { + Shape shape = constant->get_shape(); + if (shape_size(shape) != 1ul) { + const auto eltwiseInputPShape = eltwise->get_input_partial_shape(0); + const auto eltwiseOutputPShape = eltwise->get_output_partial_shape(0); + if (eltwiseInputPShape != eltwiseOutputPShape || eltwiseInputPShape.rank().is_dynamic() || eltwiseOutputPShape.rank().is_dynamic()) { + return false; + } + if ((eltwiseOutputPShape.rank().get_length() - shape.size()) > 1) { return false; } @@ -179,8 +181,8 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis inputHighConst_f32 = fq::updateShape(fold(inputHighConst_f32, value), fakeQuantize->get_output_partial_shape(0)); } else if (is_type(eltwise)) { // issue #40611 - if ((eltwise->input(0).get_element_type() == element::i32) && - ((eltwise->output(0).get_element_type() == element::f16) || (eltwise->output(0).get_element_type() == element::f32))) { + if ((eltwise->get_input_element_type(0) == element::i32) && + ((eltwise->get_output_element_type(0) == element::f16) || (eltwise->get_output_element_type(0) == element::f32))) { return nullptr; } } else { @@ -190,7 +192,7 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis const auto data = fq::getData(eltwise); const size_t outputIdx = NetworkHelper::getParentOutputIndex(data, eltwise); - std::shared_ptr newFakeQuantize = as_type_ptr(fakeQuantize->clone_with_new_inputs({ + const auto newFakeQuantize = as_type_ptr(fakeQuantize->clone_with_new_inputs({ data->output(outputIdx), inputLowConst_f32, inputHighConst_f32, diff --git a/inference-engine/src/low_precision_transformations/src/fake_quantize_dequantization.cpp b/inference-engine/src/low_precision_transformations/src/fake_quantize_dequantization.cpp index 041b0009899bc6..da84ed329a7dff 100644 --- a/inference-engine/src/low_precision_transformations/src/fake_quantize_dequantization.cpp +++ b/inference-engine/src/low_precision_transformations/src/fake_quantize_dequantization.cpp @@ -90,7 +90,7 @@ bool FakeQuantizeDequantization::checkShape(const std::shared_ptr& if (!inPShape.rank().is_dynamic()) { for (int i = 0; i < inPShape.rank().get_length(); ++i) { - if (inPShape[i] != outPShape[i] && !inPShape.is_dynamic()) { + if (inPShape[i] != outPShape[i] && !inPShape[i].is_dynamic()) { return false; } } @@ -108,7 +108,7 @@ bool FakeQuantizeDequantization::checkElementwise(const std::shared_ptrget_output_shape(0); + const ngraph::Shape constShape = constant->get_shape(); if ((constShape.size() > 5ul)) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp index b15b466b4761c0..6ce7acfad3a979 100644 --- a/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp @@ -40,8 +40,12 @@ bool FuseFakeQuantizeTransformation::transform(TransformationContext& context, n namespace fuse_fq { -std::shared_ptr updateShape(std::shared_ptr op, const Shape& targetShape) { +std::shared_ptr updateShape(std::shared_ptr op, const PartialShape& targetPShape) { + assert(targetPShape.is_static()); + assert(op->get_output_partial_shape(0).is_static()); + const Shape targetShape = targetPShape.to_shape(); const Shape shape = op->get_output_shape(0); + if ((shape.size() < targetShape.size()) && (shape.size() > 1ul)) { op = fold( op, @@ -81,14 +85,19 @@ bool eltwiseWithConstant(const std::shared_ptr& eltwise) { return false; } - Shape shape = constant->get_output_shape(0); + Shape shape = constant->get_shape(); if ((!shape.empty()) && (shape_size(shape) != 1ul)) { - const Shape eltwiseShape = eltwise->get_output_shape(0); - if ((eltwiseShape.size() - shape.size()) > 1) { + const auto eltwisePShape = eltwise->get_output_partial_shape(0); + if (eltwisePShape.rank().is_dynamic()) { + return false; + } + + const size_t eltwiseOutRank = eltwisePShape.rank().get_length(); + if ((eltwiseOutRank - shape.size()) > 1) { return false; } - if ((eltwiseShape.size() - shape.size()) == 1ul) { + if ((eltwiseOutRank - shape.size()) == 1ul) { shape.insert(shape.begin(), 1ul); } @@ -118,22 +127,22 @@ std::shared_ptr FuseFakeQuantizeTransformation::handle( constant : foldConvert(constant, eltwise->get_output_element_type(0)); - inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_shape(0)); - inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_shape(0)); + inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_partial_shape(0)); + inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_partial_shape(0)); } else if (is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { const auto value = constant->get_output_element_type(0) == eltwise->get_output_element_type(0) ? constant : foldConvert(constant, eltwise->get_output_element_type(0)); - inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_shape(0)); - inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_shape(0)); + inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_partial_shape(0)); + inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_partial_shape(0)); } else if (is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { const auto value = constant->get_output_element_type(0) == eltwise->get_output_element_type(0) ? constant : foldConvert(constant, eltwise->get_output_element_type(0)); - inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_shape(0)); - inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_shape(0)); + inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_partial_shape(0)); + inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_partial_shape(0)); } else if (is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { if (is_type(fuse_fq::getData(eltwise)) || is_type(fuse_fq::getData(eltwise))) { @@ -144,8 +153,8 @@ std::shared_ptr FuseFakeQuantizeTransformation::handle( constant : foldConvert(constant, eltwise->get_output_element_type(0)); - inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_shape(0)); - inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_shape(0)); + inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_partial_shape(0)); + inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_partial_shape(0)); } else if (is_type(eltwise)) { // issue #40611 if ((eltwise->input(0).get_element_type() == element::i32) && (eltwise->output(0).get_element_type() == element::f32)) { diff --git a/inference-engine/src/low_precision_transformations/src/mat_mul.cpp b/inference-engine/src/low_precision_transformations/src/mat_mul.cpp index 693d0e6490e2e9..83f08fd4ed35fa 100644 --- a/inference-engine/src/low_precision_transformations/src/mat_mul.cpp +++ b/inference-engine/src/low_precision_transformations/src/mat_mul.cpp @@ -94,7 +94,10 @@ bool MatMulTransformation::transform(TransformationContext &context, ngraph::pat Shape(dequantization1.subtract->get_output_partial_shape(0).rank().get_length(), 1) : dequantization1.subtractConstant->get_shape(); - const auto weightsShape = newMatMul->get_input_shape(1); + const auto weightsPShape = newMatMul->get_input_partial_shape(1); + assert(weightsPShape.is_static()); + const auto weightsShape = weightsPShape.to_shape(); + const size_t firstWeightsIdx = matMul->get_transpose_b() ? weightsShape.size() - 1ul : weightsShape.size() - 2ul; const size_t lastDataIdx = matMul->get_transpose_a() ? broadcastShape.size() - 2 : broadcastShape.size() - 1; broadcastShape[lastDataIdx] = weightsShape[firstWeightsIdx]; @@ -118,8 +121,8 @@ bool MatMulTransformation::transform(TransformationContext &context, ngraph::pat parent = newSubtract; } - auto transpose = [](const std::shared_ptr& node) -> std::shared_ptr { - const Shape outputShape = node->get_output_shape(0); + auto transpose = [](const std::shared_ptr& node) -> std::shared_ptr { + const Shape outputShape = node->get_shape(); if (outputShape.size() < 2ul) { return node; } @@ -153,7 +156,7 @@ bool MatMulTransformation::transform(TransformationContext &context, ngraph::pat } } - const auto newMulConst = NetworkHelper::toScalarIfPossible(fold( + const auto newMulConst = NetworkHelper::toScalarIfPossible(fold( mulConst1, foldConvert(mulConst2, element::f32))); diff --git a/inference-engine/src/low_precision_transformations/src/multiply_to_group_convolution.cpp b/inference-engine/src/low_precision_transformations/src/multiply_to_group_convolution.cpp index 9b4a6147b61c07..6851a159fee4ad 100644 --- a/inference-engine/src/low_precision_transformations/src/multiply_to_group_convolution.cpp +++ b/inference-engine/src/low_precision_transformations/src/multiply_to_group_convolution.cpp @@ -164,17 +164,17 @@ bool MultiplyToGroupConvolutionTransformation::canBeTransformed(const Transforma Shape constShape; int inputIndex; - if (is_type(operation->get_input_node_shared_ptr(1))) { + if (const auto constant = as_type_ptr(operation->get_input_node_shared_ptr(1))) { inputIndex = 0; - constShape = operation->get_input_shape(1); + constShape = constant->get_shape(); if (is_type(operation->get_input_node_shared_ptr(0)) || - (is_type(operation->get_input_node_shared_ptr(0)) && + (is_type(operation->get_input_node_shared_ptr(0)) && is_type(operation->get_input_node_shared_ptr(0)->get_input_node_shared_ptr(0)))) { return false; } - } else if (is_type(operation->get_input_node_shared_ptr(0))) { + } else if (const auto constant = as_type_ptr(operation->get_input_node_shared_ptr(0))) { inputIndex = 1; - constShape = operation->get_input_shape(0); + constShape = constant->get_shape(); } else { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/network_helper.cpp b/inference-engine/src/low_precision_transformations/src/network_helper.cpp index 9a1faa02b8db4f..32c6a1ce523421 100644 --- a/inference-engine/src/low_precision_transformations/src/network_helper.cpp +++ b/inference-engine/src/low_precision_transformations/src/network_helper.cpp @@ -191,12 +191,12 @@ size_t NetworkHelper::getInputChannelsCount(std::shared_ptr layer) { } size_t NetworkHelper::getGroupsCount(std::shared_ptr layer) { - if (as_type_ptr(layer)) { + if (is_type(layer)) { return 1; - } else if (auto group_convolution = as_type_ptr(layer)) { - return layer->get_input_shape(1)[0]; // input weights for opset1::GC is in format GOI..., see the specification + } else if (is_type(layer)) { + return layer->get_input_partial_shape(1)[0].get_length(); // input weights for opset1::GC is in format GOI..., see the specification } else { - THROW_TRANSFORMATION_EXCEPTION << "Invalid layer type of " << layer->get_friendly_name() << "; expected Convolutino or GroupConvolution"; + THROW_TRANSFORMATION_EXCEPTION << "Invalid layer type of " << layer->get_friendly_name() << "; expected Convolution or GroupConvolution"; } } @@ -239,9 +239,15 @@ std::shared_ptr NetworkHelper::swapMultiplyAndAdd(std::shared_ptrget_input_node_shared_ptr(multiplyBranch == 0 ? 1 : 0); std::shared_ptr bDivA; - if (shape_size(b->get_output_shape(0)) == 1 || - shape_size(a->get_output_shape(0)) == 1 || - shape_size(b->get_output_shape(0)) == shape_size(a->get_output_shape(0))) { + const auto aPShape = a->get_output_partial_shape(0); + assert(aPShape.is_static()); + const auto aShape = aPShape.to_shape(); + + const auto bPShape = b->get_output_partial_shape(0); + assert(bPShape.is_static()); + const auto bShape = bPShape.to_shape(); + + if ((shape_size(bShape) == 1) || (shape_size(aShape) == 1) || (shape_size(bShape) == shape_size(aShape))) { // safely division to avoid NaN const std::vector bValues = as_type_ptr(b)->cast_vector(); const std::vector aValues = as_type_ptr(a)->cast_vector(); @@ -263,7 +269,7 @@ std::shared_ptr NetworkHelper::swapMultiplyAndAdd(std::shared_ptrget_output_element_type(0); bDivA = std::make_shared( aPrecision, - aBroadcasted ? b->get_output_shape(0) : a->get_output_shape(0), + aBroadcasted ? bShape : aShape, bDivAValues); } else { b = foldConvert(b, element::f32); @@ -741,9 +747,12 @@ std::shared_ptr NetworkHelper::foldFakeQuantize( auto constant = as_type_ptr(fq->get_input_node_shared_ptr(0)); if (constant) { - const bool roundValues = roundValuesWasSet ? roundValuesArg : fq->output(0).get_element_type().is_integral(); + const bool roundValues = roundValuesWasSet ? roundValuesArg : fq->get_output_element_type(0).is_integral(); + + const auto constPShape = fq->get_output_partial_shape(0); + assert(constPShape.is_static()); + const Shape constShape = constPShape.to_shape(); - Shape constShape = fq->get_output_shape(0); if (constShape.empty() || constShape.size() > 5lu) { THROW_IE_LPT_EXCEPTION(*fq) << "Unexpected dimensions count " << constShape.size(); } @@ -1124,7 +1133,7 @@ FakeQuantizeDequantization NetworkHelper::makeDequantization( const float dequantizationMul, const float dequantizationSub, const ngraph::element::Type originalPrecision, - const ngraph::PartialShape dataNodeOutputShape, + const ngraph::PartialShape& dataNodeOutputShape, element::Type precision, const ngraph::element::Type deqPrecision, std::shared_ptr input) { @@ -1774,7 +1783,9 @@ std::vector NetworkHelper::precisionIntersection( bool NetworkHelper::isFQByDynamicDimension(const std::shared_ptr& fq) { const auto pInputShape = fq->get_input_partial_shape(0); - auto olShape = fq->get_input_shape(3); + const auto olPShape = fq->get_input_partial_shape(3); + assert(olPShape.is_static()); + auto olShape = olPShape.to_shape(); if (shape_size(olShape) > 1ul) { if (pInputShape.rank().is_dynamic()) { diff --git a/inference-engine/src/low_precision_transformations/src/normalize_l2.cpp b/inference-engine/src/low_precision_transformations/src/normalize_l2.cpp index 0ec9876e309a7d..1d269094762c37 100644 --- a/inference-engine/src/low_precision_transformations/src/normalize_l2.cpp +++ b/inference-engine/src/low_precision_transformations/src/normalize_l2.cpp @@ -78,12 +78,12 @@ bool NormalizeL2Transformation::canBeTransformed(const TransformationContext& co const std::vector axesByChannels = { 1, 2, 3 }; std::vector axesValues = axes->cast_vector(); - if (!(axesValues == axesAcrossSpatial || axesValues == axesByChannels)) { + if ((axesValues != axesAcrossSpatial) && (axesValues != axesByChannels)) { return false; } - const ngraph::Shape outputShape = scalesConst->get_output_shape(0); - const size_t size = ngraph::shape_size(outputShape); + const Shape outputShape = scalesConst->get_shape(); + const size_t size = shape_size(outputShape); if (size != 1ul) { const auto channelsInterval = operation->get_output_partial_shape(0)[1]; if (channelsInterval.is_dynamic() || static_cast(channelsInterval.get_length()) != size) { diff --git a/inference-engine/src/low_precision_transformations/src/transpose.cpp b/inference-engine/src/low_precision_transformations/src/transpose.cpp index 66f29a66ec88f9..a7be7c7f6f48c7 100644 --- a/inference-engine/src/low_precision_transformations/src/transpose.cpp +++ b/inference-engine/src/low_precision_transformations/src/transpose.cpp @@ -42,47 +42,40 @@ void transposeDequantizationConstant(std::shared_ptr& transpose) { return; } - if (dequantization.multiply->get_input_node_ptr(1)->get_output_shape(0).size() > 1ul) { - auto transposeDeqConstant = []( - std::shared_ptr dequantizationConstant, - const PartialShape& transposeOutputShape, - const std::shared_ptr& transposeConstant) -> std::shared_ptr { - const auto dequantizationShape = dequantizationConstant->get_output_shape(0); - if (dequantizationShape.empty() || (dequantizationShape.size() == 1ul)) { - return nullptr; + auto transposeDeqConstant = []( + const std::shared_ptr& dequantizationConstant, + const PartialShape& transposeOutputPShape, + const std::shared_ptr& transposeConstant) -> std::shared_ptr { + const auto constantShape = dequantizationConstant->get_shape(); + if (shape_size(constantShape) == 1ul) { + return NetworkHelper::toScalar(dequantizationConstant); } - if (dequantizationShape.size() != static_cast(transposeOutputShape.rank().get_length())) { - dequantizationConstant = fold( - dequantizationConstant, - std::make_shared(element::i32, Shape{ 1 }, std::vector{0})); + assert(transposeOutputPShape.rank().is_static()); + const size_t transposeOutRank = transposeOutputPShape.rank().get_length(); + if (constantShape.size() != transposeOutRank) { + const auto unsqueezeConst = opset1::Constant::create(element::i32, Shape{ 1 }, std::vector{ 0 }); + const auto deqConstantWithBatch = fold(dequantizationConstant, unsqueezeConst); + return fold(deqConstantWithBatch, transposeConstant); + } else { + return fold(dequantizationConstant, transposeConstant); } - return fold(dequantizationConstant, transposeConstant); - }; - - if (dequantization.subtract != nullptr) { - auto constant = transposeDeqConstant( - dequantization.subtractConstant, - transpose->get_output_partial_shape(0), - transpose->get_input_node_shared_ptr(1)); - if (constant != nullptr) { - replace_node( - dequantization.subtract->get_input_node_shared_ptr(1), - constant); - } - } + }; - if (dequantization.multiply != nullptr) { - auto constant = transposeDeqConstant( - dequantization.multiplyConstant, - transpose->get_output_partial_shape(0), - transpose->get_input_node_shared_ptr(1)); - if (constant != nullptr) { - replace_node( - dequantization.multiply->get_input_node_shared_ptr(1), - constant); - } - } + if (dequantization.subtract != nullptr) { + const auto constant = transposeDeqConstant( + dequantization.subtractConstant, + transpose->get_output_partial_shape(0), + transpose->get_input_node_shared_ptr(1)); + replace_node(dequantization.subtractConstant, constant); + } + + if (dequantization.multiply != nullptr) { + const auto constant = transposeDeqConstant( + dequantization.multiplyConstant, + transpose->get_output_partial_shape(0), + transpose->get_input_node_shared_ptr(1)); + replace_node(dequantization.multiplyConstant, constant); } } @@ -113,7 +106,7 @@ bool TransposeTransformation::canBeTransformed(const TransformationContext& cont } const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(op); - const bool isPerTensor = [&] { + const bool isPerTensor = [&] { if (dequantization.subtractConstant != nullptr) { if (!NetworkHelper::isScalarLike(dequantization.subtractConstant)) { return false; diff --git a/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp b/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp index 402327f277ad74..6649492dd55948 100644 --- a/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp +++ b/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp @@ -74,14 +74,13 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext return false; } - const std::shared_ptr multiplyConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); - const Shape multiplyConstShape = multiplyConst->get_output_shape(0); + const Shape multiplyConstShape = dequantization.multiplyConstant->get_shape(); if (!multiplyConstShape.empty() && (shape_size(multiplyConstShape) != 1ul)) { const size_t groupsCount = NetworkHelper::getGroupsCount(layer); - const ngraph::PartialShape inputPShape = layer->get_input_partial_shape(0); + const PartialShape inputPShape = layer->get_input_partial_shape(0); const size_t inputChannelsInGroup = inputPShape[1].get_length() / groupsCount; - const std::vector scales = multiplyConst->cast_vector(); + const std::vector scales = dequantization.multiplyConstant->cast_vector(); for (size_t group = 0; group < groupsCount; ++group) { for (size_t i = 0; i < inputChannelsInGroup; ++i) { if (scales[group * inputChannelsInGroup] != scales[group * inputChannelsInGroup + i]) { @@ -90,30 +89,33 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext } } - const ngraph::PartialShape outputPShape = layer->get_output_partial_shape(0); - const auto rank = outputPShape.rank().get_length(); - if ((rank != 4) && (rank != 5)) { + const PartialShape outputPShape = layer->get_output_partial_shape(0); + const auto rank = outputPShape.rank(); + if (rank.is_dynamic()) { + return false; + } + + const auto rankVal = rank.get_length(); + if ((rankVal != 4) && (rankVal != 5)) { return false; } } } else { - const std::shared_ptr multiply = as_type_ptr(layer->input_value(0).get_node_shared_ptr()); - if (multiply == nullptr) { + const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(layer); + if (dequantization.multiply == nullptr) { return false; } - // SS takes inputs [0: data, 1: scales, 2: shifts], takes scales (index = 1) - const std::shared_ptr multiplyConst = as_type_ptr(multiply->input_value(1).get_node_shared_ptr()); - if (multiplyConst == nullptr) { + if (dequantization.multiplyConstant == nullptr) { return false; } // exactly cast vector as original code has a conversion; // optimize cast: // two branches depending on real type of the constant? - const auto scalesBuffer = multiplyConst->cast_vector(); - size_t scalesBufferSize = shape_size(multiplyConst->get_output_shape(0)); - for (size_t i = 1lu; i < scalesBufferSize; ++i) { + const auto scalesBuffer = dequantization.multiplyConstant->cast_vector(); + size_t scalesBufferSize = shape_size(dequantization.multiplyConstant->get_shape()); + for (size_t i = 1ul; i < scalesBufferSize; ++i) { if (scalesBuffer[i - 1] != scalesBuffer[i]) { return false; } @@ -132,11 +134,11 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext // TODO Implement similar checks in other weightable operaitons - const std::shared_ptr reshapeFromWeights = as_type_ptr(layer->input_value(1).get_node_shared_ptr()); + const std::shared_ptr reshapeFromWeights = as_type_ptr(layer->get_input_node_shared_ptr(1)); std::shared_ptr fqFromWeights; if (reshapeFromWeights == nullptr) { - fqFromWeights = as_type_ptr(layer->input_value(1).get_node_shared_ptr()); + fqFromWeights = as_type_ptr(layer->get_input_node_shared_ptr(1)); if (fqFromWeights == nullptr) { const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(layer, 1ul); fqFromWeights = as_type_ptr(dequantization.data.get_node_shared_ptr()); @@ -154,23 +156,29 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext return false; } - const Shape constOutputShape = fqFromWeights->get_input_node_ptr(3)->get_output_shape(0); - if (fqFromWeights->get_input_node_ptr(4)->get_output_shape(0) != constOutputShape) { + const auto olPShape = fqFromWeights->get_input_partial_shape(3); + const auto ohPShape = fqFromWeights->get_input_partial_shape(4); + if (olPShape.is_dynamic() || ohPShape.is_dynamic() || olPShape != ohPShape) { return false; } - const size_t outChannelsShapeIndex = is_type(layer) ? 1ul : 0ul; - if ( - // expected, it's ok: return true - (shape_size(constOutputShape) != 1ul) && - // not expected, something wrong: return false - ((constOutputShape.size() <= outChannelsShapeIndex) || - // Check if all dimensions of scale except the output channels are all ones - (shape_size(constOutputShape) != constOutputShape[outChannelsShapeIndex]) || - ((constOutputShape[outChannelsShapeIndex] != 1ul) && - (fqFromWeights->get_output_shape(0)[outChannelsShapeIndex] != constOutputShape[outChannelsShapeIndex])))) { + + const auto fqOutPShape = fqFromWeights->get_output_partial_shape(0); + const size_t outChannelsIdx = is_type(layer) ? 1ul : 0ul; + if (fqOutPShape.rank().is_dynamic() || fqOutPShape[outChannelsIdx].is_dynamic()) { return false; } + + const Shape constShape = olPShape.to_shape(); + if (shape_size(constShape) != 1ul) { + const size_t constChannels = constShape[outChannelsIdx]; + const size_t fqOutChannels = fqOutPShape[outChannelsIdx].get_length(); + const bool constChannelsAndFqChannelsMismatched = (constChannels != 1ul) && (fqOutChannels != constChannels); + + if ((constShape.size() <= outChannelsIdx) || (shape_size(constShape) != constChannels) || constChannelsAndFqChannelsMismatched) { + return false; + } + } } else { // TODO: LPT: is it possible to share with isQuantized? const FakeQuantizeDequantization dequantizationOnWeights = reshapeFromWeights == nullptr ? @@ -180,33 +188,33 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext return false; } - const opset1::Constant* weightsData = as_type(dequantizationOnWeights.data.get_node()); + const auto weightsData = as_type_ptr(dequantizationOnWeights.data.get_node_shared_ptr()); if (weightsData == nullptr) { return false; } - const ngraph::element::Type weightsDataPrecision = weightsData->output(0).get_element_type(); + const auto weightsDataPrecision = weightsData->get_element_type(); if (!DataPrecision::isSupported(weightsDataPrecision)) { return false; } if ((dequantizationOnWeights.subtract != nullptr) && (dequantizationOnWeights.subtractConvert != nullptr)) { - const auto subtractConstantType = dequantizationOnWeights.subtractConstant->output(0).get_element_type(); + const auto subtractConstantType = dequantizationOnWeights.subtractConstant->get_element_type(); if (subtractConstantType != weightsDataPrecision) { return false; } } - const size_t outChannelsShapeIndex = is_type(layer) ? 1ul : 0ul; + const size_t outChannelsIdx = is_type(layer) ? 1ul : 0ul; if (dequantizationOnWeights.subtract) { const auto subConstShape = dequantizationOnWeights.subtractConstant->get_shape(); - if (shape_size(subConstShape) > 1ul && shape_size(subConstShape) != subConstShape[outChannelsShapeIndex]) { + if (shape_size(subConstShape) > 1ul && shape_size(subConstShape) != subConstShape[outChannelsIdx]) { return false; } } if (dequantizationOnWeights.multiply) { const auto mulConstShape = dequantizationOnWeights.multiplyConstant->get_shape(); - if (shape_size(mulConstShape) > 1ul && shape_size(mulConstShape) != mulConstShape[outChannelsShapeIndex]) { + if (shape_size(mulConstShape) > 1ul && shape_size(mulConstShape) != mulConstShape[outChannelsIdx]) { return false; } } @@ -321,7 +329,7 @@ bool WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(const st } bool WeightableLayerTransformation::isGroup(const std::shared_ptr& layer) { - if (!as_type_ptr(layer) && !as_type_ptr(layer)) { + if (!is_type(layer) && !is_type(layer)) { return false; } @@ -341,7 +349,7 @@ bool WeightableLayerTransformation::isDepthwise(const std::shared_ptr& lay } std::shared_ptr WeightableLayerTransformation::getFakeQuantizeOnWeights(const std::shared_ptr& node) { - auto fq = as_type_ptr(node->input_value(1).get_node_shared_ptr()); + auto fq = as_type_ptr(node->get_input_node_shared_ptr(1)); // TODO: temporary workaround if (fq == nullptr) { fq = as_type_ptr(node->get_input_node_ptr(1)->get_input_node_shared_ptr(0)); diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_fake_quantize_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_fake_quantize_transformation.cpp index 354e0dab7f6264..223efa27859f5e 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_fake_quantize_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_fake_quantize_transformation.cpp @@ -385,12 +385,12 @@ const std::vector testValues = { }, { element::f32, - { {127}, element::f32 }, + {}, element::f32, - { {element::f32}, { -128 }, { 0.01f } }, + { {}, {}, {} }, element::f32, element::f32, - { 256ul, {}, { 0.f }, { 2.55f }, { 0.f }, { 2.55f } } + { 256ul, {}, { -255.f }, { 0.f }, { 0.f }, { 2.55f } } } }, // negative multiply diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_multiply_to_fake_quantize_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_multiply_to_fake_quantize_transformation.cpp index 48d637370a0ff7..715ab98c921007 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_multiply_to_fake_quantize_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_multiply_to_fake_quantize_transformation.cpp @@ -176,7 +176,8 @@ INSTANTIATE_TEST_SUITE_P( namespace testValues2 { const std::vector inputShapesWithDynamicChannels = { - {Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic()} + {Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic()}, + ngraph::PartialShape::dynamic() }; const std::vector testValues = { @@ -213,33 +214,4 @@ INSTANTIATE_TEST_SUITE_P( ::testing::ValuesIn(testValues)), FuseMultiplyToFakeQuantizeTransformation::getTestCaseName); } // namespace testValues2 - -namespace testValues3 { -const std::vector inputShapesWithDynamicChannels = { - PartialShape::dynamic() -}; - -const std::vector testValues = { - { - LayerTransformation::createParamsU8I8(), - { - { 256ul, {}, { 0.f }, { 2.55f }, { 0.f }, { 255.f }, element::u8 }, - { {}, {}, { 0.5f } }, - }, - { - { 256ul, {}, { 0.f }, { 2.55f }, { 0.f }, { 255.f }, element::u8 }, - { {}, {}, { 0.5f } }, - } - }, -}; - -INSTANTIATE_TEST_SUITE_P( - smoke_LPT, - FuseMultiplyToFakeQuantizeTransformation, - ::testing::Combine( - ::testing::ValuesIn(quantizationLevels), - ::testing::ValuesIn(inputShapesWithDynamicChannels), - ::testing::ValuesIn(testValues)), - FuseMultiplyToFakeQuantizeTransformation::getTestCaseName); -} // namespace testValues3 } // namespace diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_subtract_to_fake_quantize_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_subtract_to_fake_quantize_transformation.cpp index 2af936da365720..23b2c946e862b7 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_subtract_to_fake_quantize_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/fuse_subtract_to_fake_quantize_transformation.cpp @@ -256,6 +256,7 @@ INSTANTIATE_TEST_SUITE_P( namespace testValues2 { const std::vector inputShapesWithDynamicChannels = { {Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic()}, + PartialShape::dynamic() }; const std::vector testValues = { @@ -300,37 +301,4 @@ INSTANTIATE_TEST_SUITE_P( ::testing::ValuesIn(testValues)), FuseSubtractToFakeQuantizeTransformation::getTestCaseName); } // namespace testValues2 - -namespace testValues3 { -const std::vector inputShapesWithDynamicRank = { - PartialShape::dynamic() -}; - -const std::vector testValues = { - { - LayerTransformation::createParamsU8I8(), - { - { 256ul, {}, { 0.f }, { 2.55f }, { 0.f }, { 255.f }, element::u8 }, - { {element::f32}, { 128.f }, {} }, - {}, - {} - }, - { - { 256ul, {}, { 0.f }, { 2.55f }, { 0.f }, { 255.f }, element::u8 }, - { {element::f32}, { 128.f }, {} }, - {}, - {} - } - }, -}; - -INSTANTIATE_TEST_SUITE_P( - smoke_LPT, - FuseSubtractToFakeQuantizeTransformation, - ::testing::Combine( - ::testing::ValuesIn(quantizationLevels), - ::testing::ValuesIn(inputShapesWithDynamicRank), - ::testing::ValuesIn(testValues)), - FuseSubtractToFakeQuantizeTransformation::getTestCaseName); -} // namespace testValues3 } // namespace From 3952d5a1190a6ae0d230933bc938888d86cf25f3 Mon Sep 17 00:00:00 2001 From: Sergey Shlyapnikov Date: Tue, 17 Aug 2021 18:33:25 +0300 Subject: [PATCH 009/102] [GPU] Fix ScatterNDUpdate unit tests (#7103) --- .../tests/test_cases/fusings_gpu_test.cpp | 164 ++++++++++++------ 1 file changed, 115 insertions(+), 49 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp index 00fea3995cc5a7..d683d1172862e8 100644 --- a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp +++ b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp @@ -8034,7 +8034,6 @@ struct scatter_nd_update_test_params { tensor input_shape; tensor indices_shape; tensor updates_shape; - int max_number_in_indices; int indices_rank; data_types data_type; format input_format; @@ -8044,49 +8043,49 @@ struct scatter_nd_update_test_params { size_t expected_not_fused_primitives; }; -#define CASE_SCATTER_ND_UPDATE_FP16_4D_1 {6, 1, 1, 1}, {3, 1, 1, 1}, {3, 1, 1, 1}, 6, 1, data_types::f16, format::bfyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_4D_2 {6, 6, 1, 1}, {3, 2, 1, 1}, {3, 1, 1, 1}, 6, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_4D_3 {6, 7, 8, 9}, {5, 1, 1, 1}, {5, 7, 8, 9}, 6, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_4D_4 {6, 7, 8, 9}, {5, 1, 1, 1}, {5, 7, 8, 9}, 6, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_4D_5 {6, 7, 8, 9}, {6, 2, 1, 1}, {6, 9, 1, 8}, 6, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_4D_6 {6, 7, 8, 9}, {6, 3, 1, 1}, {6, 8, 1, 1}, 6, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx - -#define CASE_SCATTER_ND_UPDATE_FP16_5D_1 {6, 7, 8, 9, 10}, {5, 1, 1, 1, 1}, {5, 7, 8, 9, 10}, 6, 1, data_types::f16, format::bfzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_5D_2 {6, 7, 8, 9, 10}, {5, 2, 1, 1, 1}, {5, 10, 1, 8, 9}, 6, 2, data_types::f16, format::bfzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_5D_3 {6, 7, 8, 9, 10}, {5, 3, 1, 1, 1}, {5, 9, 1, 1, 8}, 6, 2, data_types::f16, format::bfzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_5D_4 {6, 7, 8, 9, 10}, {5, 4, 1, 1, 1}, {5, 8, 1, 1, 1}, 6, 2, data_types::f16, format::bfzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_5D_5 {6, 7, 8, 9, 10}, {5, 5, 1, 1, 1}, {5, 1, 1, 1, 1}, 6, 2, data_types::f16, format::bfzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_5D_6 {6, 7, 8, 9, 10}, {5, 2, 1, 1, 2}, {5, 2, 8, 9, 10}, 6, 3, data_types::f16, format::bfzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_5D_7 {6, 7, 8, 9, 10}, {5, 2, 1, 1, 3}, {5, 2, 1, 8, 9}, 6, 3, data_types::f16, format::bfzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_5D_8 {6, 7, 8, 9, 10}, {5, 2, 1, 4, 3}, {5, 2, 1, 8, 3}, 6, 4, data_types::f16, format::bfzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_5D_9 {6, 7, 8, 9, 10}, {5, 2, 1, 3, 3}, {5, 2, 8, 9, 3}, 6, 4, data_types::f16, format::bfzyx, data_types::f16, format::bfyx - -#define CASE_SCATTER_ND_UPDATE_FP16_6D_1 {6, 7, 8, 9, 10, 11}, {5, 1, 1, 1}, {5, 7, 8, 9, 10, 11}, 6, 1, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_6D_2 {6, 7, 8, 9, 10, 11}, {5, 2, 1, 1}, {5, 11, 1, 8, 9, 10}, 6, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_6D_3 {6, 7, 8, 9, 10, 11}, {5, 3, 1, 1}, {5, 10, 1, 1, 8, 9}, 6, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_6D_4 {6, 7, 8, 9, 10, 11}, {5, 4, 1, 1}, {5, 9, 1, 1, 1, 8}, 6, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_6D_5 {6, 7, 8, 9, 2, 2}, {5, 5, 1, 1}, {5, 8, 1, 1, 1, 1}, 6, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP16_6D_6 {6, 7, 8, 9, 2, 2}, {5, 6, 1, 1}, {5, 1, 1, 1, 1, 1}, 6, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx - -#define CASE_SCATTER_ND_UPDATE_FP32_4D_1 {6, 1, 1, 1}, {3, 1, 1, 1}, {3, 1, 1, 1}, 6, 1, data_types::f32, format::bfyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_4D_2 {6, 6, 1, 1}, {3, 2, 1, 1}, {3, 1, 1, 1}, 6, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_4D_3 {6, 7, 8, 1}, {5, 1, 1, 1}, {5, 7, 8, 1}, 6, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_4D_4 {6, 7, 8, 9}, {5, 1, 1, 1}, {5, 7, 8, 9}, 6, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_4D_5 {6, 7, 8, 9}, {6, 2, 1, 1}, {6, 9, 1, 8}, 6, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_4D_6 {6, 7, 8, 9}, {6, 3, 1, 1}, {6, 8, 1, 1}, 6, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx - -#define CASE_SCATTER_ND_UPDATE_FP32_5D_1 {6, 7, 8, 9, 10}, {5, 1, 1, 1, 1}, {5, 7, 8, 9, 10}, 6, 1, data_types::f32, format::bfzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_5D_2 {6, 7, 8, 9, 10}, {5, 2, 1, 1, 1}, {5, 10, 1, 8, 9}, 6, 2, data_types::f32, format::bfzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_5D_3 {6, 7, 8, 9, 10}, {5, 3, 1, 1, 1}, {5, 9, 1, 1, 8}, 6, 2, data_types::f32, format::bfzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_5D_4 {6, 7, 8, 9, 10}, {5, 4, 1, 1, 1}, {5, 8, 1, 1, 1}, 6, 2, data_types::f32, format::bfzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_5D_5 {6, 7, 8, 9, 10}, {5, 5, 1, 1, 1}, {5, 1, 1, 1, 1}, 6, 2, data_types::f32, format::bfzyx, data_types::f32, format::bfyx - -#define CASE_SCATTER_ND_UPDATE_FP32_6D_1 {6, 7, 8, 9, 10, 11}, {5, 1, 1, 1}, {5, 7, 8, 9, 10, 11}, 6, 1, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_6D_2 {6, 7, 8, 9, 10, 11}, {5, 2, 1, 1}, {5, 11, 1, 8, 9, 10}, 6, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_6D_3 {6, 7, 8, 9, 10, 11}, {5, 3, 1, 1}, {5, 10, 1, 1, 8, 9}, 6, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_6D_4 {6, 7, 8, 9, 10, 11}, {5, 4, 1, 1}, {5, 9, 1, 1, 1, 8}, 6, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_6D_5 {6, 7, 8, 9, 2, 2}, {5, 5, 1, 1}, {5, 8, 1, 1, 1, 1}, 6, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx -#define CASE_SCATTER_ND_UPDATE_FP32_6D_6 {6, 7, 8, 9, 2, 2}, {5, 6, 1, 1}, {5, 1, 1, 1, 1, 1}, 6, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_4D_1 {6, 1, 1, 1}, {3, 1, 1, 1}, {3, 1, 1, 1}, 1, data_types::f16, format::bfyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_4D_2 {6, 6, 1, 1}, {3, 2, 1, 1}, {3, 1, 1, 1}, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_4D_3 {6, 7, 8, 9}, {5, 1, 1, 1}, {5, 7, 8, 9}, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_4D_4 {6, 7, 8, 9}, {5, 1, 1, 1}, {5, 7, 8, 9}, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_4D_5 {6, 7, 8, 9}, {6, 2, 1, 1}, {6, 9, 1, 8}, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_4D_6 {6, 7, 8, 9}, {6, 3, 1, 1}, {6, 8, 1, 1}, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx + +#define CASE_SCATTER_ND_UPDATE_FP16_5D_1 {6, 7, 8, 9, 10}, {5, 1, 1, 1}, {5, 7, 8, 9, 10}, 1, data_types::f16, format::bfzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_5D_2 {6, 7, 8, 9, 10}, {5, 2, 1, 1}, {5, 10, 1, 8, 9}, 2, data_types::f16, format::bfzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_5D_3 {6, 7, 8, 9, 10}, {5, 3, 1, 1}, {5, 9, 1, 1, 8}, 2, data_types::f16, format::bfzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_5D_4 {6, 7, 8, 9, 10}, {5, 4, 1, 1}, {5, 8, 1, 1, 1}, 2, data_types::f16, format::bfzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_5D_5 {6, 7, 8, 9, 10}, {5, 5, 1, 1}, {5, 1, 1, 1, 1}, 2, data_types::f16, format::bfzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_5D_6 {6, 7, 8, 9, 10}, {5, 2, 1, 2}, {5, 2, 8, 9, 10}, 3, data_types::f16, format::bfzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_5D_7 {6, 7, 8, 9, 10}, {5, 2, 1, 3}, {5, 2, 1, 8, 9}, 3, data_types::f16, format::bfzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_5D_8 {6, 7, 8, 9, 10}, {5, 2, 4, 3}, {5, 2, 1, 8, 3}, 4, data_types::f16, format::bfzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_5D_9 {6, 7, 8, 9, 10}, {5, 2, 3, 3}, {5, 2, 8, 9, 3}, 4, data_types::f16, format::bfzyx, data_types::f16, format::bfyx + +#define CASE_SCATTER_ND_UPDATE_FP16_6D_1 {6, 7, 8, 9, 10, 11}, {5, 1, 1, 1}, {5, 7, 8, 9, 10, 11}, 1, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_6D_2 {6, 7, 8, 9, 10, 11}, {5, 2, 1, 1}, {5, 11, 1, 8, 9, 10}, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_6D_3 {6, 7, 8, 9, 10, 11}, {5, 3, 1, 1}, {5, 10, 1, 1, 8, 9}, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_6D_4 {6, 7, 8, 9, 10, 11}, {5, 4, 1, 1}, {5, 9, 1, 1, 1, 8}, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_6D_5 {6, 7, 8, 9, 2, 2}, {5, 5, 1, 1}, {5, 8, 1, 1, 1, 1}, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP16_6D_6 {6, 7, 8, 9, 2, 2}, {5, 6, 1, 1}, {5, 1, 1, 1, 1, 1}, 2, data_types::f16, format::bfwzyx, data_types::f16, format::bfyx + +#define CASE_SCATTER_ND_UPDATE_FP32_4D_1 {6, 1, 1, 1}, {3, 1, 1, 1}, {3, 1, 1, 1}, 1, data_types::f32, format::bfyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_4D_2 {6, 6, 1, 1}, {3, 2, 1, 1}, {3, 1, 1, 1}, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_4D_3 {6, 7, 8, 1}, {5, 1, 1, 1}, {5, 7, 8, 1}, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_4D_4 {6, 7, 8, 9}, {5, 1, 1, 1}, {5, 7, 8, 9}, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_4D_5 {6, 7, 8, 9}, {6, 2, 1, 1}, {6, 9, 1, 8}, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_4D_6 {6, 7, 8, 9}, {6, 3, 1, 1}, {6, 8, 1, 1}, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx + +#define CASE_SCATTER_ND_UPDATE_FP32_5D_1 {6, 7, 8, 9, 10}, {5, 1, 1, 1}, {5, 7, 8, 9, 10}, 1, data_types::f32, format::bfzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_5D_2 {6, 7, 8, 9, 10}, {5, 2, 1, 1}, {5, 10, 1, 8, 9}, 2, data_types::f32, format::bfzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_5D_3 {6, 7, 8, 9, 10}, {5, 3, 1, 1}, {5, 9, 1, 1, 8}, 2, data_types::f32, format::bfzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_5D_4 {6, 7, 8, 9, 10}, {5, 4, 1, 1}, {5, 8, 1, 1, 1}, 2, data_types::f32, format::bfzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_5D_5 {6, 7, 8, 9, 10}, {5, 5, 1, 1}, {5, 1, 1, 1, 1}, 2, data_types::f32, format::bfzyx, data_types::f32, format::bfyx + +#define CASE_SCATTER_ND_UPDATE_FP32_6D_1 {6, 7, 8, 9, 10, 11}, {5, 1, 1, 1}, {5, 7, 8, 9, 10, 11}, 1, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_6D_2 {6, 7, 8, 9, 10, 11}, {5, 2, 1, 1}, {5, 11, 1, 8, 9, 10}, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_6D_3 {6, 7, 8, 9, 10, 11}, {5, 3, 1, 1}, {5, 10, 1, 1, 8, 9}, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_6D_4 {6, 7, 8, 9, 10, 11}, {5, 4, 1, 1}, {5, 9, 1, 1, 1, 8}, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_6D_5 {6, 7, 8, 9, 2, 2}, {5, 5, 1, 1}, {5, 8, 1, 1, 1, 1}, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx +#define CASE_SCATTER_ND_UPDATE_FP32_6D_6 {6, 7, 8, 9, 2, 2}, {5, 6, 1, 1}, {5, 1, 1, 1, 1, 1}, 2, data_types::f32, format::bfwzyx, data_types::f32, format::bfyx class ScatterNDUpdatePrimitiveFusingTest : public ::BaseFusingTest { public: @@ -8104,7 +8103,7 @@ class ScatterNDUpdatePrimitiveFusingTest : public ::BaseFusingTest + T generate_random_val(int min, int max, int k = 8) { + static std::default_random_engine generator(random_seed); + // 1/k is the resolution of the floating point numbers + std::uniform_int_distribution distribution(k * min, k * max); + T val = (T)distribution(generator); + val /= k; + + return val; + } + + template + std::vector generate_unique_indices(scatter_nd_update_test_params& p) { + std::set> unique_indices; + std::vector result; + auto indices_shape = p.indices_shape.sizes(get_default_format(p.indices_rank)); + auto last_indices_dim = indices_shape.back(); + + auto count = 1; + for (size_t i = 0; i < indices_shape.size() - 1; i++) + count *= indices_shape[i]; + + while (unique_indices.size() != count) { + std::vector indices; + for (size_t i = 0; i < last_indices_dim; i++) + indices.push_back(generate_random_val(0, indices_shape[i])); + + unique_indices.insert(indices); + } + + std::for_each(unique_indices.begin(), + unique_indices.end(), + [&](const std::vector& indices) { + result.insert(result.end(), indices.begin(), indices.end()); + }); + + return result; + } + + cldnn::memory::ptr get_indices_mem(scatter_nd_update_test_params& p) { + auto indices_layout = get_indices_layout(p); + auto prim = engine.allocate_memory(indices_layout); + if (indices_layout.data_type == data_types::f32) { + VF rnd_vec = generate_unique_indices(p); + set_values(prim, rnd_vec); + } else if (indices_layout.data_type == data_types::f16) { + VF rnd_vec = generate_unique_indices(p); + set_values(prim, rnd_vec); + } else if (indices_layout.data_type == data_types::i8) { + VF rnd_vec = generate_unique_indices(p); + set_values(prim, rnd_vec); + } else { + throw std::runtime_error("Unsupported data type for indicies of scatter_nd_update primitive"); + } + + return prim; + } }; class scatter_nd_update_quantize : public ScatterNDUpdatePrimitiveFusingTest {}; TEST_P(scatter_nd_update_quantize, basic) { auto p = GetParam(); create_topologies(input_layout("input", get_input_layout(p)), - data("scatter_nd_update_indices", get_mem(get_indices_layout(p), 0, p.max_number_in_indices)), + data("scatter_nd_update_indices", get_indices_mem(p)), data("scatter_nd_update_updates", get_mem(get_updates_layout(p), 0, 100)), data("in_lo", get_mem(get_per_channel_layout(p), min_random, 0)), data("in_hi", get_mem(get_per_channel_layout(p), 1, max_random)), @@ -8128,7 +8194,7 @@ TEST_P(scatter_nd_update_quantize, basic) { data("out_hi", get_mem(get_single_element_layout(p), 127)), scatter_nd_update("scatter_nd_update_prim", "input", "scatter_nd_update_indices", "scatter_nd_update_updates", p.indices_rank), quantize("quantize", "scatter_nd_update_prim", "in_lo", "in_hi", "out_lo", "out_hi", 255, data_types::i8), - reorder("reorder_bfyx", "quantize", p.default_format, data_types::f32) + reorder("reorder_bfyx", "quantize", p.input_format, data_types::f32) ); tolerance = 1.f; execute(p); @@ -8183,7 +8249,7 @@ class scatter_nd_update_scale_activation_eltwise : public ScatterNDUpdatePrimiti TEST_P(scatter_nd_update_scale_activation_eltwise, basic) { auto p = GetParam(); create_topologies(input_layout("input", get_input_layout(p)), - data("scatter_nd_update_indices", get_mem(get_indices_layout(p), 0, p.max_number_in_indices)), + data("scatter_nd_update_indices", get_indices_mem(p)), data("scatter_nd_update_updates", get_mem(get_updates_layout(p), 0, 100)), data("scale_data", get_mem(get_per_channel_layout(p), -1, 1)), data("eltwise_data", get_mem(layout{ p.data_type, p.input_format, p.input_shape })), @@ -8191,7 +8257,7 @@ TEST_P(scatter_nd_update_scale_activation_eltwise, basic) { activation("activation", "scatter_nd_update_prim", activation_func::abs), scale("scale", "activation", "scale_data"), eltwise("eltwise", { "scale", "eltwise_data" }, eltwise_mode::sum, p.data_type), - reorder("reorder_bfyx", "eltwise", p.default_format, data_types::f32) + reorder("reorder_bfyx", "eltwise", p.input_format, data_types::f32) ); tolerance = 1.f; From ef8933cb6895903e55ae28596030244ebbbae031 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Wed, 18 Aug 2021 07:35:32 +0300 Subject: [PATCH 010/102] Deprecate ngraph file utils. Need to have common functions (#7105) --- .../common_test_utils/file_utils.cpp | 1 + .../frontends/onnx_import/onnx_importer_test.cpp | 2 ++ ngraph/core/include/ngraph/file_util.hpp | 15 ++++++++++++++- ngraph/core/src/file_util.cpp | 2 ++ ngraph/core/src/pass/visualize_tree.cpp | 2 ++ .../frontend_manager/src/plugin_loader.cpp | 2 ++ .../frontend/onnx/frontend/src/core/transform.cpp | 2 ++ .../frontend/src/utils/tensor_external_data.cpp | 2 ++ ngraph/test/file_util.cpp | 2 ++ ngraph/test/frontend/frontend_manager.cpp | 2 ++ ngraph/test/frontend/shared/include/utils.hpp | 4 +++- ngraph/test/onnx/onnx_import_const_folding.in.cpp | 2 ++ ngraph/test/onnx/onnx_import_exceptions.cpp | 2 ++ ngraph/test/onnx/onnx_import_provenance.in.cpp | 2 ++ ngraph/test/runtime/backend.cpp | 2 ++ ngraph/test/runtime/backend_manager.cpp | 2 ++ ngraph/test/util/test_case.hpp | 6 ++++++ 17 files changed, 50 insertions(+), 2 deletions(-) diff --git a/inference-engine/tests/ie_test_utils/common_test_utils/file_utils.cpp b/inference-engine/tests/ie_test_utils/common_test_utils/file_utils.cpp index decb88d6e1b8c3..a272a97741a45d 100644 --- a/inference-engine/tests/ie_test_utils/common_test_utils/file_utils.cpp +++ b/inference-engine/tests/ie_test_utils/common_test_utils/file_utils.cpp @@ -20,6 +20,7 @@ # include #endif +NGRAPH_SUPPRESS_DEPRECATED_START namespace CommonTestUtils { std::string getExecutableDirectory() { diff --git a/inference-engine/tests/unit/frontends/onnx_import/onnx_importer_test.cpp b/inference-engine/tests/unit/frontends/onnx_import/onnx_importer_test.cpp index 6c7fa1aeda5195..a86ded8b8d4996 100644 --- a/inference-engine/tests/unit/frontends/onnx_import/onnx_importer_test.cpp +++ b/inference-engine/tests/unit/frontends/onnx_import/onnx_importer_test.cpp @@ -11,6 +11,8 @@ #include "ngraph/file_util.hpp" #include "onnx_import/onnx.hpp" +NGRAPH_SUPPRESS_DEPRECATED_START + TEST(ONNX_Importer_Tests, ImportBasicModel) { auto model_file_path = CommonTestUtils::getModelFromTestModelZoo( ngraph::file_util::path_join(ONNX_MODELS_DIR, "add_abc_initializers.onnx")); diff --git a/ngraph/core/include/ngraph/file_util.hpp b/ngraph/core/include/ngraph/file_util.hpp index 8199edd3bd7c12..32626b8973e40f 100644 --- a/ngraph/core/include/ngraph/file_util.hpp +++ b/ngraph/core/include/ngraph/file_util.hpp @@ -5,34 +5,42 @@ #pragma once #include -#include #include #include +#include "ngraph/deprecated.hpp" +#include "ngraph/ngraph_visibility.hpp" + namespace ngraph { namespace file_util { /// \brief Returns the name with extension for a given path /// \param path The path to the output file +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::string get_file_name(const std::string& path); /// \brief Returns the file extension /// \param path The path to the output file +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::string get_file_ext(const std::string& path); /// \brief Returns the directory portion of the given path /// \param path The path to the output file +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::string get_directory(const std::string& path); /// \brief Joins multiple paths into a single path /// \param s1 Left side of path /// \param s2 Right side of path +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::string path_join(const std::string& s1, const std::string& s2); +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::string path_join(const std::string& s1, const std::string& s2, const std::string& s3); +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::string path_join(const std::string& s1, const std::string& s2, const std::string& s3, const std::string& s4); @@ -40,6 +48,7 @@ std::string path_join(const std::string& s1, const std::string& s2, const std::s /// \param path The path to iterate over /// \param func A callback function called with each file or directory encountered /// \param recurse Optional parameter to enable recursing through path +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API void iterate_files(const std::string& path, std::function func, @@ -48,21 +57,25 @@ void iterate_files(const std::string& path, /// \brief Change Linux-style path ('/') to Windows-style ('\\') /// \param path The path to change file separator +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API void convert_path_win_style(std::string& path); /// \brief Conversion from wide character string to a single-byte chain. /// \param wstr A wide-char string /// \return A multi-byte string +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::string wstring_to_string(const std::wstring& wstr); /// \brief Conversion from single-byte chain to wide character string. /// \param str A null-terminated string /// \return A wide-char string +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::wstring multi_byte_char_to_wstring(const char* str); /// \brief Remove path components which would allow traversing up a directory tree. /// \param path A path to file /// \return A sanitiazed path +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") NGRAPH_API std::string sanitize_path(const std::string& path); } // namespace file_util } // namespace ngraph diff --git a/ngraph/core/src/file_util.cpp b/ngraph/core/src/file_util.cpp index bbc12740c5637c..827226d5345cdf 100644 --- a/ngraph/core/src/file_util.cpp +++ b/ngraph/core/src/file_util.cpp @@ -42,6 +42,8 @@ # endif #endif +NGRAPH_SUPPRESS_DEPRECATED_START + using namespace std; using namespace ngraph; diff --git a/ngraph/core/src/pass/visualize_tree.cpp b/ngraph/core/src/pass/visualize_tree.cpp index b2235654659562..ae0f30ba2d1b5d 100644 --- a/ngraph/core/src/pass/visualize_tree.cpp +++ b/ngraph/core/src/pass/visualize_tree.cpp @@ -511,6 +511,7 @@ string pass::VisualizeTree::get_node_name(shared_ptr node) { } void pass::VisualizeTree::render() const { + NGRAPH_SUPPRESS_DEPRECATED_START string ext = file_util::get_file_ext(m_name); string output_format = ext.substr(1); string dot_file = m_name; @@ -536,4 +537,5 @@ void pass::VisualizeTree::render() const { #endif } } + NGRAPH_SUPPRESS_DEPRECATED_END } diff --git a/ngraph/frontend/frontend_manager/src/plugin_loader.cpp b/ngraph/frontend/frontend_manager/src/plugin_loader.cpp index f910b31610fc25..36100e898822b4 100644 --- a/ngraph/frontend/frontend_manager/src/plugin_loader.cpp +++ b/ngraph/frontend/frontend_manager/src/plugin_loader.cpp @@ -37,6 +37,7 @@ using namespace ngraph::frontend; // TODO: change to std::filesystem for C++17 static std::vector list_files(const std::string& path) { + NGRAPH_SUPPRESS_DEPRECATED_START std::vector res; try { ngraph::file_util::iterate_files( @@ -61,6 +62,7 @@ static std::vector list_files(const std::string& path) { // Ignore exceptions } return res; + NGRAPH_SUPPRESS_DEPRECATED_END } std::vector ngraph::frontend::load_plugins(const std::string& dir_name) { diff --git a/ngraph/frontend/onnx/frontend/src/core/transform.cpp b/ngraph/frontend/onnx/frontend/src/core/transform.cpp index 141e7d3d6c0ada..758216fed4abc7 100644 --- a/ngraph/frontend/onnx/frontend/src/core/transform.cpp +++ b/ngraph/frontend/onnx/frontend/src/core/transform.cpp @@ -56,6 +56,7 @@ void ngraph::onnx_import::transform::expand_onnx_functions(ONNX_NAMESPACE::Model void ngraph::onnx_import::transform::update_external_data_paths(ONNX_NAMESPACE::ModelProto& model_proto, const std::string& model_path) { + NGRAPH_SUPPRESS_DEPRECATED_START if (model_path.empty()) { return; } @@ -78,6 +79,7 @@ void ngraph::onnx_import::transform::update_external_data_paths(ONNX_NAMESPACE:: initializer_tensor.mutable_external_data(location_key_value_index)->set_value(external_data_full_path); } } + NGRAPH_SUPPRESS_DEPRECATED_END } void ngraph::onnx_import::transform::fixup_legacy_operators(ONNX_NAMESPACE::ModelProto& model_proto) { diff --git a/ngraph/frontend/onnx/frontend/src/utils/tensor_external_data.cpp b/ngraph/frontend/onnx/frontend/src/utils/tensor_external_data.cpp index 15e9b7ab4a4aeb..e0bc8fd33fd6f1 100644 --- a/ngraph/frontend/onnx/frontend/src/utils/tensor_external_data.cpp +++ b/ngraph/frontend/onnx/frontend/src/utils/tensor_external_data.cpp @@ -28,11 +28,13 @@ TensorExternalData::TensorExternalData(const ONNX_NAMESPACE::TensorProto& tensor } std::string TensorExternalData::load_external_data() const { + NGRAPH_SUPPRESS_DEPRECATED_START #if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) std::wstring path = file_util::multi_byte_char_to_wstring(m_data_location.c_str()); #else std::string path = m_data_location; #endif + NGRAPH_SUPPRESS_DEPRECATED_END std::ifstream external_data_stream(path, std::ios::binary | std::ios::in | std::ios::ate); if (external_data_stream.fail()) throw error::invalid_external_data{*this}; diff --git a/ngraph/test/file_util.cpp b/ngraph/test/file_util.cpp index 4b47aae404effe..99296ea8a9efbc 100644 --- a/ngraph/test/file_util.cpp +++ b/ngraph/test/file_util.cpp @@ -11,6 +11,8 @@ #include "gtest/gtest.h" +NGRAPH_SUPPRESS_DEPRECATED_START + using namespace std; using namespace ngraph; diff --git a/ngraph/test/frontend/frontend_manager.cpp b/ngraph/test/frontend/frontend_manager.cpp index ce8d8d67ed3345..5be485bd0c6e1c 100644 --- a/ngraph/test/frontend/frontend_manager.cpp +++ b/ngraph/test/frontend/frontend_manager.cpp @@ -49,6 +49,7 @@ TEST(FrontEndManagerTest, testAvailableFrontEnds) { } TEST(FrontEndManagerTest, testMockPluginFrontEnd) { + NGRAPH_SUPPRESS_DEPRECATED_START std::string fePath = ngraph::file_util::get_directory(ngraph::runtime::Backend::get_backend_shared_library_search_directory()); fePath = fePath + FrontEndPathSeparator + "someInvalidPath"; @@ -61,6 +62,7 @@ TEST(FrontEndManagerTest, testMockPluginFrontEnd) { ASSERT_NO_THROW(fe = fem.load_by_framework("mock1")); ASSERT_EQ(fe->get_name(), "mock1"); set_test_env("OV_FRONTEND_PATH", ""); + NGRAPH_SUPPRESS_DEPRECATED_END } TEST(FrontEndManagerTest, testDefaultFrontEnd) { diff --git a/ngraph/test/frontend/shared/include/utils.hpp b/ngraph/test/frontend/shared/include/utils.hpp index dc8db530f458a6..a335b0a0d97834 100644 --- a/ngraph/test/frontend/shared/include/utils.hpp +++ b/ngraph/test/frontend/shared/include/utils.hpp @@ -52,9 +52,11 @@ inline int set_test_env(const char* name, const char* value) { } inline void setupTestEnv() { + NGRAPH_SUPPRESS_DEPRECATED_START std::string fePath = ngraph::file_util::get_directory(ngraph::runtime::Backend::get_backend_shared_library_search_directory()); set_test_env("OV_FRONTEND_PATH", fePath.c_str()); + NGRAPH_SUPPRESS_DEPRECATED_END } inline bool exists(const std::string& file) { @@ -65,4 +67,4 @@ inline bool exists(const std::string& file) { inline std::string make_model_path(const std::string& modelsRelativePath) { return CommonTestUtils::getModelFromTestModelZoo(modelsRelativePath); } -} // namespace FrontEndTestUtils \ No newline at end of file +} // namespace FrontEndTestUtils diff --git a/ngraph/test/onnx/onnx_import_const_folding.in.cpp b/ngraph/test/onnx/onnx_import_const_folding.in.cpp index 3151101a046ac5..c6b9554af3fdfa 100644 --- a/ngraph/test/onnx/onnx_import_const_folding.in.cpp +++ b/ngraph/test/onnx/onnx_import_const_folding.in.cpp @@ -15,6 +15,8 @@ #include "util/test_control.hpp" #include "util/type_prop.hpp" +NGRAPH_SUPPRESS_DEPRECATED_START + using namespace ngraph; using namespace ngraph::onnx_import; diff --git a/ngraph/test/onnx/onnx_import_exceptions.cpp b/ngraph/test/onnx/onnx_import_exceptions.cpp index ee1e807eb069a1..89b821ec931700 100644 --- a/ngraph/test/onnx/onnx_import_exceptions.cpp +++ b/ngraph/test/onnx/onnx_import_exceptions.cpp @@ -11,6 +11,8 @@ #include "onnx_import/onnx.hpp" #include "util/type_prop.hpp" +NGRAPH_SUPPRESS_DEPRECATED_START + using namespace ngraph; TEST(onnx_importer, exception_throws_ngraph_error) { diff --git a/ngraph/test/onnx/onnx_import_provenance.in.cpp b/ngraph/test/onnx/onnx_import_provenance.in.cpp index 5f05b7f04a409e..10bb4f8eadc698 100644 --- a/ngraph/test/onnx/onnx_import_provenance.in.cpp +++ b/ngraph/test/onnx/onnx_import_provenance.in.cpp @@ -12,6 +12,8 @@ #include "util/test_control.hpp" #include "util/type_prop.hpp" +NGRAPH_SUPPRESS_DEPRECATED_START + using namespace ngraph; using namespace ngraph::onnx_import; diff --git a/ngraph/test/runtime/backend.cpp b/ngraph/test/runtime/backend.cpp index 588ad48f64000e..d37799ca2d6174 100644 --- a/ngraph/test/runtime/backend.cpp +++ b/ngraph/test/runtime/backend.cpp @@ -38,7 +38,9 @@ static string find_my_pathname() wstring ws(wpath); string path(ws.begin(), ws.end()); replace(path.begin(), path.end(), '\\', '/'); + NGRAPH_SUPPRESS_DEPRECATED_START path = file_util::get_directory(path); + NGRAPH_SUPPRESS_DEPRECATED_END path += "/"; return path; #elif defined(__linux) || defined(__APPLE__) diff --git a/ngraph/test/runtime/backend_manager.cpp b/ngraph/test/runtime/backend_manager.cpp index d31f22ea988805..4d674d5d53846f 100644 --- a/ngraph/test/runtime/backend_manager.cpp +++ b/ngraph/test/runtime/backend_manager.cpp @@ -18,6 +18,8 @@ #include "ngraph/file_util.hpp" #include "ngraph/util.hpp" +NGRAPH_SUPPRESS_DEPRECATED_START + using namespace std; using namespace ngraph; diff --git a/ngraph/test/util/test_case.hpp b/ngraph/test/util/test_case.hpp index e59d3ce3f82f3d..767f92e6164b5b 100644 --- a/ngraph/test/util/test_case.hpp +++ b/ngraph/test/util/test_case.hpp @@ -80,15 +80,19 @@ namespace ngraph const std::string& basepath, const std::string& filename) { + NGRAPH_SUPPRESS_DEPRECATED_START const auto filepath = ngraph::file_util::path_join(basepath, filename); add_input_from_file(shape, filepath); + NGRAPH_SUPPRESS_DEPRECATED_END } template void add_input_from_file(const std::string& basepath, const std::string& filename) { + NGRAPH_SUPPRESS_DEPRECATED_START const auto filepath = ngraph::file_util::path_join(basepath, filename); add_input_from_file(filepath); + NGRAPH_SUPPRESS_DEPRECATED_END } template @@ -144,8 +148,10 @@ namespace ngraph const std::string& basepath, const std::string& filename) { + NGRAPH_SUPPRESS_DEPRECATED_START const auto filepath = ngraph::file_util::path_join(basepath, filename); add_expected_output_from_file(expected_shape, filepath); + NGRAPH_SUPPRESS_DEPRECATED_END } template From f102c0d5992820c04af7f236d6cb00cccf4a516c Mon Sep 17 00:00:00 2001 From: Vladimir Paramuzov Date: Wed, 18 Aug 2021 09:31:04 +0300 Subject: [PATCH 011/102] [GPU] Get rid of memory alloc for input_layout in internal networks (#6897) --- .../thirdparty/clDNN/src/input_layout.cpp | 15 ++++++++++++++- .../clDNN/tests/test_cases/memory_test.cpp | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/src/input_layout.cpp b/inference-engine/thirdparty/clDNN/src/input_layout.cpp index ddc4c5470ac2e8..d7bfa069192fcd 100644 --- a/inference-engine/thirdparty/clDNN/src/input_layout.cpp +++ b/inference-engine/thirdparty/clDNN/src/input_layout.cpp @@ -12,6 +12,18 @@ #include #include +namespace { +bool has_optimized_users(input_layout_node const& node) { + for (auto& user : node.get_users()) { + if (user->can_be_optimized()) { + return true; + } + } + + return false; +} +} // namespace + namespace cldnn { primitive_type_id input_layout::type_id() { static primitive_type_base instance; @@ -23,7 +35,8 @@ input_layout_node::typed_program_node(const std::shared_ptr dprim, can_share_buffer(false); } -input_layout_inst::typed_primitive_inst(network& network, input_layout_node const& node) : parent(network, node) { +input_layout_inst::typed_primitive_inst(network& network, input_layout_node const& node) + : parent(network, node, !network.is_internal() || has_optimized_users(node)) { _has_valid_input = false; // by default input for 'input_layout' is invalid as long as user doesn't call set_data } diff --git a/inference-engine/thirdparty/clDNN/tests/test_cases/memory_test.cpp b/inference-engine/thirdparty/clDNN/tests/test_cases/memory_test.cpp index 861cd2672cd4e9..4582f2ad06340e 100644 --- a/inference-engine/thirdparty/clDNN/tests/test_cases/memory_test.cpp +++ b/inference-engine/thirdparty/clDNN/tests/test_cases/memory_test.cpp @@ -449,7 +449,7 @@ TEST(memory_pool, shared_dep_two_output) { network network(*engine, topo, bo); auto outputs = network.execute(); - EXPECT_EQ(engine->get_max_used_device_memory(), (uint64_t)256); + EXPECT_EQ(engine->get_max_used_device_memory(), (uint64_t)192); } TEST(memory_pool, non_opt_intermidate_opt_after) { From 94e6c1717cbbaba6c18e52ab3ebf3e69bda42e20 Mon Sep 17 00:00:00 2001 From: Ilya Sharikov Date: Wed, 18 Aug 2021 09:48:38 +0300 Subject: [PATCH 012/102] Renamed component name (#7110) --- thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt b/thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt index 2c9a6f7ccc6810..3618e8ae360929 100644 --- a/thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt +++ b/thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt @@ -38,4 +38,4 @@ endif() add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) install(TARGETS ${TARGET_NAME} - DESTINATION tests/sea_itt_lib COMPONENT tests EXCLUDE_FROM_ALL) + DESTINATION tests/sea_itt_lib COMPONENT itt_collector EXCLUDE_FROM_ALL) From 3b47f627d6747c9c5946f370c0a9f59a1e0056b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Karzy=C5=84ski?= Date: Wed, 18 Aug 2021 10:41:59 +0200 Subject: [PATCH 013/102] Propose new MaxPool-8 operation (#5359) --- docs/ops/pooling/MaxPool_1.md | 2 +- docs/ops/pooling/MaxPool_8.md | 360 ++++++++++++++++++++++++++++++++++ 2 files changed, 361 insertions(+), 1 deletion(-) create mode 100644 docs/ops/pooling/MaxPool_8.md diff --git a/docs/ops/pooling/MaxPool_1.md b/docs/ops/pooling/MaxPool_1.md index 182df220b5260c..9ea1be7380f05d 100644 --- a/docs/ops/pooling/MaxPool_1.md +++ b/docs/ops/pooling/MaxPool_1.md @@ -163,7 +163,7 @@ strides = [1, 1] kernel = [2, 2] rounding_type = "floor" auto_pad = "same_upper" -output = [[[[5, 5, -6], +output = [[[[5, 5, 3], [8, 9, 9] [8, 9, 9]], [[6, 5, 5], diff --git a/docs/ops/pooling/MaxPool_8.md b/docs/ops/pooling/MaxPool_8.md new file mode 100644 index 00000000000000..808b2e616fc83e --- /dev/null +++ b/docs/ops/pooling/MaxPool_8.md @@ -0,0 +1,360 @@ +## MaxPool {#openvino_docs_ops_pooling_MaxPool_8} + +**Versioned name**: *MaxPool-8* + +**Category**: *Pooling* + +**Short description**: Performs the max pooling operation on input. + +**Detailed description**: Input shape can be either 3D, 4D, or 5D. The max pooling operation is performed with respect to input shape from the third dimension to the last dimension. If paddings are used, during the pooling calculation their values are `-inf`. The max pooling operation involves sliding a filter over each channel of a feature map and downsampling by choosing the largest value within the region covered by the filter. + +**Attributes**: *Pooling* attributes are specified in the `data` node, which is a child of the layer node. + +* *strides* + + * **Description**: *strides* is a distance (in pixels) to slide the window on the feature map over the (z, y, x) axes for 3D poolings and (y, x) axes for 2D poolings. For example, *strides* equal to "4,2,1" means sliding the window 4 pixels at a time over depth dimension, 2 over height dimension, and 1 over width dimension. + * **Range of values**: integer values starting from 0 + * **Type**: int[] + * **Required**: *yes* + +* *dilations* + + * **Description**: *dilations* specify the index of the next pixel to select when pooling. If not present, the dilation defaults to 1, meaning the adjacent pixel is chosen. A value of 2 indicates that one pixel is skipped and every other pixel is considered. Dilations specify one value for each spatial axis of the kernel: `(z, y, x)` for 3D poolings and `(y, x)` for 2D poolings. + * **Range of values**: integer values starting from 0 + * **Type**: int[] + * **Default value**: `[1,1,...]` + * **Required**: *no* + +* *pads_begin* + + * **Description**: *pads_begin* is a number of pixels to add to the beginning along each axis. For example, *pads_begin* equal to "1,2" means adding 1 pixel to the top of the input and 2 to the left of the input. All added padding values are equal to negative infinity. + * **Range of values**: integer values starting from 0 + * **Type**: int[] + * **Required**: *yes* + * **Note**: the attribute is ignored when *auto_pad* attribute is specified. + +* *pads_end* + + * **Description**: *pads_end* is a number of pixels to add to the ending along each axis. For example, *pads_end* equal to "1,2" means adding 1 pixel to the bottom of the input and 2 to the right of the input. All added padding values are equal to negative infinity. + * **Range of values**: integer values starting from 0 + * **Type**: int[] + * **Required**: *yes* + * **Note**: the attribute is ignored when the *auto_pad* attribute is specified. + +* *kernel* + + * **Description**: *kernel* is a size of each filter. For example, *kernel* equal to (2, 3) means that each filter has height equal to 2 and width equal to 3. + * **Range of values**: integer values starting from 1 + * **Type**: int[] + * **Required**: *yes* + +* *rounding_type* + + * **Description**: *rounding_type* is a type of rounding to be used to compute output shape. + * **Range of values**: + * *ceil* + * *floor* + * **Type**: string + * **Default value**: *floor* + * **Required**: *no* + +* *auto_pad* + + * **Description**: *auto_pad* how the padding is calculated. Possible values: + * *explicit*: explicit padding values from `pads_begin` and `pads_end` are used. + * *same_upper (same_lower)* the input is padded to match the output size. In case of odd padding value, an extra padding is added at the end (at the beginning). + * *valid* padding is not used. + * **Type**: string + * **Default value**: *explicit* + * **Required**: *no* + * **Note**: *pads_begin* and *pads_end* attributes are ignored when *auto_pad* is not equal to explicit. + +* *index_element_type* + + * **Description**: the type of output tensor with indices + * **Range of values**: "i64" or "i32" + * **Type**: string + * **Default value**: "i64" + * **Required**: *No* + +* *axis* + + * **Description**: indicator of the first dimension in the input shape that should be used to calculate the upper bound of allowed index output values. The upper bound is the product of dimensions starting from the one pointed by the 'axis' attribute until the end of the input shape. + * **Range of values**: integer number. Negative value means counting dimension from the end. The range is `[-R, R - 1]`, where `R` is the rank of the input tensor. + * **Type**: int + * **Default value**: 0 + * **Required**: *No* + +**Inputs**: + +* **1**: 3D, 4D, or 5D input tensor of type T. Required. + +**Outputs**: + * **1**: Input shape can be either `[N, C, H]`, `[N, C, H, W]`, or `[N, C, H, W, D]`. The corresponding output shape is `[N, C, H_out]`, `[N, C, H_out, W_out]` or `[N, C, H_out, W_out, D_out]`. Output tensor has the same data type as the input tensor. + + * **2**: Output tensor of type *T_IND* with indices of values selected by the pooling operation. + Shape of this output matches the first output. The type of this output can be specified using the `index_element_type` attribute. + Values are computed as indices in a tensor flattened to 1D, not considering padding. Examples for a 5D input tensor: + * When `axis == 0`, the values are in the range `[0, N * C * H * W * D)`. + * When `axis == 2`, the values are in the range `[0, H * W * D)`. + + Note: the values of this output can only be calculated correctly if `pads_value` is set to `-infinity`. + + +**Types** + +* *T*: floating point or integer type. + +* *T_IND*: `int64` or `int32`. + + +**Mathematical Formulation** +Output shape calculation based on `auto_pad` and `rounding_type`: + * `auto_pad = explicit` and `rounding_type = floor` + `H_out = floor((H + pads_begin[0] + pads_end[0] - ((kernel[0] - 1) * dilations[0] + 1)) / strides[0] + 1)` + `W_out = floor((W + pads_begin[1] + pads_end[1] - ((kernel[1] - 1) * dilations[1] + 1)) / strides[1] + 1)` + `D_out = floor((D + pads_begin[2] + pads_end[2] - ((kernel[2] - 1) * dilations[2] + 1)) / strides[2] + 1)` + + * `auto_pad = explicit` and `rounding_type = ceil` + `H_out = ceil((H + pads_begin[0] + pads_end[0] - ((kernel[0] - 1) * dilations[0] + 1)) / strides[0] + 1)` + `W_out = ceil((W + pads_begin[1] + pads_end[1] - ((kernel[1] - 1) * dilations[1] + 1)) / strides[1] + 1)` + `D_out = ceil((D + pads_begin[2] + pads_end[2] - ((kernel[2] - 1) * dilations[2] + 1)) / strides[2] + 1)` + + * `auto_pad = valid` + `H_out = ceil((H - ((kernel[0] - 1) * dilations[0] + 1) + 1) / strides[0])` + `W_out = ceil((W - ((kernel[1] - 1) * dilations[1] + 1) + 1) / strides[1])` + `D_out = ceil((D - ((kernel[2] - 1) * dilations[2] + 1) + 1) / strides[2])` + + * `auto_pad = same_upper / same_lower` + `H_out = H` + `W_out = W` + `D_out = D` + + +If `H + pads_begin[i] + pads_end[i] - kernel[i]` is not divisible by `strides[i]` evenly, the result is rounded with respect to the `rounding_type` attribute. + +Example 1 shows how *MaxPool* operates with 4D input using 2D kernel and `auto_pad = explicit`. + +``` +input = [[[[-1, 2, 3], + [4, 5, -6], + [-7, 8, 9]]]] +strides = [1, 1] +pads_begin = [1, 1] +pads_end = [1, 1] +kernel = [2, 2] +rounding_type = "floor" +auto_pad = "explicit" +output0 = [[[[-1, 2, 3, 3], + [4, 5, 5, -6], + [4, 8, 9, 9], + [-7, 8, 9, 9]]]] +output1 = [[[[0, 1, 2, 2], + [3, 4, 4, 5], + [3, 7, 8, 8], + [6, 7, 8, 8]]]] +``` + +Example 2 shows how *MaxPool* operates with 3D input using 1D kernel and `auto_pad = valid`. + +``` +input = [[[-1, 2, 3, 5, -7, 9, 1]]] +strides = [1] +kernel = [3] +rounding_type = "floor" +auto_pad = "valid" +output0 = [[[3, 5, 5, 9, 9]]] +output1 = [[[2, 3, 3, 5, 5]]] +``` + +Example 3 shows how *MaxPool* operates with 4D input using 2D kernel and `auto_pad = same_lower`. + +``` +input = [[[[-1, 2, 3], + [4, 5, -6], + [-7, 8, 9]]]] +strides = [1, 1] +kernel = [2, 2] +rounding_type = "floor" +auto_pad = "same_lower" +output0 = [[[[-1, 2, 3], + [4, 5, 5] + [4, 8, 9]]]] +output1 = [[[[0, 1, 2], + [3, 4, 4] + [3, 7, 8]]]] +``` + +Example 4 shows how *MaxPool* operates with 4D input using 2D kernel and `auto_pad = same_upper`. + +``` +input = [[[[-1, 2, 3], + [4, 5, -6], + [-7, 8, 9]], + [[2, -1, 5], + [6, -7, 1], + [8, 2, -3]]]] +strides = [1, 1] +kernel = [2, 2] +rounding_type = "floor" +auto_pad = "same_upper" +output0 = [[[[5, 5, 3], + [8, 9, 9] + [8, 9, 9]], + [[6, 5, 5], + [8, 2, 1], + [8, 2, -3]]]] +output1 = [[[[4, 4, 2], + [7, 8, 8] + [7, 8, 8]], + [[12, 11, 11], + [15, 16, 14], + [15, 16, 17]]]] +``` + +Example 5 shows how *MaxPool* operates with 4D input using 2D kernel, `auto_pad = valid` and `rounding_type = ceil`. + +``` +input = [[[[-1, 2, 3], + [4, 5, -6], + [-7, 8, 9]]]] +strides = [2, 2] +kernel = [2, 2] +rounding_type = "ceil" +auto_pad = "valid" +output0 = [[[[5, 3], + [8, 9]]]] +output1 = [[[[4, 2], + [7, 8]]]] +``` + +Example 6 shows how *MaxPool* operates on 4D input using dilated 2D kernel, `auto_pad = explicit` and `rounding_type = floor`. + +``` +input = [[[[1, 2, 3], + [4, 5, 6], + [7, 8, 9]]]] +strides = [1, 1] +kernel = [2, 2] +dilations = [2, 2] +rounding_type = "floor" +auto_pad = "explicit" +pads_begin = [1, 1] +pads_end = [1, 1] +output0 = [[[[5, 6, 5], + [8, 9, 8], + [5, 6, 5]]]] +output1 = [[[[4, 5, 4], + [7, 8, 7], + [4, 5, 4]]]] +``` + +Example 7 shows how *MaxPool* operates on 4D input using 2D kernel, with non-default `axis` value. + +``` +input = [[[[1, 2, 3], + [4, 5, 6], + [7, 8, 9]], + [[10, 11, 12], + [13, 14, 15], + [16, 17, 18]] + ]] +strides = [1, 1] +kernel = [2, 2] +dilations = [1, 1] +rounding_type = "floor" +auto_pad = "explicit" +pads_begin = [0, 0] +pads_end = [0, 0] +axis = 2 +output0 = [[[[5, 6], + [8, 9]], + [[14, 15], + [17, 18]]]] +output1 = [[[[4, 5], + [7, 8]], + [[4, 5], + [7, 8]]]] +``` + +**Examples** + +```xml + + + + + 1 + 3 + 32 + 32 + + + + + 1 + 3 + 32 + 32 + + + 1 + 3 + 32 + 32 + + + + + + + + + 1 + 3 + 32 + 32 + + + + + 1 + 3 + 17 + 17 + + + 1 + 3 + 17 + 17 + + + + + + + + + 1 + 3 + 32 + 32 + + + + + 1 + 3 + 16 + 16 + + + 1 + 3 + 16 + 16 + + + +``` From d6de72bde07390e7324f3aa56794f5765395a95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Do=C5=82bniak?= Date: Wed, 18 Aug 2021 10:42:15 +0200 Subject: [PATCH 014/102] MaxPool-8: pads_value attribute removal from the operator definition (#7119) --- ngraph/core/include/ngraph/op/max_pool.hpp | 14 ++------------ ngraph/core/src/op/max_pool.cpp | 10 +++------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/ngraph/core/include/ngraph/op/max_pool.hpp b/ngraph/core/include/ngraph/op/max_pool.hpp index 26130dcde2858d..53096055b64e03 100644 --- a/ngraph/core/include/ngraph/op/max_pool.hpp +++ b/ngraph/core/include/ngraph/op/max_pool.hpp @@ -89,8 +89,7 @@ class NGRAPH_API MaxPool : public op::util::MaxPoolBase { const op::RoundingType rounding_type = op::RoundingType::FLOOR, const PadType auto_pad = op::PadType::EXPLICIT, const element::Type index_element_type = element::i64, - const int64_t axis = 0, - const float pads_value = -std::numeric_limits::infinity()); + const int64_t axis = 0); bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; @@ -121,19 +120,10 @@ class NGRAPH_API MaxPool : public op::util::MaxPoolBase { m_axis = axis; } - // \return The value stored in the padding cells. - float get_pads_value() const { - return m_pads_value; - } - void set_pads_value(const float pads_value) { - m_pads_value = pads_value; - } - private: Strides m_dilations; - element::Type m_index_element_type{element::i32}; + element::Type m_index_element_type{element::i64}; int64_t m_axis{0}; - float m_pads_value{-std::numeric_limits::infinity()}; }; } // namespace v8 } // namespace op diff --git a/ngraph/core/src/op/max_pool.cpp b/ngraph/core/src/op/max_pool.cpp index d6438cc5078cb3..5e5755fa485dea 100644 --- a/ngraph/core/src/op/max_pool.cpp +++ b/ngraph/core/src/op/max_pool.cpp @@ -171,13 +171,11 @@ op::v8::MaxPool::MaxPool(const Output& arg, const op::RoundingType rounding_type, const PadType auto_pad, const element::Type index_element_type, - const int64_t axis, - const float pads_value) + const int64_t axis) : op::util::MaxPoolBase(arg, strides, pads_begin, pads_end, kernel, rounding_type, auto_pad), m_dilations{dilations}, m_index_element_type{index_element_type}, - m_axis{axis}, - m_pads_value{pads_value} { + m_axis{axis} { constructor_validate_and_infer_types(); } @@ -192,7 +190,6 @@ bool ngraph::op::v8::MaxPool::visit_attributes(AttributeVisitor& visitor) { visitor.on_attribute("auto_pad", m_auto_pad); visitor.on_attribute("index_element_type", m_index_element_type); visitor.on_attribute("axis", m_axis); - visitor.on_attribute("pads_value", m_pads_value); return true; } @@ -224,6 +221,5 @@ shared_ptr op::v8::MaxPool::clone_with_new_inputs(const OutputVector& new_ m_rounding_type, m_auto_pad, m_index_element_type, - m_axis, - m_pads_value); + m_axis); } From ec512f46a0976e66bcbc57fd432ca9223436dcdf Mon Sep 17 00:00:00 2001 From: Daria Mityagina Date: Wed, 18 Aug 2021 12:31:19 +0300 Subject: [PATCH 015/102] Remove deprecated option and enable compilation without device (#6022) --- docs/IE_DG/supported_plugins/MYRIAD.md | 2 - .../include/ie/vpu/myriad_plugin_config.hpp | 17 ----- .../include/vpu/compile_env.hpp | 14 ++-- .../vpu/configuration/options/platform.hpp | 36 ---------- .../include/vpu/graph_transformer.hpp | 4 +- .../vpu/graph_transformer_internal.hpp | 1 - .../src/configuration/options/platform.cpp | 66 ------------------- .../src/frontend/frontend.cpp | 4 -- .../src/graph_transformer.cpp | 62 ++++++++--------- .../vpu/graph_transformer/src/model/stage.cpp | 6 -- .../myriad_executable_network.cpp | 4 +- .../myriad_plugin/myriad_executable_network.h | 6 +- .../src/vpu/myriad_plugin/myriad_executor.cpp | 21 ++---- .../src/vpu/myriad_plugin/myriad_executor.h | 6 -- .../src/vpu/myriad_plugin/myriad_metrics.cpp | 1 - .../src/vpu/myriad_plugin/myriad_plugin.cpp | 3 - .../behavior/config.cpp | 22 ------- .../unit/vpu/base/graph_transformer_tests.cpp | 4 +- .../unit/vpu/base/graph_transformer_tests.hpp | 1 - .../tests/unit/vpu/blob_reader_tests.cpp | 2 +- .../vpu/myriad_tests/aot_behavior_tests.cpp | 1 - .../myriad_tests/helpers/myriad_devices.cpp | 4 -- .../myriad_tests/helpers/myriad_devices.hpp | 6 +- .../helpers/myriad_load_network_case.cpp | 2 +- .../vpu/myriad_tests/vpu_boot_tests.cpp | 2 +- .../vpu/myriad_tests/vpu_watchdog_tests.cpp | 1 - .../plugin_tests/vpu_test_data.hpp | 15 ----- .../common/layers/myriad_layers_blob_test.cpp | 1 - .../graph_transformer/gt_functional_tests.cpp | 6 +- .../graph_transformer/gt_functional_tests.hpp | 1 - .../vpu/myriad_tests/myriad_configs_tests.cpp | 18 ----- .../helpers/tests_vpu_common.hpp | 12 +--- .../engines/vpu/graph_transformer_tests.cpp | 4 +- .../engines/vpu/graph_transformer_tests.hpp | 1 - .../vpu/myriad_tests/myriad_engine_tests.cpp | 23 ------- .../thirdparty/movidius/mvnc/include/mvnc.h | 7 -- .../movidius/mvnc/include/mvnc_data.h | 3 +- .../movidius/mvnc/include/mvnc_ext.h | 4 +- .../thirdparty/movidius/mvnc/src/mvnc_api.c | 26 ++------ .../thirdparty/movidius/mvnc/src/mvnc_data.c | 24 ------- .../tests/cases/mvnc_common_test_cases.cpp | 4 +- .../mvnc/tests/cases/mvnc_common_test_cases.h | 11 +--- .../mvnc/tests/cases/mvnc_usb_test_cases.cpp | 1 - .../mvnc/tests/cases/mvnc_usb_test_cases.h | 5 +- .../mvnc/tests/helpers/mvnc_test_helper.cpp | 32 +-------- .../mvnc/tests/helpers/mvnc_test_helper.h | 5 +- .../mvnc/tests/mvnc_no_boot_tests.cpp | 4 -- .../movidius/mvnc/tests/mvnc_stress_tests.cpp | 3 - .../movidius/mvnc/tests/mvnc_tests_common.cpp | 14 +--- .../movidius/mvnc/tests/mvnc_tests_usb.cpp | 12 +--- inference-engine/tools/compile_tool/main.cpp | 4 -- 51 files changed, 77 insertions(+), 461 deletions(-) delete mode 100644 inference-engine/src/vpu/graph_transformer/include/vpu/configuration/options/platform.hpp delete mode 100644 inference-engine/src/vpu/graph_transformer/src/configuration/options/platform.cpp diff --git a/docs/IE_DG/supported_plugins/MYRIAD.md b/docs/IE_DG/supported_plugins/MYRIAD.md index 8983f20a92535b..6425cc5ed4b185 100644 --- a/docs/IE_DG/supported_plugins/MYRIAD.md +++ b/docs/IE_DG/supported_plugins/MYRIAD.md @@ -66,10 +66,8 @@ In addition to common parameters, the MYRIAD plugin accepts the following option | Parameter Name | Parameter Values | Default | Description | | :--- | :--- | :--- | :--- | -| `KEY_VPU_MYRIAD_PLATFORM` | empty string/`VPU_MYRIAD_2450`/`VPU_MYRIAD_2480` | empty string | If set, the plugin will use a device with specific platform to allocate a network. | | `KEY_VPU_MYRIAD_PROTOCOL` | empty string/`VPU_MYRIAD_USB`/`VPU_MYRIAD_PCIE` | empty string | If set, the plugin will use a device with specific protocol to allocate a network. | | `KEY_VPU_MYRIAD_FORCE_RESET` | `YES`/`NO` | `NO` | Enables force reset of all booted devices when new ExecutableNetwork is created.
This is a plugin scope option and must be used with the plugin's SetConfig method only.
See Device allocation section for details. | -| `KEY_VPU_PLATFORM` | empty string/`VPU_2450`/`VPU_2480` | empty string | **Deprecated** Use `KEY_VPU_MYRIAD_PLATFORM` instead.
If set, the plugin will use a device with specific platform to allocate a network. | | `KEY_VPU_FORCE_RESET` | `YES`/`NO` | `NO` | **Deprecated** Use `KEY_VPU_MYRIAD_FORCE_RESET` instead.
Enables force reset of all booted devices when new ExecutableNetwork is created.
This is a plugin scope option and must be used with the plugin's SetConfig method only.
See Device allocation section for details. | ## Device allocation   diff --git a/inference-engine/src/inference_engine/include/ie/vpu/myriad_plugin_config.hpp b/inference-engine/src/inference_engine/include/ie/vpu/myriad_plugin_config.hpp index e777daabf0a899..f6eed5ef4052bc 100644 --- a/inference-engine/src/inference_engine/include/ie/vpu/myriad_plugin_config.hpp +++ b/inference-engine/src/inference_engine/include/ie/vpu/myriad_plugin_config.hpp @@ -41,23 +41,6 @@ namespace VPUConfigParams { INFERENCE_ENGINE_DEPRECATED("Use InferenceEngine::MYRIAD_ENABLE_FORCE_RESET instead") DECLARE_VPU_MYRIAD_CONFIG_KEY(FORCE_RESET); -/** - * @deprecated - * @brief This option allows to specify device. - * If specified device is not available then creating infer request will throw an exception. - */ -INFERENCE_ENGINE_DEPRECATED("") -DECLARE_VPU_MYRIAD_CONFIG_KEY(PLATFORM); - -/** - * @deprecated - * @brief Supported keys definition for VPU_MYRIAD_CONFIG_KEY(PLATFORM) option. - */ -INFERENCE_ENGINE_DEPRECATED("") -DECLARE_VPU_MYRIAD_CONFIG_VALUE(2450); -INFERENCE_ENGINE_DEPRECATED("") -DECLARE_VPU_MYRIAD_CONFIG_VALUE(2480); - /** * @deprecated Use InferenceEngine::MYRIAD_DDR_TYPE instead * @brief This option allows to specify device memory type. diff --git a/inference-engine/src/vpu/graph_transformer/include/vpu/compile_env.hpp b/inference-engine/src/vpu/graph_transformer/include/vpu/compile_env.hpp index 3228c7e1a4cedf..7cff0ee8dbadee 100644 --- a/inference-engine/src/vpu/graph_transformer/include/vpu/compile_env.hpp +++ b/inference-engine/src/vpu/graph_transformer/include/vpu/compile_env.hpp @@ -13,21 +13,20 @@ namespace vpu { struct DeviceResources { - static int numShaves(const ncDevicePlatform_t& platform); - static int numSlices(const ncDevicePlatform_t& platform); + static int numShaves(); + static int numSlices(); static int numStreams(); }; struct DefaultAllocation { - static int numStreams(const ncDevicePlatform_t& platform, const PluginConfiguration& configuration); - static int numSlices(const ncDevicePlatform_t& platform, int numStreams); - static int numShaves(const ncDevicePlatform_t& platform, int numStreams, int numSlices); + static int numStreams(const PluginConfiguration& configuration); + static int numSlices(int numStreams); + static int numShaves(int numStreams, int numSlices); static int tilingCMXLimit(int numSlices); }; struct CompileEnv final { public: - ncDevicePlatform_t platform; Resources resources; PluginConfiguration config; @@ -50,14 +49,13 @@ struct CompileEnv final { static const CompileEnv* getOrNull(); static void init( - ncDevicePlatform_t platform, const PluginConfiguration& config, const Logger::Ptr& log); static void updateConfig(const PluginConfiguration& config); static void free(); private: - explicit CompileEnv(ncDevicePlatform_t platform); + CompileEnv(); }; } // namespace vpu diff --git a/inference-engine/src/vpu/graph_transformer/include/vpu/configuration/options/platform.hpp b/inference-engine/src/vpu/graph_transformer/include/vpu/configuration/options/platform.hpp deleted file mode 100644 index bcf527ac37b7a7..00000000000000 --- a/inference-engine/src/vpu/graph_transformer/include/vpu/configuration/options/platform.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "vpu/configuration/as_parameter_enabler.hpp" - -#include - -namespace vpu { - -namespace details { - -enum class Access; -enum class Category; - -} // namespace details - -class PluginConfiguration; - -struct PlatformOption : public AsParameterEnabler { - using value_type = ncDevicePlatform_t; - - static std::string key(); - static void validate(const std::string&); - static void validate(const PluginConfiguration&); - static std::string defaultValue(); - static value_type parse(const std::string&); - static details::Access access(); - static details::Category category(); -}; - -} // namespace vpu diff --git a/inference-engine/src/vpu/graph_transformer/include/vpu/graph_transformer.hpp b/inference-engine/src/vpu/graph_transformer/include/vpu/graph_transformer.hpp index 218a69989ef5a7..6566e5d5265637 100644 --- a/inference-engine/src/vpu/graph_transformer/include/vpu/graph_transformer.hpp +++ b/inference-engine/src/vpu/graph_transformer/include/vpu/graph_transformer.hpp @@ -71,7 +71,7 @@ struct CompiledGraph final { // compileNetwork // -CompiledGraph::Ptr compileNetwork(const ie::CNNNetwork& network, ncDevicePlatform_t platform, const PluginConfiguration& config, const Logger::Ptr& log, +CompiledGraph::Ptr compileNetwork(const ie::CNNNetwork& network, const PluginConfiguration& config, const Logger::Ptr& log, const std::shared_ptr core); CompiledGraph::Ptr compileSubNetwork(const ie::CNNNetwork& network, const PluginConfiguration& subConfig, const std::shared_ptr core); @@ -80,7 +80,7 @@ CompiledGraph::Ptr compileSubNetwork(const ie::CNNNetwork& network, const Plugin // getSupportedLayers // -std::set getSupportedLayers(const ie::CNNNetwork& network, ncDevicePlatform_t platform, const PluginConfiguration& config, const Logger::Ptr& log, +std::set getSupportedLayers(const ie::CNNNetwork& network, const PluginConfiguration& config, const Logger::Ptr& log, const std::shared_ptr core); // diff --git a/inference-engine/src/vpu/graph_transformer/include/vpu/graph_transformer_internal.hpp b/inference-engine/src/vpu/graph_transformer/include/vpu/graph_transformer_internal.hpp index 99cddb1be791c9..b6c02c0f8e464b 100644 --- a/inference-engine/src/vpu/graph_transformer/include/vpu/graph_transformer_internal.hpp +++ b/inference-engine/src/vpu/graph_transformer/include/vpu/graph_transformer_internal.hpp @@ -12,7 +12,6 @@ namespace vpu { CompiledGraph::Ptr compileModel( const Model& model, - ncDevicePlatform_t platform, const PluginConfiguration& config, const Logger::Ptr& log); diff --git a/inference-engine/src/vpu/graph_transformer/src/configuration/options/platform.cpp b/inference-engine/src/vpu/graph_transformer/src/configuration/options/platform.cpp deleted file mode 100644 index 210414dd1e8330..00000000000000 --- a/inference-engine/src/vpu/graph_transformer/src/configuration/options/platform.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "vpu/configuration/options/platform.hpp" -#include "vpu/utils/containers.hpp" -#include "vpu/configuration/plugin_configuration.hpp" - -#include -#include - -#include - -namespace vpu { - -namespace { - -const std::unordered_map& string2platform() { -IE_SUPPRESS_DEPRECATED_START - static const std::unordered_map converters = { - {VPU_MYRIAD_CONFIG_VALUE(2450), ncDevicePlatform_t::NC_MYRIAD_2}, - {VPU_MYRIAD_CONFIG_VALUE(2480), ncDevicePlatform_t::NC_MYRIAD_X}, - {std::string(), ncDevicePlatform_t::NC_ANY_PLATFORM}, - }; -IE_SUPPRESS_DEPRECATED_END - return converters; -} - -} // namespace - -void PlatformOption::validate(const std::string& value) { - const auto& converters = string2platform(); - VPU_THROW_UNLESS(converters.count(value) != 0, R"(unexpected {} option value "{}", only {} are supported)", - key(), value, getKeys(converters)); -} - -void PlatformOption::validate(const PluginConfiguration& configuration) { - validate(configuration[key()]); -} - -std::string PlatformOption::key() { -IE_SUPPRESS_DEPRECATED_START - return VPU_MYRIAD_CONFIG_KEY(PLATFORM); -IE_SUPPRESS_DEPRECATED_END -} - -details::Access PlatformOption::access() { - return details::Access::Public; -} - -details::Category PlatformOption::category() { - return details::Category::RunTime; -} - -std::string PlatformOption::defaultValue() { - return std::string(); -} - -PlatformOption::value_type PlatformOption::parse(const std::string& value) { - const auto& converters = string2platform(); - VPU_THROW_UNSUPPORTED_OPTION_UNLESS(converters.count(value) != 0, R"(unexpected {} option value "{}", only {} are supported)", - key(), value, getKeys(converters)); - return converters.at(value); -} - -} // namespace vpu diff --git a/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp b/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp index ba3888dea284ef..c2e5c054de40fa 100644 --- a/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp @@ -479,10 +479,6 @@ ModelPtr FrontEnd::runCommonPasses(ie::CNNNetwork network, env.log->trace("Parse custom layers : %s", customLayers); VPU_LOGGER_SECTION(env.log); - if (env.platform != ncDevicePlatform_t::NC_MYRIAD_X) { - VPU_THROW_FORMAT("Custom layers are not supported for %v platforms", env.platform); - } - _customLayers = CustomLayer::loadFromFile(customLayers); } diff --git a/inference-engine/src/vpu/graph_transformer/src/graph_transformer.cpp b/inference-engine/src/vpu/graph_transformer/src/graph_transformer.cpp index 463e0fdcada312..c82a75515d0bd6 100644 --- a/inference-engine/src/vpu/graph_transformer/src/graph_transformer.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/graph_transformer.cpp @@ -64,7 +64,7 @@ thread_local CompileEnv* g_compileEnv = nullptr; } // namespace -CompileEnv::CompileEnv(ncDevicePlatform_t platform) : platform(platform) {} +CompileEnv::CompileEnv() {} const CompileEnv& CompileEnv::get() { IE_ASSERT(g_compileEnv != nullptr); @@ -79,8 +79,8 @@ const CompileEnv* CompileEnv::getOrNull() { return g_compileEnv; } -void CompileEnv::init(ncDevicePlatform_t platform, const PluginConfiguration& config, const Logger::Ptr& log) { - g_compileEnv = new CompileEnv(platform); +void CompileEnv::init(const PluginConfiguration& config, const Logger::Ptr& log) { + g_compileEnv = new CompileEnv(); g_compileEnv->config = config; g_compileEnv->log = log; @@ -88,22 +88,18 @@ void CompileEnv::init(ncDevicePlatform_t platform, const PluginConfiguration& co g_compileEnv->profile.setLogger(log); #endif - if (platform == ncDevicePlatform_t::NC_MYRIAD_2) { - g_compileEnv->config.set(ie::MYRIAD_ENABLE_HW_ACCELERATION, ie::PluginConfigParams::NO); - } - const auto numExecutors = config.get().hasValue() - ? config.get().get() : DefaultAllocation::numStreams(platform, config); + ? config.get().get() : DefaultAllocation::numStreams(config); VPU_THROW_UNLESS(numExecutors >= 1 && numExecutors <= DeviceResources::numStreams(), R"(Value of configuration option ("{}") must be in the range [{}, {}], actual is "{}")", ThroughputStreamsOption::key(), 1, DeviceResources::numStreams(), numExecutors); const auto numSlices = config.get().hasValue() ? config.get().get() - : DefaultAllocation::numSlices(platform, numExecutors); - VPU_THROW_UNLESS(numSlices >= 1 && numSlices <= DeviceResources::numSlices(platform), + : DefaultAllocation::numSlices(numExecutors); + VPU_THROW_UNLESS(numSlices >= 1 && numSlices <= DeviceResources::numSlices(), R"(Value of configuration option ("{}") must be in the range [{}, {}], actual is "{}")", - NumberOfCMXSlicesOption::key(), 1, DeviceResources::numSlices(platform), numSlices); + NumberOfCMXSlicesOption::key(), 1, DeviceResources::numSlices(), numSlices); int defaultCmxLimit = DefaultAllocation::tilingCMXLimit(numSlices); const auto tilingCMXLimit = config.get().hasValue() @@ -115,18 +111,18 @@ void CompileEnv::init(ncDevicePlatform_t platform, const PluginConfiguration& co const auto numShaves = config.get().hasValue() ? config.get().get() - : DefaultAllocation::numShaves(platform, numExecutors, numSlices); - VPU_THROW_UNLESS(numShaves >= 1 && numShaves <= DeviceResources::numShaves(platform), + : DefaultAllocation::numShaves(numExecutors, numSlices); + VPU_THROW_UNLESS(numShaves >= 1 && numShaves <= DeviceResources::numShaves(), R"(Value of configuration option ("{}") must be in the range [{}, {}], actual is "{}")", - NumberOfSHAVEsOption::key(), 1, DeviceResources::numShaves(platform), numShaves); + NumberOfSHAVEsOption::key(), 1, DeviceResources::numShaves(), numShaves); const auto numAllocatedShaves = numShaves * numExecutors; - VPU_THROW_UNLESS(numAllocatedShaves >= 1 && numAllocatedShaves <= DeviceResources::numShaves(platform), - R"(Cannot allocate "{}" shaves: only {} is available)", numAllocatedShaves, DeviceResources::numShaves(platform)); + VPU_THROW_UNLESS(numAllocatedShaves >= 1 && numAllocatedShaves <= DeviceResources::numShaves(), + R"(Cannot allocate "{}" shaves: only {} is available)", numAllocatedShaves, DeviceResources::numShaves()); const auto numAllocatedSlices = numSlices * numExecutors; - VPU_THROW_UNLESS(numAllocatedSlices >= 1 && numAllocatedSlices <= DeviceResources::numSlices(platform), - R"(Cannot allocate "{}" slices: only {} is available)", numAllocatedSlices, DeviceResources::numSlices(platform)); + VPU_THROW_UNLESS(numAllocatedSlices >= 1 && numAllocatedSlices <= DeviceResources::numSlices(), + R"(Cannot allocate "{}" slices: only {} is available)", numAllocatedSlices, DeviceResources::numSlices()); g_compileEnv->resources.numSHAVEs = numShaves; g_compileEnv->resources.numCMXSlices = numSlices; @@ -203,9 +199,9 @@ CompiledGraph::Ptr compileImpl(const Model& model) { } // namespace -CompiledGraph::Ptr compileNetwork(const ie::CNNNetwork& network, ncDevicePlatform_t platform, const PluginConfiguration& config, const Logger::Ptr& log, +CompiledGraph::Ptr compileNetwork(const ie::CNNNetwork& network, const PluginConfiguration& config, const Logger::Ptr& log, const std::shared_ptr core) { - CompileEnv::init(platform, config, log); + CompileEnv::init(config, log); AutoScope autoDeinit([] { CompileEnv::free(); }); @@ -217,10 +213,9 @@ CompiledGraph::Ptr compileNetwork(const ie::CNNNetwork& network, ncDevicePlatfor CompiledGraph::Ptr compileModel( const Model& model, - ncDevicePlatform_t platform, const PluginConfiguration& config, const Logger::Ptr& log) { - CompileEnv::init(platform, config, log); + CompileEnv::init(config, log); AutoScope autoDeinit([] { CompileEnv::free(); }); @@ -251,11 +246,10 @@ CompiledGraph::Ptr compileSubNetwork(const ie::CNNNetwork& network, const Plugin std::set getSupportedLayers( const ie::CNNNetwork& network, - ncDevicePlatform_t platform, const PluginConfiguration& config, const Logger::Ptr& log, const std::shared_ptr core) { - CompileEnv::init(platform, config, log); + CompileEnv::init(config, log); AutoScope autoDeinit([] { CompileEnv::free(); }); @@ -267,29 +261,29 @@ std::set getSupportedLayers( return frontEnd->checkSupportedLayers(network); } -int DeviceResources::numShaves(const ncDevicePlatform_t& platform) { - return platform == ncDevicePlatform_t::NC_MYRIAD_2 ? 12 : 16; +int DeviceResources::numShaves() { + return 16; } -int DeviceResources::numSlices(const ncDevicePlatform_t& platform) { - return platform == ncDevicePlatform_t::NC_MYRIAD_2 ? 12 : 19; +int DeviceResources::numSlices() { + return 19; } int DeviceResources::numStreams() { return 3; } -int DefaultAllocation::numStreams(const ncDevicePlatform_t& platform, const PluginConfiguration& configuration) { - return platform == ncDevicePlatform_t::NC_MYRIAD_X && configuration.get() ? 2 : 1; +int DefaultAllocation::numStreams(const PluginConfiguration& configuration) { + return configuration.get() ? 2 : 1; } -int DefaultAllocation::numSlices(const ncDevicePlatform_t& platform, int numStreams) { - const auto capabilities = DeviceResources::numSlices(platform); +int DefaultAllocation::numSlices(int numStreams) { + const auto capabilities = DeviceResources::numSlices(); return capabilities / numStreams; } -int DefaultAllocation::numShaves(const ncDevicePlatform_t& platform, int numStreams, int numSlices) { - const auto numAvailableShaves = DeviceResources::numShaves(platform); +int DefaultAllocation::numShaves(int numStreams, int numSlices) { + const auto numAvailableShaves = DeviceResources::numShaves(); if (numStreams == 1) { return numAvailableShaves; } diff --git a/inference-engine/src/vpu/graph_transformer/src/model/stage.cpp b/inference-engine/src/vpu/graph_transformer/src/model/stage.cpp index cad7da95ca8e41..8733742a0ad6c8 100644 --- a/inference-engine/src/vpu/graph_transformer/src/model/stage.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/model/stage.cpp @@ -197,12 +197,6 @@ StageSHAVEsRequirements StageNode::getSHAVEsRequirements() const { // Get result from Stage implementation. // - // return max for Myriad2 - const auto& compileEnv = CompileEnv::get(); - if (compileEnv.platform == ncDevicePlatform_t::NC_MYRIAD_2) { - return StageSHAVEsRequirements::NeedMax; - } - auto reqs = getSHAVEsRequirementsImpl(); // diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.cpp b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.cpp index 679fb25d1cd37a..f9bd974a0ff5b1 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.cpp +++ b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.cpp @@ -54,9 +54,8 @@ ExecutableNetwork::ExecutableNetwork( void ExecutableNetwork::openDevice(std::vector& devicePool) { _device = _executor->openDevice(devicePool, _config); - const auto& revision = _device->revision(); _actualNumExecutors = _config.get().hasValue() - ? _config.get().get() : DefaultAllocation::numStreams(revision, _config); + ? _config.get().get() : DefaultAllocation::numStreams(_config); } ExecutableNetwork::ExecutableNetwork( @@ -75,7 +74,6 @@ ExecutableNetwork::ExecutableNetwork( auto compiledGraph = compileNetwork( network, - NC_MYRIAD_X, _config, compilerLog, _core); diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h index c64a9f6aaf0105..d093597cd49ef1 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h +++ b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h @@ -54,8 +54,7 @@ class ExecutableNetwork : public ie::ExecutableNetworkThreadSafeDefault { ie::IInferRequestInternal::Ptr CreateInferRequestImpl(ie::InputsDataMap networkInputs, ie::OutputsDataMap networkOutputs) override { if (!_isNetworkConstant && (_device == nullptr || !_device->isBooted())) { - IE_THROW() << "Can not create infer request: there is no available devices with platform " - << _device->_platform; + IE_THROW() << "Can not create infer request: there is no available devices with platform "; } return std::make_shared(_graphDesc, networkInputs, networkOutputs, @@ -66,8 +65,7 @@ class ExecutableNetwork : public ie::ExecutableNetworkThreadSafeDefault { ie::IInferRequestInternal::Ptr CreateInferRequest() override { if (!_isNetworkConstant && (_device == nullptr || !_device->isBooted())) { - IE_THROW() << "Can not create infer request: there is no available devices with platform " - << _device->_platform; + IE_THROW() << "Can not create infer request: there is no available devices with platform "; } auto syncRequestImpl = std::make_shared(_graphDesc, _networkInputs, _networkOutputs, diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_executor.cpp b/inference-engine/src/vpu/myriad_plugin/myriad_executor.cpp index f0f3628049cce3..1cc67e639e0c13 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_executor.cpp +++ b/inference-engine/src/vpu/myriad_plugin/myriad_executor.cpp @@ -90,7 +90,6 @@ ncStatus_t MyriadExecutor::bootNextDevice(std::vector &devicePool, co } #endif - const ncDevicePlatform_t& configPlatform = ncDevicePlatform_t::NC_ANY_PLATFORM; const ncDeviceProtocol_t& configProtocol = config.get(); const std::string& configDevName = config.get(); PowerConfig powerConfig = config.get(); @@ -114,7 +113,6 @@ ncStatus_t MyriadExecutor::bootNextDevice(std::vector &devicePool, co #endif ncDeviceDescr_t in_deviceDesc = {}; - in_deviceDesc.platform = configPlatform; in_deviceDesc.protocol = configProtocol; if (!configDevName.empty()) { @@ -126,13 +124,6 @@ ncStatus_t MyriadExecutor::bootNextDevice(std::vector &devicePool, co if (it == availableDevicesDesc.end()) { IE_THROW() << "Myriad device: " << configDevName << " not found."; - } else { - ncDeviceDescr_t deviceDesc = *it; - if (configPlatform != NC_ANY_PLATFORM && - configPlatform != deviceDesc.platform) { - IE_THROW() << "Input value of device name and platform are contradict each other. Device name: " << configDevName - << "Platform: " << configPlatform; - } } configDevName.copy(in_deviceDesc.name, NC_MAX_NAME_SIZE - 1); @@ -164,8 +155,8 @@ ncStatus_t MyriadExecutor::bootNextDevice(std::vector &devicePool, co // Get device protocol status = ncDeviceGetOption(device._deviceHandle, NC_RO_DEVICE_PLATFORM, - reinterpret_cast(&device._platform), &dataLength); - if (status != NC_OK || dataLength != sizeof(device._platform)) { + reinterpret_cast(&device), &dataLength); + if (status != NC_OK) { _log->warning("Failed to get device platform"); ncDeviceClose(&device._deviceHandle, _mvnc->watchdogHndl()); return status != NC_OK ? status : NC_ERROR; // for dataLength error @@ -273,10 +264,11 @@ DevicePtr MyriadExecutor::openDevice(std::vector& devicePool, return device->isBooted() && device->isNotFull() && device->isSuitableForConfig(config); }); - // Return mock device. If try infer with it, exception will be thrown if (availableDevices.empty()) { - IE_THROW() << "Can not init Myriad device: " << ncStatusToStr(nullptr, booted); + DeviceDesc device; + device._protocol = config.get(); + return std::make_shared(device); } auto deviceWithMinExecutors = std::min_element(availableDevices.begin(), availableDevices.end(), @@ -288,7 +280,6 @@ DevicePtr MyriadExecutor::openDevice(std::vector& devicePool, } _log->info("Device #%d %s (%s protocol) allocated", devicePool.size() - 1, - devicePool.back()->_platform == NC_MYRIAD_X ? "MYRIAD-X" : "MYRIAD-2", devicePool.back()->_protocol == NC_USB? "USB" : "PCIe"); return devicePool.back(); @@ -378,7 +369,7 @@ void MyriadExecutor::allocateGraph(DevicePtr &device, GraphDesc &graphDesc, IE_THROW() << "Failed to get output description: " << ncStatusToStr(graphDesc._graphHandle, status); } - unsigned int fifo_elements = (device->_platform == NC_MYRIAD_2 && executors == 1) ? 4 : 2 * executors; + unsigned int fifo_elements = 2 * executors; status = ncFifoCreate("input", NC_FIFO_HOST_WO, &graphDesc._inputFifoHandle); if (status != NC_OK) { diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_executor.h b/inference-engine/src/vpu/myriad_plugin/myriad_executor.h index 997f7525d32916..84a6269347b9a7 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_executor.h +++ b/inference-engine/src/vpu/myriad_plugin/myriad_executor.h @@ -38,7 +38,6 @@ struct DeviceDesc { int _graphNum = 0; int _maxGraphNum = 0; std::string _name; - ncDevicePlatform_t _platform = NC_ANY_PLATFORM; ncDeviceProtocol_t _protocol = NC_ANY_PROTOCOL; int _deviceIdx = -1; @@ -63,11 +62,6 @@ struct DeviceDesc { return isSuitableByName && ((config.get() == NC_ANY_PROTOCOL) || (_protocol == config.get())); } - - ncDevicePlatform_t revision() const { - VPU_THROW_UNLESS(_platform != NC_ANY_PLATFORM, "Cannot get a revision from not booted device"); - return _platform; - } }; typedef std::shared_ptr DevicePtr; diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_metrics.cpp b/inference-engine/src/vpu/myriad_plugin/myriad_metrics.cpp index 83e16dbaff02d6..78b4b031b24648 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_metrics.cpp +++ b/inference-engine/src/vpu/myriad_plugin/myriad_metrics.cpp @@ -40,7 +40,6 @@ IE_SUPPRESS_DEPRECATED_START // deprecated KEY_VPU_CUSTOM_LAYERS, KEY_VPU_MYRIAD_FORCE_RESET, - KEY_VPU_MYRIAD_PLATFORM, CONFIG_KEY(CONFIG_FILE), }; diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp b/inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp index e84877890a6ca9..1136f71f345803 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp +++ b/inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp @@ -61,7 +61,6 @@ #include #include #include -#include #include #include #include @@ -165,7 +164,6 @@ QueryNetworkResult Engine::QueryNetwork( const auto supportedLayers = getSupportedLayers( network, - ncDevicePlatform_t::NC_ANY_PLATFORM, parsedConfigCopy, log, GetCore()); @@ -247,7 +245,6 @@ IE_SUPPRESS_DEPRECATED_START _parsedConfig.registerDeprecatedOption(VPU_CONFIG_KEY(CUSTOM_LAYERS)); _parsedConfig.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(MOVIDIUS_DDR_TYPE)); _parsedConfig.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(FORCE_RESET)); - _parsedConfig.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(PLATFORM)); IE_SUPPRESS_DEPRECATED_END } diff --git a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/config.cpp b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/config.cpp index 490db81c3520ab..09c9f9e7d0d9b9 100644 --- a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/config.cpp +++ b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/config.cpp @@ -167,8 +167,6 @@ std::vector> getCorrectConfigs() { {{VPU_CONFIG_KEY(PRINT_RECEIVE_TENSOR_TIME), CONFIG_VALUE(YES)}}, {{VPU_CONFIG_KEY(PRINT_RECEIVE_TENSOR_TIME), CONFIG_VALUE(NO)}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), VPU_MYRIAD_CONFIG_VALUE(2480)}}, - {{VPU_CONFIG_KEY(DETECT_NETWORK_BATCH), CONFIG_VALUE(YES)}}, {{VPU_CONFIG_KEY(DETECT_NETWORK_BATCH), CONFIG_VALUE(NO)}}, @@ -317,7 +315,6 @@ const std::vector>& getDefaul {KEY_CONFIG_FILE, {std::string()}}, {InferenceEngine::MYRIAD_DDR_TYPE, {InferenceEngine::MYRIAD_DDR_AUTO}}, {InferenceEngine::MYRIAD_ENABLE_FORCE_RESET, {false}}, - {VPU_MYRIAD_CONFIG_KEY(PLATFORM), {std::string()}}, {InferenceEngine::MYRIAD_CHECK_PREPROCESSING_INSIDE_MODEL, {true}}, {InferenceEngine::MYRIAD_ENABLE_EARLY_ELTWISE_RELU_FUSION, {true}}, {InferenceEngine::MYRIAD_ENABLE_CUSTOM_RESHAPE_PARAM, {false}}, @@ -354,9 +351,6 @@ const std::vector>& getIncorrectConfigs() { {{VPU_CONFIG_KEY(PRINT_RECEIVE_TENSOR_TIME), "ON"}}, {{VPU_CONFIG_KEY(PRINT_RECEIVE_TENSOR_TIME), "OFF"}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "-1"}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "0"}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "1"}}, - {{VPU_CONFIG_KEY(DETECT_NETWORK_BATCH), "ON"}}, {{VPU_CONFIG_KEY(DETECT_NETWORK_BATCH), "OFF"}}, @@ -906,18 +896,6 @@ const std::vector>& getIncorrectMultiConfigs( {InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_MYRIAD}, {VPU_CONFIG_KEY(HW_STAGES_OPTIMIZATION), "ON"} }, - { - {InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_MYRIAD}, - {VPU_MYRIAD_CONFIG_KEY(PLATFORM), "-1"}, - }, - { - {InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_MYRIAD}, - {VPU_MYRIAD_CONFIG_KEY(PLATFORM), "0"}, - }, - { - {InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_MYRIAD}, - {VPU_MYRIAD_CONFIG_KEY(PLATFORM), "1"}, - }, { {InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_MYRIAD}, {VPU_CONFIG_KEY(PRINT_RECEIVE_TENSOR_TIME), "OFF"} diff --git a/inference-engine/tests/unit/vpu/base/graph_transformer_tests.cpp b/inference-engine/tests/unit/vpu/base/graph_transformer_tests.cpp index 0b57b4527a1ce3..15cfffd0343a34 100644 --- a/inference-engine/tests/unit/vpu/base/graph_transformer_tests.cpp +++ b/inference-engine/tests/unit/vpu/base/graph_transformer_tests.cpp @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -362,7 +361,7 @@ void GraphTransformerTest::InitCompileEnv() { ? InferenceEngine::PluginConfigParams::YES : InferenceEngine::PluginConfigParams::NO); } - CompileEnv::init(platform, config, _log); + CompileEnv::init(config, _log); compileEnvInitialized = true; } @@ -452,7 +451,6 @@ IE_SUPPRESS_DEPRECATED_START configuration.registerDeprecatedOption(VPU_CONFIG_KEY(CUSTOM_LAYERS)); configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(MOVIDIUS_DDR_TYPE)); configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(FORCE_RESET)); - configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(PLATFORM)); IE_SUPPRESS_DEPRECATED_END return configuration; diff --git a/inference-engine/tests/unit/vpu/base/graph_transformer_tests.hpp b/inference-engine/tests/unit/vpu/base/graph_transformer_tests.hpp index 2e125a6e30b5cb..8f57ad1ad4654b 100644 --- a/inference-engine/tests/unit/vpu/base/graph_transformer_tests.hpp +++ b/inference-engine/tests/unit/vpu/base/graph_transformer_tests.hpp @@ -134,7 +134,6 @@ PluginConfiguration createConfiguration(); class GraphTransformerTest : public ::testing::Test { public: - ncDevicePlatform_t platform = ncDevicePlatform_t::NC_MYRIAD_X; PluginConfiguration config; StageBuilder::Ptr stageBuilder; diff --git a/inference-engine/tests/unit/vpu/blob_reader_tests.cpp b/inference-engine/tests/unit/vpu/blob_reader_tests.cpp index 65f16f6cae007c..8c3e9a86aed7aa 100644 --- a/inference-engine/tests/unit/vpu/blob_reader_tests.cpp +++ b/inference-engine/tests/unit/vpu/blob_reader_tests.cpp @@ -51,7 +51,7 @@ class VPUBlobReaderHeaderTests: public ::testing::Test, public testing::WithPara ASSERT_NO_THROW(_network = InferenceEngine::CNNNetwork(fn_ptr)); auto log = std::make_shared("GraphCompiler", LogLevel::None, consoleOutput()); - _compiledGraph = compileNetwork(_network, ncDevicePlatform_t::NC_MYRIAD_X, createConfiguration(), log, _mockCore); + _compiledGraph = compileNetwork(_network, createConfiguration(), log, _mockCore); } CNNNetwork _network; diff --git a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/aot_behavior_tests.cpp b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/aot_behavior_tests.cpp index b67029dbedcc2e..b0b0cbffa7f3f9 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/aot_behavior_tests.cpp +++ b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/aot_behavior_tests.cpp @@ -127,7 +127,6 @@ class AOTBehaviorTests : public BehaviorPluginTest { #endif // _WIN32 ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_ANY_PROTOCOL; - deviceDesc.platform = NC_ANY_PLATFORM; ncDeviceOpenParams_t deviceOpenParams = {}; deviceOpenParams.watchdogHndl = m_watchdogHndl; diff --git a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_devices.cpp b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_devices.cpp index 5016a4a3b9d8b3..c31465b19287d7 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_devices.cpp +++ b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_devices.cpp @@ -28,11 +28,9 @@ MyriadDevicesInfo::MyriadDevicesInfo() { std::vector MyriadDevicesInfo::getDevicesList( const ncDeviceProtocol_t deviceProtocol, - const ncDevicePlatform_t devicePlatform, const XLinkDeviceState_t state) { deviceDesc_t req_deviceDesc = {}; req_deviceDesc.protocol = convertProtocolToXlink(deviceProtocol); - req_deviceDesc.platform = convertPlatformToXlink(devicePlatform); deviceDesc_t deviceDescArray[NC_MAX_DEVICES] = {}; unsigned int foundDevices = 0; @@ -49,11 +47,9 @@ std::vector MyriadDevicesInfo::getDevicesList( int MyriadDevicesInfo::getAmountOfDevices( const ncDeviceProtocol_t deviceProtocol, - const ncDevicePlatform_t devicePlatform, const XLinkDeviceState_t state) { deviceDesc_t req_deviceDesc = {}; req_deviceDesc.protocol = convertProtocolToXlink(deviceProtocol); - req_deviceDesc.platform = convertPlatformToXlink(devicePlatform); deviceDesc_t deviceDescArray[NC_MAX_DEVICES] = {}; unsigned int foundDevices = 0; diff --git a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_devices.hpp b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_devices.hpp index ed9265f868cc5a..ad7faee1969659 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_devices.hpp +++ b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_devices.hpp @@ -29,7 +29,6 @@ class MyriadDevicesInfo { std::vector getDevicesList( const ncDeviceProtocol_t deviceProtocol = NC_ANY_PROTOCOL, - const ncDevicePlatform_t devicePlatform = NC_ANY_PLATFORM, const XLinkDeviceState_t state = X_LINK_ANY_STATE); inline bool isMyriadXDevice(const std::string &device_name); @@ -39,7 +38,6 @@ class MyriadDevicesInfo { inline bool isMyriadUnbootedDevice(const std::string &device_name); int getAmountOfDevices(const ncDeviceProtocol_t deviceProtocol = NC_ANY_PROTOCOL, - const ncDevicePlatform_t devicePlatform = NC_ANY_PLATFORM, const XLinkDeviceState_t state = X_LINK_ANY_STATE); inline long getAmountOfBootedDevices(const ncDeviceProtocol_t deviceProtocol); @@ -71,9 +69,9 @@ bool MyriadDevicesInfo::isMyriadUnbootedDevice(const std::string &device_name) { } long MyriadDevicesInfo::getAmountOfUnbootedDevices(const ncDeviceProtocol_t deviceProtocol) { - return getAmountOfDevices(deviceProtocol, NC_ANY_PLATFORM, X_LINK_UNBOOTED); + return getAmountOfDevices(deviceProtocol, X_LINK_UNBOOTED); } long MyriadDevicesInfo::getAmountOfBootedDevices(const ncDeviceProtocol_t deviceProtocol) { - return getAmountOfDevices(deviceProtocol, NC_ANY_PLATFORM, X_LINK_BOOTED); + return getAmountOfDevices(deviceProtocol, X_LINK_BOOTED); } diff --git a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_load_network_case.cpp b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_load_network_case.cpp index 1dd11961d06a0e..3801ff0077e3a4 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_load_network_case.cpp +++ b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/helpers/myriad_load_network_case.cpp @@ -25,6 +25,6 @@ void MyriadLoadNetworkTestCase::LoadNetwork() { } bool MyriadLoadNetworkTestCase::IsDeviceAvailable(std::string device_name) { - auto act_devices = getDevicesList(NC_ANY_PROTOCOL, NC_ANY_PLATFORM, X_LINK_UNBOOTED); + auto act_devices = getDevicesList(NC_ANY_PROTOCOL, X_LINK_UNBOOTED); return std::find(act_devices.begin(), act_devices.end(), device_name) != act_devices.end(); } diff --git a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_boot_tests.cpp b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_boot_tests.cpp index 0998c48e25cf96..95fa056270b209 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_boot_tests.cpp +++ b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_boot_tests.cpp @@ -45,7 +45,7 @@ class MYRIADBoot : public MyriadDevicesInfo, * @brief Boot any free device */ void bootOneDevice() { - ASSERT_NO_ERROR(ncDeviceLoadFirmware(NC_ANY_PLATFORM, firmwareDir)); + ASSERT_NO_ERROR(ncDeviceLoadFirmware(firmwareDir)); } }; diff --git a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_watchdog_tests.cpp b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_watchdog_tests.cpp index 6e4e6f38519990..1362e9e82bdf0d 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_watchdog_tests.cpp +++ b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_watchdog_tests.cpp @@ -84,7 +84,6 @@ class MYRIADWatchdog : public BehaviorPluginTest, ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_ANY_PROTOCOL; - deviceDesc.platform = NC_ANY_PLATFORM; ncDeviceOpenParams_t deviceOpenParams = {}; deviceOpenParams.watchdogHndl = m_watchdogHndl; diff --git a/inference-engine/tests_deprecated/behavior/vpu/shared_tests_instances/plugin_tests/vpu_test_data.hpp b/inference-engine/tests_deprecated/behavior/vpu/shared_tests_instances/plugin_tests/vpu_test_data.hpp index 6a1ab38d36a4e2..64e0a577f9a87f 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/shared_tests_instances/plugin_tests/vpu_test_data.hpp +++ b/inference-engine/tests_deprecated/behavior/vpu/shared_tests_instances/plugin_tests/vpu_test_data.hpp @@ -81,10 +81,6 @@ const std::vector deviceSpecificConfigurations = { BEH_MYRIAD.withConfig({{InferenceEngine::MYRIAD_PROTOCOL, InferenceEngine::MYRIAD_USB}}), BEH_MYRIAD.withConfig({{InferenceEngine::MYRIAD_PROTOCOL, InferenceEngine::MYRIAD_PCIE}}), - // Deprecated - BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(PLATFORM), VPU_MYRIAD_CONFIG_VALUE(2450)}}), - BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(PLATFORM), VPU_MYRIAD_CONFIG_VALUE(2480)}}), - BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(PROTOCOL), VPU_MYRIAD_CONFIG_VALUE(USB)}}), BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(PROTOCOL), VPU_MYRIAD_CONFIG_VALUE(PCIE)}}), }; @@ -192,17 +188,6 @@ const BehTestParams withIncorrectConfValues[] = { BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(MOVIDIUS_DDR_TYPE), "-1"}}), BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(MOVIDIUS_DDR_TYPE), "MICRON"}}), - - BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "-1"}}), - BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "0"}}), - BEH_MYRIAD.withConfig({{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "1"}}), - - BEH_MULTI_CONFIG.withConfig({{MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, "MYRIAD"}, - {VPU_MYRIAD_CONFIG_KEY(PLATFORM), "-1"}}), - BEH_MULTI_CONFIG.withConfig({{MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, "MYRIAD"}, - {VPU_MYRIAD_CONFIG_KEY(PLATFORM), "0"}}), - BEH_MULTI_CONFIG.withConfig({{MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, "MYRIAD"}, - {VPU_MYRIAD_CONFIG_KEY(PLATFORM), "1"}}), }; const BehTestParams withIncorrectConfKeys[] = { diff --git a/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_blob_test.cpp b/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_blob_test.cpp index 6128ac1ee1bd17..2dba65615b7559 100644 --- a/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_blob_test.cpp +++ b/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_blob_test.cpp @@ -197,7 +197,6 @@ TEST_F(myriadConfigsWithBlobImportTests_smoke, TryingToSetRuntimeOptionDoesNotPr {InferenceEngine::MYRIAD_ENABLE_RECEIVING_TENSOR_TIME, CONFIG_VALUE(YES)} }; if (vpu::tests::deviceForceReset()) { config.insert({InferenceEngine::MYRIAD_ENABLE_FORCE_RESET, CONFIG_VALUE(NO)}); - config.insert({VPU_MYRIAD_CONFIG_KEY(PLATFORM), VPU_MYRIAD_CONFIG_VALUE(2480)}); } InferenceEngine::ExecutableNetwork importedNetwork; diff --git a/inference-engine/tests_deprecated/functional/vpu/graph_transformer/gt_functional_tests.cpp b/inference-engine/tests_deprecated/functional/vpu/graph_transformer/gt_functional_tests.cpp index 209a4ef3057be2..b6b82f72eb25fa 100644 --- a/inference-engine/tests_deprecated/functional/vpu/graph_transformer/gt_functional_tests.cpp +++ b/inference-engine/tests_deprecated/functional/vpu/graph_transformer/gt_functional_tests.cpp @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -66,12 +65,11 @@ void graphTransformerFunctionalTests::SetUp() { vpuLayersTests::SetUp(); _stageBuilder = std::make_shared(); - _platform = CheckMyriadX() ? ncDevicePlatform_t::NC_MYRIAD_X : ncDevicePlatform_t::NC_MYRIAD_2; } void graphTransformerFunctionalTests::CreateModel() { const auto compilerLog = std::make_shared("Test", LogLevel::Info, consoleOutput()); - CompileEnv::init(_platform, _configuration, compilerLog); + CompileEnv::init(_configuration, compilerLog); AutoScope autoDeinit([] { CompileEnv::free(); }); @@ -147,7 +145,6 @@ IE_SUPPRESS_DEPRECATED_START _configuration.registerDeprecatedOption(VPU_CONFIG_KEY(CUSTOM_LAYERS)); _configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(MOVIDIUS_DDR_TYPE)); _configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(FORCE_RESET)); - _configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(PLATFORM)); IE_SUPPRESS_DEPRECATED_END _inputsInfo.clear(); @@ -192,7 +189,6 @@ int64_t graphTransformerFunctionalTests::CompileAndInfer(Blob::Ptr& inputBlob, B auto compiledGraph = compileModel( _gtModel, - _platform, _configuration, compilerLog); diff --git a/inference-engine/tests_deprecated/functional/vpu/graph_transformer/gt_functional_tests.hpp b/inference-engine/tests_deprecated/functional/vpu/graph_transformer/gt_functional_tests.hpp index ff3063b217f7f2..535a694d681d4f 100644 --- a/inference-engine/tests_deprecated/functional/vpu/graph_transformer/gt_functional_tests.hpp +++ b/inference-engine/tests_deprecated/functional/vpu/graph_transformer/gt_functional_tests.hpp @@ -31,6 +31,5 @@ class graphTransformerFunctionalTests : public vpuLayersTests { vpu::Data _dataIntermediate; private: - ncDevicePlatform_t _platform = ncDevicePlatform_t::NC_MYRIAD_X; InferenceEngine::ExecutableNetwork _executableNetwork; }; diff --git a/inference-engine/tests_deprecated/functional/vpu/myriad_tests/myriad_configs_tests.cpp b/inference-engine/tests_deprecated/functional/vpu/myriad_tests/myriad_configs_tests.cpp index 70fdb6c20d2fb7..800a13ca39bf28 100644 --- a/inference-engine/tests_deprecated/functional/vpu/myriad_tests/myriad_configs_tests.cpp +++ b/inference-engine/tests_deprecated/functional/vpu/myriad_tests/myriad_configs_tests.cpp @@ -58,18 +58,6 @@ TEST_P(myriadIncorrectModelsConfigsTests_nightly, LoadNetworkWithIncorrectConfig // Tests initiation //------------------------------------------------------------------------------ -static const std::vector myriadCorrectPlatformConfigValues = { - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), VPU_MYRIAD_CONFIG_VALUE(2450)}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), VPU_MYRIAD_CONFIG_VALUE(2480)}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), ""}} -}; - -static const std::vector myriadIncorrectPlatformConfigValues = { - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "-1"}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), " 0"}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "MyriadX"}} -}; - static const std::vector myriadCorrectPackageTypeConfigValues = { // Please do not use other types of DDR in tests with a real device, because it may hang. {{InferenceEngine::MYRIAD_DDR_TYPE, InferenceEngine::MYRIAD_DDR_AUTO}}, @@ -87,12 +75,6 @@ static const std::vector myriadIncorrectPackageTypeConfigValues = { {{VPU_MYRIAD_CONFIG_KEY(MOVIDIUS_DDR_TYPE), "-MICRON_1GB"}}, }; -INSTANTIATE_TEST_SUITE_P(MyriadConfigs, myriadCorrectModelsConfigsTests_nightly, - ::testing::ValuesIn(myriadCorrectPlatformConfigValues)); - -INSTANTIATE_TEST_SUITE_P(MyriadConfigs, myriadIncorrectModelsConfigsTests_nightly, - ::testing::ValuesIn(myriadIncorrectPlatformConfigValues)); - INSTANTIATE_TEST_SUITE_P(MyriadPackageConfigs, myriadCorrectModelsConfigsTests_nightly, ::testing::ValuesIn(myriadCorrectPackageTypeConfigValues)); diff --git a/inference-engine/tests_deprecated/helpers/tests_vpu_common.hpp b/inference-engine/tests_deprecated/helpers/tests_vpu_common.hpp index 18d17be9337dfc..1ea84fc4fde1cf 100644 --- a/inference-engine/tests_deprecated/helpers/tests_vpu_common.hpp +++ b/inference-engine/tests_deprecated/helpers/tests_vpu_common.hpp @@ -62,16 +62,8 @@ static bool hasMyriad2() { static bool hasAppropriateStick(const config_t &config) { bool suitsConfig; - auto platform = config.find(VPU_MYRIAD_CONFIG_KEY(PLATFORM)); - if (platform == config.end() || platform->second.empty()) { - suitsConfig = hasMyriad2() || hasMyriadX(); - } else { - bool hasRequestedMyriad2 = - platform->second == VPU_MYRIAD_CONFIG_VALUE(2450) && hasMyriad2(); - bool hasRequestedMyriadX = - platform->second == VPU_MYRIAD_CONFIG_VALUE(2480) && hasMyriadX(); - suitsConfig = hasRequestedMyriad2 || hasRequestedMyriadX; - } + bool hasRequestedMyriadX = hasMyriadX(); + suitsConfig = hasRequestedMyriadX; return suitsConfig; } diff --git a/inference-engine/tests_deprecated/unit/engines/vpu/graph_transformer_tests.cpp b/inference-engine/tests_deprecated/unit/engines/vpu/graph_transformer_tests.cpp index eedf042217c202..a75d0ba76217a7 100644 --- a/inference-engine/tests_deprecated/unit/engines/vpu/graph_transformer_tests.cpp +++ b/inference-engine/tests_deprecated/unit/engines/vpu/graph_transformer_tests.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -264,7 +263,6 @@ IE_SUPPRESS_DEPRECATED_START configuration.registerDeprecatedOption(VPU_CONFIG_KEY(CUSTOM_LAYERS)); configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(MOVIDIUS_DDR_TYPE)); configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(FORCE_RESET)); - configuration.registerDeprecatedOption(VPU_MYRIAD_CONFIG_KEY(PLATFORM)); IE_SUPPRESS_DEPRECATED_END return configuration; @@ -310,7 +308,7 @@ void GraphTransformerTest::InitCompileEnv() { ? InferenceEngine::PluginConfigParams::YES : InferenceEngine::PluginConfigParams::NO); } - CompileEnv::init(platform, config, _log); + CompileEnv::init(config, _log); compileEnvInitialized = true; } diff --git a/inference-engine/tests_deprecated/unit/engines/vpu/graph_transformer_tests.hpp b/inference-engine/tests_deprecated/unit/engines/vpu/graph_transformer_tests.hpp index 94d394b4c09fb0..6b6ea91212aef0 100644 --- a/inference-engine/tests_deprecated/unit/engines/vpu/graph_transformer_tests.hpp +++ b/inference-engine/tests_deprecated/unit/engines/vpu/graph_transformer_tests.hpp @@ -180,7 +180,6 @@ PluginConfiguration createConfiguration(); class GraphTransformerTest : public TestsCommon { public: - ncDevicePlatform_t platform = ncDevicePlatform_t::NC_MYRIAD_X; PluginConfiguration config; StageBuilder::Ptr stageBuilder; diff --git a/inference-engine/tests_deprecated/unit/engines/vpu/myriad_tests/myriad_engine_tests.cpp b/inference-engine/tests_deprecated/unit/engines/vpu/myriad_tests/myriad_engine_tests.cpp index 7bd1ad415b9937..e2222fbc86d796 100644 --- a/inference-engine/tests_deprecated/unit/engines/vpu/myriad_tests/myriad_engine_tests.cpp +++ b/inference-engine/tests_deprecated/unit/engines/vpu/myriad_tests/myriad_engine_tests.cpp @@ -22,20 +22,6 @@ TEST_P(MyriadEngineSetIncorrectConfigTest, SetIncorrectConfig) { IE_SUPPRESS_DEPRECATED_START -static const std::vector myriadCorrectPlatformConfigValues = { - // Deprecated - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), VPU_MYRIAD_CONFIG_VALUE(2450)}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), VPU_MYRIAD_CONFIG_VALUE(2480)}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), ""}} -}; - -static const std::vector myriadIncorrectPlatformConfigValues = { - // Deprecated - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "-1"}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), " 0"}}, - {{VPU_MYRIAD_CONFIG_KEY(PLATFORM), "MyriadX"}} -}; - static const std::vector myriadCorrectProtocolConfigValues = { {{InferenceEngine::MYRIAD_PROTOCOL, InferenceEngine::MYRIAD_PCIE}}, {{InferenceEngine::MYRIAD_PROTOCOL, InferenceEngine::MYRIAD_USB}}, @@ -50,12 +36,10 @@ static const std::vector myriadCorrectProtocolConfigValues = { static const std::vector myriadIncorrectProtocolConfigValues = { // Protocols {{InferenceEngine::MYRIAD_PROTOCOL, "0"}}, - {{InferenceEngine::MYRIAD_PROTOCOL, "2450"}}, {{InferenceEngine::MYRIAD_PROTOCOL, "PCI"}}, // Deprecated {{VPU_MYRIAD_CONFIG_KEY(PROTOCOL), "0"}}, - {{VPU_MYRIAD_CONFIG_KEY(PROTOCOL), "2450"}}, {{VPU_MYRIAD_CONFIG_KEY(PROTOCOL), "PCI"}}, }; @@ -106,13 +90,6 @@ static const std::vector myriadIncorrectPackageTypeConfigValues = { IE_SUPPRESS_DEPRECATED_END -/// Platform -INSTANTIATE_TEST_SUITE_P(MyriadPlatformConfigs, MyriadEngineSetCorrectConfigTest, - ::testing::ValuesIn(myriadCorrectPlatformConfigValues)); - -INSTANTIATE_TEST_SUITE_P(MyriadPlatformConfigs, MyriadEngineSetIncorrectConfigTest, - ::testing::ValuesIn(myriadIncorrectPlatformConfigValues)); - /// Protocol INSTANTIATE_TEST_SUITE_P(MyriadProtocolConfigs, MyriadEngineSetCorrectConfigTest, ::testing::ValuesIn(myriadCorrectProtocolConfigValues)); diff --git a/inference-engine/thirdparty/movidius/mvnc/include/mvnc.h b/inference-engine/thirdparty/movidius/mvnc/include/mvnc.h index b4585e14aa3c85..c25f7cebdea154 100644 --- a/inference-engine/thirdparty/movidius/mvnc/include/mvnc.h +++ b/inference-engine/thirdparty/movidius/mvnc/include/mvnc.h @@ -124,12 +124,6 @@ typedef enum { NC_RW_ENABLE_ASYNC_DMA = 2102 // enable/disable asynchronous DMA on device } ncDeviceOption_t; -typedef enum { - NC_ANY_PLATFORM = 0, - NC_MYRIAD_2 = 2450, - NC_MYRIAD_X = 2480, -} ncDevicePlatform_t; - typedef enum { NC_ANY_PROTOCOL = 0, NC_USB, @@ -158,7 +152,6 @@ struct ncDeviceHandle_t { struct ncDeviceDescr_t { ncDeviceProtocol_t protocol; - ncDevicePlatform_t platform; char name[NC_MAX_NAME_SIZE]; }; diff --git a/inference-engine/thirdparty/movidius/mvnc/include/mvnc_data.h b/inference-engine/thirdparty/movidius/mvnc/include/mvnc_data.h index a010e91289357a..331c0bfbaa90cd 100644 --- a/inference-engine/thirdparty/movidius/mvnc/include/mvnc_data.h +++ b/inference-engine/thirdparty/movidius/mvnc/include/mvnc_data.h @@ -16,8 +16,7 @@ extern "C" XLinkProtocol_t convertProtocolToXlink(const ncDeviceProtocol_t ncProtocol); ncDeviceProtocol_t convertProtocolToNC(const XLinkProtocol_t xLinkProtocol); -XLinkPlatform_t convertPlatformToXlink(const ncDevicePlatform_t ncProtocol); -ncDevicePlatform_t convertPlatformToNC(const XLinkPlatform_t xLinkProtocol); +XLinkPlatform_t convertPlatformToXlink(); int copyNcDeviceDescrToXLink( const struct ncDeviceDescr_t *in_ncDeviceDesc, deviceDesc_t *out_deviceDesc); diff --git a/inference-engine/thirdparty/movidius/mvnc/include/mvnc_ext.h b/inference-engine/thirdparty/movidius/mvnc/include/mvnc_ext.h index 66155be76f6686..2efafb610e76e5 100644 --- a/inference-engine/thirdparty/movidius/mvnc/include/mvnc_ext.h +++ b/inference-engine/thirdparty/movidius/mvnc/include/mvnc_ext.h @@ -16,14 +16,14 @@ extern "C" * @param devicePlatform Platform to boot * @param customFirmwareDir Path to directory with firmware to load. If NULL, use default */ -MVNC_EXPORT_API ncStatus_t ncDeviceLoadFirmware(const ncDevicePlatform_t devicePlatform, const char* customFirmwareDir); +MVNC_EXPORT_API ncStatus_t ncDeviceLoadFirmware(const char* customFirmwareDir); /** * @brief Reset all devices */ MVNC_EXPORT_API ncStatus_t ncDeviceResetAll(); -MVNC_EXPORT_API char* ncPlatformToStr(ncDevicePlatform_t devicePlatform); +MVNC_EXPORT_API char* ncPlatformToStr(); MVNC_EXPORT_API char* ncProtocolToStr(ncDeviceProtocol_t deviceProtocol); #ifdef __cplusplus diff --git a/inference-engine/thirdparty/movidius/mvnc/src/mvnc_api.c b/inference-engine/thirdparty/movidius/mvnc/src/mvnc_api.c index 03447a36a9a566..de5d39bb7c80e5 100644 --- a/inference-engine/thirdparty/movidius/mvnc/src/mvnc_api.c +++ b/inference-engine/thirdparty/movidius/mvnc/src/mvnc_api.c @@ -150,12 +150,8 @@ char* ncProtocolToStr(const ncDeviceProtocol_t deviceProtocol) { } } -char* ncPlatformToStr(const ncDevicePlatform_t platform) { - switch(platform) { - case NC_MYRIAD_2: return "NC_MYRIAD_2"; - case NC_MYRIAD_X: return "NC_MYRIAD_X"; - default: return "NC_ANY_PLATFORM"; - } +char* ncPlatformToStr() { + return "NC_MYRIAD_X"; } int mvnc_memcpy(void* dest, size_t destsz, void const* src, size_t count) { @@ -1186,21 +1182,20 @@ ncStatus_t ncAvailableDevices(struct ncDeviceDescr_t *deviceDescrPtr, return NC_OK; } -ncStatus_t ncDeviceLoadFirmware(const ncDevicePlatform_t devicePlatform, const char* customFirmwareDir) { - mvLog(MVLOG_WARN, "Boot (%s) without connecting to it", ncPlatformToStr(devicePlatform)); +ncStatus_t ncDeviceLoadFirmware(const char* customFirmwareDir) { + mvLog(MVLOG_WARN, "Boot (%s) without connecting to it", ""); XLinkError_t rc; ncStatus_t sc; // Find device with specific platform deviceDesc_t deviceDesc = {0}; deviceDesc_t in_deviceDesc = { - .platform = convertPlatformToXlink(devicePlatform), .protocol = X_LINK_USB_VSC }; rc = XLinkFindFirstSuitableDevice(X_LINK_UNBOOTED, in_deviceDesc, &deviceDesc); if (rc) { - mvLog(MVLOG_WARN, "Failed to find (%s) platform device", ncPlatformToStr(devicePlatform)); + mvLog(MVLOG_WARN, "Failed to find (%s) platform device", ""); return NC_DEVICE_NOT_FOUND; } @@ -2668,14 +2663,7 @@ static ncStatus_t getDeviceOption(struct _devicePrivate_t *d, mv_strncpy((char *) data, *dataLength, d->dev_addr, *dataLength - 1); break; case NC_RO_DEVICE_PLATFORM: - if (d->dev_attr.fw_version[1] == 0x2480){ - *(ncDevicePlatform_t *) data = NC_MYRIAD_X; - } else if (d->dev_attr.fw_version[1] == 0x2450) { - *(ncDevicePlatform_t *) data = NC_MYRIAD_2; - } else { - *(ncDevicePlatform_t *) data = NC_ANY_PLATFORM; - } - *dataLength = sizeof(ncDevicePlatform_t); + *dataLength = sizeof(data); break; case NC_RO_DEVICE_PROTOCOL: *(ncDeviceProtocol_t *) data = convertProtocolToNC(d->protocol); @@ -2821,7 +2809,7 @@ ncStatus_t ncDeviceGetOption(struct ncDeviceHandle_t * deviceHandle, CHECK_HANDLE_CORRECT(deviceHandle); ncStatus_t rc; - if (!dataLength || (*dataLength != 0 && !data)) { + if (!dataLength) { mvLog(MVLOG_ERROR, "Some of the parameters are NULL"); return NC_INVALID_PARAMETERS; } diff --git a/inference-engine/thirdparty/movidius/mvnc/src/mvnc_data.c b/inference-engine/thirdparty/movidius/mvnc/src/mvnc_data.c index ddebe959e4adac..b8ceafc0504049 100644 --- a/inference-engine/thirdparty/movidius/mvnc/src/mvnc_data.c +++ b/inference-engine/thirdparty/movidius/mvnc/src/mvnc_data.c @@ -35,35 +35,12 @@ ncDeviceProtocol_t convertProtocolToNC( } } -XLinkPlatform_t convertPlatformToXlink( - const ncDevicePlatform_t ncProtocol) { - switch (ncProtocol) { - case NC_ANY_PLATFORM: return X_LINK_ANY_PLATFORM; - case NC_MYRIAD_2: return X_LINK_MYRIAD_2; - case NC_MYRIAD_X: return X_LINK_MYRIAD_X; - default: return X_LINK_ANY_PLATFORM; - } -} - -ncDevicePlatform_t convertPlatformToNC( - const XLinkPlatform_t xLinkProtocol) { - switch (xLinkProtocol) { - case X_LINK_ANY_PLATFORM: return NC_ANY_PLATFORM; - case X_LINK_MYRIAD_2: return NC_MYRIAD_2; - case X_LINK_MYRIAD_X: return NC_MYRIAD_X; - default: - mvLog(MVLOG_WARN, "This convertation not supported, set to NC_ANY_PLATFORM"); - return NC_ANY_PLATFORM; - } -} - int copyNcDeviceDescrToXLink(const struct ncDeviceDescr_t *in_ncDeviceDesc, deviceDesc_t *out_deviceDesc) { CHECK_HANDLE_CORRECT(in_ncDeviceDesc); CHECK_HANDLE_CORRECT(out_deviceDesc); out_deviceDesc->protocol = convertProtocolToXlink(in_ncDeviceDesc->protocol); - out_deviceDesc->platform = convertPlatformToXlink(in_ncDeviceDesc->platform); mv_strncpy(out_deviceDesc->name, XLINK_MAX_NAME_SIZE, in_ncDeviceDesc->name, XLINK_MAX_NAME_SIZE - 1); return NC_OK; @@ -75,7 +52,6 @@ int copyXLinkDeviceDescrToNc(const deviceDesc_t *in_DeviceDesc, CHECK_HANDLE_CORRECT(out_ncDeviceDesc); out_ncDeviceDesc->protocol = convertProtocolToNC(in_DeviceDesc->protocol); - out_ncDeviceDesc->platform = convertPlatformToNC(in_DeviceDesc->platform); mv_strncpy(out_ncDeviceDesc->name, XLINK_MAX_NAME_SIZE, in_DeviceDesc->name, XLINK_MAX_NAME_SIZE - 1); return NC_OK; diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_common_test_cases.cpp b/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_common_test_cases.cpp index f21da7a63addb9..bb66bef31e1b5d 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_common_test_cases.cpp +++ b/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_common_test_cases.cpp @@ -57,7 +57,6 @@ void MvncTestsCommon::openDevices(const int devicesToBoot, ncDeviceHandle_t **de amountOfBooted = 0; ncDeviceDescr_t ncDeviceDesc = {}; ncDeviceDesc.protocol = NC_USB; - ncDeviceDesc.platform = NC_ANY_PLATFORM; for (int index = 0; index < devicesToBoot; ++index) { ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandlers[index], ncDeviceDesc, m_ncDeviceOpenParams)); @@ -71,7 +70,7 @@ void MvncTestsCommon::bootOneDevice(ncDeviceProtocol_t deviceProtocol) { if (deviceProtocol == NC_PCIE) { GTEST_FATAL_FAILURE_("Boot doesn't supported for PCIe protocol\n"); } - ASSERT_NO_ERROR(ncDeviceLoadFirmware(NC_ANY_PLATFORM, firmwareDir)); + ASSERT_NO_ERROR(ncDeviceLoadFirmware(firmwareDir)); } @@ -123,7 +122,6 @@ void MvncLoggingTests::SetUp() { MvncOpenDevice::SetUp(); _deviceDesc.protocol = _deviceProtocol; - _deviceDesc.platform = NC_ANY_PLATFORM; for (int index = 0; index < availableDevices_; ++index) { ASSERT_NO_ERROR(ncDeviceOpen(&_deviceHandles[index], _deviceDesc, m_ncDeviceOpenParams)); diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_common_test_cases.h b/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_common_test_cases.h index ba513c23dccca4..496caaa95a8647 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_common_test_cases.h +++ b/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_common_test_cases.h @@ -137,12 +137,6 @@ static const std::vector myriadProtocols = { NC_PCIE }; -static const std::vector myriadPlatforms = { - NC_MYRIAD_2, - NC_MYRIAD_X -}; - - namespace { /** * @brief Converter from enum to string @@ -153,9 +147,8 @@ namespace { return ncProtocolToStr(info.param); } - std::string operator()( - const ::testing::TestParamInfo &info) const { - return std::string("USB_") + ncPlatformToStr(info.param); + std::string operator()() const { + return std::string("USB_"); } }; } diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_usb_test_cases.cpp b/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_usb_test_cases.cpp index 3f288b12412474..9f6913066e603d 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_usb_test_cases.cpp +++ b/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_usb_test_cases.cpp @@ -14,7 +14,6 @@ void MvncOpenUSBDevice::SetUp() { availableDevices_ = getAmountOfNotBootedDevices(NC_USB); deviceDesc_.protocol = NC_USB; - deviceDesc_.platform = NC_ANY_PLATFORM; } //------------------------------------------------------------------------------ diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_usb_test_cases.h b/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_usb_test_cases.h index 3714e0b98e9f71..aecce0815b0628 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_usb_test_cases.h +++ b/inference-engine/thirdparty/movidius/mvnc/tests/cases/mvnc_usb_test_cases.h @@ -29,12 +29,11 @@ class MvncCloseUSBDevice : public MvncOpenUSBDevice { //------------------------------------------------------------------------------ // class MvncDevicePlatform //------------------------------------------------------------------------------ -class MvncDevicePlatform : public MvncOpenUSBDevice, - public testing::WithParamInterface{ +class MvncDevicePlatform : public MvncOpenUSBDevice + { public: long available_myriadX_ = 0; long available_myriad2_ = 0; - ncDevicePlatform_t devicePlatform_; ~MvncDevicePlatform() override = default; diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/helpers/mvnc_test_helper.cpp b/inference-engine/thirdparty/movidius/mvnc/tests/helpers/mvnc_test_helper.cpp index 57c39e9adab345..dea7cf0d2a7dcf 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/helpers/mvnc_test_helper.cpp +++ b/inference-engine/thirdparty/movidius/mvnc/tests/helpers/mvnc_test_helper.cpp @@ -10,11 +10,9 @@ // Implementations of helpers - counters //------------------------------------------------------------------------------ int getAmountOfDevices(const ncDeviceProtocol_t deviceProtocol, - const ncDevicePlatform_t devicePlatform, const XLinkDeviceState_t state) { deviceDesc_t req_deviceDesc = {}; req_deviceDesc.protocol = convertProtocolToXlink(deviceProtocol); - req_deviceDesc.platform = convertPlatformToXlink(devicePlatform); deviceDesc_t deviceDescArray[NC_MAX_DEVICES] = {}; unsigned int foundDevices = 0; @@ -24,22 +22,6 @@ int getAmountOfDevices(const ncDeviceProtocol_t deviceProtocol, return foundDevices; } -long getAmountOfMyriadXDevices(ncDeviceProtocol_t deviceProtocol) { - return getAmountOfDevices(deviceProtocol, NC_MYRIAD_X); -} - -long getAmountOfMyriad2Devices(ncDeviceProtocol_t deviceProtocol) { - return getAmountOfDevices(deviceProtocol, NC_MYRIAD_2); -} - -long getAmountOfBootedDevices(ncDeviceProtocol_t deviceProtocol) { - return getAmountOfDevices(deviceProtocol, NC_ANY_PLATFORM, X_LINK_BOOTED); -} - -long getAmountOfNotBootedDevices(ncDeviceProtocol_t deviceProtocol) { - return getAmountOfDevices(deviceProtocol, NC_ANY_PLATFORM, X_LINK_UNBOOTED); -} - long getAmountOfPCIeDevices() { return getAmountOfDevices(NC_PCIE); } @@ -52,12 +34,10 @@ long getAmountOfUSBDevices() { // Implementations of helpers - get devices //------------------------------------------------------------------------------ std::vector getDevicesList(const ncDeviceProtocol_t deviceProtocol, - const ncDevicePlatform_t devicePlatform, const XLinkDeviceState_t state) { deviceDesc_t req_deviceDesc = {}; req_deviceDesc.protocol = convertProtocolToXlink(deviceProtocol); - req_deviceDesc.platform = convertPlatformToXlink(devicePlatform); deviceDesc_t deviceDescArray[NC_MAX_DEVICES] = {}; unsigned int foundDevices = 0; @@ -112,16 +92,8 @@ bool isSameProtocolDevice(const std::string &deviceName, const ncDeviceProtocol_ } bool -isSamePlatformUSBDevice(const std::string &deviceName, const ncDevicePlatform_t expectedPlatform) { - switch (expectedPlatform) { - case NC_MYRIAD_2: return isMyriad2USBDevice(deviceName); - case NC_MYRIAD_X: return isMyriadXUSBDevice(deviceName); - case NC_ANY_PLATFORM: - return isMyriad2USBDevice(deviceName) || isMyriadXUSBDevice(deviceName); - default: - std::cout << "Unknown device platform" << std::endl; - return false; - } +isSamePlatformUSBDevice(const std::string &deviceName) { + return isMyriadXUSBDevice(deviceName); } //------------------------------------------------------------------------------ diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/helpers/mvnc_test_helper.h b/inference-engine/thirdparty/movidius/mvnc/tests/helpers/mvnc_test_helper.h index c6c8d8ae715248..9ddef27cb120f6 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/helpers/mvnc_test_helper.h +++ b/inference-engine/thirdparty/movidius/mvnc/tests/helpers/mvnc_test_helper.h @@ -56,7 +56,6 @@ extern "C" void initialize_usb_boot(); * @param[in] deviceProtocol Count only platform specific devices */ int getAmountOfDevices(const ncDeviceProtocol_t deviceProtocol = NC_ANY_PROTOCOL, - const ncDevicePlatform_t devicePlatform = NC_ANY_PLATFORM, const XLinkDeviceState_t state = X_LINK_ANY_STATE); long getAmountOfMyriadXDevices(ncDeviceProtocol_t deviceProtocol = NC_ANY_PROTOCOL); @@ -79,7 +78,6 @@ long getAmountOfUSBDevices(); */ std::vector getDevicesList( const ncDeviceProtocol_t deviceProtocol = NC_ANY_PROTOCOL, - const ncDevicePlatform_t devicePlatform = NC_ANY_PLATFORM, const XLinkDeviceState_t state = X_LINK_ANY_STATE); //------------------------------------------------------------------------------ @@ -107,8 +105,7 @@ bool isSameProtocolDevice(const std::string &deviceName, /** * @brief Check that device matches the specified platform for USB */ -bool isSamePlatformUSBDevice(const std::string &deviceName, - const ncDevicePlatform_t expectedPlatform); +bool isSamePlatformUSBDevice(const std::string &deviceName); //------------------------------------------------------------------------------ // Helpers - file loader diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_no_boot_tests.cpp b/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_no_boot_tests.cpp index fe8c522ac3c311..7b30165be118ea 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_no_boot_tests.cpp +++ b/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_no_boot_tests.cpp @@ -15,7 +15,6 @@ TEST_F(MvncNoBootOpenDevice, OpenAndClose) { ncDeviceHandle_t *deviceHandle = nullptr; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_USB; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle, deviceDesc, watchdogInterval, firmwarePath)); ASSERT_NO_ERROR(ncDeviceClose(&deviceHandle)); @@ -28,7 +27,6 @@ TEST_F(MvncNoBootOpenDevice, OpenTwiceSameHandler) { ncDeviceHandle_t *deviceHandle = nullptr; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_USB; - deviceDesc.platform = NC_ANY_PLATFORM; char dev_addr_first_open[MAX_DEV_NAME]; unsigned int data_length_first = MAX_DEV_NAME; @@ -60,7 +58,6 @@ TEST_F(MvncNoBootOpenDevice, OpenDeviceWithOneXLinkInitializion) { ncDeviceHandle_t *deviceHandle = nullptr; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_USB; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle, deviceDesc, watchdogInterval, firmwarePath)); ASSERT_NO_ERROR(ncDeviceClose(&deviceHandle)); @@ -93,7 +90,6 @@ TEST_F(MvncNoBootCloseDevice, AlreadyBootedDeviceWillNotReboot) { ncDeviceHandle_t *deviceHandle = nullptr; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_USB; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle, deviceDesc, watchdogInterval, firmwarePath)); ASSERT_NO_ERROR(ncDeviceClose(&deviceHandle)); diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_stress_tests.cpp b/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_stress_tests.cpp index 2f7f74ce63072e..1d0153bd039721 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_stress_tests.cpp +++ b/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_stress_tests.cpp @@ -19,7 +19,6 @@ TEST_P(MvncStressTests, OpenClose1001) { ncDeviceHandle_t *deviceHandle = nullptr; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = _deviceProtocol; - deviceDesc.platform = NC_ANY_PLATFORM; for (int i = 0; i < iterations; ++i) { printf("Iteration %d of %d\n", i, iterations); @@ -36,7 +35,6 @@ TEST_P(MvncStressTests, AllocateDeallocateGraph1001) { const int iterations = 1001; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = _deviceProtocol; - deviceDesc.platform = NC_ANY_PLATFORM; // Load graph const std::string blobPath = "bvlc_googlenet_fp16.blob"; @@ -79,7 +77,6 @@ TEST_P(MvncStressTests, FullCycleOfWork101Times) { const int iterations = 101; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = _deviceProtocol; - deviceDesc.platform = NC_ANY_PLATFORM; const std::string blobPath = "bvlc_googlenet_fp16.blob"; std::vector blob; diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_tests_common.cpp b/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_tests_common.cpp index 11c8c58c7116a5..8a3c9a1162b719 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_tests_common.cpp +++ b/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_tests_common.cpp @@ -92,7 +92,6 @@ TEST_F(MvncTestsCommon, OpenUSBThenPCIEAndClose) { std::string actDeviceName; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_USB; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle_USB, deviceDesc, m_ncDeviceOpenParams)); @@ -127,7 +126,6 @@ TEST_F(MvncTestsCommon, OpenPCIEThenUSBAndClose) { std::string actDeviceName; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_PCIE; - deviceDesc.platform = NC_ANY_PLATFORM; // Open PCIe device ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle_PCIe, deviceDesc, m_ncDeviceOpenParams)); @@ -164,7 +162,6 @@ TEST_P(MvncOpenDevice, OpenAndClose) { std::string deviceName; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = _deviceProtocol; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle, deviceDesc, m_ncDeviceOpenParams)); @@ -190,7 +187,6 @@ TEST_P(MvncOpenDevice, AllHandleFieldsInitialized) { ncDeviceHandle_t* deviceHandle = nullptr; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = _deviceProtocol; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle, deviceDesc, m_ncDeviceOpenParams)); @@ -217,7 +213,6 @@ TEST_P(MvncOpenDevice, OpenTwiceSameHandler) { ncDeviceHandle_t *deviceHandle = nullptr; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = _deviceProtocol; - deviceDesc.platform = NC_ANY_PLATFORM; char dev_addr_first_open[MAX_DEV_NAME]; unsigned int data_length_first = MAX_DEV_NAME; @@ -254,7 +249,6 @@ TEST_P(MvncOpenDevice, DISABLED_OpenSameDeviceTwiceDifferentHandlers) { ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = _deviceProtocol; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle1, deviceDesc, m_ncDeviceOpenParams)); @@ -278,7 +272,6 @@ TEST_P(MvncOpenDevice, OpenTwiceWithOneXLinkInitializion) { ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = _deviceProtocol; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncDeviceOpen(&deviceHandle, deviceDesc, m_ncDeviceOpenParams)); @@ -304,8 +297,7 @@ TEST_P(MvncOpenDevice, WatchdogShouldResetDeviceWithoutConnection) { deviceDesc_t deviceDescToBoot = {}; deviceDesc_t in_deviceDesc = {}; in_deviceDesc.protocol = convertProtocolToXlink(_deviceProtocol); - in_deviceDesc.platform = convertPlatformToXlink(NC_ANY_PLATFORM); - int expectAvailableDevices = getAmountOfDevices(_deviceProtocol, NC_ANY_PLATFORM, X_LINK_UNBOOTED); + int expectAvailableDevices = getAmountOfDevices(_deviceProtocol, X_LINK_UNBOOTED); XLinkError_t rc = X_LINK_ERROR; auto waittm = std::chrono::system_clock::now() + std::chrono::seconds(5); @@ -321,11 +313,11 @@ TEST_P(MvncOpenDevice, WatchdogShouldResetDeviceWithoutConnection) { std::this_thread::sleep_for(5_sec); ASSERT_EQ(expectAvailableDevices - 1, - getAmountOfDevices(_deviceProtocol, NC_ANY_PLATFORM, X_LINK_UNBOOTED)); + getAmountOfDevices(_deviceProtocol, X_LINK_UNBOOTED)); std::this_thread::sleep_for(15_sec); ASSERT_EQ(expectAvailableDevices, - getAmountOfDevices(_deviceProtocol, NC_ANY_PLATFORM, X_LINK_UNBOOTED)); + getAmountOfDevices(_deviceProtocol, X_LINK_UNBOOTED)); } //------------------------------------------------------------------------------ diff --git a/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_tests_usb.cpp b/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_tests_usb.cpp index 5e98b1a77e4261..b30912bdabf39d 100644 --- a/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_tests_usb.cpp +++ b/inference-engine/thirdparty/movidius/mvnc/tests/mvnc_tests_usb.cpp @@ -24,7 +24,6 @@ TEST_F(MvncOpenUSBDevice, ShouldOpenDeviceAfterChangeConnectTimeoutFromZero) { std::string actDeviceName; ncDeviceDescr_t deviceDesc = {}; deviceDesc.protocol = NC_ANY_PROTOCOL; - deviceDesc.platform = NC_ANY_PLATFORM; ASSERT_NO_ERROR(ncSetDeviceConnectTimeout(0)); ASSERT_ERROR(ncDeviceOpen(&deviceHandle, deviceDesc, m_ncDeviceOpenParams)); @@ -175,19 +174,10 @@ TEST_F(MvncOpenUSBDevice, CheckErrorWhenPlatformConflictWithName) { if (availableDevices_ == 0) GTEST_SKIP(); - ncDevicePlatform_t wrongPlatform = NC_ANY_PLATFORM; auto availableDevices = getDevicesList(); ASSERT_TRUE(availableDevices.size()); - - if(isMyriadXUSBDevice(availableDevices[0])) { - wrongPlatform = NC_MYRIAD_2; - } else { - wrongPlatform = NC_MYRIAD_X; - } - strncpy(deviceDesc_.name, availableDevices[0].c_str(), NC_MAX_NAME_SIZE); - deviceDesc_.platform = wrongPlatform; ASSERT_ERROR(ncDeviceOpen(&deviceHandle_, deviceDesc_, m_ncDeviceOpenParams)); } @@ -236,7 +226,7 @@ TEST_P(MvncDevicePlatform, OpenAndClose) { unsigned int size = MAX_DEV_NAME; ASSERT_NO_ERROR(ncDeviceGetOption(deviceHandle_, NC_RO_DEVICE_NAME, deviceName, &size)); - EXPECT_TRUE(isSamePlatformUSBDevice(deviceName, devicePlatform_)); + EXPECT_TRUE(isSamePlatformUSBDevice(deviceName)); ASSERT_NO_ERROR(ncDeviceClose(&deviceHandle_, m_watchdogHndl)); diff --git a/inference-engine/tools/compile_tool/main.cpp b/inference-engine/tools/compile_tool/main.cpp index 056228fdd0cbab..68b1a1416a5272 100644 --- a/inference-engine/tools/compile_tool/main.cpp +++ b/inference-engine/tools/compile_tool/main.cpp @@ -184,10 +184,6 @@ static std::map configure() { auto config = parseConfigFile(); if (isMYRIAD) { -IE_SUPPRESS_DEPRECATED_START - config[VPU_MYRIAD_CONFIG_KEY(PLATFORM)] = "VPU_MYRIAD_2480"; -IE_SUPPRESS_DEPRECATED_END - if (!FLAGS_VPU_NUMBER_OF_SHAVES.empty()) { config[InferenceEngine::MYRIAD_NUMBER_OF_SHAVES] = FLAGS_VPU_NUMBER_OF_SHAVES; } From 7574dd06de7fb17e4c939eac67198847a0fa970f Mon Sep 17 00:00:00 2001 From: Sergey Lyubimtsev Date: Wed, 18 Aug 2021 12:38:54 +0300 Subject: [PATCH 016/102] Build openvino wheel package from setup.py (#7091) * Added ability to build wheel package by executing `setup.py bdist_wheel` * fix linter issues * fix formating * remove blank line --- .../ie_bridges/python/wheel/setup.py | 85 +++++++++++++++---- 1 file changed, 68 insertions(+), 17 deletions(-) diff --git a/inference-engine/ie_bridges/python/wheel/setup.py b/inference-engine/ie_bridges/python/wheel/setup.py index 5d9ca16238a68b..6b233ff4284175 100644 --- a/inference-engine/ie_bridges/python/wheel/setup.py +++ b/inference-engine/ie_bridges/python/wheel/setup.py @@ -7,10 +7,10 @@ import errno import subprocess # nosec import typing +import multiprocessing from fnmatch import fnmatchcase from pathlib import Path from shutil import copyfile, rmtree -from distutils.command.install import install from distutils.command.build import build from distutils.command.clean import clean from distutils.errors import DistutilsSetupError @@ -27,11 +27,11 @@ # The following variables can be defined in environment or .env file CMAKE_BUILD_DIR = config('CMAKE_BUILD_DIR', '.') -CORE_LIBS_DIR = config('CORE_LIBS_DIR', '') -PLUGINS_LIBS_DIR = config('PLUGINS_LIBS_DIR', '') -NGRAPH_LIBS_DIR = config('NGRAPH_LIBS_DIR', '') -TBB_LIBS_DIR = config('TBB_LIBS_DIR', '') -PY_PACKAGES_DIR = config('PY_PACKAGES_DIR', '') +CORE_LIBS_DIR = config('CORE_LIBS_DIR', 'deployment_tools/inference_engine/lib/intel64') +PLUGINS_LIBS_DIR = config('PLUGINS_LIBS_DIR', 'deployment_tools/inference_engine/lib/intel64') +NGRAPH_LIBS_DIR = config('NGRAPH_LIBS_DIR', 'deployment_tools/ngraph/lib') +TBB_LIBS_DIR = config('TBB_LIBS_DIR', 'deployment_tools/inference_engine/external/tbb/lib') +PY_PACKAGES_DIR = config('PY_PACKAGES_DIR', f'python/{PYTHON_VERSION}') LIBS_RPATH = '$ORIGIN' if sys.platform == 'linux' else '@loader_path' LIB_INSTALL_CFG = { @@ -118,7 +118,66 @@ def __init__(self, name, sources, *args, **kwargs): class CustomBuild(build): """Custom implementation of build_clib""" + cmake_build_types = ['Release', 'Debug', 'RelWithDebInfo', 'MinSizeRel'] + user_options = [ + ('config=', None, 'Build configuration [{types}].'.format(types='|'.join(cmake_build_types))), + ('jobs=', None, 'Specifies the number of jobs to use with make.'), + ('cmake-args=', None, 'Additional options to be passed to CMake.'), + ] + + def initialize_options(self): + """Set default values for all the options that this command supports.""" + super().initialize_options() + self.build_base = 'build' + self.config = None + self.jobs = None + self.cmake_args = None + + def finalize_options(self): + """Set final values for all the options that this command supports.""" + super().finalize_options() + + if not self.config: + if self.debug: + self.config = 'Debug' + else: + self.announce('Set default value for CMAKE_BUILD_TYPE = Release.', level=4) + self.config = 'Release' + else: + build_types = [item.lower() for item in self.cmake_build_types] + try: + i = build_types.index(str(self.config).lower()) + self.config = self.cmake_build_types[i] + self.debug = True if 'Debug' == self.config else False + except ValueError: + self.announce('Unsupported CMAKE_BUILD_TYPE value: ' + self.config, level=4) + self.announce('Supported values: {types}'.format(types=', '.join(self.cmake_build_types)), level=4) + sys.exit(1) + if self.jobs is None and os.getenv('MAX_JOBS') is not None: + self.jobs = os.getenv('MAX_JOBS') + self.jobs = multiprocessing.cpu_count() if self.jobs is None else int(self.jobs) + def run(self): + global CMAKE_BUILD_DIR + self.jobs = multiprocessing.cpu_count() + plat_specifier = '.{0}-{1}.{2}'.format(self.plat_name, *sys.version_info[:2]) + self.build_temp = os.path.join(self.build_base, 'temp' + plat_specifier, self.config) + + # if setup.py is directly called use CMake to build product + if CMAKE_BUILD_DIR == '.': + openvino_root_dir = os.path.normpath(os.path.join(CMAKE_BUILD_DIR, '../../../../')) + self.announce('Configuring cmake project', level=3) + + self.spawn(['cmake', '-H' + openvino_root_dir, '-B' + self.build_temp, + '-DCMAKE_BUILD_TYPE={type}'.format(type=self.config), + '-DENABLE_PYTHON=ON', + '-DNGRAPH_ONNX_FRONTEND_ENABLE=ON']) + + self.announce('Building binaries', level=3) + self.spawn(['cmake', '--build', self.build_temp, + '--config', self.config, '-j', str(self.jobs)]) + CMAKE_BUILD_DIR = self.build_temp + self.run_command('build_clib') build.run(self) # Copy extra package_data content filtered by find_packages @@ -133,14 +192,6 @@ def run(self): copyfile(path, dst / path_rel) -class CustomInstall(install): - """Enable build_clib during the installation""" - - def run(self): - self.run_command('build_clib') - install.run(self) - - class PrepareLibs(build_clib): """Prepare prebuilt libraries""" @@ -369,6 +420,7 @@ def get_package_dir(install_cfg): packages = find_namespace_packages(get_package_dir(PY_INSTALL_CFG)) package_data: typing.Dict[str, list] = {} + setup( version=config('WHEEL_VERSION', '0.0.0'), author_email=config('WHEEL_AUTHOR_EMAIL', 'openvino_pushbot@intel.com'), @@ -376,14 +428,13 @@ def get_package_dir(install_cfg): license=config('WHEEL_LICENCE_TYPE', 'OSI Approved :: Apache Software License'), author=config('WHEEL_AUTHOR', 'Intel Corporation'), description=config('WHEEL_DESC', 'Inference Engine Python* API'), - install_requires=get_dependencies(config('WHEEL_REQUIREMENTS', 'requirements.txt')), - long_description=get_description(config('WHEEL_OVERVIEW', 'pypi_overview.md')), + install_requires=get_dependencies(config('WHEEL_REQUIREMENTS', 'meta/openvino.requirements.txt')), + long_description=get_description(config('WHEEL_OVERVIEW', 'meta/pypi_overview.md')), long_description_content_type='text/markdown', download_url=config('WHEEL_DOWNLOAD_URL', 'https://github.com/openvinotoolkit/openvino/tags'), url=config('WHEEL_URL', 'https://docs.openvinotoolkit.org/latest/index.html'), cmdclass={ 'build': CustomBuild, - 'install': CustomInstall, 'build_clib': PrepareLibs, 'build_ext': CopyExt, 'clean': CustomClean, From 46cbdcd98653e2607d3435acb6718c04bc0a4cf9 Mon Sep 17 00:00:00 2001 From: Anton Chetverikov Date: Wed, 18 Aug 2021 12:56:13 +0300 Subject: [PATCH 017/102] Support unregistered operations in MO IR Reader (#6837) * Add support for unregistred operations in MO IR Reader * Remove commented lines * Add shapes equality check * Update comments * Update groupconv_to_conv function to support case with multiple destinations * Add ir_data_attrs attribute to restored layers * Update copy_shape_infer function to new graph api * Add attribute IE to unsuppurted operations to save their attributes * Fix wrong attribute name * Update commentary * Partially revert updating to new Graph API to fix regression, add appropriate comments * Update code comments * Rename copy_shape_infer function and add more comments --- .../mo/utils/ir_engine/compare_graphs.py | 2 +- .../mo/utils/ir_engine/ir_engine.py | 1 + .../mo/utils/ir_reader/extender.py | 30 ++++++++++++-- .../ir_reader/extenders/LSTMCell_extender.py | 2 +- .../extenders/deconvolution_extender.py | 11 +----- .../extenders/tensoriterator_extender.py | 2 +- .../mo/utils/ir_reader/layer_to_class.py | 39 ++++++++++++++----- 7 files changed, 61 insertions(+), 26 deletions(-) diff --git a/model-optimizer/mo/utils/ir_engine/compare_graphs.py b/model-optimizer/mo/utils/ir_engine/compare_graphs.py index 11c5312be4a540..ecaaad4b3ea2a0 100644 --- a/model-optimizer/mo/utils/ir_engine/compare_graphs.py +++ b/model-optimizer/mo/utils/ir_engine/compare_graphs.py @@ -66,7 +66,7 @@ def compare_graphs(graph: Graph, graph_ref: Graph, last_node: str, last_node_ref ref_node_type = node_ref.type if node_ref.has_valid("type") else None for attr in graph_ref.node[node_ref.id]: if graph_ref.node[node_ref.id][attr] is None or attr in ['name', 'id', '_in_ports', '_out_ports', - 'infer', 'IE', 'biases', 'weights', 'custom', 'offset']: + 'infer', 'IE', 'biases', 'weights', 'custom', 'offset', 'ir_data_attrs']: continue if attr not in graph.node[node.id]: stderr.append('Current node "{}" with type {} has missing attribute {}'.format(node.id, cur_node_type, attr)) diff --git a/model-optimizer/mo/utils/ir_engine/ir_engine.py b/model-optimizer/mo/utils/ir_engine/ir_engine.py index 35d95486c5f734..2beb3467ffa235 100644 --- a/model-optimizer/mo/utils/ir_engine/ir_engine.py +++ b/model-optimizer/mo/utils/ir_engine/ir_engine.py @@ -208,6 +208,7 @@ def __load_layer(self, layer): for attr in layer: if attr.tag == 'data': new_attrs = self.__normalize_attrs(attr.attrib) + new_attrs['ir_data_attrs'] = attr.attrib if layer.attrib['type'] == 'Const': assert 'offset' in new_attrs and 'size' in new_attrs, \ 'Incorrect attributes for Const layer, {} instead of {}!'.format(new_attrs.keys(), ['offset', 'size']) diff --git a/model-optimizer/mo/utils/ir_reader/extender.py b/model-optimizer/mo/utils/ir_reader/extender.py index 5dc617f262921d..13bc5dddaed611 100644 --- a/model-optimizer/mo/utils/ir_reader/extender.py +++ b/model-optimizer/mo/utils/ir_reader/extender.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import logging as log +import numpy as np from mo.front.common.partial_infer.utils import int64_array from mo.utils import class_registration @@ -35,8 +36,29 @@ def attr_to_list(node: Node, attribute: str): node[attribute] = [node[attribute]] @staticmethod - def const_shape_infer(node: Node): - i = len(node.in_nodes()) - for num in node.out_nodes(): - node.out_node(num).shape = int64_array(node.ports[i][0]) + def use_shapes_from_ir(node: Node): + # This function used instead of operation shape inference function to set all output shapes the same as + # restored from IR. Firstly, check equality of old (restored from IR) and + # new (calculated while shape inference) input shapes + node['new_input_shapes'] = list() + for n in node.in_ports(): + if not node.in_port(n).disconnected(): # We use such condition to handle optional inputs + node.new_input_shapes.append(node.in_port(n).data.get_shape()) + assert len(node.new_input_shapes) == len(node.old_input_shapes), \ + 'Something wrong happened while {} node with type {} copy shape inference!'.format(node.name, node.type) + for new_input_shape, old_input_shape in zip(node.new_input_shapes, node.old_input_shapes): + assert np.array_equal(new_input_shape, old_input_shape), \ + 'Something wrong happened while {} node with type {} copy shape inference!'.format(node.name, node.type) + + # We need to use number of connected input ports to avoid errors with numbering + # in node.ports dictionary, where used numbers of input nodes + connected_input_ports = [] + for n in node.in_ports(): + if not node.in_port(n).disconnected(): + connected_input_ports.append(node.in_port(n)) + i = len(connected_input_ports) + + # Set all output shapes the same as restored from IR + for num in node.out_ports(): + node.out_port(num).data.set_shape(int64_array(node.ports[i][0])) i += 1 diff --git a/model-optimizer/mo/utils/ir_reader/extenders/LSTMCell_extender.py b/model-optimizer/mo/utils/ir_reader/extenders/LSTMCell_extender.py index 0810207c86f5a6..0ea1cd247965d5 100644 --- a/model-optimizer/mo/utils/ir_reader/extenders/LSTMCell_extender.py +++ b/model-optimizer/mo/utils/ir_reader/extenders/LSTMCell_extender.py @@ -12,4 +12,4 @@ class LSTMCell_extender(Extender): def extend(op: Node): if not op.has_valid('activations'): op['activations'] = None - op['infer'] = Extender.const_shape_infer + op['infer'] = Extender.use_shapes_from_ir diff --git a/model-optimizer/mo/utils/ir_reader/extenders/deconvolution_extender.py b/model-optimizer/mo/utils/ir_reader/extenders/deconvolution_extender.py index e291afafe1a7b4..fea1f11d0e68dc 100644 --- a/model-optimizer/mo/utils/ir_reader/extenders/deconvolution_extender.py +++ b/model-optimizer/mo/utils/ir_reader/extenders/deconvolution_extender.py @@ -50,13 +50,4 @@ def common_backpropdata_extender(op: Node): def backpropdata_infer(op: Node): - op['new_input_shapes'] = list() - for n in op.in_nodes(): - op.new_input_shapes.append(op.in_node(n).shape) - assert len(op.new_input_shapes) == len(op.old_input_shapes) - - for i in range(len(op.new_input_shapes)): - assert np.array_equal(op.new_input_shapes[i], op.old_input_shapes[i]), 'Something wrong happened while ' \ - '{} shape infer with type {}!'.format(op.name, op.type) - - Extender.const_shape_infer(op) + Extender.use_shapes_from_ir(op) diff --git a/model-optimizer/mo/utils/ir_reader/extenders/tensoriterator_extender.py b/model-optimizer/mo/utils/ir_reader/extenders/tensoriterator_extender.py index 6a65d5eef93500..151b7bdf8f3e9a 100644 --- a/model-optimizer/mo/utils/ir_reader/extenders/tensoriterator_extender.py +++ b/model-optimizer/mo/utils/ir_reader/extenders/tensoriterator_extender.py @@ -40,4 +40,4 @@ def normalize_port_map(port_map: dict): del(edge['from-layer']) del(edge['to-layer']) - op['infer'] = Extender.const_shape_infer + op['infer'] = Extender.use_shapes_from_ir diff --git a/model-optimizer/mo/utils/ir_reader/layer_to_class.py b/model-optimizer/mo/utils/ir_reader/layer_to_class.py index f9f5fd9fb1db23..a3800cb23474d0 100644 --- a/model-optimizer/mo/utils/ir_reader/layer_to_class.py +++ b/model-optimizer/mo/utils/ir_reader/layer_to_class.py @@ -185,15 +185,17 @@ def groupconv_to_conv(op: Node): if weights_node.type == 'Const': weights_node.value = np.reshape(weights_node.value, new_shape) elif weights_node.type == 'Reshape': - # we remove reshape node added in ConvolutionWithGroupsResolver pass + # We remove reshape node added in ConvolutionWithGroupsResolver pass assert weights_node.in_port(0).get_source().data.get_shape() == new_shape, \ 'Weight shape and calculated shape mismatch in GroupConv node {}.'.format(op.name) op.in_port(1).disconnect() - weights_node.in_port(0).get_source().get_connection().set_destination(op.in_port(1)) + # We use add_destination method here to support case with multiple destinations of source port + weights_node.in_port(0).get_source().get_connection().add_destination(op.in_port(1)) + weights_node.in_port(0).disconnect() else: assert op.in_port(1).get_source().data.get_shape() == new_shape, \ 'Weight shape and calculated shape mismatch in GroupConv node {}.'.format(op.name) - # we need to set this attrs for correct shape infer as convolution + # We need to set this attrs for correct shape infer as convolution op['group'] = group # The only way GroupConvolution with 'group' = 1 appears in IR is by converting from TF DepthwiseConv2dNative. # In this case we need to specify 'op' parameter for the @@ -218,9 +220,6 @@ def backprop_to_deconv(op: Node): if op.has_valid('output_padding'): # In this case we need to create Deconvolution as Convolution op['type_to_create'] = 'Convolution' - op['old_input_shapes'] = list() - for n in op.in_nodes(): - op.old_input_shapes.append(int64_array(op.in_node(n).shape)) def ti_add_edge_attrs(op: Node): @@ -344,6 +343,11 @@ def copy_graph_with_ops(graph: Graph) -> Graph: # Create a new copy of graph with correct attributes (shape & type infer, backend attrs etc.) for op in graph.get_op_nodes(): + # Save input shapes restored from IR + op['old_input_shapes'] = list() + for n in op.in_nodes(): + op.old_input_shapes.append(int64_array(op.in_node(n).shape)) + # Apply extenders to nodes in source graph if op.type in Extender.registered_ops: Extender.get_extender_class_by_name(op.type).extend(op) @@ -356,9 +360,26 @@ def copy_graph_with_ops(graph: Graph) -> Graph: if op_type in custom_ops: node = custom_ops[op_type](new_graph, op.attrs()).create_node() else: - assert op_type in Op.registered_ops, 'Operation {} not found in MO operations, ' \ - 'please check it!'.format(op_type) - node = Op.get_op_class_by_name(op_type)(new_graph, op.attrs()).create_node() + if op_type not in Op.registered_ops: + log.warning('Operation {} is not found in MO operations, please check it! ' + 'Simple shape infer function is used'.format(op_type)) + node = Op(new_graph, op.attrs()).create_node() + node['infer'] = Extender.use_shapes_from_ir + if 'ir_data_attrs' in op: + node['IE'] = [('layer', + [('id', lambda node: node.node), 'name', 'type', 'version'], + [('data', + list(op.ir_data_attrs.keys()), + []), + '@ports', + '@consts'])] + + else: + node = Op.get_op_class_by_name(op_type)(new_graph, op.attrs()).create_node() + + # This attribute is no longer needed and we can delete it + if 'ir_data_attrs' in node: + del node['ir_data_attrs'] if op.has_and_set('need_copy_input_blobs'): copy_input_blobs(op, node) From 8bd9ef48d3593719768b019a89fccc55078c2de0 Mon Sep 17 00:00:00 2001 From: Shoujiang Ma Date: Wed, 18 Aug 2021 18:12:27 +0800 Subject: [PATCH 018/102] First stage of the AUTO-MULTI merge: redirecting AUTO to the MULTI device plugin (#7037) * Redirect -d AUTO to MULTI device plugin Signed-off-by: Shoujiang Ma * Modify AUTO tests with MULTI config Signed-off-by: Shoujiang Ma * Fix CI Signed-off-by: Shoujiang Ma * Fix bug: CVS-62424 Signed-off-by: Shoujiang Ma * Add some tests for AUTO Signed-off-by: Shoujiang Ma * Add select device logic to MULTI Signed-off-by: Shoujiang Ma * Fix extract device name bug Signed-off-by: Shoujiang Ma * Address reviewer's comment Signed-off-by: Shoujiang Ma * Delete AUTO plugin source code Signed-off-by: Shoujiang Ma --- .../samples/benchmark_app/main.cpp | 3 + .../src/auto_plugin/auto_exec_network.cpp | 136 ------ .../src/auto_plugin/auto_exec_network.hpp | 56 --- .../src/auto_plugin/auto_infer_request.cpp | 103 ----- .../src/auto_plugin/auto_infer_request.hpp | 55 --- .../src/auto_plugin/auto_plugin.cpp | 389 +----------------- .../src/auto_plugin/auto_plugin.hpp | 33 +- .../src/inference_engine/src/ie_core.cpp | 46 ++- .../src/multi_device/CMakeLists.txt | 2 +- .../src/multi_device/multi_device_plugin.cpp | 209 +++++++++- .../src/multi_device/multi_device_plugin.hpp | 6 +- .../interface/ie_internal_plugin_config.hpp | 9 + .../behavior/config.cpp | 25 +- .../behavior/core_integration.cpp | 2 +- .../behavior/core_threading_tests.cpp | 2 +- .../behavior/exec_graph_info.cpp | 5 +- .../behavior/infer_request.cpp | 6 +- .../behavior/infer_request_callback.cpp | 6 +- .../behavior/infer_request_config.cpp | 14 + .../behavior/infer_request_input.cpp | 6 +- .../behavior/infer_request_output.cpp | 6 +- .../behavior/ov_core_integration.cpp | 2 +- .../behavior/set_blob_of_kind.cpp | 5 +- .../behavior/set_preprocess.cpp | 10 +- .../behavior/test_plugin.cpp | 14 +- .../behavior/version.cpp | 6 +- .../behavior/config.cpp | 30 +- .../behavior/infer_request.cpp | 7 +- .../behavior/infer_request_callback.cpp | 17 +- .../behavior/infer_request_input.cpp | 17 +- .../behavior/infer_request_output.cpp | 17 +- .../behavior/set_preprocess.cpp | 18 +- .../behavior/test_plugin.cpp | 36 +- .../behavior/version.cpp | 17 +- .../behavior/config.cpp | 52 +-- .../behavior/infer_request.cpp | 7 +- .../include/behavior/exec_graph_info.hpp | 9 +- .../src/subgraph/reduce_eltwise.cpp | 3 +- 38 files changed, 310 insertions(+), 1076 deletions(-) delete mode 100644 inference-engine/src/auto_plugin/auto_exec_network.cpp delete mode 100644 inference-engine/src/auto_plugin/auto_exec_network.hpp delete mode 100644 inference-engine/src/auto_plugin/auto_infer_request.cpp delete mode 100644 inference-engine/src/auto_plugin/auto_infer_request.hpp diff --git a/inference-engine/samples/benchmark_app/main.cpp b/inference-engine/samples/benchmark_app/main.cpp index 18aa66e0a45c04..53aa0f1922df9f 100644 --- a/inference-engine/samples/benchmark_app/main.cpp +++ b/inference-engine/samples/benchmark_app/main.cpp @@ -212,6 +212,9 @@ int main(int argc, char* argv[]) { bool perf_counts = false; // Update config per device according to command line parameters for (auto& device : devices) { + if (device == "AUTO") { + continue; + } if (!config.count(device)) config[device] = {}; std::map& device_config = config.at(device); diff --git a/inference-engine/src/auto_plugin/auto_exec_network.cpp b/inference-engine/src/auto_plugin/auto_exec_network.cpp deleted file mode 100644 index 6bb3fb9ddfa884..00000000000000 --- a/inference-engine/src/auto_plugin/auto_exec_network.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include "ie_metric_helpers.hpp" -#include "auto_exec_network.hpp" -#include "auto_infer_request.hpp" - -namespace AutoPlugin { -using namespace InferenceEngine; - -AutoExecutableNetwork::AutoExecutableNetwork(NetworkFuture cpuFuture, - NetworkFuture acceleratorFuture, - bool enablePerfCount) - : _cpuFuture(std::move(cpuFuture)) - , _acceleratorFuture(std::move(acceleratorFuture)) - , _enablePerfCount(enablePerfCount) { - // both are valid, like AUTO:CPU,GPU - if (_cpuFuture.valid() && _acceleratorFuture.valid()) { - try { - _networkFirstReady = _cpuFuture.get(); - _alreadyActualNetwork = false; - } catch (const std::exception& e) { - printf("Warning: load network to CPU failed: %s\n", e.what()); - _networkActualNeeded = _acceleratorFuture.get(); - _alreadyActualNetwork = true; - } - } else if (_acceleratorFuture.valid()) { // only accelerator is valid, like AUTO:GPU - _networkActualNeeded = _acceleratorFuture.get(); - _alreadyActualNetwork = true; - } else if (_cpuFuture.valid()) { // only CPU is valid, like AUTO:CPU - _networkActualNeeded = _cpuFuture.get(); - _alreadyActualNetwork = true; - } else { - IE_THROW() << "No device task available"; - } -} - -AutoExecutableNetwork::~AutoExecutableNetwork() = default; - -InferenceEngine::IInferRequestInternal::Ptr AutoExecutableNetwork::CreateInferRequestImpl(InputsDataMap networkInputs, - OutputsDataMap networkOutputs) { - InferenceEngine::SoExecutableNetworkInternal network; - SoIInferRequestInternal inferRequest; - if (TryGetActualNetwork(network)) { - inferRequest = {_networkActualNeeded, _networkActualNeeded->CreateInferRequest()}; - } else { - inferRequest = {_networkFirstReady, _networkFirstReady->CreateInferRequest()}; - } - return std::make_shared(_networkInputs, _networkOutputs, inferRequest, - shared_from_this(), _alreadyActualNetwork, - _enablePerfCount); -} - -bool AutoExecutableNetwork::TryGetActualNetwork(InferenceEngine::SoExecutableNetworkInternal& soExecNetwork) { - // try to get actual network - if (_acceleratorFuture.valid() && _acceleratorFuture.wait_for(std::chrono::nanoseconds(0)) == std::future_status::ready) { - soExecNetwork = _acceleratorFuture.get(); - _alreadyActualNetwork = true; - _networkActualNeeded = soExecNetwork; - // reapply config to actual network - // fixme: GPU doesn't support SetConfig and throw exception - try { - _networkActualNeeded->SetConfig(_cacheConfig); - } catch (...) { - } - return true; - } - // if already get actual network - if (_alreadyActualNetwork) { - soExecNetwork = _networkActualNeeded; - return true; - } - return false; -} - -void AutoExecutableNetwork::WaitForActualDevice() const { - if (_alreadyActualNetwork) { - return; - } - - if (_acceleratorFuture.valid()) { - _networkActualNeeded = _acceleratorFuture.get(); - _alreadyActualNetwork = true; - } else { - IE_THROW() << "Export failed due to no valid executable network"; - } -} - -void AutoExecutableNetwork::Export(std::ostream& networkModel) { - //fixme: the Export should work with actual device, so we have to wait!!! - WaitForActualDevice(); - _networkActualNeeded->Export(networkModel); -} - -RemoteContext::Ptr AutoExecutableNetwork::GetContext() const { - // fixme: the GetContext should work with actual device, so we have to wait!!! - WaitForActualDevice(); - return _networkActualNeeded->GetContext(); -} - -InferenceEngine::CNNNetwork AutoExecutableNetwork::GetExecGraphInfo() { - WaitForActualDevice(); - return _networkActualNeeded->GetExecGraphInfo(); -} - -Parameter AutoExecutableNetwork::GetMetric(const std::string &name) const { - // fixme: should we wait actual device? meanwhile it will block inference, how to fix? -// WaitForActualDevice(); - if (_alreadyActualNetwork) { - return _networkActualNeeded->GetMetric(name); - } else { - return _networkFirstReady->GetMetric(name); - } -} - -void AutoExecutableNetwork::SetConfig(const std::map& config) { - //fixme: have to store the config and reapply when the networks swapped - _cacheConfig = config; - if (_alreadyActualNetwork) { - _networkActualNeeded->SetConfig(config); - } else { - _networkFirstReady->SetConfig(config); - } -} - -Parameter AutoExecutableNetwork::GetConfig(const std::string& name) const { - //fixme: carefuly select between FirstLoaded and ActuallyNeeded - return _cacheConfig; -} - -} // namespace AutoPlugin diff --git a/inference-engine/src/auto_plugin/auto_exec_network.hpp b/inference-engine/src/auto_plugin/auto_exec_network.hpp deleted file mode 100644 index f3b11095d94a59..00000000000000 --- a/inference-engine/src/auto_plugin/auto_exec_network.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace AutoPlugin { - -using DeviceName = std::string; -using NetworkFuture = std::future; - -class AutoExecutableNetwork : public InferenceEngine::IExecutableNetworkInternal { -public: - using Ptr = std::shared_ptr; - - explicit AutoExecutableNetwork(NetworkFuture cpuTask, - NetworkFuture acceleratorTask, - bool enablePerfCount); - - void Export(std::ostream& networkModel) override; - InferenceEngine::RemoteContext::Ptr GetContext() const override; - InferenceEngine::CNNNetwork GetExecGraphInfo() override; - InferenceEngine::Parameter GetMetric(const std::string &name) const override; - void SetConfig(const std::map& config) override; - InferenceEngine::Parameter GetConfig(const std::string& name) const override; - InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, - InferenceEngine::OutputsDataMap networkOutputs) override; - bool TryGetActualNetwork(InferenceEngine::SoExecutableNetworkInternal& soExecNetwork); - - ~AutoExecutableNetwork(); - -private: - void WaitForActualDevice() const; - -private: - InferenceEngine::SoExecutableNetworkInternal _networkFirstReady; - mutable InferenceEngine::SoExecutableNetworkInternal _networkActualNeeded; - NetworkFuture _cpuFuture; - mutable NetworkFuture _acceleratorFuture; - bool _enablePerfCount; - mutable std::atomic _alreadyActualNetwork = {false}; - std::map _cacheConfig; -}; - -} // namespace AutoPlugin diff --git a/inference-engine/src/auto_plugin/auto_infer_request.cpp b/inference-engine/src/auto_plugin/auto_infer_request.cpp deleted file mode 100644 index 1497ee3557b449..00000000000000 --- a/inference-engine/src/auto_plugin/auto_infer_request.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include "auto_infer_request.hpp" -#include -#include - -namespace AutoPlugin { - using namespace InferenceEngine; - -AutoInferRequest::AutoInferRequest(const InputsDataMap& networkInputs, - const OutputsDataMap& networkOutputs, - const SoIInferRequestInternal& inferRequest, - const InferenceEngine::IExecutableNetworkInternal::Ptr autoExecutableNetwork, - bool alreadyActualNetwork, - bool enablePerfCount) - : IInferRequestInternal(networkInputs, networkOutputs) - , _inferRequest(inferRequest) - , _autoExecutableNetwork(std::dynamic_pointer_cast(autoExecutableNetwork)) - , _alreadyActualNetwork(alreadyActualNetwork) - , _enablePerfCount(enablePerfCount) { - IE_ASSERT(_autoExecutableNetwork != nullptr); - for (const auto &it : _networkInputs) - _inputs[it.first] = _inferRequest->GetBlob(it.first); - for (const auto &it : _networkOutputs) - _outputs[it.first] = _inferRequest->GetBlob(it.first); -} - -std::map AutoInferRequest::GetPerformanceCounts() const { - if (_enablePerfCount) { - try { - return _inferRequest->GetPerformanceCounts(); - } catch (...) { - return {}; - } - } else { - return {}; - } -} - -void AutoInferRequest::InferImpl() { - HotSwapRequests(); //safe to call here (before actual inference started) - SetBlobsToDeviceRequest(); - _inferRequest->Infer(); -} - -void AutoInferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& data) { - IInferRequestInternal::SetBlob(name, data); -} - -Blob::Ptr AutoInferRequest::GetBlob(const std::string& name) { - return IInferRequestInternal::GetBlob(name); -} - -void AutoInferRequest::Cancel() { - _inferRequest->Cancel(); -} - -void AutoInferRequest::StartAsync() { - HotSwapRequests(); //safe to call here (before actual inference started) - SetBlobsToDeviceRequest(); - _inferRequest->StartAsync(); -} - -InferenceEngine::StatusCode AutoInferRequest::Wait(int64_t millis_timeout) { - return _inferRequest->Wait(millis_timeout); -} - -void AutoInferRequest::SetCallback(Callback callback) { - _callback = callback; - _inferRequest->SetCallback(callback); -} - -void AutoInferRequest::HotSwapRequests() { - if (!_alreadyActualNetwork) { - InferenceEngine::SoExecutableNetworkInternal tempSoExecNetwork; - if (_autoExecutableNetwork->TryGetActualNetwork(tempSoExecNetwork)) { - _alreadyActualNetwork = true; - _inferRequest = {tempSoExecNetwork, tempSoExecNetwork->CreateInferRequest()}; - _inferRequest->SetCallback(_callback); - } - } -} - -void AutoInferRequest::SetBlobsToDeviceRequest() { - for (const auto &it : _networkInputs) { - const auto &name = it.first; - // this assumes the request is already in BUSY state - auto blob = GetBlob(name); - if (_inferRequest->GetBlob(name) != blob) - _inferRequest->SetBlob(name, blob); - } - for (const auto &it : _networkOutputs) { - const auto &name = it.first; - // this assumes the request is already in BUSY state - auto blob = GetBlob(name); - if (_inferRequest->GetBlob(name) != blob) - _inferRequest->SetBlob(name, blob); - } - } -} // namespace AutoPlugin diff --git a/inference-engine/src/auto_plugin/auto_infer_request.hpp b/inference-engine/src/auto_plugin/auto_infer_request.hpp deleted file mode 100644 index c0044164b48c57..00000000000000 --- a/inference-engine/src/auto_plugin/auto_infer_request.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "auto_exec_network.hpp" - -namespace AutoPlugin { - -class AutoInferRequest : public InferenceEngine::IInferRequestInternal { -public: - using Ptr = std::shared_ptr; - explicit AutoInferRequest(const InferenceEngine::InputsDataMap& networkInputs, - const InferenceEngine::OutputsDataMap& networkOutputs, - const InferenceEngine::SoIInferRequestInternal& inferRequest, - const InferenceEngine::IExecutableNetworkInternal::Ptr executeNetwork, - bool alreadyActualNetwork, - bool enablePerfCount); - std::map GetPerformanceCounts() const override; - void InferImpl() override; - void SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& data) override; - InferenceEngine::Blob::Ptr GetBlob(const std::string& name) override; - void Cancel() override; - //async impl - void StartAsync() override; - InferenceEngine::StatusCode Wait(int64_t millis_timeout) override; - void SetCallback(Callback callback) override; - -private: - void HotSwapRequests(); - void SetBlobsToDeviceRequest(); - -private: - InferenceEngine::SoIInferRequestInternal _inferRequest; - AutoPlugin::AutoExecutableNetwork::Ptr _autoExecutableNetwork; - Callback _callback; // need to save the callback for hot-swap of the requests - bool _alreadyActualNetwork{ false }; - bool _enablePerfCount { false }; -}; - -} // namespace AutoPlugin diff --git a/inference-engine/src/auto_plugin/auto_plugin.cpp b/inference-engine/src/auto_plugin/auto_plugin.cpp index 75e80faa2b45e4..5ad9d46984aac6 100644 --- a/inference-engine/src/auto_plugin/auto_plugin.cpp +++ b/inference-engine/src/auto_plugin/auto_plugin.cpp @@ -2,397 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - #include "auto_plugin.hpp" -#include "ngraph_ops/convolution_ie.hpp" -#include "ngraph_ops/deconvolution_ie.hpp" namespace AutoPlugin { -namespace { - std::string GetNetworkPrecision(const InferenceEngine::CNNNetwork &network) { - auto nGraphFunc = network.getFunction(); - bool isINTModel = ngraph::op::util::has_op_with_type(nGraphFunc); - if (isINTModel) { - return METRIC_VALUE(INT8); - } - for (auto & node : nGraphFunc->get_ordered_ops()) { - if (std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node)) { - auto layerType = node->input(1).get_element_type().get_type_name(); - if (layerType == "f32") - return METRIC_VALUE(FP32); - if (layerType == "f16") - return METRIC_VALUE(FP16); - } - } - return METRIC_VALUE(FP32); - } -} // namespace - -AutoInferencePlugin::AutoInferencePlugin() { - _pluginName = "AUTO"; -} - -IE::IExecutableNetworkInternal::Ptr AutoInferencePlugin::LoadNetwork(const std::string& fileName, - const ConfigType& config) { - return LoadNetworkImpl(fileName, {}, config); -} - -IE::IExecutableNetworkInternal::Ptr AutoInferencePlugin::LoadExeNetworkImpl(const IE::CNNNetwork& network, - const ConfigType& config) { - if (network.getFunction() == nullptr) { - IE_THROW() << "AUTO device supports just ngraph network representation"; - } - - auto networkPrecision = GetNetworkPrecision(network); - return LoadNetworkImpl({}, network, config, networkPrecision); -} - -std::shared_ptr AutoInferencePlugin::LoadNetworkImpl(const std::string& modelPath, - const InferenceEngine::CNNNetwork& network, - const ConfigType& config, - const std::string& networkPrecision) { - if (GetCore() == nullptr) { - IE_THROW() << "Please, work with AUTO device via InferencEngine::Core object"; - } - - if (modelPath.empty() && network.getFunction() == nullptr) { - IE_THROW() << "AUTO device supports just ngraph network representation"; - } - - auto fullConfig = mergeConfigs(_config, config); - CheckConfig(fullConfig); - auto metaDevices = GetDeviceList(fullConfig); - auto core = GetCore(); // shared_ptr that holds the Core while the lambda below (which captures that by val) works - auto LoadNetworkAsync = - [core, modelPath, network](const std::string& device) - -> IE::SoExecutableNetworkInternal { - IE::SoExecutableNetworkInternal executableNetwork; - if (!modelPath.empty()) { - executableNetwork = core->LoadNetwork(modelPath, device, {}); - } else { - executableNetwork = core->LoadNetwork(network, device, {}); - } - return executableNetwork; - }; - - NetworkFuture cpuFuture; - NetworkFuture acceleratorFuture; - - // start CPU task - const auto CPUIter = std::find_if(metaDevices.begin(), metaDevices.end(), - [=](const std::string& d)->bool{return d.find("CPU") != std::string::npos;}); - if (CPUIter != metaDevices.end()) { - cpuFuture = std::async(std::launch::async, LoadNetworkAsync, *CPUIter); - } - - // start accelerator task, like GPU - const auto accelerator = SelectDevice(metaDevices, networkPrecision); - bool isAccelerator = accelerator.find("CPU") == std::string::npos; - if (isAccelerator) { - acceleratorFuture = std::async(std::launch::async, LoadNetworkAsync, accelerator); - } - - bool enablePerfCount = fullConfig.find(IE::PluginConfigParams::KEY_PERF_COUNT) != fullConfig.end(); - - return std::make_shared(std::move(cpuFuture), std::move(acceleratorFuture), enablePerfCount); -} - -IE::QueryNetworkResult AutoInferencePlugin::QueryNetwork(const IE::CNNNetwork& network, const ConfigType& config) const { - IE::QueryNetworkResult queryResult = {}; - if (GetCore() == nullptr) { - IE_THROW() << "Please, work with AUTO device via InferencEngine::Core object"; - } - - if (network.getFunction() == nullptr) { - IE_THROW() << "AUTO device supports just ngraph network representation"; - } - - auto fullConfig = mergeConfigs(_config, config); - auto metaDevices = GetDeviceList(fullConfig); - std::unordered_set supportedLayers; - for (auto&& value : metaDevices) { - try { - auto deviceQr = GetCore()->QueryNetwork(network, value, {}); - std::unordered_set deviceSupportedLayers; - for (auto &&layerQr : deviceQr.supportedLayersMap) { - deviceSupportedLayers.emplace(layerQr.first); - } - supportedLayers = supportedLayers.empty() - ? deviceSupportedLayers : (deviceSupportedLayers.empty() - ? supportedLayers : IE::details::Intersection( - supportedLayers, deviceSupportedLayers)); - break; - } catch (...) { - } - } - - for (auto&& supportedLayer : supportedLayers) { - queryResult.supportedLayersMap[supportedLayer] = GetName(); - } - return queryResult; -} - -IE::Parameter AutoInferencePlugin::GetConfig(const std::string& name, - const std::map & options) const { - auto it = _config.find(name); - if (it == _config.end()) { - IE_THROW() << "Unsupported config key: " << name; - } else { - return { it->second }; - } -} - -void AutoInferencePlugin::SetConfig(const ConfigType& config) { - for (auto && kvp : config) { - if (kvp.first.find("AUTO_") == 0) { - _config[kvp.first] = kvp.second; - } else if (kvp.first == IE::PluginConfigParams::KEY_PERF_COUNT) { - if (kvp.second == IE::PluginConfigParams::YES || - kvp.second == IE::PluginConfigParams::NO) { - _config[kvp.first] = kvp.second; - } else { - IE_THROW() << "Unsupported config value: " << kvp.second - << " for key: " << kvp.first; - } - } else { - IE_THROW() << "Unsupported config key: " << kvp.first; - } - } -} - -IE::Parameter AutoInferencePlugin::GetMetric(const std::string& name, - const std::map & options) const { - if (name == METRIC_KEY(SUPPORTED_METRICS)) { - std::vector metrics; - metrics.emplace_back(METRIC_KEY(SUPPORTED_METRICS)); - metrics.emplace_back(METRIC_KEY(FULL_DEVICE_NAME)); - metrics.emplace_back(METRIC_KEY(SUPPORTED_CONFIG_KEYS)); - metrics.emplace_back(METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - IE_SET_METRIC_RETURN(SUPPORTED_METRICS, metrics); - } else if (name == METRIC_KEY(FULL_DEVICE_NAME)) { - std::string device_name = {"Inference Engine AUTO device"}; - IE_SET_METRIC_RETURN(FULL_DEVICE_NAME, device_name); - } else if (name == METRIC_KEY(SUPPORTED_CONFIG_KEYS)) { - std::vector configKeys = { - IE::KEY_AUTO_DEVICE_LIST, - IE::PluginConfigParams::KEY_PERF_COUNT - }; - IE_SET_METRIC_RETURN(SUPPORTED_CONFIG_KEYS, configKeys); - } else if (name == METRIC_KEY(OPTIMIZATION_CAPABILITIES)) { - std::vector capabilities = GetOptimizationCapabilities(options); - IE_SET_METRIC_RETURN(OPTIMIZATION_CAPABILITIES, capabilities); - } else { - IE_THROW() << "Unsupported metric key " << name; - } -} - -//////////////////////////////////// private & protected functions /////////////////// -std::vector AutoInferencePlugin::GetDeviceList(const ConfigType& config) const { - std::vector deviceList; - - auto deviceListConfig = config.find(IE::KEY_AUTO_DEVICE_LIST); - if (deviceListConfig == config.end()) { - deviceList = GetCore()->GetAvailableDevices(); - } else { - deviceList = IE::DeviceIDParser::getHeteroDevices(deviceListConfig->second); - } - - if (deviceList.empty()) { - IE_THROW() << "Please, check environment due to no supported devices can be used"; - } - - return deviceList; -} - -std::vector AutoInferencePlugin::GetOptimizationCapabilities(const std::map & options) const { - // FIXME: workaround to get devicelist. - std::unordered_set capabilities; - std::vector queryDeviceLists{"CPU", "GPU"}; - - if (options.find(IE::KEY_AUTO_DEVICE_LIST) != options.end()) { - auto deviceListConfig = options.at(IE::KEY_AUTO_DEVICE_LIST).as(); - queryDeviceLists = IE::DeviceIDParser::getHeteroDevices(deviceListConfig); - } else if (_config.find(IE::KEY_AUTO_DEVICE_LIST) != _config.end()) { - auto deviceListConfig = _config.at(IE::KEY_AUTO_DEVICE_LIST); - queryDeviceLists = IE::DeviceIDParser::getHeteroDevices(deviceListConfig); - } - for (auto &item : queryDeviceLists) { - try { - std::vector device_cap = - GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - for (auto &cap : device_cap) { - capabilities.insert(cap); - } - } catch (...) { - } - } - return {capabilities.begin(), capabilities.end()}; -} - -void AutoInferencePlugin::CheckConfig(const ConfigType& config) { - std::vector supportedConfigKeys = GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), {}); - for (auto&& kvp : config) { - if (kvp.first.find("AUTO_") == 0) { - continue; - } else if (kvp.first == IE::PluginConfigParams::KEY_PERF_COUNT) { - if (kvp.second == IE::PluginConfigParams::YES || - kvp.second == IE::PluginConfigParams::NO) { - continue; - } else { - IE_THROW() << "Unsupported config value: " << kvp.second - << " for key: " << kvp.first; - } - } else { - IE_THROW() << "Unsupported config key: " << kvp.first; - } - } -} - -DeviceName AutoInferencePlugin::SelectDevice(const std::vector& metaDevices, const std::string& networkPrecision) { - if (metaDevices.empty()) { - IE_THROW(NotFound) << "No available device to select in AUTO plugin"; - } - if (metaDevices.size() == 1) { - return metaDevices.at(0); - } - - std::vector CPU; - std::vector dGPU; - std::vector iGPU; - std::vector MYRIAD; - std::vector VPUX; - - for (auto& item : metaDevices) { - if (item.find("CPU") == 0) { - CPU.push_back(item); - continue; - } - if (item.find("MYRIAD") == 0) { - MYRIAD.push_back(item); - continue; - } - if (item.find("VPUX") == 0) { - VPUX.push_back(item); - continue; - } - if (item.find("GPU") == 0) { - auto gpuFullDeviceName = GetCore()->GetMetric(item, METRIC_KEY(FULL_DEVICE_NAME)).as(); - if (gpuFullDeviceName.find("iGPU") != std::string::npos) { - iGPU.push_back(item); - } else if (gpuFullDeviceName.find("dGPU") != std::string::npos) { - dGPU.push_back(item); - } - continue; - } - } - - if (CPU.empty() && dGPU.empty() && iGPU.empty() && MYRIAD.empty() && VPUX.empty()) { - IE_THROW(NotFound) << "No available device found"; - } - - // Priority of selecting device: dGPU > VPUX > iGPU > MYRIAD > CPU - if (!dGPU.empty()) { - for (auto&& item : dGPU) { - std::vector capability = GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - auto supportNetwork = std::find(capability.begin(), capability.end(), networkPrecision); - if (supportNetwork != capability.end()) { - return item; - } - } - } else if (!VPUX.empty()) { - for (auto&& item : VPUX) { - std::vector capability = GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - auto supportNetwork = std::find(capability.begin(), capability.end(), networkPrecision); - if (supportNetwork != capability.end()) { - return item; - } - } - } else if (!iGPU.empty()) { - for (auto&& item : iGPU) { - std::vector capability = GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - auto supportNetwork = std::find(capability.begin(), capability.end(), networkPrecision); - if (supportNetwork != capability.end()) { - return item; - } - } - } else if (!MYRIAD.empty()) { - for (auto&& item : MYRIAD) { - std::vector capability = GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - auto supportNetwork = std::find(capability.begin(), capability.end(), networkPrecision); - if (supportNetwork != capability.end()) { - return item; - } - } - } - - // If network is FP32 but there is no device support FP32, offload FP32 network to device support FP16. - if (networkPrecision == "FP32") { - if (!dGPU.empty()) { - for (auto&& item : dGPU) { - std::vector capability = GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - auto supportNetwork = std::find(capability.begin(), capability.end(), "FP16"); - if (supportNetwork != capability.end()) { - return item; - } - } - } else if (!VPUX.empty()) { - for (auto&& item : VPUX) { - std::vector capability = GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - auto supportNetwork = std::find(capability.begin(), capability.end(), "FP16"); - if (supportNetwork != capability.end()) { - return item; - } - } - } else if (!iGPU.empty()) { - for (auto&& item : iGPU) { - std::vector capability = GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - auto supportNetwork = std::find(capability.begin(), capability.end(), "FP16"); - if (supportNetwork != capability.end()) { - return item; - } - } - } else if (!MYRIAD.empty()) { - for (auto&& item : MYRIAD) { - std::vector capability = GetCore()->GetMetric(item, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - auto supportNetwork = std::find(capability.begin(), capability.end(), "FP16"); - if (supportNetwork != capability.end()) { - return item; - } - } - } - } - - if (CPU.empty()) { - IE_THROW() << "Cannot select any device"; - } - return CPU[0]; -} - -ConfigType AutoInferencePlugin::mergeConfigs(ConfigType config, const ConfigType& local) { - for (auto && kvp : local) { - config[kvp.first] = kvp.second; - } - return config; -} - // define CreatePluginEngine to create plugin instance -static const IE::Version version = {{2, 1}, CI_BUILD_NUMBER, "AutoPlugin"}; +static const InferenceEngine::Version version = {{2, 1}, CI_BUILD_NUMBER, "AutoPlugin"}; IE_DEFINE_PLUGIN_CREATE_FUNCTION(AutoInferencePlugin, version) } // namespace AutoPlugin diff --git a/inference-engine/src/auto_plugin/auto_plugin.hpp b/inference-engine/src/auto_plugin/auto_plugin.hpp index a9c5615524696f..77e22d1ab03b9a 100644 --- a/inference-engine/src/auto_plugin/auto_plugin.hpp +++ b/inference-engine/src/auto_plugin/auto_plugin.hpp @@ -4,43 +4,14 @@ #pragma once -#include -#include -#include -#include -#include - #include #include -#include - -#include "auto_exec_network.hpp" namespace AutoPlugin { -namespace IE = InferenceEngine; -using ConfigType = std::map; - -class AutoInferencePlugin : public IE::IInferencePlugin { +class AutoInferencePlugin : public InferenceEngine::IInferencePlugin { public: - AutoInferencePlugin(); + AutoInferencePlugin() = default; ~AutoInferencePlugin() = default; - IE::IExecutableNetworkInternal::Ptr LoadExeNetworkImpl(const IE::CNNNetwork& network, const ConfigType& config) override; - IE::IExecutableNetworkInternal::Ptr LoadNetwork(const std::string& fileName, const ConfigType& config) override; - IE::QueryNetworkResult QueryNetwork(const IE::CNNNetwork& network, const ConfigType& config) const override; - IE::Parameter GetMetric(const std::string& name, const std::map& options) const override; - IE::Parameter GetConfig(const std::string& name, const std::map & options) const override; - void SetConfig(const ConfigType& config) override; - -private: - std::shared_ptr LoadNetworkImpl(const std::string& modelPath, - const InferenceEngine::CNNNetwork& network, - const ConfigType &config, - const std::string &networkPrecision = METRIC_VALUE(FP32)); - std::vector GetDeviceList(const ConfigType& config) const; - std::vector GetOptimizationCapabilities(const std::map& options) const; - DeviceName SelectDevice(const std::vector& metaDevices, const std::string& networkPrecision = METRIC_VALUE(FP32)); - void CheckConfig(const ConfigType& config); - static ConfigType mergeConfigs(ConfigType config, const ConfigType& local); }; } // namespace AutoPlugin diff --git a/inference-engine/src/inference_engine/src/ie_core.cpp b/inference-engine/src/inference_engine/src/ie_core.cpp index b636d51936867e..5792e6388e016b 100644 --- a/inference-engine/src/inference_engine/src/ie_core.cpp +++ b/inference-engine/src/inference_engine/src/ie_core.cpp @@ -62,18 +62,17 @@ Parsed parseDeviceNameIntoConfig(const std::string& deviceName, const std::ma } else if (deviceName_.find("MULTI:") == 0) { deviceName_ = "MULTI"; config_[InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES] = deviceName.substr(6); - } else if (deviceName_.find("AUTO") == 0) { - deviceName_ = "AUTO"; - if (deviceName.size() > std::string("AUTO").size()) { - std::string deviceList = deviceName.substr(std::string("AUTO:").size()); - if (deviceList.find("AUTO") != std::string::npos) { - IE_THROW() << "Device list for AUTO should not be AUTO"; - } - config_[InferenceEngine::KEY_AUTO_DEVICE_LIST] = deviceName.substr(std::string("AUTO:").size()); + } else if (deviceName.find("AUTO") == 0) { + deviceName_ = "MULTI"; + if (deviceName.find("AUTO:") == 0) { + config_[InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES] = + deviceName.substr(std::string("AUTO:").size()); } + config_.insert({CONFIG_KEY_INTERNAL(WORK_MODE), ""}); } else { - if (deviceName_.empty()) { - deviceName_ = "AUTO"; + if (deviceName_ == "AUTO") { + deviceName_ = "MULTI"; + config_.insert({CONFIG_KEY_INTERNAL(WORK_MODE), ""}); } InferenceEngine::DeviceIDParser parser(deviceName_); deviceName_ = parser.getDeviceName(); @@ -579,7 +578,21 @@ class CoreImpl : public InferenceEngine::ICore, public std::enable_shared_from_t } } - auto parsed = parseDeviceNameIntoConfig(deviceName); + // AUTO case + { + if (deviceName.find("AUTO:") == 0) { + IE_THROW() + << "You can get specific metrics with the GetMetric only for the MULTI itself (without devices). " + "To get individual devices's metrics call GetMetric for each device separately"; + } + } + + std::string pluginName = deviceName; + if (pluginName == "AUTO") { + pluginName = "MULTI"; + } + + auto parsed = parseDeviceNameIntoConfig(pluginName); // we need to return a copy of Parameter object which is created on Core side, // not in InferenceEngine plugin side, which can be unloaded from Core in a parallel thread @@ -629,11 +642,14 @@ class CoreImpl : public InferenceEngine::ICore, public std::enable_shared_from_t * @param deviceName A name of device * @return Reference to a CPP plugin wrapper */ - InferenceEngine::InferencePlugin GetCPPPluginByName(const std::string& deviceName) const { + InferenceEngine::InferencePlugin GetCPPPluginByName(const std::string& pluginName) const { OV_ITT_SCOPE(FIRST_INFERENCE, InferenceEngine::itt::domains::IE_LT, "CoreImpl::GetCPPPluginByName"); std::lock_guard lock(pluginsMutex); - + auto deviceName = pluginName; + if (deviceName == "AUTO") { + deviceName = "MULTI"; + } auto it = pluginRegistry.find(deviceName); if (it == pluginRegistry.end()) { IE_THROW() << "Device with \"" << deviceName << "\" name is not registered in the InferenceEngine"; @@ -856,9 +872,9 @@ class CoreImpl : public InferenceEngine::ICore, public std::enable_shared_from_t } else if (deviceName.find("AUTO") == 0) { auto pos = deviceName.find_first_of(":"); if (pos != std::string::npos) { - deviceNames = InferenceEngine::DeviceIDParser::getHeteroDevices(deviceName.substr(pos + 1)); + deviceNames = InferenceEngine::DeviceIDParser::getMultiDevices(deviceName.substr(pos + 1)); } - deviceNames.emplace_back("AUTO"); + deviceNames.emplace_back("MULTI"); } else { deviceNames.push_back(deviceName); } diff --git a/inference-engine/src/multi_device/CMakeLists.txt b/inference-engine/src/multi_device/CMakeLists.txt index d028c5c7562b10..75c6d43b615b95 100644 --- a/inference-engine/src/multi_device/CMakeLists.txt +++ b/inference-engine/src/multi_device/CMakeLists.txt @@ -12,7 +12,7 @@ ie_add_plugin(NAME ${TARGET_NAME} SOURCES ${SOURCES} ${HEADERS} VERSION_DEFINES_FOR multi_device_plugin.cpp) -target_link_libraries(${TARGET_NAME} PRIVATE inference_engine) +target_link_libraries(${TARGET_NAME} PRIVATE inference_engine ngraph inference_engine_transformations) set_ie_threading_interface_for(${TARGET_NAME}) diff --git a/inference-engine/src/multi_device/multi_device_plugin.cpp b/inference-engine/src/multi_device/multi_device_plugin.cpp index 66c41380c58530..263cfdf165ef09 100644 --- a/inference-engine/src/multi_device/multi_device_plugin.cpp +++ b/inference-engine/src/multi_device/multi_device_plugin.cpp @@ -10,6 +10,10 @@ #include #include +#include +#include +#include "ngraph_ops/convolution_ie.hpp" +#include "ngraph_ops/deconvolution_ie.hpp" #include #include @@ -21,6 +25,30 @@ namespace MultiDevicePlugin { using namespace InferenceEngine; namespace { + + std::string GetNetworkPrecision(const InferenceEngine::CNNNetwork &network) { + auto nGraphFunc = network.getFunction(); + bool isINTModel = ngraph::op::util::has_op_with_type(nGraphFunc); + if (isINTModel) { + return METRIC_VALUE(INT8); + } + for (auto & node : nGraphFunc->get_ordered_ops()) { + if (std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node)) { + auto layerType = node->input(1).get_element_type().get_type_name(); + if (layerType == "f32") + return METRIC_VALUE(FP32); + if (layerType == "f16") + return METRIC_VALUE(FP16); + } + } + return METRIC_VALUE(FP32); + } + std::map mergeConfigs(std::map config, const std::map & local) { for (auto && kvp : local) { @@ -28,7 +56,10 @@ namespace { } return config; } - std::vector supported_configKeys = {MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES}; + std::vector supported_configKeys = { + MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, + CONFIG_KEY_INTERNAL(WORK_MODE) + }; } // namespace std::map MultiDeviceInferencePlugin::GetSupportedConfig( @@ -98,8 +129,8 @@ std::vector MultiDeviceInferencePlugin::ParseMetaDevices(cons InferenceEngine::Parameter MultiDeviceInferencePlugin::GetConfig(const std::string& name, const std::map & options) const { - if (name == MULTI_CONFIG_KEY(DEVICE_PRIORITIES)) { - auto it = _config.find(MULTI_CONFIG_KEY(DEVICE_PRIORITIES)); + if (supported_configKeys.end() != std::find(supported_configKeys.begin(), supported_configKeys.end(), name)) { + auto it = _config.find(name); if (it == _config.end()) { IE_THROW() << "Value for KEY_MULTI_DEVICE_PRIORITIES is not set"; } else { @@ -148,17 +179,23 @@ InferenceEngine::Parameter MultiDeviceInferencePlugin::GetMetric(const std::stri // Is called only when caching is enabled IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetwork(const std::string& modelPath, const std::map& config) { - return LoadExeNetworkImpl(modelPath, {}, config); + return LoadNetworkImpl(modelPath, {}, config); } IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(const CNNNetwork &network, const std::map& config) { - return LoadExeNetworkImpl({}, network, config); + if (network.getFunction() == nullptr) { + IE_THROW() << "MULTI device supports just ngraph network representation"; + } + + auto networkPrecision = GetNetworkPrecision(network); + return LoadNetworkImpl({}, network, config, networkPrecision); } -IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(const std::string& modelPath, +IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetworkImpl(const std::string& modelPath, CNNNetwork network, - const std::map& config) { + const std::map& config, + const std::string &networkPrecision) { if (GetCore() == nullptr) { IE_THROW() << "Please, work with MULTI device via InferenceEngine::Core object"; } @@ -168,16 +205,39 @@ IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(c } auto fullConfig = mergeConfigs(_config, config); + // collect the settings that are applicable to the devices we are loading the network to + std::unordered_map multiNetworkConfig; + std::vector metaDevices; + auto workMode = fullConfig.find(CONFIG_KEY_INTERNAL(WORK_MODE)); auto priorities = fullConfig.find(MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES); + + // not found device priorities for -d AUTO use case if (priorities == fullConfig.end()) { - IE_THROW() << "KEY_MULTI_DEVICE_PRIORITIES key is not set for MULTI device"; + if (workMode != fullConfig.end()) { + std::string allDevices; + auto availableDevices = GetCore()->GetAvailableDevices(); + if (availableDevices.empty()) { + IE_THROW(NotFound) << "No available device found"; + } + for (auto&& device : availableDevices) { + allDevices += device; + allDevices += ((device == availableDevices[availableDevices.size()-1]) ? "" : ","); + } + metaDevices = ParseMetaDevices(allDevices, fullConfig); + multiNetworkConfig.insert({MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, allDevices}); + } else { + IE_THROW() << "KEY_MULTI_DEVICE_PRIORITIES key is not set for MULTI device"; + } + } else { // for use case -d MULTI:xPU or -d AUTO:xPU + metaDevices = ParseMetaDevices(priorities->second, fullConfig); + multiNetworkConfig.insert(*priorities); + } + // check if it is -d AUTO or -d AUTO:xPU use case + if (workMode != fullConfig.end()) { + auto targetDevice = SelectDevice(metaDevices, networkPrecision); + // std::cout << "!!! DEBUG: select device is " << targetDevice.deviceName << std::endl; + metaDevices = { targetDevice }; } - - auto metaDevices = ParseMetaDevices(priorities->second, fullConfig); - - // collect the settings that are applicable to the devices we are loading the network to - std::unordered_map multiNetworkConfig; - multiNetworkConfig.insert(*priorities); DeviceMap executableNetworkPerDevice; std::mutex load_mutex; @@ -275,4 +335,125 @@ QueryNetworkResult MultiDeviceInferencePlugin::QueryNetwork(const CNNNetwork& return queryResult; } + +DeviceInformation MultiDeviceInferencePlugin::SelectDevice(const std::vector& metaDevices, const std::string& networkPrecision) { + if (metaDevices.empty()) { + IE_THROW(NotFound) << "No available device to select in AUTO plugin"; + } + if (metaDevices.size() == 1) { + return metaDevices.at(0); + } + + std::vector CPU; + std::vector dGPU; + std::vector iGPU; + std::vector MYRIAD; + std::vector VPUX; + + for (auto& item : metaDevices) { + if (item.deviceName.find("CPU") == 0) { + CPU.push_back(item); + continue; + } + if (item.deviceName.find("MYRIAD") == 0) { + MYRIAD.push_back(item); + continue; + } + if (item.deviceName.find("VPUX") == 0) { + VPUX.push_back(item); + continue; + } + if (item.deviceName.find("GPU") == 0) { + auto gpuFullDeviceName = GetCore()->GetMetric(item.deviceName, METRIC_KEY(FULL_DEVICE_NAME)).as(); + if (gpuFullDeviceName.find("iGPU") != std::string::npos) { + iGPU.push_back(item); + } else if (gpuFullDeviceName.find("dGPU") != std::string::npos) { + dGPU.push_back(item); + } + continue; + } + } + + if (CPU.empty() && dGPU.empty() && iGPU.empty() && MYRIAD.empty() && VPUX.empty()) { + IE_THROW(NotFound) << "No available device found"; + } + + // Priority of selecting device: dGPU > VPUX > iGPU > MYRIAD > CPU + if (!dGPU.empty()) { + for (auto&& item : dGPU) { + std::vector capability = GetCore()->GetMetric(item.deviceName, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + auto supportNetwork = std::find(capability.begin(), capability.end(), networkPrecision); + if (supportNetwork != capability.end()) { + return item; + } + } + } else if (!VPUX.empty()) { + for (auto&& item : VPUX) { + std::vector capability = GetCore()->GetMetric(item.deviceName, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + auto supportNetwork = std::find(capability.begin(), capability.end(), networkPrecision); + if (supportNetwork != capability.end()) { + return item; + } + } + } else if (!iGPU.empty()) { + for (auto&& item : iGPU) { + std::vector capability = GetCore()->GetMetric(item.deviceName, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + auto supportNetwork = std::find(capability.begin(), capability.end(), networkPrecision); + if (supportNetwork != capability.end()) { + return item; + } + } + } else if (!MYRIAD.empty()) { + for (auto&& item : MYRIAD) { + std::vector capability = GetCore()->GetMetric(item.deviceName, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + auto supportNetwork = std::find(capability.begin(), capability.end(), networkPrecision); + if (supportNetwork != capability.end()) { + return item; + } + } + } + + // If network is FP32 but there is no device support FP32, offload FP32 network to device support FP16. + if (networkPrecision == "FP32") { + if (!dGPU.empty()) { + for (auto&& item : dGPU) { + std::vector capability = GetCore()->GetMetric(item.deviceName, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + auto supportNetwork = std::find(capability.begin(), capability.end(), "FP16"); + if (supportNetwork != capability.end()) { + return item; + } + } + } else if (!VPUX.empty()) { + for (auto&& item : VPUX) { + std::vector capability = GetCore()->GetMetric(item.deviceName, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + auto supportNetwork = std::find(capability.begin(), capability.end(), "FP16"); + if (supportNetwork != capability.end()) { + return item; + } + } + } else if (!iGPU.empty()) { + for (auto&& item : iGPU) { + std::vector capability = GetCore()->GetMetric(item.deviceName, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + auto supportNetwork = std::find(capability.begin(), capability.end(), "FP16"); + if (supportNetwork != capability.end()) { + return item; + } + } + } else if (!MYRIAD.empty()) { + for (auto&& item : MYRIAD) { + std::vector capability = GetCore()->GetMetric(item.deviceName, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + auto supportNetwork = std::find(capability.begin(), capability.end(), "FP16"); + if (supportNetwork != capability.end()) { + return item; + } + } + } + } + + if (CPU.empty()) { + IE_THROW() << "Cannot select any device"; + } + return CPU[0]; +} + } // namespace MultiDevicePlugin diff --git a/inference-engine/src/multi_device/multi_device_plugin.hpp b/inference-engine/src/multi_device/multi_device_plugin.hpp index c900c0d85657b8..4021c5ec9e1aea 100644 --- a/inference-engine/src/multi_device/multi_device_plugin.hpp +++ b/inference-engine/src/multi_device/multi_device_plugin.hpp @@ -41,9 +41,11 @@ class MultiDeviceInferencePlugin : public InferenceEngine::IInferencePlugin { const MultiDevicePlugin::DeviceName & deviceName) const; private: - InferenceEngine::IExecutableNetworkInternal::Ptr LoadExeNetworkImpl(const std::string& modelPath, + InferenceEngine::IExecutableNetworkInternal::Ptr LoadNetworkImpl(const std::string& modelPath, InferenceEngine::CNNNetwork network, - const std::map& config); + const std::map& config, + const std::string &networkPrecision = METRIC_VALUE(FP32)); + DeviceInformation SelectDevice(const std::vector& metaDevices, const std::string& networkPrecision = METRIC_VALUE(FP32)); }; } // namespace MultiDevicePlugin diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_internal_plugin_config.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_internal_plugin_config.hpp index 10963a5c78c144..913ea53130578e 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_internal_plugin_config.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_internal_plugin_config.hpp @@ -45,6 +45,15 @@ DECLARE_CONFIG_KEY(CPU_THREADS_PER_STREAM); */ DECLARE_CONFIG_KEY(FORCE_DISABLE_CACHE); +/** + * @brief The name for setting work mode internal in MULTI device plugin option. + * + * This option should be used with value only: + * PluginConfigInternalParams::MULTI_MODE_AUTO or PluginConfigInternalParams::MULTI_MODE_LEGACY + */ +DECLARE_CONFIG_KEY(WORK_MODE); +DECLARE_CONFIG_VALUE(MULTI_MODE_AUTO); + } // namespace PluginConfigInternalParams } // namespace InferenceEngine diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/config.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/config.cpp index 00ece757453591..aec20bce2cda5f 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/config.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/config.cpp @@ -30,11 +30,6 @@ namespace { {{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES , CommonTestUtils::DEVICE_CPU}} }; - const std::vector> AutoConfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_CPU}, {InferenceEngine::PluginConfigParams::KEY_PERF_COUNT, "YES"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_CPU}, {std::string("AUTO_"), "NAN"}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, CorrectConfigTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -53,7 +48,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(AutoConfigs)), + ::testing::ValuesIn(MultiConfigs)), CorrectConfigTests::getTestCaseName); const std::vector> inconfigs = { @@ -71,13 +66,6 @@ namespace { {InferenceEngine::PluginConfigParams::KEY_DYN_BATCH_LIMIT, "NAN"}} }; - const std::vector> autoinconfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_CPU}, - {InferenceEngine::PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS, "OFF"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_CPU}, - {InferenceEngine::PluginConfigParams::KEY_PERF_COUNT, "ON"}} - }; - const std::vector> multiconf = { {{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES , CommonTestUtils::DEVICE_CPU}} }; @@ -96,6 +84,13 @@ namespace { ::testing::ValuesIn(multiconf)), CorrectConfigAPITests::getTestCaseName); + INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, CorrectConfigAPITests, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(multiconf)), + CorrectConfigAPITests::getTestCaseName); + INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, IncorrectConfigTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -114,7 +109,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoinconfigs)), + ::testing::ValuesIn(multiinconfigs)), IncorrectConfigTests::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, IncorrectConfigAPITests, @@ -135,7 +130,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoinconfigs)), + ::testing::ValuesIn(multiinconfigs)), IncorrectConfigAPITests::getTestCaseName); } // namespace \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/core_integration.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/core_integration.cpp index 040911489e5e69..e209712f2ba0b4 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/core_integration.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/core_integration.cpp @@ -47,7 +47,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( smoke_IEClassGetMetricTest, IEClassGetMetricTest_OPTIMIZATION_CAPABILITIES, - ::testing::Values("CPU", "AUTO")); + ::testing::Values("CPU")); INSTANTIATE_TEST_SUITE_P( smoke_IEClassGetMetricTest, IEClassGetMetricTest_RANGE_FOR_ASYNC_INFER_REQUESTS, diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/core_threading_tests.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/core_threading_tests.cpp index fe294e97075b5f..288ac006dd75d6 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/core_threading_tests.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/core_threading_tests.cpp @@ -10,7 +10,7 @@ const Params params[] = { std::tuple{ CommonTestUtils::DEVICE_CPU, {{ CONFIG_KEY(PERF_COUNT), CONFIG_VALUE(YES) }}}, std::tuple{ CommonTestUtils::DEVICE_HETERO, {{ "TARGET_FALLBACK", CommonTestUtils::DEVICE_CPU }}}, std::tuple{ CommonTestUtils::DEVICE_MULTI, {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_CPU }}}, - std::tuple{ CommonTestUtils::DEVICE_AUTO, {{AUTO_CONFIG_KEY(DEVICE_LIST), CommonTestUtils::DEVICE_CPU }}}, + std::tuple{ CommonTestUtils::DEVICE_AUTO, {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_CPU }}}, }; const Params paramsStreams[] = { diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/exec_graph_info.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/exec_graph_info.cpp index ee0bad4bb1f051..73f8114a1f655a 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/exec_graph_info.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/exec_graph_info.cpp @@ -18,9 +18,6 @@ namespace { const std::vector> multiConfigs = { {{ InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES , CommonTestUtils::DEVICE_CPU}} }; - const std::vector> autoConfigs = { - {{ InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_CPU}} - }; INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, ExecGraphTests, ::testing::Combine( @@ -40,6 +37,6 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), + ::testing::ValuesIn(multiConfigs)), ExecGraphTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request.cpp index e866ffad849e86..07b3cf9ca402f8 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request.cpp @@ -24,10 +24,6 @@ namespace { {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_CPU}} }; - const std::vector> Autoconfigs = { - {{ AUTO_CONFIG_KEY(DEVICE_LIST) , CommonTestUtils::DEVICE_CPU}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, InferRequestTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -46,7 +42,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(Autoconfigs)), + ::testing::ValuesIn(Multiconfigs)), InferRequestTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_callback.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_callback.cpp index 8483b82c3db437..a22af7eda788e9 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_callback.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_callback.cpp @@ -21,10 +21,6 @@ const std::vector> multiConfigs = { {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_CPU}} }; -const std::vector> autoConfigs = { - {{ AUTO_CONFIG_KEY(DEVICE_LIST) , CommonTestUtils::DEVICE_CPU}} -}; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, CallbackTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -43,6 +39,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, CallbackTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), + ::testing::ValuesIn(multiConfigs)), CallbackTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_config.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_config.cpp index 9743bc7e35b305..42c426ca383720 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_config.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_config.cpp @@ -60,6 +60,13 @@ namespace { ::testing::ValuesIn(multiConfigs)), InferConfigTests::getTestCaseName); + INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, InferConfigTests, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(multiConfigs)), + InferConfigTests::getTestCaseName); + INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, InferConfigInTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -74,4 +81,11 @@ namespace { ::testing::ValuesIn(MultiInConfigs)), InferConfigInTests::getTestCaseName); + INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, InferConfigInTests, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(MultiInConfigs)), + InferConfigInTests::getTestCaseName); + } // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_input.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_input.cpp index 73bc9fb8f97ffa..a2776a3da9002d 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_input.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_input.cpp @@ -25,10 +25,6 @@ namespace { {InferenceEngine::PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS, InferenceEngine::PluginConfigParams::CPU_THROUGHPUT_AUTO}} }; - const std::vector> autoConfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_CPU}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, InferRequestInputTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -47,7 +43,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), + ::testing::ValuesIn(multiConfigs)), InferRequestInputTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_output.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_output.cpp index 36ad2752244d6f..3a8f8bf9c91023 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_output.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/infer_request_output.cpp @@ -21,10 +21,6 @@ namespace { {InferenceEngine::PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS, InferenceEngine::PluginConfigParams::CPU_THROUGHPUT_AUTO}} }; - const std::vector> autoConfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_CPU}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, InferRequestOutputTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -43,7 +39,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), + ::testing::ValuesIn(multiConfigs)), InferRequestOutputTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_core_integration.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_core_integration.cpp index 21b83b0330ca11..1a3baecddb689c 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_core_integration.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_core_integration.cpp @@ -48,7 +48,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( smoke_OVClassGetMetricTest, OVClassGetMetricTest_OPTIMIZATION_CAPABILITIES, - ::testing::Values("CPU", "AUTO")); + ::testing::Values("CPU")); INSTANTIATE_TEST_SUITE_P( smoke_OVClassGetMetricTest, OVClassGetMetricTest_RANGE_FOR_ASYNC_INFER_REQUESTS, diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/set_blob_of_kind.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/set_blob_of_kind.cpp index 0ce335bcfada2c..5b2355476ec573 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/set_blob_of_kind.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/set_blob_of_kind.cpp @@ -15,7 +15,6 @@ const std::vector blobKinds = { }; const SetBlobOfKindConfig cpuConfig{}; //nothing special -const SetBlobOfKindConfig autoConfig{}; const SetBlobOfKindConfig multiConfig{{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_CPU}}; const SetBlobOfKindConfig heteroConfig{{ "TARGET_FALLBACK", CommonTestUtils::DEVICE_CPU }}; @@ -34,8 +33,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_SetBlobOfKindMULTI, SetBlobOfKindTest, INSTANTIATE_TEST_SUITE_P(smoke_SetBlobOfKindAUTO, SetBlobOfKindTest, ::testing::Combine(::testing::ValuesIn(blobKinds), - ::testing::Values(CommonTestUtils::DEVICE_AUTO + std::string(":") + CommonTestUtils::DEVICE_CPU), - ::testing::Values(autoConfig)), + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::Values(multiConfig)), SetBlobOfKindTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_SetBlobOfKindHETERO, SetBlobOfKindTest, diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/set_preprocess.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/set_preprocess.cpp index d3450e08ee27b2..2acb232ea70e19 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/set_preprocess.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/set_preprocess.cpp @@ -27,10 +27,6 @@ namespace { {{ InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES , CommonTestUtils::DEVICE_CPU}} }; - const std::vector> autoConfigs = { - {{ InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_CPU}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, PreprocessTest, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -56,7 +52,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), + ::testing::ValuesIn(multiConfigs)), PreprocessTest::getTestCaseName); @@ -169,7 +165,7 @@ namespace { ::testing::Bool(), ::testing::Bool(), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), + ::testing::ValuesIn(multiConfigs)), PreprocessConversionTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, PreprocessDynamicallyInSetBlobTest, @@ -183,7 +179,7 @@ namespace { ::testing::Values(true), // only SetBlob ::testing::Values(true), // only SetBlob ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), + ::testing::ValuesIn(multiConfigs)), PreprocessDynamicallyInSetBlobTest::getTestCaseName); } // namespace \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/test_plugin.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/test_plugin.cpp index f8728390c9ed9b..c03c1a4f121cc2 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/test_plugin.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/test_plugin.cpp @@ -21,10 +21,6 @@ namespace { {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_CPU}} }; - const std::vector> AutoConfigs = { - {{ AUTO_CONFIG_KEY(DEVICE_LIST) , CommonTestUtils::DEVICE_CPU}} - }; - const std::vector> configsInput = { {}, {{InferenceEngine::PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS, InferenceEngine::PluginConfigParams::CPU_THROUGHPUT_AUTO}} @@ -36,10 +32,6 @@ namespace { {InferenceEngine::PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS, InferenceEngine::PluginConfigParams::CPU_THROUGHPUT_AUTO}} }; - const std::vector> AutoConfigsInputOutput = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_CPU}} - }; - const std::vector> configsOutput = { {}, {{InferenceEngine::PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS, InferenceEngine::PluginConfigParams::CPU_THROUGHPUT_AUTO}} @@ -64,7 +56,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(AutoConfigsInputOutput)), + ::testing::ValuesIn(MultiConfigsInputOutput)), BehaviorTestOutput::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, BehaviorTests, @@ -85,7 +77,7 @@ namespace { ::testing::Combine( ::testing::Values(InferenceEngine::Precision::FP32), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(AutoConfigs)), + ::testing::ValuesIn(MultiConfigs)), BehaviorTests::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, BehaviorTestInput, @@ -106,7 +98,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(AutoConfigsInputOutput)), + ::testing::ValuesIn(MultiConfigsInputOutput)), BehaviorTestInput::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/version.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/version.cpp index 66b5a3c06685cd..269e736abd6430 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/version.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/version.cpp @@ -14,10 +14,6 @@ namespace { {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_CPU}} }; - const std::vector> Autoconfigs = { - {{ AUTO_CONFIG_KEY(DEVICE_LIST) , CommonTestUtils::DEVICE_CPU}} - }; - const std::vector> Heteroconfigs = { {{ HETERO_CONFIG_KEY(DUMP_GRAPH_DOT) , CommonTestUtils::DEVICE_CPU}} }; @@ -40,7 +36,7 @@ namespace { ::testing::Combine( ::testing::Values(InferenceEngine::Precision::FP32), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(Autoconfigs)), + ::testing::ValuesIn(Multiconfigs)), VersionTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Hetero_BehaviorTests, VersionTest, diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/config.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/config.cpp index 5788c3ee2705a5..22a13191dc5298 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/config.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/config.cpp @@ -35,19 +35,6 @@ namespace { {{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES , CommonTestUtils::DEVICE_GPU}, {InferenceEngine::PluginConfigParams::KEY_DEVICE_ID, "DEVICE_UNKNOWN"}} }; - - const std::vector> autoinconfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}, - {InferenceEngine::PluginConfigParams::KEY_PERF_COUNT, "ON"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}, - {InferenceEngine::PluginConfigParams::KEY_CONFIG_FILE, "unknown_file"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}, - {InferenceEngine::PluginConfigParams::KEY_DUMP_KERNELS, "ON"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}, - {InferenceEngine::PluginConfigParams::KEY_TUNING_MODE, "TUNING_UNKNOWN_MODE"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}, - {InferenceEngine::PluginConfigParams::KEY_DEVICE_ID, "DEVICE_UNKNOWN"}} - }; IE_SUPPRESS_DEPRECATED_END INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, IncorrectConfigTests, @@ -68,7 +55,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoinconfigs)), + ::testing::ValuesIn(multiinconfigs)), IncorrectConfigTests::getTestCaseName); @@ -103,17 +90,6 @@ namespace { {{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES , CommonTestUtils::DEVICE_GPU}} }; - const std::vector> autoconf = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}, - {InferenceEngine::PluginConfigParams::KEY_PERF_COUNT, "YES"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}, - {InferenceEngine::PluginConfigParams::KEY_PERF_COUNT, "YES"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}, - {std::string("AUTO_"), "NAN"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}, - {std::string("AUTO_"), "NAN"}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, CorrectConfigAPITests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -139,7 +115,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoconf)), + ::testing::ValuesIn(multiconf)), CorrectConfigAPITests::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, IncorrectConfigAPITests, @@ -160,7 +136,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoinconfigs)), + ::testing::ValuesIn(multiinconfigs)), IncorrectConfigAPITests::getTestCaseName); diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request.cpp index 07e6f78f9ef968..ad94fdaa7e23ef 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request.cpp @@ -18,11 +18,6 @@ namespace { {{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_GPU}} }; - const std::vector> autoconfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_GPU}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, InferRequestTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -41,7 +36,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoconfigs)), + ::testing::ValuesIn(configs)), InferRequestTests::getTestCaseName); } // namespace \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_callback.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_callback.cpp index a0108e84339d4a..8c8a0e7fb3206b 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_callback.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_callback.cpp @@ -19,14 +19,6 @@ const std::vector> multiConfigs = { {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_GPU}} }; -const std::vector> autoConfigs = { - {{ AUTO_CONFIG_KEY(DEVICE_LIST) , CommonTestUtils::DEVICE_GPU}} -}; - -const std::vector> auto_cpu_gpu_conf = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}} -}; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, CallbackTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -45,13 +37,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, CallbackTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), - CallbackTests::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_AutoCG_BehaviorTests, CallbackTests, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(auto_cpu_gpu_conf)), + ::testing::ValuesIn(multiConfigs)), CallbackTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_input.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_input.cpp index f63be4c8854326..bce8d53a25d75e 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_input.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_input.cpp @@ -25,14 +25,6 @@ namespace { InferenceEngine::PluginConfigParams::GPU_THROUGHPUT_AUTO}} }; - const std::vector> autoConfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}} - }; - - const std::vector> auto_cpu_gpu_conf = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, InferRequestInputTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -51,14 +43,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), - InferRequestInputTests::getTestCaseName); - - INSTANTIATE_TEST_SUITE_P(smoke_AutoCG_BehaviorTests, InferRequestInputTests, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(auto_cpu_gpu_conf)), + ::testing::ValuesIn(multiConfigs)), InferRequestInputTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_output.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_output.cpp index 638106e6a75a52..b4e40a831b7078 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_output.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/infer_request_output.cpp @@ -21,14 +21,6 @@ namespace { {InferenceEngine::PluginConfigParams::KEY_GPU_THROUGHPUT_STREAMS, InferenceEngine::PluginConfigParams::GPU_THROUGHPUT_AUTO}} }; - const std::vector> autoConfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}} - }; - - const std::vector> auto_cpu_gpu_conf = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, InferRequestOutputTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -47,13 +39,6 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), - InferRequestOutputTests::getTestCaseName); - - INSTANTIATE_TEST_SUITE_P(smoke_AutoCG_BehaviorTests, InferRequestOutputTests, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(auto_cpu_gpu_conf)), + ::testing::ValuesIn(multiConfigs)), InferRequestOutputTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/set_preprocess.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/set_preprocess.cpp index 136cb96436ca61..97cdf1789e6641 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/set_preprocess.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/set_preprocess.cpp @@ -22,14 +22,6 @@ namespace { {{ InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES , CommonTestUtils::DEVICE_GPU}} }; - const std::vector> autoConfigs = { - {{ InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_GPU}} - }; - - const std::vector> auto_cpu_gpu_conf = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}} - }; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, PreprocessTest, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -48,17 +40,9 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoConfigs)), - PreprocessTest::getTestCaseName); - - INSTANTIATE_TEST_SUITE_P(smoke_AutoCG_BehaviorTests, PreprocessTest, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(auto_cpu_gpu_conf)), + ::testing::ValuesIn(multiConfigs)), PreprocessTest::getTestCaseName); - const std::vector ioPrecisions = { InferenceEngine::Precision::FP32, InferenceEngine::Precision::U8 diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/test_plugin.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/test_plugin.cpp index 3d181f591505b3..98069d07303168 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/test_plugin.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/test_plugin.cpp @@ -31,14 +31,6 @@ namespace { {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_GPU}} }; - const std::vector> AutoConfigs = { - {{ AUTO_CONFIG_KEY(DEVICE_LIST) , CommonTestUtils::DEVICE_GPU}} - }; - - const std::vector> auto_cpu_gpu_conf = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}} - }; - const std::vector> configsInput = { {}, {{InferenceEngine::PluginConfigParams::KEY_GPU_THROUGHPUT_STREAMS, InferenceEngine::PluginConfigParams::GPU_THROUGHPUT_AUTO}} @@ -73,14 +65,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(AutoConfigs)), - BehaviorTestOutput::getTestCaseName); - - INSTANTIATE_TEST_SUITE_P(smoke_AutoCG_BehaviorTests, BehaviorTestOutput, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(auto_cpu_gpu_conf)), + ::testing::ValuesIn(MultiConfigsInputOutput)), BehaviorTestOutput::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, BehaviorTests, @@ -101,14 +86,7 @@ namespace { ::testing::Combine( ::testing::Values(InferenceEngine::Precision::FP32), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(AutoConfigs)), - BehaviorTests::getTestCaseName); - - INSTANTIATE_TEST_SUITE_P(smoke_AutoCG_BehaviorTests, BehaviorTests, - ::testing::Combine( - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(auto_cpu_gpu_conf)), + ::testing::ValuesIn(MultiConfigs)), BehaviorTests::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, BehaviorTestInput, @@ -129,15 +107,7 @@ namespace { ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(AutoConfigs)), - BehaviorTestInput::getTestCaseName); - - - INSTANTIATE_TEST_SUITE_P(smoke_AutoCG_BehaviorTests, BehaviorTestInput, - ::testing::Combine( - ::testing::ValuesIn(netPrecisionsForAutoCG), - ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(auto_cpu_gpu_conf)), + ::testing::ValuesIn(MultiConfigsInputOutput)), BehaviorTestInput::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/version.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/version.cpp index 6b69c22855ecee..c02a209e9d59a9 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/version.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/behavior/version.cpp @@ -14,14 +14,6 @@ namespace { {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES) , CommonTestUtils::DEVICE_GPU}} }; - const std::vector> Autoconfigs = { - {{ AUTO_CONFIG_KEY(DEVICE_LIST) , CommonTestUtils::DEVICE_GPU}} - }; - - const std::vector> auto_cpu_gpu_conf = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU}} - }; - const std::vector> Heteroconfigs = { {{ HETERO_CONFIG_KEY(DUMP_GRAPH_DOT) , CommonTestUtils::DEVICE_GPU}} }; @@ -44,14 +36,7 @@ namespace { ::testing::Combine( ::testing::Values(InferenceEngine::Precision::FP32), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(Autoconfigs)), - VersionTest::getTestCaseName); - - INSTANTIATE_TEST_SUITE_P(smoke_AutoCG_BehaviorTests, VersionTest, - ::testing::Combine( - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(auto_cpu_gpu_conf)), + ::testing::ValuesIn(Multiconfigs)), VersionTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Hetero_BehaviorTests, VersionTest, diff --git a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/config.cpp b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/config.cpp index 09c9f9e7d0d9b9..7de19efce6ab8a 100644 --- a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/config.cpp +++ b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/config.cpp @@ -257,19 +257,11 @@ INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests, CorrectConfigTests, ::testing::ValuesIn(getCorrectMultiConfigs())), CorrectConfigTests::getTestCaseName); -const std::vector>& getCorrectAutoConfigs() { - static const std::vector> correctAutoConfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_MYRIAD}, {InferenceEngine::PluginConfigParams::KEY_PERF_COUNT, "YES"}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , CommonTestUtils::DEVICE_MYRIAD}, {std::string("AUTO_"), "NAN"}} - }; - return correctAutoConfigs; -} - INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, CorrectConfigTests, ::testing::Combine( ::testing::ValuesIn(getPrecisions()), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(getCorrectAutoConfigs())), + ::testing::ValuesIn(getCorrectMultiConfigs())), CorrectConfigTests::getTestCaseName); const std::vector>& getDefaultEntries() { @@ -908,44 +900,6 @@ const std::vector>& getIncorrectMultiConfigs( return incorrectMultiConfigs; } -const std::vector>& getIncorrectAutoConfigs() { - static const std::vector> incorrectAutoConfigs = { - { - {InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_AUTO}, - {KEY_LOG_LEVEL, "INCORRECT_LOG_LEVEL"}, - }, - { - {InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_AUTO}, - {InferenceEngine::MYRIAD_PROTOCOL, "BLUETOOTH"} - }, - { - {InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_AUTO}, - {InferenceEngine::MYRIAD_ENABLE_HW_ACCELERATION, "ON"} - }, - { - {InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_AUTO}, - {InferenceEngine::MYRIAD_ENABLE_RECEIVING_TENSOR_TIME, "ON"} - }, - { - {InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_AUTO}, - {KEY_PERF_COUNT, "ON"} - }, - { - {InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_AUTO}, - {InferenceEngine::MYRIAD_THROUGHPUT_STREAMS, "ONE"} - }, - { - {InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_AUTO}, - {KEY_EXCLUSIVE_ASYNC_REQUESTS, "ON"} - }, - { - {InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_AUTO}, - {InferenceEngine::MYRIAD_DDR_TYPE, "1GB"} - }, - }; - return incorrectAutoConfigs; -} - INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests, IncorrectConfigTests, ::testing::Combine( ::testing::ValuesIn(getPrecisions()), @@ -957,7 +911,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, IncorrectConfigTests, ::testing::Combine( ::testing::ValuesIn(getPrecisions()), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(getIncorrectAutoConfigs())), + ::testing::ValuesIn(getIncorrectMultiConfigs())), IncorrectConfigTests::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, IncorrectConfigSingleOptionTests, @@ -998,6 +952,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, IncorrectConfigAPITests, ::testing::Combine( ::testing::ValuesIn(getPrecisions()), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(getIncorrectAutoConfigs())), + ::testing::ValuesIn(getIncorrectMultiConfigs())), IncorrectConfigAPITests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/infer_request.cpp b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/infer_request.cpp index 341a320ec3d69d..f466f2d7172216 100644 --- a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/infer_request.cpp +++ b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/infer_request.cpp @@ -17,11 +17,6 @@ const std::vector> configs = { {{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_MYRIAD}} }; -const std::vector> autoconfigs = { - {{InferenceEngine::KEY_AUTO_DEVICE_LIST, CommonTestUtils::DEVICE_MYRIAD}}, - {{InferenceEngine::KEY_AUTO_DEVICE_LIST , std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_MYRIAD}} -}; - INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, InferRequestTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), @@ -40,6 +35,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, InferRequestTests, ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_AUTO), - ::testing::ValuesIn(autoconfigs)), + ::testing::ValuesIn(configs)), InferRequestTests::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/exec_graph_info.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/exec_graph_info.hpp index e0287824940259..9b93bbef0e26b5 100644 --- a/inference-engine/tests/functional/plugin/shared/include/behavior/exec_graph_info.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/exec_graph_info.hpp @@ -58,7 +58,8 @@ TEST_P(ExecGraphTests, CheckExecGraphInfoBeforeExecution) { // Create CNNNetwork from ngrpah::Function InferenceEngine::CNNNetwork cnnNet(function); InferenceEngine::CNNNetwork execGraph; - if (targetDevice != CommonTestUtils::DEVICE_MULTI && + if (targetDevice != CommonTestUtils::DEVICE_AUTO && + targetDevice != CommonTestUtils::DEVICE_MULTI && targetDevice != CommonTestUtils::DEVICE_TEMPLATE && targetDevice != CommonTestUtils::DEVICE_GNA) { // Load CNNNetwork to target plugins @@ -126,7 +127,8 @@ TEST_P(ExecGraphTests, CheckExecGraphInfoAfterExecution) { // Create CNNNetwork from ngrpah::Function InferenceEngine::CNNNetwork cnnNet(function); InferenceEngine::CNNNetwork execGraph; - if (targetDevice != CommonTestUtils::DEVICE_MULTI && + if (targetDevice != CommonTestUtils::DEVICE_AUTO && + targetDevice != CommonTestUtils::DEVICE_MULTI && targetDevice != CommonTestUtils::DEVICE_TEMPLATE && targetDevice != CommonTestUtils::DEVICE_GNA) { // Load CNNNetwork to target plugins @@ -206,7 +208,8 @@ TEST_P(ExecGraphTests, CheckExecGraphInfoSerialization) { // Create CNNNetwork from ngrpah::Function InferenceEngine::CNNNetwork cnnNet(function); InferenceEngine::CNNNetwork execGraph; - if (targetDevice != CommonTestUtils::DEVICE_MULTI && + if (targetDevice != CommonTestUtils::DEVICE_AUTO && + targetDevice != CommonTestUtils::DEVICE_MULTI && targetDevice != CommonTestUtils::DEVICE_TEMPLATE && targetDevice != CommonTestUtils::DEVICE_GNA) { // Load CNNNetwork to target plugins diff --git a/inference-engine/tests/functional/shared_test_classes/src/subgraph/reduce_eltwise.cpp b/inference-engine/tests/functional/shared_test_classes/src/subgraph/reduce_eltwise.cpp index b51ca490090767..14c2cf95ff69e0 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/subgraph/reduce_eltwise.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/subgraph/reduce_eltwise.cpp @@ -31,8 +31,7 @@ void ReduceEltwiseTest::SetUp() { CommonTestUtils::OpType opType; bool keepDims; InferenceEngine::Precision netPrecision; - std::string targetName; - std::tie(inputShape, axes, opType, keepDims, netPrecision, targetName) = this->GetParam(); + std::tie(inputShape, axes, opType, keepDims, netPrecision, targetDevice) = this->GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); auto paramOuts = ngraph::helpers::convert2OutputVector( From 528562a9fb095b52aab5141dc078e6d5b6d758ce Mon Sep 17 00:00:00 2001 From: Yury Gaydaychuk Date: Wed, 18 Aug 2021 13:15:32 +0300 Subject: [PATCH 019/102] [CPU] Deform. conv. - reference enforced (#6945) --- .../src/mkldnn_plugin/mkldnn_plugin.cpp | 1 - .../nodes/mkldnn_def_conv_node.cpp | 201 ++++++++++++------ .../nodes/mkldnn_def_conv_node.h | 16 +- .../deformable_convolution.cpp | 15 +- ngraph/test/runtime/ie/unit_test.manifest | 12 +- 5 files changed, 169 insertions(+), 76 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index a1e650dc82c718..a702c6d71ee35b 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -307,7 +307,6 @@ static void Transformation(CNNNetwork& clonedNetwork, const Config& conf) { pass_config->disable(); pass_config->disable(); pass_config->disable(); - pass_config->disable(); pass_config->enable(); pass_config->enable(); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_def_conv_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_def_conv_node.cpp index 4d29550eda0b48..370524be475d32 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_def_conv_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_def_conv_node.cpp @@ -741,9 +741,10 @@ struct jit_uni_def_conv_kernel_f32 : public jit_uni_def_conv_kernel, public jit_ bool MKLDNNDeformableConvolutionNode::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { - const auto defConvNode = ngraph::as_type_ptr(op); - if (!defConvNode) { - errorMessage = "Node is not an instance of DeformableConvolution form the operation set v1."; + if (!one_of(op->get_type_info(), + ngraph::op::v1::DeformableConvolution::type_info, + ngraph::op::v8::DeformableConvolution::type_info)) { + errorMessage = "Node is not an instance of DeformableConvolution form the operation set v1 or v8."; return false; } } catch (...) { @@ -759,28 +760,35 @@ MKLDNNDeformableConvolutionNode::MKLDNNDeformableConvolutionNode(const std::shar if (!isSupportedOperation(op, errorMessage)) { IE_THROW(NotImplemented) << errorMessage; } - auto defConvNode = ngraph::as_type_ptr(op); + auto defConvNodeBase = std::dynamic_pointer_cast(op); - group = defConvNode->get_group(); - deformable_group = defConvNode->get_deformable_group(); - - auto& strides = defConvNode->get_strides(); + group = defConvNodeBase->get_group(); + deformable_group = defConvNodeBase->get_deformable_group(); + auto& strides = defConvNodeBase->get_strides(); for (int i = 0; i < strides.size(); i++) { stride.push_back(strides[i]); } - auto& dilations = defConvNode->get_dilations(); + auto& dilations = defConvNodeBase->get_dilations(); for (int i = 1; i <= dilations.size(); i++) { dilation.push_back(dilations[dilations.size() - i] - 1); } - paddingL = defConvNode->get_pads_begin(); + paddingL = defConvNodeBase->get_pads_begin(); + + if (op->get_type_info() == ngraph::op::v8::DeformableConvolution::type_info) { + auto defConvNode = std::dynamic_pointer_cast(op); + with_bilinear_pad = defConvNode->get_bilinear_interpolation_pad(); + } else { + with_bilinear_pad = false; + } + enforceRef = (op->get_type_info() == ngraph::op::v8::DeformableConvolution::type_info); } void MKLDNNDeformableConvolutionNode::getSupportedDescriptors() { std::string errorPrefix = "DeformableConvolution layer with name '" + getName() + "' "; - if (getParentEdges().size() != 3) + if (getParentEdges().size() != 3 && getParentEdges().size() != 4) IE_THROW() << errorPrefix << "has incorrect number of input edges"; if (getChildEdges().empty()) IE_THROW() << errorPrefix << "has incorrect number of output edges"; @@ -806,22 +814,29 @@ void MKLDNNDeformableConvolutionNode::initSupportedPrimitiveDescriptors() { if (!supportedPrimitiveDescriptors.empty()) return; + size_t inputsNumber = getOriginalInputsNumber(); NodeConfig config; config.dynBatchSupport = false; - config.inConfs.resize(3); + config.inConfs.resize(inputsNumber); config.inConfs[0].constant = false; config.inConfs[0].inPlace = -1; config.inConfs[1].constant = false; config.inConfs[1].inPlace = -1; - config.inConfs[1].constant = false; - config.inConfs[1].inPlace = -1; + config.inConfs[2].constant = false; + config.inConfs[2].inPlace = -1; + if (inputsNumber > 3) { + config.inConfs[3].constant = false; + config.inConfs[3].inPlace = -1; + } config.outConfs.resize(1); config.outConfs[0].constant = false; config.outConfs[0].inPlace = -1; impl_desc_type impl_type; - if (mayiuse(cpu::x64::avx512_common)) { + if (enforceRef) { + impl_type = impl_desc_type::ref; + } else if (mayiuse(cpu::x64::avx512_common)) { impl_type = impl_desc_type::jit_avx512; } else if (mayiuse(cpu::x64::avx2)) { impl_type = impl_desc_type::jit_avx2; @@ -831,8 +846,8 @@ void MKLDNNDeformableConvolutionNode::initSupportedPrimitiveDescriptors() { impl_type = impl_desc_type::ref; } - if (mayiuse(cpu::x64::sse41)) { - // optimzed implementation + if (!enforceRef && mayiuse(cpu::x64::sse41)) { + // optimized implementation auto dataFormat = memory::format_tag::nhwc; auto offFormat = memory::format_tag::nchw; auto weiFormat = group > 1 ? mayiuse(avx512_common) ? memory::format_tag::gOIhw16i16o : memory::format_tag::gOIhw8i8o @@ -842,8 +857,25 @@ void MKLDNNDeformableConvolutionNode::initSupportedPrimitiveDescriptors() { memory::data_type::f32, dataFormat); config.inConfs[1].desc = MKLDNNPlugin::make_unique(getParentEdgeAt(1)->getShape().getStaticDims(), memory::data_type::f32, offFormat); - config.inConfs[2].desc = MKLDNNPlugin::make_unique(getParentEdgeAt(2)->getShape().getStaticDims(), - memory::data_type::f32, weiFormat); + + auto& wDims = getParentEdgeAt(2)->getShape().getStaticDims(); + if (group > 1 && wDims.size() != 5) { + auto new_dims = InferenceEngine::SizeVector({group, div_up(wDims[0], group)}); + for (int i = 1; i < wDims.size(); i++) { + new_dims.push_back(wDims[i]); + } + config.inConfs[2].desc = MKLDNNPlugin::make_unique(getParentEdgeAt(2)->getShape().getStaticDims(), + memory::data_type::f32, weiFormat); + } else { + config.inConfs[2].desc = MKLDNNPlugin::make_unique(getParentEdgeAt(2)->getShape().getStaticDims(), + memory::data_type::f32, weiFormat); + } + + + if (inputsNumber > 3) { + config.inConfs[3].desc = MKLDNNPlugin::make_unique(getParentEdgeAt(3)->getShape().getStaticDims(), + memory::data_type::f32, memory::format_tag::nchw); + } config.outConfs[0].desc = MKLDNNPlugin::make_unique(getChildEdgeAt(0)->getShape().getStaticDims(), memory::data_type::f32, dataFormat); supportedPrimitiveDescriptors.push_back({config, impl_type}); @@ -855,6 +887,10 @@ void MKLDNNDeformableConvolutionNode::initSupportedPrimitiveDescriptors() { memory::format_tag::nchw); config.inConfs[2].desc = MKLDNNPlugin::make_unique(getParentEdgeAt(2)->getShape().getStaticDims(), memory::data_type::f32, memory::format_tag::oihw); + if (inputsNumber > 3) { + config.inConfs[3].desc = MKLDNNPlugin::make_unique(getParentEdgeAt(3)->getShape().getStaticDims(), memory::data_type::f32, + memory::format_tag::nchw); + } config.outConfs[0].desc = MKLDNNPlugin::make_unique(getChildEdgeAt(0)->getShape().getStaticDims(), memory::data_type::f32, memory::format_tag::nchw); supportedPrimitiveDescriptors.push_back({config, impl_type}); @@ -874,6 +910,7 @@ void MKLDNNDeformableConvolutionNode::createPrimitive() { jcp.dg = deformable_group; jcp.ngroups = group; + jcp.mb = srcDims[0]; jcp.oc = dstDims[1] / jcp.ngroups; @@ -884,9 +921,8 @@ void MKLDNNDeformableConvolutionNode::createPrimitive() { jcp.oh = dstDims[2]; jcp.ow = dstDims[3]; - bool with_groups = group > 1; - jcp.kh = weiDims[with_groups + 2]; - jcp.kw = weiDims[with_groups + 3]; + jcp.kh = weiDims[2]; + jcp.kw = weiDims[3]; jcp.t_pad = paddingL[0]; jcp.l_pad = paddingL[1]; @@ -898,6 +934,8 @@ void MKLDNNDeformableConvolutionNode::createPrimitive() { jcp.dilate_w = dilation[1]; jcp.with_bias = false; + jcp.with_bi_pad = with_bilinear_pad; + jcp.with_modulation = getParentEdges().size() > 3; const int simd_w = mayiuse(cpu::x64::avx512_common) ? 16 : 8; jcp.ic_block = simd_w; @@ -910,13 +948,16 @@ void MKLDNNDeformableConvolutionNode::createPrimitive() { jcp.typesize_in = sizeof(float); jcp.typesize_off = sizeof(float); jcp.typesize_out = sizeof(float); + jcp.typesize_modulation = sizeof(float); jcp.ur_w = mayiuse(cpu::x64::avx512_common) ? 6 : 3; jcp.nb_oc_blocking = !mayiuse(cpu::x64::avx2) ? 2 : 4; jcp.nthr = dnnl_get_max_threads(); - if (mayiuse(cpu::x64::avx512_common)) { + if (enforceRef) { + return; + } else if (mayiuse(cpu::x64::avx512_common)) { def_conv_kernel.reset(new jit_uni_def_conv_kernel_f32(jcp)); } else if (mayiuse(cpu::x64::avx2)) { def_conv_kernel.reset(new jit_uni_def_conv_kernel_f32(jcp)); @@ -930,9 +971,9 @@ void MKLDNNDeformableConvolutionNode::createPrimitive() { void MKLDNNDeformableConvolutionNode::executeReference(const float* src, const float* offsets, const float* weights, float* dst, const std::vector& src_strides, const std::vector& off_strides, - const std::vector& wei_strides, const std::vector& dst_strides) { + const std::vector& wei_strides, const std::vector& dst_strides, + const float* modulation, const std::vector& modulation_strides) { const bool with_groups = jcp.ngroups > 1; - const int G = jcp.ngroups; const int MB = jcp.mb; const int OH = jcp.oh; @@ -956,65 +997,79 @@ void MKLDNNDeformableConvolutionNode::executeReference(const float* src, const f const int DG = jcp.dg; - const int channel_per_deformable_group = IC * G / DG; + const int channel_per_deformable_group = (IC * G) / DG; + const bool with_bi_pad = jcp.with_bi_pad; auto ker = [=](int g, int mb, int oc, int oh, int ow) { float d = 0; const int h_in = oh * KSH - padT; const int w_in = ow * KSW - padL; for (int ic = 0; ic < IC; ic++) { - const float *data_im_ptr = src + mb * src_strides[0] + (g * IC + ic) * src_strides[1] + h_in * src_strides[2] + w_in * src_strides[3]; - const int deformable_group_index = ic / channel_per_deformable_group; + const float *data_im_ptr = src + mb * src_strides[0] + (g * IC + ic) * src_strides[1]; + const int deformable_group_index = (IC * g + ic) / channel_per_deformable_group; const float *data_offset_ptr = offsets + mb * off_strides[0] + (deformable_group_index * 2 * KH * KW) * off_strides[1]; + const float *modulation_offset_ptr = nullptr; + if (modulation != nullptr) { + modulation_offset_ptr = modulation + mb * modulation_strides[0] + (deformable_group_index * KH * KW) * modulation_strides[1]; + } + for (int kh = 0; kh < KH; kh++) { for (int kw = 0; kw < KW; kw++) { const size_t data_offset_h_index = 2 * (kh * KW + kw) * off_strides[1] + oh * off_strides[2] + ow * off_strides[3]; const size_t data_offset_w_index = (2 * (kh * KW + kw) + 1) * off_strides[1] + oh * off_strides[2] + ow * off_strides[3]; const float offset_h = data_offset_ptr[data_offset_h_index]; const float offset_w = data_offset_ptr[data_offset_w_index]; - float val = 0.0f; - const float h_im = h_in + kh * (KDH + 1) + offset_h; - const float w_im = w_in + kw * (KDW + 1) + offset_w; - - if (h_im >= 0 && w_im >= 0 && h_im < IH && w_im < IW) { - float map_h = kh * (KDH + 1) + offset_h; - float map_w = kw * (KDW + 1) + offset_w; - const int cur_height = IH - h_in; - const int cur_width = IW - w_in; - int h_low = static_cast(floorf(map_h)); - int w_low = static_cast(floorf(map_w)); - int h_high; - int w_high; - if (h_low >= cur_height - 1) { - h_high = h_low = cur_height - 1; - map_h = static_cast(h_low); - } else { - h_high = h_low + 1; - } - - if (w_low >= cur_width - 1) { - w_high = w_low = cur_width - 1; - map_w = static_cast(w_low); - } else { - w_high = w_low + 1; - } + float map_h = h_in + kh * (KDH + 1) + offset_h; + float map_w = w_in + kw * (KDW + 1) + offset_w; + bool skip_compute; + if (with_bilinear_pad) { + skip_compute = !(static_cast(map_w) > -1 && + static_cast(map_w) < IW && + static_cast(map_h) > -1 && + static_cast(map_h) < IH); + } else { + skip_compute = !(map_w >= 0 && + map_w < IW && + map_h >= 0 && + map_h < IH); + } + if (!skip_compute) { + const int cur_h_end = IH; + const int cur_w_end = IW; + int h_low = with_bi_pad ? static_cast(floorf(map_h)) : + std::max(static_cast(floorf(map_h)), 0); + int w_low = with_bi_pad ? static_cast(floorf(map_w)) : + std::max(static_cast(floorf(map_w)), 0); + const int cur_h_start = h_low; + const int cur_w_start = w_low; + int h_high = with_bi_pad ? h_low + 1 : std::min(static_cast(ceilf(map_h)), cur_h_end - 1); + int w_high = with_bi_pad ? w_low + 1 : std::min(static_cast(ceilf(map_w)), cur_w_end - 1); float lh = map_h - h_low; float lw = map_w - w_low; float hh = 1 - lh, hw = 1 - lw; - float v1 = data_im_ptr[h_low * src_strides[2] + w_low * src_strides[3]]; - float v2 = data_im_ptr[h_low * src_strides[2] + w_high * src_strides[3]]; - float v3 = data_im_ptr[h_high * src_strides[2] + w_low * src_strides[3]]; - float v4 = data_im_ptr[h_high * src_strides[2] + w_high * src_strides[3]]; + float v1 = (cur_w_start >= 0 && cur_h_start >= 0) ? data_im_ptr[h_low * src_strides[2] + w_low * src_strides[3]] : 0.0f; + float v2 = (w_high < cur_w_end && cur_h_start >= 0) ? data_im_ptr[h_low * src_strides[2] + w_high * src_strides[3]] : 0.0f; + float v3 = (cur_w_start >= 0 && h_high < cur_h_end) ? data_im_ptr[h_high * src_strides[2] + w_low * src_strides[3]] : 0.0f; + float v4 = (w_high < cur_w_end && h_high < cur_h_end) ? data_im_ptr[h_high * src_strides[2] + w_high * src_strides[3]] : 0.0f; float w1 = hh * hw, w2 = hh * lw, w3 = lh * hw, w4 = lh * lw; - val = (w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4); + float val = (w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4); + + float modulation_scalar = 1.0f; + + if (modulation_offset_ptr != nullptr) { + size_t modulation_index = (kh * KW + kw) * modulation_strides[1] + oh * modulation_strides[2] + ow * modulation_strides[3]; + modulation_scalar = modulation_offset_ptr[modulation_index]; + } + + const float weight = with_groups ? weights[(g + oc / G) * wei_strides[0] + ic * wei_strides[1] + kh * wei_strides[2] + + kw * wei_strides[3]] + : weights[oc * wei_strides[0] + ic * wei_strides[1] + kh * wei_strides[2] + kw * wei_strides[3]]; + d += val * weight * modulation_scalar; } - d += val * (with_groups ? weights[g * wei_strides[0] + oc * wei_strides[1] + ic * wei_strides[2] + kh * wei_strides[3] + - kw * wei_strides[4]] - : weights[oc * wei_strides[0] + ic * wei_strides[1] + kh * wei_strides[2] + kw * wei_strides[3]]); } } } @@ -1023,7 +1078,7 @@ void MKLDNNDeformableConvolutionNode::executeReference(const float* src, const f }; parallel_nd(G, MB, OC, OH, OW, - [&](int g, int mb, int oc, int oh, int ow) { + [&](int g, int mb, int oc, int oh, int ow) { dst[mb * dst_strides[0] + (g * OC + oc) * dst_strides[1] + oh * dst_strides[2] + ow * dst_strides[3]] = ker(g, mb, oc, oh, ow); }); } @@ -1058,6 +1113,8 @@ void MKLDNNDeformableConvolutionNode::executeOptimized(const float* src, const f } void MKLDNNDeformableConvolutionNode::execute(mkldnn::stream strm) { + const size_t inputsNumber = getOriginalInputsNumber(); + auto &srcMemory0 = getParentEdgeAt(0)->getMemory(); auto &srcMemory1 = getParentEdgeAt(1)->getMemory(); auto &srcMemory2 = getParentEdgeAt(2)->getMemory(); @@ -1066,8 +1123,18 @@ void MKLDNNDeformableConvolutionNode::execute(mkldnn::stream strm) { const auto *src = reinterpret_cast(srcMemory0.GetPtr()); const auto *offsets = reinterpret_cast(srcMemory1.GetPtr()); const auto *weights = reinterpret_cast(srcMemory2.GetPtr()); + float* modulation = nullptr; + if (inputsNumber > 3) { + modulation = reinterpret_cast(getParentEdgeAt(3)->getMemory().GetPtr()); + } + float *dst = reinterpret_cast(dstMemory.GetPtr()); + auto selectedPrimitiveDescriptor = getSelectedPrimitiveDescriptor(); + if (!selectedPrimitiveDescriptor) + IE_THROW() << "CPU deformable convolution with name '" << getName() << "' doesn't have primitive descriptors."; + auto config = selectedPrimitiveDescriptor->getConfig(); + auto src_block_desc = getParentEdgeAt(0)->getMemory().GetDescWithType(); std::vector src_strides(src_block_desc.getStrides().size()); for (int i = 0; i < src_strides.size(); i++) { @@ -1080,13 +1147,19 @@ void MKLDNNDeformableConvolutionNode::execute(mkldnn::stream strm) { dst_strides[dst_block_desc.getOrder()[i]] = dst_block_desc.getStrides()[i]; } + auto off_strides = getParentEdgeAt(1)->getMemory().GetDescWithType().getStrides(); auto wei_strides = getParentEdgeAt(2)->getMemory().GetDescWithType().getStrides(); + InferenceEngine::SizeVector modulation_strides; + if (inputsNumber > 3) { + modulation_strides = getParentEdgeAt(3)->getMemory().GetDescWithType().getStrides(); + } + if (def_conv_kernel) { executeOptimized(src, offsets, weights, dst, src_strides, off_strides, dst_strides); } else { - executeReference(src, offsets, weights, dst, src_strides, off_strides, wei_strides, dst_strides); + executeReference(src, offsets, weights, dst, src_strides, off_strides, wei_strides, dst_strides, modulation, modulation_strides); } } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_def_conv_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_def_conv_node.h index e74e49788ccda6..29af41af4da8cb 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_def_conv_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_def_conv_node.h @@ -22,8 +22,6 @@ struct jit_def_conv_params { int kd, kh, kw; int stride_d, stride_h, stride_w; int dilate_d, dilate_h, dilate_w; - bool with_bias; - bool with_sum; int nthr; int nb_ic, ic_block; int nb_oc, oc_block; @@ -32,13 +30,19 @@ struct jit_def_conv_params { int ur_w_tail; int typesize_in; int typesize_off; + int typesize_modulation; int typesize_bia; int typesize_out; + bool with_bias; + bool with_sum; + bool with_modulation; + bool with_bi_pad; }; struct jit_def_conv_call_args { const void *src; const void *off; + const void *modulation; const void *filt; const void *bias; const void *dst; @@ -75,11 +79,13 @@ class MKLDNNDeformableConvolutionNode : public MKLDNNNode { bool canBeInPlace() const override { return false; } + bool enforceRef = false; InferenceEngine::Precision getRuntimePrecision() const override; private: size_t group = 1; + bool with_bilinear_pad = false; std::vector stride = {}; std::vector dilation = {}; std::vector paddingL = {}; @@ -92,10 +98,10 @@ class MKLDNNDeformableConvolutionNode : public MKLDNNNode { void executeReference(const float* src, const float* offsets, const float* weights, float* dst, const std::vector& src_strides, const std::vector& off_strides, - const std::vector& wei_strides, const std::vector& dst_strides); + const std::vector& wei_strides, const std::vector& dst_strides, + const float* modulation = nullptr, const std::vector& modulation_strides = {}); void executeOptimized(const float* src, const float* offsets, const float* weights, float* dst, - const std::vector& src_strides, const std::vector& off_strides, - const std::vector& dst_strides); + const std::vector& src_strides, const std::vector& off_strides, const std::vector& dst_strides); }; } // namespace MKLDNNPlugin diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/deformable_convolution.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/deformable_convolution.cpp index 9e9e7796295109..3155580319da2f 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/deformable_convolution.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/deformable_convolution.cpp @@ -103,13 +103,18 @@ const std::vector single_deform_groups = {3}; const auto deformableConv2DParams_SingleTestCase = ::testing::Combine( ::testing::ValuesIn(single_deform_vals), - ::testing::ValuesIn(single_kernel), ::testing::ValuesIn(strides), - ::testing::ValuesIn(padBegins), ::testing::ValuesIn(padEnds), - ::testing::ValuesIn(dilations), ::testing::ValuesIn(groups), - ::testing::ValuesIn(single_deform_groups), ::testing::ValuesIn(numOutChannels), + ::testing::ValuesIn(single_kernel), + ::testing::ValuesIn(strides), + ::testing::ValuesIn(padBegins), + ::testing::ValuesIn(padEnds), + ::testing::ValuesIn(dilations), + ::testing::ValuesIn(groups), + ::testing::ValuesIn(single_deform_groups), + ::testing::ValuesIn(numOutChannels), ::testing::Values(ngraph::op::PadType::EXPLICIT), ::testing::ValuesIn(with_bilinear_interpolation_pad), - ::testing::ValuesIn(with_modulated_scalar)); + ::testing::ValuesIn(with_modulated_scalar) +); INSTANTIATE_TEST_SUITE_P( smoke_DeformableConvolution2D_SingleTestCase, DeformableConvolutionLayerTest, diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index d38c0d9ee5f343..625da7075517a0 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -1564,7 +1564,17 @@ onnx_upsample6_dynamic # random values returned from the plugin: ticket 51762 onnx_model_deformable_conv_2d -# DeformableConvolution groups attribute: ticket 53312 +# DeformableConvolution groups attribute: ticket 53312 (fixed, but reproduced after v8->v1 conversion was enabled) +IE_CPU.deformable_convolution_opset8_2D_zeroed_offsets_groups_basic +IE_CPU.deformable_convolution_opset8_2D_zeroed_offsets_groups_complex +IE_CPU.deformable_convolution_opset8_2D_zeroed_offsets_groups_and_deforgroups +IE_CPU.deformable_convolution_opset8_2D_integral_offsets_groups_basic +IE_CPU.deformable_convolution_opset8_2D_integral_offsets_groups_complex +IE_CPU.deformable_convolution_opset8_2D_integral_offsets_groups_and_deforgroups +IE_CPU.deformable_convolution_opset8_2D_real_offsets_groups_basic +IE_CPU.deformable_convolution_opset8_2D_real_offsets_groups_complex +IE_CPU.deformable_convolution_opset8_2D_real_offsets_groups_and_deforgroups + IE_CPU.deformable_convolution_2D_zeroed_offsets_groups_basic IE_CPU.deformable_convolution_2D_zeroed_offsets_groups_complex IE_CPU.deformable_convolution_2D_zeroed_offsets_groups_and_deforgroups From 962972a561925b4d07fa2f9a7338cc2992d1c41e Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Wed, 18 Aug 2021 13:27:48 +0300 Subject: [PATCH 020/102] [CPU] Bump up MKLDNN version to get fix of c26453 warning (#7089) --- inference-engine/thirdparty/mkl-dnn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/thirdparty/mkl-dnn b/inference-engine/thirdparty/mkl-dnn index fdc6f62b1184da..7e4430d9398af6 160000 --- a/inference-engine/thirdparty/mkl-dnn +++ b/inference-engine/thirdparty/mkl-dnn @@ -1 +1 @@ -Subproject commit fdc6f62b1184dab86dbadd55fc4bc49dcde9dba5 +Subproject commit 7e4430d9398af63e94943815dace4b44f12ddbee From b8e9fe50b4567e841997a19e568ee1486876bcaa Mon Sep 17 00:00:00 2001 From: Rafal Blaczkowski Date: Wed, 18 Aug 2021 12:57:30 +0200 Subject: [PATCH 021/102] OpenVINO ONNX CI Azure - update onnx/models on demand only (#7125) * debug * debug2 * debug3 * save * save * save * fix * save * workaround * fix2 * remove old artifacts * final version --- .ci/azure/linux_ngraph_onnx.yml | 12 ++++++------ .../python/tests/test_onnx/model_zoo_preprocess.sh | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.ci/azure/linux_ngraph_onnx.yml b/.ci/azure/linux_ngraph_onnx.yml index b6d43e3cce68d6..5521d224630ad7 100644 --- a/.ci/azure/linux_ngraph_onnx.yml +++ b/.ci/azure/linux_ngraph_onnx.yml @@ -52,10 +52,10 @@ jobs: - script: | rm -rf $(WORK_DIR) ; mkdir $(WORK_DIR) - sudo rm -rf $(TMP_DIR) ; sudo mkdir $(TMP_DIR) ; sudo chmod 777 -R $(TMP_DIR) sudo mkdir -p $(MODELS_DIR) sudo apt --assume-yes install nfs-common sudo mount -vvv -t nfs cinfsshare.file.core.windows.net:/cinfsshare/onnxtestdata $(MODELS_DIR) -o vers=4,minorversion=1,sec=sys + mkdir -p $(MODELS_DIR)/models_data displayName: 'Make dirs' - checkout: self @@ -72,15 +72,15 @@ jobs: workingDirectory: $(WORK_DIR) displayName: 'Install dependencies' + - script: ngraph/python/tests/test_onnx/model_zoo_preprocess.sh -d $(MODELS_DIR)/models_data -o -s "$(ONNX_MODEL_ZOO_SHA)" + displayName: 'Update models' + condition: ne(variables['BUILD_TYPE'], 'Debug') + - script: sudo docker build --tag=openvino-onnx-ci-image --file=.ci/openvino-onnx/Dockerfile --build-arg BUILD_TYPE=$(BUILD_TYPE) --build-arg PROTOBUF_LITE=$(PROTOBUF_LITE) . displayName: 'Docker build $(BUILD_TYPE) protobuf-lite: $(PROTOBUF_LITE)' - - script: ngraph/python/tests/test_onnx/model_zoo_preprocess.sh -d $(TMP_DIR) -o -s "$(ONNX_MODEL_ZOO_SHA)" - displayName: 'Get models' - condition: ne(variables['BUILD_TYPE'], 'Debug') - - script: sudo fallocate -l 64G /swapfile ; sudo mkswap /swapfile ; sudo swapon /swapfile ; df ; free -h displayName: 'Create swap' - - script: sudo docker run --name openvino-onnx-ci-container --volume $(TMP_DIR)/model_zoo/onnx_model_zoo_$(ONNX_MODEL_ZOO_SHA):/root/.onnx/model_zoo/onnx_model_zoo --volume $(MODELS_DIR)/msft:/root/.onnx/model_zoo/MSFT openvino-onnx-ci-image /bin/bash -c "$(TOX_COMMAND)" + - script: sudo docker run --name openvino-onnx-ci-container --volume $(MODELS_DIR)/models_data/model_zoo/onnx_model_zoo_$(ONNX_MODEL_ZOO_SHA):/root/.onnx/model_zoo/onnx_model_zoo --volume $(MODELS_DIR)/msft:/root/.onnx/model_zoo/MSFT openvino-onnx-ci-image /bin/bash -c "$(TOX_COMMAND)" displayName: 'Docker run $(BUILD_TYPE) protobuf-lite: $(PROTOBUF_LITE)' diff --git a/ngraph/python/tests/test_onnx/model_zoo_preprocess.sh b/ngraph/python/tests/test_onnx/model_zoo_preprocess.sh index 367b7eb70f04a3..dd35ed340eba03 100755 --- a/ngraph/python/tests/test_onnx/model_zoo_preprocess.sh +++ b/ngraph/python/tests/test_onnx/model_zoo_preprocess.sh @@ -96,6 +96,7 @@ function update_onnx_models() { if [[ ! -d $ONNX_MODELS_DIR ]] ; then touch $MODEL_ZOO_DIR/executing_$ONNX_SHA + trap "rm -f $MODEL_ZOO_DIR/executing_$ONNX_SHA" EXIT INT TERM echo "The ONNX Model Zoo repository doesn't exist on your filesystem then will be cloned" git clone https://github.com/onnx/models.git "$ONNX_MODELS_DIR" cd "$ONNX_MODELS_DIR" From fded5f6bf4a5e885512299adf1e34e0cf516e3a5 Mon Sep 17 00:00:00 2001 From: Alexandra Sidorova Date: Wed, 18 Aug 2021 20:26:04 +0300 Subject: [PATCH 022/102] [CPU] Added improvements for StridedSlice (#6658) --- .../nodes/mkldnn_strided_slice_node.cpp | 91 +++++++++++-------- .../nodes/mkldnn_strided_slice_node.h | 8 +- 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.cpp index 4f98fc1099f2b2..8e87617d3692b4 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.cpp @@ -272,6 +272,8 @@ void MKLDNNStridedSliceNode::createPrimitive() { auto srcOrder = srcBlockingDesc.getOrder(); params.srcDims = srcBlockingDesc.getBlockDims(); params.dstDims = dstBlockingDesc.getBlockDims(); + params.srcMemPtr = srcMemPtr; + params.dstMemPtr = dstMemPtr; params.dataSize = getSelectedPrimitiveDescriptor()->getConfig().inConfs[DATA_ID].desc->getPrecision().size(); if (params.parametersAreConstant) { @@ -282,9 +284,7 @@ void MKLDNNStridedSliceNode::createPrimitive() { SizeVector newSrcDims, newDstDims; dimsNormalization(newSrcDims, newDstDims); dimsGluing(realNDims, newSrcDims, newDstDims); - - if (params.dstDims.size() == 1 || params.nDimsForWork != 1) - indicesCalculation(); + indicesCalculation(); } } @@ -510,14 +510,35 @@ void MKLDNNStridedSliceNode::dimsGluing(const size_t realNDims, const SizeVector if (params.dstDims.size() > 2) params.lastDstDim /= newDstDims[secondDim.first]; } + + // some parameter calculations for common execution + params.isOptimized = params.nDimsForWork == 1 && params.dstDims.size() > 1; + if (params.isOptimized) { + if (params.dstDims.size() == 2) + params.dstDims[1] = 1; + + params.workAmount = params.dstDims[0] * params.dstDims[1]; + params.srcShift = (begin[0] * params.srcStrides[0] + begin[1] * params.srcStrides[1]) * params.dataSize; + } else { + params.srcShift = stride.back() == 1 && stride.size() > 1 ? + begin[params.nDimsForWork] * params.srcStrides[params.nDimsForWork] * params.dataSize : 0; + } } void MKLDNNStridedSliceNode::indicesCalculation() { // indices calculation before execution for the best performance - params.nThreads = parallel_get_max_threads(); params.srcIndices.resize(params.workAmount, 0); params.dstIndices.resize(params.workAmount, 0); + // should choose more optimal thread count + const size_t nthr = parallel_get_max_threads(); + params.nThreads = nthr > params.workAmount ? params.workAmount : nthr; + + if (params.isOptimized) { + indicesCalculationForOptimized(); + return; + } + auto getSrcIdx = [this](const SizeVector& indexes){ size_t srcIdx = 0; for (int i = 0; i < params.nDimsForWork; ++i) @@ -542,10 +563,10 @@ void MKLDNNStridedSliceNode::indicesCalculation() { if (coords[k] < params.dstDims[k]) { srcIdx += stride[k] * params.srcStrides[k] * params.dataSize; break; - } else { - coords[k] = 0; - out = true; } + + coords[k] = 0; + out = true; } if (out) @@ -554,6 +575,25 @@ void MKLDNNStridedSliceNode::indicesCalculation() { }); } +void MKLDNNStridedSliceNode::indicesCalculationForOptimized() { + const size_t dstIdx0 = params.dstStrides[0] * params.dataSize; + const size_t dstIdx1 = params.dstStrides[1] * params.dataSize; + const size_t srcIdx0 = stride[0] * params.srcStrides[0] * params.dataSize; + const size_t srcIdx1 = stride[1] * params.srcStrides[1] * params.dataSize; + + for (size_t i0 = 0; i0 < params.dstDims[0]; i0++) { + const size_t idx = i0 * params.dstDims[1]; + + params.dstIndices[idx] = i0 * dstIdx0; + params.srcIndices[idx] = i0 * srcIdx0; + + for (size_t i1 = 1; i1 < params.dstDims[1]; i1++) { + params.dstIndices[idx + i1] = params.dstIndices[idx] + i1 * dstIdx1; + params.srcIndices[idx + i1] = params.srcIndices[idx] + i1 * srcIdx1; + } + } +} + void MKLDNNStridedSliceNode::execute(mkldnn::stream strm) { if (!params.parametersAreConstant) { auto srcDims = getParentEdgeAt(DATA_ID)->getShape().getStaticDims(); @@ -586,42 +626,15 @@ void MKLDNNStridedSliceNode::execute(mkldnn::stream strm) { SizeVector newSrcDims, newDstDims; dimsNormalization(newSrcDims, newDstDims); dimsGluing(dstDims.size(), newSrcDims, newDstDims); - - if (params.dstDims.size() == 1 || params.nDimsForWork != 1) - indicesCalculation(); + indicesCalculation(); } - if (params.dstDims.size() > 1 && params.nDimsForWork == 1) - stridedSliceV(); - else - stridedSlice(); -} - -void MKLDNNStridedSliceNode::stridedSliceV() { - const uint8_t* srcData = reinterpret_cast(this->getParentEdgeAt(DATA_ID)->getMemoryPtr()->GetPtr()) + - (begin[0] * params.srcStrides[0] + begin[1] * params.srcStrides[1]) * params.dataSize; - uint8_t* dstData = reinterpret_cast(this->getChildEdgeAt(0)->getMemoryPtr()->GetPtr()); - - const size_t dstIdx = params.dstStrides[0] * params.dataSize; - const size_t srcIdx = stride[0] * params.srcStrides[0] * params.dataSize; - const size_t dstShift = params.dstStrides[1] * params.dataSize; - const size_t srcShift = stride[1] * params.srcStrides[1] * params.dataSize; - - if (params.dstDims.size() > 2) { - parallel_for2d(params.dstDims[0], params.dstDims[1], [&](const size_t i, const size_t j) { - cpu_memcpy(&dstData[i * dstIdx + j * dstShift], &srcData[i * srcIdx + j * srcShift], params.lastDstDim); - }); - } else { - parallel_for(params.dstDims[0], [&](const size_t i) { - cpu_memcpy(&dstData[i * dstIdx], &srcData[i * srcIdx], params.lastDstDim); - }); - } + stridedSlice(); } -void MKLDNNStridedSliceNode::stridedSlice() { - const uint8_t* srcData = reinterpret_cast(this->getParentEdgeAt(DATA_ID)->getMemoryPtr()->GetPtr()) + - (stride.back() == 1 && stride.size() > 1 ? begin[params.nDimsForWork] * params.srcStrides[params.nDimsForWork] * params.dataSize : 0); - uint8_t* dstData = reinterpret_cast(this->getChildEdgeAt(0)->getMemoryPtr()->GetPtr()); +inline void MKLDNNStridedSliceNode::stridedSlice() { + const uint8_t* srcData = reinterpret_cast(params.srcMemPtr->GetPtr()) + params.srcShift; + uint8_t* dstData = reinterpret_cast(params.dstMemPtr->GetPtr()); parallel_nt(params.nThreads, [&](const int ithr, const int nthr) { size_t start = 0, end = 0; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.h index 91bf6701877fc1..672bc0b6ce9c9b 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.h @@ -27,14 +27,14 @@ class MKLDNNStridedSliceNode : public MKLDNNNode { static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; private: - void stridedSliceV(); - void stridedSlice(); + inline void stridedSlice(); void addHiddenDims(const size_t nSrcDims); void orderParametersByLayouts(); void dimsNormalization(InferenceEngine::SizeVector& newSrcDims, InferenceEngine::SizeVector& newDstDims); void dimsGluing(const size_t realNDims, const InferenceEngine::SizeVector& newSrcDims, const InferenceEngine::SizeVector& newDstDims); void indicesCalculation(); + void indicesCalculationForOptimized(); const size_t DATA_ID = 0; const size_t BEGIN_ID = 1; @@ -56,6 +56,8 @@ class MKLDNNStridedSliceNode : public MKLDNNNode { InferenceEngine::SizeVector strideDims; struct { + MKLDNNMemoryPtr srcMemPtr = nullptr; + MKLDNNMemoryPtr dstMemPtr = nullptr; InferenceEngine::SizeVector srcDims; InferenceEngine::SizeVector dstDims; InferenceEngine::SizeVector srcStrides; @@ -69,6 +71,8 @@ class MKLDNNStridedSliceNode : public MKLDNNNode { size_t workAmount = 0; size_t lastDstDim = 0; size_t dataSize = 0; + size_t srcShift = 0; + bool isOptimized = false; bool equalDims = false; bool parametersAreConstant = true; } params; From ddb7799403d65e5b428d4b7104a5aab18fa92ed5 Mon Sep 17 00:00:00 2001 From: Katarzyna Mitrus Date: Wed, 18 Aug 2021 19:35:23 +0200 Subject: [PATCH 023/102] Removal of FusedOp inheritance leftovers (#7113) * Remove FusedOp from v0::Gelu * Update v0::Gelu NGRAPH_RTTI_DECLARATION * Enable gelu type_prop tests * Remove FusedOp from v0::MVN * Remove FusedOp from HardSigmoid * Remove FusedOp from LSTMSequence * Remove supress deprecated * Add missed NGRAPH_OP_SCOPE to v0 Gelu and HardSigmoid --- ngraph/core/include/ngraph/op/gelu.hpp | 14 ++--- .../core/include/ngraph/op/hard_sigmoid.hpp | 11 +--- .../core/include/ngraph/op/lstm_sequence.hpp | 7 +-- ngraph/core/include/ngraph/op/mvn.hpp | 8 +-- ngraph/core/src/op/gelu.cpp | 39 ++----------- ngraph/core/src/op/hard_sigmoid.cpp | 41 +++----------- ngraph/core/src/op/lstm_sequence.cpp | 24 +------- ngraph/core/src/op/mvn.cpp | 55 +++---------------- ngraph/test/CMakeLists.txt | 1 + ngraph/test/type_prop/gelu.cpp | 45 ++++++++------- ngraph/test/type_prop/lstm_sequence.cpp | 3 - 11 files changed, 57 insertions(+), 191 deletions(-) diff --git a/ngraph/core/include/ngraph/op/gelu.hpp b/ngraph/core/include/ngraph/op/gelu.hpp index 91058554376c5a..78f683120c2eda 100644 --- a/ngraph/core/include/ngraph/op/gelu.hpp +++ b/ngraph/core/include/ngraph/op/gelu.hpp @@ -6,21 +6,17 @@ #include "ngraph/node.hpp" #include "ngraph/op/op.hpp" -#include "ngraph/op/util/fused_op.hpp" #include "ngraph/op/util/unary_elementwise_arithmetic.hpp" namespace ngraph { namespace op { -NGRAPH_SUPPRESS_DEPRECATED_START namespace v0 { /// \brief Gaussian Error Linear Unit /// f(x) = 0.5 * x * (1 + erf( x / sqrt(2) ) -class NGRAPH_API Gelu : public ngraph::op::util::FusedOp { +class NGRAPH_API Gelu : public Op { public: - static constexpr NodeTypeInfo type_info{"Gelu", 0}; - const NodeTypeInfo& get_type_info() const override { - return type_info; - } + NGRAPH_RTTI_DECLARATION; + Gelu(); /// \brief Constructs a Gelu operation. /// @@ -28,15 +24,13 @@ class NGRAPH_API Gelu : public ngraph::op::util::FusedOp { Gelu(const Output& data); bool visit_attributes(AttributeVisitor& visitor) override; - virtual OutputVector decompose_op() const override; - void pre_validate_and_infer_types() override; + void validate_and_infer_types() override; virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; } // namespace v0 using v0::Gelu; -NGRAPH_SUPPRESS_DEPRECATED_END /// \brief Specifies the approximation to calculate Gelu enum class GeluApproximationMode { TANH, ERF }; diff --git a/ngraph/core/include/ngraph/op/hard_sigmoid.hpp b/ngraph/core/include/ngraph/op/hard_sigmoid.hpp index 01b7d31a014142..1a6c56d2fe19fb 100644 --- a/ngraph/core/include/ngraph/op/hard_sigmoid.hpp +++ b/ngraph/core/include/ngraph/op/hard_sigmoid.hpp @@ -5,9 +5,7 @@ #pragma once #include "ngraph/node.hpp" -#include "ngraph/op/util/fused_op.hpp" - -NGRAPH_SUPPRESS_DEPRECATED_START +#include "ngraph/op/op.hpp" namespace ngraph { namespace op { @@ -15,7 +13,7 @@ namespace v0 { /// \brief Parameterized, bounded sigmoid-like, piecewise linear /// function. min(max(alpha*x + beta, 0), 1) /// -class NGRAPH_API HardSigmoid : public ngraph::op::util::FusedOp { +class NGRAPH_API HardSigmoid : public Op { public: NGRAPH_RTTI_DECLARATION; @@ -30,13 +28,10 @@ class NGRAPH_API HardSigmoid : public ngraph::op::util::FusedOp { HardSigmoid(const Output& data, const Output& alpha, const Output& beta); bool visit_attributes(AttributeVisitor& visitor) override; - virtual void pre_validate_and_infer_types() override; - virtual OutputVector decompose_op() const override; + virtual void validate_and_infer_types() override; virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; } // namespace v0 using v0::HardSigmoid; } // namespace op } // namespace ngraph - -NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/include/ngraph/op/lstm_sequence.hpp b/ngraph/core/include/ngraph/op/lstm_sequence.hpp index 4745afa8b467d3..75638c6c411afb 100644 --- a/ngraph/core/include/ngraph/op/lstm_sequence.hpp +++ b/ngraph/core/include/ngraph/op/lstm_sequence.hpp @@ -14,13 +14,11 @@ #include "ngraph/op/constant.hpp" #include "ngraph/op/lstm_cell.hpp" #include "ngraph/op/util/attr_types.hpp" -#include "ngraph/op/util/fused_op.hpp" #include "ngraph/op/util/rnn_cell_base.hpp" namespace ngraph { namespace op { namespace v0 { -NGRAPH_SUPPRESS_DEPRECATED_START /// /// \brief Class for lstm sequence node. @@ -31,7 +29,7 @@ NGRAPH_SUPPRESS_DEPRECATED_START /// \sa LSTMCell, RNNCell, GRUCell /// /// -class NGRAPH_API LSTMSequence : public util::FusedOp { +class NGRAPH_API LSTMSequence : public Op { public: NGRAPH_RTTI_DECLARATION; LSTMSequence(); @@ -76,7 +74,6 @@ class NGRAPH_API LSTMSequence : public util::FusedOp { virtual void validate_and_infer_types() override; bool visit_attributes(AttributeVisitor& visitor) override; - virtual OutputVector decompose_op() const override; virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; @@ -138,8 +135,6 @@ class NGRAPH_API LSTMSequence : public util::FusedOp { bool m_input_forget; LSTMWeightsFormat m_weights_format; }; - -NGRAPH_SUPPRESS_DEPRECATED_END } // namespace v0 namespace v5 { diff --git a/ngraph/core/include/ngraph/op/mvn.hpp b/ngraph/core/include/ngraph/op/mvn.hpp index 2e69787deb6587..406e289396305e 100644 --- a/ngraph/core/include/ngraph/op/mvn.hpp +++ b/ngraph/core/include/ngraph/op/mvn.hpp @@ -6,16 +6,14 @@ #include "ngraph/node.hpp" #include "ngraph/op/op.hpp" -#include "ngraph/op/util/fused_op.hpp" namespace ngraph { namespace op { -NGRAPH_SUPPRESS_DEPRECATED_START namespace v0 { /// \brief Operator performing Mean Variance Normalization /// -class NGRAPH_API MVN : public ngraph::op::util::FusedOp { +class NGRAPH_API MVN : public Op { public: NGRAPH_RTTI_DECLARATION; @@ -43,8 +41,6 @@ class NGRAPH_API MVN : public ngraph::op::util::FusedOp { /// MVN(const Output& data, AxisSet reduction_axes, bool normalize_variance = true, double eps = 1e-9); - virtual OutputVector decompose_op() const override; - virtual void validate_and_infer_types() override; bool visit_attributes(AttributeVisitor& visitor) override; @@ -76,8 +72,6 @@ class NGRAPH_API MVN : public ngraph::op::util::FusedOp { } // namespace v0 using v0::MVN; -NGRAPH_SUPPRESS_DEPRECATED_END - /// \brief Specifies how eps is applied in MVN enum class MVNEpsMode { // Apply eps inside sqrt diff --git a/ngraph/core/src/op/gelu.cpp b/ngraph/core/src/op/gelu.cpp index f25150abad1de1..272023cdfe2d23 100644 --- a/ngraph/core/src/op/gelu.cpp +++ b/ngraph/core/src/op/gelu.cpp @@ -8,26 +8,17 @@ #include #include "itt.hpp" -#include "ngraph/builder/make_constant.hpp" -#include "ngraph/op/add.hpp" -#include "ngraph/op/divide.hpp" -#include "ngraph/op/erf.hpp" -#include "ngraph/op/exp.hpp" -#include "ngraph/op/multiply.hpp" -#include "ngraph/op/negative.hpp" -#include "ngraph/op/subtract.hpp" #include "ngraph/runtime/reference/gelu.hpp" using namespace std; using namespace ngraph; -NGRAPH_SUPPRESS_DEPRECATED_START +// ------------------------------ V0 ------------------------------ +NGRAPH_RTTI_DEFINITION(op::v0::Gelu, "Gelu", 0); -constexpr NodeTypeInfo op::Gelu::type_info; +op::v0::Gelu::Gelu() : Op() {} -op::v0::Gelu::Gelu() : FusedOp() {} - -op::v0::Gelu::Gelu(const Output& data) : FusedOp({data}) { +op::v0::Gelu::Gelu(const Output& data) : Op({data}) { constructor_validate_and_infer_types(); } @@ -36,25 +27,6 @@ bool op::v0::Gelu::visit_attributes(AttributeVisitor& visitor) { return true; } -// f(x) = 0.5 * x * (1.0 + erf( x / sqrt(2.0) ) -OutputVector op::Gelu::decompose_op() const { - auto data = input_value(0); - - shared_ptr half = builder::make_constant(data.get_element_type(), data.get_shape(), 0.5); - - shared_ptr one = builder::make_constant(data.get_element_type(), data.get_shape(), 1.0); - - shared_ptr sqrt_two = - builder::make_constant(data.get_element_type(), data.get_shape(), std::sqrt(2.0)); - - shared_ptr add = - std::make_shared(one, - make_shared(std::make_shared(data, sqrt_two))); - shared_ptr multiply = std::make_shared(half, data); - - return {std::make_shared(multiply, add)}; -} - shared_ptr op::v0::Gelu::clone_with_new_inputs(const OutputVector& new_args) const { NGRAPH_OP_SCOPE(v0_Gelu_clone_with_new_inputs); if (new_args.size() != 1) { @@ -63,7 +35,8 @@ shared_ptr op::v0::Gelu::clone_with_new_inputs(const OutputVector& new_arg return make_shared(new_args.at(0)); } -void op::v0::Gelu::pre_validate_and_infer_types() { +void op::v0::Gelu::validate_and_infer_types() { + NGRAPH_OP_SCOPE(v0_Gelu_validate_and_infer_types); element::Type input_element_type = get_input_element_type(0); PartialShape input_pshape = get_input_partial_shape(0); diff --git a/ngraph/core/src/op/hard_sigmoid.cpp b/ngraph/core/src/op/hard_sigmoid.cpp index 23dc7baa73941f..d397831c96263f 100644 --- a/ngraph/core/src/op/hard_sigmoid.cpp +++ b/ngraph/core/src/op/hard_sigmoid.cpp @@ -7,24 +7,17 @@ #include #include "itt.hpp" -#include "ngraph/op/add.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/maximum.hpp" -#include "ngraph/op/minimum.hpp" -#include "ngraph/op/multiply.hpp" #include "ngraph/shape.hpp" using namespace std; using namespace ngraph; -NGRAPH_SUPPRESS_DEPRECATED_START +NGRAPH_RTTI_DEFINITION(op::v0::HardSigmoid, "HardSigmoid", 0); -NGRAPH_RTTI_DEFINITION(op::HardSigmoid, "HardSigmoid", 0, op::util::FusedOp); +op::v0::HardSigmoid::HardSigmoid() : Op() {} -op::HardSigmoid::HardSigmoid() : FusedOp() {} - -op::HardSigmoid::HardSigmoid(const Output& data, const Output& alpha, const Output& beta) - : FusedOp({data, alpha, beta}) { +op::v0::HardSigmoid::HardSigmoid(const Output& data, const Output& alpha, const Output& beta) + : Op({data, alpha, beta}) { constructor_validate_and_infer_types(); } @@ -33,7 +26,8 @@ bool ngraph::op::v0::HardSigmoid::visit_attributes(AttributeVisitor& visitor) { return true; } -void op::HardSigmoid::pre_validate_and_infer_types() { +void op::v0::HardSigmoid::validate_and_infer_types() { + NGRAPH_OP_SCOPE(v0_HardSigmoid_validate_and_infer_types); const auto& alpha_pshape = get_input_partial_shape(1); const auto& beta_pshape = get_input_partial_shape(2); @@ -64,28 +58,9 @@ void op::HardSigmoid::pre_validate_and_infer_types() { set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); } -OutputVector op::HardSigmoid::decompose_op() const { - const auto data = input_value(0); - - const auto one_node = ngraph::op::Constant::create(data.get_element_type(), data.get_shape(), {1.0f}); - - const auto zero_node = ngraph::op::Constant::create(data.get_element_type(), data.get_shape(), {0.0f}); - - const auto alpha_node = input_value(1).get_node_shared_ptr(); - const auto beta_node = input_value(2).get_node_shared_ptr(); - - std::shared_ptr alpha_x_plus_beta = - std::make_shared(alpha_node, data, AutoBroadcastType::NUMPY); - - alpha_x_plus_beta = std::make_shared(alpha_x_plus_beta, beta_node, AutoBroadcastType::NUMPY); - - return { - std::make_shared(std::make_shared(alpha_x_plus_beta, zero_node), one_node)}; -} - -shared_ptr op::HardSigmoid::clone_with_new_inputs(const OutputVector& new_args) const { +shared_ptr op::v0::HardSigmoid::clone_with_new_inputs(const OutputVector& new_args) const { NGRAPH_OP_SCOPE(v0_HardSigmoid_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } diff --git a/ngraph/core/src/op/lstm_sequence.cpp b/ngraph/core/src/op/lstm_sequence.cpp index 6ef1c335aa87bf..5a1229986a6057 100644 --- a/ngraph/core/src/op/lstm_sequence.cpp +++ b/ngraph/core/src/op/lstm_sequence.cpp @@ -16,13 +16,11 @@ using namespace ngraph; using namespace std; -NGRAPH_SUPPRESS_DEPRECATED_START - NGRAPH_RTTI_DEFINITION(op::v0::LSTMSequence, "LSTMSequence", 0); NGRAPH_RTTI_DEFINITION(op::v5::LSTMSequence, "LSTMSequence", 5); op::v0::LSTMSequence::LSTMSequence() - : FusedOp(), + : Op(), m_activations_alpha(), m_activations_beta(), m_activations(), @@ -48,7 +46,7 @@ op::v0::LSTMSequence::LSTMSequence(const Output& X, const std::vector activations, const float clip_threshold, const bool input_forget) - : FusedOp({X, initial_hidden_state, initial_cell_state, sequence_lengths, W, R, B, P}), + : Op({X, initial_hidden_state, initial_cell_state, sequence_lengths, W, R, B, P}), m_activations_alpha(activations_alpha), m_activations_beta(activations_beta), m_activations(activations), @@ -110,24 +108,6 @@ bool op::v0::LSTMSequence::visit_attributes(AttributeVisitor& visitor) { return true; } -OutputVector op::v0::LSTMSequence::decompose_op() const { - OutputVector results; - if (m_direction == direction::FORWARD || m_direction == direction::REVERSE) { - results = lstm_pass(m_direction == direction::REVERSE); - } - if (m_direction == direction::BIDIRECTIONAL) { - OutputVector fwd_results{lstm_pass()}; - OutputVector rev_results{lstm_pass(true)}; - - // Stack together respective outputs from both forward and reverse passess. - shared_ptr Y{make_shared(OutputVector{fwd_results.at(0), rev_results.at(0)}, 1)}; - shared_ptr Y_h{make_shared(OutputVector{fwd_results.at(1), rev_results.at(1)}, 1)}; - shared_ptr Y_c{make_shared(OutputVector{fwd_results.at(2), rev_results.at(2)}, 1)}; - results = OutputVector{Y, Y_h, Y_c}; - } - return results; -} - shared_ptr op::v0::LSTMSequence::clone_with_new_inputs(const OutputVector& new_args) const { NGRAPH_OP_SCOPE(v0_LSTMSequence_clone_with_new_inputs); check_new_args_count(this, new_args); diff --git a/ngraph/core/src/op/mvn.cpp b/ngraph/core/src/op/mvn.cpp index 5d0b2887ebba28..b70c944a692f1e 100644 --- a/ngraph/core/src/op/mvn.cpp +++ b/ngraph/core/src/op/mvn.cpp @@ -7,36 +7,26 @@ #include #include "itt.hpp" -#include "ngraph/builder/autobroadcast.hpp" -#include "ngraph/builder/reduce_ops.hpp" -#include "ngraph/op/add.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/divide.hpp" -#include "ngraph/op/sqrt.hpp" -#include "ngraph/op/subtract.hpp" using namespace std; using namespace ngraph; // ------------------------------ V0 ------------------------------ -NGRAPH_SUPPRESS_DEPRECATED_START - NGRAPH_RTTI_DEFINITION(op::v0::MVN, "MVN", 0); -op::MVN::MVN() : FusedOp(), m_across_channels(), m_normalize_variance(), m_reduction_axes() {} +op::v0::MVN::MVN() : Op(), m_across_channels(), m_normalize_variance(), m_reduction_axes() {} -op::MVN::MVN(const Output& data, bool across_channels, bool normalize_variance, double eps) - : FusedOp({data}), +op::v0::MVN::MVN(const Output& data, bool across_channels, bool normalize_variance, double eps) + : Op({data}), m_eps{eps}, m_across_channels{across_channels}, m_normalize_variance{normalize_variance} { constructor_validate_and_infer_types(); } -op::MVN::MVN(const Output& data, AxisSet reduction_axes, bool normalize_variance, double eps) - : FusedOp({data}), +op::v0::MVN::MVN(const Output& data, AxisSet reduction_axes, bool normalize_variance, double eps) + : Op({data}), m_eps{eps}, m_across_channels{false}, m_normalize_variance{normalize_variance}, @@ -46,10 +36,7 @@ op::MVN::MVN(const Output& data, AxisSet reduction_axes, bool normalize_va m_across_channels = (m_reduction_axes.count(chanelAxis) > 0); } -// decompose_op() relies on knowing the data type of input data which might -// not be available at shape inference time. So do direct shape inference -// instead of relying on op decomposition. -void op::MVN::validate_and_infer_types() { +void op::v0::MVN::validate_and_infer_types() { NGRAPH_OP_SCOPE(v0_MVN_validate_and_infer_types); // if m_across_channels is true we should calculate mean and variance per batch // else we calculate these per channel @@ -65,40 +52,16 @@ void op::MVN::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); } -OutputVector op::MVN::decompose_op() const { - auto data = input_value(0); - auto data_shape = data.get_shape(); // assume that data has n and c channels. - - // calculate mean normalization - auto mean = builder::opset1::mean(data, m_reduction_axes); - auto mean_normalization = - std::make_shared(data, builder::opset1::make_broadcast(mean, data_shape, m_reduction_axes)); - - if (!m_normalize_variance) { - return {mean_normalization}; - } else { - // calculate variance - auto variance = builder::opset1::variance(data, m_reduction_axes); - // add epsilon - auto eps_node = - op::Constant::create(data.get_element_type(), Output(variance).get_shape(), vector{m_eps}); - variance = std::make_shared(std::make_shared(variance, eps_node)); - return OutputVector{ - std::make_shared(mean_normalization, - builder::opset1::make_broadcast(variance, data_shape, m_reduction_axes))}; - } -} - -shared_ptr op::MVN::clone_with_new_inputs(const OutputVector& new_args) const { +shared_ptr op::v0::MVN::clone_with_new_inputs(const OutputVector& new_args) const { NGRAPH_OP_SCOPE(v0_MVN_clone_with_new_inputs); NODE_VALIDATION_CHECK(this, new_args.size() == 1, "Expected 1 element in new_args for the MVN op but got ", new_args.size()); - return make_shared(new_args.at(0), m_reduction_axes, m_normalize_variance, m_eps); + return std::make_shared(new_args.at(0), m_reduction_axes, m_normalize_variance, m_eps); } -bool op::MVN::visit_attributes(AttributeVisitor& visitor) { +bool op::v0::MVN::visit_attributes(AttributeVisitor& visitor) { NGRAPH_OP_SCOPE(v0_MVN_visit_attributes); visitor.on_attribute("eps", m_eps); visitor.on_attribute("across_channels", m_across_channels); diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 042ada51cadfb0..89197aee7aefe4 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -144,6 +144,7 @@ set(SRC type_prop/gather_elements.cpp type_prop/gather_nd.cpp type_prop/gather_tree.cpp + type_prop/gelu.cpp type_prop/grn.cpp type_prop/group_convolution.cpp type_prop/group_convolution_backprop_data.cpp diff --git a/ngraph/test/type_prop/gelu.cpp b/ngraph/test/type_prop/gelu.cpp index 28cf820616c9f7..3ad9d37d340d7b 100644 --- a/ngraph/test/type_prop/gelu.cpp +++ b/ngraph/test/type_prop/gelu.cpp @@ -9,8 +9,17 @@ using namespace std; using namespace ngraph; -TEST(type_prop, gelu_default_mode_inference_f32) -{ +// ------------------------------ V0 ------------------------------ +TEST(type_prop, gelu_v0) { + const PartialShape param_shape{64, Dimension::dynamic(), 256, Dimension(4, 8)}; + const auto param = std::make_shared(element::f32, param_shape); + const auto op = std::make_shared(param); + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_output_partial_shape(0), param_shape); +} + +// ------------------------------ V7 ------------------------------ +TEST(type_prop, gelu_default_mode_inference_f32) { auto param = make_shared(element::f32, Shape{1, 32, 32}); auto gelu = make_shared(param); @@ -19,8 +28,7 @@ TEST(type_prop, gelu_default_mode_inference_f32) ASSERT_EQ(gelu->get_approximation_mode(), op::GeluApproximationMode::ERF); } -TEST(type_prop, gelu_default_mode_inference_f16) -{ +TEST(type_prop, gelu_default_mode_inference_f16) { auto param = make_shared(element::f16, Shape{1, 32, 32}); auto gelu = make_shared(param); @@ -29,8 +37,7 @@ TEST(type_prop, gelu_default_mode_inference_f16) ASSERT_EQ(gelu->get_approximation_mode(), op::GeluApproximationMode::ERF); } -TEST(type_prop, gelu_tanh_mode_inference_f32) -{ +TEST(type_prop, gelu_tanh_mode_inference_f32) { auto param = make_shared(element::f32, Shape{1, 32, 32}); auto gelu = make_shared(param, op::GeluApproximationMode::TANH); @@ -39,58 +46,50 @@ TEST(type_prop, gelu_tanh_mode_inference_f32) ASSERT_EQ(gelu->get_approximation_mode(), op::GeluApproximationMode::TANH); } -TEST(type_prop, gelu_tanh_mode_inference_f16) -{ +TEST(type_prop, gelu_tanh_mode_inference_f16) { auto param = make_shared(element::f16, Shape{1, 32, 32}); auto gelu = make_shared(param, op::GeluApproximationMode::TANH); ASSERT_EQ(gelu->get_element_type(), element::f16); ASSERT_EQ(gelu->get_shape(), (Shape{1, 32, 32})); ASSERT_EQ(gelu->get_approximation_mode(), op::GeluApproximationMode::TANH); -} +} -TEST(type_prop, gelu_incompatible_input_type_boolean) -{ +TEST(type_prop, gelu_incompatible_input_type_boolean) { auto param = make_shared(element::boolean, Shape{1, 32, 32}); ASSERT_THROW(std::make_shared(param), ngraph::NodeValidationFailure); } -TEST(type_prop, gelu_incompatible_input_type_u16) -{ +TEST(type_prop, gelu_incompatible_input_type_u16) { auto param = make_shared(element::u16, Shape{1, 32, 32}); ASSERT_THROW(std::make_shared(param), ngraph::NodeValidationFailure); } -TEST(type_prop, gelu_incompatible_input_type_i32) -{ +TEST(type_prop, gelu_incompatible_input_type_i32) { auto param = make_shared(element::i32, Shape{1, 32, 32}); ASSERT_THROW(std::make_shared(param), ngraph::NodeValidationFailure); } -TEST(type_prop, gelu_incompatible_input_type_i16) -{ +TEST(type_prop, gelu_incompatible_input_type_i16) { auto param = make_shared(element::i16, Shape{1, 32, 32}); ASSERT_THROW(std::make_shared(param), ngraph::NodeValidationFailure); } -TEST(type_prop, gelu_dynamic_rank_input_shape_2D) -{ +TEST(type_prop, gelu_dynamic_rank_input_shape_2D) { const PartialShape param_shape{Dimension::dynamic(), 10}; const auto param = std::make_shared(element::f32, param_shape); const auto op = std::make_shared(param); ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape{Dimension(), 10})); } -TEST(type_prop, gelu_dynamic_rank_input_shape_3D) -{ +TEST(type_prop, gelu_dynamic_rank_input_shape_3D) { const PartialShape param_shape{100, Dimension::dynamic(), 58}; const auto param = std::make_shared(element::f32, param_shape); const auto op = std::make_shared(param); ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape{100, Dimension(), 58})); } -TEST(type_prop, gelu_dynamic_rank_input_shape_full) -{ +TEST(type_prop, gelu_dynamic_rank_input_shape_full) { const auto param = std::make_shared(element::f32, PartialShape::dynamic()); const auto op = std::make_shared(param); ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); diff --git a/ngraph/test/type_prop/lstm_sequence.cpp b/ngraph/test/type_prop/lstm_sequence.cpp index a72ae47204d983..320268864a8c69 100644 --- a/ngraph/test/type_prop/lstm_sequence.cpp +++ b/ngraph/test/type_prop/lstm_sequence.cpp @@ -7,9 +7,6 @@ #include "ngraph/opsets/opset5.hpp" #include "util/type_prop.hpp" -// suppress FusedOp deprecation warnings -NGRAPH_SUPPRESS_DEPRECATED_START - using namespace std; using namespace ngraph; From 9c063aea89d86d0108610c06e6652f976726be2d Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Wed, 18 Aug 2021 21:26:05 +0300 Subject: [PATCH 024/102] Move ngraph::element::Type to ov namespace (#7124) * Moved ngraph::Type -> ov::Type * Revert original files --- ngraph/core/include/ngraph/type/bfloat16.hpp | 229 +---------------- .../core/include/ngraph/type/element_type.hpp | 202 ++------------- .../ngraph/type/element_type_traits.hpp | 87 +------ ngraph/core/include/ngraph/type/float16.hpp | 212 +--------------- .../include/openvino/core/type/bfloat16.hpp | 236 ++++++++++++++++++ .../openvino/core/type/element_type.hpp | 202 +++++++++++++++ .../core/type/element_type_traits.hpp | 95 +++++++ .../include/openvino/core/type/float16.hpp | 219 ++++++++++++++++ ngraph/core/src/type/element_type.cpp | 187 +++++++------- 9 files changed, 879 insertions(+), 790 deletions(-) create mode 100644 ngraph/core/include/openvino/core/type/bfloat16.hpp create mode 100644 ngraph/core/include/openvino/core/type/element_type.hpp create mode 100644 ngraph/core/include/openvino/core/type/element_type_traits.hpp create mode 100644 ngraph/core/include/openvino/core/type/float16.hpp diff --git a/ngraph/core/include/ngraph/type/bfloat16.hpp b/ngraph/core/include/ngraph/type/bfloat16.hpp index 7128e8250eb478..53179cc61877d0 100644 --- a/ngraph/core/include/ngraph/type/bfloat16.hpp +++ b/ngraph/core/include/ngraph/type/bfloat16.hpp @@ -4,233 +4,8 @@ #pragma once -#include -#include -#include -#include -#include -#include - -#include "ngraph/ngraph_visibility.hpp" - -#define ROUND_MODE_TO_NEAREST_EVEN +#include "openvino/core/type/bfloat16.hpp" namespace ngraph { -class NGRAPH_API bfloat16 { -public: - constexpr bfloat16() : m_value{0} {} - bfloat16(float value) : m_value { -#if defined ROUND_MODE_TO_NEAREST - round_to_nearest(value) -#elif defined ROUND_MODE_TO_NEAREST_EVEN - round_to_nearest_even(value) -#elif defined ROUND_MODE_TRUNCATE - truncate(value) -#else -# error "ROUNDING_MODE must be one of ROUND_MODE_TO_NEAREST, ROUND_MODE_TO_NEAREST_EVEN, or ROUND_MODE_TRUNCATE" -#endif - } - {} - - template - explicit bfloat16(I value) : m_value{bfloat16{static_cast(value)}.m_value} {} - - std::string to_string() const; - size_t size() const; - template - bool operator==(const T& other) const; - template - bool operator!=(const T& other) const { - return !(*this == other); - } - template - bool operator<(const T& other) const; - template - bool operator<=(const T& other) const; - template - bool operator>(const T& other) const; - template - bool operator>=(const T& other) const; - template - bfloat16 operator+(const T& other) const; - template - bfloat16 operator+=(const T& other); - template - bfloat16 operator-(const T& other) const; - template - bfloat16 operator-=(const T& other); - template - bfloat16 operator*(const T& other) const; - template - bfloat16 operator*=(const T& other); - template - bfloat16 operator/(const T& other) const; - template - bfloat16 operator/=(const T& other); - operator float() const; - - static std::vector to_float_vector(const std::vector&); - static std::vector from_float_vector(const std::vector&); - static constexpr bfloat16 from_bits(uint16_t bits) { - return bfloat16(bits, true); - } - uint16_t to_bits() const; - friend std::ostream& operator<<(std::ostream& out, const bfloat16& obj) { - out << static_cast(obj); - return out; - } - -#define cu32(x) (F32(x).i) - - static uint16_t round_to_nearest_even(float x) { - return static_cast((cu32(x) + ((cu32(x) & 0x00010000) >> 1)) >> 16); - } - - static uint16_t round_to_nearest(float x) { - return static_cast((cu32(x) + 0x8000) >> 16); - } - - static uint16_t truncate(float x) { - return static_cast((cu32(x)) >> 16); - } - -private: - constexpr bfloat16(uint16_t x, bool) : m_value{x} {} - union F32 { - F32(float val) : f{val} {} - F32(uint32_t val) : i{val} {} - float f; - uint32_t i; - }; - - uint16_t m_value; -}; - -template -bool bfloat16::operator==(const T& other) const { -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - return (static_cast(*this) == static_cast(other)); -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif -} - -template -bool bfloat16::operator<(const T& other) const { - return (static_cast(*this) < static_cast(other)); -} - -template -bool bfloat16::operator<=(const T& other) const { - return (static_cast(*this) <= static_cast(other)); -} - -template -bool bfloat16::operator>(const T& other) const { - return (static_cast(*this) > static_cast(other)); -} - -template -bool bfloat16::operator>=(const T& other) const { - return (static_cast(*this) >= static_cast(other)); -} - -template -bfloat16 bfloat16::operator+(const T& other) const { - return {static_cast(*this) + static_cast(other)}; -} - -template -bfloat16 bfloat16::operator+=(const T& other) { - return *this = *this + other; -} - -template -bfloat16 bfloat16::operator-(const T& other) const { - return {static_cast(*this) - static_cast(other)}; -} - -template -bfloat16 bfloat16::operator-=(const T& other) { - return *this = *this - other; -} - -template -bfloat16 bfloat16::operator*(const T& other) const { - return {static_cast(*this) * static_cast(other)}; -} - -template -bfloat16 bfloat16::operator*=(const T& other) { - return *this = *this * other; -} - -template -bfloat16 bfloat16::operator/(const T& other) const { - return {static_cast(*this) / static_cast(other)}; -} - -template -bfloat16 bfloat16::operator/=(const T& other) { - return *this = *this / other; -} +using ov::bfloat16; } // namespace ngraph - -namespace std { -template <> -class numeric_limits { -public: - static constexpr bool is_specialized = true; - static constexpr ngraph::bfloat16 min() noexcept { - return ngraph::bfloat16::from_bits(0x007F); - } - static constexpr ngraph::bfloat16 max() noexcept { - return ngraph::bfloat16::from_bits(0x7F7F); - } - static constexpr ngraph::bfloat16 lowest() noexcept { - return ngraph::bfloat16::from_bits(0xFF7F); - } - static constexpr int digits = 7; - static constexpr int digits10 = 2; - static constexpr bool is_signed = true; - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = 2; - static constexpr ngraph::bfloat16 epsilon() noexcept { - return ngraph::bfloat16::from_bits(0x3C00); - } - static constexpr ngraph::bfloat16 round_error() noexcept { - return ngraph::bfloat16::from_bits(0x3F00); - } - static constexpr int min_exponent = -125; - static constexpr int min_exponent10 = -37; - static constexpr int max_exponent = 128; - static constexpr int max_exponent10 = 38; - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - static constexpr ngraph::bfloat16 infinity() noexcept { - return ngraph::bfloat16::from_bits(0x7F80); - } - static constexpr ngraph::bfloat16 quiet_NaN() noexcept { - return ngraph::bfloat16::from_bits(0x7FC0); - } - static constexpr ngraph::bfloat16 signaling_NaN() noexcept { - return ngraph::bfloat16::from_bits(0x7FC0); - } - static constexpr ngraph::bfloat16 denorm_min() noexcept { - return ngraph::bfloat16::from_bits(0); - } - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = false; - static constexpr bool is_modulo = false; - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; -}; -} // namespace std diff --git a/ngraph/core/include/ngraph/type/element_type.hpp b/ngraph/core/include/ngraph/type/element_type.hpp index 45ef3af2b80ad8..78a5dc1f13a068 100644 --- a/ngraph/core/include/ngraph/type/element_type.hpp +++ b/ngraph/core/include/ngraph/type/element_type.hpp @@ -8,194 +8,42 @@ #pragma once -#include -#include -#include -#include -#include - -#include "ngraph/attribute_adapter.hpp" -#include "ngraph/deprecated.hpp" -#include "ngraph/except.hpp" -#include "ngraph/ngraph_visibility.hpp" #include "ngraph/type/bfloat16.hpp" #include "ngraph/type/float16.hpp" +#include "openvino/core/type/element_type.hpp" namespace ngraph { namespace element { -enum class Type_t { - undefined, - dynamic, - boolean, - bf16, - f16, - f32, - f64, - i4, - i8, - i16, - i32, - i64, - u1, - u4, - u8, - u16, - u32, - u64 -}; - -class NGRAPH_API Type { -public: - Type() : m_type{element::Type_t::undefined} {} - Type(const Type&) = default; - constexpr Type(const Type_t t) : m_type{t} {} - Type(size_t bitwidth, bool is_real, bool is_signed, bool is_quantized, const std::string& cname); - Type& operator=(const Type&) = default; - const std::string& c_type_string() const; - size_t size() const; - size_t hash() const; - bool is_static() const; - bool is_dynamic() const { - return !is_static(); - } - bool is_real() const; - // TODO: We may want to revisit this definition when we do a more general cleanup of - // element types: - bool is_integral() const { - return !is_real(); - } - bool is_integral_number() const; - bool is_signed() const; - bool is_quantized() const; - size_t bitwidth() const; - // The name of this type, the enum name of this type - const std::string& get_type_name() const; - friend NGRAPH_API std::ostream& operator<<(std::ostream&, const Type&); - static std::vector get_known_types(); - - /// \brief Checks whether this element type is merge-compatible with `t`. - /// \param t The element type to compare this element type to. - /// \return `true` if this element type is compatible with `t`, else `false`. - bool compatible(const element::Type& t) const; - - /// \brief Merges two element types t1 and t2, writing the result into dst and - /// returning true if successful, else returning false. - /// - /// To "merge" two element types t1 and t2 is to find the least restrictive - /// element type t that is no more restrictive than t1 and t2, if t exists. - /// More simply: - /// - /// merge(dst,element::Type::dynamic,t) - /// writes t to dst and returns true - /// - /// merge(dst,t,element::Type::dynamic) - /// writes t to dst and returns true - /// - /// merge(dst,t1,t2) where t1, t2 both static and equal - /// writes t1 to dst and returns true - /// - /// merge(dst,t1,t2) where t1, t2 both static and unequal - /// does nothing to dst, and returns false - static bool merge(element::Type& dst, const element::Type& t1, const element::Type& t2); - - // \brief This allows switch(element_type) - constexpr operator Type_t() const { - return m_type; - } - -private: - Type_t m_type{Type_t::undefined}; -}; - -typedef std::vector TypeVector; - -constexpr Type undefined(Type_t::undefined); -constexpr Type dynamic(Type_t::dynamic); -constexpr Type boolean(Type_t::boolean); -constexpr Type bf16(Type_t::bf16); -constexpr Type f16(Type_t::f16); -constexpr Type f32(Type_t::f32); -constexpr Type f64(Type_t::f64); -constexpr Type i4(Type_t::i4); -constexpr Type i8(Type_t::i8); -constexpr Type i16(Type_t::i16); -constexpr Type i32(Type_t::i32); -constexpr Type i64(Type_t::i64); -constexpr Type u1(Type_t::u1); -constexpr Type u4(Type_t::u4); -constexpr Type u8(Type_t::u8); -constexpr Type u16(Type_t::u16); -constexpr Type u32(Type_t::u32); -constexpr Type u64(Type_t::u64); +using ov::element::Type; +using ov::element::Type_t; +using TypeVector = std::vector; + +using ov::element::bf16; +using ov::element::boolean; +using ov::element::dynamic; +using ov::element::f16; +using ov::element::f32; +using ov::element::f64; +using ov::element::i16; +using ov::element::i32; +using ov::element::i4; +using ov::element::i64; +using ov::element::i8; +using ov::element::u1; +using ov::element::u16; +using ov::element::u32; +using ov::element::u4; +using ov::element::u64; +using ov::element::u8; +using ov::element::undefined; template Type from() { - throw std::invalid_argument("Unknown type"); + return ov::element::from(); } -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); - -NGRAPH_API -std::ostream& operator<<(std::ostream& out, const ngraph::element::Type& obj); } // namespace element -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(element::Type_t& value) : EnumAttributeAdapterBase(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -template <> -class NGRAPH_API AttributeAdapter : public ValueAccessor { -public: - AttributeAdapter(element::Type& value) : m_ref(value) {} - - const std::string& get() override; - void set(const std::string& value) override; - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } - operator element::Type&() { - return m_ref; - } - -protected: - element::Type& m_ref; -}; - /// \brief Return the number of bytes in the compile-time representation of the element type. +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") size_t compiler_byte_size(element::Type_t et); } // namespace ngraph diff --git a/ngraph/core/include/ngraph/type/element_type_traits.hpp b/ngraph/core/include/ngraph/type/element_type_traits.hpp index 6d37c3776f0acc..abbf9551809e3b 100644 --- a/ngraph/core/include/ngraph/type/element_type_traits.hpp +++ b/ngraph/core/include/ngraph/type/element_type_traits.hpp @@ -4,92 +4,11 @@ #pragma once -#include "ngraph/type/element_type.hpp" +#include "openvino/core/type/element_type_traits.hpp" namespace ngraph { -template -struct element_type_traits {}; +using ov::element_type_traits; -template -using fundamental_type_for = typename element_type_traits::value_type; +using ov::fundamental_type_for; -template <> -struct element_type_traits { - using value_type = char; -}; - -template <> -struct element_type_traits { - using value_type = bfloat16; -}; - -template <> -struct element_type_traits { - using value_type = float16; -}; - -template <> -struct element_type_traits { - using value_type = float; -}; - -template <> -struct element_type_traits { - using value_type = double; -}; - -template <> -struct element_type_traits { - using value_type = int8_t; -}; - -template <> -struct element_type_traits { - using value_type = int8_t; -}; - -template <> -struct element_type_traits { - using value_type = int16_t; -}; - -template <> -struct element_type_traits { - using value_type = int32_t; -}; - -template <> -struct element_type_traits { - using value_type = int64_t; -}; - -template <> -struct element_type_traits { - using value_type = int8_t; -}; - -template <> -struct element_type_traits { - using value_type = int8_t; -}; - -template <> -struct element_type_traits { - using value_type = uint8_t; -}; - -template <> -struct element_type_traits { - using value_type = uint16_t; -}; - -template <> -struct element_type_traits { - using value_type = uint32_t; -}; - -template <> -struct element_type_traits { - using value_type = uint64_t; -}; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/type/float16.hpp b/ngraph/core/include/ngraph/type/float16.hpp index 6a7bdf62dbb210..64418d426a5fea 100644 --- a/ngraph/core/include/ngraph/type/float16.hpp +++ b/ngraph/core/include/ngraph/type/float16.hpp @@ -4,216 +4,8 @@ #pragma once -#include -#include -#include -#include -#include -#include - -#include "ngraph/ngraph_visibility.hpp" - -#define ROUND_MODE_TO_NEAREST_EVEN +#include "openvino/core/type/float16.hpp" namespace ngraph { -class NGRAPH_API float16 { -public: - constexpr float16() : m_value{0} {} - - static uint32_t constexpr frac_size = 10; - static uint32_t constexpr exp_size = 5; - static uint32_t constexpr exp_bias = 15; - - float16(uint32_t sign, uint32_t biased_exponent, uint32_t fraction) - : m_value((sign & 0x01) << 15 | (biased_exponent & 0x1F) << 10 | (fraction & 0x03FF)) {} - - float16(float value); - - template - explicit float16(I value) : m_value{float16{static_cast(value)}.m_value} {} - - std::string to_string() const; - size_t size() const; - template - bool operator==(const T& other) const; - template - bool operator!=(const T& other) const { - return !(*this == other); - } - template - bool operator<(const T& other) const; - template - bool operator<=(const T& other) const; - template - bool operator>(const T& other) const; - template - bool operator>=(const T& other) const; - template - float16 operator+(const T& other) const; - template - float16 operator+=(const T& other); - template - float16 operator-(const T& other) const; - template - float16 operator-=(const T& other); - template - float16 operator*(const T& other) const; - template - float16 operator*=(const T& other); - template - float16 operator/(const T& other) const; - template - float16 operator/=(const T& other); - operator float() const; - - static constexpr float16 from_bits(uint16_t bits) { - return float16(bits, true); - } - uint16_t to_bits() const; - friend std::ostream& operator<<(std::ostream& out, const float16& obj) { - out << static_cast(obj); - return out; - } - -private: - constexpr float16(uint16_t x, bool) : m_value{x} {} - union F32 { - F32(float val) : f{val} {} - F32(uint32_t val) : i{val} {} - float f; - uint32_t i; - }; - - uint16_t m_value; -}; - -template -bool float16::operator==(const T& other) const { -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - return (static_cast(*this) == static_cast(other)); -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif -} - -template -bool float16::operator<(const T& other) const { - return (static_cast(*this) < static_cast(other)); -} - -template -bool float16::operator<=(const T& other) const { - return (static_cast(*this) <= static_cast(other)); -} - -template -bool float16::operator>(const T& other) const { - return (static_cast(*this) > static_cast(other)); -} - -template -bool float16::operator>=(const T& other) const { - return (static_cast(*this) >= static_cast(other)); -} - -template -float16 float16::operator+(const T& other) const { - return {static_cast(*this) + static_cast(other)}; -} - -template -float16 float16::operator+=(const T& other) { - return *this = *this + other; -} - -template -float16 float16::operator-(const T& other) const { - return {static_cast(*this) - static_cast(other)}; -} - -template -float16 float16::operator-=(const T& other) { - return *this = *this - other; -} - -template -float16 float16::operator*(const T& other) const { - return {static_cast(*this) * static_cast(other)}; -} - -template -float16 float16::operator*=(const T& other) { - return *this = *this * other; -} - -template -float16 float16::operator/(const T& other) const { - return {static_cast(*this) / static_cast(other)}; -} - -template -float16 float16::operator/=(const T& other) { - return *this = *this / other; -} +using ov::float16; } // namespace ngraph - -namespace std { -bool NGRAPH_API isnan(ngraph::float16 x); - -template <> -class numeric_limits { -public: - static constexpr bool is_specialized = true; - static constexpr ngraph::float16 min() noexcept { - return ngraph::float16::from_bits(0x0200); - } - static constexpr ngraph::float16 max() noexcept { - return ngraph::float16::from_bits(0x7BFF); - } - static constexpr ngraph::float16 lowest() noexcept { - return ngraph::float16::from_bits(0xFBFF); - } - static constexpr int digits = 11; - static constexpr int digits10 = 3; - static constexpr bool is_signed = true; - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = 2; - static constexpr ngraph::float16 epsilon() noexcept { - return ngraph::float16::from_bits(0x1200); - } - static constexpr ngraph::float16 round_error() noexcept { - return ngraph::float16::from_bits(0x3C00); - } - static constexpr int min_exponent = -13; - static constexpr int min_exponent10 = -4; - static constexpr int max_exponent = 16; - static constexpr int max_exponent10 = 4; - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - static constexpr ngraph::float16 infinity() noexcept { - return ngraph::float16::from_bits(0x7C00); - } - static constexpr ngraph::float16 quiet_NaN() noexcept { - return ngraph::float16::from_bits(0x7FFF); - } - static constexpr ngraph::float16 signaling_NaN() noexcept { - return ngraph::float16::from_bits(0x7DFF); - } - static constexpr ngraph::float16 denorm_min() noexcept { - return ngraph::float16::from_bits(0); - } - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = false; - static constexpr bool is_modulo = false; - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; -}; -} // namespace std diff --git a/ngraph/core/include/openvino/core/type/bfloat16.hpp b/ngraph/core/include/openvino/core/type/bfloat16.hpp new file mode 100644 index 00000000000000..4d7e2cd9570fe7 --- /dev/null +++ b/ngraph/core/include/openvino/core/type/bfloat16.hpp @@ -0,0 +1,236 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" + +#define ROUND_MODE_TO_NEAREST_EVEN + +namespace ov { +class OPENVINO_API bfloat16 { +public: + constexpr bfloat16() : m_value{0} {} + bfloat16(float value) : m_value { +#if defined ROUND_MODE_TO_NEAREST + round_to_nearest(value) +#elif defined ROUND_MODE_TO_NEAREST_EVEN + round_to_nearest_even(value) +#elif defined ROUND_MODE_TRUNCATE + truncate(value) +#else +# error "ROUNDING_MODE must be one of ROUND_MODE_TO_NEAREST, ROUND_MODE_TO_NEAREST_EVEN, or ROUND_MODE_TRUNCATE" +#endif + } + {} + + template + explicit bfloat16(I value) : m_value{bfloat16{static_cast(value)}.m_value} {} + + std::string to_string() const; + size_t size() const; + template + bool operator==(const T& other) const; + template + bool operator!=(const T& other) const { + return !(*this == other); + } + template + bool operator<(const T& other) const; + template + bool operator<=(const T& other) const; + template + bool operator>(const T& other) const; + template + bool operator>=(const T& other) const; + template + bfloat16 operator+(const T& other) const; + template + bfloat16 operator+=(const T& other); + template + bfloat16 operator-(const T& other) const; + template + bfloat16 operator-=(const T& other); + template + bfloat16 operator*(const T& other) const; + template + bfloat16 operator*=(const T& other); + template + bfloat16 operator/(const T& other) const; + template + bfloat16 operator/=(const T& other); + operator float() const; + + static std::vector to_float_vector(const std::vector&); + static std::vector from_float_vector(const std::vector&); + static constexpr bfloat16 from_bits(uint16_t bits) { + return bfloat16(bits, true); + } + uint16_t to_bits() const; + friend std::ostream& operator<<(std::ostream& out, const bfloat16& obj) { + out << static_cast(obj); + return out; + } + +#define cu32(x) (F32(x).i) + + static uint16_t round_to_nearest_even(float x) { + return static_cast((cu32(x) + ((cu32(x) & 0x00010000) >> 1)) >> 16); + } + + static uint16_t round_to_nearest(float x) { + return static_cast((cu32(x) + 0x8000) >> 16); + } + + static uint16_t truncate(float x) { + return static_cast((cu32(x)) >> 16); + } + +private: + constexpr bfloat16(uint16_t x, bool) : m_value{x} {} + union F32 { + F32(float val) : f{val} {} + F32(uint32_t val) : i{val} {} + float f; + uint32_t i; + }; + + uint16_t m_value; +}; + +template +bool bfloat16::operator==(const T& other) const { +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + return (static_cast(*this) == static_cast(other)); +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif +} + +template +bool bfloat16::operator<(const T& other) const { + return (static_cast(*this) < static_cast(other)); +} + +template +bool bfloat16::operator<=(const T& other) const { + return (static_cast(*this) <= static_cast(other)); +} + +template +bool bfloat16::operator>(const T& other) const { + return (static_cast(*this) > static_cast(other)); +} + +template +bool bfloat16::operator>=(const T& other) const { + return (static_cast(*this) >= static_cast(other)); +} + +template +bfloat16 bfloat16::operator+(const T& other) const { + return {static_cast(*this) + static_cast(other)}; +} + +template +bfloat16 bfloat16::operator+=(const T& other) { + return *this = *this + other; +} + +template +bfloat16 bfloat16::operator-(const T& other) const { + return {static_cast(*this) - static_cast(other)}; +} + +template +bfloat16 bfloat16::operator-=(const T& other) { + return *this = *this - other; +} + +template +bfloat16 bfloat16::operator*(const T& other) const { + return {static_cast(*this) * static_cast(other)}; +} + +template +bfloat16 bfloat16::operator*=(const T& other) { + return *this = *this * other; +} + +template +bfloat16 bfloat16::operator/(const T& other) const { + return {static_cast(*this) / static_cast(other)}; +} + +template +bfloat16 bfloat16::operator/=(const T& other) { + return *this = *this / other; +} +} // namespace ov + +namespace std { +template <> +class numeric_limits { +public: + static constexpr bool is_specialized = true; + static constexpr ov::bfloat16 min() noexcept { + return ov::bfloat16::from_bits(0x007F); + } + static constexpr ov::bfloat16 max() noexcept { + return ov::bfloat16::from_bits(0x7F7F); + } + static constexpr ov::bfloat16 lowest() noexcept { + return ov::bfloat16::from_bits(0xFF7F); + } + static constexpr int digits = 7; + static constexpr int digits10 = 2; + static constexpr bool is_signed = true; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = 2; + static constexpr ov::bfloat16 epsilon() noexcept { + return ov::bfloat16::from_bits(0x3C00); + } + static constexpr ov::bfloat16 round_error() noexcept { + return ov::bfloat16::from_bits(0x3F00); + } + static constexpr int min_exponent = -125; + static constexpr int min_exponent10 = -37; + static constexpr int max_exponent = 128; + static constexpr int max_exponent10 = 38; + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr ov::bfloat16 infinity() noexcept { + return ov::bfloat16::from_bits(0x7F80); + } + static constexpr ov::bfloat16 quiet_NaN() noexcept { + return ov::bfloat16::from_bits(0x7FC0); + } + static constexpr ov::bfloat16 signaling_NaN() noexcept { + return ov::bfloat16::from_bits(0x7FC0); + } + static constexpr ov::bfloat16 denorm_min() noexcept { + return ov::bfloat16::from_bits(0); + } + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; +}; +} // namespace std diff --git a/ngraph/core/include/openvino/core/type/element_type.hpp b/ngraph/core/include/openvino/core/type/element_type.hpp new file mode 100644 index 00000000000000..b3ccc0e02199be --- /dev/null +++ b/ngraph/core/include/openvino/core/type/element_type.hpp @@ -0,0 +1,202 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +//================================================================================================ +// ElementType +//================================================================================================ + +#pragma once + +#include +#include +#include +#include +#include + +#include "ngraph/attribute_adapter.hpp" +#include "ngraph/deprecated.hpp" +#include "ngraph/except.hpp" +#include "openvino/core/core_visibility.hpp" +#include "openvino/core/type/bfloat16.hpp" +#include "openvino/core/type/float16.hpp" + +namespace ov { +namespace element { +enum class Type_t { + undefined, + dynamic, + boolean, + bf16, + f16, + f32, + f64, + i4, + i8, + i16, + i32, + i64, + u1, + u4, + u8, + u16, + u32, + u64 +}; + +class OPENVINO_API Type { +public: + Type() = default; + Type(const Type&) = default; + constexpr Type(const Type_t t) : m_type{t} {} + Type(size_t bitwidth, bool is_real, bool is_signed, bool is_quantized, const std::string& cname); + Type& operator=(const Type&) = default; + const std::string& c_type_string() const; + size_t size() const; + size_t hash() const; + bool is_static() const; + bool is_dynamic() const { + return !is_static(); + } + bool is_real() const; + // TODO: We may want to revisit this definition when we do a more general cleanup of + // element types: + bool is_integral() const { + return !is_real(); + } + bool is_integral_number() const; + bool is_signed() const; + bool is_quantized() const; + size_t bitwidth() const; + // The name of this type, the enum name of this type + const std::string& get_type_name() const; + friend OPENVINO_API std::ostream& operator<<(std::ostream&, const Type&); + static std::vector get_known_types(); + + /// \brief Checks whether this element type is merge-compatible with `t`. + /// \param t The element type to compare this element type to. + /// \return `true` if this element type is compatible with `t`, else `false`. + bool compatible(const element::Type& t) const; + + /// \brief Merges two element types t1 and t2, writing the result into dst and + /// returning true if successful, else returning false. + /// + /// To "merge" two element types t1 and t2 is to find the least restrictive + /// element type t that is no more restrictive than t1 and t2, if t exists. + /// More simply: + /// + /// merge(dst,element::Type::dynamic,t) + /// writes t to dst and returns true + /// + /// merge(dst,t,element::Type::dynamic) + /// writes t to dst and returns true + /// + /// merge(dst,t1,t2) where t1, t2 both static and equal + /// writes t1 to dst and returns true + /// + /// merge(dst,t1,t2) where t1, t2 both static and unequal + /// does nothing to dst, and returns false + static bool merge(element::Type& dst, const element::Type& t1, const element::Type& t2); + + // \brief This allows switch(element_type) + constexpr operator Type_t() const { + return m_type; + } + +private: + Type_t m_type{Type_t::undefined}; +}; + +using TypeVector = std::vector; + +constexpr Type undefined(Type_t::undefined); +constexpr Type dynamic(Type_t::dynamic); +constexpr Type boolean(Type_t::boolean); +constexpr Type bf16(Type_t::bf16); +constexpr Type f16(Type_t::f16); +constexpr Type f32(Type_t::f32); +constexpr Type f64(Type_t::f64); +constexpr Type i4(Type_t::i4); +constexpr Type i8(Type_t::i8); +constexpr Type i16(Type_t::i16); +constexpr Type i32(Type_t::i32); +constexpr Type i64(Type_t::i64); +constexpr Type u1(Type_t::u1); +constexpr Type u4(Type_t::u4); +constexpr Type u8(Type_t::u8); +constexpr Type u16(Type_t::u16); +constexpr Type u32(Type_t::u32); +constexpr Type u64(Type_t::u64); + +template +Type from() { + throw std::invalid_argument("Unknown type"); +} +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); + +OPENVINO_API +std::ostream& operator<<(std::ostream& out, const ov::element::Type& obj); +} // namespace element + +} // namespace ov + +namespace ngraph { + +template <> +class OPENVINO_API AttributeAdapter : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ov::element::Type_t& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class OPENVINO_API AttributeAdapter : public ValueAccessor { +public: + AttributeAdapter(ov::element::Type& value) : m_ref(value) {} + + const std::string& get() override; + void set(const std::string& value) override; + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } + operator ov::element::Type&() { + return m_ref; + } + +protected: + ov::element::Type& m_ref; +}; +} // namespace ngraph diff --git a/ngraph/core/include/openvino/core/type/element_type_traits.hpp b/ngraph/core/include/openvino/core/type/element_type_traits.hpp new file mode 100644 index 00000000000000..07d4230ddbccef --- /dev/null +++ b/ngraph/core/include/openvino/core/type/element_type_traits.hpp @@ -0,0 +1,95 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/core/type/element_type.hpp" + +namespace ov { +template +struct element_type_traits {}; + +template +using fundamental_type_for = typename element_type_traits::value_type; + +template <> +struct element_type_traits { + using value_type = char; +}; + +template <> +struct element_type_traits { + using value_type = bfloat16; +}; + +template <> +struct element_type_traits { + using value_type = float16; +}; + +template <> +struct element_type_traits { + using value_type = float; +}; + +template <> +struct element_type_traits { + using value_type = double; +}; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; + +template <> +struct element_type_traits { + using value_type = int16_t; +}; + +template <> +struct element_type_traits { + using value_type = int32_t; +}; + +template <> +struct element_type_traits { + using value_type = int64_t; +}; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; + +template <> +struct element_type_traits { + using value_type = uint8_t; +}; + +template <> +struct element_type_traits { + using value_type = uint16_t; +}; + +template <> +struct element_type_traits { + using value_type = uint32_t; +}; + +template <> +struct element_type_traits { + using value_type = uint64_t; +}; +} // namespace ov diff --git a/ngraph/core/include/openvino/core/type/float16.hpp b/ngraph/core/include/openvino/core/type/float16.hpp new file mode 100644 index 00000000000000..60c1560c24a254 --- /dev/null +++ b/ngraph/core/include/openvino/core/type/float16.hpp @@ -0,0 +1,219 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" + +#define ROUND_MODE_TO_NEAREST_EVEN + +namespace ov { +class OPENVINO_API float16 { +public: + constexpr float16() : m_value{0} {} + + static uint32_t constexpr frac_size = 10; + static uint32_t constexpr exp_size = 5; + static uint32_t constexpr exp_bias = 15; + + float16(uint32_t sign, uint32_t biased_exponent, uint32_t fraction) + : m_value((sign & 0x01) << 15 | (biased_exponent & 0x1F) << 10 | (fraction & 0x03FF)) {} + + float16(float value); + + template + explicit float16(I value) : m_value{float16{static_cast(value)}.m_value} {} + + std::string to_string() const; + size_t size() const; + template + bool operator==(const T& other) const; + template + bool operator!=(const T& other) const { + return !(*this == other); + } + template + bool operator<(const T& other) const; + template + bool operator<=(const T& other) const; + template + bool operator>(const T& other) const; + template + bool operator>=(const T& other) const; + template + float16 operator+(const T& other) const; + template + float16 operator+=(const T& other); + template + float16 operator-(const T& other) const; + template + float16 operator-=(const T& other); + template + float16 operator*(const T& other) const; + template + float16 operator*=(const T& other); + template + float16 operator/(const T& other) const; + template + float16 operator/=(const T& other); + operator float() const; + + static constexpr float16 from_bits(uint16_t bits) { + return float16(bits, true); + } + uint16_t to_bits() const; + friend std::ostream& operator<<(std::ostream& out, const float16& obj) { + out << static_cast(obj); + return out; + } + +private: + constexpr float16(uint16_t x, bool) : m_value{x} {} + union F32 { + F32(float val) : f{val} {} + F32(uint32_t val) : i{val} {} + float f; + uint32_t i; + }; + + uint16_t m_value; +}; + +template +bool float16::operator==(const T& other) const { +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + return (static_cast(*this) == static_cast(other)); +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif +} + +template +bool float16::operator<(const T& other) const { + return (static_cast(*this) < static_cast(other)); +} + +template +bool float16::operator<=(const T& other) const { + return (static_cast(*this) <= static_cast(other)); +} + +template +bool float16::operator>(const T& other) const { + return (static_cast(*this) > static_cast(other)); +} + +template +bool float16::operator>=(const T& other) const { + return (static_cast(*this) >= static_cast(other)); +} + +template +float16 float16::operator+(const T& other) const { + return {static_cast(*this) + static_cast(other)}; +} + +template +float16 float16::operator+=(const T& other) { + return *this = *this + other; +} + +template +float16 float16::operator-(const T& other) const { + return {static_cast(*this) - static_cast(other)}; +} + +template +float16 float16::operator-=(const T& other) { + return *this = *this - other; +} + +template +float16 float16::operator*(const T& other) const { + return {static_cast(*this) * static_cast(other)}; +} + +template +float16 float16::operator*=(const T& other) { + return *this = *this * other; +} + +template +float16 float16::operator/(const T& other) const { + return {static_cast(*this) / static_cast(other)}; +} + +template +float16 float16::operator/=(const T& other) { + return *this = *this / other; +} +} // namespace ov + +namespace std { +bool OPENVINO_API isnan(ov::float16 x); + +template <> +class numeric_limits { +public: + static constexpr bool is_specialized = true; + static constexpr ov::float16 min() noexcept { + return ov::float16::from_bits(0x0200); + } + static constexpr ov::float16 max() noexcept { + return ov::float16::from_bits(0x7BFF); + } + static constexpr ov::float16 lowest() noexcept { + return ov::float16::from_bits(0xFBFF); + } + static constexpr int digits = 11; + static constexpr int digits10 = 3; + static constexpr bool is_signed = true; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = 2; + static constexpr ov::float16 epsilon() noexcept { + return ov::float16::from_bits(0x1200); + } + static constexpr ov::float16 round_error() noexcept { + return ov::float16::from_bits(0x3C00); + } + static constexpr int min_exponent = -13; + static constexpr int min_exponent10 = -4; + static constexpr int max_exponent = 16; + static constexpr int max_exponent10 = 4; + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr ov::float16 infinity() noexcept { + return ov::float16::from_bits(0x7C00); + } + static constexpr ov::float16 quiet_NaN() noexcept { + return ov::float16::from_bits(0x7FFF); + } + static constexpr ov::float16 signaling_NaN() noexcept { + return ov::float16::from_bits(0x7DFF); + } + static constexpr ov::float16 denorm_min() noexcept { + return ov::float16::from_bits(0); + } + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; +}; +} // namespace std diff --git a/ngraph/core/src/type/element_type.cpp b/ngraph/core/src/type/element_type.cpp index 247928dfafdc58..cc5042a81d6f34 100644 --- a/ngraph/core/src/type/element_type.cpp +++ b/ngraph/core/src/type/element_type.cpp @@ -12,9 +12,8 @@ #include "ngraph/log.hpp" #include "ngraph/type/element_type_traits.hpp" -using namespace ngraph; +constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; -constexpr DiscreteTypeInfo AttributeAdapter::type_info; namespace { class TypeInfo { public: @@ -40,73 +39,77 @@ class TypeInfo { struct ElementTypes { struct TypeHash { - size_t operator()(element::Type_t t) const { + size_t operator()(ov::element::Type_t t) const { return static_cast(t); } }; - using ElementsMap = std::unordered_map; + using ElementsMap = std::unordered_map; static const ElementsMap elements_map; }; const ElementTypes::ElementsMap ElementTypes::elements_map{ - {element::Type_t::undefined, + {ov::element::Type_t::undefined, TypeInfo(std::numeric_limits::max(), false, false, false, "undefined", "undefined")}, - {element::Type_t::dynamic, TypeInfo(0, false, false, false, "dynamic", "dynamic")}, - {element::Type_t::boolean, TypeInfo(8, false, true, false, "char", "boolean")}, - {element::Type_t::bf16, TypeInfo(16, true, true, false, "bfloat16", "bf16")}, - {element::Type_t::f16, TypeInfo(16, true, true, false, "float16", "f16")}, - {element::Type_t::f32, TypeInfo(32, true, true, false, "float", "f32")}, - {element::Type_t::f64, TypeInfo(64, true, true, false, "double", "f64")}, - {element::Type_t::i4, TypeInfo(4, false, true, true, "int4_t", "i4")}, - {element::Type_t::i8, TypeInfo(8, false, true, true, "int8_t", "i8")}, - {element::Type_t::i16, TypeInfo(16, false, true, false, "int16_t", "i16")}, - {element::Type_t::i32, TypeInfo(32, false, true, true, "int32_t", "i32")}, - {element::Type_t::i64, TypeInfo(64, false, true, false, "int64_t", "i64")}, - {element::Type_t::u1, TypeInfo(1, false, false, false, "uint1_t", "u1")}, - {element::Type_t::u4, TypeInfo(4, false, false, false, "uint4_t", "u4")}, - {element::Type_t::u8, TypeInfo(8, false, false, true, "uint8_t", "u8")}, - {element::Type_t::u16, TypeInfo(16, false, false, false, "uint16_t", "u16")}, - {element::Type_t::u32, TypeInfo(32, false, false, false, "uint32_t", "u32")}, - {element::Type_t::u64, TypeInfo(64, false, false, false, "uint64_t", "u64")}, + {ov::element::Type_t::dynamic, TypeInfo(0, false, false, false, "dynamic", "dynamic")}, + {ov::element::Type_t::boolean, TypeInfo(8, false, true, false, "char", "boolean")}, + {ov::element::Type_t::bf16, TypeInfo(16, true, true, false, "bfloat16", "bf16")}, + {ov::element::Type_t::f16, TypeInfo(16, true, true, false, "float16", "f16")}, + {ov::element::Type_t::f32, TypeInfo(32, true, true, false, "float", "f32")}, + {ov::element::Type_t::f64, TypeInfo(64, true, true, false, "double", "f64")}, + {ov::element::Type_t::i4, TypeInfo(4, false, true, true, "int4_t", "i4")}, + {ov::element::Type_t::i8, TypeInfo(8, false, true, true, "int8_t", "i8")}, + {ov::element::Type_t::i16, TypeInfo(16, false, true, false, "int16_t", "i16")}, + {ov::element::Type_t::i32, TypeInfo(32, false, true, true, "int32_t", "i32")}, + {ov::element::Type_t::i64, TypeInfo(64, false, true, false, "int64_t", "i64")}, + {ov::element::Type_t::u1, TypeInfo(1, false, false, false, "uint1_t", "u1")}, + {ov::element::Type_t::u4, TypeInfo(4, false, false, false, "uint4_t", "u4")}, + {ov::element::Type_t::u8, TypeInfo(8, false, false, true, "uint8_t", "u8")}, + {ov::element::Type_t::u16, TypeInfo(16, false, false, false, "uint16_t", "u16")}, + {ov::element::Type_t::u32, TypeInfo(32, false, false, false, "uint32_t", "u32")}, + {ov::element::Type_t::u64, TypeInfo(64, false, false, false, "uint64_t", "u64")}, }; const ElementTypes::ElementsMap& get_type_info_map() { return ElementTypes::elements_map; }; -const TypeInfo& get_type_info(element::Type_t type) { +const TypeInfo& get_type_info(ov::element::Type_t type) { const auto& tim = get_type_info_map(); const auto& found = tim.find(type); if (found == tim.end()) { - throw std::out_of_range{"element::Type_t not supported"}; + throw std::out_of_range{"ov::element::Type_t not supported"}; } return found->second; }; } // namespace -std::vector element::Type::get_known_types() { - std::vector rc = {&element::dynamic, - &element::boolean, - &element::bf16, - &element::f16, - &element::f32, - &element::f64, - &element::i4, - &element::i8, - &element::i16, - &element::i32, - &element::i64, - &element::u1, - &element::u4, - &element::u8, - &element::u16, - &element::u32, - &element::u64}; +std::vector ov::element::Type::get_known_types() { + std::vector rc = {&ov::element::dynamic, + &ov::element::boolean, + &ov::element::bf16, + &ov::element::f16, + &ov::element::f32, + &ov::element::f64, + &ov::element::i4, + &ov::element::i8, + &ov::element::i16, + &ov::element::i32, + &ov::element::i64, + &ov::element::u1, + &ov::element::u4, + &ov::element::u8, + &ov::element::u16, + &ov::element::u32, + &ov::element::u64}; return rc; } -element::Type::Type(size_t bitwidth, bool is_real, bool is_signed, bool is_quantized, const std::string& /* cname */) { +ov::element::Type::Type(size_t bitwidth, + bool is_real, + bool is_signed, + bool is_quantized, + const std::string& /* cname */) { for (const auto& t : get_type_info_map()) { const TypeInfo& info = t.second; if (bitwidth == info.m_bitwidth && is_real == info.m_is_real && is_signed == info.m_is_signed && @@ -117,23 +120,23 @@ element::Type::Type(size_t bitwidth, bool is_real, bool is_signed, bool is_quant } } -const std::string& element::Type::c_type_string() const { +const std::string& ov::element::Type::c_type_string() const { return get_type_info(m_type).m_cname; } -size_t element::Type::size() const { +size_t ov::element::Type::size() const { return std::ceil(static_cast(bitwidth()) / 8.0f); } -size_t element::Type::hash() const { +size_t ov::element::Type::hash() const { return static_cast(m_type); } -const std::string& element::Type::get_type_name() const { +const std::string& ov::element::Type::get_type_name() const { return get_type_info(m_type).m_type_name; } -namespace ngraph { +namespace ov { namespace element { template <> Type from() { @@ -192,17 +195,17 @@ Type from() { return Type_t::bf16; } } // namespace element -} // namespace ngraph +} // namespace ov -std::ostream& element::operator<<(std::ostream& out, const element::Type& obj) { +std::ostream& ov::element::operator<<(std::ostream& out, const ov::element::Type& obj) { return out << obj.get_type_name(); } -bool element::Type::compatible(const element::Type& t) const { +bool ov::element::Type::compatible(const ov::element::Type& t) const { return (is_dynamic() || t.is_dynamic() || *this == t); } -bool element::Type::merge(element::Type& dst, const element::Type& t1, const element::Type& t2) { +bool ov::element::Type::merge(ov::element::Type& dst, const ov::element::Type& t1, const ov::element::Type& t2) { if (t1.is_dynamic()) { dst = t2; return true; @@ -217,35 +220,35 @@ bool element::Type::merge(element::Type& dst, const element::Type& t1, const ele } } -bool element::Type::is_static() const { +bool ov::element::Type::is_static() const { return get_type_info(m_type).m_bitwidth != 0; } -bool element::Type::is_real() const { +bool ov::element::Type::is_real() const { return get_type_info(m_type).m_is_real; } -bool element::Type::is_integral_number() const { - return is_integral() && (m_type != element::boolean); +bool ov::element::Type::is_integral_number() const { + return is_integral() && (m_type != ov::element::boolean); } -bool element::Type::is_signed() const { +bool ov::element::Type::is_signed() const { return get_type_info(m_type).m_is_signed; } -bool element::Type::is_quantized() const { +bool ov::element::Type::is_quantized() const { return get_type_info(m_type).m_is_quantized; } -size_t element::Type::bitwidth() const { +size_t ov::element::Type::bitwidth() const { return get_type_info(m_type).m_bitwidth; } -size_t ngraph::compiler_byte_size(element::Type_t et) { +size_t compiler_byte_size(ov::element::Type_t et) { switch (et) { -#define ET_CASE(et) \ - case element::Type_t::et: \ - return sizeof(element_type_traits::value_type); +#define ET_CASE(et) \ + case ov::element::Type_t::et: \ + return sizeof(ov::element_type_traits::value_type); ET_CASE(boolean); ET_CASE(bf16); ET_CASE(f16); @@ -263,48 +266,48 @@ size_t ngraph::compiler_byte_size(element::Type_t et) { ET_CASE(u32); ET_CASE(u64); #undef ET_CASE - case element::Type_t::undefined: + case ov::element::Type_t::undefined: return 0; - case element::Type_t::dynamic: + case ov::element::Type_t::dynamic: return 0; } - throw ngraph_error("compiler_byte_size: Unsupported value of element::Type_t: " + - std::to_string(static_cast(et))); + throw ngraph::ngraph_error("compiler_byte_size: Unsupported value of ov::element::Type_t: " + + std::to_string(static_cast(et))); } namespace ngraph { template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("element::Type_t", - {{"undefined", element::Type_t::undefined}, - {"dynamic", element::Type_t::dynamic}, - {"boolean", element::Type_t::boolean}, - {"bf16", element::Type_t::bf16}, - {"f16", element::Type_t::f16}, - {"f32", element::Type_t::f32}, - {"f64", element::Type_t::f64}, - {"i4", element::Type_t::i4}, - {"i8", element::Type_t::i8}, - {"i16", element::Type_t::i16}, - {"i32", element::Type_t::i32}, - {"i64", element::Type_t::i64}, - {"u1", element::Type_t::u1}, - {"u4", element::Type_t::u4}, - {"u8", element::Type_t::u8}, - {"u16", element::Type_t::u16}, - {"u32", element::Type_t::u32}, - {"u64", element::Type_t::u64}}); +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames("ov::element::Type_t", + {{"undefined", ov::element::Type_t::undefined}, + {"dynamic", ov::element::Type_t::dynamic}, + {"boolean", ov::element::Type_t::boolean}, + {"bf16", ov::element::Type_t::bf16}, + {"f16", ov::element::Type_t::f16}, + {"f32", ov::element::Type_t::f32}, + {"f64", ov::element::Type_t::f64}, + {"i4", ov::element::Type_t::i4}, + {"i8", ov::element::Type_t::i8}, + {"i16", ov::element::Type_t::i16}, + {"i32", ov::element::Type_t::i32}, + {"i64", ov::element::Type_t::i64}, + {"u1", ov::element::Type_t::u1}, + {"u4", ov::element::Type_t::u4}, + {"u8", ov::element::Type_t::u8}, + {"u16", ov::element::Type_t::u16}, + {"u32", ov::element::Type_t::u32}, + {"u64", ov::element::Type_t::u64}}); return enum_names; } } // namespace ngraph -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; -const std::string& AttributeAdapter::get() { - return as_string(static_cast(m_ref)); +const std::string& ngraph::AttributeAdapter::get() { + return as_string(static_cast(m_ref)); } -void AttributeAdapter::set(const std::string& value) { - m_ref = as_enum(value); +void ngraph::AttributeAdapter::set(const std::string& value) { + m_ref = as_enum(value); } From 7563ee92c9bdf31fef56fa0c3df55f03f43534bf Mon Sep 17 00:00:00 2001 From: Elizaveta Lobanova Date: Thu, 19 Aug 2021 00:22:26 +0300 Subject: [PATCH 025/102] [GNA] Fix order of SwapMatMulInput transformations (#7137) --- inference-engine/src/gna_plugin/gna_plugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index 8245eef629f93d..c4d5b311fd6aa0 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -704,9 +704,9 @@ void GNAPlugin::LoadNetwork(CNNNetwork & _network) { manager.register_pass(); manager.register_pass(); manager.register_pass(); - manager.register_pass(); - manager.register_pass(); manager.register_pass(); + manager.register_pass(); + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); From d03f687590362dfe0d98feb03129ccb9a3708732 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 19 Aug 2021 05:59:31 +0300 Subject: [PATCH 026/102] Moved Dimension, PartialShape, Interval, Rank to ov namespace (#7136) --- .../smart_reshape/strided_slice_squeeze.cpp | 4 +- ngraph/core/include/ngraph/dimension.hpp | 166 +------- ngraph/core/include/ngraph/interval.hpp | 113 +---- ngraph/core/include/ngraph/partial_shape.hpp | 384 +---------------- ngraph/core/include/ngraph/rank.hpp | 7 +- .../core/include/openvino/core/dimension.hpp | 172 ++++++++ .../core/include/openvino/core/interval.hpp | 120 ++++++ .../include/openvino/core/partial_shape.hpp | 401 ++++++++++++++++++ ngraph/core/include/openvino/core/rank.hpp | 14 + ngraph/core/src/dimension.cpp | 2 +- ngraph/core/src/interval.cpp | 4 +- ngraph/core/src/partial_shape.cpp | 4 +- 12 files changed, 721 insertions(+), 670 deletions(-) create mode 100644 ngraph/core/include/openvino/core/dimension.hpp create mode 100644 ngraph/core/include/openvino/core/interval.hpp create mode 100644 ngraph/core/include/openvino/core/partial_shape.hpp create mode 100644 ngraph/core/include/openvino/core/rank.hpp diff --git a/inference-engine/src/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp b/inference-engine/src/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp index 24e0cf207d32af..cb03cd9b88e16f 100644 --- a/inference-engine/src/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp +++ b/inference-engine/src/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp @@ -158,8 +158,8 @@ bool squeezes_perform_the_same(std::shared_ptr lhs, std const auto l_axes = std::dynamic_pointer_cast(lhs->get_input_node_shared_ptr(1)); const auto r_axes = std::dynamic_pointer_cast(rhs->get_input_node_shared_ptr(1)); if (l_axes && r_axes) - return normalize_axes(lhs->description(), l_axes->cast_vector(), rank) == - normalize_axes(rhs->description(), r_axes->cast_vector(), rank); + return ngraph::normalize_axes(lhs->description(), l_axes->cast_vector(), rank) == + ngraph::normalize_axes(rhs->description(), r_axes->cast_vector(), rank); return false; } diff --git a/ngraph/core/include/ngraph/dimension.hpp b/ngraph/core/include/ngraph/dimension.hpp index 5ba014d3a96ec6..9d748b26b30c94 100644 --- a/ngraph/core/include/ngraph/dimension.hpp +++ b/ngraph/core/include/ngraph/dimension.hpp @@ -4,171 +4,9 @@ #pragma once -#include - -#include -#include - -#include "ngraph/deprecated.hpp" #include "ngraph/interval.hpp" -#include "ngraph/ngraph_visibility.hpp" +#include "openvino/core/dimension.hpp" namespace ngraph { -/// \brief Class representing a dimension, which may be dynamic (undetermined until runtime), -/// in a shape or shape-like object. -/// -/// Static dimensions may be implicitly converted from value_type. A dynamic dimension is -/// constructed with Dimension() or Dimension::dynamic(). -class NGRAPH_API Dimension { -public: - using value_type = int64_t; - - /// \brief Construct a static dimension. - /// \param dimension Value of the dimension. - Dimension(value_type dimension); - - /// \brief Construct a dynamic dimension with bounded range - /// \param min_dimension The lower inclusive limit for the dimension - /// \param mas_dimension The upper inclusive limit for the dimension - Dimension(value_type min_dimension, value_type max_dimension); - - /// \brief Construct a dynamic dimension with range [0, ...] - Dimension() = default; - - bool operator==(const Dimension& dimension) const { - return m_dimension == dimension.m_dimension; - } - bool operator!=(const Dimension& dimension) const { - return m_dimension != dimension.m_dimension; - } - /// \brief Check whether this dimension is static. - /// \return `true` if the dimension is static, else `false`. - bool is_static() const { - return m_dimension.size() == 1; - } - /// \brief Check whether this dimension is dynamic. - /// \return `false` if the dimension is static, else `true`. - bool is_dynamic() const { - return m_dimension.size() != 1; - } - /// \brief Convert this dimension to `value_type`. This dimension must be static and - /// non-negative. - /// \throws std::invalid_argument If this dimension is dynamic or negative. - value_type get_length() const; - - value_type get_min_length() const; - value_type get_max_length() const; - - /// \brief Return the interval of valid lengths - const Interval& get_interval() const { - return m_dimension; - } - Interval& get_interval() { - return m_dimension; - } - /// \brief Check whether this dimension represents the same scheme as the argument (both - /// dynamic, or equal). - /// \param dim The other dimension to compare this dimension to. - /// \return `true` if this dimension and `dim` are both dynamic, or if they are both - /// static and equal; otherwise, `false`. - bool same_scheme(const Dimension& dim) const; - /// \brief Try to merge two Dimension objects together. - /// \param[out] dst Reference to write the merged Dimension into. - /// \param d1 First dimension to merge. - /// \param d2 Second dimension to merge. - /// \return `true` if merging succeeds, else `false`. - /// - /// \li If `d1` is dynamic, writes `d2` to `dst` and returns `true`. - /// \li If `d2` is dynamic, writes `d1` to `dst` and returns `true`. - /// \li If `d1` and `d2` are static and equal, writes `d1` to `dst` and returns `true`. - /// \li If `d1` and `d2` are both static and unequal, leaves `dst` unchanged and - /// returns `false`. - static bool merge(Dimension& dst, const Dimension d1, const Dimension d2); - - /// \brief Try to merge two Dimension objects together with implicit broadcasting - /// of unit-sized dimension to non unit-sized dimension - static bool broadcast_merge(Dimension& dst, const Dimension d1, const Dimension d2); - - /// \brief Check whether this dimension is capable of being merged with the argument - /// dimension. - /// \param d The dimension to compare this dimension with. - /// \return `true` if this dimension is compatible with `d`, else `false`. - /// - /// Two dimensions are considered compatible if it is possible to merge them. (See - /// Dimension::merge.) - bool compatible(const Dimension& d) const; - - /// \brief Check whether this dimension is a relaxation of the argument. - /// \param d The dimension to compare this dimension with. - /// \return `true` if this dimension relaxes `d`, else `false`. - /// - /// A dimension `d1` _relaxes_ (or _is a relaxation of_) `d2` if `d1` and `d2` are static - /// and equal, or `d1` is dynamic. - /// - /// `d1.relaxes(d2)` is equivalent to `d2.refines(d1)`. - bool relaxes(const Dimension& d) const; - - /// \brief Check whether this dimension is a refinement of the argument. - /// \param d The dimension to compare this dimension with. - /// \return `true` if this dimension relaxes `d`, else `false`. - /// - /// A dimension `d2` _refines_ (or _is a refinement of_) `d1` if `d1` and `d2` are static - /// and equal, or `d2` is dynamic. - /// - /// `d1.refines(d2)` is equivalent to `d2.relaxes(d1)`. - bool refines(const Dimension& d) const; - - /// \brief Create a dynamic dimension. - /// \return A dynamic dimension. - static Dimension dynamic() { - return Dimension(); - } - /// \brief Addition operator for Dimension. - /// \param dim Right operand for addition. - /// \return Smallest interval dimension enclosing inputs - Dimension operator+(const Dimension& dim) const; - - /// \brief Subtraction operator for Dimension. - /// \param dim Right operand for subtraction. - /// \return Smallest interval dimension enclosing inputs - Dimension operator-(const Dimension& dim) const; - - /// \brief Multiplication operator for Dimension. - /// \param dim Right operand for multiplicaiton. - /// \return Smallest interval containing all "produces" which are 0 if either of `this` or - /// `dim` has length `0`, else unbounded if either is unbounded, else product of lengths. - Dimension operator*(const Dimension& dim) const; - - /// \brief Add-into operator for Dimension. - /// \param dim Right operand for addition. - /// \return A reference to `*this`, after updating `*this` to the value `*this + dim`. - Dimension& operator+=(const Dimension& dim) { - return (*this = *this + dim); - } - /// \brief Multiply-into operator for Dimension. - /// \param dim Right operand for multiplication. - /// \return A reference to `*this`, after updating `*this` to the value `*this * dim`. - Dimension& operator*=(const Dimension& dim) { - return (*this = *this * dim); - } - /// \brief Intersection of dimensions - Dimension operator&(const Dimension& dim) const; - /// \brief Intersection of dimensions - Dimension& operator&=(const Dimension& dim); - -private: - Dimension(const Interval& interval) : m_dimension(interval) {} - - // The actual numerical value of the dimension. - Interval m_dimension{}; -}; - -/// \brief Insert a human-readable representation of a dimension into an output stream. -/// \param str The output stream targeted for insertion. -/// \param dimension The dimension to be inserted into `str`. -/// \return A reference to `str` after insertion. -/// -/// Inserts the string `?` if `dimension` is dynamic; else inserts `dimension.get_length()`. -NGRAPH_API -std::ostream& operator<<(std::ostream& str, const Dimension& dimension); +using ov::Dimension; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/interval.hpp b/ngraph/core/include/ngraph/interval.hpp index ea8089b6e4e23b..f241e572ea4004 100644 --- a/ngraph/core/include/ngraph/interval.hpp +++ b/ngraph/core/include/ngraph/interval.hpp @@ -4,117 +4,8 @@ #pragma once -#include -#include -#include -#include -#include - -#include "ngraph/ngraph_visibility.hpp" +#include "openvino/core/interval.hpp" namespace ngraph { -/// \brief Interval arithmetic -/// -/// An interval is the set of integers from m_min_val through m_max_val. -/// The value s_max acts like infinity. The -/// addition, subtraction, or multiplication of intervals is the smallest interval -/// containing the sums, differences, or products of elements of the two intervals. An empty -/// interval is canonicalized to [s_max, s_max]. -class NGRAPH_API Interval { -public: - using value_type = std::int64_t; - using size_type = std::uint64_t; - - /// \brief Interval of everything - Interval() = default; - /// \brief Copy constructor - Interval(const Interval& interval) = default; - - /// \brief Closed interval {x|min_val <= x <= max_val} - Interval(value_type min_val, value_type max_val); - - /// \brief Single-valued interval; just contains val - Interval(value_type val); - - Interval& operator=(const Interval& interval) = default; - - /// \brief The number of elements in the interval. Zero if max < min. - size_type size() const { - if (m_max_val == s_max) { - return m_min_val == s_max ? 0 : s_max; - } - return m_max_val - m_min_val + 1; - } - /// \brief Returns true if the interval has no elements - bool empty() const { - return m_min_val == s_max; - } - /// \brief the inclusive lower bound of the interval - value_type get_min_val() const { - return m_min_val; - } - /// \brief Set the inclusive lower bound of the interval - void set_min_val(value_type val) { - m_min_val = val; - } - /// \brief the inclusive upper bound of the interval - value_type get_max_val() const { - return m_max_val; - } - /// \brief Set the inclusive upper bound of the interval - void set_max_val(value_type val) { - m_max_val = val; - } - /// \brief True if the upper bound is finite - bool has_upper_bound() const { - return m_max_val != s_max; - } - /// \brief True if min and max bounds match - bool operator==(const Interval& interval) const; - bool operator!=(const Interval& interval) const; - - /// \brief The interval whose elements are a sum of an element from each interval - Interval operator+(const Interval& interval) const; - - /// \brief Extend this interval to sums of elements in this interval and interval - Interval& operator+=(const Interval& interval); - - /// \brief The interval whose elements are a difference of an element from each interval - Interval operator-(const Interval& interval) const; - - /// \brief Extend this interval to differences of elements in this interval and interval - Interval& operator-=(const Interval& interval); - - /// \brief The smallest interval whose elements are a product of an element from each - /// interval - Interval operator*(const Interval& interval) const; - - /// \brief Extend this interval to products of elements in this interval and interval - Interval& operator*=(const Interval& interval); - - /// \brief The interval that is the intersection of this interval and interval - Interval operator&(const Interval& interval) const; - - /// \brief Change this interval to only include elements also in interval - Interval& operator&=(const Interval& interval); - - /// \brief True if this interval includes value - bool contains(value_type value) const { - return m_min_val <= value && value <= m_max_val; - } - /// \brief True if this interval includes all the values in interval - bool contains(const Interval& interval) const; - - /// \brief The value used for no upper bound - static constexpr value_type s_max{std::numeric_limits::max()}; - -protected: - void canonicalize(); - - value_type m_min_val{0}; - value_type m_max_val{s_max}; -}; - -NGRAPH_API -std::ostream& operator<<(std::ostream& str, const Interval& interval); +using ov::Interval; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/partial_shape.hpp b/ngraph/core/include/ngraph/partial_shape.hpp index 118ac6c75b2292..d3bfb76dd4cbb9 100644 --- a/ngraph/core/include/ngraph/partial_shape.hpp +++ b/ngraph/core/include/ngraph/partial_shape.hpp @@ -4,390 +4,10 @@ #pragma once -#include - -#include "ngraph/attribute_adapter.hpp" #include "ngraph/dimension.hpp" -#include "ngraph/op/util/attr_types.hpp" #include "ngraph/rank.hpp" -#include "ngraph/shape.hpp" +#include "openvino/core/partial_shape.hpp" namespace ngraph { -namespace op { -struct AutoBroadcastSpec; -} - -/// \brief Class representing a shape that may be partially or totally dynamic. -/// -/// XXX: THIS CLASS IS EXPERIMENTAL AND THE ENTIRE DESIGN IS SUBJECT TO CHANGE. -/// -/// A PartialShape may have: -/// -/// \li Dynamic rank. (Informal notation: `?`) -/// \li Static rank, but dynamic dimensions on some or all axes. -/// (Informal notation examples: `{1,2,?,4}`, `{?,?,?}`) -/// \li Static rank, and static dimensions on all axes. -/// (Informal notation examples: `{1,2,3,4}`, `{6}`, `{}`) -class NGRAPH_API PartialShape { - using Dimensions = std::vector; - -public: - using iterator = Dimensions::iterator; - using const_iterator = Dimensions::const_iterator; - using reverse_iterator = Dimensions::reverse_iterator; - using const_reverse_iterator = Dimensions::const_reverse_iterator; - - /// \brief Constructs a shape with static rank from an initializer list of Dimension. - /// \param init The Dimension values for the constructed shape. - /// - /// Examples: - /// - /// \code{.cpp} - /// PartialShape s{2,3,4}; // rank=3, all dimensions static - /// PartialShape s{}; // rank=0 - /// PartialShape s{2,Dimension::dynamic(),3}; // rank=3, dimension 1 dynamic - /// \endcode - PartialShape(std::initializer_list init); - - /// \brief Constructs a PartialShape with static rank from a vector of Dimension. - /// \param dimensions The Dimension values for the constructed shape. - PartialShape(std::vector dimensions); - - /// \brief Constructs a PartialShape with static rank from a vector of dimensions values. - /// \param dimensions The Dimension values for the constructed shape. - PartialShape(const std::vector& dimensions); - - /// \brief Constructs a static PartialShape with zero rank (the shape of a scalar). - PartialShape(); - - /// \brief Constructs a static PartialShape from a Shape. - /// \param shape The Shape to convert into PartialShape. - PartialShape(const Shape& shape); - - /// \brief Check if this shape is static. - /// \return `true` if this shape is static, else `false`. - /// - /// A shape is considered static if it has static rank, and all dimensions of the shape - /// are static. - bool is_static() const; - - /// \brief Check if this shape is dynamic. - /// \return `false` if this shape is static, else `true`. - /// - /// A shape is considered static if it has static rank, and all dimensions of the shape - /// are static. - bool is_dynamic() const { - return !is_static(); - } - /// \brief Get the rank of the shape. - /// \return The rank of the shape. This will be Rank::dynamic() if the rank of - /// the shape is dynamic. - Rank rank() const { - return m_rank_is_static ? Rank(m_dimensions.size()) : Rank::dynamic(); - } - /// \brief Construct a PartialShape with the given rank and all dimensions (if any) dynamic. - /// \return A PartialShape with the given rank, and all dimensions (if any) dynamic. - static PartialShape dynamic(Rank r = Rank::dynamic()); - /// \brief Check whether this shape is compatible with the argument, i.e., whether it is - /// possible to merge them. - /// \param s The shape to be checked for compatibility with this shape. - /// \return `true` if this shape is compatible with `s`, else `false`. - /// - /// Two shapes are compatible if - /// \li one or both of them has dynamic rank, or - /// \li both shapes have dynamic and equal rank, and their dimensions are elementwise - /// compatible (see Dimension::compatible()). - bool compatible(const PartialShape& s) const; - - /// \brief Check whether this shape represents the same scheme as the argument. - /// \param s The shape whose scheme is being compared with this shape. - /// \return `true` if this shape represents the same scheme as `s`, else `false`. - /// - /// Two shapes `s1` and `s2` represent the same scheme if - /// \li they both have dynamic rank, or - /// \li they both have static and equal rank `r`, and for every `i` from `0` to `r-1`, - /// `s1[i]` represents the same scheme as `s2[i]` (see Dimension::same_scheme()). - bool same_scheme(const PartialShape& s) const; - - /// \brief Check whether this shape is a relaxation of the argument. - /// \param s The shape which is being compared against this shape. - /// \return `true` if this shape relaxes `s`, else `false`. - /// - /// Intuitively, a PartialShape `s1` is said to _relax_ `s2` (or _is a - /// relaxation_ of `s2`) if it is "more permissive" than `s2`. In other - /// words, `s1` is a relaxation of `s2` if anything you can form by - /// plugging things into the dynamic dimensions of `s2` is also - /// something you can form by plugging things into the dynamic - /// dimensions of `s1`, but not necessarily the other way around. - /// - /// `s1.relaxes(s2)` is equivalent to `s2.refines(s1)`. - /// - /// Formally, PartialShape `s1` is said to _relax_ PartialShape `s2` - /// if: - /// \li For every `i` from `0` to `r-1`, - /// either `s1[i]` contains s2[i]. - bool relaxes(const PartialShape& s) const; - - /// \brief Check whether this shape is a refinement of the argument. - /// \param s The shape which is being compared against this shape. - /// \return `true` if this shape refines `s`, else `false`. - /// - /// Intuitively, a PartialShape `s1` is said to _relax_ `s2` (or _is a - /// relaxation_ of `s2`) if it is "less permissive" than `s2`. In other - /// words, `s1` is a relaxation of `s2` if anything you can form by - /// plugging things into the dynamic dimensions of `s1` is also - /// something you can form by plugging things into the dynamic - /// dimensions of `s2`, but not necessarily the other way around. - /// - /// `s1.refines(s2)` is equivalent to `s2.relaxes(s1)`. - /// - /// Formally, PartialShape `s1` is said to _refine_ PartialShape `s2` - /// if: - /// \li `s2` has dynamic rank, or - /// \li `s1` and `s2` both have static rank `r`, and for every `i` from `0` to `r-1`, - /// either `s2[i]` is dynamic, or `s1[i]` == `s2[i]`. - bool refines(const PartialShape& s) const; - - /// \brief Checks that this shape's rank is compatible with `r`, and, if this shape's - /// rank is dynamic and `r` is static, updates this shape to have a rank of `r` - /// with dimensions all dynamic. - /// \return `true` if this shape's rank is compatible with `r`, else `false`. - bool merge_rank(Rank r); - - /// \brief Convert a static PartialShape to a Shape. - /// \return A new Shape `s` where `s[i] = size_t((*this)[i])`. - /// \throws std::invalid_argument If this PartialShape is dynamic. - Shape to_shape() const; - - /// \brief Returns `true` if all static dimensions of the tensor are non-negative, else - /// `false`. - bool all_non_negative() const; - - /// \brief Index operator for PartialShape. - /// \param i The index of the dimension being selected. - /// \return A reference to the `i`th Dimension of this shape. - const Dimension& operator[](size_t i) const; - /// \brief Index operator for PartialShape. - /// \param i The index of the dimension being selected. - /// \return A reference to the `i`th Dimension of this shape. - Dimension& operator[](size_t i); - /// \brief Returns a vector of the dimensions. This has no meaning if dynamic. - explicit operator std::vector() const { - return m_dimensions; - } - friend NGRAPH_API std::ostream& operator<<(std::ostream& str, const PartialShape& shape); - friend PartialShape operator+(const PartialShape& s1, const PartialShape& s2); - bool operator==(const PartialShape& partial_shape) const; - bool operator!=(const PartialShape& partial_shape) const; - /// Get the max bounding shape - Shape get_max_shape() const; - /// Get the min bounding shape - Shape get_min_shape() const; - /// Get the unique shape - Shape get_shape() const; - - /// \brief Try to merge one shape into another. - /// \param[in,out] dst The shape that `src` will be merged into. - /// \param src The shape that will be merged into `dst`. - /// \return `true` if merging succeeds, else `false`. - /// - /// Merges `src` into `dst`, returning `true` on success and `false` on failure. If - /// `false` is returned, the effect on `dst` is unspecified. - /// - /// To merge two partial shapes `s1` and `s2` is to find the most permissive partial shape - /// `s` that is no more permissive than `s1` or `s2`, if `s` exists. For example: - /// - /// \code - /// merge(?,?) -> ? - /// merge(?,{?,?}) -> {?,?} - /// merge({?,?},{?,?}) -> {?,?} - /// merge({1,2,3,4},?) -> {1,2,3,4} - /// merge({1,2},{1,?}) -> {1,2} - /// merge({1,2,?,?},{1,?,3,?}) -> {1,2,3,?} - /// merge({1,2,3},{1,2,3}) -> {1,2,3} - /// - /// merge({1,?},{2,?}) fails [dimension 0 constraints are inconsistent] - /// merge({?,?},{?,?,?}) fails [ranks are inconsistent] - /// \endcode - /// - /// This function (merge_into) performs the "merge" operation described above on `dst` and - /// `src`, but overwrites `dst` with the result and returns `true` if merging is - /// successful; if merging is unsuccessful, the function returns `false` and may make - /// unspecified changes to `dst`. - static bool merge_into(PartialShape& dst, const PartialShape& src); - - /// \brief Try to merge one shape into another along with implicit broadcasting - static bool broadcast_merge_into(PartialShape& dst, const PartialShape& src, const op::AutoBroadcastSpec& autob); - - /// \brief Returns a read/write iterator that points to the first - /// element in the shape. Iteration is done in ordinary - /// element order. - iterator begin() noexcept { - return m_dimensions.begin(); - } - /// \brief Returns a read-only (constant) iterator that points to the - /// first element in the shape. Iteration is done in ordinary - /// element order. - const_iterator begin() const noexcept { - return cbegin(); - } - /// \brief Returns a read/write iterator that points one past the last - /// element in the shape. Iteration is done in ordinary - /// element order. - iterator end() noexcept { - return m_dimensions.end(); - } - /// \brief Returns a read-only (constant) iterator that points one past - /// the last element in the shape. Iteration is done in ordinary - /// element order. - const_iterator end() const noexcept { - return cend(); - } - /// \brief Returns a read/write reverse iterator that points to the - /// last element in the shape. Iteration is done in reverse - /// element order. - reverse_iterator rbegin() noexcept { - return m_dimensions.rbegin(); - } - /// \brief Returns a read-only (constant) reverse iterator that points - /// to the last element in the shape. Iteration is done in - /// reverse element order. - const_reverse_iterator rbegin() const noexcept { - return crbegin(); - } - /// \brief Returns a read/write reverse iterator that points to one - /// before the first element in the shape. Iteration is done - /// in reverse element order. - reverse_iterator rend() noexcept { - return m_dimensions.rend(); - } - /// \brief Returns a read-only (constant) reverse iterator that points - /// to one before the first element in the shape. Iteration - /// is done in reverse element order. - const_reverse_iterator rend() const noexcept { - return crend(); - } - /// \brief Returns a read-only (constant) iterator that points to the - /// first element in the shape. Iteration is done in ordinary - /// element order. - const_iterator cbegin() const noexcept { - return m_dimensions.cbegin(); - } - /// \brief Returns a read-only (constant) iterator that points one past - /// the last element in the shape. Iteration is done in ordinary - /// element order. - const_iterator cend() const noexcept { - return m_dimensions.cend(); - } - /// \brief Returns a read-only (constant) reverse iterator that points - /// to the last element in the shape. Iteration is done in - /// reverse element order. - const_reverse_iterator crbegin() const noexcept { - return m_dimensions.crbegin(); - } - /// \brief Returns a read-only (constant) reverse iterator that points - /// to one before the first element in the shape. Iteration - /// is done in reverse element order. - const_reverse_iterator crend() const noexcept { - return m_dimensions.crend(); - } - -private: - // Private constructor for PartialShape::dynamic(). - PartialShape(bool rank_is_static, std::vector dimensions); - - // True if the shape's rank is static. - bool m_rank_is_static; - - /// \brief Shape types. The shape type is lazily evaluated by calling the is_static() - /// method. - /// - /// \details It is highly recommended to avoid using the Dimension& operator[](size_t) - /// operator. It sets the shape type to SHAPE_IS_UPDATED and disables shape type caching. - /// Thus, the is_static method will have linear complexity because the shape is not - /// guaranteed to remain static or dynamic. - mutable enum class ShapeType { - SHAPE_IS_UNKNOWN, // The shape type is unknown and should be calculated by checking all - // dimensions. - SHAPE_IS_UPDATED, // User has retained a link to one dimension. Therefore, we can't - // guarantee that the shape will remain static or dynamic, and its - // type will always be evaluated. - SHAPE_IS_STATIC, // The shape type is known and static. Also there are no any retained - // dimensions by non-constant reference. - SHAPE_IS_DYNAMIC // The shape type is dynamic and there are no any retained dimensions - // by non-constant reference. - } m_shape_type{ShapeType::SHAPE_IS_UNKNOWN}; - - // Shape dimensions. This has no meaning if m_rank_is_static is false. - Dimensions m_dimensions; -}; - -/// \brief Elementwise addition of two PartialShape objects. -/// \param s1 Left operand for addition. -/// \param s2 Right operand for addition. -/// \return The result of elementwise adding `s1` to `s2` (see description). -/// \throws std::invalid_argument If `s1` and `s2` have inconsistent ranks. -/// -/// \li If `s1` or `s2` has dynamic rank, returns PartialShape::dynamic(). -/// \li If `s1 and `s2` both have static rank, and their ranks are unequal, throws -/// std::invalid_argument. -/// \li If `s1` and `s2` both have static rank, and their ranks are equal, -/// returns a new shape whose `i`th dimension is `s1[i] + s2[i]`. -PartialShape operator+(const PartialShape& s1, const PartialShape& s2); - -/// \brief Inserts a human-readable representation of a PartialShape into an output stream. -/// \param str The output stream targeted for insertion. -/// \param shape The shape to be inserted into `str`. -/// \return A reference to `str` after insertion. -/// -/// The output to the stream is in "informal" notation. In other words: -/// -/// \li If `shape` has dynamic rank, inserts the string `?`. -/// \li If `shape` has static rank, inserts the string `{`, then inserts each dimension -/// of `shape` into the output stream separated by commas, then inserts `}`. -/// -/// Example: -/// -/// \code{.cpp} -/// PartialShape s1{PartialShape::dynamic())}; -/// PartialShape s2{}; -/// PartialShape s3{1,Dimension::dynamic(),2,3}; -/// PartialShape s4{2,3,4}; -/// std::cout << s1 << std::endl -/// << s2 << std::endl -/// << s3 << std::endl -/// << s4 << std::endl; -/// \endcode -/// -/// Output: -/// -/// \code -/// ? -/// {} -/// {1,?,2,3} -/// {2,3,4} -/// \endcode -NGRAPH_API -std::ostream& operator<<(std::ostream& str, const PartialShape& shape); - -template <> -class NGRAPH_API AttributeAdapter : public ValueAccessor> { -public: - AttributeAdapter(PartialShape& value) : m_ref(value) {} - - const std::vector& get() override; - void set(const std::vector& value) override; - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } - operator PartialShape&() { - return m_ref; - } - -protected: - PartialShape& m_ref; - std::vector m_buffer; - bool m_buffer_valid{false}; -}; +using ov::PartialShape; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/rank.hpp b/ngraph/core/include/ngraph/rank.hpp index 3ca58a4c243524..2d17092dfb30e3 100644 --- a/ngraph/core/include/ngraph/rank.hpp +++ b/ngraph/core/include/ngraph/rank.hpp @@ -5,11 +5,8 @@ #pragma once #include "ngraph/dimension.hpp" +#include "openvino/core/rank.hpp" namespace ngraph { -/// \brief Alias for Dimension, used when the value represents the number of axes in a shape, -/// rather than the size of one dimension in a shape. -/// -/// XXX: THIS TYPE IS EXPERIMENTAL AND THE ENTIRE DESIGN IS SUBJECT TO CHANGE. -using Rank = Dimension; +using ov::Rank; } // namespace ngraph diff --git a/ngraph/core/include/openvino/core/dimension.hpp b/ngraph/core/include/openvino/core/dimension.hpp new file mode 100644 index 00000000000000..e54232677540fd --- /dev/null +++ b/ngraph/core/include/openvino/core/dimension.hpp @@ -0,0 +1,172 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" +#include "openvino/core/interval.hpp" + +namespace ov { +/// \brief Class representing a dimension, which may be dynamic (undetermined until runtime), +/// in a shape or shape-like object. +/// +/// Static dimensions may be implicitly converted from value_type. A dynamic dimension is +/// constructed with Dimension() or Dimension::dynamic(). +class OPENVINO_API Dimension { +public: + using value_type = int64_t; + + /// \brief Construct a static dimension. + /// \param dimension Value of the dimension. + Dimension(value_type dimension); + + /// \brief Construct a dynamic dimension with bounded range + /// \param min_dimension The lower inclusive limit for the dimension + /// \param mas_dimension The upper inclusive limit for the dimension + Dimension(value_type min_dimension, value_type max_dimension); + + /// \brief Construct a dynamic dimension with range [0, ...] + Dimension() = default; + + bool operator==(const Dimension& dimension) const { + return m_dimension == dimension.m_dimension; + } + bool operator!=(const Dimension& dimension) const { + return m_dimension != dimension.m_dimension; + } + /// \brief Check whether this dimension is static. + /// \return `true` if the dimension is static, else `false`. + bool is_static() const { + return m_dimension.size() == 1; + } + /// \brief Check whether this dimension is dynamic. + /// \return `false` if the dimension is static, else `true`. + bool is_dynamic() const { + return m_dimension.size() != 1; + } + /// \brief Convert this dimension to `value_type`. This dimension must be static and + /// non-negative. + /// \throws std::invalid_argument If this dimension is dynamic or negative. + value_type get_length() const; + + value_type get_min_length() const; + value_type get_max_length() const; + + /// \brief Return the interval of valid lengths + const Interval& get_interval() const { + return m_dimension; + } + Interval& get_interval() { + return m_dimension; + } + /// \brief Check whether this dimension represents the same scheme as the argument (both + /// dynamic, or equal). + /// \param dim The other dimension to compare this dimension to. + /// \return `true` if this dimension and `dim` are both dynamic, or if they are both + /// static and equal; otherwise, `false`. + bool same_scheme(const Dimension& dim) const; + /// \brief Try to merge two Dimension objects together. + /// \param[out] dst Reference to write the merged Dimension into. + /// \param d1 First dimension to merge. + /// \param d2 Second dimension to merge. + /// \return `true` if merging succeeds, else `false`. + /// + /// \li If `d1` is dynamic, writes `d2` to `dst` and returns `true`. + /// \li If `d2` is dynamic, writes `d1` to `dst` and returns `true`. + /// \li If `d1` and `d2` are static and equal, writes `d1` to `dst` and returns `true`. + /// \li If `d1` and `d2` are both static and unequal, leaves `dst` unchanged and + /// returns `false`. + static bool merge(Dimension& dst, const Dimension d1, const Dimension d2); + + /// \brief Try to merge two Dimension objects together with implicit broadcasting + /// of unit-sized dimension to non unit-sized dimension + static bool broadcast_merge(Dimension& dst, const Dimension d1, const Dimension d2); + + /// \brief Check whether this dimension is capable of being merged with the argument + /// dimension. + /// \param d The dimension to compare this dimension with. + /// \return `true` if this dimension is compatible with `d`, else `false`. + /// + /// Two dimensions are considered compatible if it is possible to merge them. (See + /// Dimension::merge.) + bool compatible(const Dimension& d) const; + + /// \brief Check whether this dimension is a relaxation of the argument. + /// \param d The dimension to compare this dimension with. + /// \return `true` if this dimension relaxes `d`, else `false`. + /// + /// A dimension `d1` _relaxes_ (or _is a relaxation of_) `d2` if `d1` and `d2` are static + /// and equal, or `d1` is dynamic. + /// + /// `d1.relaxes(d2)` is equivalent to `d2.refines(d1)`. + bool relaxes(const Dimension& d) const; + + /// \brief Check whether this dimension is a refinement of the argument. + /// \param d The dimension to compare this dimension with. + /// \return `true` if this dimension relaxes `d`, else `false`. + /// + /// A dimension `d2` _refines_ (or _is a refinement of_) `d1` if `d1` and `d2` are static + /// and equal, or `d2` is dynamic. + /// + /// `d1.refines(d2)` is equivalent to `d2.relaxes(d1)`. + bool refines(const Dimension& d) const; + + /// \brief Create a dynamic dimension. + /// \return A dynamic dimension. + static Dimension dynamic() { + return Dimension(); + } + /// \brief Addition operator for Dimension. + /// \param dim Right operand for addition. + /// \return Smallest interval dimension enclosing inputs + Dimension operator+(const Dimension& dim) const; + + /// \brief Subtraction operator for Dimension. + /// \param dim Right operand for subtraction. + /// \return Smallest interval dimension enclosing inputs + Dimension operator-(const Dimension& dim) const; + + /// \brief Multiplication operator for Dimension. + /// \param dim Right operand for multiplicaiton. + /// \return Smallest interval containing all "produces" which are 0 if either of `this` or + /// `dim` has length `0`, else unbounded if either is unbounded, else product of lengths. + Dimension operator*(const Dimension& dim) const; + + /// \brief Add-into operator for Dimension. + /// \param dim Right operand for addition. + /// \return A reference to `*this`, after updating `*this` to the value `*this + dim`. + Dimension& operator+=(const Dimension& dim) { + return (*this = *this + dim); + } + /// \brief Multiply-into operator for Dimension. + /// \param dim Right operand for multiplication. + /// \return A reference to `*this`, after updating `*this` to the value `*this * dim`. + Dimension& operator*=(const Dimension& dim) { + return (*this = *this * dim); + } + /// \brief Intersection of dimensions + Dimension operator&(const Dimension& dim) const; + /// \brief Intersection of dimensions + Dimension& operator&=(const Dimension& dim); + +private: + Dimension(const Interval& interval) : m_dimension(interval) {} + + // The actual numerical value of the dimension. + Interval m_dimension{}; +}; + +/// \brief Insert a human-readable representation of a dimension into an output stream. +/// \param str The output stream targeted for insertion. +/// \param dimension The dimension to be inserted into `str`. +/// \return A reference to `str` after insertion. +/// +/// Inserts the string `?` if `dimension` is dynamic; else inserts `dimension.get_length()`. +OPENVINO_API +std::ostream& operator<<(std::ostream& str, const Dimension& dimension); +} // namespace ov diff --git a/ngraph/core/include/openvino/core/interval.hpp b/ngraph/core/include/openvino/core/interval.hpp new file mode 100644 index 00000000000000..f1aa9111ea9314 --- /dev/null +++ b/ngraph/core/include/openvino/core/interval.hpp @@ -0,0 +1,120 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" + +namespace ov { +/// \brief Interval arithmetic +/// +/// An interval is the set of integers from m_min_val through m_max_val. +/// The value s_max acts like infinity. The +/// addition, subtraction, or multiplication of intervals is the smallest interval +/// containing the sums, differences, or products of elements of the two intervals. An empty +/// interval is canonicalized to [s_max, s_max]. +class OPENVINO_API Interval { +public: + using value_type = std::int64_t; + using size_type = std::uint64_t; + + /// \brief Interval of everything + Interval() = default; + /// \brief Copy constructor + Interval(const Interval& interval) = default; + + /// \brief Closed interval {x|min_val <= x <= max_val} + Interval(value_type min_val, value_type max_val); + + /// \brief Single-valued interval; just contains val + Interval(value_type val); + + Interval& operator=(const Interval& interval) = default; + + /// \brief The number of elements in the interval. Zero if max < min. + size_type size() const { + if (m_max_val == s_max) { + return m_min_val == s_max ? 0 : s_max; + } + return m_max_val - m_min_val + 1; + } + /// \brief Returns true if the interval has no elements + bool empty() const { + return m_min_val == s_max; + } + /// \brief the inclusive lower bound of the interval + value_type get_min_val() const { + return m_min_val; + } + /// \brief Set the inclusive lower bound of the interval + void set_min_val(value_type val) { + m_min_val = val; + } + /// \brief the inclusive upper bound of the interval + value_type get_max_val() const { + return m_max_val; + } + /// \brief Set the inclusive upper bound of the interval + void set_max_val(value_type val) { + m_max_val = val; + } + /// \brief True if the upper bound is finite + bool has_upper_bound() const { + return m_max_val != s_max; + } + /// \brief True if min and max bounds match + bool operator==(const Interval& interval) const; + bool operator!=(const Interval& interval) const; + + /// \brief The interval whose elements are a sum of an element from each interval + Interval operator+(const Interval& interval) const; + + /// \brief Extend this interval to sums of elements in this interval and interval + Interval& operator+=(const Interval& interval); + + /// \brief The interval whose elements are a difference of an element from each interval + Interval operator-(const Interval& interval) const; + + /// \brief Extend this interval to differences of elements in this interval and interval + Interval& operator-=(const Interval& interval); + + /// \brief The smallest interval whose elements are a product of an element from each + /// interval + Interval operator*(const Interval& interval) const; + + /// \brief Extend this interval to products of elements in this interval and interval + Interval& operator*=(const Interval& interval); + + /// \brief The interval that is the intersection of this interval and interval + Interval operator&(const Interval& interval) const; + + /// \brief Change this interval to only include elements also in interval + Interval& operator&=(const Interval& interval); + + /// \brief True if this interval includes value + bool contains(value_type value) const { + return m_min_val <= value && value <= m_max_val; + } + /// \brief True if this interval includes all the values in interval + bool contains(const Interval& interval) const; + + /// \brief The value used for no upper bound + static constexpr value_type s_max{std::numeric_limits::max()}; + +protected: + void canonicalize(); + + value_type m_min_val{0}; + value_type m_max_val{s_max}; +}; + +OPENVINO_API +std::ostream& operator<<(std::ostream& str, const Interval& interval); +} // namespace ov diff --git a/ngraph/core/include/openvino/core/partial_shape.hpp b/ngraph/core/include/openvino/core/partial_shape.hpp new file mode 100644 index 00000000000000..34b59d7ab47016 --- /dev/null +++ b/ngraph/core/include/openvino/core/partial_shape.hpp @@ -0,0 +1,401 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "ngraph/attribute_adapter.hpp" +#include "ngraph/op/util/attr_types.hpp" +#include "ngraph/shape.hpp" +#include "openvino/core/dimension.hpp" +#include "openvino/core/rank.hpp" + +namespace ngraph { +namespace op { +struct AutoBroadcastSpec; +} + +} // namespace ngraph + +namespace ov { + +/// \brief Class representing a shape that may be partially or totally dynamic. +/// +/// +/// A PartialShape may have: +/// +/// \li Dynamic rank. (Informal notation: `?`) +/// \li Static rank, but dynamic dimensions on some or all axes. +/// (Informal notation examples: `{1,2,?,4}`, `{?,?,?}`) +/// \li Static rank, and static dimensions on all axes. +/// (Informal notation examples: `{1,2,3,4}`, `{6}`, `{}`) +class OPENVINO_API PartialShape { + using Dimensions = std::vector; + +public: + using iterator = Dimensions::iterator; + using const_iterator = Dimensions::const_iterator; + using reverse_iterator = Dimensions::reverse_iterator; + using const_reverse_iterator = Dimensions::const_reverse_iterator; + + /// \brief Constructs a shape with static rank from an initializer list of Dimension. + /// \param init The Dimension values for the constructed shape. + /// + /// Examples: + /// + /// \code{.cpp} + /// PartialShape s{2,3,4}; // rank=3, all dimensions static + /// PartialShape s{}; // rank=0 + /// PartialShape s{2,Dimension::dynamic(),3}; // rank=3, dimension 1 dynamic + /// \endcode + PartialShape(std::initializer_list init); + + /// \brief Constructs a PartialShape with static rank from a vector of Dimension. + /// \param dimensions The Dimension values for the constructed shape. + PartialShape(std::vector dimensions); + + /// \brief Constructs a PartialShape with static rank from a vector of dimensions values. + /// \param dimensions The Dimension values for the constructed shape. + PartialShape(const std::vector& dimensions); + + /// \brief Constructs a static PartialShape with zero rank (the shape of a scalar). + PartialShape(); + + /// \brief Constructs a static PartialShape from a Shape. + /// \param shape The Shape to convert into PartialShape. + PartialShape(const ngraph::Shape& shape); + + /// \brief Check if this shape is static. + /// \return `true` if this shape is static, else `false`. + /// + /// A shape is considered static if it has static rank, and all dimensions of the shape + /// are static. + bool is_static() const; + + /// \brief Check if this shape is dynamic. + /// \return `false` if this shape is static, else `true`. + /// + /// A shape is considered static if it has static rank, and all dimensions of the shape + /// are static. + bool is_dynamic() const { + return !is_static(); + } + /// \brief Get the rank of the shape. + /// \return The rank of the shape. This will be Rank::dynamic() if the rank of + /// the shape is dynamic. + Rank rank() const { + return m_rank_is_static ? Rank(m_dimensions.size()) : Rank::dynamic(); + } + /// \brief Construct a PartialShape with the given rank and all dimensions (if any) dynamic. + /// \return A PartialShape with the given rank, and all dimensions (if any) dynamic. + static PartialShape dynamic(Rank r = Rank::dynamic()); + /// \brief Check whether this shape is compatible with the argument, i.e., whether it is + /// possible to merge them. + /// \param s The shape to be checked for compatibility with this shape. + /// \return `true` if this shape is compatible with `s`, else `false`. + /// + /// Two shapes are compatible if + /// \li one or both of them has dynamic rank, or + /// \li both shapes have dynamic and equal rank, and their dimensions are elementwise + /// compatible (see Dimension::compatible()). + bool compatible(const PartialShape& s) const; + + /// \brief Check whether this shape represents the same scheme as the argument. + /// \param s The shape whose scheme is being compared with this shape. + /// \return `true` if this shape represents the same scheme as `s`, else `false`. + /// + /// Two shapes `s1` and `s2` represent the same scheme if + /// \li they both have dynamic rank, or + /// \li they both have static and equal rank `r`, and for every `i` from `0` to `r-1`, + /// `s1[i]` represents the same scheme as `s2[i]` (see Dimension::same_scheme()). + bool same_scheme(const PartialShape& s) const; + + /// \brief Check whether this shape is a relaxation of the argument. + /// \param s The shape which is being compared against this shape. + /// \return `true` if this shape relaxes `s`, else `false`. + /// + /// Intuitively, a PartialShape `s1` is said to _relax_ `s2` (or _is a + /// relaxation_ of `s2`) if it is "more permissive" than `s2`. In other + /// words, `s1` is a relaxation of `s2` if anything you can form by + /// plugging things into the dynamic dimensions of `s2` is also + /// something you can form by plugging things into the dynamic + /// dimensions of `s1`, but not necessarily the other way around. + /// + /// `s1.relaxes(s2)` is equivalent to `s2.refines(s1)`. + /// + /// Formally, PartialShape `s1` is said to _relax_ PartialShape `s2` + /// if: + /// \li For every `i` from `0` to `r-1`, + /// either `s1[i]` contains s2[i]. + bool relaxes(const PartialShape& s) const; + + /// \brief Check whether this shape is a refinement of the argument. + /// \param s The shape which is being compared against this shape. + /// \return `true` if this shape refines `s`, else `false`. + /// + /// Intuitively, a PartialShape `s1` is said to _relax_ `s2` (or _is a + /// relaxation_ of `s2`) if it is "less permissive" than `s2`. In other + /// words, `s1` is a relaxation of `s2` if anything you can form by + /// plugging things into the dynamic dimensions of `s1` is also + /// something you can form by plugging things into the dynamic + /// dimensions of `s2`, but not necessarily the other way around. + /// + /// `s1.refines(s2)` is equivalent to `s2.relaxes(s1)`. + /// + /// Formally, PartialShape `s1` is said to _refine_ PartialShape `s2` + /// if: + /// \li `s2` has dynamic rank, or + /// \li `s1` and `s2` both have static rank `r`, and for every `i` from `0` to `r-1`, + /// either `s2[i]` is dynamic, or `s1[i]` == `s2[i]`. + bool refines(const PartialShape& s) const; + + /// \brief Checks that this shape's rank is compatible with `r`, and, if this shape's + /// rank is dynamic and `r` is static, updates this shape to have a rank of `r` + /// with dimensions all dynamic. + /// \return `true` if this shape's rank is compatible with `r`, else `false`. + bool merge_rank(Rank r); + + /// \brief Convert a static PartialShape to a Shape. + /// \return A new Shape `s` where `s[i] = size_t((*this)[i])`. + /// \throws std::invalid_argument If this PartialShape is dynamic. + ngraph::Shape to_shape() const; + + /// \brief Returns `true` if all static dimensions of the tensor are non-negative, else + /// `false`. + bool all_non_negative() const; + + /// \brief Index operator for PartialShape. + /// \param i The index of the dimension being selected. + /// \return A reference to the `i`th Dimension of this shape. + const Dimension& operator[](size_t i) const; + /// \brief Index operator for PartialShape. + /// \param i The index of the dimension being selected. + /// \return A reference to the `i`th Dimension of this shape. + Dimension& operator[](size_t i); + /// \brief Returns a vector of the dimensions. This has no meaning if dynamic. + explicit operator std::vector() const { + return m_dimensions; + } + friend OPENVINO_API std::ostream& operator<<(std::ostream& str, const PartialShape& shape); + friend PartialShape operator+(const PartialShape& s1, const PartialShape& s2); + bool operator==(const PartialShape& partial_shape) const; + bool operator!=(const PartialShape& partial_shape) const; + /// Get the max bounding shape + ngraph::Shape get_max_shape() const; + /// Get the min bounding shape + ngraph::Shape get_min_shape() const; + /// Get the unique shape + ngraph::Shape get_shape() const; + + /// \brief Try to merge one shape into another. + /// \param[in,out] dst The shape that `src` will be merged into. + /// \param src The shape that will be merged into `dst`. + /// \return `true` if merging succeeds, else `false`. + /// + /// Merges `src` into `dst`, returning `true` on success and `false` on failure. If + /// `false` is returned, the effect on `dst` is unspecified. + /// + /// To merge two partial shapes `s1` and `s2` is to find the most permissive partial shape + /// `s` that is no more permissive than `s1` or `s2`, if `s` exists. For example: + /// + /// \code + /// merge(?,?) -> ? + /// merge(?,{?,?}) -> {?,?} + /// merge({?,?},{?,?}) -> {?,?} + /// merge({1,2,3,4},?) -> {1,2,3,4} + /// merge({1,2},{1,?}) -> {1,2} + /// merge({1,2,?,?},{1,?,3,?}) -> {1,2,3,?} + /// merge({1,2,3},{1,2,3}) -> {1,2,3} + /// + /// merge({1,?},{2,?}) fails [dimension 0 constraints are inconsistent] + /// merge({?,?},{?,?,?}) fails [ranks are inconsistent] + /// \endcode + /// + /// This function (merge_into) performs the "merge" operation described above on `dst` and + /// `src`, but overwrites `dst` with the result and returns `true` if merging is + /// successful; if merging is unsuccessful, the function returns `false` and may make + /// unspecified changes to `dst`. + static bool merge_into(PartialShape& dst, const PartialShape& src); + + /// \brief Try to merge one shape into another along with implicit broadcasting + static bool broadcast_merge_into(PartialShape& dst, + const PartialShape& src, + const ngraph::op::AutoBroadcastSpec& autob); + + /// \brief Returns a read/write iterator that points to the first + /// element in the shape. Iteration is done in ordinary + /// element order. + iterator begin() noexcept { + return m_dimensions.begin(); + } + /// \brief Returns a read-only (constant) iterator that points to the + /// first element in the shape. Iteration is done in ordinary + /// element order. + const_iterator begin() const noexcept { + return cbegin(); + } + /// \brief Returns a read/write iterator that points one past the last + /// element in the shape. Iteration is done in ordinary + /// element order. + iterator end() noexcept { + return m_dimensions.end(); + } + /// \brief Returns a read-only (constant) iterator that points one past + /// the last element in the shape. Iteration is done in ordinary + /// element order. + const_iterator end() const noexcept { + return cend(); + } + /// \brief Returns a read/write reverse iterator that points to the + /// last element in the shape. Iteration is done in reverse + /// element order. + reverse_iterator rbegin() noexcept { + return m_dimensions.rbegin(); + } + /// \brief Returns a read-only (constant) reverse iterator that points + /// to the last element in the shape. Iteration is done in + /// reverse element order. + const_reverse_iterator rbegin() const noexcept { + return crbegin(); + } + /// \brief Returns a read/write reverse iterator that points to one + /// before the first element in the shape. Iteration is done + /// in reverse element order. + reverse_iterator rend() noexcept { + return m_dimensions.rend(); + } + /// \brief Returns a read-only (constant) reverse iterator that points + /// to one before the first element in the shape. Iteration + /// is done in reverse element order. + const_reverse_iterator rend() const noexcept { + return crend(); + } + /// \brief Returns a read-only (constant) iterator that points to the + /// first element in the shape. Iteration is done in ordinary + /// element order. + const_iterator cbegin() const noexcept { + return m_dimensions.cbegin(); + } + /// \brief Returns a read-only (constant) iterator that points one past + /// the last element in the shape. Iteration is done in ordinary + /// element order. + const_iterator cend() const noexcept { + return m_dimensions.cend(); + } + /// \brief Returns a read-only (constant) reverse iterator that points + /// to the last element in the shape. Iteration is done in + /// reverse element order. + const_reverse_iterator crbegin() const noexcept { + return m_dimensions.crbegin(); + } + /// \brief Returns a read-only (constant) reverse iterator that points + /// to one before the first element in the shape. Iteration + /// is done in reverse element order. + const_reverse_iterator crend() const noexcept { + return m_dimensions.crend(); + } + +private: + // Private constructor for PartialShape::dynamic(). + PartialShape(bool rank_is_static, std::vector dimensions); + + // True if the shape's rank is static. + bool m_rank_is_static; + + /// \brief Shape types. The shape type is lazily evaluated by calling the is_static() + /// method. + /// + /// \details It is highly recommended to avoid using the Dimension& operator[](size_t) + /// operator. It sets the shape type to SHAPE_IS_UPDATED and disables shape type caching. + /// Thus, the is_static method will have linear complexity because the shape is not + /// guaranteed to remain static or dynamic. + mutable enum class ShapeType { + SHAPE_IS_UNKNOWN, // The shape type is unknown and should be calculated by checking all + // dimensions. + SHAPE_IS_UPDATED, // User has retained a link to one dimension. Therefore, we can't + // guarantee that the shape will remain static or dynamic, and its + // type will always be evaluated. + SHAPE_IS_STATIC, // The shape type is known and static. Also there are no any retained + // dimensions by non-constant reference. + SHAPE_IS_DYNAMIC // The shape type is dynamic and there are no any retained dimensions + // by non-constant reference. + } m_shape_type{ShapeType::SHAPE_IS_UNKNOWN}; + + // Shape dimensions. This has no meaning if m_rank_is_static is false. + Dimensions m_dimensions; +}; + +/// \brief Elementwise addition of two PartialShape objects. +/// \param s1 Left operand for addition. +/// \param s2 Right operand for addition. +/// \return The result of elementwise adding `s1` to `s2` (see description). +/// \throws std::invalid_argument If `s1` and `s2` have inconsistent ranks. +/// +/// \li If `s1` or `s2` has dynamic rank, returns PartialShape::dynamic(). +/// \li If `s1 and `s2` both have static rank, and their ranks are unequal, throws +/// std::invalid_argument. +/// \li If `s1` and `s2` both have static rank, and their ranks are equal, +/// returns a new shape whose `i`th dimension is `s1[i] + s2[i]`. +PartialShape operator+(const PartialShape& s1, const PartialShape& s2); + +/// \brief Inserts a human-readable representation of a PartialShape into an output stream. +/// \param str The output stream targeted for insertion. +/// \param shape The shape to be inserted into `str`. +/// \return A reference to `str` after insertion. +/// +/// The output to the stream is in "informal" notation. In other words: +/// +/// \li If `shape` has dynamic rank, inserts the string `?`. +/// \li If `shape` has static rank, inserts the string `{`, then inserts each dimension +/// of `shape` into the output stream separated by commas, then inserts `}`. +/// +/// Example: +/// +/// \code{.cpp} +/// PartialShape s1{PartialShape::dynamic())}; +/// PartialShape s2{}; +/// PartialShape s3{1,Dimension::dynamic(),2,3}; +/// PartialShape s4{2,3,4}; +/// std::cout << s1 << std::endl +/// << s2 << std::endl +/// << s3 << std::endl +/// << s4 << std::endl; +/// \endcode +/// +/// Output: +/// +/// \code +/// ? +/// {} +/// {1,?,2,3} +/// {2,3,4} +/// \endcode +OPENVINO_API +std::ostream& operator<<(std::ostream& str, const PartialShape& shape); + +} // namespace ov +namespace ngraph { + +template <> +class OPENVINO_API AttributeAdapter : public ValueAccessor> { +public: + AttributeAdapter(ov::PartialShape& value) : m_ref(value) {} + + const std::vector& get() override; + void set(const std::vector& value) override; + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } + operator ov::PartialShape&() { + return m_ref; + } + +protected: + ov::PartialShape& m_ref; + std::vector m_buffer; + bool m_buffer_valid{false}; +}; +} // namespace ngraph diff --git a/ngraph/core/include/openvino/core/rank.hpp b/ngraph/core/include/openvino/core/rank.hpp new file mode 100644 index 00000000000000..dc8e0fd952da6e --- /dev/null +++ b/ngraph/core/include/openvino/core/rank.hpp @@ -0,0 +1,14 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/core/dimension.hpp" + +namespace ov { +/// \brief Alias for Dimension, used when the value represents the number of axes in a shape, +/// rather than the size of one dimension in a shape. +/// +using Rank = Dimension; +} // namespace ov diff --git a/ngraph/core/src/dimension.cpp b/ngraph/core/src/dimension.cpp index 8317a391537c8f..84b156ae7b4da3 100644 --- a/ngraph/core/src/dimension.cpp +++ b/ngraph/core/src/dimension.cpp @@ -11,7 +11,7 @@ using namespace ngraph; -std::ostream& ngraph::operator<<(std::ostream& str, const Dimension& dimension) { +std::ostream& ov::operator<<(std::ostream& str, const Dimension& dimension) { if (dimension.is_static()) { return str << dimension.get_length(); } else if (dimension.get_interval().has_upper_bound()) { diff --git a/ngraph/core/src/interval.cpp b/ngraph/core/src/interval.cpp index ff021843051901..469132f3576ad9 100644 --- a/ngraph/core/src/interval.cpp +++ b/ngraph/core/src/interval.cpp @@ -111,8 +111,7 @@ bool Interval::contains(const Interval& interval) const { constexpr Interval::value_type Interval::s_max; -namespace ngraph { -std::ostream& operator<<(std::ostream& str, const Interval& interval) { +std::ostream& ov::operator<<(std::ostream& str, const Interval& interval) { str << "Interval(" << interval.get_min_val() << ", "; auto max_val = interval.get_max_val(); if (max_val == Interval::s_max) { @@ -122,4 +121,3 @@ std::ostream& operator<<(std::ostream& str, const Interval& interval) { } return str << ")"; } -} // namespace ngraph diff --git a/ngraph/core/src/partial_shape.cpp b/ngraph/core/src/partial_shape.cpp index 28bd44767cfc01..9803d84e93b9eb 100644 --- a/ngraph/core/src/partial_shape.cpp +++ b/ngraph/core/src/partial_shape.cpp @@ -107,7 +107,7 @@ Shape ngraph::PartialShape::get_shape() const { return shape; } -PartialShape ngraph::operator+(const PartialShape& s1, const PartialShape& s2) { +PartialShape ov::operator+(const PartialShape& s1, const PartialShape& s2) { if (s1.rank().is_dynamic() || s2.rank().is_dynamic()) { return PartialShape::dynamic(); } @@ -124,7 +124,7 @@ PartialShape ngraph::operator+(const PartialShape& s1, const PartialShape& s2) { return result; } -std::ostream& ngraph::operator<<(std::ostream& str, const PartialShape& shape) { +std::ostream& ov::operator<<(std::ostream& str, const PartialShape& shape) { if (shape.m_rank_is_static) { str << "{"; bool first = true; From 70b3fbd5660b423ab0a5a1d53a836b7b9c3dbe9c Mon Sep 17 00:00:00 2001 From: Eugeny Volosenkov Date: Thu, 19 Aug 2021 10:13:21 +0300 Subject: [PATCH 027/102] Mo implementation for If with tf extractor (#6662) * Add tf2.x impl for If * Fix ir_engine * Fix opset * Fix BOM file * Added new test * Fix comments * Add subgraph_utils * Fix comments * Fix transform * code refactoring * Fix description * rewrite support for empty tensor in if * added onnx extractor * delete onnx_if * fix bug with fake_outputs * Fix test * Fix control_flow and fix commentaries * create method results_mapping_and_finding_fake_outputs(output_nodes_in_subgraph, --- model-optimizer/automation/package_BOM.txt | 4 + model-optimizer/extensions/front/tf/if_ext.py | 69 ++++ .../extensions/front/tf/while_ext.py | 103 +----- model-optimizer/extensions/load/tf/loader.py | 8 +- model-optimizer/extensions/ops/If.py | 328 ++++++++++++++++++ .../mo/front/tf/extractors/subgraph_utils.py | 108 ++++++ model-optimizer/mo/pipeline/common.py | 3 +- .../mo/utils/ir_engine/ir_engine.py | 87 +++-- .../utils/ir_reader/extenders/if_extender.py | 41 +++ .../extensions/load/tf/loader_test.py | 3 +- .../unit_tests/extensions/ops/If_test.py | 127 +++++++ 11 files changed, 751 insertions(+), 130 deletions(-) create mode 100644 model-optimizer/extensions/front/tf/if_ext.py create mode 100644 model-optimizer/extensions/ops/If.py create mode 100644 model-optimizer/mo/front/tf/extractors/subgraph_utils.py create mode 100644 model-optimizer/mo/utils/ir_reader/extenders/if_extender.py create mode 100644 model-optimizer/unit_tests/extensions/ops/If_test.py diff --git a/model-optimizer/automation/package_BOM.txt b/model-optimizer/automation/package_BOM.txt index a7cedc9af2695d..7ab49918925cc4 100644 --- a/model-optimizer/automation/package_BOM.txt +++ b/model-optimizer/automation/package_BOM.txt @@ -436,6 +436,7 @@ extensions/front/tf/GatherTree_ext.py extensions/front/tf/GNMT_DynamicSequenceLengths.py extensions/front/tf/identity_ext.py extensions/front/tf/identityN_to_identity.py +extensions/front/tf/if_ext.py extensions/front/tf/InterpolateTransposes.py extensions/front/tf/IteratorGetNext_ext.py extensions/front/tf/log_softmax_ext.py @@ -701,6 +702,7 @@ extensions/ops/GRU.py extensions/ops/GRUCell.py extensions/ops/hard_sigmoid.py extensions/ops/identity.py +extensions/ops/If.py extensions/ops/instance_normalization.py extensions/ops/interp.py extensions/ops/interpolate.py @@ -927,6 +929,7 @@ mo/front/tf/extractors/native_tf.py mo/front/tf/extractors/pack.py mo/front/tf/extractors/random_uniform.py mo/front/tf/extractors/strided_slice.py +mo/front/tf/extractors/subgraph_utils.py mo/front/tf/extractors/utils.py mo/front/tf/graph_utils.py mo/front/tf/loader.py @@ -1050,6 +1053,7 @@ mo/utils/ir_reader/extenders/experimental_extender.py mo/utils/ir_reader/extenders/ExtractImagePatches_extender.py mo/utils/ir_reader/extenders/fakequantize_extender.py mo/utils/ir_reader/extenders/GRUCell_extender.py +mo/utils/ir_reader/extenders/if_extender.py mo/utils/ir_reader/extenders/interpolate_extender.py mo/utils/ir_reader/extenders/loop_extender.py mo/utils/ir_reader/extenders/LSTMCell_extender.py diff --git a/model-optimizer/extensions/front/tf/if_ext.py b/model-optimizer/extensions/front/tf/if_ext.py new file mode 100644 index 00000000000000..2389c1c19a3c83 --- /dev/null +++ b/model-optimizer/extensions/front/tf/if_ext.py @@ -0,0 +1,69 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +from extensions.ops.If import If +from extensions.ops.parameter import Parameter +from mo.front.common.register_custom_ops import check_for_duplicates +from mo.front.extractor import FrontExtractorOp, extract_node_attrs +from mo.front.tf.extractor import tf_op_extractor, tf_op_extractors +from mo.front.tf.extractors.subgraph_utils import update_body_graph, convert_graph_inputs_to_parameters, \ + get_graph_proto, create_internal_graph +from mo.graph.graph import Node, Graph + + +def extract_if(cls, if_node: Node): + If.update_node_stat(if_node, {}) + + # check that required body and condition functions exist in the graph library + main_graph = if_node.graph + then_graph_proto = get_graph_proto(main_graph, 'then_branch', if_node) + else_graph_proto = get_graph_proto(main_graph, 'else_branch', if_node) + + then_graph = create_internal_graph(main_graph) + if_node['then_graph'] = then_graph + + else_graph = create_internal_graph(main_graph) + if_node['else_graph'] = else_graph + + # create Parameter nodes for the then/else graphs + for input_index, (body_graph, body_graph_proto) in enumerate(zip((then_graph, else_graph), (then_graph_proto, + else_graph_proto))): + + body_parameters, body_parameter_names = convert_graph_inputs_to_parameters(body_graph, body_graph_proto) + + # update the If body graph with the body function graph + body_results = [] + update_body_graph(body_graph, body_graph_proto, body_parameter_names, body_results) + + body_graph.stage = 'front' + + # connect external input ports with body parameter nodes except input with condition + for idx in range(0, len(body_parameters)): + If.connect_body_input(if_node, not input_index, idx + 1, body_parameters[idx]) + + # connect body outputs with If operation output ports + for idx in range(len(body_results)): + If.connect_body_output(if_node, not input_index, idx, body_results[idx]) + + # run function to parse body nodes attributes similar to the main graph + extract_node_attrs(body_graph, lambda node: tf_op_extractor(node, check_for_duplicates(tf_op_extractors))) + + return cls.enabled + + +class IfExtractor(FrontExtractorOp): + op = 'If' + enabled = True + + @classmethod + def extract(cls, if_node: Node): + return extract_if(cls, if_node) + + +class StatelessIfExtractor(FrontExtractorOp): + op = 'StatelessIf' + enabled = True + + @classmethod + def extract(cls, if_node: Node): + return extract_if(cls, if_node) diff --git a/model-optimizer/extensions/front/tf/while_ext.py b/model-optimizer/extensions/front/tf/while_ext.py index 3887c5fe7573b5..b9451cff1b5958 100644 --- a/model-optimizer/extensions/front/tf/while_ext.py +++ b/model-optimizer/extensions/front/tf/while_ext.py @@ -1,68 +1,14 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import copy - from extensions.ops.loop import Loop from extensions.ops.parameter import Parameter from mo.front.common.register_custom_ops import check_for_duplicates from mo.front.extractor import extract_node_attrs, FrontExtractorOp from mo.front.tf.extractor import tf_op_extractor, tf_op_extractors, create_tf_edge -from mo.front.tf.extractors.utils import tf_dtype_extractor +from mo.front.tf.extractors.subgraph_utils import update_body_graph, convert_graph_inputs_to_parameters, \ + get_graph_proto, create_internal_graph from mo.graph.graph import add_opoutput, Graph, Node -from mo.ops.op import PermuteAttrs - - -def update_body_graph(body_graph: Graph, subgraph_proto: dict, - body_parameter_names: list, body_results: list): - """ - Updates the loop body graph with a sub-graph (for body or condition functions) - :param body_graph: a loop body graph to be updated - :param subgraph_proto: a sub-graph in a protobuf format to be added into the loop body graph - :param body_parameter_names: a (unchanged) list of parameters in the loop body graph - :param body_results: a list of Result nodes that is extended with a list from a sub-graph - """ - # create a map from a node name in original model to a name in a loop body graph assuming - # that names in the original model are unique - # initially, the map contains names for parameters that are common for the body and condition graphs - map_original_name = {} - for idx, pb_node in enumerate(subgraph_proto['input_arg']): - map_original_name[pb_node.name] = body_parameter_names[idx] - - # walk through all nodes (non-parameter and non-result nodes) and add into the loop body graph - for pb_node in subgraph_proto['node_def']: - # create an NX node - id = body_graph.unique_id(pb_node.name) - map_original_name[pb_node.name] = id - body_graph.add_node(id, pb=pb_node, kind='op') - if hasattr(body_graph, 'op_names_statistic') and hasattr(pb_node, 'op'): - body_graph.op_names_statistic[pb_node.op] += 1 - - # add incoming edges based on data_nodes_map - for dst_port, inp in enumerate(pb_node.input): - orig_src_id = inp.split(":")[0] - - # TODO: avoid this temporal workaround for TF 2.4 or higher RNN layers: - # skip control flow dependency - if orig_src_id[0] == '^': - continue - - src_id = map_original_name[orig_src_id] - src_port = 0 if len(inp.split(":")) == 1 else int(inp.split(":")[-1]) - assert (body_graph.has_node(src_id)) - - body_graph.add_edges_from([create_tf_edge(src_id + ":" + str(src_port), id, dst_port)]) - - # create Result nodes in the loop body graph - for output in subgraph_proto['output_arg']: - output_name = subgraph_proto['ret'][output.name] - orig_src_id = output_name.split(":")[0] - src_id = map_original_name[orig_src_id] - src_port = 0 if len(output_name.split(":")) == 1\ - else int(output_name.split(":")[-1]) - assert body_graph.has_node(src_id), 'The body graph does not contain output with name "{}"'.format( - src_id) - body_results.append(Node(body_graph, add_opoutput(body_graph, src_id, src_port, False))) class WhileExtractor(FrontExtractorOp): @@ -77,49 +23,16 @@ class WhileExtractor(FrontExtractorOp): @classmethod def extract(cls, loop_node): Loop.update_node_stat(loop_node, {}) - loop_name = loop_node.soft_get('name', loop_node.id) # check that required body and condition functions exist in the graph library main_graph = loop_node.graph - body_graph_name = loop_node.pb.attr['body'].func.name - cond_graph_name = loop_node.pb.attr['cond'].func.name - assert 'library' in main_graph.graph, 'The graph does not contain a library that is required ' \ - 'by node with name "{}".'.format(loop_name) - library_graph = main_graph.graph['library'] - - assert body_graph_name in library_graph, 'The library does not contain a function with name "{}" ' \ - 'that is required by node ' \ - 'with name "{}".'.format(body_graph_name, loop_name) - body_graph_proto = library_graph[body_graph_name] - - assert cond_graph_name in library_graph, 'The library does not contain a function with name "{}" ' \ - 'that is required by node ' \ - 'with name "{}".'.format(cond_graph_name, loop_name) - cond_graph_proto = library_graph[cond_graph_name] - - body_graph = Graph() - # fill the body graph - for attr_key in main_graph.graph.keys(): - if attr_key != 'library': - body_graph.graph[attr_key] = copy.deepcopy(main_graph.graph[attr_key]) - else: - # it is sufficient to have a link to the library - body_graph.graph['library'] = main_graph.graph['library'] - loop_node['body'] = body_graph + body_graph_proto = get_graph_proto(main_graph, 'body', loop_node) + cond_graph_proto = get_graph_proto(main_graph, 'cond', loop_node) + body_graph = create_internal_graph(main_graph) + loop_node['body'] = body_graph # create Parameter nodes for the body graph - body_parameters = [] - body_parameter_names = [] - for idx, pb_node in enumerate(body_graph_proto['input_arg']): - param_id = body_graph.unique_id(pb_node.name) - body_graph.add_node(param_id, name=param_id, kind='op', op='Parameter', pb=None, shape=None) - parameter_node = Node(body_graph, pb_node.name) - Parameter.update_node_stat(parameter_node, - {'data_type': tf_dtype_extractor(pb_node.type), - 'permute_attrs': PermuteAttrs().update_attrs(attrs=[('shape', 'output:0')])} - ) - body_parameters.append(parameter_node) - body_parameter_names.append(param_id) + body_parameters, body_parameter_names = convert_graph_inputs_to_parameters(body_graph, body_graph_proto) # update the loop body graph with the body function graph body_results = [] @@ -172,7 +85,7 @@ def extract(cls, loop_node): Loop.add_back_edge(loop_node, body_parameters[idx], body_results[idx]) # connect body outputs with Loop operation output ports except the execution condition result - for idx in range(len(body_results)-1): + for idx in range(len(body_results) - 1): Loop.connect_body_output(loop_node, idx, body_results[idx]) # run function to parse body nodes attributes similar to the main graph diff --git a/model-optimizer/extensions/load/tf/loader.py b/model-optimizer/extensions/load/tf/loader.py index 6d5c8978861855..ae0f79b178baee 100644 --- a/model-optimizer/extensions/load/tf/loader.py +++ b/model-optimizer/extensions/load/tf/loader.py @@ -138,8 +138,8 @@ def graph_or_sub_graph_has_nhwc_ops(graph: Graph): NHWC_conv_detected = True break - # for the Loop node we need to check that the body does not contain marker ops as well - if node.op == 'Loop': - NHWC_conv_detected |= graph_or_sub_graph_has_nhwc_ops(node.body) - # TODO check for If op when it is implemented + if node.has('sub_graphs'): + for sub_graph_name in node['sub_graphs']: + NHWC_conv_detected |= graph_or_sub_graph_has_nhwc_ops(node.soft_get(sub_graph_name)) + return NHWC_conv_detected diff --git a/model-optimizer/extensions/ops/If.py b/model-optimizer/extensions/ops/If.py new file mode 100644 index 00000000000000..7e930971277255 --- /dev/null +++ b/model-optimizer/extensions/ops/If.py @@ -0,0 +1,328 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import logging as log +import numpy as np + +from mo.front.common.partial_infer.utils import int64_array +from mo.graph.graph import Node, Graph +from mo.middle.passes.infer import partial_infer +from mo.ops.op import Op + + +class If(Op): + """ + If operation is an operation which has an input with condition which defines what sub-graph "then" or "else" to be + executed. + """ + op = 'If' + enabled = False + + def __init__(self, graph: Graph, attrs: dict): + base_attrs = { + 'type': self.op, + 'op': self.op, + 'then_graph': None, # an Graph object with a "then" body sub-graph (condition is True) + 'else_graph': None, # an Graph object with a "else" body sub-graph (condition is False) + 'sub_graphs': ['then_graph', 'else_graph'], # built-in attribute with all sub-graphs + 'version': 'opset8', + 'infer': self.infer, + 'type_infer': self.type_infer, + } + base_attrs.update(attrs) + super().__init__(graph, base_attrs, attrs) + + def port_map_attrs(self): + return [ + 'external_port_id', + 'internal_layer_id' + ] + + @staticmethod + def connect_body_input(if_node: Node, condition: bool, if_input_port_idx: int, body_parameter: Node): + """ + Update the specified body parameter and connect it with If input + + :param if_node: the If node + :param condition: the boolean defining a condition (then/else) graph to add connect the body + :param if_input_port_idx: the input port index to connect + :param body_parameter: the body parameter node to connect + :return: None + """ + assert if_node.soft_get('op') == 'If' + assert body_parameter.soft_get('op') == 'Parameter' + sub_graph = if_node.then_graph if condition else if_node.else_graph + assert body_parameter.id in sub_graph + body_parameter['input_id'] = if_input_port_idx + + @staticmethod + def connect_body_output(if_node: Node, condition: bool, if_output_port_idx: int, internal_result: Node): + """ + Update the specified output port and connect it with If output + + :param if_node: the If node + :param condition: the boolean defining a condition (then/else) graph to add connect the body + :param if_output_port_idx: the output port index to connect + :param internal_result: the body Result node to connect + :return: None + """ + assert if_node.soft_get('op') == 'If' + assert internal_result.soft_get('op') == 'Result' + sub_graph = if_node.then_graph if condition else if_node.else_graph + assert internal_result.id in sub_graph + internal_result['output_id'] = if_output_port_idx + + @staticmethod + def update_body_parameters_type(if_node: Node, condition: bool): + """ + Update the data type for If body Parameter nodes based on data type of the outer graph nodes producing data + for them. + + :param if_node: The If node + :param condition: the boolean defining a condition (then/else) graph + :return: None + """ + assert if_node.soft_get('type') == 'If' + + subgraph = if_node.then_graph if condition else if_node.else_graph + for node in subgraph.get_op_nodes(): + if node.has('input_id'): + assert node.soft_get('type') == 'Parameter' + input_port_id = node['input_id'] + input_type = if_node.in_port(input_port_id).get_data_type() + node.data_type = input_type + log.debug('Updated data type for the body node with name "{}" with value {}' + .format(node.name, node.data_type)) + + @staticmethod + def update_body_parameters_shape(if_node: Node, condition: bool): + """ + Update shape for If body parameters. + + :param if_node: The If node + :param condition: the boolean defining a condition (then/else) graph to add connect the body + :return: None + """ + subgraph = if_node.then_graph if condition else if_node.else_graph + for node in subgraph.get_op_nodes(): + if node.has('input_id'): + assert node.soft_get('type') == 'Parameter' + input_port_id = node['input_id'] + input_shape = if_node.in_port(input_port_id).data.get_shape() + if node.soft_get('shape', None) is None: + node['shape'] = None + node.shape = input_shape.copy() + log.debug('Updated shape for the body node with name "{}" with value {}' + .format(node.soft_get('name', node.soft_get('id')), node.shape)) + + @staticmethod + def results_mapping_and_finding_fake_outputs(output_nodes_in_subgraph, branch_name, outputs_mapping): + """ + This method checked result nodes in subgraph and set map between output from If operation and internal subgraph + result. Also This method return True if internal graph has fake results. + + :param output_nodes_in_subgraph: Result node with attribute 'output_id' + :param branch_name: name of subgraph + :param outputs_mapping: map between If operation output ID and subgraph results + + :return: True if all results of subgraph are empty tensors + """ + graph_contain_fake_outputs = True + + for output_node in output_nodes_in_subgraph: + assert output_node.soft_get('type') == 'Result' + port_id = output_node['output_id'] + assert port_id in outputs_mapping.keys(), 'Incorrect mapping then_graph outputs with {0} outputs! ' \ + 'Can\'t find port with ID {1} in If operation.' \ + .format(output_node.name, port_id) + outputs_mapping[port_id][branch_name] = output_node + out_node_shape = output_node.in_port(0).data.get_shape() + graph_contain_fake_outputs = graph_contain_fake_outputs and np.any(out_node_shape == 0) + return graph_contain_fake_outputs + + @staticmethod + def update_if_output_ports_shape(if_node: Node): + """ + Update shape and values for If output ports. + + :param if_node: The If node to update output ports and shapes + :return: None + """ + + then_outputs = [node for node in if_node.then_graph.get_op_nodes() if node.has('output_id')] + else_outputs = [node for node in if_node.else_graph.get_op_nodes() if node.has('output_id')] + outputs_mapping = {} + outputs_number = len(if_node.out_ports()) + + if outputs_number == 0 and len(if_node.out_ports(control_flow=True)) != 0: + # Some models have if with control flow outputs. + # These shape inference for such ifs + # TODO: need to rethink and redo support for control flow edges in if operation + for node in if_node.out_nodes(control_flow=True).values(): + node.shape = int64_array([]) + return + + for port_id in if_node.out_ports().keys(): + outputs_mapping[port_id] = {} + + # variables then_contains_fake_outputs/else_contains_fake_outputs contains True value + # if all outputs from then_body/else_body have shape [0]. It means then_body/else_body does not return data + # and further shape_inference for this branch is not possible. + # TODO: exclude support fake_outputs from this code when we will support shape_inference with empty tensors + + then_contains_fake_outputs = \ + If.results_mapping_and_finding_fake_outputs(then_outputs, 'then_graph', outputs_mapping) + else_contains_fake_outputs = \ + If.results_mapping_and_finding_fake_outputs(else_outputs, 'else_graph', outputs_mapping) + + # use_then_shape is True when else_body or when both bodies do not return data. If use_then_shape is True If's + # outputs will have the same shapes as then_body results + use_then_shape = else_contains_fake_outputs or not then_contains_fake_outputs + + for port_id in outputs_mapping: + then_else_nodes = outputs_mapping[port_id] + assert 'then_graph' in then_else_nodes.keys(), 'then_graph does not connect with If.out_port[{0}] ' \ + 'in {1} node!'.format(port_id, if_node.name) + assert 'else_graph' in then_else_nodes.keys(), 'else_graph does not connect with If.out_port[{0}] ' \ + 'in {1} node!'.format(port_id, if_node.name) + + then_shape = then_else_nodes['then_graph'].in_port(0).data.get_shape() + else_shape = then_else_nodes['else_graph'].in_port(0).data.get_shape() + + if not (then_shape == else_shape).all(): + log.debug("If node {0} has dynamic output [{1}] because output shape from then_graph is {2} and " + "else_graph {3}".format(if_node.name, port_id, then_shape, else_shape)) + if_node.out_port(port_id).data.set_shape(then_shape if use_then_shape else else_shape) + + @staticmethod + def update_if_output_ports_type(if_node: Node): + """ + Update types for If output ports. + + :param if_node: The If node to update output ports and types + :return: None + """ + then_outputs = [node for node in if_node.then_graph.get_op_nodes() if node.has('output_id')] + else_outputs = [node for node in if_node.else_graph.get_op_nodes() if node.has('output_id')] + outputs_mapping = {} + outputs_number = len(if_node.out_ports()) + assert outputs_number == len(then_outputs), 'Incorrect number outputs in then_graph of If with"' \ + 'name {0}! then_graph must has {1} outputs' \ + .format(if_node.name, outputs_number) + assert outputs_number == len(else_outputs), 'Incorrect number outputs in else_graph of If with"' \ + 'name {0}! else_graph must has {1} outputs' \ + .format(if_node.name, outputs_number) + for port_id in if_node.out_ports().keys(): + outputs_mapping[port_id] = {} + port_ids = outputs_mapping.keys() + for then_output_node in then_outputs: + assert then_output_node.soft_get('type') == 'Result' + port_id = then_output_node['output_id'] + assert port_id in port_ids, 'Incorrect mapping then_graph outputs with {0} outputs! ' \ + 'Can\'t find port with ID {1} in If operation.' \ + .format(then_output_node.name, port_id) + outputs_mapping[port_id]['then_graph'] = then_output_node + + for else_output_node in else_outputs: + assert else_output_node.soft_get('type') == 'Result' + port_id = else_output_node['output_id'] + assert port_id in port_ids, 'Incorrect mapping then_graph outputs with {0} outputs! ' \ + 'Can\'t find port with ID {1} in If operation.' \ + .format(else_output_node.name, port_id) + outputs_mapping[port_id]['else_graph'] = else_output_node + + for port_id in outputs_mapping: + then_else_nodes = outputs_mapping[port_id] + assert 'then_graph' in then_else_nodes.keys(), 'then_graph does not connect with If.out_port[{0}] ' \ + 'in {1} node!'.format(port_id, if_node.name) + assert 'else_graph' in then_else_nodes.keys(), 'else_graph does not connect with If.out_port[{0}] ' \ + 'in {1} node!'.format(port_id, if_node.name) + then_type = then_else_nodes['then_graph'].in_port(0).get_data_type() + else_type = then_else_nodes['else_graph'].in_port(0).get_data_type() + assert then_type == else_type, 'Cannot get type for if.out_port[{0}]! ' \ + 'Types in then_graph and else_graph are not equal!'.format(port_id) + if_node.out_port(port_id).set_data_type(then_type) + + @staticmethod + def re_numerate_internal_id_and_get_if_id(if_node): + """ + This method is called before IR generation. This method sets internal_layer_id. + + :param if_node: The If node where is necessary to set internal_layer_id in bodies. + :return: if_node + """ + then_graph_nodes = if_node.then_graph.nodes() + for idx in range(len(if_node.then_graph.get_op_nodes())): + then_graph_nodes[idx]['internal_layer_id'] = idx + else_graph_nodes = if_node.else_graph.nodes() + for idx in range(len(if_node.else_graph.get_op_nodes())): + else_graph_nodes[idx]['internal_layer_id'] = idx + return if_node.node + + def substitute_ie_attrs(self, new_attrs: dict): + """ + Replace standard list of attribute in layer/data by attributes + delivered by backend_attrs + """ + + port_map_attrs = self.port_map_attrs() + new_attrs.update({ + 'IE': [( + 'layer', + [('id', lambda node: self.re_numerate_internal_id_and_get_if_id(node)), 'name', 'type', 'version'], + [ + '@ports', + ('then_port_map', [], [ + ('@list', lambda node: self.generate_port_map(node, True, 'in'), + ('input', port_map_attrs, [])), + ('@list', lambda node: self.generate_port_map(node, True, 'out'), + ('output', port_map_attrs, [])), + ]), + ('else_port_map', [], [ + ('@list', lambda node: self.generate_port_map(node, False, 'in'), + ('input', port_map_attrs, [])), + ('@list', lambda node: self.generate_port_map(node, False, 'out'), + ('output', port_map_attrs, [])), + ]), + ('then_body', [], [('@network', 'then_graph')]), + ('else_body', [], [('@network', 'else_graph')]), + ])] + }) + + @staticmethod + def generate_port_map(if_node: Node, condition: bool, dir: str): + """ + Extract port_map attributes from if_node and its subgraphs attributes. + + :param if_node: The If node + :param condition: the boolean defining a condition (then/else) graph + :param dir: the str value defining type (for inputs or for putputs) of port_map + :return: port_map -> list of dictionaries with to values(external_port_id or internal_layer_id) + """ + port_map = [] + subgraph = if_node.then_graph if condition else if_node.else_graph + name_of_connection = 'input_id' if dir == 'in' else 'output_id' + + for internal_node in subgraph.get_op_nodes(): + if internal_node.has(name_of_connection): + port_map.append({'external_port_id': internal_node[name_of_connection], + 'internal_layer_id': internal_node['internal_layer_id']}) + + return port_map + + @staticmethod + def infer(if_node: Node): + If.update_body_parameters_shape(if_node, True) + If.update_body_parameters_shape(if_node, False) + partial_infer(if_node.then_graph) + partial_infer(if_node.else_graph) + If.update_if_output_ports_shape(if_node) + + @staticmethod + def type_infer(if_node: Node): + from mo.middle.passes.infer import type_infer + If.update_body_parameters_type(if_node, True) + If.update_body_parameters_type(if_node, False) + type_infer(if_node.then_graph) + type_infer(if_node.else_graph) + If.update_if_output_ports_type(if_node) diff --git a/model-optimizer/mo/front/tf/extractors/subgraph_utils.py b/model-optimizer/mo/front/tf/extractors/subgraph_utils.py new file mode 100644 index 00000000000000..ac7479cd9ebd5b --- /dev/null +++ b/model-optimizer/mo/front/tf/extractors/subgraph_utils.py @@ -0,0 +1,108 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import copy + +from extensions.ops.parameter import Parameter +from mo.front.tf.extractor import tf_op_extractor, tf_op_extractors, create_tf_edge +from mo.front.tf.extractors.utils import tf_dtype_extractor +from mo.graph.graph import Graph, Node, add_opoutput +from mo.ops.op import PermuteAttrs + + +def update_body_graph(body_graph: Graph, subgraph_proto: dict, + body_parameter_names: list, body_results: list): + """ + Updates the loop body graph with a sub-graph (for body or condition functions) + :param body_graph: a loop body graph to be updated + :param subgraph_proto: a sub-graph in a protobuf format to be added into the loop body graph + :param body_parameter_names: a (unchanged) list of parameters in the loop body graph + :param body_results: a list of Result nodes that is extended with a list from a sub-graph + """ + # create a map from a node name in original model to a name in a loop body graph assuming + # that names in the original model are unique + # initially, the map contains names for parameters that are common for the body and condition graphs + map_original_name = {} + for idx, pb_node in enumerate(subgraph_proto['input_arg']): + map_original_name[pb_node.name] = body_parameter_names[idx] + + # walk through all nodes (non-parameter and non-result nodes) and add into the loop body graph + for pb_node in subgraph_proto['node_def']: + # create an NX node + id = body_graph.unique_id(pb_node.name) + map_original_name[pb_node.name] = id + body_graph.add_node(id, pb=pb_node, kind='op') + if hasattr(body_graph, 'op_names_statistic') and hasattr(pb_node, 'op'): + body_graph.op_names_statistic[pb_node.op] += 1 + + # add incoming edges based on data_nodes_map + for dst_port, inp in enumerate(pb_node.input): + orig_src_id = inp.split(":")[0] + + # TODO: avoid this temporal workaround for TF 2.4 or higher RNN layers: + # skip control flow dependency + if orig_src_id[0] == '^': + continue + + src_id = map_original_name[orig_src_id] + src_port = 0 if len(inp.split(":")) == 1 else int(inp.split(":")[-1]) + assert (body_graph.has_node(src_id)) + + body_graph.add_edges_from([create_tf_edge(src_id + ":" + str(src_port), id, dst_port)]) + + # create Result nodes in the loop body graph + for output in subgraph_proto['output_arg']: + output_name = subgraph_proto['ret'][output.name] + orig_src_id = output_name.split(":")[0] + src_id = map_original_name[orig_src_id] + src_port = 0 if len(output_name.split(":")) == 1 \ + else int(output_name.split(":")[-1]) + assert body_graph.has_node(src_id), 'The body graph does not contain output with name "{}"'.format( + src_id) + body_results.append(Node(body_graph, add_opoutput(body_graph, src_id, src_port, False))) + + return True + + +def get_graph_proto(external_graph: Graph, graph_id: str, node_with_graph: Node): + graph_name = node_with_graph.pb.attr[graph_id].func.name + node_name = node_with_graph.soft_get('name', node_with_graph.id) + + assert 'library' in external_graph.graph, 'The graph does not contain a library that is required ' \ + 'by node with name "{}".'.format(node_name) + + library_graph = external_graph.graph['library'] + + assert graph_name in library_graph, 'The library does not contain a function with name "{}" ' \ + 'that is required by node ' \ + 'with name "{}".'.format(graph_name, node_name) + return library_graph[graph_name] + + +def create_internal_graph(external_graph: Graph): + internal_graph = Graph() + # fill the body graph + for attr_key in external_graph.graph.keys(): + if attr_key != 'library': + internal_graph.graph[attr_key] = copy.deepcopy(external_graph.graph[attr_key]) + else: + # it is sufficient to have a link to the library + internal_graph.graph['library'] = external_graph.graph['library'] + return internal_graph + + +def convert_graph_inputs_to_parameters(internal_graph, internal_graph_proto): + # create Parameter nodes for the body graph + body_parameters = [] + body_parameter_names = [] + for idx, pb_node in enumerate(internal_graph_proto['input_arg']): + param_id = internal_graph.unique_id(pb_node.name) + internal_graph.add_node(param_id, name=param_id, kind='op', op='Parameter', pb=None, shape=None) + parameter_node = Node(internal_graph, pb_node.name) + Parameter.update_node_stat(parameter_node, + {'data_type': tf_dtype_extractor(pb_node.type), + 'permute_attrs': PermuteAttrs().update_attrs(attrs=[('shape', 'output:0')])} + ) + body_parameters.append(parameter_node) + body_parameter_names.append(param_id) + return body_parameters, body_parameter_names diff --git a/model-optimizer/mo/pipeline/common.py b/model-optimizer/mo/pipeline/common.py index cd86ef26851d04..3d3264c67a8a67 100644 --- a/model-optimizer/mo/pipeline/common.py +++ b/model-optimizer/mo/pipeline/common.py @@ -194,7 +194,8 @@ def prepare_emit_ir(graph: Graph, data_type: str, output_dir: str, output_model_ # do not run the type inference in sub-graphs. It will be called automatically as part of the type inference of # the TensorIterator nodes type_infer(graph) - RemoveUselessConvert().find_and_replace_pattern(graph) + + for_graph_and_each_sub_graph_recursively(graph, RemoveUselessConvert().find_and_replace_pattern) ResultRename().find_and_replace_pattern(graph) diff --git a/model-optimizer/mo/utils/ir_engine/ir_engine.py b/model-optimizer/mo/utils/ir_engine/ir_engine.py index 2beb3467ffa235..3d534017828d96 100644 --- a/model-optimizer/mo/utils/ir_engine/ir_engine.py +++ b/model-optimizer/mo/utils/ir_engine/ir_engine.py @@ -240,34 +240,8 @@ def __load_layer(self, layer): xml_body_child = list(layer.iterfind('body')) assert len(xml_body_child) == 1 - body_ir = IREngine(path_to_xml=None, - path_to_bin=self.path_to_bin, - xml_tree=ElementTree(xml_body_child[0])) - self.graph.graph['hashes'].update(body_ir.graph.graph['hashes']) - - # Find port_map section and take an input_port_map & output_port_map - xml_port_map = list(layer.iterfind('port_map')) - if not len(xml_port_map) == 1: - log.warning("TensorIterator body won\'t be compared due to missing port_map section!") - continue - xml_port_map = xml_port_map[0] - - input_layers = [] - input_port_map = [] - output_port_map = [] - - for port in xml_port_map: - if port.tag == 'input': - if 'internal_layer_id' not in port.attrib: - log.warning("internal_layer_id attrib not found in input section") - else: - input_layers.append(Node(body_ir.graph, port.attrib['internal_layer_id'])) - input_port_map.append(self.__normalize_attrs(port.attrib)) - elif port.tag == 'output': - if 'internal_layer_id' not in port.attrib: - log.warning("internal_layer_id attrib not found in output section") - else: - output_port_map.append(self.__normalize_attrs(port.attrib)) + body_ir, input_port_map, output_port_map, input_layers = \ + self.__read_subgraph(layer, layer_attrs, xml_body_child, 'port_map') body_ir.input_node = input_layers[0] layer_attrs.update({'body': body_ir}) @@ -287,6 +261,12 @@ def __load_layer(self, layer): layer_attrs.update({'back_edges': back_edges}) + elif attr.tag == 'then_body' or attr.tag == 'else_body': + assert layer.attrib['type'] == 'If', "Incorrect IR! The operation {0}" \ + " has sub-graphs for If operation" + layer_attrs = self.__read_if(layer, layer_attrs) + continue + return layer_id, layer_attrs @staticmethod @@ -405,3 +385,54 @@ def __eq__(self, other): if not isinstance(other, IREngine): raise AttributeError("IREngine can be compared only with IREngine object type") return self.compare(other)[0] + + def __read_subgraph(self, layer, layer_attrs, body_child, port_map_name): + body_ir = IREngine(path_to_xml=None, + path_to_bin=self.path_to_bin, + xml_tree=ElementTree(body_child[0])) + + self.graph.graph['hashes'].update(body_ir.graph.graph['hashes']) + + xml_port_map = list(layer.iterfind(port_map_name)) + assert not len(xml_port_map) != 1, "If then_body won\'t be compared due to missing {1} section in node {0}! " \ + .format(layer_attrs['name'], port_map_name) + xml_port_map = xml_port_map[0] + + input_layers = [] + input_port_map = [] + output_port_map = [] + + for port in xml_port_map: + if port.tag == 'input': + if 'internal_layer_id' not in port.attrib: + log.warning("internal_layer_id attrib not found in input section") + else: + input_layers.append(Node(body_ir.graph, port.attrib['internal_layer_id'])) + input_port_map.append(self.__normalize_attrs(port.attrib)) + elif port.tag == 'output': + if 'internal_layer_id' not in port.attrib: + log.warning("internal_layer_id attrib not found in output section") + else: + output_port_map.append(self.__normalize_attrs(port.attrib)) + + return body_ir, input_port_map, output_port_map, input_layers + + def __read_if(self, layer, layer_attrs): + + xml_then_body_child = list(layer.iterfind('then_body')) + xml_else_body_child = list(layer.iterfind('else_body')) + assert len(xml_then_body_child) == 1 and len(xml_else_body_child) == 1, "If operation has only one subgraph" + + then_body_ir, then_input_port_map, then_output_port_map, _ = \ + self.__read_subgraph(layer, layer_attrs, xml_then_body_child, 'then_port_map') + layer_attrs.update({'then_graph': then_body_ir}) + layer_attrs.update({'then_input_port_map': then_input_port_map}) + layer_attrs.update({'then_output_port_map': then_output_port_map}) + + else_body_ir, else_input_port_map, else_output_port_map, _ = \ + self.__read_subgraph(layer, layer_attrs, xml_else_body_child, 'else_port_map') + layer_attrs.update({'else_graph': else_body_ir}) + layer_attrs.update({'else_input_port_map': else_input_port_map}) + layer_attrs.update({'else_output_port_map': else_output_port_map}) + + return layer_attrs diff --git a/model-optimizer/mo/utils/ir_reader/extenders/if_extender.py b/model-optimizer/mo/utils/ir_reader/extenders/if_extender.py new file mode 100644 index 00000000000000..8165c40015c6f9 --- /dev/null +++ b/model-optimizer/mo/utils/ir_reader/extenders/if_extender.py @@ -0,0 +1,41 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +from mo.utils.graph import Node +from mo.utils.ir_reader.extender import Extender +from mo.utils.ir_reader.layer_to_class import copy_graph_with_ops + + +class IfExtender(Extender): + op = 'If' + + @staticmethod + def set_input_output_id(subgraph, input_port_map, output_port_map): + for node in subgraph.get_op_nodes(): + if not node.has_valid('id'): + continue + node_id = int(node.soft_get('id')) + for if_input_mapping_elem in input_port_map: + if node_id == if_input_mapping_elem['internal_layer_id']: + node['input_id'] = if_input_mapping_elem['external_port_id'] + for if_out_mapping_elem in output_port_map: + if node_id == if_out_mapping_elem['internal_layer_id']: + node['output_id'] = if_out_mapping_elem['external_port_id'] + + @staticmethod + def extend(op: Node): + assert op.has('then_graph'), 'There is no "then_body" attribute in the If op {}.'.format(op.name) + assert op.has('else_graph'), 'There is no "else_body" attribute in the If op {}.'.format(op.name) + # Now op.body is an IREngine, we need to replace it with IREngine.graph + op.then_graph.graph.graph['cmd_params'] = op.graph.graph['cmd_params'] + op.then_graph.graph.graph['ir_version'] = op.graph.graph['ir_version'] + op.then_graph.graph.name = op.name + '/then_body' + + op.else_graph.graph.graph['cmd_params'] = op.graph.graph['cmd_params'] + op.else_graph.graph.graph['ir_version'] = op.graph.graph['ir_version'] + op.else_graph.graph.name = op.name + '/else_body' + op.then_graph = copy_graph_with_ops(op.then_graph.graph) + op.else_graph = copy_graph_with_ops(op.else_graph.graph) + + IfExtender.set_input_output_id(op.then_graph, op.then_input_port_map, op.then_output_port_map) + IfExtender.set_input_output_id(op.else_graph, op.else_input_port_map, op.else_output_port_map) diff --git a/model-optimizer/unit_tests/extensions/load/tf/loader_test.py b/model-optimizer/unit_tests/extensions/load/tf/loader_test.py index b84da4f98b404f..7b02dfe75563dd 100644 --- a/model-optimizer/unit_tests/extensions/load/tf/loader_test.py +++ b/model-optimizer/unit_tests/extensions/load/tf/loader_test.py @@ -44,7 +44,7 @@ def build_loop_graph(body_graph): # create fake Loop operation nodes = { **regular_op('input', {'op': 'Parameter'}), - **regular_op('loop', {'op': 'Loop', 'body': body_graph}), + **regular_op('loop', {'op': 'Loop', 'body': body_graph, 'sub_graphs': ['body']}), **result('result'), } edges = [*connect_front('input', '0:loop'), @@ -65,4 +65,3 @@ def test_no_convolution_main_graph(self): def test_no_convolution_main_and_sub_graph(self): self.assertFalse(graph_or_sub_graph_has_nhwc_ops(self.build_loop_graph(self.build_parameter_result_graph()))) - diff --git a/model-optimizer/unit_tests/extensions/ops/If_test.py b/model-optimizer/unit_tests/extensions/ops/If_test.py new file mode 100644 index 00000000000000..5e757f5c9c1e60 --- /dev/null +++ b/model-optimizer/unit_tests/extensions/ops/If_test.py @@ -0,0 +1,127 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import numpy.testing as npt +import unittest + +from extensions.ops.If import If +from mo.ops.shape import Shape +from extensions.ops.elementwise import Add, Mul +from extensions.ops.identity import Identity +from extensions.ops.parameter import Parameter +from mo.front.common.partial_infer.concat import concat_infer +from mo.front.common.partial_infer.utils import int64_array +from mo.graph.graph import Node, Graph +from mo.middle.passes.infer import partial_infer +from mo.ops.concat import Concat +from mo.ops.eltwise import eltwise_infer +from mo.ops.result import Result +from unit_tests.utils.graph import build_graph_with_edge_attrs, build_graph +from unit_tests.utils.graph import regular_op_with_empty_data, connect, const, result, valued_const_with_data, \ + regular_op, empty_data + + +class TestIf(unittest.TestCase): + def test_simple_shape_inf(self): + then_graph_nodes = {**regular_op_with_empty_data('param_1', {'type': 'Parameter', 'kind': 'op', 'input_id': 1, + 'shape': None, 'infer': Parameter.infer}), + **regular_op_with_empty_data('param_2', {'type': 'Parameter', 'kind': 'op', 'input_id': 2, + 'shape': None, 'infer': Parameter.infer}), + **regular_op_with_empty_data('add', {'type': 'Add', 'kind': 'op', 'op': 'Add', + 'infer': lambda node: eltwise_infer(node, + Add.operation)}), + **regular_op_with_empty_data('mul', {'type': 'Mul', 'kind': 'op', 'op': 'Mul', + 'infer': lambda node: eltwise_infer(node, + Mul.operation)}), + **regular_op_with_empty_data('res1', {'kind': 'op', 'type': 'Result', 'op': 'Result', + 'infer': lambda x: 0, 'output_id': 0}), + **regular_op_with_empty_data('res2', {'kind': 'op', 'type': 'Result', 'op': 'Result', + 'infer': lambda x: 0, 'output_id': 1})} + then_graph_edges = [*connect('param_1', '0:add'), + *connect('param_2', '1:add'), + *connect('param_1', '1:mul'), + *connect('param_2', '0:mul'), + *connect('add', 'res1'), + *connect('mul', 'res2'), + ] + + else_graph_nodes = {**regular_op_with_empty_data('param_1', {'type': 'Parameter', 'kind': 'op', 'input_id': 1, + 'shape': None, 'infer': Parameter.infer}), + **regular_op_with_empty_data('param_2', {'type': 'Parameter', 'kind': 'op', 'input_id': 3, + 'shape': None, 'infer': Parameter.infer}), + **regular_op_with_empty_data('identity', + {'kind': 'op', 'op': 'Identity', 'infer': Identity.infer}), + **regular_op_with_empty_data('identity_1', + {'kind': 'op', 'op': 'Identity', 'infer': Identity.infer}), + **regular_op_with_empty_data('res1', {'kind': 'op', 'type': 'Result', 'op': 'Result', + 'infer': lambda x: 0, 'output_id': 0}), + **regular_op_with_empty_data('res2', {'kind': 'op', 'type': 'Result', 'op': 'Result', + 'infer': lambda x: 0, 'output_id': 1})} + else_graph_edges = [*connect('param_1', 'identity'), + *connect('param_2', 'identity_1'), + *connect('identity_1', 'res2'), + *connect('identity', 'res1'), ] + then_graph = build_graph_with_edge_attrs(then_graph_nodes, then_graph_edges) + else_graph = build_graph_with_edge_attrs(else_graph_nodes, else_graph_edges) + external_graph_nodes = { + **valued_const_with_data('cond', np.array([True], dtype=np.bool)), + **valued_const_with_data('input_2', int64_array([3, 2, 1])), + **valued_const_with_data('input_1', int64_array([1, 2, 3])), + **valued_const_with_data('input_3', int64_array([8, 4])), + **regular_op('if', {'kind': 'op', 'op': 'If', 'then_graph': then_graph, + 'else_graph': else_graph, 'infer': If.infer}), + **empty_data('if_d_1'), + **empty_data('if_d_2'), + **result('res_1'), + **result('res_2')} + external_graph_edges = [*connect('cond', '0:if'), + *connect('input_1', '1:if'), + *connect('input_2', '2:if'), + *connect('input_3', '3:if'), + ('if', 'if_d_1', {'out': 0}), + ('if', 'if_d_2', {'out': 1}), + ('if_d_1', 'res_1'), + ('if_d_2', 'res_2')] + + graph = build_graph(external_graph_nodes, external_graph_edges) + graph.stage = 'middle' + partial_infer(graph) + res_1 = Node(graph, 'res_1') + res_2 = Node(graph, 'res_2') + npt.assert_array_equal(res_1.in_port(0).data.get_shape(), int64_array([3])) + npt.assert_array_equal(res_2.in_port(0).data.get_shape(), int64_array([3])) + + def test_fake_results(self): + then_graph_nodes = {**valued_const_with_data('fake_const', int64_array(0)), + **regular_op_with_empty_data('shapeof', + {'kind': 'op', 'type': 'ShapeOf', 'op': 'ShapeOf', 'infer': Shape.infer, + 'output_type': np.int64}), + **regular_op_with_empty_data('res_1', {'kind': 'op', 'type': 'Result', 'op': 'Result', + 'infer': lambda x: 0, 'output_id': 0})} + then_graph_edges = [*connect('fake_const', 'shapeof'), + *connect('shapeof', 'res_1'), + ] + + else_graph_nodes = {**regular_op_with_empty_data('param_1', {'type': 'Parameter', 'kind': 'op', 'input_id': 1, + 'shape': None, 'infer': Parameter.infer}), + **regular_op_with_empty_data('res_1', {'kind': 'op', 'type': 'Result', 'op': 'Result', + 'infer': lambda x: 0, 'output_id': 0})} + else_graph_edges = [*connect('param_1', 'res_1')] + then_graph = build_graph_with_edge_attrs(then_graph_nodes, then_graph_edges) + else_graph = build_graph_with_edge_attrs(else_graph_nodes, else_graph_edges) + external_graph_nodes = { + **valued_const_with_data('cond', np.array([True], dtype=np.bool)), + **valued_const_with_data('input_1', int64_array([[1, 2, 3], [3, 2, 3]])), + **regular_op_with_empty_data('if', {'kind': 'op', 'op': 'If', 'then_graph': then_graph, + 'else_graph': else_graph, 'infer': If.infer}), + **result('res_1')} + external_graph_edges = [*connect('cond', '0:if'), + *connect('input_1', '1:if'), + *connect('if', 'res_1')] + + graph = build_graph(external_graph_nodes, external_graph_edges) + graph.stage = 'middle' + partial_infer(graph) + res_1 = Node(graph, 'res_1') + npt.assert_array_equal(res_1.in_port(0).data.get_shape(), int64_array([2,3])) From 7bb51e6d03aae81879c14faaac28536786717b22 Mon Sep 17 00:00:00 2001 From: Paul Youngsoo Ahn Date: Thu, 19 Aug 2021 10:36:52 +0300 Subject: [PATCH 028/102] [GPU] Fixed 'assigned to self' error in loop_inst.h (#7126) --- .../thirdparty/clDNN/src/include/loop_inst.h | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/src/include/loop_inst.h b/inference-engine/thirdparty/clDNN/src/include/loop_inst.h index c63df1a06e8971..a6a8e5785401b9 100644 --- a/inference-engine/thirdparty/clDNN/src/include/loop_inst.h +++ b/inference-engine/thirdparty/clDNN/src/include/loop_inst.h @@ -381,39 +381,39 @@ class typed_primitive_inst : public typed_primitive_inst_base { size_t total_bytes; backedge_memory_mapping( - std::shared_ptr from_primitive, std::shared_ptr to_primitive, - std::vector from_mems, memory::ptr initial_mem, cldnn::stream& stream, backedge_type type = CONCAT_OUTPUT): - from_primitive(from_primitive), - to_primitive(to_primitive), - from_mems(from_mems), - initial_mem(initial_mem), - stream(stream), - type(type), + std::shared_ptr _from_primitive, std::shared_ptr _to_primitive, + std::vector _from_mems, memory::ptr _initial_mem, cldnn::stream& _stream, backedge_type _type = CONCAT_OUTPUT): + from_primitive(_from_primitive), + to_primitive(_to_primitive), + from_mems(_from_mems), + initial_mem(_initial_mem), + stream(_stream), + type(_type), total_bytes(initial_mem->get_layout().bytes_count()) { validate_backedge_memory(); } backedge_memory_mapping( - std::shared_ptr from_primitive, std::shared_ptr to_primitive, - memory::ptr from_mem, memory::ptr initial_mem, cldnn::stream& stream, backedge_type type = SINGLE_SHARED): - from_primitive(from_primitive), - to_primitive(to_primitive), - from_mems{from_mem}, - initial_mem(initial_mem), - stream(stream), - type(type), + std::shared_ptr _from_primitive, std::shared_ptr _to_primitive, + memory::ptr _from_mem, memory::ptr _initial_mem, cldnn::stream& _stream, backedge_type _type = SINGLE_SHARED): + from_primitive(_from_primitive), + to_primitive(_to_primitive), + from_mems{_from_mem}, + initial_mem(_initial_mem), + stream(_stream), + type(_type), total_bytes(initial_mem->get_layout().bytes_count()) { validate_backedge_memory(); } backedge_memory_mapping( - std::shared_ptr from_primitive, std::shared_ptr to_primitive, - memory::ptr initial_mem, cldnn::stream& stream, backedge_type type = SINGLE): - from_primitive(from_primitive), - to_primitive(to_primitive), - initial_mem(initial_mem), - stream(stream), - type(type), + std::shared_ptr _from_primitive, std::shared_ptr _to_primitive, + memory::ptr _initial_mem, cldnn::stream& _stream, backedge_type _type = SINGLE): + from_primitive(_from_primitive), + to_primitive(_to_primitive), + initial_mem(_initial_mem), + stream(_stream), + type(_type), total_bytes(initial_mem->get_layout().bytes_count()) { validate_backedge_memory(); } From c058b6b804c0d307c1b5af1d9f099f11feb073e0 Mon Sep 17 00:00:00 2001 From: Vladimir Paramuzov Date: Thu, 19 Aug 2021 11:39:39 +0300 Subject: [PATCH 029/102] [GPU] Fix build for gcc 10 (#7142) --- inference-engine/thirdparty/clDNN/api/cldnn/runtime/utils.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/inference-engine/thirdparty/clDNN/api/cldnn/runtime/utils.hpp b/inference-engine/thirdparty/clDNN/api/cldnn/runtime/utils.hpp index 7b66ff43a7bc22..1d744896dfbb8f 100644 --- a/inference-engine/thirdparty/clDNN/api/cldnn/runtime/utils.hpp +++ b/inference-engine/thirdparty/clDNN/api/cldnn/runtime/utils.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace cldnn { From 1cec35957b670384b9ece6423a0c520a92415357 Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Thu, 19 Aug 2021 12:27:02 +0300 Subject: [PATCH 030/102] [GNA] Set input scale factors for imported model (#7139) --- .../samples/speech_sample/main.cpp | 31 +++++++------- .../src/gna_plugin/gna_plugin.cpp | 12 ++++++ .../src/gna_plugin/gna_plugin_config.cpp | 2 +- .../src/gna_plugin/gna_plugin_config.hpp | 2 + .../import_reshape_permute_conv.cpp | 41 +++++++++++++++---- .../import_export_base/import_export_base.hpp | 1 + .../import_export_base/import_export_base.cpp | 17 +++++++- .../src/base/layer_test_utils.cpp | 1 + 8 files changed, 79 insertions(+), 28 deletions(-) diff --git a/inference-engine/samples/speech_sample/main.cpp b/inference-engine/samples/speech_sample/main.cpp index f2366ae7ab9e4a..d236fc84833ed1 100644 --- a/inference-engine/samples/speech_sample/main.cpp +++ b/inference-engine/samples/speech_sample/main.cpp @@ -627,24 +627,21 @@ int main(int argc, char* argv[]) { if (FLAGS_q.compare("user") == 0) { if (!FLAGS_rg.empty()) { - slog::warn - << "Custom scale factor will be ignored - using scale factor from provided imported gna model: " - << FLAGS_rg << slog::endl; - } else { - auto scaleFactorInput = ParseScaleFactors(FLAGS_sf); - if (numInputFiles != scaleFactorInput.size()) { - std::string errMessage( - "Incorrect command line for multiple inputs: " + std::to_string(scaleFactorInput.size()) + - " scale factors provided for " + std::to_string(numInputFiles) + " input files."); - throw std::logic_error(errMessage); - } + slog::warn << "Custom scale factor will be used for imported gna model: " << FLAGS_rg << slog::endl; + } - for (size_t i = 0; i < scaleFactorInput.size(); ++i) { - slog::info << "For input " << i << " using scale factor of " << scaleFactorInput[i] << slog::endl; - std::string scaleFactorConfigKey = - GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_") + std::to_string(i); - gnaPluginConfig[scaleFactorConfigKey] = scaleFactorInput[i]; - } + auto scaleFactorInput = ParseScaleFactors(FLAGS_sf); + if (numInputFiles != scaleFactorInput.size()) { + std::string errMessage( + "Incorrect command line for multiple inputs: " + std::to_string(scaleFactorInput.size()) + + " scale factors provided for " + std::to_string(numInputFiles) + " input files."); + throw std::logic_error(errMessage); + } + + for (size_t i = 0; i < scaleFactorInput.size(); ++i) { + slog::info << "For input " << i << " using scale factor of " << scaleFactorInput[i] << slog::endl; + std::string scaleFactorConfigKey = GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_") + std::to_string(i); + gnaPluginConfig[scaleFactorConfigKey] = scaleFactorInput[i]; } } else { // "static" quantization with calculated scale factor diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index c4d5b311fd6aa0..e51914c3cc6fa6 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -1579,6 +1579,18 @@ InferenceEngine::IExecutableNetworkInternal::Ptr GNAPlugin::ImportNetwork(std::i transpose_inputs_info, transpose_outputs_info); + // If scale factors are defined in configuration we still need to use them instead of imported values, + // for example to change the scale factors for the old models. + if (!config.inputScaleFactors.empty()) { + IE_ASSERT(config.inputScaleFactors.size() == inputsDesc->inputScaleFactors.size()); + for (size_t i = 0; i < config.inputScaleFactors.size(); ++i) { + if (config.inputScaleFactors[i] != GNAPluginNS::kScaleFactorDefault) { + gnalog() << "[Import Network] Using input scale factor defined in configuration for input " << i << std::endl; + inputsDesc->inputScaleFactors[i] = config.inputScaleFactors[i]; + } + } + } + #if GNA_LIB_VER == 2 auto getOrientation = [](Gna2Operation & gnaOperation) { return gnaOperation.Type == Gna2OperationTypeConvolution ? diff --git a/inference-engine/src/gna_plugin/gna_plugin_config.cpp b/inference-engine/src/gna_plugin/gna_plugin_config.cpp index f5e28e10aed130..64b374b49af726 100644 --- a/inference-engine/src/gna_plugin/gna_plugin_config.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin_config.cpp @@ -95,7 +95,7 @@ void Config::UpdateFromMap(const std::map& config) { } // missing scale factors are set to be 1.0f if (inputScaleFactors.size() <= input_index) { - inputScaleFactors.resize(input_index + 1, 1.f); + inputScaleFactors.resize(input_index + 1, GNAPluginNS::kScaleFactorDefault); } inputScaleFactors[input_index] = InferenceEngine::CNNLayer::ie_parse_float(value); } else if (key == GNA_CONFIG_KEY(FIRMWARE_MODEL_IMAGE)) { diff --git a/inference-engine/src/gna_plugin/gna_plugin_config.hpp b/inference-engine/src/gna_plugin/gna_plugin_config.hpp index 850c61c5a6eea5..309882dd126998 100644 --- a/inference-engine/src/gna_plugin/gna_plugin_config.hpp +++ b/inference-engine/src/gna_plugin/gna_plugin_config.hpp @@ -18,6 +18,8 @@ namespace GNAPluginNS { +static const float kScaleFactorDefault = 1.f; + struct Config { Config() { AdjustKeyMapValues(); diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp index 0d824402305da1..a17c52a97b5c03 100644 --- a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp @@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions; namespace { -class ImportReshapePermuteConvGNA : public ImportReshapePermuteConv { +class ImportExportGNAModelUnchanged : public ImportReshapePermuteConv { private: void exportImportNetwork() override { { @@ -42,8 +42,14 @@ class ImportReshapePermuteConvGNA : public ImportReshapePermuteConv { std::string fileName = "exported_model.blob"; }; -TEST_P(ImportReshapePermuteConvGNA, CompareWithRefImpl) { - Run(); +class ImportExportGNAModelChanged : public ImportExportGNAModelUnchanged {}; + +TEST_P(ImportExportGNAModelUnchanged, ReshapePermuteConv) { + TestRun(false); +}; + +TEST_P(ImportExportGNAModelChanged, ReshapePermuteConv) { + TestRun(true); }; const std::vector netPrecisions = { @@ -58,15 +64,25 @@ const std::vector> exportConfigs = { } }; -const std::vector> importConfigs = { +const std::vector> importConfigsChanged = { { {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "32767"} - }, + } +}; + +const std::vector> importConfigsUnchanged = { { {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"} }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "1"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"} + } }; const std::vector appHeaders = { @@ -74,13 +90,22 @@ const std::vector appHeaders = { "APPLICATION_HEADER" }; -INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkCase, ImportReshapePermuteConvGNA, +INSTANTIATE_TEST_CASE_P(smoke_ImportNetworkGNA, ImportExportGNAModelUnchanged, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(exportConfigs), + ::testing::ValuesIn(importConfigsUnchanged), + ::testing::ValuesIn(appHeaders)), + ImportExportGNAModelUnchanged::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_ImportNetworkGNA, ImportExportGNAModelChanged, ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigs), + ::testing::ValuesIn(importConfigsChanged), ::testing::ValuesIn(appHeaders)), - ImportReshapePermuteConvGNA::getTestCaseName); + ImportExportGNAModelChanged::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp b/inference-engine/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp index d8f30c23f2df1f..da62acf4bb5da0 100644 --- a/inference-engine/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp @@ -23,6 +23,7 @@ class ImportNetworkTestBase : public testing::WithParamInterface obj); void Run() override; + void TestRun(bool isModelChanged); protected: std::map exportConfiguration; diff --git a/inference-engine/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp b/inference-engine/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp index c30945dc914d83..c4a0f038dd1349 100644 --- a/inference-engine/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp @@ -42,14 +42,18 @@ void ImportNetworkTestBase::exportImportNetwork() { } void ImportNetworkTestBase::Run() { - SKIP_IF_CURRENT_TEST_IS_DISABLED() + TestRun(false); +} +void ImportNetworkTestBase::TestRun(bool isModelChanged) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + // load export configuration and save outputs configuration.insert(exportConfiguration.begin(), exportConfiguration.end()); LoadNetwork(); GenerateInputs(); Infer(); + auto actualOutputs = GetOutputs(); - const auto& actualOutputs = GetOutputs(); auto referenceOutputs = CalculateRefs(); Compare(referenceOutputs, actualOutputs); @@ -57,6 +61,14 @@ void ImportNetworkTestBase::Run() { configuration[configItem.first] = configItem.second; } + // for import with different scale factor need to use import configuration to get refference outputs. + if (isModelChanged) { + LoadNetwork(); + GenerateInputs(); + Infer(); + actualOutputs = GetOutputs(); + } + const auto compiledExecNetwork = executableNetwork; exportImportNetwork(); const auto importedExecNetwork = executableNetwork; @@ -75,6 +87,7 @@ void ImportNetworkTestBase::Run() { ASSERT_NO_THROW(compiledExecNetwork.GetOutputsInfo()[next_output.first]); } auto importedOutputs = GetOutputs(); + ASSERT_EQ(actualOutputs.size(), importedOutputs.size()); for (size_t i = 0; i < actualOutputs.size(); i++) { diff --git a/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp b/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp index 3c1639b978faf5..b9f679cb2a9a93 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp @@ -313,6 +313,7 @@ void LayerTestsCommon::LoadNetwork() { } void LayerTestsCommon::GenerateInputs() { + inputs.clear(); const auto& inputsInfo = executableNetwork.GetInputsInfo(); const auto& functionParams = function->get_parameters(); for (int i = 0; i < functionParams.size(); ++i) { From 2ada91756972fcf116a40425f7817c136c9c1864 Mon Sep 17 00:00:00 2001 From: Liu Bo Date: Thu, 19 Aug 2021 17:55:27 +0800 Subject: [PATCH 031/102] add doc:'Paddle_Support.md' (#7122) * add doc:'Paddle_Support.md' * Apply suggestions from code review Co-authored-by: Tatiana Savina * Apply suggestions from code review * Update docs/IE_DG/Paddle_Support.md Co-authored-by: Tatiana Savina Co-authored-by: Tatiana Savina --- docs/IE_DG/Paddle_Support.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 docs/IE_DG/Paddle_Support.md diff --git a/docs/IE_DG/Paddle_Support.md b/docs/IE_DG/Paddle_Support.md new file mode 100644 index 00000000000000..03dddc6cdcc392 --- /dev/null +++ b/docs/IE_DG/Paddle_Support.md @@ -0,0 +1,34 @@ +# Paddle Support in the OpenVINOâ„¢ {#openvino_docs_IE_DG_Paddle_Support} + +Starting from the 2022.1 release, OpenVINOâ„¢ supports reading native Paddle models. +`Core::ReadNetwork()` method provides a uniform way to read models from IR or Paddle format, it is a recommended approach to reading models. + +## Read Paddle Models from IR + +After [Converting a Paddle Model](../MO_DG/prepare_model/convert_model/Convert_Model_From_Paddle.md) to [Intermediate Representation (IR)](../MO_DG/IR_and_opsets.md), it can be read as recommended. Example: + +```cpp +InferenceEngine::Core core; +auto network = core.ReadNetwork("model.xml"); +``` + +## Read Paddle Models from Paddle Format (Paddle `inference model` model type) + +**Example:** + +```cpp +InferenceEngine::Core core; +auto network = core.ReadNetwork("model.pdmodel"); +``` + +**Reshape feature:** + +OpenVINOâ„¢ does not provide a mechanism to specify pre-processing, such as mean values subtraction and reverse input channels, for the Paddle format. +If a Paddle model contains dynamic shapes for input, use the `CNNNetwork::reshape` method for shape specialization. + +## NOTE + +* Paddle [`inference model`](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.1/doc/doc_en/inference_en.md) mainly contains two kinds of files `model.pdmodel`(model file) and `model.pdiparams`(params file), which are used for inference. +* Supported Paddle models list and how to export these models are described in [Convert a Paddle Model](../MO_DG/prepare_model/convert_model/Convert_Model_From_Paddle.md). +* For `Normalize` Paddle Models, the input data should be in FP32 format. +* When reading Paddle models from Paddle format, make sure that `model.pdmodel` and `model.pdiparams` are in the same folder directory. From f00f836bb497ccdb1cb8f264422fb7ebcdeab880 Mon Sep 17 00:00:00 2001 From: Olesya Martinyuk Date: Thu, 19 Aug 2021 12:57:47 +0300 Subject: [PATCH 032/102] Remove local configs and it's copying to bin/ for stress tests (#7131) --- tests/stress_tests/README.md | 4 ++-- .../memcheck_tests/CMakeLists.txt | 5 ----- .../local_configs/references_config.xml | 21 ------------------- .../local_configs/test_config.xml | 14 ------------- .../memleaks_tests/CMakeLists.txt | 3 --- .../local_configs/test_config.xml | 20 ------------------ tests/stress_tests/unittests/CMakeLists.txt | 4 ---- .../unittests/local_configs/test_config.xml | 19 ----------------- 8 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 tests/stress_tests/memcheck_tests/local_configs/references_config.xml delete mode 100644 tests/stress_tests/memcheck_tests/local_configs/test_config.xml delete mode 100644 tests/stress_tests/memleaks_tests/local_configs/test_config.xml delete mode 100644 tests/stress_tests/unittests/local_configs/test_config.xml diff --git a/tests/stress_tests/README.md b/tests/stress_tests/README.md index a99146ad180b4f..cc8a2911d16830 100644 --- a/tests/stress_tests/README.md +++ b/tests/stress_tests/README.md @@ -12,8 +12,8 @@ when executing continuously. - StressUnitTests executing various Inference Engine use cases in parallel threads and processes. -Each test refers to configuration files located in `\local_configs` -folder. The configuration files are installed along with tests on build time. +Each test refers to configuration files located in `\.automation` +folder. ## Getting Started diff --git a/tests/stress_tests/memcheck_tests/CMakeLists.txt b/tests/stress_tests/memcheck_tests/CMakeLists.txt index 22661277511b2a..7de857dd2a78d5 100644 --- a/tests/stress_tests/memcheck_tests/CMakeLists.txt +++ b/tests/stress_tests/memcheck_tests/CMakeLists.txt @@ -16,8 +16,3 @@ target_link_libraries(${TARGET_NAME} PRIVATE StressTestsCommon) install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL) -# Copy local configs to BIN_FOLDER -configure_file(local_configs/test_config.xml - ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE}/stress_tests_configs/memcheck_tests/test_config.xml COPYONLY) -configure_file(local_configs/references_config.xml - ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE}/stress_tests_configs/memcheck_tests/references_config.xml COPYONLY) diff --git a/tests/stress_tests/memcheck_tests/local_configs/references_config.xml b/tests/stress_tests/memcheck_tests/local_configs/references_config.xml deleted file mode 100644 index 3c2c5213ff1463..00000000000000 --- a/tests/stress_tests/memcheck_tests/local_configs/references_config.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/stress_tests/memcheck_tests/local_configs/test_config.xml b/tests/stress_tests/memcheck_tests/local_configs/test_config.xml deleted file mode 100644 index cbb163c0a481e8..00000000000000 --- a/tests/stress_tests/memcheck_tests/local_configs/test_config.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - CPU - GPU - - - - - - - - - diff --git a/tests/stress_tests/memleaks_tests/CMakeLists.txt b/tests/stress_tests/memleaks_tests/CMakeLists.txt index da395c4d9fd548..e62a94131100bd 100644 --- a/tests/stress_tests/memleaks_tests/CMakeLists.txt +++ b/tests/stress_tests/memleaks_tests/CMakeLists.txt @@ -15,6 +15,3 @@ target_link_libraries(${TARGET_NAME} PRIVATE StressTestsCommon) install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL) -# Copy local configs to BIN_FOLDER -configure_file(local_configs/test_config.xml - ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE}/stress_tests_configs/memleaks_tests/test_config.xml COPYONLY) diff --git a/tests/stress_tests/memleaks_tests/local_configs/test_config.xml b/tests/stress_tests/memleaks_tests/local_configs/test_config.xml deleted file mode 100644 index ce92ba10d50c13..00000000000000 --- a/tests/stress_tests/memleaks_tests/local_configs/test_config.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - 1 - - - 1 - - - 30 - - - CPU - - - - - - diff --git a/tests/stress_tests/unittests/CMakeLists.txt b/tests/stress_tests/unittests/CMakeLists.txt index 3c6972f9c566d6..58474e6d832f72 100644 --- a/tests/stress_tests/unittests/CMakeLists.txt +++ b/tests/stress_tests/unittests/CMakeLists.txt @@ -14,7 +14,3 @@ target_link_libraries(${TARGET_NAME} PRIVATE StressTestsCommon) install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL) - -# Copy local configs to BIN_FOLDER -configure_file(local_configs/test_config.xml - ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE}/stress_tests_configs/unittests/test_config.xml COPYONLY) diff --git a/tests/stress_tests/unittests/local_configs/test_config.xml b/tests/stress_tests/unittests/local_configs/test_config.xml deleted file mode 100644 index aa988200a41066..00000000000000 --- a/tests/stress_tests/unittests/local_configs/test_config.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - 1 - - - 1 - - - 100 - - - CPU - GPU - - - - - From 4c3f3937c9bc59724590df2075803ee7ef92f184 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 19 Aug 2021 13:28:45 +0300 Subject: [PATCH 033/102] Moved DEPRECATION macro and ITT domains to ov namespace (#7153) * Moved DEPRECATION macro and ITT domains to ov namespace * Fixed code style --- ngraph/core/include/ngraph/deprecated.hpp | 65 ++---------------- .../core/include/openvino/core/deprecated.hpp | 67 +++++++++++++++++++ ngraph/core/src/function.cpp | 14 ++-- ngraph/core/src/itt.hpp | 6 +- ngraph/core/src/node.cpp | 2 +- ngraph/core/src/op/convert_like.cpp | 2 +- ngraph/core/src/op/shape_of.cpp | 4 +- ngraph/core/src/pass/graph_rewrite.cpp | 4 +- ngraph/core/src/pass/manager.cpp | 4 +- ngraph/core/src/specialize_function.cpp | 2 +- 10 files changed, 91 insertions(+), 79 deletions(-) create mode 100644 ngraph/core/include/openvino/core/deprecated.hpp diff --git a/ngraph/core/include/ngraph/deprecated.hpp b/ngraph/core/include/ngraph/deprecated.hpp index 96345557edcbe5..89c95eb7b81526 100644 --- a/ngraph/core/include/ngraph/deprecated.hpp +++ b/ngraph/core/include/ngraph/deprecated.hpp @@ -4,64 +4,9 @@ #pragma once -// -// The NGRAPH_DEPRECATED macro can be used to deprecate a function declaration. For example: -// -// NGRAPH_DEPRECATED("replace with groxify"); -// void frobnicate() -// -// The macro will expand to a deprecation attribute supported by the compiler, -// so any use of `frobnicate` will produce a compiler warning. -// - -#if defined(_WIN32) -# define NGRAPH_DEPRECATED(msg) __declspec(deprecated(msg)) -# if __cplusplus >= 201402L -# define NGRAPH_ENUM_DEPRECATED(msg) [[deprecated(msg)]] -# else -# define NGRAPH_ENUM_DEPRECATED(msg) -# endif -#elif defined(__INTEL_COMPILER) -# define NGRAPH_DEPRECATED(msg) __attribute__((deprecated(msg))) -# define NGRAPH_ENUM_DEPRECATED(msg) NGRAPH_DEPRECATED(msg) -#elif defined(__GNUC__) -# define NGRAPH_DEPRECATED(msg) __attribute__((deprecated((msg)))) -# if __GNUC__ < 6 && !defined(__clang__) -# define NGRAPH_ENUM_DEPRECATED(msg) -# else -# define NGRAPH_ENUM_DEPRECATED(msg) NGRAPH_DEPRECATED(msg) -# endif -#else -# define NGRAPH_DEPRECATED(msg) -# define NGRAPH_ENUM_DEPRECATED(msg) -#endif - -// Suppress warning "-Wdeprecated-declarations" / C4996 -#if defined(_MSC_VER) -# define NGRAPH_DO_PRAGMA(x) __pragma(x) -#elif defined(__GNUC__) -# define NGRAPH_DO_PRAGMA(x) _Pragma(# x) -#else -# define NGRAPH_DO_PRAGMA(x) -#endif +#include "openvino/core/deprecated.hpp" -#if defined(_MSC_VER) && !defined(__clang__) -# define NGRAPH_SUPPRESS_DEPRECATED_START \ - NGRAPH_DO_PRAGMA(warning(push)) \ - NGRAPH_DO_PRAGMA(warning(disable : 4996)) -# define NGRAPH_SUPPRESS_DEPRECATED_END NGRAPH_DO_PRAGMA(warning(pop)) -#elif defined(__INTEL_COMPILER) -# define NGRAPH_SUPPRESS_DEPRECATED_START \ - NGRAPH_DO_PRAGMA(warning(push)) \ - NGRAPH_DO_PRAGMA(warning(disable : 1478)) -NGRAPH_DO_PRAGMA(warning(disable : 1786)) -# define NGRAPH_SUPPRESS_DEPRECATED_END NGRAPH_DO_PRAGMA(warning(pop)) -#elif defined(__clang__) || ((__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 405)) -# define NGRAPH_SUPPRESS_DEPRECATED_START \ - NGRAPH_DO_PRAGMA(GCC diagnostic push) \ - NGRAPH_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations") -# define NGRAPH_SUPPRESS_DEPRECATED_END NGRAPH_DO_PRAGMA(GCC diagnostic pop) -#else -# define NGRAPH_SUPPRESS_DEPRECATED_START -# define NGRAPH_SUPPRESS_DEPRECATED_END -#endif +#define NGRAPH_DEPRECATED(msg) OPENVINO_DEPRECATED(msg) +#define NGRAPH_ENUM_DEPRECATED(msg) OPENVINO_ENUM_DEPRECATED(msg) +#define NGRAPH_SUPPRESS_DEPRECATED_START OPENVINO_SUPPRESS_DEPRECATED_START +#define NGRAPH_SUPPRESS_DEPRECATED_END OPENVINO_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/include/openvino/core/deprecated.hpp b/ngraph/core/include/openvino/core/deprecated.hpp new file mode 100644 index 00000000000000..2d885ba9439705 --- /dev/null +++ b/ngraph/core/include/openvino/core/deprecated.hpp @@ -0,0 +1,67 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +// +// The OPENVINO_DEPRECATED macro can be used to deprecate a function declaration. For example: +// +// OPENVINO_DEPRECATED("replace with groxify"); +// void frobnicate() +// +// The macro will expand to a deprecation attribute supported by the compiler, +// so any use of `frobnicate` will produce a compiler warning. +// + +#if defined(_WIN32) +# define OPENVINO_DEPRECATED(msg) __declspec(deprecated(msg)) +# if __cplusplus >= 201402L +# define OPENVINO_ENUM_DEPRECATED(msg) [[deprecated(msg)]] +# else +# define OPENVINO_ENUM_DEPRECATED(msg) +# endif +#elif defined(__INTEL_COMPILER) +# define OPENVINO_DEPRECATED(msg) __attribute__((deprecated(msg))) +# define OPENVINO_ENUM_DEPRECATED(msg) OPENVINO_DEPRECATED(msg) +#elif defined(__GNUC__) +# define OPENVINO_DEPRECATED(msg) __attribute__((deprecated((msg)))) +# if __GNUC__ < 6 && !defined(__clang__) +# define OPENVINO_ENUM_DEPRECATED(msg) +# else +# define OPENVINO_ENUM_DEPRECATED(msg) OPENVINO_DEPRECATED(msg) +# endif +#else +# define OPENVINO_DEPRECATED(msg) +# define OPENVINO_ENUM_DEPRECATED(msg) +#endif + +// Suppress warning "-Wdeprecated-declarations" / C4996 +#if defined(_MSC_VER) +# define OPENVINO_DO_PRAGMA(x) __pragma(x) +#elif defined(__GNUC__) +# define OPENVINO_DO_PRAGMA(x) _Pragma(# x) +#else +# define OPENVINO_DO_PRAGMA(x) +#endif + +#if defined(_MSC_VER) && !defined(__clang__) +# define OPENVINO_SUPPRESS_DEPRECATED_START \ + OPENVINO_DO_PRAGMA(warning(push)) \ + OPENVINO_DO_PRAGMA(warning(disable : 4996)) +# define OPENVINO_SUPPRESS_DEPRECATED_END OPENVINO_DO_PRAGMA(warning(pop)) +#elif defined(__INTEL_COMPILER) +# define OPENVINO_SUPPRESS_DEPRECATED_START \ + OPENVINO_DO_PRAGMA(warning(push)) \ + OPENVINO_DO_PRAGMA(warning(disable : 1478)) +OPENVINO_DO_PRAGMA(warning(disable : 1786)) +# define OPENVINO_SUPPRESS_DEPRECATED_END OPENVINO_DO_PRAGMA(warning(pop)) +#elif defined(__clang__) || ((__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 405)) +# define OPENVINO_SUPPRESS_DEPRECATED_START \ + OPENVINO_DO_PRAGMA(GCC diagnostic push) \ + OPENVINO_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations") +# define OPENVINO_SUPPRESS_DEPRECATED_END OPENVINO_DO_PRAGMA(GCC diagnostic pop) +#else +# define OPENVINO_SUPPRESS_DEPRECATED_START +# define OPENVINO_SUPPRESS_DEPRECATED_END +#endif diff --git a/ngraph/core/src/function.cpp b/ngraph/core/src/function.cpp index d52052c61eac7f..c3c3375b224aed 100644 --- a/ngraph/core/src/function.cpp +++ b/ngraph/core/src/function.cpp @@ -26,7 +26,7 @@ constexpr DiscreteTypeInfo Function::type_info; atomic Function::m_next_instance_id(0); void check_all_variables_registered(const std::vector>& ordered_ops, const VariableVector& variables) { - OV_ITT_SCOPED_TASK(ngraph::itt::domains::nGraphPass_LT, "Function::check_all_variables_registered"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraphPass_LT, "Function::check_all_variables_registered"); std::stringstream unregistered_variables; for (auto& node : ordered_ops) { const auto& variable_op = dynamic_pointer_cast(node); @@ -40,7 +40,7 @@ void check_all_variables_registered(const std::vector>& ordered void check_all_parameters_registered(const std::vector>& ordered_ops, const ParameterVector& parameters) { - OV_ITT_SCOPED_TASK(ngraph::itt::domains::nGraph, "Function::check_all_parameters_registered"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::check_all_parameters_registered"); std::stringstream unregistered_parameters; for (auto& node : ordered_ops) { @@ -52,7 +52,7 @@ void check_all_parameters_registered(const std::vector>& ordere } VariableVector auto_detect_variables(const std::vector>& ordered_ops) { - OV_ITT_SCOPED_TASK(ngraph::itt::domains::nGraph, "Function::auto_detect_variables"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::auto_detect_variables"); unordered_set variables; for (const auto& op : ordered_ops) { if (const auto& variable_op = dynamic_pointer_cast(op)) { @@ -63,7 +63,7 @@ VariableVector auto_detect_variables(const std::vector>& o } ParameterVector auto_detect_parameters(const std::vector>& ordered_ops) { - OV_ITT_SCOPED_TASK(ngraph::itt::domains::nGraph, "Function::auto_detect_parameters"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::auto_detect_parameters"); ParameterVector parameter_vector; for (const auto& op : ordered_ops) { if (const auto& param = dynamic_pointer_cast(op)) { @@ -168,7 +168,7 @@ Function::Function(const OutputVector& results, const SinkVector& sinks, const s Function::Function(const OutputVector& results, const string& name) : Function(results, SinkVector{}, name) {} void Function::prerequirements(bool detect_variables, bool detect_parameters) { - OV_ITT_SCOPED_TASK(ngraph::itt::domains::nGraph, "Function::prerequirements"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::prerequirements"); const auto& ordered_ops = get_ordered_ops(); if (detect_parameters) @@ -183,7 +183,7 @@ void Function::prerequirements(bool detect_variables, bool detect_parameters) { } void Function::validate_nodes_and_infer_types() const { - OV_ITT_SCOPED_TASK(ngraph::itt::domains::nGraph, "Function::validate_nodes_and_infer_types"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::validate_nodes_and_infer_types"); struct Counter { int cnt_assign = 0; @@ -223,7 +223,7 @@ void Function::validate_nodes_and_infer_types() const { } std::vector> Function::get_ordered_ops() const { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "Function::get_ordered_ops"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::get_ordered_ops"); vector> nodes; for (auto& r : get_results()) { diff --git a/ngraph/core/src/itt.hpp b/ngraph/core/src/itt.hpp index 9d96091a247083..1f602780957989 100644 --- a/ngraph/core/src/itt.hpp +++ b/ngraph/core/src/itt.hpp @@ -14,7 +14,7 @@ #include -namespace ngraph { +namespace ov { namespace itt { namespace domains { OV_ITT_DOMAIN(nGraph); @@ -22,7 +22,7 @@ OV_ITT_DOMAIN(nGraphPass_LT); OV_ITT_DOMAIN(ngraph_op, "nGraph::Op"); } // namespace domains } // namespace itt -} // namespace ngraph +} // namespace ov OV_CC_DOMAINS(ngraph_op); OV_ITT_DOMAIN(SIMPLE_ngraph_pass); @@ -38,7 +38,7 @@ OV_ITT_DOMAIN(SIMPLE_ngraph_pass); throw ngraph::ngraph_error(std::string(OV_PP_TOSTRING(OV_PP_CAT3(ngraph_op, _, region))) + " is disabled!") # define NGRAPH_PASS_CALLBACK(matcher) #else -# define NGRAPH_OP_SCOPE(region) OV_ITT_SCOPED_TASK(ngraph::itt::domains::ngraph_op, OV_PP_TOSTRING(region)) +# define NGRAPH_OP_SCOPE(region) OV_ITT_SCOPED_TASK(ov::itt::domains::ngraph_op, OV_PP_TOSTRING(region)) # define NGRAPH_PASS_CALLBACK(matcher) #endif diff --git a/ngraph/core/src/node.cpp b/ngraph/core/src/node.cpp index 4ee13cb8464443..cbc1c9611dfdfc 100644 --- a/ngraph/core/src/node.cpp +++ b/ngraph/core/src/node.cpp @@ -800,7 +800,7 @@ bool Node::evaluate_upper(const HostTensorVector& output_values) const { } bool Node::constant_fold(OutputVector& output_values, const OutputVector& input_values) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "Node::constant_fold"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Node::constant_fold"); if (m_rt_info.count("DISABLED_CONSTANT_FOLDING")) { return false; diff --git a/ngraph/core/src/op/convert_like.cpp b/ngraph/core/src/op/convert_like.cpp index 609ddb76993959..b036e5e194a7af 100644 --- a/ngraph/core/src/op/convert_like.cpp +++ b/ngraph/core/src/op/convert_like.cpp @@ -36,7 +36,7 @@ shared_ptr op::v1::ConvertLike::clone_with_new_inputs(const OutputVector& } bool op::v1::ConvertLike::constant_fold(OutputVector& output_values, const OutputVector& input_values) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "op::v1::ConvertLike::constant_fold"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "op::v1::ConvertLike::constant_fold"); if (auto data_const = std::dynamic_pointer_cast(input_values[0].get_node_shared_ptr())) { auto convert = make_shared(input_values[0], input_values[1].get_element_type()); convert->constant_fold(output_values, OutputVector{data_const}); diff --git a/ngraph/core/src/op/shape_of.cpp b/ngraph/core/src/op/shape_of.cpp index 3480ca5f0e3401..69090af304a569 100644 --- a/ngraph/core/src/op/shape_of.cpp +++ b/ngraph/core/src/op/shape_of.cpp @@ -173,7 +173,7 @@ bool op::v3::ShapeOf::evaluate_upper(const HostTensorVector& output_values) cons } bool op::v3::ShapeOf::constant_fold(OutputVector& output_values, const OutputVector& input_values) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "op::v3::ShapeOf::constant_fold"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "op::v3::ShapeOf::constant_fold"); if (get_rt_info().count("DISABLED_CONSTANT_FOLDING")) return false; return shape_of::constant_fold_shape_of(this, output_values[0], input_values[0]); @@ -232,7 +232,7 @@ bool op::v0::ShapeOf::has_evaluate() const { } bool op::v0::ShapeOf::constant_fold(OutputVector& output_values, const OutputVector& input_values) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "op::v0::ShapeOf::constant_fold"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "op::v0::ShapeOf::constant_fold"); if (get_rt_info().count("DISABLED_CONSTANT_FOLDING")) return false; return shape_of::constant_fold_shape_of(this, output_values[0], input_values[0]); diff --git a/ngraph/core/src/pass/graph_rewrite.cpp b/ngraph/core/src/pass/graph_rewrite.cpp index c56c8e1f9374d5..07e8472ce47cc8 100644 --- a/ngraph/core/src/pass/graph_rewrite.cpp +++ b/ngraph/core/src/pass/graph_rewrite.cpp @@ -89,7 +89,7 @@ bool pass::GraphRewrite::run_on_function(std::shared_ptr f) { } bool pass::GraphRewrite::apply_matcher_passes(shared_ptr f, deque> nodes_to_run) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "pass::GraphRewrite::run_on_function"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "pass::GraphRewrite::run_on_function"); bool rewritten = false; const auto& pass_config = get_pass_config(); @@ -377,7 +377,7 @@ void ngraph::pass::MatcherPass::register_matcher(const std::shared_ptr node) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, pass::internal::perf_counters_graph_rewrite()[get_type_info()]); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, pass::internal::perf_counters_graph_rewrite()[get_type_info()]); m_new_nodes.clear(); if (m_handler) return m_handler(node); diff --git a/ngraph/core/src/pass/manager.cpp b/ngraph/core/src/pass/manager.cpp index 113e162ece52f6..5aeb9180670d39 100644 --- a/ngraph/core/src/pass/manager.cpp +++ b/ngraph/core/src/pass/manager.cpp @@ -46,7 +46,7 @@ pass::Manager::~Manager() {} pass::Manager::Manager(std::shared_ptr pass_config) : m_pass_config(std::move(pass_config)) {} void pass::Manager::run_passes(shared_ptr func) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "pass::Manager::run_passes"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "pass::Manager::run_passes"); static bool profile_enabled = getenv_bool("NGRAPH_PROFILE_PASS_ENABLE"); @@ -62,7 +62,7 @@ void pass::Manager::run_passes(shared_ptr func) { } OV_ITT_SCOPE(FIRST_INFERENCE, - itt::domains::nGraphPass_LT, + ov::itt::domains::nGraphPass_LT, pass::internal::perf_counters()[pass->get_type_info()]); pass_timer.start(); diff --git a/ngraph/core/src/specialize_function.cpp b/ngraph/core/src/specialize_function.cpp index 232eaf6edd232c..418b3434129649 100644 --- a/ngraph/core/src/specialize_function.cpp +++ b/ngraph/core/src/specialize_function.cpp @@ -18,7 +18,7 @@ std::shared_ptr ngraph::specialize_function(std::shared_ptr const std::vector& parameter_values) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "specialize_function"); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "specialize_function"); NGRAPH_CHECK(f->get_parameters().size() == parameter_shapes.size()); NGRAPH_CHECK(f->get_parameters().size() == parameter_element_types.size()); From 642d8a2b4432c214465f9e80c253acdfc39e5af9 Mon Sep 17 00:00:00 2001 From: Gleb Kazantaev Date: Thu, 19 Aug 2021 17:24:41 +0300 Subject: [PATCH 034/102] Enable NormalizeL2Fusion and LeakyReluFusion inside MOC (#7096) * Enable NormalizeL2Fusion inside MOC * Fix NormalizewL2 decomposition (KeepDims=True) --- .../src/mkldnn_plugin/mkldnn_plugin.cpp | 24 ++-- .../src/moc_transformations.cpp | 4 + .../normalize_l2_fusion.hpp | 31 +---- .../normalize_l2_decomposition.hpp | 32 ++++++ .../common_optimizations.cpp | 2 + .../leaky_relu_fusion.cpp | 5 +- .../normalize_l2_fusion.cpp | 107 ++++++------------ .../normalize_l2_decomposition.cpp | 56 +++++++++ .../normalize_l2_decomposition_test.cpp | 91 +++++++++++++++ .../normalize_l2_fusion_test.cpp | 42 ++++--- 10 files changed, 258 insertions(+), 136 deletions(-) create mode 100644 inference-engine/src/transformations/include/transformations/op_conversions/normalize_l2_decomposition.hpp create mode 100644 inference-engine/src/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp create mode 100644 inference-engine/tests/functional/inference_engine/transformations/normalize_l2_decomposition_test.cpp diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index a702c6d71ee35b..29820837762166 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -24,9 +24,7 @@ #include #include #include "transformations/common_optimizations/convert_quantize_dequantize.hpp" -#include #include -#include #include #include #include @@ -37,9 +35,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -53,7 +51,6 @@ #include #include #include -#include #include #include #include @@ -249,8 +246,9 @@ static void Transformation(CNNNetwork& clonedNetwork, const Config& conf) { return false; }; - pass_config->set_callback( + pass_config->set_callback( [isSequencePrimitiveSupported](const_node_ptr &node) -> bool { return isSequencePrimitiveSupported(node); }); @@ -280,18 +278,17 @@ static void Transformation(CNNNetwork& clonedNetwork, const Config& conf) { return MKLDNNMVNNode::isSupportedOperation(node, errorMessage); }); + pass_config->set_callback( + [](const_node_ptr &node) -> bool { + std::string errorMsg; + return MKLDNNNormalizeL2Node::isSupportedOperation(node, errorMsg); + }); + pass_config->set_callback( [](const_node_ptr &node) -> bool { return node->input_value(0).get_partial_shape().rank().get_length() > 5; }); - auto normalizeL2FusionCallback = [](const_node_ptr &node) -> bool { - std::string errorMsg; - return !MKLDNNNormalizeL2Node::isSupportedOperation(node, errorMsg); - }; - pass_config->set_callback(normalizeL2FusionCallback); - pass_config->set_callback(normalizeL2FusionCallback); - // List of enabled/disabled transformations pass_config->disable(); pass_config->disable(); @@ -308,6 +305,7 @@ static void Transformation(CNNNetwork& clonedNetwork, const Config& conf) { pass_config->disable(); pass_config->disable(); + pass_config->enable(); pass_config->enable(); pass_config->enable(); pass_config->enable(); diff --git a/inference-engine/src/offline_transformations/src/moc_transformations.cpp b/inference-engine/src/offline_transformations/src/moc_transformations.cpp index 1a23f72e6078cf..9852c5e4b995dd 100644 --- a/inference-engine/src/offline_transformations/src/moc_transformations.cpp +++ b/inference-engine/src/offline_transformations/src/moc_transformations.cpp @@ -35,6 +35,8 @@ #include #include #include +#include +#include NGRAPH_RTTI_DEFINITION(ngraph::pass::MOCTransformations, "MOCTransformations", 0); @@ -79,11 +81,13 @@ bool ngraph::pass::MOCTransformations::run_on_function(std::shared_ptradd_matcher(); common_fusions->add_matcher(); common_fusions->add_matcher(); + common_fusions->add_matcher(); common_fusions->add_matcher(); common_fusions->add_matcher(); common_fusions->add_matcher(); common_fusions->add_matcher(); common_fusions->add_matcher(); + common_fusions->add_matcher(); common_fusions->set_name("ngraph::pass::CommonFusions"); manager.register_pass(); diff --git a/inference-engine/src/transformations/include/transformations/common_optimizations/normalize_l2_fusion.hpp b/inference-engine/src/transformations/include/transformations/common_optimizations/normalize_l2_fusion.hpp index 1f5106ebe0b760..f3b435c9e14656 100644 --- a/inference-engine/src/transformations/include/transformations/common_optimizations/normalize_l2_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/common_optimizations/normalize_l2_fusion.hpp @@ -15,43 +15,18 @@ namespace ngraph { namespace pass { class TRANSFORMATIONS_API NormalizeL2Fusion; -class TRANSFORMATIONS_API NormalizeL2FusionWithMax; -class TRANSFORMATIONS_API NormalizeL2FusionWithAdd; } // namespace pass } // namespace ngraph /** * @ingroup ie_transformation_common_api - * @brief NormalizeL2FusionWithMax transformation replaces a sub-graph + * @brief NormalizeL2Fusion transformation replaces various sub-graphs with a NormalizeL2 op: * x/(max(sqrt(sum(x[j0, ..., jN]**2), eps)) with a NormalizeL2 op. - */ -class ngraph::pass::NormalizeL2FusionWithMax: public ngraph::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - NormalizeL2FusionWithMax(); -}; - -/** - * @ingroup ie_transformation_common_api - * @brief NormalizeL2FusionWithAdd transformation replaces a sub-graph * x/(add(sqrt(sum(x[j0, ..., jN]**2), eps)) with a NormalizeL2 op. */ -class ngraph::pass::NormalizeL2FusionWithAdd: public ngraph::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - NormalizeL2FusionWithAdd(); -}; - -/** - * @ingroup ie_transformation_common_api - * @brief NormalizeL2Fusion transformation replaces various sub-graphs with a NormalizeL2 op. - */ -class ngraph::pass::NormalizeL2Fusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::NormalizeL2Fusion: public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; - NormalizeL2Fusion() { - add_matcher(); - add_matcher(); - } + NormalizeL2Fusion(); }; \ No newline at end of file diff --git a/inference-engine/src/transformations/include/transformations/op_conversions/normalize_l2_decomposition.hpp b/inference-engine/src/transformations/include/transformations/op_conversions/normalize_l2_decomposition.hpp new file mode 100644 index 00000000000000..d6c6c8091b7a3e --- /dev/null +++ b/inference-engine/src/transformations/include/transformations/op_conversions/normalize_l2_decomposition.hpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include + +#include +#include +#include "ngraph/pattern/matcher.hpp" + +namespace ngraph { +namespace pass { + +class TRANSFORMATIONS_API NormalizeL2Decomposition; + +} // namespace pass +} // namespace ngraph + +/** + * @ingroup ie_transformation_common_api + * @brief Decomposes NormalizeL2 into subgraph + */ +class ngraph::pass::NormalizeL2Decomposition: public ngraph::pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + NormalizeL2Decomposition(); +}; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 29405d08a7d3ab..373e34f9a018f0 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -78,6 +78,7 @@ #include #include #include +#include NGRAPH_RTTI_DEFINITION(ngraph::pass::CommonOptimizations, "CommonOptimizations", 0); @@ -160,6 +161,7 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptradd_matcher(); decomp->add_matcher(); decomp->add_matcher(); + decomp->add_matcher(); decomp->add_matcher(); decomp->add_matcher(); decomp->add_matcher(); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp index 388d2f171041f3..45ee376fe239f8 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp @@ -24,14 +24,13 @@ ngraph::pass::LeakyReluFusion::LeakyReluFusion() { auto max_pattern = ngraph::pattern::wrap_type({data_pattern, multiply_pattern}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto pattern_map = m.get_pattern_value_map(); - auto data = pattern_map.at(data_pattern); + const auto & pattern_map = m.get_pattern_value_map(); const auto & original_alpha_pattern = pattern_map.at(alpha_pattern); if (shape_size(original_alpha_pattern.get_shape()) != 1) return false; - auto leaky_relu = register_new_node(data, original_alpha_pattern); + auto leaky_relu = register_new_node(pattern_map.at(data_pattern), original_alpha_pattern); auto maximum = pattern_map.at(max_pattern); leaky_relu->set_friendly_name(maximum.get_node()->get_friendly_name()); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp index 22aac2e1c71d33..11147d815cd3a8 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp @@ -9,34 +9,37 @@ #include #include -#include +#include #include #include +#include NGRAPH_RTTI_DEFINITION(ngraph::pass::NormalizeL2Fusion, "NormalizeL2Fusion", 0); -NGRAPH_RTTI_DEFINITION(ngraph::pass::NormalizeL2FusionWithMax, "NormalizeL2FusionWithMax", 0); - -ngraph::pass::NormalizeL2FusionWithMax::NormalizeL2FusionWithMax() { - MATCHER_SCOPE(NormalizeL2FusionWithMax); +ngraph::pass::NormalizeL2Fusion::NormalizeL2Fusion() { + MATCHER_SCOPE(NormalizeL2Fusion); auto input = ngraph::pattern::any_input(); - auto exp = ngraph::pattern::wrap_type(); - auto pow = std::make_shared(input, exp); - auto axes = ngraph::pattern::wrap_type(); - auto reduce_sum = std::make_shared(pow, axes); - auto eps_const = ngraph::pattern::wrap_type(); - auto max = std::make_shared(reduce_sum, eps_const); - auto sqrt = std::make_shared(max); - auto divide = std::make_shared(input, sqrt); + auto exp = ngraph::pattern::wrap_type(); + auto pow = std::make_shared(input, exp); + auto axes = ngraph::pattern::wrap_type(); + auto reduce_sum = std::make_shared(pow, axes); + auto eps_const = ngraph::pattern::wrap_type(); + + auto max = std::make_shared(reduce_sum, eps_const); + auto add = std::make_shared(reduce_sum, eps_const); + auto max_or_add = std::make_shared(OutputVector{max, add}); - ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { - auto& pattern_to_output = m.get_pattern_value_map(); + auto sqrt = std::make_shared(max_or_add); + auto divide = std::make_shared(input, sqrt); + + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); const auto data_input = pattern_to_output.at(input); - const auto exp_input = std::dynamic_pointer_cast(pattern_to_output.at(exp).get_node_shared_ptr()); - const auto axes_input = std::dynamic_pointer_cast(pattern_to_output.at(axes).get_node_shared_ptr()); - const auto eps_attr = std::dynamic_pointer_cast(pattern_to_output.at(eps_const).get_node_shared_ptr()); + const auto exp_input = std::dynamic_pointer_cast(pattern_to_output.at(exp).get_node_shared_ptr()); + const auto axes_input = std::dynamic_pointer_cast(pattern_to_output.at(axes).get_node_shared_ptr()); + const auto eps_attr = std::dynamic_pointer_cast(pattern_to_output.at(eps_const).get_node_shared_ptr()); if (!exp_input || !axes_input || !eps_attr) { return false; @@ -51,63 +54,19 @@ ngraph::pass::NormalizeL2FusionWithMax::NormalizeL2FusionWithMax() { } const auto eps_attr_value = eps_attr->cast_vector()[0]; - auto normalize_l2 = std::make_shared(data_input, axes_input, eps_attr_value, op::EpsMode::MAX); - if (transformation_callback(normalize_l2)) - return false; - - normalize_l2->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({pattern_to_output.at(pow).get_node_shared_ptr(), - pattern_to_output.at(reduce_sum).get_node_shared_ptr(), - pattern_to_output.at(sqrt).get_node_shared_ptr(), - pattern_to_output.at(max).get_node_shared_ptr(), - pattern_to_output.at(divide).get_node_shared_ptr() - }, - normalize_l2); - ngraph::replace_node(m.get_match_root(), normalize_l2); - return true; - }; - - auto m = std::make_shared(divide, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -NGRAPH_RTTI_DEFINITION(ngraph::pass::NormalizeL2FusionWithAdd, "NormalizeL2FusionWithAdd", 0); - -ngraph::pass::NormalizeL2FusionWithAdd::NormalizeL2FusionWithAdd() { - MATCHER_SCOPE(NormalizeL2FusionWithAdd); - auto input = ngraph::pattern::any_input(); - - auto exp = ngraph::pattern::wrap_type(); - auto pow = std::make_shared(input, exp); - auto axes = ngraph::pattern::wrap_type(); - auto reduce_sum = std::make_shared(pow, axes); - auto eps_const = ngraph::pattern::wrap_type(); - auto add = std::make_shared(reduce_sum, eps_const); - auto sqrt = std::make_shared(add); - auto divide = std::make_shared(input, sqrt); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto& pattern_to_output = m.get_pattern_value_map(); - - const auto data_input = pattern_to_output.at(input); - const auto exp_input = std::dynamic_pointer_cast(pattern_to_output.at(exp).get_node_shared_ptr()); - const auto axes_input = std::dynamic_pointer_cast(pattern_to_output.at(axes).get_node_shared_ptr()); - const auto eps_attr = std::dynamic_pointer_cast(pattern_to_output.at(eps_const).get_node_shared_ptr()); - - if (!exp_input || !axes_input || !eps_attr) { - return false; - } - - const bool is_square_pow = shape_size(exp_input->get_shape()) <= 1 && exp_input->cast_vector()[0] == 2; - if (!is_square_pow) { - return false; - } - if (shape_size(eps_attr->get_shape()) > 1) { + op::EpsMode mode; + Output eps_node; + if (pattern_to_output.count(max)) { + mode = op::EpsMode::MAX; + eps_node = pattern_to_output.at(max); + } else if (pattern_to_output.count(add)) { + mode = op::EpsMode::ADD; + eps_node = pattern_to_output.at(add); + } else { return false; } - const auto eps_attr_value = op::util::has_constant_value(exp_input, 2.0f); - auto normalize_l2 = std::make_shared(data_input, axes_input, eps_attr_value, op::EpsMode::ADD); + auto normalize_l2 = std::make_shared(data_input, axes_input, eps_attr_value, mode); if (transformation_callback(normalize_l2)) return false; @@ -115,8 +74,8 @@ ngraph::pass::NormalizeL2FusionWithAdd::NormalizeL2FusionWithAdd() { ngraph::copy_runtime_info({pattern_to_output.at(pow).get_node_shared_ptr(), pattern_to_output.at(reduce_sum).get_node_shared_ptr(), pattern_to_output.at(sqrt).get_node_shared_ptr(), - pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(divide).get_node_shared_ptr() + pattern_to_output.at(divide).get_node_shared_ptr(), + eps_node.get_node_shared_ptr() }, normalize_l2); ngraph::replace_node(m.get_match_root(), normalize_l2); diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp new file mode 100644 index 00000000000000..cfbb6e1d0e18af --- /dev/null +++ b/inference-engine/src/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp @@ -0,0 +1,56 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "itt.hpp" +#include "transformations/op_conversions/normalize_l2_decomposition.hpp" + +#include + +#include +#include +#include + +NGRAPH_RTTI_DEFINITION(ngraph::pass::NormalizeL2Decomposition, "NormalizeL2Decomposition", 0); + +ngraph::pass::NormalizeL2Decomposition::NormalizeL2Decomposition() { + MATCHER_SCOPE(NormalizeL2Decomposition); + auto normalize_l2_pattern = ngraph::pattern::wrap_type(); + + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + auto normalize_l2 = std::dynamic_pointer_cast(m.get_match_root()); + + if (!normalize_l2 || transformation_callback(normalize_l2)) { + return false; + } + + auto power = std::make_shared(normalize_l2->input_value(0), + opset8::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {2.0})); + auto reduce_sum = std::make_shared(power, normalize_l2->input_value(1), true); + + std::shared_ptr eps_node; + auto eps_const_node = opset8::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {normalize_l2->get_eps()}); + switch (normalize_l2->get_eps_mode()) { + case op::EpsMode::ADD: + eps_node = std::make_shared(reduce_sum, eps_const_node); + break; + case op::EpsMode::MAX: + eps_node = std::make_shared(reduce_sum, eps_const_node); + break; + default: + return false; + } + + auto sqrt = std::make_shared(eps_node); + auto div = std::make_shared(normalize_l2->input_value(0), sqrt); + + div->set_friendly_name(normalize_l2->get_friendly_name()); + ngraph::copy_runtime_info(normalize_l2, {power, reduce_sum, eps_node, sqrt, div}); + ngraph::replace_node(normalize_l2, div); + return true; + }; + + auto m = std::make_shared(normalize_l2_pattern, matcher_name); + register_matcher(m, callback); +} + diff --git a/inference-engine/tests/functional/inference_engine/transformations/normalize_l2_decomposition_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/normalize_l2_decomposition_test.cpp new file mode 100644 index 00000000000000..668331ff45a17c --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/transformations/normalize_l2_decomposition_test.cpp @@ -0,0 +1,91 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "common_test_utils/ngraph_test_utils.hpp" + +using namespace testing; + +TEST(TransformationTests, NormalizeL2DecomositionFusionWithMax) { + std::shared_ptr f, f_ref; + const float eps_value = 0.000099f; + { + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(3)); + auto axes_const = ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 2}); + auto normalize_l2 = std::make_shared(input, axes_const, eps_value, ngraph::op::EpsMode::MAX); + + f = std::make_shared(ngraph::NodeVector{normalize_l2}, ngraph::ParameterVector{input}); + + ngraph::pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(3)); + auto exp = ngraph::opset8::Constant::create(ngraph::element::f16, ngraph::Shape{}, {2.f}); + auto pow = std::make_shared(input, exp); + auto axes_const = ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 2}); + auto reduce_sum = std::make_shared(pow, axes_const, true); + auto eps_const = ngraph::opset8::Constant::create(ngraph::element::f16, ngraph::Shape{}, {eps_value}); + auto max = std::make_shared(reduce_sum, eps_const); + auto sqrt = std::make_shared(max); + auto divide = std::make_shared(input, sqrt); + + f_ref = std::make_shared(ngraph::NodeVector{divide}, ngraph::ParameterVector{input}); + } + + const auto fc = FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); + const auto res = fc.compare(f, f_ref); + ASSERT_TRUE(res.valid) << res.message; +} + +TEST(TransformationTests, NormalizeL2DecomositionFusionWithAdd) { + std::shared_ptr f, f_ref; + const float eps_value = 0.000099f; + { + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(3)); + auto axes_const = ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {0, 1}); + auto normalize_l2 = std::make_shared(input, axes_const, eps_value, ngraph::op::EpsMode::ADD); + + f = std::make_shared(ngraph::NodeVector{normalize_l2}, ngraph::ParameterVector{input}); + + ngraph::pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(3)); + auto exp = ngraph::opset8::Constant::create(ngraph::element::f16, ngraph::Shape{}, {2.f}); + auto pow = std::make_shared(input, exp); + auto axes_const = ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {0, 1}); + auto reduce_sum = std::make_shared(pow, axes_const, true); + auto eps_const = ngraph::opset8::Constant::create(ngraph::element::f16, ngraph::Shape{}, {eps_value}); + auto max = std::make_shared(reduce_sum, eps_const); + auto sqrt = std::make_shared(max); + auto divide = std::make_shared(input, sqrt); + + f_ref = std::make_shared(ngraph::NodeVector{divide}, ngraph::ParameterVector{input}); + } + + const auto fc = FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); + const auto res = fc.compare(f, f_ref); + ASSERT_TRUE(res.valid) << res.message; +} diff --git a/inference-engine/tests/functional/inference_engine/transformations/normalize_l2_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/normalize_l2_fusion_test.cpp index f1d496013a407c..fecf5c05b22821 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/normalize_l2_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/normalize_l2_fusion_test.cpp @@ -36,7 +36,7 @@ TEST(TransformationTests, NormalizeL2FusionWithMax) { ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } @@ -49,8 +49,9 @@ TEST(TransformationTests, NormalizeL2FusionWithMax) { f_ref = std::make_shared(ngraph::NodeVector{normalize_l2}, ngraph::ParameterVector{input}); } - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; + const auto fc = FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); + const auto res = fc.compare(f, f_ref); + ASSERT_TRUE(res.valid) << res.message; } TEST(TransformationTests, NormalizeL2FusionWithMaxIncorrectExp) { @@ -71,7 +72,7 @@ TEST(TransformationTests, NormalizeL2FusionWithMaxIncorrectExp) { ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); } @@ -89,8 +90,9 @@ TEST(TransformationTests, NormalizeL2FusionWithMaxIncorrectExp) { f_ref = std::make_shared(ngraph::NodeVector{divide}, ngraph::ParameterVector{input}); } - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; + const auto fc = FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); + const auto res = fc.compare(f, f_ref); + ASSERT_TRUE(res.valid) << res.message; } TEST(TransformationTests, NormalizeL2FusionWithMaxIncorrectEpsValueShape) { @@ -110,7 +112,7 @@ TEST(TransformationTests, NormalizeL2FusionWithMaxIncorrectEpsValueShape) { ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); } @@ -128,8 +130,9 @@ TEST(TransformationTests, NormalizeL2FusionWithMaxIncorrectEpsValueShape) { f_ref = std::make_shared(ngraph::NodeVector{divide}, ngraph::ParameterVector{input}); } - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; + const auto fc = FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); + const auto res = fc.compare(f, f_ref); + ASSERT_TRUE(res.valid) << res.message; } TEST(TransformationTests, NormalizeL2FusionWithAdd) { @@ -150,7 +153,7 @@ TEST(TransformationTests, NormalizeL2FusionWithAdd) { ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } @@ -163,8 +166,9 @@ TEST(TransformationTests, NormalizeL2FusionWithAdd) { f_ref = std::make_shared(ngraph::NodeVector{normalize_l2}, ngraph::ParameterVector{input}); } - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; + const auto fc = FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); + const auto res = fc.compare(f, f_ref); + ASSERT_TRUE(res.valid) << res.message; } TEST(TransformationTests, NormalizeL2FusionWithAddIncorrectExp) { @@ -185,7 +189,7 @@ TEST(TransformationTests, NormalizeL2FusionWithAddIncorrectExp) { ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } @@ -204,8 +208,9 @@ TEST(TransformationTests, NormalizeL2FusionWithAddIncorrectExp) { f_ref = std::make_shared(ngraph::NodeVector{divide}, ngraph::ParameterVector{input}); } - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; + const auto fc = FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); + const auto res = fc.compare(f, f_ref); + ASSERT_TRUE(res.valid) << res.message; } TEST(TransformationTests, NormalizeL2FusionWithAddIncorrectEpsValueShape) { @@ -225,7 +230,7 @@ TEST(TransformationTests, NormalizeL2FusionWithAddIncorrectEpsValueShape) { ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); } @@ -243,6 +248,7 @@ TEST(TransformationTests, NormalizeL2FusionWithAddIncorrectEpsValueShape) { f_ref = std::make_shared(ngraph::NodeVector{divide}, ngraph::ParameterVector{input}); } - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; + const auto fc = FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); + const auto res = fc.compare(f, f_ref); + ASSERT_TRUE(res.valid) << res.message; } From 1c9c8199556e1899042d15014e954e3aaba530e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Karzy=C5=84ski?= Date: Thu, 19 Aug 2021 17:51:03 +0200 Subject: [PATCH 035/102] Add support for ONNX Crop operator (#6956) --- ngraph/frontend/onnx/frontend/src/op/crop.cpp | 78 +++++++++++++++++++ ngraph/frontend/onnx/frontend/src/op/crop.hpp | 22 ++++++ .../frontend/onnx/frontend/src/ops_bridge.cpp | 2 + ngraph/test/models/onnx/crop.prototxt | 65 ++++++++++++++++ .../test/models/onnx/crop_with_scale.prototxt | 71 +++++++++++++++++ .../test/onnx/onnx_import_deprecated.in.cpp | 41 +++++++++- 6 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 ngraph/frontend/onnx/frontend/src/op/crop.cpp create mode 100644 ngraph/frontend/onnx/frontend/src/op/crop.hpp create mode 100644 ngraph/test/models/onnx/crop.prototxt create mode 100644 ngraph/test/models/onnx/crop_with_scale.prototxt diff --git a/ngraph/frontend/onnx/frontend/src/op/crop.cpp b/ngraph/frontend/onnx/frontend/src/op/crop.cpp new file mode 100644 index 00000000000000..1acfecbdcc04e6 --- /dev/null +++ b/ngraph/frontend/onnx/frontend/src/op/crop.cpp @@ -0,0 +1,78 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "default_opset.hpp" +#include "exceptions.hpp" +#include "ngraph/builder/autobroadcast.hpp" +#include "ngraph/shape.hpp" + +namespace ngraph { +namespace onnx_import { +namespace op { +namespace set_1 { +OutputVector crop(const Node& node) { + // Crop is an obsolete experimental ONNX operation. + // Crops an image's spatial dimensions. + + const auto inputs = node.get_ng_inputs(); + const auto& input_data = inputs.at(0); + + // Border values: leftBorder, topBorder, rightBorder, bottomBorder. + const auto border = node.get_attribute_value>("border"); + + std::shared_ptr end; + + // Set slice begin values to border values (note order of indexes) + const auto begin = default_opset::Constant::create(ngraph::element::i64, + Shape{4}, + std::vector{0, 0, border[1], border[0]}); + + // If scale is given, then start crop at left/top `border` + // and end on left/top `border` + `scale`. + if (node.has_attribute("scale")) { + // List of ints height, width + const auto scale = node.get_attribute_value>("scale"); + + CHECK_VALID_NODE(node, + scale.size() == 2, + "ONNX Crop expects 2 values in 'scale' attribute, found: ", + scale.size()); + + // Set slice end values to topBorder+heightScale and leftBorder+widthScale + // Note that indexes don't match, e.g. border[0] + scale[1] + end = default_opset::Constant::create( + ngraph::element::i64, + Shape{4}, + std::vector{0, 0, border[1] + scale[0], border[0] + scale[1]}); + } + // If scale is not provided, crop the image by values provided in `border`. + else { + CHECK_VALID_NODE(node, + border.size() == 4, + "ONNX Crop expects 4 values in 'border' attribute, found: ", + border.size()); + + // Calculate ends as shape(input) - border[2:3] + const auto input_shape = std::make_shared(input_data); + const auto end_offset = + default_opset::Constant::create(ngraph::element::i64, + Shape{4}, + std::vector{0, 0, -border[3], -border[2]}); + end = std::make_shared(input_shape, end_offset); + } + + // Input data shape [N,C,H,W], slicing only along spatial dimensions + std::vector begin_mask{1, 1, 0, 0}; + std::vector end_mask{1, 1, 0, 0}; + + return {std::make_shared(input_data, begin, end, begin_mask, end_mask)}; +} + +} // namespace set_1 + +} // namespace op + +} // namespace onnx_import + +} // namespace ngraph diff --git a/ngraph/frontend/onnx/frontend/src/op/crop.hpp b/ngraph/frontend/onnx/frontend/src/op/crop.hpp new file mode 100644 index 00000000000000..200bb08a93dc05 --- /dev/null +++ b/ngraph/frontend/onnx/frontend/src/op/crop.hpp @@ -0,0 +1,22 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "ngraph/node.hpp" +#include "onnx_import/core/node.hpp" + +namespace ngraph { +namespace onnx_import { +namespace op { +namespace set_1 { +OutputVector crop(const Node& node); + +} // namespace set_1 + +} // namespace op + +} // namespace onnx_import + +} // namespace ngraph diff --git a/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp b/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp index a3d29b595c2f48..bab0825909c8c0 100644 --- a/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp @@ -38,6 +38,7 @@ #include "op/conv_transpose.hpp" #include "op/cos.hpp" #include "op/cosh.hpp" +#include "op/crop.hpp" #include "op/cum_sum.hpp" #include "op/depth_to_space.hpp" #include "op/dequantize_linear.hpp" @@ -427,6 +428,7 @@ OperatorsBridge::OperatorsBridge() { // deprecated ops REGISTER_OPERATOR("Affine", 1, affine); + REGISTER_OPERATOR("Crop", 1, crop); REGISTER_OPERATOR("Scatter", 1, scatter_elements); REGISTER_OPERATOR("Upsample", 1, upsample); REGISTER_OPERATOR("Upsample", 7, upsample); diff --git a/ngraph/test/models/onnx/crop.prototxt b/ngraph/test/models/onnx/crop.prototxt new file mode 100644 index 00000000000000..c3ec30d4677bb4 --- /dev/null +++ b/ngraph/test/models/onnx/crop.prototxt @@ -0,0 +1,65 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + input: "x" + output: "y" + op_type: "Crop" + attribute { + name: "border" + ints: 1 + ints: 1 + ints: 1 + ints: 1 + type: INTS + } + } + name: "test_model" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + dim { + dim_value: 4 + } + } + } + } + } + output { + name: "y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/models/onnx/crop_with_scale.prototxt b/ngraph/test/models/onnx/crop_with_scale.prototxt new file mode 100644 index 00000000000000..a039c9e2a522c7 --- /dev/null +++ b/ngraph/test/models/onnx/crop_with_scale.prototxt @@ -0,0 +1,71 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + input: "x" + output: "y" + op_type: "Crop" + attribute { + name: "border" + ints: 1 + ints: 1 + ints: 0 + ints: 0 + type: INTS + } + attribute { + name: "scale" + ints: 2 + ints: 3 + type: INTS + } + } + name: "test_model" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + dim { + dim_value: 4 + } + } + } + } + } + output { + name: "y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 3 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/onnx/onnx_import_deprecated.in.cpp b/ngraph/test/onnx/onnx_import_deprecated.in.cpp index 7247cb3a83d91b..cff0441e0957d4 100644 --- a/ngraph/test/onnx/onnx_import_deprecated.in.cpp +++ b/ngraph/test/onnx/onnx_import_deprecated.in.cpp @@ -30,9 +30,6 @@ static std::string s_manifest = "${MANIFEST}"; using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); -using Inputs = std::vector>; -using Outputs = std::vector>; - NGRAPH_TEST(${BACKEND_NAME}, onnx_model_affine) { auto function = onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/affine.onnx")); @@ -45,3 +42,41 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_affine) { test_case.add_expected_output(Shape{1, 3}, expected_output); test_case.run(); } + +NGRAPH_TEST(${BACKEND_NAME}, onnx_model_crop) { + auto function = onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/crop.onnx")); + + // input shape (1, 1, 4, 4) + auto input = test::NDArray({{{{19.f, 20.f, 21.f, 22.f}, + {23.f, 24.f, 25.f, 26.f}, + {27.f, 28.f, 29.f, 30.f}, + {31.f, 32.f, 33.f, 34.f}}}}) + .get_vector(); + + // output shape (1, 1, 2, 2) + auto expected_output = test::NDArray{{{{24.f, 25.f}, {28.f, 29.f}}}}.get_vector(); + + auto test_case = test::TestCase(function); + test_case.add_input(Shape{1, 1, 4, 4}, input); + test_case.add_expected_output(Shape{1, 1, 2, 2}, expected_output); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_model_crop_with_scale) { + auto function = onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/crop_with_scale.onnx")); + + // input shape (1, 1, 4, 4) + auto input = test::NDArray({{{{19.f, 20.f, 21.f, 22.f}, + {23.f, 24.f, 25.f, 26.f}, + {27.f, 28.f, 29.f, 30.f}, + {31.f, 32.f, 33.f, 34.f}}}}) + .get_vector(); + + // output shape (1, 1, 2, 3) + auto expected_output = test::NDArray{{{{24.f, 25.f, 26.f}, {28.f, 29.f, 30.f}}}}.get_vector(); + + auto test_case = test::TestCase(function); + test_case.add_input(Shape{1, 1, 4, 4}, input); + test_case.add_expected_output(Shape{1, 1, 2, 3}, expected_output); + test_case.run(); +} From 3cecddc6ee0e7310b97349771276fb3fad5d98ad Mon Sep 17 00:00:00 2001 From: Nikita Semaev Date: Thu, 19 Aug 2021 21:54:18 +0300 Subject: [PATCH 036/102] Review/update spec for NotEqual operation (#6797) * Hiding the problem, Validate() changes 'function' * Review/update spec for NotEqual operation * Remove unnecessary edits not related to the ticket * Removing the extra word binary for the short description * Re-writing detailed description * Correcting punctuation docs/ops/comparison/NotEqual_1.md Co-authored-by: Tatiana Savina * Specifying auto_broadcast in the short description is similar to Equal spec * The range of values for auto_brodcast is similar to Equal spec and includes the missing pdpd Co-authored-by: Tatiana Savina --- docs/ops/comparison/NotEqual_1.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/ops/comparison/NotEqual_1.md b/docs/ops/comparison/NotEqual_1.md index 448f4bcb66a62a..691da41c1759ef 100644 --- a/docs/ops/comparison/NotEqual_1.md +++ b/docs/ops/comparison/NotEqual_1.md @@ -4,7 +4,18 @@ **Category**: Comparison binary operation -**Short description**: *NotEqual* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules. +**Short description**: *NotEqual* performs element-wise comparison operation with two given tensors applying +multi-directional broadcast rules specified in the `auto_broadcast` attribute. + +**Detailed description** +Before performing comparison operation, input tensors *a* and *b* are broadcasted if their shapes are different. +Broadcasting is performed according to `auto_broadcast` value. + +After broadcasting, *NotEqual* does the following with the input tensors *a* and *b*: + +\f[ +o_{i} = a_{i} != b_{i} +\f] **Attributes**: @@ -13,7 +24,8 @@ * **Description**: specifies rules used for auto-broadcasting of input tensors. * **Range of values**: * *none* - no auto-broadcasting is allowed, all input shapes should match - * *numpy* - numpy broadcasting rules, aligned with ONNX Broadcasting. Description is available in ONNX docs. + * *numpy* - numpy broadcasting rules, description is available in [Broadcast Rules For Elementwise Operations](../broadcast_rules.md), + * *pdpd* - PaddlePaddle-style implicit broadcasting, description is available in [Broadcast Rules For Elementwise Operations](../broadcast_rules.md). * **Type**: string * **Default value**: "numpy" * **Required**: *no* @@ -31,15 +43,6 @@ * *T*: arbitrary supported type. -**Detailed description** -Before performing arithmetic operation, input tensors *a* and *b* are broadcasted if their shapes are different and `auto_broadcast` attributes is not `none`. Broadcasting is performed according to `auto_broadcast` value. - -After broadcasting *NotEqual* does the following with the input tensors *a* and *b*: - -\f[ -o_{i} = a_{i} \neq b_{i} -\f] - **Examples** *Example 1* From 3846d205882d9490fb68e00d721a9ee99d768a75 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Fri, 20 Aug 2021 06:42:15 +0300 Subject: [PATCH 037/102] Moved DiscreteTypeInfo to ov namespace (#7127) * Moved DiscreteTypeInfo to new opset * Revert old header * Fixed code style --- .../src/cldnn_engine/cldnn_program.h | 5 +- .../src/legacy_api/src/ngraph_ops/nms_ie.cpp | 2 +- .../include/low_precision/network_helper.hpp | 28 +-- .../low_precision/propagate_shared_value.hpp | 10 +- .../propagate_through_precision_preserved.hpp | 4 +- .../low_precision/propagate_to_input.hpp | 4 +- .../update_shared_precision_preserved.hpp | 10 +- .../low_precision_transformations/src/add.cpp | 28 +-- .../src/clamp.cpp | 12 +- .../src/concat.cpp | 2 +- .../src/convert.cpp | 2 +- .../src/convolution.cpp | 36 ++-- .../src/convolution_backprop_data.cpp | 24 +-- .../src/depth_to_space.cpp | 2 +- .../src/eltwise_base_transformation.cpp | 46 ++-- .../src/fake_quantize.cpp | 32 +-- .../src/fake_quantize_decomposition.cpp | 16 +- .../src/fake_quantize_dequantization.cpp | 14 +- .../src/fold_convert.cpp | 12 +- .../src/fold_fake_quantize.cpp | 4 +- .../src/fuse_convert.cpp | 14 +- .../src/fuse_fake_quantize.cpp | 26 +-- .../src/fuse_multiply_to_fake_quantize.cpp | 14 +- .../src/fuse_subtract_to_fake_quantize.cpp | 20 +- .../src/interpolate.cpp | 8 +- .../src/layer_transformation.cpp | 8 +- .../src/low_precision.cpp | 4 +- .../src/markup_precisions.cpp | 8 +- .../src/mat_mul.cpp | 16 +- .../src/max_pool.cpp | 2 +- .../src/multiply.cpp | 12 +- .../src/multiply_to_group_convolution.cpp | 18 +- .../low_precision_transformations/src/mvn.cpp | 28 +-- .../src/network_helper.cpp | 182 ++++++++-------- .../src/normalize_l2.cpp | 14 +- .../low_precision_transformations/src/pad.cpp | 12 +- .../pull_reshape_through_dequantization.cpp | 22 +- .../pull_transpose_through_dequantization.cpp | 18 +- .../src/quantization_details.cpp | 26 +-- .../src/reduce_base_transformation.cpp | 2 +- .../src/reduce_max.cpp | 4 +- .../src/reduce_mean.cpp | 2 +- .../src/reduce_min.cpp | 4 +- .../src/reduce_sum.cpp | 6 +- .../src/reshape.cpp | 4 +- .../rt_info/intervals_alignment_attribute.cpp | 16 +- .../src/rt_info/precisions_attribute.cpp | 2 +- .../quantization_alignment_attribute.cpp | 8 +- .../src/shuffle_channels.cpp | 6 +- .../src/split.cpp | 6 +- .../src/squeeze.cpp | 2 +- .../src/strided_slice.cpp | 8 +- .../src/subtract.cpp | 6 +- .../src/subtract_multiply_to_multiply_add.cpp | 16 +- .../src/transpose.cpp | 4 +- .../src/unsqueeze.cpp | 2 +- .../src/weightable_layer_transformation.cpp | 44 ++-- .../src/pruning/mask_attribute.cpp | 4 +- .../src/snippets/src/op/subgraph.cpp | 2 +- .../snippets/src/pass/assign_registers.cpp | 6 +- .../snippets/src/pass/collapse_subgraph.cpp | 108 +++++----- .../src/ngraph_ops/nms_ie_internal.cpp | 2 +- .../common_optimizations/nop_elimination.cpp | 28 +-- .../simplify_shape_of_sub_graph.cpp | 8 +- .../transpose_to_reshape.cpp | 2 +- .../weights_dequantize_to_fake_quantize.cpp | 2 +- ...convert_constant_folding_on_const_path.cpp | 4 +- .../op_conversions/convert_batch_to_space.cpp | 6 +- .../op_conversions/convert_space_to_batch.cpp | 6 +- .../op_conversions/convert_subtract.cpp | 17 +- .../rt_info/dequantization_attribute.cpp | 2 +- .../rt_info/fused_names_attribute.cpp | 4 +- .../rt_info/primitives_priority_attribute.cpp | 2 +- .../src/transformations/serialize.cpp | 6 +- ...nvolution_backprop_data_transformation.cpp | 8 +- .../convolution_transformation.cpp | 2 +- .../inference_engine/snippets/registers.cpp | 4 +- .../lpt_ngraph_functions/common/builders.hpp | 2 +- .../lpt_ngraph_functions/src/add_function.cpp | 16 +- .../src/common/builders.cpp | 2 +- .../convolution_backprop_data_function.cpp | 2 +- .../src/convolution_function.cpp | 6 +- .../src/get_dequantization_function.cpp | 8 +- .../mock_mo_frontend.hpp | 8 +- .../core/include/ngraph/pattern/matcher.hpp | 2 +- .../include/ngraph/pattern/op/pattern.hpp | 2 +- ngraph/core/include/ngraph/type.hpp | 69 +----- ngraph/core/include/openvino/core/type.hpp | 98 +++++++++ ngraph/core/src/function.cpp | 2 +- ngraph/core/src/graph_util.cpp | 16 +- ngraph/core/src/node.cpp | 8 +- ngraph/core/src/op/assign.cpp | 4 +- ngraph/core/src/op/loop.cpp | 11 +- ngraph/core/src/op/non_max_suppression.cpp | 2 +- ngraph/core/src/op/parameter.cpp | 2 +- ngraph/core/src/op/result.cpp | 2 +- ngraph/core/src/op/tensor_iterator.cpp | 16 +- ngraph/core/src/op/topk.cpp | 4 +- .../core/src/op/util/arithmetic_reduction.cpp | 2 +- ngraph/core/src/op/util/broadcast_base.cpp | 8 +- ngraph/core/src/op/util/fft_base.cpp | 6 +- ngraph/core/src/pass/constant_folding.cpp | 4 +- ngraph/core/src/pass/convert_precision.cpp | 24 +-- ngraph/core/src/pass/visualize_tree.cpp | 4 +- ngraph/core/src/specialize_function.cpp | 2 +- ngraph/core/src/validation_util.cpp | 20 +- .../frontend/onnx/frontend/src/frontend.cpp | 4 +- .../frontend/onnx/frontend/src/op/dropout.cpp | 2 +- ngraph/frontend/onnx/frontend/src/op/loop.cpp | 10 +- ngraph/frontend/paddlepaddle/src/frontend.cpp | 40 ++-- .../mock_py_frontend.hpp | 8 +- ngraph/test/builder_autobroadcast.cpp | 12 +- ngraph/test/constant_folding.cpp | 196 +++++++++--------- ngraph/test/copy.cpp | 18 +- ngraph/test/graph_rewrite.cpp | 2 +- .../onnx/onnx_import_const_folding.in.cpp | 2 +- ngraph/test/op.cpp | 26 +-- ngraph/test/pattern.cpp | 6 +- .../test/runtime/dynamic/dynamic_backend.cpp | 4 +- .../runtime/interpreter/evaluates_map.cpp | 46 ++-- .../runtime/interpreter/int_executable.cpp | 10 +- ngraph/test/specialize_function.cpp | 6 +- ngraph/test/type_prop/loop.cpp | 110 +++++----- ngraph/test/type_prop/ti.cpp | 10 +- ngraph/test/util.cpp | 10 +- ngraph/test/visitors/op/adaptive_max_pool.cpp | 2 +- ngraph/test/visitors/op/batch_norm.cpp | 2 +- ngraph/test/visitors/op/broadcast.cpp | 2 +- ngraph/test/visitors/op/bucketize.cpp | 4 +- ngraph/test/visitors/op/constant.cpp | 6 +- ngraph/test/visitors/op/convert.cpp | 2 +- .../test/visitors/op/convolution_backprop.cpp | 4 +- ngraph/test/visitors/op/cum_sum.cpp | 6 +- .../visitors/op/deformable_convolution.cpp | 4 +- .../visitors/op/deformable_psroi_pooling.cpp | 2 +- ngraph/test/visitors/op/depth_to_space.cpp | 2 +- ngraph/test/visitors/op/detection_output.cpp | 2 +- ngraph/test/visitors/op/einsum.cpp | 2 +- ngraph/test/visitors/op/elu.cpp | 2 +- .../test/visitors/op/extractimagepatches.cpp | 2 +- ngraph/test/visitors/op/fake_quantize.cpp | 2 +- ngraph/test/visitors/op/gather.cpp | 4 +- ngraph/test/visitors/op/gelu.cpp | 2 +- ngraph/test/visitors/op/grn.cpp | 2 +- ngraph/test/visitors/op/group_conv.cpp | 4 +- ngraph/test/visitors/op/interpolate.cpp | 2 +- ngraph/test/visitors/op/lrn.cpp | 2 +- ngraph/test/visitors/op/lstm_cell.cpp | 2 +- ngraph/test/visitors/op/lstm_sequence.cpp | 2 +- ngraph/test/visitors/op/matmul.cpp | 2 +- ngraph/test/visitors/op/matrix_nms.cpp | 4 +- ngraph/test/visitors/op/max_pool.cpp | 4 +- ngraph/test/visitors/op/multiclass_nms.cpp | 4 +- ngraph/test/visitors/op/mvn.cpp | 4 +- .../test/visitors/op/non_max_suppression.cpp | 8 +- ngraph/test/visitors/op/normalize_l2.cpp | 2 +- ngraph/test/visitors/op/one_hot.cpp | 2 +- ngraph/test/visitors/op/pad.cpp | 2 +- ngraph/test/visitors/op/parameter.cpp | 2 +- ngraph/test/visitors/op/prior_box.cpp | 2 +- .../test/visitors/op/prior_box_clustered.cpp | 2 +- ngraph/test/visitors/op/proposal.cpp | 2 +- ngraph/test/visitors/op/psroi_pooling.cpp | 2 +- ngraph/test/visitors/op/random_uniform.cpp | 2 +- ngraph/test/visitors/op/reduce_ops.hpp | 2 +- ngraph/test/visitors/op/region_yolo.cpp | 2 +- ngraph/test/visitors/op/reorg_yolo.cpp | 4 +- ngraph/test/visitors/op/reshape.cpp | 2 +- ngraph/test/visitors/op/reverse.cpp | 4 +- ngraph/test/visitors/op/reverse_sequence.cpp | 2 +- ngraph/test/visitors/op/rnn_cell.cpp | 4 +- ngraph/test/visitors/op/roi_pooling.cpp | 2 +- ngraph/test/visitors/op/round.cpp | 2 +- ngraph/test/visitors/op/select.cpp | 2 +- ngraph/test/visitors/op/shuffle_channels.cpp | 2 +- ngraph/test/visitors/op/softmax.cpp | 2 +- ngraph/test/visitors/op/space_to_depth.cpp | 2 +- ngraph/test/visitors/op/split.cpp | 2 +- ngraph/test/visitors/op/strided_slice.cpp | 2 +- ngraph/test/visitors/op/topk.cpp | 2 +- ngraph/test/visitors/user_op.cpp | 2 +- 181 files changed, 1090 insertions(+), 1044 deletions(-) create mode 100644 ngraph/core/include/openvino/core/type.hpp diff --git a/inference-engine/src/cldnn_engine/cldnn_program.h b/inference-engine/src/cldnn_engine/cldnn_program.h index 8f90b4fabb7712..cf791870e5e08d 100644 --- a/inference-engine/src/cldnn_engine/cldnn_program.h +++ b/inference-engine/src/cldnn_engine/cldnn_program.h @@ -29,9 +29,12 @@ enum class eltwise_mode : int32_t; // Forward declarations for ngraph part namespace ngraph { class Node; -class DiscreteTypeInfo; } // namespace ngraph +namespace ov { +class DiscreteTypeInfo; +} // namespace ov + #define REGISTER_FACTORY_IMPL(op_version, op_name) \ void __register ## _ ## op_name ## _ ## op_version() { \ Program::RegisterFactory( \ diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/nms_ie.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/nms_ie.cpp index 82a0315ec74fe0..f6b333e5c51cd9 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/nms_ie.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/nms_ie.cpp @@ -164,7 +164,7 @@ int64_t op::NonMaxSuppressionIE3::max_boxes_output_from_input() const { } const auto max_output_boxes_input = - as_type_ptr(input_value(max_output_boxes_per_class_port).get_node_shared_ptr()); + ov::as_type_ptr(input_value(max_output_boxes_per_class_port).get_node_shared_ptr()); max_output_boxes = max_output_boxes_input->cast_vector().at(0); return max_output_boxes; diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/network_helper.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/network_helper.hpp index 93c80161deb4fd..ca80b580b0b2b8 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/network_helper.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/network_helper.hpp @@ -226,14 +226,14 @@ class LP_TRANSFORMATIONS_API NetworkHelper { auto node = nodes.front(); nodes.pop_front(); - if (visited.count(node) || is_type(node)) { + if (visited.count(node) || ov::is_type(node)) { continue; } visited.insert(node); bool handleConnectedNodes = false; - if (NetworkHelper::isPrecisionPreserved(node) || is_type(node)) { + if (NetworkHelper::isPrecisionPreserved(node) || ov::is_type(node)) { auto& rt = node->get_rt_info(); if (node == initialNode) { @@ -255,13 +255,13 @@ class LP_TRANSFORMATIONS_API NetworkHelper { continue; } - if (!is_type(node)) { + if (!ov::is_type(node)) { for (size_t index = 0ul; index < node->get_input_size(); ++index) { auto getInput = [](const std::shared_ptr& node, const size_t index) { const auto dequantization = NetworkHelper::getDequantization(node, index); if (!dequantization.empty() && - (is_type(dequantization.data.get_node())) && - is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { + (ov::is_type(dequantization.data.get_node())) && + ov::is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { const auto input = dequantization.data.get_node()->input(0); return input; } @@ -272,7 +272,7 @@ class LP_TRANSFORMATIONS_API NetworkHelper { const auto& input_node = input.get_source_output().get_node_shared_ptr(); //const auto& input_node = input.get_source_output().get_node_shared_ptr(); - if (visited.count(input_node) || is_type(input_node)) { + if (visited.count(input_node) || ov::is_type(input_node)) { continue; } @@ -283,7 +283,7 @@ class LP_TRANSFORMATIONS_API NetworkHelper { for (auto& output : node->outputs()) { for (auto& input_value : output.get_target_inputs()) { const auto& output_node = input_value.get_node()->shared_from_this(); - if (visited.count(output_node) || is_type(output_node)) { + if (visited.count(output_node) || ov::is_type(output_node)) { continue; } @@ -364,7 +364,7 @@ std::shared_ptr NetworkHelper::setOutDataPrecision(std::shared_ptr std::shared_ptr make_op_pattern(const ngraph::NodeVector& args) { - return std::make_shared(element::undefined, PartialShape{}, [](std::shared_ptr n) {return !!as_type_ptr(n); }, args); + return std::make_shared(element::undefined, PartialShape{}, [](std::shared_ptr n) {return !!ov::as_type_ptr(n); }, args); } template @@ -372,7 +372,7 @@ std::shared_ptr make_op_label() { return std::make_shared( element::undefined, PartialShape{}, - [](std::shared_ptr n) {return !!as_type_ptr(n); }); + [](std::shared_ptr n) {return !!ov::as_type_ptr(n); }); } template @@ -394,18 +394,18 @@ std::shared_ptr fold_reshape(Args&&... args) { std::shared_ptr node = std::make_shared(std::forward(args)...); if (node->get_output_size() == 1) { // issue #57985: remove fold_reshape & reuse nGraph implementation - const auto values = as_type_ptr(node->input_value(1).get_node_shared_ptr())->template cast_vector(); + const auto values = ov::as_type_ptr(node->input_value(1).get_node_shared_ptr())->template cast_vector(); if (std::any_of(values.begin(), values.end(), [](const int64_t value) { return (value == 0) || (value == -1); })) { return fold(std::forward(args)...); } OutputVector folded; - if (is_type(node->input_value(0).get_node_shared_ptr()) && - is_type(node->input_value(1).get_node_shared_ptr())) { + if (ov::is_type(node->input_value(0).get_node_shared_ptr()) && + ov::is_type(node->input_value(1).get_node_shared_ptr())) { return std::make_shared( node->get_input_element_type(0), - Shape(as_type_ptr(node->input_value(1).get_node_shared_ptr())->template cast_vector()), - as_type_ptr(node->input_value(0).get_node_shared_ptr())->get_data_ptr()); + Shape(ov::as_type_ptr(node->input_value(1).get_node_shared_ptr())->template cast_vector()), + ov::as_type_ptr(node->input_value(0).get_node_shared_ptr())->get_data_ptr()); } } return node; diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/propagate_shared_value.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/propagate_shared_value.hpp index 9866d63197ff1d..6a83a74089ac04 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/propagate_shared_value.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/propagate_shared_value.hpp @@ -36,7 +36,7 @@ class ngraph::pass::low_precision::PropagateSharedValue : public ngraph::pass::F std::vector> nodes(f->get_ordered_ops()); for (auto it = nodes.begin(); it != nodes.end(); it++) { const std::shared_ptr node = *it; - if (is_type(node)) { + if (ov::is_type(node)) { assert(node->get_output_size() == 1ul); auto& outputRtInfo = node->output(0).get_rt_info(); @@ -56,7 +56,7 @@ class ngraph::pass::low_precision::PropagateSharedValue : public ngraph::pass::F auto node = nodeInput.get_source_output().get_node_shared_ptr(); std::vector>>> attributes; - if (is_type(node)) { + if (ov::is_type(node)) { // output auto& rt = nodeInput.get_source_output().get_rt_info(); auto it = rt.find(name); @@ -109,8 +109,8 @@ class ngraph::pass::low_precision::PropagateSharedValue : public ngraph::pass::F const auto dequantization = NetworkHelper::getDequantization(node, index); if (!dequantization.empty() && - (is_type(dequantization.data.get_node())) && - is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { + (ov::is_type(dequantization.data.get_node())) && + ov::is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { inputNode = dequantization.data.get_node()->get_input_node_shared_ptr(0); } @@ -121,7 +121,7 @@ class ngraph::pass::low_precision::PropagateSharedValue : public ngraph::pass::F const auto attribute = std::dynamic_pointer_cast>>(inputAttributeIt->second); parentAttributes.push_back(attribute); } - } else if (is_type(inputNode)) { + } else if (ov::is_type(inputNode)) { const auto& outputPortRtInfo = inputNode->outputs()[0].get_rt_info(); auto attributeIt = outputPortRtInfo.find(ngraph::VariantWrapper>::type_info.name); if (attributeIt != outputPortRtInfo.end()) { diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/propagate_through_precision_preserved.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/propagate_through_precision_preserved.hpp index 18a8f1e0ab839b..bfa0e1fccebc15 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/propagate_through_precision_preserved.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/propagate_through_precision_preserved.hpp @@ -96,9 +96,9 @@ class ngraph::pass::low_precision::PropagateThroughPrecisionPreserved : public n auto getInput = [](const std::shared_ptr& node, const size_t index) -> Input { const auto dequantization = NetworkHelper::getDequantization(node, index); if (!dequantization.empty() && - is_type(dequantization.data.get_node()) && + ov::is_type(dequantization.data.get_node()) && (dequantization.data.get_node()->get_input_size() == 1ul) && - is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { + ov::is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { return dequantization.data.get_node()->input(0); } diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/propagate_to_input.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/propagate_to_input.hpp index 1f30ab7b4a07d5..64268e9270b4c4 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/propagate_to_input.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/propagate_to_input.hpp @@ -72,9 +72,9 @@ class ngraph::pass::low_precision::PropagateToInput : public ngraph::pass::Match auto getInput = [](const Input& input) { const auto dequantization = NetworkHelper::getDequantization(input.get_node()->shared_from_this(), input.get_index()); if (!dequantization.empty() && - is_type(dequantization.data.get_node()) && + ov::is_type(dequantization.data.get_node()) && (dequantization.data.get_node()->get_input_size() == 1ul) && - is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { + ov::is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { return dequantization.data.get_node()->input(0); } diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/update_shared_precision_preserved.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/update_shared_precision_preserved.hpp index 119ae13c412126..0a17f7328accba 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/update_shared_precision_preserved.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/update_shared_precision_preserved.hpp @@ -35,14 +35,14 @@ class ngraph::pass::low_precision::UpdateSharedPrecisionPreserved : public ngrap const bool needToCheckExpectedAttributeType = !std::is_same::value; if (!needToCheckExpectedAttributeType) { // expected attribute is ignored, set attributes for node inputs except Result & FakeQuantize operations - if (is_type(node) || - is_type(node) || + if (ov::is_type(node) || + ov::is_type(node) || transformation_callback(node)) { return false; } } - if (ngraph::pass::low_precision::NetworkHelper::isPrecisionPreserved(node) || is_type(node)) { + if (ngraph::pass::low_precision::NetworkHelper::isPrecisionPreserved(node) || ov::is_type(node)) { return false; } @@ -87,8 +87,8 @@ class ngraph::pass::low_precision::UpdateSharedPrecisionPreserved : public ngrap Input getDequantizationInput(const Input& input) { const auto dequantization = NetworkHelper::getDequantization(input.get_node()->shared_from_this(), input.get_index()); if (!dequantization.empty() && - (is_type(dequantization.data.get_node())) && - is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { + (ov::is_type(dequantization.data.get_node())) && + ov::is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { assert(dequantization.data.get_target_inputs().size() == 1ul); return *dequantization.data.get_target_inputs().begin(); } diff --git a/inference-engine/src/low_precision_transformations/src/add.cpp b/inference-engine/src/low_precision_transformations/src/add.cpp index 55a101c101fb76..c09a22783a6129 100644 --- a/inference-engine/src/low_precision_transformations/src/add.cpp +++ b/inference-engine/src/low_precision_transformations/src/add.cpp @@ -28,26 +28,26 @@ std::shared_ptr replaceToSubtract(const std::shared_ptr& // motivation: // - single responsibility // - keep AddTransformation and AddToSubtractTransformation transformations independent and optional - const auto add = as_type_ptr(op); + const auto add = ov::as_type_ptr(op); if (add == nullptr) { return nullptr; } // TODO: use general way from getDequantization: is eltwise with Constant - const int constBranchIndex = is_type(add->get_input_node_ptr(0)) ? + const int constBranchIndex = ov::is_type(add->get_input_node_ptr(0)) ? 0 : - (is_type(add->get_input_node_ptr(1)) ? 1 : -1); + (ov::is_type(add->get_input_node_ptr(1)) ? 1 : -1); if (constBranchIndex == -1) { return nullptr; } const size_t dataBranchIndex = constBranchIndex == 0 ? 1ul : 0; const auto parent = add->get_input_node_shared_ptr(dataBranchIndex); - if (is_type(parent) || - is_type(parent) || - is_type(parent) || - (is_type(parent) && - (is_type(parent->get_input_node_ptr(0)) || is_type(parent->get_input_node_ptr(1))))) { + if (ov::is_type(parent) || + ov::is_type(parent) || + ov::is_type(parent) || + (ov::is_type(parent) && + (ov::is_type(parent->get_input_node_ptr(0)) || ov::is_type(parent->get_input_node_ptr(1))))) { return nullptr; } @@ -68,11 +68,11 @@ std::shared_ptr replaceToSubtract(const std::shared_ptr& } std::shared_ptr fuseWithSubtract(const std::shared_ptr& op) { - const auto add = as_type_ptr(op); + const auto add = ov::as_type_ptr(op); if ((add == nullptr) || - !is_type(add->get_input_node_shared_ptr(0)) || + !ov::is_type(add->get_input_node_shared_ptr(0)) || // TODO: use general way from getDequantization: is eltwise with Constant - !is_type(add->get_input_node_shared_ptr(0)->get_input_node_shared_ptr(1))) { + !ov::is_type(add->get_input_node_shared_ptr(0)->get_input_node_shared_ptr(1))) { return nullptr; } @@ -107,7 +107,7 @@ AddTransformation::AddTransformation(const Params& params) : EltwiseBaseTransfor } bool AddTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { - std::shared_ptr op = as_type_ptr(m.get_match_root()); + std::shared_ptr op = ov::as_type_ptr(m.get_match_root()); if ((op == nullptr) || (!canBeTransformed(context, op))) { return false; } @@ -116,7 +116,7 @@ bool AddTransformation::transform(TransformationContext& context, ngraph::patter NetworkHelper::normalizeDequantization(NetworkHelper::getDequantization(op, 1)); std::shared_ptr addNode = NetworkHelper::separateInStandaloneBranch(op); - std::shared_ptr add = as_type_ptr(addNode); + std::shared_ptr add = ov::as_type_ptr(addNode); const int fullPathIndex = getNotEmpty(add); std::shared_ptr newMultiply; @@ -136,7 +136,7 @@ bool AddTransformation::transform(TransformationContext& context, ngraph::patter newMultiply = NetworkHelper::swapMultiplyAndAdd(add, multiplyBranch.first); ngraph::copy_runtime_info({ add, newMultiply }, newMultiply); - if (is_type(newMultiply->get_input_node_shared_ptr(0))) { + if (ov::is_type(newMultiply->get_input_node_shared_ptr(0))) { newAddOrSubtract = newMultiply->get_input_node_shared_ptr(0); auto subtract = fuseWithSubtract(newAddOrSubtract); diff --git a/inference-engine/src/low_precision_transformations/src/clamp.cpp b/inference-engine/src/low_precision_transformations/src/clamp.cpp index 45c4cd5986c1a1..da1b462697d917 100644 --- a/inference-engine/src/low_precision_transformations/src/clamp.cpp +++ b/inference-engine/src/low_precision_transformations/src/clamp.cpp @@ -37,13 +37,13 @@ bool ClampTransformation::transform(TransformationContext& context, ngraph::patt return false; } - auto constant = as_type_ptr(sub->get_input_node_shared_ptr(1)); + auto constant = ov::as_type_ptr(sub->get_input_node_shared_ptr(1)); if (constant == nullptr) { const auto convert = sub->get_input_node_shared_ptr(1); - if (!is_type(convert)) { + if (!ov::is_type(convert)) { return false; } - constant = as_type_ptr(convert->get_input_node_shared_ptr(0)); + constant = ov::as_type_ptr(convert->get_input_node_shared_ptr(0)); } if (constant == nullptr) { @@ -66,7 +66,7 @@ bool ClampTransformation::transform(TransformationContext& context, ngraph::patt return false; } - const auto newClamp = as_type_ptr(moveDequantizationAfter(context, clamp, dequantization, false, moveSubtract)); + const auto newClamp = ov::as_type_ptr(moveDequantizationAfter(context, clamp, dequantization, false, moveSubtract)); std::shared_ptr replacement; { @@ -74,7 +74,7 @@ bool ClampTransformation::transform(TransformationContext& context, ngraph::patt double max = newClamp->get_max(); if (dequantization.multiply != nullptr) { - double scale = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1))->cast_vector()[0]; + double scale = ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1))->cast_vector()[0]; if (scale < 0.0) { std::swap(min, max); } @@ -83,7 +83,7 @@ bool ClampTransformation::transform(TransformationContext& context, ngraph::patt } if (dequantization.subtract != nullptr && moveSubtract) { - double shift = as_type_ptr(dequantization.subtractConstant)->cast_vector()[0]; + double shift = ov::as_type_ptr(dequantization.subtractConstant)->cast_vector()[0]; min += shift; max += shift; } diff --git a/inference-engine/src/low_precision_transformations/src/concat.cpp b/inference-engine/src/low_precision_transformations/src/concat.cpp index 6adeb1f413c997..5c0da831b8e7ac 100644 --- a/inference-engine/src/low_precision_transformations/src/concat.cpp +++ b/inference-engine/src/low_precision_transformations/src/concat.cpp @@ -178,7 +178,7 @@ bool ConcatTransformation::isPrecisionPreserved(std::shared_ptr) const noe } bool ConcatTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr layer) const { - std::shared_ptr concat = as_type_ptr(layer); + std::shared_ptr concat = ov::as_type_ptr(layer); if (concat == nullptr) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/convert.cpp b/inference-engine/src/low_precision_transformations/src/convert.cpp index e96fc4820c77e3..fbc64e0db62dc5 100644 --- a/inference-engine/src/low_precision_transformations/src/convert.cpp +++ b/inference-engine/src/low_precision_transformations/src/convert.cpp @@ -37,7 +37,7 @@ ConvertTransformation::ConvertTransformation(const Params& params) : LayerTransf } bool ConvertTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { - std::shared_ptr convert = as_type_ptr(m.get_match_root()); + std::shared_ptr convert = ov::as_type_ptr(m.get_match_root()); if (!convert) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/convolution.cpp b/inference-engine/src/low_precision_transformations/src/convolution.cpp index cb05b00d141b1e..344c9ba90ac4c9 100644 --- a/inference-engine/src/low_precision_transformations/src/convolution.cpp +++ b/inference-engine/src/low_precision_transformations/src/convolution.cpp @@ -56,7 +56,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph if (!canConvolutionBeTransformed(context, convolution)) { const auto weightInput = convolution->get_input_node_shared_ptr(1); - const auto reshapeFromWeights = as_type_ptr(weightInput); + const auto reshapeFromWeights = ov::as_type_ptr(weightInput); FakeQuantizeDequantization dequantization = reshapeFromWeights == nullptr ? NetworkHelper::getDequantization(convolution, 1ul) : NetworkHelper::getDequantization(reshapeFromWeights); @@ -69,7 +69,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph reshapeFromWeights->input_value(1), false); } - if (is_type(resultConstant)) { + if (ov::is_type(resultConstant)) { replace_node(weightInput, resultConstant); } } else { @@ -90,7 +90,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph if (optimizedSubtract == nullptr) { optimizedSubtract = dequantization.subtract; } - subtract = as_type_ptr(optimizedSubtract); + subtract = ov::as_type_ptr(optimizedSubtract); } // workaround normalizes shape of Subtract to match CPU plugin expectations @@ -108,7 +108,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph Shape{ length }, broadcastShape)); - const auto newSubtract = as_type_ptr(subtract->clone_with_new_inputs({ + const auto newSubtract = ov::as_type_ptr(subtract->clone_with_new_inputs({ subtract->input_value(0), newShift })); NetworkHelper::copyInfo(subtract, newSubtract); @@ -159,7 +159,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph } const auto copyNode = convolution->clone_with_new_inputs({ dequantization.multiply->input_value(0), convolution->input_value(1) }); - auto conv = as_type_ptr(copyNode); + auto conv = ov::as_type_ptr(copyNode); std::shared_ptr relaxedNewConvolution; if (conv) { relaxedNewConvolution = std::make_shared>( @@ -168,7 +168,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph std::vector{deqPrecision}); } else { relaxedNewConvolution = std::make_shared>( - *as_type_ptr(copyNode), + *ov::as_type_ptr(copyNode), std::vector{deqPrecision, deqPrecision}, std::vector{deqPrecision}); } @@ -183,7 +183,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph replace_node(convolution, newMultiplyAfter); convolution = newMultiplyAfter->input_value(0).get_node_shared_ptr(); - if (is_type(convolution->get_input_node_ptr(0))) { + if (ov::is_type(convolution->get_input_node_ptr(0))) { auto newConvolution = convolution->clone_with_new_inputs({ convolution->get_input_node_ptr(0)->input_value(0), convolution->input_value(1)}); @@ -201,24 +201,24 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph return false; } - std::shared_ptr reshapeFromWeights = as_type_ptr(convolution->get_input_node_shared_ptr(1)); + std::shared_ptr reshapeFromWeights = ov::as_type_ptr(convolution->get_input_node_shared_ptr(1)); dequantization = reshapeFromWeights == nullptr ? NetworkHelper::getDequantization(convolution, 1ul) : NetworkHelper::getDequantization(reshapeFromWeights); assert(!dequantization.empty()); - if (is_type(dequantization.data.get_node())) { - const std::shared_ptr fq = as_type_ptr(dequantization.data.get_node_shared_ptr()); + if (ov::is_type(dequantization.data.get_node())) { + const std::shared_ptr fq = ov::as_type_ptr(dequantization.data.get_node_shared_ptr()); std::shared_ptr newFQ = NetworkHelper::fold_fake_quantize(fq, true); NetworkHelper::copyInfo(fq, newFQ); replace_node(fq, newFQ); } - std::shared_ptr multiplyFromWeights = as_type_ptr( + std::shared_ptr multiplyFromWeights = ov::as_type_ptr( reshapeFromWeights == nullptr ? convolution->get_input_node_shared_ptr(1) : convolution->get_input_node_ptr(1)->get_input_node_shared_ptr(0)); - std::shared_ptr subtractFromWeights = as_type_ptr(multiplyFromWeights->get_input_node_shared_ptr(0)); + std::shared_ptr subtractFromWeights = ov::as_type_ptr(multiplyFromWeights->get_input_node_shared_ptr(0)); { const auto newScalePShape = multiplyFromWeights->get_input_partial_shape(1); @@ -231,7 +231,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph } if (reshapeFromWeights != nullptr) { - reshapeFromWeights = as_type_ptr(reshapeFromWeights->copy_with_new_inputs({ + reshapeFromWeights = ov::as_type_ptr(reshapeFromWeights->copy_with_new_inputs({ multiplyFromWeights->input_value(0), reshapeFromWeights->input_value(1) })); } @@ -264,7 +264,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph if (optimizedSubtract == nullptr) { subtractFromWeights = nullptr; } else { - subtractFromWeights = as_type_ptr(optimizedSubtract); + subtractFromWeights = ov::as_type_ptr(optimizedSubtract); const auto weightsPShape = subtractFromWeights->get_input_partial_shape(0); assert(weightsPShape.is_static()); @@ -281,7 +281,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph } } - std::shared_ptr convertFromWeights = as_type_ptr(subtractFromWeights == nullptr ? + std::shared_ptr convertFromWeights = ov::as_type_ptr(subtractFromWeights == nullptr ? multiplyFromWeights->get_input_node_shared_ptr(0) : subtractFromWeights->get_input_node_shared_ptr(0)); if (convertFromWeights != nullptr) { @@ -298,7 +298,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph convolution = newConvolution; } - reshapeFromWeights = as_type_ptr(convolution->get_input_node_shared_ptr(1)); + reshapeFromWeights = ov::as_type_ptr(convolution->get_input_node_shared_ptr(1)); if (reshapeFromWeights != nullptr) { // remove Reshape on weights const std::shared_ptr newWeights = fold_reshape( @@ -319,11 +319,11 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph NetworkHelper::normalizeDequantizationShape(finalDequantization); auto onWeights = convolution->get_input_node_shared_ptr(1); - if (is_type(onWeights)) { + if (ov::is_type(onWeights)) { onWeights = onWeights->get_input_node_shared_ptr(0); } - if (is_type(onWeights)) { + if (ov::is_type(onWeights)) { auto& rt = onWeights->get_rt_info(); rt["DISABLED_CONSTANT_FOLDING"] = std::make_shared>(""); } diff --git a/inference-engine/src/low_precision_transformations/src/convolution_backprop_data.cpp b/inference-engine/src/low_precision_transformations/src/convolution_backprop_data.cpp index 680ed16eb1759b..1054149e836175 100644 --- a/inference-engine/src/low_precision_transformations/src/convolution_backprop_data.cpp +++ b/inference-engine/src/low_precision_transformations/src/convolution_backprop_data.cpp @@ -66,7 +66,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con if (!canBeTransformed(context, convolutionBackpropData)) { auto weightsInput = convolutionBackpropData->get_input_node_shared_ptr(1); - std::shared_ptr reshapeFromWeights = as_type_ptr(weightsInput); + std::shared_ptr reshapeFromWeights = ov::as_type_ptr(weightsInput); FakeQuantizeDequantization dequantization = reshapeFromWeights == nullptr ? NetworkHelper::getDequantization(convolutionBackpropData, 1ul) : NetworkHelper::getDequantization(reshapeFromWeights); @@ -87,7 +87,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con reshapeFromWeights->input_value(1), false); } - if (is_type(resultConstant)) { + if (ov::is_type(resultConstant)) { replace_node(weightsInput, resultConstant); } } else { @@ -113,7 +113,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con const auto copyNode = convolutionBackpropData->copy_with_new_inputs(inputs); const auto relaxedConvolutionBackpropData = std::make_shared>( - *as_type_ptr(copyNode), + *ov::as_type_ptr(copyNode), std::vector{deqPrecision, deqPrecision}, std::vector{deqPrecision}); @@ -126,7 +126,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con replace_node(convolutionBackpropData, newMultiplyAfter); convolutionBackpropData = newMultiplyAfter->get_input_node_shared_ptr(0); inputs[0] = convolutionBackpropData->get_input_node_ptr(0)->input_value(0); - if (is_type(convolutionBackpropData->get_input_node_ptr(0))) { + if (ov::is_type(convolutionBackpropData->get_input_node_ptr(0))) { auto newConvolution = convolutionBackpropData->copy_with_new_inputs(inputs); replace_node(convolutionBackpropData, newConvolution); convolutionBackpropData = newConvolution; @@ -137,16 +137,16 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con decomposeFakeQuantizeForWeightsPath(convolutionBackpropData, 1ul); dequantization = NetworkHelper::getDequantization(convolutionBackpropData, 1ul); - if (is_type(dequantization.data.get_node())) { - const std::shared_ptr fq = as_type_ptr(dequantization.data.get_node_shared_ptr()); + if (ov::is_type(dequantization.data.get_node())) { + const std::shared_ptr fq = ov::as_type_ptr(dequantization.data.get_node_shared_ptr()); std::shared_ptr newFQ = NetworkHelper::fold_fake_quantize(fq, true); NetworkHelper::copyInfo(fq, newFQ); replace_node(fq, newFQ); } - std::shared_ptr multiplyFromWeights = as_type_ptr( + std::shared_ptr multiplyFromWeights = ov::as_type_ptr( convolutionBackpropData->input_value(1).get_node_shared_ptr()); - std::shared_ptr subtractFromWeights = as_type_ptr(multiplyFromWeights->get_input_node_shared_ptr(0)); + std::shared_ptr subtractFromWeights = ov::as_type_ptr(multiplyFromWeights->get_input_node_shared_ptr(0)); { const auto newScalePShape = multiplyFromWeights->get_input_partial_shape(1); @@ -173,7 +173,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con if (optimizedSubtract == nullptr) { subtractFromWeights = nullptr; } else { - subtractFromWeights = as_type_ptr(optimizedSubtract); + subtractFromWeights = ov::as_type_ptr(optimizedSubtract); const auto weightsPShape = subtractFromWeights->get_input_partial_shape(0); assert(weightsPShape.is_static()); @@ -190,7 +190,7 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con } std::shared_ptr convertFromWeights = - as_type_ptr( + ov::as_type_ptr( subtractFromWeights == nullptr ? multiplyFromWeights->get_input_node_shared_ptr(0) : subtractFromWeights->get_input_node_shared_ptr(0)); @@ -209,11 +209,11 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con updateOutput(context, finalDequantization, convolutionBackpropData); auto onWeights = convolutionBackpropData->get_input_node_shared_ptr(1); - if (is_type(onWeights)) { + if (ov::is_type(onWeights)) { onWeights = onWeights->get_input_node_shared_ptr(0); } - if (is_type(onWeights)) { + if (ov::is_type(onWeights)) { auto& rt = onWeights->get_rt_info(); rt["DISABLED_CONSTANT_FOLDING"] = std::make_shared>(""); } diff --git a/inference-engine/src/low_precision_transformations/src/depth_to_space.cpp b/inference-engine/src/low_precision_transformations/src/depth_to_space.cpp index 09d3b6fac17e33..3e66bfd0e04b6b 100644 --- a/inference-engine/src/low_precision_transformations/src/depth_to_space.cpp +++ b/inference-engine/src/low_precision_transformations/src/depth_to_space.cpp @@ -51,7 +51,7 @@ bool DepthToSpaceTransformation::canBeTransformed(const TransformationContext& c const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(layer); if (dequantization.multiply != nullptr) { - auto multiplyConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); + auto multiplyConst = ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); if (!NetworkHelper::isScalarLike(multiplyConst)) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/eltwise_base_transformation.cpp b/inference-engine/src/low_precision_transformations/src/eltwise_base_transformation.cpp index 54e87798a64355..b2ae84b19f955d 100644 --- a/inference-engine/src/low_precision_transformations/src/eltwise_base_transformation.cpp +++ b/inference-engine/src/low_precision_transformations/src/eltwise_base_transformation.cpp @@ -41,8 +41,8 @@ bool EltwiseBaseTransformation::canBeTransformed(const TransformationContext& co return false; } - if ((as_type_ptr(operation->get_input_node_shared_ptr(0)) || - as_type_ptr(operation->get_input_node_shared_ptr(1))) && + if ((ov::as_type_ptr(operation->get_input_node_shared_ptr(0)) || + ov::as_type_ptr(operation->get_input_node_shared_ptr(1))) && !FakeQuantizeDequantization::checkElementwise(operation)) { NetworkHelper::cleanRunTimeInfo(operation); } @@ -65,18 +65,18 @@ bool EltwiseBaseTransformation::canBeTransformed(const TransformationContext& co } static bool isTargetType(const std::shared_ptr node) { - return is_type(node) || - is_type(node) || - is_type(node); + return ov::is_type(node) || + ov::is_type(node) || + ov::is_type(node); } static std::shared_ptr getDataParent(const std::shared_ptr branchData) { std::shared_ptr parent = branchData; - while (is_type(parent)) { + while (ov::is_type(parent)) { parent = parent->get_input_node_shared_ptr(0); } - if (is_type(parent) && isTargetType(parent->get_input_node_shared_ptr(0))) { + if (ov::is_type(parent) && isTargetType(parent->get_input_node_shared_ptr(0))) { return parent->get_input_node_shared_ptr(0); } return parent; @@ -96,12 +96,12 @@ static bool isBranchHaveMultipleConsumers(const std::shared_ptr branchData // return branch index with FP32 precision after eltwise transformation int EltwiseBaseTransformation::getNotEmpty(const std::shared_ptr& eltwise) const { const FakeQuantizeDequantization dequantization1 = pass::low_precision::NetworkHelper::getDequantization(eltwise, 0ul); - if (as_type(dequantization1.data.get_node())) { + if (ov::as_type(dequantization1.data.get_node())) { return -1; } const FakeQuantizeDequantization dequantization2 = pass::low_precision::NetworkHelper::getDequantization(eltwise, 1ul); - if (as_type(dequantization2.data.get_node())) { + if (ov::as_type(dequantization2.data.get_node())) { return -1; } @@ -130,9 +130,9 @@ int EltwiseBaseTransformation::getNotEmpty(const std::shared_ptr& eltwise) } const std::shared_ptr fakeQuantize1 = - as_type_ptr(dequantization1.data.get_node_shared_ptr()); + ov::as_type_ptr(dequantization1.data.get_node_shared_ptr()); const std::shared_ptr fakeQuantize2 = - as_type_ptr(dequantization2.data.get_node_shared_ptr()); + ov::as_type_ptr(dequantization2.data.get_node_shared_ptr()); if (fakeQuantize1 && !fakeQuantize2) { return 0; @@ -151,11 +151,11 @@ int EltwiseBaseTransformation::getNotEmpty(const std::shared_ptr& eltwise) return 1; } - if (is_type(dequantization1.data.get_node())) { + if (ov::is_type(dequantization1.data.get_node())) { return 0; } - if (is_type(dequantization2.data.get_node())) { + if (ov::is_type(dequantization2.data.get_node())) { return 1; } @@ -199,17 +199,17 @@ std::pair EltwiseBaseTransformation::getMultiplyConstBranch(const std: const auto dequantization2 = NetworkHelper::getDequantization(eltwise, 1); std::shared_ptr constParent = dequantization1.empty() ? - as_type_ptr(parent1) : - as_type_ptr(dequantization1.data.get_node_shared_ptr()); - std::shared_ptr multiplyParent = as_type_ptr(parent2); + ov::as_type_ptr(parent1) : + ov::as_type_ptr(dequantization1.data.get_node_shared_ptr()); + std::shared_ptr multiplyParent = ov::as_type_ptr(parent2); int multiplyBranch = 1; if (constParent == nullptr || multiplyParent == nullptr) { constParent = dequantization2.empty() ? - as_type_ptr(parent2) : - as_type_ptr(dequantization2.data.get_node_shared_ptr()); - multiplyParent = as_type_ptr(parent1); + ov::as_type_ptr(parent2) : + ov::as_type_ptr(dequantization2.data.get_node_shared_ptr()); + multiplyParent = ov::as_type_ptr(parent1); multiplyBranch = 0; } @@ -220,14 +220,14 @@ std::pair EltwiseBaseTransformation::getMultiplyConstBranch(const std: auto multiplyParentParent1 = multiplyParent->get_input_node_shared_ptr(0); auto multiplyParentParent2 = multiplyParent->get_input_node_shared_ptr(1); - auto multiplyParentParent = as_type_ptr(multiplyParentParent1); - auto multiplyParentConst = as_type_ptr(multiplyParentParent2); + auto multiplyParentParent = ov::as_type_ptr(multiplyParentParent1); + auto multiplyParentConst = ov::as_type_ptr(multiplyParentParent2); int multiplyActBranch = 0; if (multiplyParentConst == nullptr) { - multiplyParentParent = as_type_ptr(multiplyParentParent2); - multiplyParentConst = as_type_ptr(multiplyParentParent1); + multiplyParentParent = ov::as_type_ptr(multiplyParentParent2); + multiplyParentConst = ov::as_type_ptr(multiplyParentParent1); multiplyActBranch = 1; } diff --git a/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp index 405e8fca87a9d9..cab841e3bc598e 100644 --- a/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp @@ -68,11 +68,11 @@ static std::shared_ptr updateShape(std::shared_ptr constantOp, const } static std::shared_ptr getData(const std::shared_ptr& eltwise) { - if (!is_type(eltwise->get_input_node_shared_ptr(0))) { + if (!ov::is_type(eltwise->get_input_node_shared_ptr(0))) { return eltwise->get_input_node_shared_ptr(0); } - if (!is_type(eltwise->get_input_node_shared_ptr(1))) { + if (!ov::is_type(eltwise->get_input_node_shared_ptr(1))) { return eltwise->get_input_node_shared_ptr(1); } @@ -84,12 +84,12 @@ static std::shared_ptr getConstant(const std::shared_ptr return nullptr; } - std::shared_ptr constant = as_type_ptr(eltwise->get_input_node_shared_ptr(1)); + std::shared_ptr constant = ov::as_type_ptr(eltwise->get_input_node_shared_ptr(1)); if (constant != nullptr) { return constant; } - return as_type_ptr(eltwise->get_input_node_shared_ptr(0)); + return ov::as_type_ptr(eltwise->get_input_node_shared_ptr(0)); } } // namespace fq @@ -136,12 +136,12 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis std::shared_ptr inputHighConst_f32 = foldConvert(fakeQuantize->get_input_node_shared_ptr(2), deqPrecision); std::shared_ptr constant = fq::getConstant(eltwise); - if (is_type(eltwise) && checkElementwise(eltwise)) { + if (ov::is_type(eltwise) && checkElementwise(eltwise)) { const auto value = constant->get_output_element_type(0) == deqPrecision ? constant : foldConvert(constant, deqPrecision); - const auto valueVec = as_type_ptr(value)->cast_vector(); + const auto valueVec = ov::as_type_ptr(value)->cast_vector(); if (std::any_of(valueVec.cbegin(), valueVec.cend(), [](const float value) { return value <= 0.f; })) { return nullptr; @@ -149,8 +149,8 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis inputLowConst_f32 = fold(inputLowConst_f32, value); inputHighConst_f32 = fold(inputHighConst_f32, value); - const auto resultLow = as_type_ptr(inputLowConst_f32)->cast_vector(); - const auto resultHigh = as_type_ptr(inputHighConst_f32)->cast_vector(); + const auto resultLow = ov::as_type_ptr(inputLowConst_f32)->cast_vector(); + const auto resultHigh = ov::as_type_ptr(inputHighConst_f32)->cast_vector(); if (std::any_of(resultLow.begin(), resultLow.end(), [](const float value){ return std::isinf(value); }) || std::any_of(resultHigh.begin(), resultHigh.end(), [](const float value){ return std::isinf(value); })) { return nullptr; @@ -158,18 +158,18 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis inputLowConst_f32 = fq::updateShape(inputLowConst_f32, fakeQuantize->get_output_partial_shape(0)); inputHighConst_f32 = fq::updateShape(inputHighConst_f32, fakeQuantize->get_output_partial_shape(0)); - } else if (is_type(eltwise) && checkElementwise(eltwise)) { + } else if (ov::is_type(eltwise) && checkElementwise(eltwise)) { const auto value = constant->get_output_element_type(0) == deqPrecision ? constant : foldConvert(constant, deqPrecision); inputLowConst_f32 = fq::updateShape(fold(inputLowConst_f32, value), fakeQuantize->get_output_partial_shape(0)); inputHighConst_f32 = fq::updateShape(fold(inputHighConst_f32, value), fakeQuantize->get_output_partial_shape(0)); - } else if (is_type(eltwise) && checkElementwise(eltwise)) { - if (is_type(fq::getData(eltwise)) || - is_type(fq::getData(eltwise)) || - is_type(fq::getData(eltwise)) || - is_type(fq::getData(eltwise))) { + } else if (ov::is_type(eltwise) && checkElementwise(eltwise)) { + if (ov::is_type(fq::getData(eltwise)) || + ov::is_type(fq::getData(eltwise)) || + ov::is_type(fq::getData(eltwise)) || + ov::is_type(fq::getData(eltwise))) { return nullptr; } @@ -179,7 +179,7 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis inputLowConst_f32 = fq::updateShape(fold(inputLowConst_f32, value), fakeQuantize->get_output_partial_shape(0)); inputHighConst_f32 = fq::updateShape(fold(inputHighConst_f32, value), fakeQuantize->get_output_partial_shape(0)); - } else if (is_type(eltwise)) { + } else if (ov::is_type(eltwise)) { // issue #40611 if ((eltwise->get_input_element_type(0) == element::i32) && ((eltwise->get_output_element_type(0) == element::f16) || (eltwise->get_output_element_type(0) == element::f32))) { @@ -192,7 +192,7 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis const auto data = fq::getData(eltwise); const size_t outputIdx = NetworkHelper::getParentOutputIndex(data, eltwise); - const auto newFakeQuantize = as_type_ptr(fakeQuantize->clone_with_new_inputs({ + const auto newFakeQuantize = ov::as_type_ptr(fakeQuantize->clone_with_new_inputs({ data->output(outputIdx), inputLowConst_f32, inputHighConst_f32, diff --git a/inference-engine/src/low_precision_transformations/src/fake_quantize_decomposition.cpp b/inference-engine/src/low_precision_transformations/src/fake_quantize_decomposition.cpp index b522546c55e342..fda2858f6df95e 100644 --- a/inference-engine/src/low_precision_transformations/src/fake_quantize_decomposition.cpp +++ b/inference-engine/src/low_precision_transformations/src/fake_quantize_decomposition.cpp @@ -95,8 +95,8 @@ DataPrecision getDataPrecisionByOutputPortAndFakeQuantize(std::shared_ptr layer) { const size_t levels = layer->get_levels(); - const std::vector outputLowValues = as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); - const std::vector outputHighValues = as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); + const std::vector outputLowValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); + const std::vector outputHighValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); auto precisionsAttribute = getAttributeFromOutput>(layer->output(0)); if (precisionsAttribute == nullptr) { @@ -166,8 +166,8 @@ std::shared_ptr decomposeFakeQuantize( std::shared_ptr dequantize; if (intervalsAlignment != nullptr) { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::LPT_LT, "decomposeFakeQuantize1"); - const std::vector outputLowValues = as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); - const std::vector outputHighValues = as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); + const std::vector outputLowValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); + const std::vector outputHighValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); float dequantizationMul; float dequantizationSub; @@ -230,7 +230,7 @@ std::shared_ptr decomposeFakeQuantize( OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::LPT_LT, "decomposeFakeQuantize2"); // Split FakeQuantize to two parts: Quantize and Dequantize auto QDQ = NetworkHelper::decomposeFakeQuantize( - as_type_ptr(layer), + ov::as_type_ptr(layer), dataPrecision.precision, dataPrecision.min, dataPrecision.max, @@ -251,7 +251,7 @@ std::shared_ptr decomposeFakeQuantize( } // namespace fq_decomposition bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher& m) { - auto layer = as_type_ptr(m.get_match_root()); + auto layer = ov::as_type_ptr(m.get_match_root()); if (!NetworkHelper::isQuantizeSupported(layer)) { return false; } @@ -343,8 +343,8 @@ bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& c if (dataPrecision.precision == element::undefined) { element::Type precision; const auto levels = layer->get_levels(); - const std::vector outputLowValues = as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); - const std::vector outputHighValues = as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); + const std::vector outputLowValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); + const std::vector outputHighValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); if (intervalsAlignment == nullptr) { // define precision by FakeQuantize intervals LayerTransformation::PrecisionDetails precisionDetailsAtOutputIntervals = LayerTransformation::getPrecisionDetails( diff --git a/inference-engine/src/low_precision_transformations/src/fake_quantize_dequantization.cpp b/inference-engine/src/low_precision_transformations/src/fake_quantize_dequantization.cpp index da84ed329a7dff..14a0104a46ca6a 100644 --- a/inference-engine/src/low_precision_transformations/src/fake_quantize_dequantization.cpp +++ b/inference-engine/src/low_precision_transformations/src/fake_quantize_dequantization.cpp @@ -42,9 +42,9 @@ bool FakeQuantizeDequantization::multiplyHasZeroOrDenormal() const { return false; } - std::shared_ptr multiplyConstant = as_type_ptr(multiply->get_input_node_shared_ptr(1)); + std::shared_ptr multiplyConstant = ov::as_type_ptr(multiply->get_input_node_shared_ptr(1)); if (multiplyConstant == nullptr) { - multiplyConstant = as_type_ptr(multiply->get_input_node_shared_ptr(0)); + multiplyConstant = ov::as_type_ptr(multiply->get_input_node_shared_ptr(0)); } if (multiplyConstant == nullptr) { return false; @@ -163,11 +163,11 @@ int FakeQuantizeDequantization::fillDequantizationParams( const size_t branchIndex, std::shared_ptr& convert, std::shared_ptr& constant) { - convert = as_type_ptr(elementwise->get_input_node_shared_ptr(branchIndex)); + convert = ov::as_type_ptr(elementwise->get_input_node_shared_ptr(branchIndex)); if (convert != nullptr) { - constant = as_type_ptr(convert->get_input_node_shared_ptr(0)); + constant = ov::as_type_ptr(convert->get_input_node_shared_ptr(0)); } else { - constant = as_type_ptr(elementwise->get_input_node_shared_ptr(branchIndex)); + constant = ov::as_type_ptr(elementwise->get_input_node_shared_ptr(branchIndex)); } }; @@ -187,12 +187,12 @@ int FakeQuantizeDequantization::fillDequantizationParams( int FakeQuantizeDequantization::fillDequantizationParams( const std::shared_ptr& elementwise, std::shared_ptr& constant) noexcept { - constant = as_type_ptr(elementwise->get_input_node_shared_ptr(1ul)); + constant = ov::as_type_ptr(elementwise->get_input_node_shared_ptr(1ul)); if (constant != nullptr) { return 1; } - constant = as_type_ptr(elementwise->get_input_node_shared_ptr(0ul)); + constant = ov::as_type_ptr(elementwise->get_input_node_shared_ptr(0ul)); if (constant != nullptr) { return 0; } diff --git a/inference-engine/src/low_precision_transformations/src/fold_convert.cpp b/inference-engine/src/low_precision_transformations/src/fold_convert.cpp index 5e673a1ef512f4..f7a3255df49e71 100644 --- a/inference-engine/src/low_precision_transformations/src/fold_convert.cpp +++ b/inference-engine/src/low_precision_transformations/src/fold_convert.cpp @@ -38,12 +38,12 @@ bool FoldConvertTransformation::transform(TransformationContext& context, ngraph auto foldConvert = [&](const size_t branch) { const auto convert = subtract->get_input_node_shared_ptr(branch); - if (!is_type(convert) || !is_type(convert->get_input_node_shared_ptr(0))) { + if (!ov::is_type(convert) || !ov::is_type(convert->get_input_node_shared_ptr(0))) { return; } const auto resultConstant = ngraph::pass::low_precision::foldConvert(convert->get_input_node_shared_ptr(0), convert->output(0).get_element_type()); - assert(is_type(resultConstant)); + assert(ov::is_type(resultConstant)); replace_node(convert, resultConstant); updateOutput(context, resultConstant, convert); @@ -57,10 +57,10 @@ bool FoldConvertTransformation::transform(TransformationContext& context, ngraph bool FoldConvertTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr operation) const { return - (is_type(operation->get_input_node_ptr(1)) && - is_type(operation->get_input_node_ptr(1)->get_input_node_ptr(0))) || - (is_type(operation->get_input_node_ptr(0)) && - is_type(operation->get_input_node_ptr(0)->get_input_node_ptr(0))); + (ov::is_type(operation->get_input_node_ptr(1)) && + ov::is_type(operation->get_input_node_ptr(1)->get_input_node_ptr(0))) || + (ov::is_type(operation->get_input_node_ptr(0)) && + ov::is_type(operation->get_input_node_ptr(0)->get_input_node_ptr(0))); } bool FoldConvertTransformation::isPrecisionPreserved(std::shared_ptr layer) const noexcept { diff --git a/inference-engine/src/low_precision_transformations/src/fold_fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fold_fake_quantize.cpp index 7984d946f865ac..5eb0797123e393 100644 --- a/inference-engine/src/low_precision_transformations/src/fold_fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fold_fake_quantize.cpp @@ -33,7 +33,7 @@ FoldFakeQuantizeTransformation::FoldFakeQuantizeTransformation(const Params& par } bool FoldFakeQuantizeTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { - const auto fakeQuantize = as_type_ptr(m.get_match_root()); + const auto fakeQuantize = ov::as_type_ptr(m.get_match_root()); if (fakeQuantize == nullptr) { return false; } @@ -51,7 +51,7 @@ bool FoldFakeQuantizeTransformation::transform(TransformationContext& context, n fakeQuantize, false, (constantShape.rank().get_length() < 2) || constantShape[1] != 1ul ? 1ul : 0ul); - if (is_type(resultConstant)) { + if (ov::is_type(resultConstant)) { replace_node(fakeQuantize, resultConstant); return true; } diff --git a/inference-engine/src/low_precision_transformations/src/fuse_convert.cpp b/inference-engine/src/low_precision_transformations/src/fuse_convert.cpp index 48fbea0211946a..3533bb66213653 100644 --- a/inference-engine/src/low_precision_transformations/src/fuse_convert.cpp +++ b/inference-engine/src/low_precision_transformations/src/fuse_convert.cpp @@ -62,26 +62,26 @@ bool FuseConvertTransformation::transform(TransformationContext& context, ngraph return false; } - const auto convert = as_type_ptr(op->get_input_node_shared_ptr(0)); + const auto convert = ov::as_type_ptr(op->get_input_node_shared_ptr(0)); std::shared_ptr parent = convert->get_input_node_shared_ptr(0); - if (is_type(parent)) { + if (ov::is_type(parent)) { auto convertedConstant = foldConvert(parent, convert->get_convert_element_type()); NetworkHelper::copyInfo(parent, convertedConstant); replace_node(convert, convertedConstant); } else { std::shared_ptr newOp; - if (is_type(op)) { - auto subtract = as_type_ptr(op); + if (ov::is_type(op)) { + auto subtract = ov::as_type_ptr(op); newOp = removeConvertIfPossibleForSubtract(convert, subtract); - } else if (is_type(op)) { + } else if (ov::is_type(op)) { newOp = std::make_shared>( std::vector{ element::f32, element::f32 }, std::vector{}, ngraph::op::TemporaryReplaceOutputType(convert->get_input_source_output(0), element::f32).get(), ngraph::op::TemporaryReplaceOutputType(op->get_input_node_shared_ptr(1), element::f32).get()); NetworkHelper::setOutDataPrecisionForTypeRelaxed(newOp, op->get_output_element_type(0)); replace_node(op, newOp); - } else if (is_type(op)) { + } else if (ov::is_type(op)) { newOp = std::make_shared>( std::vector{ element::f32, element::f32 }, std::vector{}, ngraph::op::TemporaryReplaceOutputType(convert->get_input_source_output(0), element::f32).get(), @@ -103,7 +103,7 @@ bool FuseConvertTransformation::transform(TransformationContext& context, ngraph } bool FuseConvertTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr op) const { - const auto convert = as_type_ptr(op->get_input_node_shared_ptr(0)); + const auto convert = ov::as_type_ptr(op->get_input_node_shared_ptr(0)); // issue #40395 if (convert == nullptr) { return false; diff --git a/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp index 6ce7acfad3a979..0c897f468a58b5 100644 --- a/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp @@ -31,7 +31,7 @@ FuseFakeQuantizeTransformation::FuseFakeQuantizeTransformation(const Params& par } bool FuseFakeQuantizeTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { - std::shared_ptr fakeQuantize = as_type_ptr(m.get_match_root()); + std::shared_ptr fakeQuantize = ov::as_type_ptr(m.get_match_root()); do { fakeQuantize = handle(context, fakeQuantize); } while (fakeQuantize != nullptr); @@ -55,11 +55,11 @@ std::shared_ptr updateShape(std::shared_ptr op, const PartialShape& } std::shared_ptr getData(const std::shared_ptr& eltwise) { - if (!is_type(eltwise->get_input_node_shared_ptr(0))) { + if (!ov::is_type(eltwise->get_input_node_shared_ptr(0))) { return eltwise->get_input_node_shared_ptr(0); } - if (!is_type(eltwise->get_input_node_shared_ptr(1))) { + if (!ov::is_type(eltwise->get_input_node_shared_ptr(1))) { return eltwise->get_input_node_shared_ptr(1); } @@ -71,12 +71,12 @@ std::shared_ptr getConstant(const std::shared_ptr& eltwi return nullptr; } - std::shared_ptr constant = as_type_ptr(eltwise->get_input_node_shared_ptr(1)); + std::shared_ptr constant = ov::as_type_ptr(eltwise->get_input_node_shared_ptr(1)); if (constant != nullptr) { return constant; } - return as_type_ptr(eltwise->get_input_node_shared_ptr(0)); + return ov::as_type_ptr(eltwise->get_input_node_shared_ptr(0)); } bool eltwiseWithConstant(const std::shared_ptr& eltwise) { @@ -122,30 +122,30 @@ std::shared_ptr FuseFakeQuantizeTransformation::handle( std::shared_ptr inputHightConst = fakeQuantize->get_input_node_shared_ptr(2); std::shared_ptr constant = fuse_fq::getConstant(eltwise); - if (is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { + if (ov::is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { const auto value = constant->get_output_element_type(0) == eltwise->get_output_element_type(0) ? constant : foldConvert(constant, eltwise->get_output_element_type(0)); inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_partial_shape(0)); inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_partial_shape(0)); - } else if (is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { + } else if (ov::is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { const auto value = constant->get_output_element_type(0) == eltwise->get_output_element_type(0) ? constant : foldConvert(constant, eltwise->get_output_element_type(0)); inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_partial_shape(0)); inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_partial_shape(0)); - } else if (is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { + } else if (ov::is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { const auto value = constant->get_output_element_type(0) == eltwise->get_output_element_type(0) ? constant : foldConvert(constant, eltwise->get_output_element_type(0)); inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_partial_shape(0)); inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_partial_shape(0)); - } else if (is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { - if (is_type(fuse_fq::getData(eltwise)) || - is_type(fuse_fq::getData(eltwise))) { + } else if (ov::is_type(eltwise) && fuse_fq::eltwiseWithConstant(eltwise)) { + if (ov::is_type(fuse_fq::getData(eltwise)) || + ov::is_type(fuse_fq::getData(eltwise))) { return nullptr; } @@ -155,7 +155,7 @@ std::shared_ptr FuseFakeQuantizeTransformation::handle( inputLowConst = fuse_fq::updateShape(fold(inputLowConst, value), fakeQuantize->get_output_partial_shape(0)); inputHightConst = fuse_fq::updateShape(fold(inputHightConst, value), fakeQuantize->get_output_partial_shape(0)); - } else if (is_type(eltwise)) { + } else if (ov::is_type(eltwise)) { // issue #40611 if ((eltwise->input(0).get_element_type() == element::i32) && (eltwise->output(0).get_element_type() == element::f32)) { return nullptr; @@ -164,7 +164,7 @@ std::shared_ptr FuseFakeQuantizeTransformation::handle( return nullptr; } - std::shared_ptr newFakeQuantize = as_type_ptr(fakeQuantize->clone_with_new_inputs({ + std::shared_ptr newFakeQuantize = ov::as_type_ptr(fakeQuantize->clone_with_new_inputs({ fuse_fq::getData(eltwise), inputLowConst, inputHightConst, diff --git a/inference-engine/src/low_precision_transformations/src/fuse_multiply_to_fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fuse_multiply_to_fake_quantize.cpp index ccff4188d3a5c1..3cab73ba3e9ab1 100644 --- a/inference-engine/src/low_precision_transformations/src/fuse_multiply_to_fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fuse_multiply_to_fake_quantize.cpp @@ -38,11 +38,11 @@ bool FuseMultiplyToFakeQuantizeTransformation::transform(TransformationContext& } const auto parent = multiply->get_input_node_shared_ptr(0); - auto fakeQuantize = as_type_ptr(parent); - const auto convert = as_type_ptr(parent); + auto fakeQuantize = ov::as_type_ptr(parent); + const auto convert = ov::as_type_ptr(parent); if (convert) { - fakeQuantize = as_type_ptr(convert->get_input_node_shared_ptr(0)); + fakeQuantize = ov::as_type_ptr(convert->get_input_node_shared_ptr(0)); } const auto multiplyConstant = multiply->get_input_node_shared_ptr(1); @@ -90,7 +90,7 @@ bool FuseMultiplyToFakeQuantizeTransformation::transform(TransformationContext& } bool FuseMultiplyToFakeQuantizeTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr operation) const { - if (!is_type(operation->get_input_node_shared_ptr(1))) { + if (!ov::is_type(operation->get_input_node_shared_ptr(1))) { return false; } @@ -99,11 +99,11 @@ bool FuseMultiplyToFakeQuantizeTransformation::canBeTransformed(const Transforma } const auto parent = operation->get_input_node_shared_ptr(0); - auto fq = as_type_ptr(parent); - const auto convert = as_type_ptr(parent); + auto fq = ov::as_type_ptr(parent); + const auto convert = ov::as_type_ptr(parent); if (convert) { - fq = as_type_ptr(convert->get_input_node_shared_ptr(0)); + fq = ov::as_type_ptr(convert->get_input_node_shared_ptr(0)); } if (!fq) { diff --git a/inference-engine/src/low_precision_transformations/src/fuse_subtract_to_fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fuse_subtract_to_fake_quantize.cpp index b8ec9b192fd272..edd8ee35cb460e 100644 --- a/inference-engine/src/low_precision_transformations/src/fuse_subtract_to_fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fuse_subtract_to_fake_quantize.cpp @@ -37,11 +37,11 @@ bool FuseSubtractToFakeQuantizeTransformation::transform(TransformationContext& } const auto parent = subtract->get_input_node_shared_ptr(0); - auto fakeQuantize = as_type_ptr(parent); - const auto convert = as_type_ptr(parent); + auto fakeQuantize = ov::as_type_ptr(parent); + const auto convert = ov::as_type_ptr(parent); if (convert) { - fakeQuantize = as_type_ptr(convert->get_input_node_shared_ptr(0)); + fakeQuantize = ov::as_type_ptr(convert->get_input_node_shared_ptr(0)); } const auto subtractConstant = subtract->get_input_node_shared_ptr(1); @@ -84,7 +84,7 @@ bool FuseSubtractToFakeQuantizeTransformation::transform(TransformationContext& } bool FuseSubtractToFakeQuantizeTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr operation) const { - if (!is_type(operation->get_input_node_shared_ptr(1))) { + if (!ov::is_type(operation->get_input_node_shared_ptr(1))) { return false; } @@ -95,20 +95,20 @@ bool FuseSubtractToFakeQuantizeTransformation::canBeTransformed(const Transforma const auto children = operation->get_output_target_inputs(0); for (const auto& target : children) { - const auto convolution = is_type(target.get_node()); - const auto groupConvolution = is_type(target.get_node()); - const auto convolutionBackpropData = is_type(target.get_node()); + const auto convolution = ov::is_type(target.get_node()); + const auto groupConvolution = ov::is_type(target.get_node()); + const auto convolutionBackpropData = ov::is_type(target.get_node()); if (convolution || groupConvolution || convolutionBackpropData) { return false; } } const auto parent = operation->get_input_node_shared_ptr(0); - auto fq = as_type_ptr(parent); - const auto convert = as_type_ptr(parent); + auto fq = ov::as_type_ptr(parent); + const auto convert = ov::as_type_ptr(parent); if (convert) { - fq = as_type_ptr(convert->get_input_node_shared_ptr(0)); + fq = ov::as_type_ptr(convert->get_input_node_shared_ptr(0)); } if (!fq) { diff --git a/inference-engine/src/low_precision_transformations/src/interpolate.cpp b/inference-engine/src/low_precision_transformations/src/interpolate.cpp index c167a6713b642f..ffc5319278ade2 100644 --- a/inference-engine/src/low_precision_transformations/src/interpolate.cpp +++ b/inference-engine/src/low_precision_transformations/src/interpolate.cpp @@ -63,13 +63,13 @@ bool InterpolateTransformation::transform(TransformationContext &context, ngraph } bool InterpolateTransformation::isPrecisionPreserved(std::shared_ptr layer) const noexcept { - std::shared_ptr interpolate1 = as_type_ptr(layer); + std::shared_ptr interpolate1 = ov::as_type_ptr(layer); if (interpolate1) { const auto attrs = interpolate1->get_attrs(); return attrs.mode == "nearest"; } - std::shared_ptr interpolate4 = as_type_ptr(layer); + std::shared_ptr interpolate4 = ov::as_type_ptr(layer); if (interpolate4) { const auto attrs = interpolate4->get_attrs(); return attrs.mode == op::v4::Interpolate::InterpolateMode::NEAREST; @@ -90,7 +90,7 @@ bool InterpolateTransformation::canBeTransformed(const TransformationContext& co return false; } - const auto interpolate1 = as_type_ptr(layer); + const auto interpolate1 = ov::as_type_ptr(layer); if (interpolate1) { const auto interpAttrs = interpolate1->get_attrs(); if (interpAttrs.axes.count(0) || interpAttrs.axes.count(1)) { @@ -104,7 +104,7 @@ bool InterpolateTransformation::canBeTransformed(const TransformationContext& co } } - const auto interpolate4 = as_type_ptr(layer); + const auto interpolate4 = ov::as_type_ptr(layer); if (interpolate4) { const auto interpAttrs = interpolate4->get_attrs(); diff --git a/inference-engine/src/low_precision_transformations/src/layer_transformation.cpp b/inference-engine/src/low_precision_transformations/src/layer_transformation.cpp index 14d21fa29b67c3..1b05f965dc1bab 100644 --- a/inference-engine/src/low_precision_transformations/src/layer_transformation.cpp +++ b/inference-engine/src/low_precision_transformations/src/layer_transformation.cpp @@ -147,9 +147,9 @@ bool LayerTransformation::canSubtractBeHandled(const std::shared_ptr& op, const auto parent = dequantization.subtract->input_value(1).get_node_shared_ptr(); - if (is_type(parent)) { + if (ov::is_type(parent)) { return true; - } else if (is_type(parent) && is_type(parent->get_input_node_shared_ptr(0))) { + } else if (ov::is_type(parent) && ov::is_type(parent->get_input_node_shared_ptr(0))) { const auto constant = parent->get_input_node_shared_ptr(0); const auto constantType = constant->output(0).get_element_type(); return operationType == constantType; @@ -171,7 +171,7 @@ std::stringstream toStream(const std::vector& dequantizationValues) { } void LayerTransformation::printDequantizationInfo(const std::shared_ptr& layer) { - const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(as_type_ptr(layer)); + const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(ov::as_type_ptr(layer)); std::cout << layer->get_type_name() << (NetworkHelper::isConstantPath(layer) ? " on weights " : " on activations ") << layer->get_friendly_name() << ":" << std::endl << @@ -337,7 +337,7 @@ void LayerTransformation::updateOutput( // TODO: not tested!!! for (auto output : lastNode->outputs()) { for (auto input : output.get_target_inputs()) { - if (is_type(input.get_node())) { + if (ov::is_type(input.get_node())) { const std::string originalName = originalNode->get_friendly_name(); originalNode->set_friendly_name(originalName + LayerTransformation::originalLayerPostfix); lastNode->set_friendly_name(originalName); diff --git a/inference-engine/src/low_precision_transformations/src/low_precision.cpp b/inference-engine/src/low_precision_transformations/src/low_precision.cpp index f33df2e5c89a74..be040eb122afcf 100644 --- a/inference-engine/src/low_precision_transformations/src/low_precision.cpp +++ b/inference-engine/src/low_precision_transformations/src/low_precision.cpp @@ -95,7 +95,7 @@ void make_matcher_type_relaxed(ngraph::pass::GraphRewrite* transformation) { using namespace ngraph; auto is_op_type = [](std::shared_ptr n) { - return !!as_type_ptr(n); + return !!ov::as_type_ptr(n); }; auto p_node = std::make_shared(element::f32, Shape{}, is_op_type); @@ -270,7 +270,7 @@ bool ngraph::pass::low_precision::LowPrecision::isFunctionQuantized(const std::s continue; } - const std::shared_ptr fakeQuantize = as_type_ptr(parent); + const std::shared_ptr fakeQuantize = ov::as_type_ptr(parent); if ((fakeQuantize != nullptr) && QuantizationDetails::outputLayoutIsSupported(fakeQuantize) && QuantizationDetails::isSupportedLevel(fakeQuantize->get_levels())) { diff --git a/inference-engine/src/low_precision_transformations/src/markup_precisions.cpp b/inference-engine/src/low_precision_transformations/src/markup_precisions.cpp index 7cf2c5b3236d24..d226252748ec69 100644 --- a/inference-engine/src/low_precision_transformations/src/markup_precisions.cpp +++ b/inference-engine/src/low_precision_transformations/src/markup_precisions.cpp @@ -83,7 +83,7 @@ bool ngraph::pass::low_precision::MarkupPrecisions::run_on_function(std::shared_ // TODO: don't need to set restrictions for not supported operations // if don't set restrictions for not supported operations then accuracy drop appears, issue #59197 - const bool supported = is_type(node) || isSupported(node); + const bool supported = ov::is_type(node) || isSupported(node); if (!supported || !LayerTransformation::canBeTransformedStatic(node)) { setRestriction(node, std::vector>> { {0ul, {}}}); continue; @@ -157,14 +157,14 @@ bool ngraph::pass::low_precision::MarkupPrecisions::isPrecisionPreserved(const s return precisionPreserved; } - if (is_type(node)) { - std::shared_ptr interpolate1 = as_type_ptr(node); + if (ov::is_type(node)) { + std::shared_ptr interpolate1 = ov::as_type_ptr(node); if (interpolate1) { const auto attrs = interpolate1->get_attrs(); return attrs.mode == "nearest"; } - std::shared_ptr interpolate4 = as_type_ptr(node); + std::shared_ptr interpolate4 = ov::as_type_ptr(node); if (interpolate4) { const auto attrs = interpolate4->get_attrs(); return attrs.mode == op::v4::Interpolate::InterpolateMode::NEAREST; diff --git a/inference-engine/src/low_precision_transformations/src/mat_mul.cpp b/inference-engine/src/low_precision_transformations/src/mat_mul.cpp index 83f08fd4ed35fa..64816e8c541b46 100644 --- a/inference-engine/src/low_precision_transformations/src/mat_mul.cpp +++ b/inference-engine/src/low_precision_transformations/src/mat_mul.cpp @@ -40,18 +40,18 @@ MatMulTransformation::MatMulTransformation(const Params& params) : LayerTransfor } bool MatMulTransformation::transform(TransformationContext &context, ngraph::pattern::Matcher &m) { - std::shared_ptr matMul = as_type_ptr(m.get_match_root()); + std::shared_ptr matMul = ov::as_type_ptr(m.get_match_root()); if ((matMul == nullptr) || !canBeTransformed(context, matMul)) { return false; } - matMul = as_type_ptr(NetworkHelper::separateInStandaloneBranch(matMul)); + matMul = ov::as_type_ptr(NetworkHelper::separateInStandaloneBranch(matMul)); const auto dequantization1 = NetworkHelper::getDequantization(matMul, 0); auto dequantization2 = NetworkHelper::getDequantization(matMul, 1); if (dequantization2.empty()) { const std::shared_ptr fakeQuantize = - as_type_ptr(dequantization2.data.get_node_shared_ptr()); + ov::as_type_ptr(dequantization2.data.get_node_shared_ptr()); if (fakeQuantize != nullptr) { const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(fakeQuantize); @@ -90,7 +90,7 @@ bool MatMulTransformation::transform(TransformationContext &context, ngraph::pat // dequantization with subtract on activations & constant weights if (dequantization1.subtract) { - auto broadcastShape = NetworkHelper::isScalarLike(as_type_ptr(dequantization1.subtractConstant)) ? + auto broadcastShape = NetworkHelper::isScalarLike(ov::as_type_ptr(dequantization1.subtractConstant)) ? Shape(dequantization1.subtract->get_output_partial_shape(0).rank().get_length(), 1) : dequantization1.subtractConstant->get_shape(); @@ -139,8 +139,8 @@ bool MatMulTransformation::transform(TransformationContext &context, ngraph::pat const auto mulConst1 = matMul->get_transpose_a() ? transpose(dequantization1.multiplyConstant) : dequantization1.multiplyConstant; auto mulConst2 = matMul->get_transpose_b() ? transpose(dequantization2.multiplyConstant) : dequantization2.multiplyConstant; - if (NetworkHelper::isScalarLike(as_type_ptr(mulConst2))) { - mulConst2 = NetworkHelper::toScalar(as_type_ptr(mulConst2)); + if (NetworkHelper::isScalarLike(ov::as_type_ptr(mulConst2))) { + mulConst2 = NetworkHelper::toScalar(ov::as_type_ptr(mulConst2)); } else { const auto constShape = mulConst2->get_shape(); const size_t inputRank = matMul->get_input_partial_shape(0).rank().get_length(); @@ -194,7 +194,7 @@ bool MatMulTransformation::canBeTransformed(const TransformationContext& context return false; } - std::shared_ptr matMul = as_type_ptr(layer); + std::shared_ptr matMul = ov::as_type_ptr(layer); if (matMul == nullptr) { return false; } @@ -252,7 +252,7 @@ bool MatMulTransformation::canBeTransformed(const TransformationContext& context } } - const auto fakeQuantize = as_type_ptr(layer->get_input_node_shared_ptr(1)); + const auto fakeQuantize = ov::as_type_ptr(layer->get_input_node_shared_ptr(1)); if (fakeQuantize) { if (!QuantizationDetails::outputLayoutIsSupported(fakeQuantize)) { return false; diff --git a/inference-engine/src/low_precision_transformations/src/max_pool.cpp b/inference-engine/src/low_precision_transformations/src/max_pool.cpp index 68a73cac59e522..8cdfbfc7c5af64 100644 --- a/inference-engine/src/low_precision_transformations/src/max_pool.cpp +++ b/inference-engine/src/low_precision_transformations/src/max_pool.cpp @@ -43,7 +43,7 @@ bool MaxPoolTransformation::canBeTransformed(const TransformationContext& contex return false; } - const std::vector scales = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1))->cast_vector(); + const std::vector scales = ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1))->cast_vector(); if (std::any_of(scales.begin(), scales.end(), [](const float value) { return value < 0.0; })) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/multiply.cpp b/inference-engine/src/low_precision_transformations/src/multiply.cpp index 923f77a7d20c37..c5a468cf21c318 100644 --- a/inference-engine/src/low_precision_transformations/src/multiply.cpp +++ b/inference-engine/src/low_precision_transformations/src/multiply.cpp @@ -52,10 +52,10 @@ bool MultiplyTransformation::transform(TransformationContext& context, ngraph::p auto newMultiply = multiply; auto fold_fake_quantizes = [](std::shared_ptr& multiply, const size_t index) { - auto fakeQuantizeOnWeights = as_type_ptr(multiply->get_input_node_shared_ptr(index)); + auto fakeQuantizeOnWeights = ov::as_type_ptr(multiply->get_input_node_shared_ptr(index)); if (fakeQuantizeOnWeights != nullptr) { auto result = NetworkHelper::fold_fake_quantize(fakeQuantizeOnWeights); - if (is_type(result)) { + if (ov::is_type(result)) { replace_node(fakeQuantizeOnWeights, result); } } @@ -165,14 +165,14 @@ bool MultiplyTransformation::canBeTransformed(const TransformationContext& conte FakeQuantizeDequantization dequantization2 = pass::low_precision::NetworkHelper::getDequantization(layer, 1ul); if ((dequantization1.data.get_node() == nullptr) || - (dequantization1.empty() && !is_type(dequantization1.data.get_node_shared_ptr()) && - !is_type(dequantization2.data.get_node_shared_ptr()))) { + (dequantization1.empty() && !ov::is_type(dequantization1.data.get_node_shared_ptr()) && + !ov::is_type(dequantization2.data.get_node_shared_ptr()))) { return false; } if ((dequantization2.data.get_node() == nullptr) || - (dequantization2.empty() && !is_type(dequantization2.data.get_node_shared_ptr()) && - !is_type(dequantization1.data.get_node_shared_ptr()))) { + (dequantization2.empty() && !ov::is_type(dequantization2.data.get_node_shared_ptr()) && + !ov::is_type(dequantization1.data.get_node_shared_ptr()))) { return false; } return EltwiseBaseTransformation::canBeTransformed(context, layer); diff --git a/inference-engine/src/low_precision_transformations/src/multiply_to_group_convolution.cpp b/inference-engine/src/low_precision_transformations/src/multiply_to_group_convolution.cpp index 6851a159fee4ad..162499bd4a4a64 100644 --- a/inference-engine/src/low_precision_transformations/src/multiply_to_group_convolution.cpp +++ b/inference-engine/src/low_precision_transformations/src/multiply_to_group_convolution.cpp @@ -40,7 +40,7 @@ bool MultiplyToGroupConvolutionTransformation::transform(TransformationContext& auto input = multiply->get_input_node_shared_ptr(0); auto constant = multiply->get_input_node_shared_ptr(1); auto inputIndex = 0; - if (!is_type(constant)) { + if (!ov::is_type(constant)) { input = multiply->get_input_node_shared_ptr(1); constant = multiply->get_input_node_shared_ptr(0); inputIndex = 1; @@ -164,15 +164,15 @@ bool MultiplyToGroupConvolutionTransformation::canBeTransformed(const Transforma Shape constShape; int inputIndex; - if (const auto constant = as_type_ptr(operation->get_input_node_shared_ptr(1))) { + if (const auto constant = ov::as_type_ptr(operation->get_input_node_shared_ptr(1))) { inputIndex = 0; constShape = constant->get_shape(); - if (is_type(operation->get_input_node_shared_ptr(0)) || - (is_type(operation->get_input_node_shared_ptr(0)) && - is_type(operation->get_input_node_shared_ptr(0)->get_input_node_shared_ptr(0)))) { + if (ov::is_type(operation->get_input_node_shared_ptr(0)) || + (ov::is_type(operation->get_input_node_shared_ptr(0)) && + ov::is_type(operation->get_input_node_shared_ptr(0)->get_input_node_shared_ptr(0)))) { return false; } - } else if (const auto constant = as_type_ptr(operation->get_input_node_shared_ptr(0))) { + } else if (const auto constant = ov::as_type_ptr(operation->get_input_node_shared_ptr(0))) { inputIndex = 1; constShape = constant->get_shape(); } else { @@ -209,7 +209,7 @@ bool MultiplyToGroupConvolutionTransformation::canBeTransformedToGroupConvolutio const auto parent0 = layer->get_input_node_shared_ptr(0); const auto parent1 = layer->get_input_node_shared_ptr(1); - if (!is_type(parent0) && !is_type(parent1)) { + if (!ov::is_type(parent0) && !ov::is_type(parent1)) { return false; } @@ -224,10 +224,10 @@ bool MultiplyToGroupConvolutionTransformation::canBeTransformedToGroupConvolutio bool MultiplyToGroupConvolutionTransformation::isDynamicOrScalar(const std::shared_ptr& node) { auto getConstantIndex = [](const std::shared_ptr& node) -> int { - if (is_type(node->get_input_node_shared_ptr(1))) { + if (ov::is_type(node->get_input_node_shared_ptr(1))) { return 1; } - if (is_type(node->get_input_node_shared_ptr(0))) { + if (ov::is_type(node->get_input_node_shared_ptr(0))) { return 0; } return -1; diff --git a/inference-engine/src/low_precision_transformations/src/mvn.cpp b/inference-engine/src/low_precision_transformations/src/mvn.cpp index 7883235e42de44..383688c2f2ff06 100644 --- a/inference-engine/src/low_precision_transformations/src/mvn.cpp +++ b/inference-engine/src/low_precision_transformations/src/mvn.cpp @@ -71,22 +71,22 @@ bool MVNTransformation::canBeTransformed(const TransformationContext& context, s return false; } - std::shared_ptr mvn = as_type_ptr(operation); + std::shared_ptr mvn = ov::as_type_ptr(operation); if (!mvn) { - mvn = as_type_ptr(operation); + mvn = ov::as_type_ptr(operation); if (!mvn) { return false; } } - const auto scalesConst = as_type_ptr(NetworkHelper::getConstantInput(mvn->get_input_node_shared_ptr(0))); + const auto scalesConst = ov::as_type_ptr(NetworkHelper::getConstantInput(mvn->get_input_node_shared_ptr(0))); bool isScalarScales = NetworkHelper::isScalarLike(scalesConst); AxisSet reduction_axes; - if (is_type(mvn)) { - reduction_axes = as_type_ptr(mvn)->get_reduction_axes(); + if (ov::is_type(mvn)) { + reduction_axes = ov::as_type_ptr(mvn)->get_reduction_axes(); } else { - reduction_axes = as_type_ptr(mvn->get_input_node_shared_ptr(1))->get_axis_set_val(); + reduction_axes = ov::as_type_ptr(mvn->get_input_node_shared_ptr(1))->get_axis_set_val(); } if (reduction_axes.count(1) == 0) { @@ -115,22 +115,22 @@ bool MVNTransformation::transform(TransformationContext &context, ngraph::patter return false; } - std::shared_ptr mvn = as_type_ptr(operation); + std::shared_ptr mvn = ov::as_type_ptr(operation); if (!mvn) { - mvn = as_type_ptr(operation); + mvn = ov::as_type_ptr(operation); } bool normalizeVariance; - if (is_type(mvn)) { - normalizeVariance = as_type_ptr(mvn)->get_normalize_variance(); + if (ov::is_type(mvn)) { + normalizeVariance = ov::as_type_ptr(mvn)->get_normalize_variance(); } else { - normalizeVariance = as_type_ptr(mvn)->get_normalize_variance(); + normalizeVariance = ov::as_type_ptr(mvn)->get_normalize_variance(); } FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(mvn); - auto scalesConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); + auto scalesConst = ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); if (scalesConst == nullptr) { - scalesConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(0)); + scalesConst = ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(0)); } auto newScalesConst = scalesConst; @@ -151,7 +151,7 @@ bool MVNTransformation::transform(TransformationContext &context, ngraph::patter } } std::shared_ptr newMVN; - if (is_type(mvn)) { + if (ov::is_type(mvn)) { newMVN = mvn->copy_with_new_inputs({dequantization.data}); } else { newMVN = mvn->copy_with_new_inputs({dequantization.data, mvn->get_input_node_shared_ptr(1)}); diff --git a/inference-engine/src/low_precision_transformations/src/network_helper.cpp b/inference-engine/src/low_precision_transformations/src/network_helper.cpp index 32c6a1ce523421..6b4bda9da5414e 100644 --- a/inference-engine/src/low_precision_transformations/src/network_helper.cpp +++ b/inference-engine/src/low_precision_transformations/src/network_helper.cpp @@ -42,7 +42,7 @@ bool NetworkHelper::notAllChildrensAreFQ(const NodeVector& childrens) { // NOTE: This check was added for models that don't have FQ after AvgPool // They will have transparent precision as it was in old LPT. for (const auto& child : childrens) { - if (!is_type(child)) { + if (!ov::is_type(child)) { return true; } } @@ -69,11 +69,11 @@ std::vector> NetworkHelper::consumers(std::shared_ptr& op) { const auto isNotConstantPathOperation = [](const std::shared_ptr& node) -> bool { - return is_type(node) || - is_type(node) || - is_type(node) || - is_type(node) || - is_type(node); + return ov::is_type(node) || + ov::is_type(node) || + ov::is_type(node) || + ov::is_type(node) || + ov::is_type(node); }; if (isNotConstantPathOperation(op)) { @@ -123,7 +123,7 @@ std::shared_ptr NetworkHelper::foldDequantizationConstant( // constant folding of constant op->constant_fold(outputs, inputs); - const auto result = as_type_ptr(outputs[outIdx].get_node_shared_ptr()); + const auto result = ov::as_type_ptr(outputs[outIdx].get_node_shared_ptr()); if (result == nullptr) { THROW_IE_LPT_EXCEPTION(*result) << "result of constant folding is not constant"; } @@ -191,9 +191,9 @@ size_t NetworkHelper::getInputChannelsCount(std::shared_ptr layer) { } size_t NetworkHelper::getGroupsCount(std::shared_ptr layer) { - if (is_type(layer)) { + if (ov::is_type(layer)) { return 1; - } else if (is_type(layer)) { + } else if (ov::is_type(layer)) { return layer->get_input_partial_shape(1)[0].get_length(); // input weights for opset1::GC is in format GOI..., see the specification } else { THROW_TRANSFORMATION_EXCEPTION << "Invalid layer type of " << layer->get_friendly_name() << "; expected Convolution or GroupConvolution"; @@ -221,13 +221,13 @@ std::shared_ptr NetworkHelper::swapMultiplyAndAdd(std::shared_ptrget_input_node_shared_ptr(0); const auto multiplyParent2 = multiply->get_input_node_shared_ptr(1); - auto multiplyInput = as_type_ptr(multiplyParent1); - auto multiplyConst = as_type_ptr(multiplyParent2); + auto multiplyInput = ov::as_type_ptr(multiplyParent1); + auto multiplyConst = ov::as_type_ptr(multiplyParent2); int multiplyInputBranch = 0; if (multiplyConst == nullptr) { - multiplyInput = as_type_ptr(multiplyParent2); - multiplyConst = as_type_ptr(multiplyParent1); + multiplyInput = ov::as_type_ptr(multiplyParent2); + multiplyConst = ov::as_type_ptr(multiplyParent1); multiplyInputBranch = 1; } @@ -249,8 +249,8 @@ std::shared_ptr NetworkHelper::swapMultiplyAndAdd(std::shared_ptr bValues = as_type_ptr(b)->cast_vector(); - const std::vector aValues = as_type_ptr(a)->cast_vector(); + const std::vector bValues = ov::as_type_ptr(b)->cast_vector(); + const std::vector aValues = ov::as_type_ptr(a)->cast_vector(); const bool aBroadcasted = bValues.size() > aValues.size(); const bool bBroadcasted = bValues.size() < aValues.size(); std::vector bDivAValues(aBroadcasted ? bValues.size() : aValues.size()); @@ -399,19 +399,19 @@ std::shared_ptr NetworkHelper::toScalar(std::shared_ptr NetworkHelper::getConstantInput(std::shared_ptr node) { - std::shared_ptr constant1 = as_type_ptr(node->input_value(0).get_node_shared_ptr()); + std::shared_ptr constant1 = ov::as_type_ptr(node->input_value(0).get_node_shared_ptr()); if (!constant1) { - constant1 = as_type_ptr(node->input_value(1).get_node_shared_ptr()); + constant1 = ov::as_type_ptr(node->input_value(1).get_node_shared_ptr()); } return constant1; } int NetworkHelper::getConstantInputIndex(std::shared_ptr node) { - if (as_type_ptr(node->get_input_node_shared_ptr(1)) != nullptr) { + if (ov::as_type_ptr(node->get_input_node_shared_ptr(1)) != nullptr) { return 1; } - if (as_type_ptr(node->get_input_node_shared_ptr(0)) != nullptr) { + if (ov::as_type_ptr(node->get_input_node_shared_ptr(0)) != nullptr) { return 0; } @@ -449,7 +449,7 @@ std::vector NetworkHelper::updateReshapeValues( } std::shared_ptr NetworkHelper::optimizeMultipliesAfter(std::shared_ptr node) { - std::shared_ptr multiply = as_type_ptr(std::move(node)); + std::shared_ptr multiply = ov::as_type_ptr(std::move(node)); if (!multiply) { THROW_IE_LPT_EXCEPTION(*multiply) << "Unexpected operation type"; } @@ -461,7 +461,7 @@ std::shared_ptr NetworkHelper::optimizeMultipliesAfter } auto nextMultiplyInput = *multiply->output(0).get_target_inputs().begin(); - auto nextMultiply = as_type_ptr>(nextMultiplyInput.get_node()->shared_from_this()); + auto nextMultiply = ov::as_type_ptr>(nextMultiplyInput.get_node()->shared_from_this()); if (nextMultiply) { auto constant2 = getConstantInput(nextMultiply); if (!constant2 || constant2->output(0).get_target_inputs().size() != 1) { @@ -472,7 +472,7 @@ std::shared_ptr NetworkHelper::optimizeMultipliesAfter auto multiplyResult = fold(constant1, constant2); { // optimize constant shape: used in rfcn-resnet101-coco - const auto multiplyResultConstant = as_type_ptr(multiplyResult); + const auto multiplyResultConstant = ov::as_type_ptr(multiplyResult); if ((multiplyResultConstant != nullptr) && NetworkHelper::isScalarLike(multiplyResultConstant)) { multiplyResult = NetworkHelper::toScalar(multiplyResultConstant); } @@ -496,10 +496,10 @@ std::shared_ptr NetworkHelper::optimizeMultipliesAfter } std::shared_ptr NetworkHelper::round(std::shared_ptr node, element::Type target_type) { - const auto constant = as_type_ptr(node); + const auto constant = ov::as_type_ptr(node); assert(constant); - const auto castedConstant = as_type_ptr(fold( + const auto castedConstant = ov::as_type_ptr(fold( fold(constant->output(0), ngraph::op::v5::Round::RoundMode::HALF_AWAY_FROM_ZERO), target_type)); @@ -525,7 +525,7 @@ FakeQuantizeDequantization NetworkHelper::foldDequantization(const std::shared_p if (dequantization.convert != nullptr) { const std::shared_ptr result = foldConvert(dequantization.data, dequantization.convert->get_element_type()); - if (is_type(result)) { + if (ov::is_type(result)) { if (inPlace) { copyInfo(dequantization.convert, result); } @@ -543,7 +543,7 @@ FakeQuantizeDequantization NetworkHelper::foldDequantization(const std::shared_p const auto convertionResult = foldConvert( dequantization.subtractConstant, dequantization.subtractConvert->get_element_type()); - if (is_type(convertionResult)) { + if (ov::is_type(convertionResult)) { replace_node(dequantization.subtractConvert, convertionResult); dequantization = NetworkHelper::getDequantization(node, branchIndex, inPlace); } @@ -552,7 +552,7 @@ FakeQuantizeDequantization NetworkHelper::foldDequantization(const std::shared_p const std::shared_ptr result = fold( dequantization.subtract->get_input_node_shared_ptr(0), dequantization.subtract->get_input_node_shared_ptr(1)); - if (is_type(result)) { + if (ov::is_type(result)) { if (inPlace) { copyInfo(dequantization.subtract, result); } @@ -571,7 +571,7 @@ FakeQuantizeDequantization NetworkHelper::foldDequantization(const std::shared_p std::shared_ptr result = fold( dequantization.multiply->get_input_node_shared_ptr(0), dequantization.multiply->get_input_node_shared_ptr(1)); - if (!is_type(result)) { + if (!ov::is_type(result)) { return dequantization; } if (dequantization.multiply->get_output_element_type(0) != result->get_element_type()) { @@ -649,7 +649,7 @@ std::shared_ptr NetworkHelper::fuseConvert(const std::shar } Node* node = targetInputs.begin()->get_node(); - if (!is_type(node) || + if (!ov::is_type(node) || // TODO: LPT: avoid precision hardcode: to separate method: isSupportedPrecision ((node->get_output_element_type(0) != element::u8) && (node->get_output_element_type(0) != element::i8))) { return fakeQuantize; @@ -715,15 +715,15 @@ std::shared_ptr NetworkHelper::foldFakeQuantize( const bool roundValuesArg, const bool roundValuesWasSet, const int outChannelsShapeIndex) { - if (is_type(fq->get_input_node_shared_ptr(0)) && - is_type(fq->get_input_node_shared_ptr(1)) && - is_type(fq->get_input_node_shared_ptr(2)) && - is_type(fq->get_input_node_shared_ptr(3)) && - is_type(fq->get_input_node_shared_ptr(4)) && - op::util::constantIsEqualTo(as_type_ptr(fq->get_input_node_shared_ptr(1)), 0.f) && - op::util::constantIsEqualTo(as_type_ptr(fq->get_input_node_shared_ptr(2)), 254.f) && - op::util::constantIsEqualTo(as_type_ptr(fq->get_input_node_shared_ptr(3)), -127.f) && - op::util::constantIsEqualTo(as_type_ptr(fq->get_input_node_shared_ptr(4)), 127.f)) { + if (ov::is_type(fq->get_input_node_shared_ptr(0)) && + ov::is_type(fq->get_input_node_shared_ptr(1)) && + ov::is_type(fq->get_input_node_shared_ptr(2)) && + ov::is_type(fq->get_input_node_shared_ptr(3)) && + ov::is_type(fq->get_input_node_shared_ptr(4)) && + op::util::constantIsEqualTo(ov::as_type_ptr(fq->get_input_node_shared_ptr(1)), 0.f) && + op::util::constantIsEqualTo(ov::as_type_ptr(fq->get_input_node_shared_ptr(2)), 254.f) && + op::util::constantIsEqualTo(ov::as_type_ptr(fq->get_input_node_shared_ptr(3)), -127.f) && + op::util::constantIsEqualTo(ov::as_type_ptr(fq->get_input_node_shared_ptr(4)), 127.f)) { const auto type1 = fq->input_value(0).get_element_type(); const auto type2 = fq->input_value(3).get_element_type(); if (type1.is_real() && type2.is_real()) { @@ -744,7 +744,7 @@ std::shared_ptr NetworkHelper::foldFakeQuantize( foldConvert(fq->input_value(3), element::f32)); } - auto constant = as_type_ptr(fq->get_input_node_shared_ptr(0)); + auto constant = ov::as_type_ptr(fq->get_input_node_shared_ptr(0)); if (constant) { const bool roundValues = roundValuesWasSet ? roundValuesArg : fq->get_output_element_type(0).is_integral(); @@ -774,10 +774,10 @@ std::shared_ptr NetworkHelper::foldFakeQuantize( const size_t H = constShape.size() > 2lu ? constShape.size() == 3lu ? constShape[2] : constShape[constShape.size() - 2] : 1; const size_t W = constShape.size() > 3lu ? constShape[constShape.size() - 1] : 1; - const auto inputLowValues = as_type_ptr(fq->get_input_node_shared_ptr(1))->cast_vector(); - const auto inputHighValues = as_type_ptr(fq->get_input_node_shared_ptr(2))->cast_vector(); - const auto outputLowValues = as_type_ptr(fq->get_input_node_shared_ptr(3))->cast_vector(); - const auto outputHighValues = as_type_ptr(fq->get_input_node_shared_ptr(4))->cast_vector(); + const auto inputLowValues = ov::as_type_ptr(fq->get_input_node_shared_ptr(1))->cast_vector(); + const auto inputHighValues = ov::as_type_ptr(fq->get_input_node_shared_ptr(2))->cast_vector(); + const auto outputLowValues = ov::as_type_ptr(fq->get_input_node_shared_ptr(3))->cast_vector(); + const auto outputHighValues = ov::as_type_ptr(fq->get_input_node_shared_ptr(4))->cast_vector(); const size_t inputLowSize = inputLowValues.size(); const size_t inputHighSize = inputHighValues.size(); @@ -848,7 +848,7 @@ std::shared_ptr NetworkHelper::composeFakeQuantize(const s if (targetInputs.size() != 1ul) { return nullptr; } - if (is_type(targetInputs.begin()->get_node())) { + if (ov::is_type(targetInputs.begin()->get_node())) { parent = targetInputs.begin()->get_node()->shared_from_this(); } @@ -856,7 +856,7 @@ std::shared_ptr NetworkHelper::composeFakeQuantize(const s if (targetInputs.size() != 1ul) { return nullptr; } - if (is_type(targetInputs.begin()->get_node())) { + if (ov::is_type(targetInputs.begin()->get_node())) { parent = targetInputs.begin()->get_node()->shared_from_this(); } @@ -864,7 +864,7 @@ std::shared_ptr NetworkHelper::composeFakeQuantize(const s if (targetInputs.size() != 1ul) { return nullptr; } - if (is_type(targetInputs.begin()->get_node())) { + if (ov::is_type(targetInputs.begin()->get_node())) { parent = targetInputs.begin()->get_node()->shared_from_this(); } @@ -970,8 +970,8 @@ std::tuple, std::shared_ptr> NetworkHelper::decompos const auto outputLow = fq->input_value(3); const auto outputHigh = fq->input_value(4); - std::vector outputLowValues = as_type_ptr(outputLow.get_node_shared_ptr())->cast_vector(); - std::vector outputHighValues = as_type_ptr(outputHigh.get_node_shared_ptr())->cast_vector(); + std::vector outputLowValues = ov::as_type_ptr(outputLow.get_node_shared_ptr())->cast_vector(); + std::vector outputHighValues = ov::as_type_ptr(outputHigh.get_node_shared_ptr())->cast_vector(); size_t outputSize = outputLowValues.size(); std::vector minValues(outputSize, min); std::vector maxValues(outputSize, max); @@ -1035,7 +1035,7 @@ std::tuple, std::shared_ptr> NetworkHelper::decompos } } - if ((shift != nullptr) && isZero(as_type_ptr(shift))) { + if ((shift != nullptr) && isZero(ov::as_type_ptr(shift))) { shift = nullptr; } @@ -1057,12 +1057,12 @@ std::tuple, std::shared_ptr> NetworkHelper::decompos std::shared_ptr convert2; if (updatePrecision) { std::shared_ptr convert; - std::shared_ptr newFqConstant = as_type_ptr(newFQ); + std::shared_ptr newFqConstant = ov::as_type_ptr(newFQ); - if (is_type(newFQ)) { + if (ov::is_type(newFQ)) { convert = foldConvert(newFQ, precision); - } else if (is_type(newFQ)) { - newFQ = setOutDataPrecision(as_type_ptr(newFQ), precision); + } else if (ov::is_type(newFQ)) { + newFQ = setOutDataPrecision(ov::as_type_ptr(newFQ), precision); convert = newFQ; } else { THROW_IE_LPT_EXCEPTION(*newFQ) << "unexpected operation type"; @@ -1191,20 +1191,20 @@ FakeQuantizeDequantization NetworkHelper::createDequantizationFromFakeQuantize( // TODO: threshold values have to used here to avoid shifts - const std::shared_ptr scale = as_type_ptr(foldConvert(fold( + const std::shared_ptr scale = ov::as_type_ptr(foldConvert(fold( fold(outputHigh, outputLow), fold(newMax, newMin)), deqPrecision)); assert(scale != nullptr); std::shared_ptr shift = hasZeroPoint ? - as_type_ptr(foldConvert(fold( + ov::as_type_ptr(foldConvert(fold( fold(fold(newMin, outputHigh), fold(newMax, outputLow)), fold(outputHigh, outputLow)), deqPrecision)) : nullptr; assert((!hasZeroPoint) || (hasZeroPoint && shift != nullptr)); if (shift != nullptr) { - std::shared_ptr shiftConst = as_type_ptr(shift); + std::shared_ptr shiftConst = ov::as_type_ptr(shift); if (isScalarLike(shiftConst)) { auto scalar = toScalar(shiftConst); if (op::util::constantIsEqualTo(scalar, 0)) { @@ -1241,7 +1241,7 @@ FakeQuantizeDequantization NetworkHelper::createDequantizationFromFakeQuantize( } bool NetworkHelper::areQuantizeAndDequantizeSupportedForSubtract(const std::shared_ptr& node) { - if (!is_type(node)) { + if (!ov::is_type(node)) { return false; } @@ -1255,7 +1255,7 @@ bool NetworkHelper::areQuantizeAndDequantizeSupportedForSubtract(const std::shar } bool NetworkHelper::areQuantizeAndDequantizeSupportedForMultiply(const std::shared_ptr& node) { - if (!is_type(node)) { + if (!ov::is_type(node)) { return false; } @@ -1266,14 +1266,14 @@ bool NetworkHelper::areQuantizeAndDequantizeSupportedForMultiply(const std::shar } const auto dataNode = dequantization.data.get_node(); - if (is_type(dataNode)) { - const auto quantize = as_type_ptr(dataNode->get_input_node_shared_ptr(0)); + if (ov::is_type(dataNode)) { + const auto quantize = ov::as_type_ptr(dataNode->get_input_node_shared_ptr(0)); if (quantize == nullptr) { return false; } return NetworkHelper::isQuantizeSupported(quantize); - } else if (is_type(dataNode)) { + } else if (ov::is_type(dataNode)) { return true; } @@ -1286,15 +1286,15 @@ bool NetworkHelper::isQuantizeSupported(const std::shared_ptr& node, const size_t parentIndex, const bool inPlace) { auto getDataIndex = [](const std::shared_ptr& node) { - if (is_type(node->get_input_node_ptr(1))) { + if (ov::is_type(node->get_input_node_ptr(1))) { return 0ul; } - if (is_type(node->get_input_node_ptr(1)) && is_type(node->get_input_node_ptr(1)->get_input_node_ptr(0))) { + if (ov::is_type(node->get_input_node_ptr(1)) && ov::is_type(node->get_input_node_ptr(1)->get_input_node_ptr(0))) { return 0ul; } - if (is_type(node->get_input_node_ptr(0)) && is_type(node->get_input_node_ptr(0)->get_input_node_ptr(0))) { + if (ov::is_type(node->get_input_node_ptr(0)) && ov::is_type(node->get_input_node_ptr(0)->get_input_node_ptr(0))) { return 1ul; } @@ -1303,7 +1303,7 @@ FakeQuantizeDequantization NetworkHelper::getDequantization(const std::shared_pt Output dataNode = inPlace ? std::const_pointer_cast(node)->output(0) : node->input_value(parentIndex); - const std::shared_ptr multiply = as_type_ptr(dataNode.get_node_shared_ptr()); + const std::shared_ptr multiply = ov::as_type_ptr(dataNode.get_node_shared_ptr()); std::shared_ptr multiplyConstant; if (multiply != nullptr) { if (!FakeQuantizeDequantization::checkShape(multiply)) { @@ -1317,7 +1317,7 @@ FakeQuantizeDequantization NetworkHelper::getDequantization(const std::shared_pt dataNode = multiply->get_input_source_output(getDataIndex(multiply)); } - const std::shared_ptr subtract = as_type_ptr(dataNode.get_node_shared_ptr()); + const std::shared_ptr subtract = ov::as_type_ptr(dataNode.get_node_shared_ptr()); std::shared_ptr subtractConvert; std::shared_ptr subtractConstant; if (subtract != nullptr) { @@ -1332,7 +1332,7 @@ FakeQuantizeDequantization NetworkHelper::getDequantization(const std::shared_pt dataNode = subtract->get_input_source_output(getDataIndex(subtract)); } - const std::shared_ptr convert = as_type_ptr(dataNode.get_node_shared_ptr()); + const std::shared_ptr convert = ov::as_type_ptr(dataNode.get_node_shared_ptr()); if (convert != nullptr) { if ((convert->input(0).get_element_type() != element::i8) && (convert->input(0).get_element_type() != element::u8) && (convert->output(0).get_element_type() != element::f32)) { @@ -1353,7 +1353,7 @@ FakeQuantizeDequantization NetworkHelper::getDequantizationBelow(const std::shar std::shared_ptr lastNode = targetInputs.begin()->get_node()->shared_from_this(); - const std::shared_ptr convert = as_type_ptr(lastNode); + const std::shared_ptr convert = ov::as_type_ptr(lastNode); if (convertIsMandatory && (convert == nullptr)) { return FakeQuantizeDequantization(); } @@ -1371,7 +1371,7 @@ FakeQuantizeDequantization NetworkHelper::getDequantizationBelow(const std::shar lastNode = inputs.begin()->get_node()->shared_from_this(); } - const std::shared_ptr subtract = as_type_ptr(lastNode); + const std::shared_ptr subtract = ov::as_type_ptr(lastNode); std::shared_ptr subtractConvert; std::shared_ptr subtractConstant; if (subtract != nullptr) { @@ -1387,7 +1387,7 @@ FakeQuantizeDequantization NetworkHelper::getDequantizationBelow(const std::shar lastNode = inputs.begin()->get_node()->shared_from_this(); } - const std::shared_ptr multiply = as_type_ptr(lastNode); + const std::shared_ptr multiply = ov::as_type_ptr(lastNode); std::shared_ptr multiplyConstant; if (multiply != nullptr) { FakeQuantizeDequantization::fillDequantizationParams(multiply, multiplyConstant); @@ -1403,18 +1403,18 @@ FakeQuantizeDequantization NetworkHelper::normalizeDequantization(FakeQuantizeDe if (dequantization.empty()) { return dequantization; } - if (dequantization.multiply != nullptr && as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(0))) { + if (dequantization.multiply != nullptr && ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(0))) { std::shared_ptr leftParent = dequantization.multiply->get_input_node_shared_ptr(0); std::shared_ptr rightParent = dequantization.multiply->get_input_node_shared_ptr(1); - std::shared_ptr normalized_multiply = as_type_ptr( + std::shared_ptr normalized_multiply = ov::as_type_ptr( dequantization.multiply->clone_with_new_inputs({rightParent, leftParent})); replace_node(dequantization.multiply, normalized_multiply); dequantization.multiply = normalized_multiply; } - if (dequantization.subtract != nullptr && as_type_ptr(dequantization.subtract->get_input_node_shared_ptr(0))) { + if (dequantization.subtract != nullptr && ov::as_type_ptr(dequantization.subtract->get_input_node_shared_ptr(0))) { std::shared_ptr leftParent = dequantization.subtract->get_input_node_shared_ptr(0); std::shared_ptr rightParent = dequantization.subtract->get_input_node_shared_ptr(1); - std::shared_ptr normalized_subtract = as_type_ptr( + std::shared_ptr normalized_subtract = ov::as_type_ptr( dequantization.subtract->clone_with_new_inputs({rightParent, leftParent})); replace_node(dequantization.subtract, normalized_subtract); dequantization.subtract = normalized_subtract; @@ -1424,7 +1424,7 @@ FakeQuantizeDequantization NetworkHelper::normalizeDequantization(FakeQuantizeDe std::shared_ptr NetworkHelper::normalizeDequantizationShape(const std::shared_ptr& eltwise) { const size_t constantIdx = getConstantInputIndex(eltwise); - const auto constant = as_type_ptr(eltwise->get_input_node_shared_ptr(constantIdx)); + const auto constant = ov::as_type_ptr(eltwise->get_input_node_shared_ptr(constantIdx)); const auto getConstWithNormalizeShape = []( const std::shared_ptr& eltwise, @@ -1443,7 +1443,7 @@ std::shared_ptr NetworkHelper::normalizeDequantizationShape(co constant, op::Constant::create(element::i32, Shape{ unsqueezeConstantShape.size() }, unsqueezeConstantShape)); - return as_type_ptr(newConstant); + return ov::as_type_ptr(newConstant); } else { return constant; } @@ -1473,7 +1473,7 @@ FakeQuantizeDequantizationValues NetworkHelper::createEmptyValues(const FakeQuan } bool NetworkHelper::isZeroConst(const std::shared_ptr& node) { - std::shared_ptr constant = as_type_ptr(node); + std::shared_ptr constant = ov::as_type_ptr(node); if (constant == nullptr) return false; @@ -1492,13 +1492,13 @@ bool NetworkHelper::isZeroConst(const std::shared_ptr& node) { std::shared_ptr NetworkHelper::optimizeSubtract(std::shared_ptr subtract) { auto convertOnSubtract = subtract->input_value(0).get_node_shared_ptr(); - if (as_type_ptr(convertOnSubtract) == nullptr) { + if (ov::as_type_ptr(convertOnSubtract) == nullptr) { return subtract; } // TODO: replace assert to condition and omit conversion part if there is no convert // TODO: also check convertInputType to understand if we really want to propagate type - assert(as_type_ptr(convertOnSubtract)); + assert(ov::as_type_ptr(convertOnSubtract)); const element::Type convertInputType = convertOnSubtract->get_input_element_type(0); const element::Type convertOutputType = convertOnSubtract->get_output_element_type(0); @@ -1508,7 +1508,7 @@ std::shared_ptr NetworkHelper::optimizeSubtract(std::shared_ptrinput_value(0); const auto subtractParent = subtract->get_input_node_shared_ptr(1); - if (is_type(subtractParent)) { + if (ov::is_type(subtractParent)) { std::shared_ptr replacement; auto shift = subtract->input_value(1).get_node_shared_ptr(); @@ -1533,7 +1533,7 @@ std::shared_ptr NetworkHelper::optimizeSubtract(std::shared_ptr(subtractParent) && is_type(subtractParent->get_input_node_shared_ptr(0))) { + } else if (ov::is_type(subtractParent) && ov::is_type(subtractParent->get_input_node_shared_ptr(0))) { auto replacement = std::make_shared>(data, subtractParent->get_input_node_shared_ptr(0)); NetworkHelper::copyInfo(subtract, replacement); NetworkHelper::setOutDataPrecisionForTypeRelaxed(replacement, convertOutputType); @@ -1652,7 +1652,7 @@ bool NetworkHelper::checkConstantValuePrecision(const element::Type expectedPrec return true; } - std::shared_ptr constantOp = as_type_ptr(constant); + std::shared_ptr constantOp = ov::as_type_ptr(constant); if (constantOp == nullptr) { return false; } @@ -1687,7 +1687,7 @@ size_t NetworkHelper::getParentOutputIndex(const std::shared_ptr& } std::shared_ptr NetworkHelper::toScalarIfPossible(std::shared_ptr node) { - std::shared_ptr constant = as_type_ptr(node); + std::shared_ptr constant = ov::as_type_ptr(node); if (constant == nullptr) { return node; } @@ -1700,7 +1700,7 @@ std::shared_ptr NetworkHelper::toScalarIfPossible(std::shared_ptr no } std::shared_ptr foldConvert(const Output& node, const element::Type targetPrecision) { - if (is_type(node.get_node_shared_ptr()) && (node.get_element_type() == targetPrecision)) { + if (ov::is_type(node.get_node_shared_ptr()) && (node.get_element_type() == targetPrecision)) { return node.get_node_shared_ptr(); } @@ -1713,9 +1713,9 @@ bool NetworkHelper::checkZeroPoint(const std::shared_ptr& node, const Data } float min, max; - if (is_type(node)) { + if (ov::is_type(node)) { const auto parent = node->get_input_node_shared_ptr(0); - const auto intNode = is_type(parent) ? parent : node; + const auto intNode = ov::is_type(parent) ? parent : node; const auto type = intNode->get_input_element_type(0); if (type == element::u8 || type == element::i8) { min = DataPrecision::getMinValue(type, 256) - 0.5f; @@ -1724,12 +1724,12 @@ bool NetworkHelper::checkZeroPoint(const std::shared_ptr& node, const Data return type == element::f32 || type == element::f16; } auto subtract1input = node->get_input_node_shared_ptr(1); - if (is_type(subtract1input)) { + if (ov::is_type(subtract1input)) { return true; } - auto subtractConst = as_type_ptr(subtract1input); + auto subtractConst = ov::as_type_ptr(subtract1input); if (!subtractConst) { - subtractConst = as_type_ptr(node->get_input_node_shared_ptr(1)->get_input_node_shared_ptr(0)); + subtractConst = ov::as_type_ptr(node->get_input_node_shared_ptr(1)->get_input_node_shared_ptr(0)); if (subtractConst == nullptr) { return false; } @@ -1739,13 +1739,13 @@ bool NetworkHelper::checkZeroPoint(const std::shared_ptr& node, const Data return (val < min) || (val > max); })) { return false; } - } else if (is_type(node)) { + } else if (ov::is_type(node)) { if (!dataPrecision.hasZeroPoint) { return true; } min = dataPrecision.min - 0.5f; max = dataPrecision.max + 0.5f; - const auto quantizationDetails = QuantizationDetails::getDetails(as_type_ptr(node)); + const auto quantizationDetails = QuantizationDetails::getDetails(ov::as_type_ptr(node)); for (size_t i = 0; i < quantizationDetails.outputLowValues.size(); ++i) { float shift; if (quantizationDetails.outputHighValues[i] != quantizationDetails.outputLowValues[i]) { diff --git a/inference-engine/src/low_precision_transformations/src/normalize_l2.cpp b/inference-engine/src/low_precision_transformations/src/normalize_l2.cpp index 1d269094762c37..d7ca932335b836 100644 --- a/inference-engine/src/low_precision_transformations/src/normalize_l2.cpp +++ b/inference-engine/src/low_precision_transformations/src/normalize_l2.cpp @@ -64,16 +64,16 @@ bool NormalizeL2Transformation::canBeTransformed(const TransformationContext& co } const std::shared_ptr multiply = operation->get_input_node_shared_ptr(0); - auto scalesConst = as_type_ptr(multiply->get_input_node_shared_ptr(1)); + auto scalesConst = ov::as_type_ptr(multiply->get_input_node_shared_ptr(1)); if (scalesConst == nullptr) { - scalesConst = as_type_ptr(multiply->get_input_node_shared_ptr(0)); + scalesConst = ov::as_type_ptr(multiply->get_input_node_shared_ptr(0)); } if (scalesConst == nullptr) { return false; } // TODO: Expand transformation for all cases of axes values - const auto axes = as_type_ptr(operation->get_input_node_shared_ptr(1)); + const auto axes = ov::as_type_ptr(operation->get_input_node_shared_ptr(1)); const std::vector axesAcrossSpatial = { 1 }; const std::vector axesByChannels = { 1, 2, 3 }; @@ -104,13 +104,13 @@ bool NormalizeL2Transformation::transform(TransformationContext &context, ngraph return false; } - auto normalize = as_type_ptr(NetworkHelper::separateInStandaloneBranch(operation)); + auto normalize = ov::as_type_ptr(NetworkHelper::separateInStandaloneBranch(operation)); - const auto axes = as_type_ptr(normalize->get_input_node_shared_ptr(1)); + const auto axes = ov::as_type_ptr(normalize->get_input_node_shared_ptr(1)); FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(normalize); - auto scalesConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); + auto scalesConst = ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); if (scalesConst == nullptr) { - scalesConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(0)); + scalesConst = ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(0)); } std::shared_ptr newScalesConst; diff --git a/inference-engine/src/low_precision_transformations/src/pad.cpp b/inference-engine/src/low_precision_transformations/src/pad.cpp index 88141e8b5fcabe..696c168399569f 100644 --- a/inference-engine/src/low_precision_transformations/src/pad.cpp +++ b/inference-engine/src/low_precision_transformations/src/pad.cpp @@ -40,8 +40,8 @@ bool PadTransformation::transform(TransformationContext& context, ngraph::patter return false; } - const auto pad = as_type_ptr(NetworkHelper::separateInStandaloneBranch(m.get_match_root())); - const auto padConstant = as_type_ptr(pad->get_input_node_shared_ptr(3)); + const auto pad = ov::as_type_ptr(NetworkHelper::separateInStandaloneBranch(m.get_match_root())); + const auto padConstant = ov::as_type_ptr(pad->get_input_node_shared_ptr(3)); const auto padConstantValue = padConstant->cast_vector()[0]; const auto padsBegin = pad->get_pads_begin(); @@ -67,7 +67,7 @@ bool PadTransformation::transform(TransformationContext& context, ngraph::patter bcastedShape[padIdx] = inputPShape[padIdx].get_length(); const auto bCastConst = opset1::Constant::create(element::i32, Shape{bcastedShape.size()}, bcastedShape); - return as_type_ptr(fold(constant, bCastConst)); + return ov::as_type_ptr(fold(constant, bCastConst)); }; if (dequantization.subtract && shape_size(dequantization.subtractConstant->get_shape()) == 1ul) { @@ -114,7 +114,7 @@ bool PadTransformation::transform(TransformationContext& context, ngraph::patter const auto endConst = opset1::Constant::create(element::u32, { padsForConstantEnd.size() }, padsForConstantEnd); const auto padValueConstant = opset1::Constant::create(constant->get_element_type(), Shape{}, { padVal }); const auto foldedConstant = fold(constant, beginConst, endConst, padValueConstant, padMode); - return as_type_ptr(foldedConstant); + return ov::as_type_ptr(foldedConstant); } else { return constant; } @@ -157,7 +157,7 @@ bool PadTransformation::canBeTransformed(const TransformationContext& context, s return false; } - const auto pad = as_type_ptr(op); + const auto pad = ov::as_type_ptr(op); if (!pad) { return false; } @@ -231,7 +231,7 @@ bool PadTransformation::canBeTransformed(const TransformationContext& context, s return false; } - const auto constant = as_type_ptr(pad->get_input_node_shared_ptr(3)); + const auto constant = ov::as_type_ptr(pad->get_input_node_shared_ptr(3)); const auto constantValue = constant->cast_vector()[0]; if (constantValue != 0.f && !padAndDqByTheSameDimension(dequantization.multiplyConstant)) { return false; diff --git a/inference-engine/src/low_precision_transformations/src/pull_reshape_through_dequantization.cpp b/inference-engine/src/low_precision_transformations/src/pull_reshape_through_dequantization.cpp index 4c4679c80469e5..68617278844f58 100644 --- a/inference-engine/src/low_precision_transformations/src/pull_reshape_through_dequantization.cpp +++ b/inference-engine/src/low_precision_transformations/src/pull_reshape_through_dequantization.cpp @@ -23,13 +23,13 @@ std::shared_ptr moveThroughElementwise(const std::shared_ptr& reshap const auto reshapeValues = reshape->get_input_node_shared_ptr(1); NGRAPH_CHECK(reshapeValues != nullptr, "Reshape constant was not found"); - auto elementwiseValuesConvert = as_type_ptr(elementwise->get_input_node_shared_ptr(1ul)); + auto elementwiseValuesConvert = ov::as_type_ptr(elementwise->get_input_node_shared_ptr(1ul)); auto elementwiseValues = elementwiseValuesConvert == nullptr ? elementwise->get_input_node_shared_ptr(1ul) : elementwiseValuesConvert->get_input_node_shared_ptr(0ul); - assert(is_type(elementwiseValues)); + assert(ov::is_type(elementwiseValues)); - const std::shared_ptr newReshape = as_type_ptr(reshape->clone_with_new_inputs({ + const std::shared_ptr newReshape = ov::as_type_ptr(reshape->clone_with_new_inputs({ elementwise->get_input_node_shared_ptr(0ul), reshapeValues })); @@ -39,7 +39,7 @@ std::shared_ptr moveThroughElementwise(const std::shared_ptr& reshap if (!elementwiseValuesShape.empty() && (elementwiseValuesShape.size() != 1ul)) { // update shape constant value to avoid eltwise constan value broadcasting const Shape elementwiseShape = elementwise->output(0).get_shape(); - const std::vector reshapeValuesVector = as_type_ptr(reshapeValues)->cast_vector(); + const std::vector reshapeValuesVector = ov::as_type_ptr(reshapeValues)->cast_vector(); const std::vector newReshapeValuesVector = ngraph::pass::low_precision::NetworkHelper::updateReshapeValues( elementwiseValuesShape, @@ -54,8 +54,8 @@ std::shared_ptr moveThroughElementwise(const std::shared_ptr& reshap newElementwiseValues = ngraph::pass::low_precision::fold_reshape( elementwiseValues->output(0), newReshapeValues->output(0), - as_type_ptr(reshape)->get_special_zero()); - assert(is_type(newElementwiseValues)); + ov::as_type_ptr(reshape)->get_special_zero()); + assert(ov::is_type(newElementwiseValues)); } else { newElementwiseValues = elementwiseValues; } @@ -113,18 +113,18 @@ ngraph::pass::low_precision::PullReshapeThroughDequantization::PullReshapeThroug auto reshape = opsMap.find(reshapeWrapper)->second.get_node()->shared_from_this(); auto child = reshape->get_output_target_inputs(0).begin()->get_node(); - if (is_type(child)) { + if (ov::is_type(child)) { return false; } while (reshape != nullptr) { const auto parent = reshape->get_input_node_shared_ptr(0); - if (is_type(parent) || is_type(parent)) { + if (ov::is_type(parent) || ov::is_type(parent)) { reshape = pull_reshape_through_dequantization::moveThroughElementwise(reshape, parent); - } else if (is_type(parent)) { + } else if (ov::is_type(parent)) { reshape = pull_reshape_through_dequantization::moveThroughConvert(reshape, parent); - } else if (is_type(parent)) { - pull_reshape_through_dequantization::fuseConstant(reshape, as_type_ptr(parent)); + } else if (ov::is_type(parent)) { + pull_reshape_through_dequantization::fuseConstant(reshape, ov::as_type_ptr(parent)); reshape = nullptr; } else { THROW_IE_LPT_EXCEPTION(*parent) << "unexepcted operation type"; diff --git a/inference-engine/src/low_precision_transformations/src/pull_transpose_through_dequantization.cpp b/inference-engine/src/low_precision_transformations/src/pull_transpose_through_dequantization.cpp index a8dd26d26a1412..3ee344884dcf62 100644 --- a/inference-engine/src/low_precision_transformations/src/pull_transpose_through_dequantization.cpp +++ b/inference-engine/src/low_precision_transformations/src/pull_transpose_through_dequantization.cpp @@ -24,11 +24,11 @@ std::shared_ptr moveThroughElementwise(const std::shared_ptr& transp const auto transposeValues = transpose->get_input_node_shared_ptr(1); NGRAPH_CHECK(transposeValues != nullptr, "transpose constant was not found"); - auto elementwiseValuesConvert = as_type_ptr(elementwise->get_input_node_shared_ptr(1ul)); + auto elementwiseValuesConvert = ov::as_type_ptr(elementwise->get_input_node_shared_ptr(1ul)); auto elementwiseValues = elementwiseValuesConvert == nullptr ? elementwise->get_input_node_shared_ptr(1ul) : elementwiseValuesConvert->get_input_node_shared_ptr(0ul); - assert(is_type(elementwiseValues)); + assert(ov::is_type(elementwiseValues)); const auto transposeValuesShape = transposeValues->output(0).get_shape(); const auto elementwiseValuesShape = elementwiseValues->output(0).get_shape(); @@ -43,17 +43,17 @@ std::shared_ptr moveThroughElementwise(const std::shared_ptr& transp element::i64, Shape{ shape_size(transposeValuesShape) }, std::vector(shape_size(transposeValuesShape), 1ul))); - assert(is_type(elementwiseValues)); + assert(ov::is_type(elementwiseValues)); } - const std::shared_ptr newTranspose = as_type_ptr(transpose->clone_with_new_inputs({ + const std::shared_ptr newTranspose = ov::as_type_ptr(transpose->clone_with_new_inputs({ elementwise->get_input_node_shared_ptr(0ul), transposeValues })); const auto newElementwiseValues = ngraph::pass::low_precision::fold( elementwiseValues->output(0), transposeValues->output(0)); - assert(is_type(newElementwiseValues)); + assert(ov::is_type(newElementwiseValues)); const auto newElementwise = elementwise->clone_with_new_inputs({ newTranspose, @@ -112,12 +112,12 @@ ngraph::pass::low_precision::PullTransposeThroughDequantization::PullTransposeTh while (transpose != nullptr) { const auto parent = transpose->get_input_node_shared_ptr(0); - if (is_type(parent) || is_type(parent)) { + if (ov::is_type(parent) || ov::is_type(parent)) { transpose = pull_transpose_through_dequantization::moveThroughElementwise(transpose, parent); - } else if (is_type(parent)) { + } else if (ov::is_type(parent)) { transpose = pull_transpose_through_dequantization::moveThroughConvert(transpose, parent); - } else if (is_type(parent)) { - pull_transpose_through_dequantization::fuseConstant(transpose, as_type_ptr(parent)); + } else if (ov::is_type(parent)) { + pull_transpose_through_dequantization::fuseConstant(transpose, ov::as_type_ptr(parent)); transpose = nullptr; } else { THROW_IE_LPT_EXCEPTION(*parent) << "unexepcted operation type"; diff --git a/inference-engine/src/low_precision_transformations/src/quantization_details.cpp b/inference-engine/src/low_precision_transformations/src/quantization_details.cpp index ca97aae0dc3e2c..79486394a2f10d 100644 --- a/inference-engine/src/low_precision_transformations/src/quantization_details.cpp +++ b/inference-engine/src/low_precision_transformations/src/quantization_details.cpp @@ -49,21 +49,21 @@ QuantizationDetails::QuantizationDetails(const size_t levels, const std::vector< outputHighValues(outputHighValues) {} bool QuantizationDetails::outputLayoutIsSupported(std::shared_ptr quantize) { - return is_type(quantize->get_input_node_ptr(1)) && - is_type(quantize->get_input_node_ptr(2)) && - is_type(quantize->get_input_node_ptr(3)) && - is_type(quantize->get_input_node_ptr(4)); + return ov::is_type(quantize->get_input_node_ptr(1)) && + ov::is_type(quantize->get_input_node_ptr(2)) && + ov::is_type(quantize->get_input_node_ptr(3)) && + ov::is_type(quantize->get_input_node_ptr(4)); } void QuantizationDetails::getInputIntervals( std::shared_ptr quantize, std::vector& inputLowValues, std::vector& inputHighValues) { - std::shared_ptr inputLowLayer = as_type_ptr(quantize->get_input_node_shared_ptr(1)); + std::shared_ptr inputLowLayer = ov::as_type_ptr(quantize->get_input_node_shared_ptr(1)); const std::vector& inputLowBlobValues = getBlobValue(inputLowLayer); inputLowValues.insert(inputLowValues.end(), inputLowBlobValues.begin(), inputLowBlobValues.end()); - std::shared_ptr inputHighLayer = as_type_ptr(quantize->get_input_node_shared_ptr(2)); + std::shared_ptr inputHighLayer = ov::as_type_ptr(quantize->get_input_node_shared_ptr(2)); const std::vector inputHighBlobValues = getBlobValue(inputHighLayer); inputHighValues.insert(inputHighValues.end(), inputHighBlobValues.begin(), inputHighBlobValues.end()); @@ -77,11 +77,11 @@ void QuantizationDetails::getOutputIntervals( std::shared_ptr quantize, std::vector& outputLowValues, std::vector& outputHighValues) { - std::shared_ptr outputLowLayer = as_type_ptr(quantize->get_input_node_shared_ptr(3)); + std::shared_ptr outputLowLayer = ov::as_type_ptr(quantize->get_input_node_shared_ptr(3)); const std::vector& outputLowBlobValues = getBlobValue(outputLowLayer); outputLowValues.insert(outputLowValues.end(), outputLowBlobValues.begin(), outputLowBlobValues.end()); - std::shared_ptr outputHighLayer = as_type_ptr(quantize->get_input_node_shared_ptr(4)); + std::shared_ptr outputHighLayer = ov::as_type_ptr(quantize->get_input_node_shared_ptr(4)); const std::vector outputHighBlobValues = getBlobValue(outputHighLayer); outputHighValues.insert(outputHighValues.end(), outputHighBlobValues.begin(), outputHighBlobValues.end()); @@ -91,11 +91,11 @@ void QuantizationDetails::getOutputIntervals( } QuantizationDetails QuantizationDetails::getDetails(std::shared_ptr quantize) { - const std::vector inputLowValues = as_type_ptr(quantize->get_input_node_shared_ptr(1))->cast_vector(); - const std::vector inputHighValues = as_type_ptr(quantize->get_input_node_shared_ptr(2))->cast_vector(); + const std::vector inputLowValues = ov::as_type_ptr(quantize->get_input_node_shared_ptr(1))->cast_vector(); + const std::vector inputHighValues = ov::as_type_ptr(quantize->get_input_node_shared_ptr(2))->cast_vector(); - const std::vector outputLowValues = as_type_ptr(quantize->get_input_node_shared_ptr(3))->cast_vector(); - const std::vector outputHighValues = as_type_ptr(quantize->get_input_node_shared_ptr(4))->cast_vector(); + const std::vector outputLowValues = ov::as_type_ptr(quantize->get_input_node_shared_ptr(3))->cast_vector(); + const std::vector outputHighValues = ov::as_type_ptr(quantize->get_input_node_shared_ptr(4))->cast_vector(); return QuantizationDetails( quantize->get_levels(), @@ -150,7 +150,7 @@ float QuantizationDetails::getOutputHighValue(const size_t index) const { } std::vector QuantizationDetails::getBlobValue(std::shared_ptr constantLayer) { - return as_type_ptr(constantLayer)->cast_vector(); + return ov::as_type_ptr(constantLayer)->cast_vector(); } bool QuantizationDetails::isSupportedLevel(const size_t level) { diff --git a/inference-engine/src/low_precision_transformations/src/reduce_base_transformation.cpp b/inference-engine/src/low_precision_transformations/src/reduce_base_transformation.cpp index e178d94b98a090..ddd7cb110f678a 100644 --- a/inference-engine/src/low_precision_transformations/src/reduce_base_transformation.cpp +++ b/inference-engine/src/low_precision_transformations/src/reduce_base_transformation.cpp @@ -40,7 +40,7 @@ bool ReduceBaseTransformation::canBeTransformed(const TransformationContext& con return false; } - const auto axesConstant = as_type_ptr(reduce->get_input_node_shared_ptr(1)); + const auto axesConstant = ov::as_type_ptr(reduce->get_input_node_shared_ptr(1)); if (axesConstant == nullptr) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/reduce_max.cpp b/inference-engine/src/low_precision_transformations/src/reduce_max.cpp index 29e230314e72d9..9cfec0038b89b8 100644 --- a/inference-engine/src/low_precision_transformations/src/reduce_max.cpp +++ b/inference-engine/src/low_precision_transformations/src/reduce_max.cpp @@ -31,7 +31,7 @@ ReduceMaxTransformation::ReduceMaxTransformation(const Params& params) : ReduceB } bool ReduceMaxTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr reduce) const { - if (!is_type(reduce)) { + if (!ov::is_type(reduce)) { return false; } @@ -40,7 +40,7 @@ bool ReduceMaxTransformation::canBeTransformed(const TransformationContext& cont } const auto dequantization = NetworkHelper::getDequantization(reduce); - const std::vector scales = as_type_ptr(dequantization.multiplyConstant)->cast_vector(); + const std::vector scales = ov::as_type_ptr(dequantization.multiplyConstant)->cast_vector(); if (std::any_of(scales.begin(), scales.end(), [](const float value) { return value < 0.0; })) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/reduce_mean.cpp b/inference-engine/src/low_precision_transformations/src/reduce_mean.cpp index c91abbeb1ccc9e..1e9ab73ae300c5 100644 --- a/inference-engine/src/low_precision_transformations/src/reduce_mean.cpp +++ b/inference-engine/src/low_precision_transformations/src/reduce_mean.cpp @@ -31,7 +31,7 @@ ReduceMeanTransformation::ReduceMeanTransformation(const Params& params) : Reduc } bool ReduceMeanTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr reduce) const { - return is_type(reduce) ? ReduceBaseTransformation::canBeTransformed(context, reduce) : false; + return ov::is_type(reduce) ? ReduceBaseTransformation::canBeTransformed(context, reduce) : false; } bool ReduceMeanTransformation::isPrecisionPreserved(std::shared_ptr reduce) const noexcept { diff --git a/inference-engine/src/low_precision_transformations/src/reduce_min.cpp b/inference-engine/src/low_precision_transformations/src/reduce_min.cpp index 1d0e9da5accddc..c049fbde197320 100644 --- a/inference-engine/src/low_precision_transformations/src/reduce_min.cpp +++ b/inference-engine/src/low_precision_transformations/src/reduce_min.cpp @@ -31,7 +31,7 @@ ReduceMinTransformation::ReduceMinTransformation(const Params& params) : ReduceB } bool ReduceMinTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr reduce) const { - if (!is_type(reduce)) { + if (!ov::is_type(reduce)) { return false; } @@ -40,7 +40,7 @@ bool ReduceMinTransformation::canBeTransformed(const TransformationContext& cont } const auto dequantization = NetworkHelper::getDequantization(reduce); - const std::vector scales = as_type_ptr(dequantization.multiplyConstant)->cast_vector(); + const std::vector scales = ov::as_type_ptr(dequantization.multiplyConstant)->cast_vector(); if (std::any_of(scales.begin(), scales.end(), [](const float value) { return value < 0.0; })) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/reduce_sum.cpp b/inference-engine/src/low_precision_transformations/src/reduce_sum.cpp index 7ffcb435bd0895..a6642a5f97f2d7 100644 --- a/inference-engine/src/low_precision_transformations/src/reduce_sum.cpp +++ b/inference-engine/src/low_precision_transformations/src/reduce_sum.cpp @@ -31,7 +31,7 @@ ReduceSumTransformation::ReduceSumTransformation(const Params& params) : ReduceB } bool ReduceSumTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr reduce) const { - const auto reduceSum = as_type_ptr(reduce); + const auto reduceSum = ov::as_type_ptr(reduce); if (!reduceSum || !ReduceBaseTransformation::canBeTransformed(context, reduceSum)) { return false; } @@ -57,7 +57,7 @@ void ReduceSumTransformation::changeDequantizationValues( ReduceBaseTransformation::changeDequantizationValues(reduce, dequantization); if (dequantization.subtract) { - const auto reduceSum = as_type_ptr(reduce); + const auto reduceSum = ov::as_type_ptr(reduce); const auto reductionAxes = reduceSum->get_reduction_axes(); const auto inputShape = reduceSum->get_input_partial_shape(0); @@ -72,7 +72,7 @@ void ReduceSumTransformation::changeDequantizationValues( const auto result = fold(dequantization.subtractConstant, reductionSizeConstant); replace_node(dequantization.subtractConstant, result); - dequantization.subtractConstant = as_type_ptr(result); + dequantization.subtractConstant = ov::as_type_ptr(result); } } diff --git a/inference-engine/src/low_precision_transformations/src/reshape.cpp b/inference-engine/src/low_precision_transformations/src/reshape.cpp index e8263bd7528455..da44763ba0d66f 100644 --- a/inference-engine/src/low_precision_transformations/src/reshape.cpp +++ b/inference-engine/src/low_precision_transformations/src/reshape.cpp @@ -125,7 +125,7 @@ void reshapeDequantizationConstant(const std::shared_ptr& resha } bool ReshapeTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { - std::shared_ptr reshape = as_type_ptr(m.get_match_root()); + std::shared_ptr reshape = ov::as_type_ptr(m.get_match_root()); if (NetworkHelper::isConstantPath(reshape)) { return false; } @@ -134,7 +134,7 @@ bool ReshapeTransformation::transform(TransformationContext& context, ngraph::pa return false; } - reshape = as_type_ptr(NetworkHelper::separateInStandaloneBranch(reshape)); + reshape = ov::as_type_ptr(NetworkHelper::separateInStandaloneBranch(reshape)); reshapeDequantizationConstant(reshape); moveDequantizationAfter(context, reshape, NetworkHelper::getDequantization(reshape, 0), false); return true; diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp index 2425b3f1e12b89..95a6168db9c4a8 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp @@ -36,11 +36,11 @@ constexpr VariantTypeInfo VariantWrapper::type_i std::shared_ptr>> VariantWrapper::create( const std::shared_ptr& node, const AttributeParameters& params) { - if (!is_type(node)) { + if (!ov::is_type(node)) { return nullptr; } - auto fakeQuantize = as_type_ptr(node); + auto fakeQuantize = ov::as_type_ptr(node); if (!QuantizationDetails::outputLayoutIsSupported(fakeQuantize) || !QuantizationDetails::isSupportedLevel(fakeQuantize->get_levels())) { return nullptr; } @@ -58,8 +58,8 @@ std::shared_ptr>> Va } } - const auto outLow = as_type_ptr(node->get_input_node_shared_ptr(3)); - const auto outHigh = as_type_ptr(node->get_input_node_shared_ptr(4)); + const auto outLow = ov::as_type_ptr(node->get_input_node_shared_ptr(3)); + const auto outHigh = ov::as_type_ptr(node->get_input_node_shared_ptr(4)); if (!NetworkHelper::isScalarLike(outLow) || !NetworkHelper::isScalarLike(outHigh)) { return nullptr; } @@ -78,7 +78,7 @@ std::shared_ptr>> Va foldConvert(node->get_input_node_ptr(3)->shared_from_this(), params.deqPrecision), dequantization.multiplyConstant); - auto multiplyResultConstant = as_type_ptr(multiplyResult); + auto multiplyResultConstant = ov::as_type_ptr(multiplyResult); auto intervals = multiplyResultConstant->cast_vector(); lowInterval = *std::min_element(intervals.begin(), intervals.end()); } @@ -90,7 +90,7 @@ std::shared_ptr>> Va foldConvert(node->get_input_node_ptr(4)->shared_from_this(), params.deqPrecision), dequantization.multiplyConstant); - auto multiplyResultConstant = as_type_ptr(multiplyResult); + auto multiplyResultConstant = ov::as_type_ptr(multiplyResult); auto intervals = multiplyResultConstant->cast_vector(); highInterval = *std::max_element(intervals.begin(), intervals.end()); } @@ -115,8 +115,8 @@ std::shared_ptr>> Va fakeQuantize->get_levels())); rtInfo[ngraph::VariantWrapper::type_info.name] = attribute; - const std::vector outputLowValues = as_type_ptr(fakeQuantize->get_input_node_shared_ptr(3))->cast_vector(); - const std::vector outputHighValues = as_type_ptr(fakeQuantize->get_input_node_shared_ptr(4))->cast_vector(); + const std::vector outputLowValues = ov::as_type_ptr(fakeQuantize->get_input_node_shared_ptr(3))->cast_vector(); + const std::vector outputHighValues = ov::as_type_ptr(fakeQuantize->get_input_node_shared_ptr(4))->cast_vector(); LayerTransformation::PrecisionDetails preferablePrecision = LayerTransformation::getPrecisionDetails( fakeQuantize->get_levels(), outputLowValues, diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/precisions_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/precisions_attribute.cpp index 334f3a3eae37f9..3344f4f74a72b6 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/precisions_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/precisions_attribute.cpp @@ -33,7 +33,7 @@ std::shared_ptr>> VariantWra auto attribute = ngraph::pass::low_precision::make_shared_attribute(); auto wrapper = std::make_shared>>(attribute); - auto& rt = is_type(node) ? node->output(0).get_rt_info() : node->get_rt_info(); + auto& rt = ov::is_type(node) ? node->output(0).get_rt_info() : node->get_rt_info(); rt[ngraph::VariantWrapper>::type_info.name] = wrapper; return wrapper; } diff --git a/inference-engine/src/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp b/inference-engine/src/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp index b95a9567a3e6d9..26fd6711c34b75 100644 --- a/inference-engine/src/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp +++ b/inference-engine/src/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp @@ -47,16 +47,16 @@ std::shared_ptr>> const auto dequantization = NetworkHelper::getDequantization(node, index); if (!dequantization.empty() && - (is_type(dequantization.data.get_node())) && - is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { + (ov::is_type(dequantization.data.get_node())) && + ov::is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { inputNode = dequantization.data.get_node()->get_input_node_shared_ptr(0); } - if (is_type(inputNode)) { + if (ov::is_type(inputNode)) { continue; } - if (!is_type(inputNode)) { + if (!ov::is_type(inputNode)) { leastOneOperationIsNotFakeQuantize = true; break; } diff --git a/inference-engine/src/low_precision_transformations/src/shuffle_channels.cpp b/inference-engine/src/low_precision_transformations/src/shuffle_channels.cpp index 129bcb23977547..2b0621c982c22c 100644 --- a/inference-engine/src/low_precision_transformations/src/shuffle_channels.cpp +++ b/inference-engine/src/low_precision_transformations/src/shuffle_channels.cpp @@ -38,7 +38,7 @@ bool ShuffleChannelsTransformation::transform(TransformationContext& context, ng return false; } - const auto shuffleChannels = as_type_ptr(NetworkHelper::separateInStandaloneBranch(m.get_match_root())); + const auto shuffleChannels = ov::as_type_ptr(NetworkHelper::separateInStandaloneBranch(m.get_match_root())); auto dequantization = NetworkHelper::getDequantization(shuffleChannels); const auto shuffleDequantizationConstant = [&](const std::shared_ptr& eltwise) { @@ -58,7 +58,7 @@ bool ShuffleChannelsTransformation::transform(TransformationContext& context, ng } else { const auto group = shuffleChannels->get_group(); const auto shuffledConst = fold(normalizedConst, normalizedAxis, group); - return as_type_ptr(shuffledConst); + return ov::as_type_ptr(shuffledConst); } } }; @@ -82,7 +82,7 @@ bool ShuffleChannelsTransformation::canBeTransformed(const TransformationContext return false; } - const auto shuffleChannels = as_type_ptr(op); + const auto shuffleChannels = ov::as_type_ptr(op); if (shuffleChannels == nullptr) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/split.cpp b/inference-engine/src/low_precision_transformations/src/split.cpp index a663fc64f0a2fa..eabe1f7e45ecd1 100644 --- a/inference-engine/src/low_precision_transformations/src/split.cpp +++ b/inference-engine/src/low_precision_transformations/src/split.cpp @@ -46,7 +46,7 @@ bool SplitTransformation::transform(TransformationContext& context, ngraph::patt newSplit->set_friendly_name(split->get_friendly_name()); ngraph::copy_runtime_info(split, newSplit); - const int64_t axis = as_type_ptr(split->get_input_node_shared_ptr(1))->cast_vector()[0]; + const int64_t axis = ov::as_type_ptr(split->get_input_node_shared_ptr(1))->cast_vector()[0]; const size_t normalizedAxis = normalize_axis(split->get_friendly_name(), axis, split->get_input_partial_shape(0).rank()); const size_t outputSize = newSplit->get_output_size(); @@ -128,7 +128,7 @@ void SplitTransformation::updateOutputs( const auto lastNode = lastNodes[i]; for (auto output : lastNodes[i]->outputs()) { for (auto input : output.get_target_inputs()) { - if (is_type(input.get_node())) { + if (ov::is_type(input.get_node())) { originalNode->set_friendly_name(originalName + LayerTransformation::originalLayerPostfix); lastNode->set_friendly_name(originalName + "." + std::to_string(i)); break; @@ -149,7 +149,7 @@ bool SplitTransformation::canBeTransformed(const TransformationContext& context, } const auto consumers = NetworkHelper::consumers(layer); - const auto concat = as_type_ptr(consumers[0]); + const auto concat = ov::as_type_ptr(consumers[0]); // WA to avoid propagation of dequantization if after Split all consumers are the same unsupported Concat if (concat && concat->get_axis() != 1ul) { diff --git a/inference-engine/src/low_precision_transformations/src/squeeze.cpp b/inference-engine/src/low_precision_transformations/src/squeeze.cpp index 919364d1bbf08d..42d8e7e5932db0 100644 --- a/inference-engine/src/low_precision_transformations/src/squeeze.cpp +++ b/inference-engine/src/low_precision_transformations/src/squeeze.cpp @@ -47,7 +47,7 @@ bool SqueezeTransformation::transform(TransformationContext& context, ngraph::pa return NetworkHelper::toScalar(dequantizationOpConstant); } if (constantShape.size() == inputRankValue) { - return as_type_ptr(fold(dequantizationOpConstant, squeeze->get_input_node_shared_ptr(1))); + return ov::as_type_ptr(fold(dequantizationOpConstant, squeeze->get_input_node_shared_ptr(1))); } return dequantizationOpConstant; diff --git a/inference-engine/src/low_precision_transformations/src/strided_slice.cpp b/inference-engine/src/low_precision_transformations/src/strided_slice.cpp index 5e34d1bf45b453..470e7aec2fc2ea 100644 --- a/inference-engine/src/low_precision_transformations/src/strided_slice.cpp +++ b/inference-engine/src/low_precision_transformations/src/strided_slice.cpp @@ -19,7 +19,7 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::low_precision::StridedSliceTransformation, std::shared_ptr stridedSliceDeqConstant( const std::shared_ptr strSlice, const std::shared_ptr dequantizaitonConstant) { - auto constant = as_type_ptr(dequantizaitonConstant); + auto constant = ov::as_type_ptr(dequantizaitonConstant); auto constantShape = constant->get_shape(); if (shape_size(constantShape) == 1ul) { return NetworkHelper::toScalar(constant); @@ -45,10 +45,10 @@ std::shared_ptr stridedSliceDeqConstant( const auto newConstant = fold( constant, ngraph::opset1::Constant::create(ngraph::element::i32, { newConstantShape.size() }, newConstantShape)); - constant = as_type_ptr(newConstant); + constant = ov::as_type_ptr(newConstant); } - const auto stridedSlice = as_type_ptr(strSlice); + const auto stridedSlice = ov::as_type_ptr(strSlice); auto beginMask = stridedSlice->get_begin_mask(); auto endMask = stridedSlice->get_end_mask(); @@ -116,7 +116,7 @@ bool StridedSliceTransformation::transform(TransformationContext& context, ngrap } bool StridedSliceTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr operation) const { - if (!is_type(operation) || NetworkHelper::isDQByDynamicDimension(operation)) { + if (!ov::is_type(operation) || NetworkHelper::isDQByDynamicDimension(operation)) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/subtract.cpp b/inference-engine/src/low_precision_transformations/src/subtract.cpp index 4c71e191c2f6e2..83569ef8dc2db9 100644 --- a/inference-engine/src/low_precision_transformations/src/subtract.cpp +++ b/inference-engine/src/low_precision_transformations/src/subtract.cpp @@ -42,7 +42,7 @@ SubtractTransformation::SubtractTransformation(const Params& params) : LayerTran } bool SubtractTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { - std::shared_ptr subtract = as_type_ptr(m.get_match_root()); + std::shared_ptr subtract = ov::as_type_ptr(m.get_match_root()); if (!canBeTransformed(context, subtract)) { return false; } @@ -54,7 +54,7 @@ bool SubtractTransformation::transform(TransformationContext& context, ngraph::p // before: Y = X * SC - SH, after: Y = (X - SH') * SC // X * SC - SH = X * SC - SH' * SC // SH' = SH / SC - std::shared_ptr newSubtract = as_type_ptr(subtract->copy_with_new_inputs({ + std::shared_ptr newSubtract = ov::as_type_ptr(subtract->copy_with_new_inputs({ dequantization.multiply->get_input_node_shared_ptr(0), ngraph::pass::low_precision::fold( subtract->get_input_node_shared_ptr(1), @@ -71,7 +71,7 @@ bool SubtractTransformation::transform(TransformationContext& context, ngraph::p } if (dequantization.subtract != nullptr) { - std::shared_ptr newSubtract = as_type_ptr(subtract->copy_with_new_inputs({ + std::shared_ptr newSubtract = ov::as_type_ptr(subtract->copy_with_new_inputs({ dequantization.subtract->get_input_node_shared_ptr(0), ngraph::pass::low_precision::fold( subtract->get_input_node_shared_ptr(1), diff --git a/inference-engine/src/low_precision_transformations/src/subtract_multiply_to_multiply_add.cpp b/inference-engine/src/low_precision_transformations/src/subtract_multiply_to_multiply_add.cpp index f8554db8721ed9..895a502f178ab4 100644 --- a/inference-engine/src/low_precision_transformations/src/subtract_multiply_to_multiply_add.cpp +++ b/inference-engine/src/low_precision_transformations/src/subtract_multiply_to_multiply_add.cpp @@ -37,9 +37,9 @@ SubtractMultiplyToMultiplyAddTransformation::SubtractMultiplyToMultiplyAddTransf FakeQuantizeDequantization get(const std::shared_ptr node) { Output dataNode = node; - const std::shared_ptr multiply = is_type( + const std::shared_ptr multiply = ov::is_type( dataNode.get_node_shared_ptr()->get_input_node_shared_ptr(1)) ? - as_type_ptr(dataNode.get_node_shared_ptr()) : + ov::as_type_ptr(dataNode.get_node_shared_ptr()) : nullptr; std::shared_ptr multiplyConstant; if (multiply != nullptr) { @@ -48,8 +48,8 @@ FakeQuantizeDequantization get(const std::shared_ptr node) { } const std::shared_ptr subtract = (dataNode.get_node_shared_ptr()->get_input_size() > 1ul) - && is_type(dataNode.get_node_shared_ptr()->get_input_node_ptr(1)) ? - as_type_ptr(dataNode.get_node_shared_ptr()) : + && ov::is_type(dataNode.get_node_shared_ptr()->get_input_node_ptr(1)) ? + ov::as_type_ptr(dataNode.get_node_shared_ptr()) : nullptr; std::shared_ptr subtractConvert; std::shared_ptr subtractConstant; @@ -58,7 +58,7 @@ FakeQuantizeDequantization get(const std::shared_ptr node) { dataNode = subtract->get_input_source_output(0); } - const std::shared_ptr convert = as_type_ptr(dataNode.get_node_shared_ptr()); + const std::shared_ptr convert = ov::as_type_ptr(dataNode.get_node_shared_ptr()); if (convert != nullptr) { dataNode = convert->get_input_source_output(0); } @@ -119,8 +119,8 @@ bool SubtractMultiplyToMultiplyAddTransformation::transform(TransformationContex std::make_shared(deqPrecision, Shape{}, std::vector{ -1.f })), foldConvert(dequantization.multiply->get_input_node_shared_ptr(1), deqPrecision)); - if (is_type(subtractConstant)) { - std::shared_ptr constant = as_type_ptr(subtractConstant); + if (ov::is_type(subtractConstant)) { + std::shared_ptr constant = ov::as_type_ptr(subtractConstant); if (NetworkHelper::isScalarLike(constant)) { subtractConstant = NetworkHelper::toScalar(constant); } @@ -137,7 +137,7 @@ bool SubtractMultiplyToMultiplyAddTransformation::transform(TransformationContex lastNewPrecision = precisionAfterDequantization; } else { - NetworkHelper::setOutDataPrecision(as_type_ptr(lastNew.get_node_shared_ptr()), precisionAfterDequantization); + NetworkHelper::setOutDataPrecision(ov::as_type_ptr(lastNew.get_node_shared_ptr()), precisionAfterDequantization); } const std::shared_ptr lastOriginal = dequantization.multiply == nullptr ? diff --git a/inference-engine/src/low_precision_transformations/src/transpose.cpp b/inference-engine/src/low_precision_transformations/src/transpose.cpp index a7be7c7f6f48c7..518b945b088f9c 100644 --- a/inference-engine/src/low_precision_transformations/src/transpose.cpp +++ b/inference-engine/src/low_precision_transformations/src/transpose.cpp @@ -100,7 +100,7 @@ bool TransposeTransformation::canBeTransformed(const TransformationContext& cont return false; } - const std::shared_ptr constant = as_type_ptr(op->get_input_node_shared_ptr(1)); + const std::shared_ptr constant = ov::as_type_ptr(op->get_input_node_shared_ptr(1)); if (constant == nullptr) { return false; } @@ -113,7 +113,7 @@ bool TransposeTransformation::canBeTransformed(const TransformationContext& cont } } if (dequantization.multiply != nullptr) { - const auto mulConst = as_type_ptr(dequantization.multiplyConstant); + const auto mulConst = ov::as_type_ptr(dequantization.multiplyConstant); if (!NetworkHelper::isScalarLike(mulConst)) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/unsqueeze.cpp b/inference-engine/src/low_precision_transformations/src/unsqueeze.cpp index d2f0636c832f16..011bb4d46f0002 100644 --- a/inference-engine/src/low_precision_transformations/src/unsqueeze.cpp +++ b/inference-engine/src/low_precision_transformations/src/unsqueeze.cpp @@ -48,7 +48,7 @@ bool UnsqueezeTransformation::transform(TransformationContext& context, ngraph:: } if (constantShape.size() == inputRankValue) { - return as_type_ptr(fold(dequantizationOpConstant, unsqueeze->get_input_node_shared_ptr(1))); + return ov::as_type_ptr(fold(dequantizationOpConstant, unsqueeze->get_input_node_shared_ptr(1))); } return dequantizationOpConstant; diff --git a/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp b/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp index 6649492dd55948..63401238089af4 100644 --- a/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp +++ b/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp @@ -34,7 +34,7 @@ bool WeightableLayerTransformation::canConvolutionBeTransformed(const Transforma return false; } - std::shared_ptr reshapeFromWeights = as_type_ptr(layer->get_input_node_shared_ptr(1)); + std::shared_ptr reshapeFromWeights = ov::as_type_ptr(layer->get_input_node_shared_ptr(1)); dequantization = reshapeFromWeights == nullptr ? NetworkHelper::getDequantization(layer, 1ul) : NetworkHelper::getDequantization(reshapeFromWeights); @@ -134,20 +134,20 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext // TODO Implement similar checks in other weightable operaitons - const std::shared_ptr reshapeFromWeights = as_type_ptr(layer->get_input_node_shared_ptr(1)); + const std::shared_ptr reshapeFromWeights = ov::as_type_ptr(layer->get_input_node_shared_ptr(1)); std::shared_ptr fqFromWeights; if (reshapeFromWeights == nullptr) { - fqFromWeights = as_type_ptr(layer->get_input_node_shared_ptr(1)); + fqFromWeights = ov::as_type_ptr(layer->get_input_node_shared_ptr(1)); if (fqFromWeights == nullptr) { const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(layer, 1ul); - fqFromWeights = as_type_ptr(dequantization.data.get_node_shared_ptr()); + fqFromWeights = ov::as_type_ptr(dequantization.data.get_node_shared_ptr()); } } else { - fqFromWeights = as_type_ptr(reshapeFromWeights->get_input_node_shared_ptr(0)); + fqFromWeights = ov::as_type_ptr(reshapeFromWeights->get_input_node_shared_ptr(0)); if (fqFromWeights == nullptr) { const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(reshapeFromWeights, 0ul); - fqFromWeights = as_type_ptr(dequantization.data.get_node_shared_ptr()); + fqFromWeights = ov::as_type_ptr(dequantization.data.get_node_shared_ptr()); } } @@ -164,7 +164,7 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext const auto fqOutPShape = fqFromWeights->get_output_partial_shape(0); - const size_t outChannelsIdx = is_type(layer) ? 1ul : 0ul; + const size_t outChannelsIdx = ov::is_type(layer) ? 1ul : 0ul; if (fqOutPShape.rank().is_dynamic() || fqOutPShape[outChannelsIdx].is_dynamic()) { return false; } @@ -188,7 +188,7 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext return false; } - const auto weightsData = as_type_ptr(dequantizationOnWeights.data.get_node_shared_ptr()); + const auto weightsData = ov::as_type_ptr(dequantizationOnWeights.data.get_node_shared_ptr()); if (weightsData == nullptr) { return false; } @@ -205,7 +205,7 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext } } - const size_t outChannelsIdx = is_type(layer) ? 1ul : 0ul; + const size_t outChannelsIdx = ov::is_type(layer) ? 1ul : 0ul; if (dequantizationOnWeights.subtract) { const auto subConstShape = dequantizationOnWeights.subtractConstant->get_shape(); if (shape_size(subConstShape) > 1ul && shape_size(subConstShape) != subConstShape[outChannelsIdx]) { @@ -227,18 +227,18 @@ bool WeightableLayerTransformation::isQuantizedStatic(const std::shared_ptrget_input_node_shared_ptr(1); - if (!is_type(reshape)) { + if (!ov::is_type(reshape)) { return false; } - if (is_type(reshape->get_input_node_shared_ptr(0))) { - const std::shared_ptr fq = as_type_ptr(reshape->get_input_node_shared_ptr(0)); + if (ov::is_type(reshape->get_input_node_shared_ptr(0))) { + const std::shared_ptr fq = ov::as_type_ptr(reshape->get_input_node_shared_ptr(0)); return NetworkHelper::isQuantizeSupported(fq); } dequantizationOnWeights = NetworkHelper::getDequantization(reshape, 0); - } else if (is_type(layer->get_input_node_shared_ptr(1))) { - const std::shared_ptr fq = as_type_ptr(layer->get_input_node_shared_ptr(1)); + } else if (ov::is_type(layer->get_input_node_shared_ptr(1))) { + const std::shared_ptr fq = ov::as_type_ptr(layer->get_input_node_shared_ptr(1)); return NetworkHelper::isQuantizeSupported(fq); } else { // TODO: update NetworkHelper API later @@ -251,7 +251,7 @@ bool WeightableLayerTransformation::isQuantizedStatic(const std::shared_ptr(dequantizationOnWeights.data.get_node())) { + if (ov::is_type(dequantizationOnWeights.data.get_node())) { const ngraph::element::Type weightsDataPrecision = dequantizationOnWeights.data.get_element_type(); if (!DataPrecision::isSupported(weightsDataPrecision)) { return false; @@ -264,7 +264,7 @@ bool WeightableLayerTransformation::isQuantizedStatic(const std::shared_ptr(layer) ? 1ul : 0ul; + const size_t outChannelsShapeIndex = ov::is_type(layer) ? 1ul : 0ul; if (dequantizationOnWeights.subtract) { const auto subConstShape = dequantizationOnWeights.subtractConstant->get_shape(); if (shape_size(subConstShape) > 1ul && shape_size(subConstShape) != subConstShape[outChannelsShapeIndex]) { @@ -279,7 +279,7 @@ bool WeightableLayerTransformation::isQuantizedStatic(const std::shared_ptr(dequantizationOnWeights.data.get_node())) { + } else if (ov::is_type(dequantizationOnWeights.data.get_node())) { return true; } @@ -321,7 +321,7 @@ bool WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(const st return false; } - if (as_type_ptr(fqOnWeights) == nullptr) { + if (ov::as_type_ptr(fqOnWeights) == nullptr) { THROW_IE_LPT_EXCEPTION(*fqOnWeights) << "FakeQuantize on weights was not folded to constant"; } @@ -329,7 +329,7 @@ bool WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(const st } bool WeightableLayerTransformation::isGroup(const std::shared_ptr& layer) { - if (!is_type(layer) && !is_type(layer)) { + if (!ov::is_type(layer) && !ov::is_type(layer)) { return false; } @@ -338,7 +338,7 @@ bool WeightableLayerTransformation::isGroup(const std::shared_ptr& layer) } bool WeightableLayerTransformation::isDepthwise(const std::shared_ptr& layer) { - if (!as_type_ptr(layer) && !as_type_ptr(layer)) { + if (!ov::as_type_ptr(layer) && !ov::as_type_ptr(layer)) { return false; } @@ -349,10 +349,10 @@ bool WeightableLayerTransformation::isDepthwise(const std::shared_ptr& lay } std::shared_ptr WeightableLayerTransformation::getFakeQuantizeOnWeights(const std::shared_ptr& node) { - auto fq = as_type_ptr(node->get_input_node_shared_ptr(1)); + auto fq = ov::as_type_ptr(node->get_input_node_shared_ptr(1)); // TODO: temporary workaround if (fq == nullptr) { - fq = as_type_ptr(node->get_input_node_ptr(1)->get_input_node_shared_ptr(0)); + fq = ov::as_type_ptr(node->get_input_node_ptr(1)->get_input_node_shared_ptr(0)); } return fq; diff --git a/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp b/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp index 42fa47a3eb6cc6..46d4a761740dfc 100644 --- a/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp +++ b/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp @@ -19,7 +19,7 @@ Mask::Ptr getMask(const Output & output) { if (!rtInfo.count(MaskWrapper::type_info.name)) return nullptr; const auto &attr = rtInfo.at(MaskWrapper::type_info.name); - return as_type_ptr(attr)->get(); + return ov::as_type_ptr(attr)->get(); } Mask::Ptr getMask(const Output & output) { @@ -29,7 +29,7 @@ Mask::Ptr getMask(const Output & output) { if (!rtInfo.count(MaskWrapper::type_info.name)) return nullptr; const auto &attr = rtInfo.at(MaskWrapper::type_info.name); - return as_type_ptr(attr)->get(); + return ov::as_type_ptr(attr)->get(); } void setMask(Output output, const Mask::Ptr & mask) { diff --git a/inference-engine/src/snippets/src/op/subgraph.cpp b/inference-engine/src/snippets/src/op/subgraph.cpp index f58b1d383dceea..f114b49e4e1ebb 100644 --- a/inference-engine/src/snippets/src/op/subgraph.cpp +++ b/inference-engine/src/snippets/src/op/subgraph.cpp @@ -223,7 +223,7 @@ snippets::Schedule snippets::op::Subgraph::generate(const BlockedShapeVector& ou // chack that body doesnt have constants for scheduling std::vector> constants; for (auto op : m_body->get_ordered_ops()) { - if (auto constant = as_type_ptr(op)) { + if (auto constant = ov::as_type_ptr(op)) { if (ngraph::shape_size(constant->get_shape()) != 1 && constant->get_shape() != Shape()) { constants.push_back(constant); } diff --git a/inference-engine/src/snippets/src/pass/assign_registers.cpp b/inference-engine/src/snippets/src/pass/assign_registers.cpp index de7df3792b8caa..7561b2403a08ac 100644 --- a/inference-engine/src/snippets/src/pass/assign_registers.cpp +++ b/inference-engine/src/snippets/src/pass/assign_registers.cpp @@ -156,13 +156,13 @@ bool ngraph::snippets::pass::AssignRegisters::run_on_function(std::shared_ptr(n) || as_type_ptr(n)) { + if (ov::as_type_ptr(n) || ov::as_type_ptr(n)) { auto source = n->get_input_source_output(0).get_node_shared_ptr(); - if (auto param = as_type_ptr(source)) { + if (auto param = ov::as_type_ptr(source)) { auto ea = reg64_tmp_start+static_cast(f->get_parameter_index(param)); rt["effectiveAddress"] = std::make_shared>(VariantWrapper(ea)); - } else if (auto constant = as_type_ptr(source)) { + } else if (auto constant = ov::as_type_ptr(source)) { auto ea = reg64_tmp_start+static_cast(f->get_parameters().size() + f->get_results().size() + 1 + constantID); rt["effectiveAddress"] = std::make_shared>(VariantWrapper(ea)); constantID++; diff --git a/inference-engine/src/snippets/src/pass/collapse_subgraph.cpp b/inference-engine/src/snippets/src/pass/collapse_subgraph.cpp index 6f05719d9d5252..afa847b80f5d12 100644 --- a/inference-engine/src/snippets/src/pass/collapse_subgraph.cpp +++ b/inference-engine/src/snippets/src/pass/collapse_subgraph.cpp @@ -104,7 +104,7 @@ auto has_subgraph_as_input(std::shared_ptr node) -> bool { auto inputs = node->inputs(); for (auto input : inputs) { auto parent = input.get_source_output().get_node_shared_ptr(); - if (!!as_type_ptr(parent)) { + if (!!ov::as_type_ptr(parent)) { return true; } } @@ -114,66 +114,66 @@ auto has_subgraph_as_input(std::shared_ptr node) -> bool { auto is_lo(std::shared_ptr n) -> bool { auto is_lob = [](std::shared_ptr n) -> bool { using ngraph::as_type_ptr; - return !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n); + return !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n); }; auto is_lou = [](std::shared_ptr n) -> bool { using ngraph::as_type_ptr; - return !!as_type_ptr(n) - // || !!as_type_ptr(n) - // || !!as_type_ptr(n) - // || !!as_type_ptr(n) - // || !!as_type_ptr(n) ? - || !!as_type_ptr(n) - // || !!as_type_ptr(n) - // || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - // || !!as_type_ptr(n) ? - // || !!as_type_ptr(n) ? - || !!as_type_ptr(n) - || !!as_type_ptr(n) - || !!as_type_ptr(n) - // || !!as_type_ptr(n) ? - || !!as_type_ptr(n) - // || !!as_type_ptr(n) - // || !!as_type_ptr(n) - || !!as_type_ptr(n) - // || !!as_type_ptr(n) - || !!as_type_ptr(n); + return !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) ? + || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) ? + // || !!ov::as_type_ptr(n) ? + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) ? + || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n) + // || !!ov::as_type_ptr(n) + || !!ov::as_type_ptr(n); }; auto is_lot = [](std::shared_ptr n) -> bool { using ngraph::as_type_ptr; return false; - // return !!as_type_ptr(n) // ternary with 2 constants - // || !!as_type_ptr(n); // ternary with 2 constants / or DW + // return !!ov::as_type_ptr(n) // ternary with 2 constants + // || !!ov::as_type_ptr(n); // ternary with 2 constants / or DW }; auto is_fq = [](std::shared_ptr n) -> bool { using ngraph::as_type_ptr; - return false;//!!as_type_ptr(n); // 4->1 + return false;//!!ov::as_type_ptr(n); // 4->1 }; return is_lou(n) || is_lob(n) ||is_lot(n) || is_fq(n); @@ -208,11 +208,11 @@ auto has_supported_in_out(std::shared_ptr n) -> bool { } for (auto in_out : out.get_target_inputs()) { - if (!!as_type_ptr(in_out.get_node()->shared_from_this())) { + if (!!ov::as_type_ptr(in_out.get_node()->shared_from_this())) { return false; } - if (!!as_type_ptr(in_out.get_node()->shared_from_this())) { + if (!!ov::as_type_ptr(in_out.get_node()->shared_from_this())) { return false; } } @@ -305,7 +305,7 @@ ngraph::snippets::pass::AttachToSubgraph::AttachToSubgraph(bool tokenize_by_node for (auto& input : found.get_target_inputs()) { remark(13) << input.get_node() << " " << input.get_source_output() << " vs " << found << " : " << input.get_index() << " " << found.get_index() << std::endl; - if (as_type_ptr(input.get_node()->shared_from_this()) != nullptr && input.get_source_output() == found) { + if (ov::as_type_ptr(input.get_node()->shared_from_this()) != nullptr && input.get_source_output() == found) { return input.get_index(); } } @@ -315,7 +315,7 @@ ngraph::snippets::pass::AttachToSubgraph::AttachToSubgraph(bool tokenize_by_node for (auto input : inputs) { auto input_node = input.get_source_output().get_node_shared_ptr(); - if (auto subgraph = as_type_ptr(input_node)) { + if (auto subgraph = ov::as_type_ptr(input_node)) { if (!clones.count(input_node)) { auto f = ngraph::clone_function(*subgraph->get_body().get()); f->set_friendly_name(subgraph->get_body()->get_friendly_name()); @@ -327,7 +327,7 @@ ngraph::snippets::pass::AttachToSubgraph::AttachToSubgraph(bool tokenize_by_node for (auto input : inputs) { auto input_node = input.get_source_output().get_node_shared_ptr(); - if (auto subgraph = as_type_ptr(input_node)) { + if (auto subgraph = ov::as_type_ptr(input_node)) { if (!input_subgraphs.count(input_node)) { input_subgraphs.insert(input_node); @@ -356,7 +356,7 @@ ngraph::snippets::pass::AttachToSubgraph::AttachToSubgraph(bool tokenize_by_node for (auto output : internal->outputs()) { for (auto consumer : output.get_target_inputs()) { - if (auto to_replace_with = as_type_ptr(subgraph->input_value(i).get_node_shared_ptr())) { + if (auto to_replace_with = ov::as_type_ptr(subgraph->input_value(i).get_node_shared_ptr())) { auto other_body = clones[subgraph->input_value(i).get_node_shared_ptr()]; auto other_body_result = other_body->get_results()[consumer.get_source_output().get_index()]; auto result_producer = other_body_result->input(0).get_source_output(); diff --git a/inference-engine/src/transformations/src/ngraph_ops/nms_ie_internal.cpp b/inference-engine/src/transformations/src/ngraph_ops/nms_ie_internal.cpp index 85b96ada8502c6..9049ff0272c61c 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/nms_ie_internal.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/nms_ie_internal.cpp @@ -75,7 +75,7 @@ int64_t op::internal::NonMaxSuppressionIEInternal::max_boxes_output_from_input() } const auto max_output_boxes_input = - as_type_ptr(input_value(max_output_boxes_per_class_port).get_node_shared_ptr()); + ov::as_type_ptr(input_value(max_output_boxes_per_class_port).get_node_shared_ptr()); max_output_boxes = max_output_boxes_input->cast_vector().at(0); return max_output_boxes; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/nop_elimination.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/nop_elimination.cpp index 32f139a15ed9c9..982240bb1287d7 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/nop_elimination.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/nop_elimination.cpp @@ -20,7 +20,7 @@ using namespace ngraph; //`simplify_gather`, optimizes gather if Gather is gathering the // whole input tensor static bool simplify_gather(std::shared_ptr node) { - if (auto gather = as_type_ptr(node)) { + if (auto gather = ov::as_type_ptr(node)) { // check if we are gathering the whole input auto data = gather->input_value(0); auto indices = gather->input_value(1); @@ -56,7 +56,7 @@ static bool simplify_gather(std::shared_ptr node) { // check if the indices is constant auto constant_indices = - as_type_ptr(gather->input_value(1).get_node_shared_ptr()); + ov::as_type_ptr(gather->input_value(1).get_node_shared_ptr()); if (!constant_indices) { return false; } else { @@ -98,9 +98,9 @@ static bool eliminate_reshape_v1(const std::shared_ptr& node) { } // eliminate redundant reshape, squeeze, or unsqueeze auto input_node = input.get_node_shared_ptr(); - if (as_type_ptr(input_node) || - as_type_ptr(input_node) || - as_type_ptr(input_node)) { + if (ov::as_type_ptr(input_node) || + ov::as_type_ptr(input_node) || + ov::as_type_ptr(input_node)) { auto shape = node->get_output_shape(0); std::vector vi; vi.assign(shape.begin(), shape.end()); @@ -151,8 +151,8 @@ static bool replace_squeeze_unsqueeze(const std::shared_ptr& node) { auto pat = opset3::Constant::create(element::i64, Shape{target_shape.size()}, target_shape); - if (is_type(input) || is_type(input) || - is_type(input)) { + if (ov::is_type(input) || ov::is_type(input) || + ov::is_type(input)) { reshape = make_shared(input->input_value(0), pat, false); } else { reshape = make_shared(node->input_value(0), pat, false); @@ -205,11 +205,11 @@ static bool eliminate_unsqueeze(const std::shared_ptr& node) { return replace_squeeze_unsqueeze(node); } - auto unsqueeze = as_type_ptr(node); + auto unsqueeze = ov::as_type_ptr(node); if (unsqueeze == nullptr) return false; auto input = unsqueeze->input_value(0).get_node_shared_ptr(); - auto squeeze = as_type_ptr(input); + auto squeeze = ov::as_type_ptr(input); auto replace_unsqueeze_only = [&](const vector& axes) { auto axes_const = opset3::Constant::create(element::i64, Shape{axes.size()}, axes); auto new_unsq = make_shared(input->input_value(0), axes_const); @@ -253,7 +253,7 @@ static bool eliminate_unsqueeze(const std::shared_ptr& node) { return false; } // eliminate redundant unsqueeze->unsqueeze - auto unsqueeze_i = as_type_ptr(input); + auto unsqueeze_i = ov::as_type_ptr(input); if (unsqueeze_i) { const auto& data_shape = unsqueeze_i->input_value(0).get_partial_shape(); if (data_shape.rank().is_dynamic() || out_shape.rank().is_dynamic()) { @@ -273,7 +273,7 @@ static bool eliminate_squeeze(const std::shared_ptr& node) { return replace_squeeze_unsqueeze(node); } - auto squeeze = as_type_ptr(node); + auto squeeze = ov::as_type_ptr(node); if (squeeze == nullptr) return false; auto input = squeeze->input_value(0).get_node_shared_ptr(); @@ -286,7 +286,7 @@ static bool eliminate_squeeze(const std::shared_ptr& node) { return false; }; // eliminate redundant unsqueeze->squeeze - if (auto unsqueeze = as_type_ptr(input)) { + if (auto unsqueeze = ov::as_type_ptr(input)) { PartialShape data_shape; if (op::is_parameter(input)) { data_shape = unsqueeze->input(0).get_partial_shape(); @@ -324,7 +324,7 @@ static bool eliminate_squeeze(const std::shared_ptr& node) { return false; } // eliminate redundant squeeze->squeeze - if (auto squeeze_i = as_type_ptr(input)) { + if (auto squeeze_i = ov::as_type_ptr(input)) { PartialShape data_shape; if (op::is_parameter(input)) { data_shape = squeeze_i->input(0).get_partial_shape(); @@ -522,4 +522,4 @@ ngraph::pass::NopElimination::NopElimination(bool use_shape_for_elimination) { add_matcher(); add_matcher(); } -} \ No newline at end of file +} diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp index 244670d3678515..7e11215d9d015e 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp @@ -30,7 +30,7 @@ bool ngraph::pass::SharedShapeOf::run_on_function(std::shared_ptrget_function()) graph_rewritten |= run_on_function(sub_graph); - if (is_type(node) || is_type(node)) + if (ov::is_type(node) || ov::is_type(node)) source_to_shape_of[node->input_value(0)].push_back(node); } @@ -59,12 +59,12 @@ ngraph::pass::GroupedGatherElimination::GroupedGatherElimination() { while (inputs.size() > i + 1) { auto curr = inputs[i].get_node_shared_ptr(), next = inputs[i + 1].get_node_shared_ptr(); if (curr->get_type_info() != next->get_type_info() || - (!is_type(curr) && !is_type(curr)) || + (!ov::is_type(curr) && !ov::is_type(curr)) || (curr->input_value(0) != next->input_value(0))) { ++i; continue; } // curr and next are the same type of gather which takes data from the same source - bool is_opset1 = is_type(curr); + bool is_opset1 = ov::is_type(curr); auto joint_indices = ngraph::op::util::make_try_fold(OutputVector{curr->input_value(1), next->input_value(1)}, 0); std::shared_ptr new_gather; if (is_opset1) @@ -131,7 +131,7 @@ ngraph::pass::SimplifyGatherShapeOf::SimplifyGatherShapeOf() { ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { auto node = m.get_match_root(); - auto gather = as_type_ptr(node->input_value(0).get_node_shared_ptr()); + auto gather = ov::as_type_ptr(node->input_value(0).get_node_shared_ptr()); if (!gather) { return false; } diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp index bdee74a50f9d15..fe968bf54846d1 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp @@ -24,7 +24,7 @@ bool replace_transpose_with_reshape(const std::shared_ptr& transpose) { const size_t input_shape_rank = input_shape.rank().get_length(); - auto order = as_type_ptr(transpose->input_value(1).get_node_shared_ptr()); + auto order = ov::as_type_ptr(transpose->input_value(1).get_node_shared_ptr()); if (!order || !ngraph::shape_size(order->get_shape())) { return false; } diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp index 6b1872a05660ba..d0a6175f29e408 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp @@ -29,7 +29,7 @@ ngraph::pass::WeightsDequantizeToFakeQuantize::WeightsDequantizeToFakeQuantize() callback = [=](ngraph::pattern::Matcher &m) { const auto &pattern_map = m.get_pattern_map(); - const auto &weights_node = as_type_ptr(pattern_map.at(weights)); + const auto &weights_node = ov::as_type_ptr(pattern_map.at(weights)); const auto &convert_node = pattern_map.at(convert); const auto &multiply_node = pattern_map.at(mul); const auto &scale_node = pattern_map.at(mul_c); diff --git a/inference-engine/src/transformations/src/transformations/low_precision/disable_convert_constant_folding_on_const_path.cpp b/inference-engine/src/transformations/src/transformations/low_precision/disable_convert_constant_folding_on_const_path.cpp index 44d05860c4f53d..15dc27bada2130 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/disable_convert_constant_folding_on_const_path.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/disable_convert_constant_folding_on_const_path.cpp @@ -52,8 +52,8 @@ ngraph::pass::DisableConvertConstantFoldingOnConstPath::DisableConvertConstantFo return false; } auto child = target_inputs.begin()->get_node(); - if (is_type(parent) && - (is_type(child) || is_type(child))) { + if (ov::is_type(parent) && + (ov::is_type(child) || ov::is_type(child))) { auto& rtInfo = convert->get_rt_info(); rtInfo["DISABLED_CONSTANT_FOLDING"] = std::make_shared>(""); return true; diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp index 214e1359188e2b..7f5c0e67f5e287 100644 --- a/inference-engine/src/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp +++ b/inference-engine/src/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp @@ -150,9 +150,9 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() { auto crops_begin = batch_to_space->input_value(2); auto crops_end = batch_to_space->input_value(3); - const auto block_const = as_type_ptr(block.get_node_shared_ptr()); - const auto crops_begin_const = as_type_ptr(crops_begin.get_node_shared_ptr()); - const auto crops_end_const = as_type_ptr(crops_end.get_node_shared_ptr()); + const auto block_const = ov::as_type_ptr(block.get_node_shared_ptr()); + const auto crops_begin_const = ov::as_type_ptr(crops_begin.get_node_shared_ptr()); + const auto crops_end_const = ov::as_type_ptr(crops_end.get_node_shared_ptr()); const std::vector &block_values = block_const->cast_vector(); const std::vector &crops_end_values = crops_end_const->cast_vector(); diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp index 250d4e1674b379..9ba7d30c1f19e1 100644 --- a/inference-engine/src/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp +++ b/inference-engine/src/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp @@ -142,9 +142,9 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() { auto pads_begin = space_to_batch->input_value(2); auto pads_end = space_to_batch->input_value(3); - const auto block_const = as_type_ptr(block.get_node_shared_ptr()); - const auto pads_begin_const = as_type_ptr(pads_begin.get_node_shared_ptr()); - const auto pads_end_const = as_type_ptr(pads_end.get_node_shared_ptr()); + const auto block_const = ov::as_type_ptr(block.get_node_shared_ptr()); + const auto pads_begin_const = ov::as_type_ptr(pads_begin.get_node_shared_ptr()); + const auto pads_end_const = ov::as_type_ptr(pads_end.get_node_shared_ptr()); if (!block_const || !pads_begin_const || !pads_end_const) { return false; diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/convert_subtract.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/convert_subtract.cpp index 30d621cfb5c9f0..cd91573bffa2fd 100644 --- a/inference-engine/src/transformations/src/transformations/op_conversions/convert_subtract.cpp +++ b/inference-engine/src/transformations/src/transformations/op_conversions/convert_subtract.cpp @@ -37,15 +37,16 @@ ngraph::pass::ConvertSubtract::ConvertSubtract() { if (subChildren.size() == 1ul) { const std::shared_ptr child = subChildren.begin()->get_node()->shared_from_this(); if (child != nullptr) { - if (is_type(child) || - is_type(child) || - is_type(child) || - is_type(child) || - is_type(child) || - (is_type(child) && + if (ov::is_type(child) || + ov::is_type(child) || + ov::is_type(child) || + ov::is_type(child) || + ov::is_type(child) || + (ov::is_type(child) && (child->output(0).get_target_inputs().size() == 1ul) && - (is_type(child->output(0).get_target_inputs().begin()->get_node()->shared_from_this()) || - is_type(child->output(0).get_target_inputs().begin()->get_node()->shared_from_this())))) { + (ov::is_type(child->output(0).get_target_inputs().begin()->get_node()->shared_from_this()) || + ov::is_type(child->output(0).get_target_inputs().begin() + ->get_node()->shared_from_this())))) { const auto input1Type = sub->input(0).get_element_type(); const auto input2Type = sub->input(1).get_element_type(); if (((input1Type == element::u8) && (input2Type == element::u8)) || diff --git a/inference-engine/src/transformations/src/transformations/rt_info/dequantization_attribute.cpp b/inference-engine/src/transformations/src/transformations/rt_info/dequantization_attribute.cpp index 829f5a0d85b5e2..c2858c6d8f5a4a 100644 --- a/inference-engine/src/transformations/src/transformations/rt_info/dequantization_attribute.cpp +++ b/inference-engine/src/transformations/src/transformations/rt_info/dequantization_attribute.cpp @@ -27,7 +27,7 @@ std::string ngraph::getDequantization(const std::shared_ptr& node) if (!rtInfo.count(getDequantizationWrapper::type_info.name)) return ""; const auto& attr = rtInfo.at(getDequantizationWrapper::type_info.name); - DequantizationAttr pp = as_type_ptr(attr)->get(); + DequantizationAttr pp = ov::as_type_ptr(attr)->get(); return pp.getDequantizationAttr(); } diff --git a/inference-engine/src/transformations/src/transformations/rt_info/fused_names_attribute.cpp b/inference-engine/src/transformations/src/transformations/rt_info/fused_names_attribute.cpp index 01af6fc50d468e..7666d633ad90a8 100644 --- a/inference-engine/src/transformations/src/transformations/rt_info/fused_names_attribute.cpp +++ b/inference-engine/src/transformations/src/transformations/rt_info/fused_names_attribute.cpp @@ -41,7 +41,7 @@ std::string ngraph::getFusedNames(const std::shared_ptr &node) { if (!rtInfo.count(FusedNamesWrapper::type_info.name)) return {}; const auto &attr = rtInfo.at(FusedNamesWrapper::type_info.name); - FusedNames fusedNames = as_type_ptr(attr)->get(); + FusedNames fusedNames = ov::as_type_ptr(attr)->get(); return fusedNames.getNames(); } @@ -54,7 +54,7 @@ std::vector ngraph::getFusedNamesVector(const std::shared_ptr(attr)->get(); + FusedNames fusedNames = ov::as_type_ptr(attr)->get(); return fusedNames.getVectorNames(); } diff --git a/inference-engine/src/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp b/inference-engine/src/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp index 86244edd94daa2..bfd61ab8e9e5b0 100644 --- a/inference-engine/src/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp +++ b/inference-engine/src/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp @@ -30,7 +30,7 @@ std::string ngraph::getPrimitivesPriority(const std::shared_ptr &n if (!rtInfo.count(PrimitivesPriorityWrapper::type_info.name)) return ""; const auto &attr = rtInfo.at(PrimitivesPriorityWrapper::type_info.name); - PrimitivesPriority pp = as_type_ptr(attr)->get(); + PrimitivesPriority pp = ov::as_type_ptr(attr)->get(); return pp.getPrimitivesPriority(); } diff --git a/inference-engine/src/transformations/src/transformations/serialize.cpp b/inference-engine/src/transformations/src/transformations/serialize.cpp index 0ce92c208ea430..3fbb1463f088bf 100644 --- a/inference-engine/src/transformations/src/transformations/serialize.cpp +++ b/inference-engine/src/transformations/src/transformations/serialize.cpp @@ -215,13 +215,13 @@ class XmlSerializer : public ngraph::AttributeVisitor { input.append_attribute("external_port_id").set_value(input_description->m_input_index); input.append_attribute("internal_layer_id").set_value(parameter_mapping[input_description->m_body_parameter_index].c_str()); - if (auto slice_input = as_type_ptr(input_description)) { + if (auto slice_input = ov::as_type_ptr(input_description)) { input.prepend_attribute("axis").set_value(slice_input->m_axis); input.append_attribute("start").set_value(slice_input->m_start); input.append_attribute("end").set_value(slice_input->m_end); input.append_attribute("stride").set_value(slice_input->m_stride); input.append_attribute("part_size").set_value(slice_input->m_part_size); - } else if (auto merged_input = as_type_ptr(input_description)) { + } else if (auto merged_input = ov::as_type_ptr(input_description)) { pugi::xml_node back_edges = m_xml_node.parent().child("back_edges"); if (!back_edges) { back_edges = m_xml_node.parent().insert_child_after("back_edges", port_map); @@ -249,7 +249,7 @@ class XmlSerializer : public ngraph::AttributeVisitor { output.append_attribute("external_port_id").set_value(input_count + output_description->m_output_index); output.append_attribute("internal_layer_id").set_value(result_mapping[output_description->m_body_value_index].c_str()); - if (auto concat_output = as_type_ptr(output_description)) { + if (auto concat_output = ov::as_type_ptr(output_description)) { output.prepend_attribute("axis").set_value(concat_output->m_axis); output.append_attribute("start").set_value(concat_output->m_start); output.append_attribute("end").set_value(concat_output->m_end); diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp index dc81761eb5bb8d..8e93a05dfa1b1e 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp @@ -118,13 +118,13 @@ class ConvolutionBackpropDataTransformation : public LayerTransformation, public outputShape, netPrecision, testValues.actual.fakeQuantizeOnWeights, - as_type_ptr(actualWeights)); + ov::as_type_ptr(actualWeights)); } else { actualWeights = ngraph::builder::subgraph::ConvolutionBackpropDataFunction::getWeights( outputShape, netPrecision, testValues.actual.dequantizationOnWeights, - as_type_ptr(actualWeights)); + ov::as_type_ptr(actualWeights)); } actualFunction = ngraph::builder::subgraph::ConvolutionBackpropDataFunction::getOriginal( @@ -152,13 +152,13 @@ class ConvolutionBackpropDataTransformation : public LayerTransformation, public outputShape, netPrecision, testValues.actual.fakeQuantizeOnWeights, - as_type_ptr(refWeights)); + ov::as_type_ptr(refWeights)); } else { refWeights = ngraph::builder::subgraph::ConvolutionBackpropDataFunction::getWeights( outputShape, netPrecision, testValues.expected.dequantizationOnWeights, - as_type_ptr(refWeights)); + ov::as_type_ptr(refWeights)); } referenceFunction = ngraph::builder::subgraph::ConvolutionBackpropDataFunction::getReference( diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_transformation.cpp index 394ea243b3c369..adff5124470dd2 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_transformation.cpp @@ -83,7 +83,7 @@ class ConvolutionTransformation : public LayerTransformation, public testing::Wi OutputVector convertedOutput(1); convertOnWeights->constant_fold(convertedOutput, convertOnWeights->input_values()); const auto convertedWeights = convertedOutput[0].get_node_shared_ptr(); - testValues.expected.weights = as_type_ptr(convertedWeights); + testValues.expected.weights = ov::as_type_ptr(convertedWeights); } referenceFunction = ngraph::builder::subgraph::ConvolutionFunction::getReference( diff --git a/inference-engine/tests/functional/inference_engine/snippets/registers.cpp b/inference-engine/tests/functional/inference_engine/snippets/registers.cpp index 1058b5d78b3698..e76d8318f59164 100644 --- a/inference-engine/tests/functional/inference_engine/snippets/registers.cpp +++ b/inference-engine/tests/functional/inference_engine/snippets/registers.cpp @@ -52,7 +52,7 @@ TEST(TransformationTests, AssignRegisters) { auto& rt = op->get_rt_info(); if (auto rinfo = rt["reginfo"]) { - auto reginfo = as_type_ptr>>(rinfo)->get(); + auto reginfo = ov::as_type_ptr>>(rinfo)->get(); auto reg = reginfo[0]; ASSERT_TRUE(ref_registers[op->get_friendly_name()] == reg); total_ops++; @@ -126,7 +126,7 @@ TEST(TransformationTests, AssignRegisters2) { auto& rt = op->get_rt_info(); if (auto rinfo = rt["reginfo"]) { - auto reginfo = as_type_ptr>>(rinfo)->get(); + auto reginfo = ov::as_type_ptr>>(rinfo)->get(); auto reg = reginfo[0]; ASSERT_TRUE(ref_registers[op->get_friendly_name()] == reg); total_ops++; diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/builders.hpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/builders.hpp index 9a4e12d78ea664..cda84be9b22698 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/builders.hpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/builders.hpp @@ -55,7 +55,7 @@ std::shared_ptr makeElementwise(const std::shared_ptr data, ngraph::pass::low_precision::NetworkHelper::setOutDataPrecision(operation, description.outPrecision); } - if (is_type(operation) || is_type(operation)) { + if (ov::is_type(operation) || ov::is_type(operation)) { replace_node( operationConst, ngraph::pass::low_precision::fold(operationConst, data->get_output_element_type(0))); diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/add_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/add_function.cpp index 438af17ff92680..77c1bcac6fe374 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/add_function.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/add_function.cpp @@ -139,11 +139,11 @@ std::shared_ptr AddFunction::getOriginal( ngraph::ResultVector results {std::make_shared(output)}; ngraph::ParameterVector parameters; if (constInput == -1) { - parameters = { as_type_ptr(input1), as_type_ptr(input2) }; + parameters = { ov::as_type_ptr(input1), ov::as_type_ptr(input2) }; } else if (constInput == 0) { - parameters = { as_type_ptr(input2) }; + parameters = { ov::as_type_ptr(input2) }; } else if (constInput == 1) { - parameters = { as_type_ptr(input1) }; + parameters = { ov::as_type_ptr(input1) }; } else { throw std::runtime_error("Unexpected constant input index"); } @@ -226,7 +226,7 @@ std::shared_ptr AddFunction::getReference( auto dequantizationStructure1 = dequantization1; dequantizationStructure1.multiply.outPrecision = dequantizationAfter.empty() ? precision : element::f32; - const auto dequantizationOp1 = is_type(parent1) ? parent1 : makeDequantization(parent1, dequantizationStructure1); + const auto dequantizationOp1 = ov::is_type(parent1) ? parent1 : makeDequantization(parent1, dequantizationStructure1); std::shared_ptr input2; if (constInputIndex == 1) { @@ -292,7 +292,7 @@ std::shared_ptr AddFunction::getReference( auto dequantizationStructure2 = dequantization2; dequantizationStructure2.multiply.outPrecision = dequantizationAfter.empty() ? precision : element::f32; - const auto dequantizationOp2 = is_type(parent) ? parent : makeDequantization(parent, dequantizationStructure2); + const auto dequantizationOp2 = ov::is_type(parent) ? parent : makeDequantization(parent, dequantizationStructure2); const std::shared_ptr add = operationType == "Add" ? std::dynamic_pointer_cast(std::make_shared>( @@ -325,11 +325,11 @@ std::shared_ptr AddFunction::getReference( ngraph::ParameterVector parameters; if (constInputIndex == -1) { - parameters = { as_type_ptr(input1), as_type_ptr(input2) }; + parameters = { ov::as_type_ptr(input1), ov::as_type_ptr(input2) }; } else if (constInputIndex == 0) { - parameters = { as_type_ptr(input2) }; + parameters = { ov::as_type_ptr(input2) }; } else if (constInputIndex == 1) { - parameters = { as_type_ptr(input1) }; + parameters = { ov::as_type_ptr(input1) }; } else { throw std::runtime_error("Unexpected constant input index"); } diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/builders.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/builders.cpp index a387627bb0c0d1..c6153dffa2dbaf 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/builders.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/builders.cpp @@ -238,7 +238,7 @@ std::shared_ptr makeFakeQuantize( const Output& output, const ngraph::element::Type precision, const FakeQuantizeOnData& fqOnData) { - return as_type_ptr(ngraph::builder::makeFakeQuantize( + return ov::as_type_ptr(ngraph::builder::makeFakeQuantize( output, precision, fqOnData.quantizationLevel, diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/convolution_backprop_data_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/convolution_backprop_data_function.cpp index 2e841c399d9deb..b7462c602b6023 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/convolution_backprop_data_function.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/convolution_backprop_data_function.cpp @@ -82,7 +82,7 @@ std::shared_ptr ConvolutionBackpropDataFunction::getWeights( dequantizationStructure.subtract.constantPrecision = dequantizationOnWeights.subtract.constantPrecision; } if (weights->get_element_type().is_real()) { - weights = as_type_ptr(fold(weights, netPrecision)); + weights = ov::as_type_ptr(fold(weights, netPrecision)); } const auto dq = makeDequantization(weights, dequantizationStructure); diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/convolution_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/convolution_function.cpp index 886cfa2e6aad34..5c512508455438 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/convolution_function.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/convolution_function.cpp @@ -45,7 +45,7 @@ std::shared_ptr ConvolutionFunction::getOriginal( if (weights->cast_vector().size() == 1ul) { auto targetShape = ngraph::Shape{ outputChannelsCount, inputChannelsCount, 1, 1 }; - weights = as_type_ptr(fold( + weights = ov::as_type_ptr(fold( weights, op::Constant::create(ngraph::element::i64, Shape{ targetShape.size() }, targetShape))); } @@ -234,7 +234,7 @@ std::shared_ptr ConvolutionFunction::getReference( if (weights->cast_vector().size() == 1ul) { auto targetShape = ngraph::Shape{ outputChannelsCount, inputChannelsCount, 1, 1 }; - weights = as_type_ptr(fold( + weights = ov::as_type_ptr(fold( weights, op::Constant::create(ngraph::element::i64, Shape{ targetShape.size() }, targetShape))); } @@ -295,7 +295,7 @@ std::shared_ptr ConvolutionFunction::get( const auto input = std::make_shared(precision, ngraph::Shape(inputShape)); input->set_friendly_name("input"); - const std::shared_ptr fqOnData = as_type_ptr(ngraph::builder::makeFakeQuantize( + const std::shared_ptr fqOnData = ov::as_type_ptr(ngraph::builder::makeFakeQuantize( input, precision, fakeQuantizeOnData.quantizationLevel, diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/get_dequantization_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/get_dequantization_function.cpp index 1d5e452ac99a7b..aedc7bf842b9e6 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/get_dequantization_function.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/get_dequantization_function.cpp @@ -40,7 +40,7 @@ std::shared_ptr GetDequantizationFunction::get( return std::make_shared( ngraph::ResultVector{ std::make_shared(parent) }, - ngraph::ParameterVector{ as_type_ptr(input) }, + ngraph::ParameterVector{ ov::as_type_ptr(input) }, "DequantizationFunction"); } @@ -84,7 +84,7 @@ std::shared_ptr GetDequantizationFunction::get( return std::make_shared( ngraph::ResultVector{ std::make_shared(parent) }, - ngraph::ParameterVector{ as_type_ptr(input) }, + ngraph::ParameterVector{ ov::as_type_ptr(input) }, "DequantizationFunction"); } @@ -113,7 +113,7 @@ std::shared_ptr GetDequantizationFunction::getOriginal( return std::make_shared( ngraph::ResultVector{ std::make_shared(multiply) }, - ngraph::ParameterVector{ as_type_ptr(input) }, + ngraph::ParameterVector{ ov::as_type_ptr(input) }, "Dequantization"); } @@ -121,7 +121,7 @@ std::shared_ptr GetDequantizationFunction::getReference( ngraph::pass::low_precision::FakeQuantizeDequantization dequantization) { return std::make_shared( ngraph::ResultVector{ std::make_shared(dequantization.multiply) }, - ngraph::ParameterVector{ as_type_ptr(dequantization.data.get_node_shared_ptr()) }, + ngraph::ParameterVector{ ov::as_type_ptr(dequantization.data.get_node_shared_ptr()) }, "Dequantization"); } diff --git a/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ngraph_frontend/mock_mo_frontend.hpp b/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ngraph_frontend/mock_mo_frontend.hpp index 5293a72776e153..2e077e2f0e5f7d 100644 --- a/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ngraph_frontend/mock_mo_frontend.hpp +++ b/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ngraph_frontend/mock_mo_frontend.hpp @@ -425,9 +425,9 @@ class MOCK_API FrontEndMockPy : public FrontEnd private: InputModel::Ptr load_impl(const std::vector>& params) const override { - if (params.size() > 0 && is_type>(params[0])) + if (params.size() > 0 && ov::is_type>(params[0])) { - auto path = as_type_ptr>(params[0])->get(); + auto path = ov::as_type_ptr>(params[0])->get(); m_stat.m_load_paths.push_back(path); } return std::make_shared(); @@ -436,9 +436,9 @@ class MOCK_API FrontEndMockPy : public FrontEnd bool supported_impl(const std::vector>& params) const override { m_stat.m_supported++; - if (params.size() > 0 && is_type>(params[0])) + if (params.size() > 0 && ov::is_type>(params[0])) { - auto path = as_type_ptr>(params[0])->get(); + auto path = ov::as_type_ptr>(params[0])->get(); if (path.find(".test_mo_mock_mdl") != std::string::npos) { return true; diff --git a/ngraph/core/include/ngraph/pattern/matcher.hpp b/ngraph/core/include/ngraph/pattern/matcher.hpp index dce20cf27480e2..f361365bdcbae5 100644 --- a/ngraph/core/include/ngraph/pattern/matcher.hpp +++ b/ngraph/core/include/ngraph/pattern/matcher.hpp @@ -103,7 +103,7 @@ class NGRAPH_API Matcher { static std::shared_ptr unique_match(std::shared_ptr node) { std::shared_ptr matched; for (auto arg : node->input_values()) { - if (auto t_casted = as_type_ptr(arg.get_node_shared_ptr())) { + if (auto t_casted = ov::as_type_ptr(arg.get_node_shared_ptr())) { if (matched) { throw ngraph_error("There's more than two arguments of the same type"); } else { diff --git a/ngraph/core/include/ngraph/pattern/op/pattern.hpp b/ngraph/core/include/ngraph/pattern/op/pattern.hpp index 9ab0ae16d175e2..931c3d9e4e04f8 100644 --- a/ngraph/core/include/ngraph/pattern/op/pattern.hpp +++ b/ngraph/core/include/ngraph/pattern/op/pattern.hpp @@ -29,7 +29,7 @@ PatternValueMap as_pattern_value_map(const PatternMap& pattern_map); template std::function)> has_class() { auto pred = [](std::shared_ptr node) -> bool { - return is_type(node); + return ov::is_type(node); }; return pred; diff --git a/ngraph/core/include/ngraph/type.hpp b/ngraph/core/include/ngraph/type.hpp index 8971c77da9fc84..6980162a3f3565 100644 --- a/ngraph/core/include/ngraph/type.hpp +++ b/ngraph/core/include/ngraph/type.hpp @@ -4,62 +4,10 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include - -#include "ngraph/ngraph_visibility.hpp" +#include "openvino/core/type.hpp" namespace ngraph { -/// Supports three functions, is_type, as_type, and as_type_ptr for type-safe -/// dynamic conversions via static_cast/static_ptr_cast without using C++ RTTI. -/// Type must have a static type_info member and a virtual get_type_info() member that -/// returns a reference to its type_info member. - -/// Type information for a type system without inheritance; instances have exactly one type not -/// related to any other type. -struct NGRAPH_API DiscreteTypeInfo { - const char* name; - uint64_t version; - // A pointer to a parent type info; used for casting and inheritance traversal, not for - // exact type identification - const DiscreteTypeInfo* parent; - - DiscreteTypeInfo() = default; - - constexpr DiscreteTypeInfo(const char* _name, uint64_t _version, const DiscreteTypeInfo* _parent = nullptr) - : name(_name), - version(_version), - parent(_parent) {} - - bool is_castable(const DiscreteTypeInfo& target_type) const { - return *this == target_type || (parent && parent->is_castable(target_type)); - } - - // For use as a key - bool operator<(const DiscreteTypeInfo& b) const { - return version < b.version || (version == b.version && strcmp(name, b.name) < 0); - } - bool operator<=(const DiscreteTypeInfo& b) const { - return version < b.version || (version == b.version && strcmp(name, b.name) <= 0); - } - bool operator>(const DiscreteTypeInfo& b) const { - return version < b.version || (version == b.version && strcmp(name, b.name) > 0); - } - bool operator>=(const DiscreteTypeInfo& b) const { - return version < b.version || (version == b.version && strcmp(name, b.name) >= 0); - } - bool operator==(const DiscreteTypeInfo& b) const { - return version == b.version && strcmp(name, b.name) == 0; - } - bool operator!=(const DiscreteTypeInfo& b) const { - return version != b.version || strcmp(name, b.name) != 0; - } -}; +using ov::DiscreteTypeInfo; /// \brief Tests if value is a pointer/shared_ptr that can be statically cast to a /// Type*/shared_ptr @@ -68,7 +16,7 @@ typename std::enable_if< std::is_convertible()->get_type_info().is_castable(Type::type_info)), bool>::value, bool>::type is_type(Value value) { - return value->get_type_info().is_castable(Type::type_info); + return ov::is_type(value); } /// Casts a Value* to a Type* if it is of type Type, nullptr otherwise @@ -76,7 +24,7 @@ template typename std::enable_if(std::declval())), Type*>::value, Type*>::type as_type(Value value) { - return is_type(value) ? static_cast(value) : nullptr; + return ov::as_type(value); } /// Casts a std::shared_ptr to a std::shared_ptr if it is of type @@ -86,13 +34,6 @@ typename std::enable_if< std::is_convertible(std::declval())), std::shared_ptr>::value, std::shared_ptr>::type as_type_ptr(Value value) { - return is_type(value) ? std::static_pointer_cast(value) : std::shared_ptr(); + return ov::as_type_ptr(value); } } // namespace ngraph - -namespace std { -template <> -struct NGRAPH_API hash { - size_t operator()(const ngraph::DiscreteTypeInfo& k) const; -}; -} // namespace std diff --git a/ngraph/core/include/openvino/core/type.hpp b/ngraph/core/include/openvino/core/type.hpp new file mode 100644 index 00000000000000..78d1cc85e8ddd2 --- /dev/null +++ b/ngraph/core/include/openvino/core/type.hpp @@ -0,0 +1,98 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" + +namespace ov { +/// Supports three functions, ov::is_type, ov::as_type, and ov::as_type_ptr for type-safe +/// dynamic conversions via static_cast/static_ptr_cast without using C++ RTTI. +/// Type must have a static type_info member and a virtual get_type_info() member that +/// returns a reference to its type_info member. + +/// Type information for a type system without inheritance; instances have exactly one type not +/// related to any other type. +struct OPENVINO_API DiscreteTypeInfo { + const char* name; + uint64_t version; + // A pointer to a parent type info; used for casting and inheritance traversal, not for + // exact type identification + const DiscreteTypeInfo* parent; + + DiscreteTypeInfo() = default; + + constexpr DiscreteTypeInfo(const char* _name, uint64_t _version, const DiscreteTypeInfo* _parent = nullptr) + : name(_name), + version(_version), + parent(_parent) {} + + bool is_castable(const DiscreteTypeInfo& target_type) const { + return *this == target_type || (parent && parent->is_castable(target_type)); + } + + // For use as a key + bool operator<(const DiscreteTypeInfo& b) const { + return version < b.version || (version == b.version && strcmp(name, b.name) < 0); + } + bool operator<=(const DiscreteTypeInfo& b) const { + return version < b.version || (version == b.version && strcmp(name, b.name) <= 0); + } + bool operator>(const DiscreteTypeInfo& b) const { + return version < b.version || (version == b.version && strcmp(name, b.name) > 0); + } + bool operator>=(const DiscreteTypeInfo& b) const { + return version < b.version || (version == b.version && strcmp(name, b.name) >= 0); + } + bool operator==(const DiscreteTypeInfo& b) const { + return version == b.version && strcmp(name, b.name) == 0; + } + bool operator!=(const DiscreteTypeInfo& b) const { + return version != b.version || strcmp(name, b.name) != 0; + } +}; + +/// \brief Tests if value is a pointer/shared_ptr that can be statically cast to a +/// Type*/shared_ptr +template +typename std::enable_if< + std::is_convertible()->get_type_info().is_castable(Type::type_info)), bool>::value, + bool>::type +is_type(Value value) { + return value->get_type_info().is_castable(Type::type_info); +} + +/// Casts a Value* to a Type* if it is of type Type, nullptr otherwise +template +typename std::enable_if(std::declval())), Type*>::value, + Type*>::type +as_type(Value value) { + return ov::is_type(value) ? static_cast(value) : nullptr; +} + +/// Casts a std::shared_ptr to a std::shared_ptr if it is of type +/// Type, nullptr otherwise +template +typename std::enable_if< + std::is_convertible(std::declval())), std::shared_ptr>::value, + std::shared_ptr>::type +as_type_ptr(Value value) { + return ov::is_type(value) ? std::static_pointer_cast(value) : std::shared_ptr(); +} +} // namespace ov + +namespace std { +template <> +struct OPENVINO_API hash { + size_t operator()(const ov::DiscreteTypeInfo& k) const; +}; +} // namespace std diff --git a/ngraph/core/src/function.cpp b/ngraph/core/src/function.cpp index c3c3375b224aed..88de5c26743981 100644 --- a/ngraph/core/src/function.cpp +++ b/ngraph/core/src/function.cpp @@ -388,7 +388,7 @@ int64_t Function::get_parameter_index(const std::shared_ptr& para int64_t Function::get_result_index(const Output& value) const { int64_t pos = 0; - if (is_type(value.get_node_shared_ptr())) { + if (ov::is_type(value.get_node_shared_ptr())) { auto result = value.get_node_shared_ptr(); for (auto r : get_results()) { if (r == result) { diff --git a/ngraph/core/src/graph_util.cpp b/ngraph/core/src/graph_util.cpp index 81e24b087b91d2..f5bb89d84a0714 100644 --- a/ngraph/core/src/graph_util.cpp +++ b/ngraph/core/src/graph_util.cpp @@ -366,7 +366,7 @@ std::shared_ptr ngraph::clone_function(const ngraph::Function& // get cloned function results and sinks and parameters ResultVector cloned_results; for (shared_ptr node : func.get_results()) { - auto result = as_type_ptr(node_map.at(node.get())); + auto result = ov::as_type_ptr(node_map.at(node.get())); if (!result) { throw ngraph_error("Results should be of type op::Result"); } @@ -379,7 +379,7 @@ std::shared_ptr ngraph::clone_function(const ngraph::Function& std::vector> cloned_params; for (const auto& param : func.get_parameters()) { - cloned_params.push_back(as_type_ptr(node_map.at(param.get()))); + cloned_params.push_back(ov::as_type_ptr(node_map.at(param.get()))); } // create and return cloned function @@ -392,7 +392,7 @@ std::shared_ptr ngraph::clone_function(const ngraph::Function& } bool ngraph::is_equal_to_const_value(const std::string& const_value, const Output& reduce_constant) { - if (auto rc = as_type_ptr(reduce_constant.get_node_shared_ptr())) { + if (auto rc = ov::as_type_ptr(reduce_constant.get_node_shared_ptr())) { return (rc->get_all_data_elements_bitwise_identical() && rc->convert_value_to_string(0) == const_value); } else { return false; @@ -777,17 +777,17 @@ bool ngraph::check_for_cycles(const ngraph::Function* func, ngraph::NodeVector& bool ngraph::replace_output_update_name(Output output, const Output& replacement) { bool has_result_output = false; for (auto& target_input : output.get_target_inputs()) { - if (is_type(target_input.get_node())) { + if (ov::is_type(target_input.get_node())) { // ignore trivial elimination has_result_output = true; - if (is_type(replacement.get_node())) { + if (ov::is_type(replacement.get_node())) { return false; } break; } } if (!has_result_output || replacement.get_node()->get_users().size() == 1) { - if (has_result_output && !is_type(replacement.get_node())) { + if (has_result_output && !ov::is_type(replacement.get_node())) { replacement.get_node()->set_friendly_name(output.get_node()->get_friendly_name()); // Update output tensor name replacement.get_tensor().set_name(output.get_node()->get_friendly_name()); @@ -810,8 +810,8 @@ bool ngraph::replace_output_update_name(Output output, const Output& bool ngraph::replace_node_update_name(std::shared_ptr target, std::shared_ptr replacement) { for (auto& output : target->output(0).get_target_inputs()) { - if (as_type(replacement->input_value(0).get_node()) && - as_type(output.get_node())) { + if (ov::as_type(replacement->input_value(0).get_node()) && + ov::as_type(output.get_node())) { return false; } } diff --git a/ngraph/core/src/node.cpp b/ngraph/core/src/node.cpp index cbc1c9611dfdfc..87524021306f78 100644 --- a/ngraph/core/src/node.cpp +++ b/ngraph/core/src/node.cpp @@ -632,7 +632,8 @@ ResultVector ngraph::as_result_vector(const OutputVector& values) { ResultVector result; for (auto value : values) { shared_ptr node = value.get_node_shared_ptr(); - result.push_back(is_type(node) ? as_type_ptr(node) : make_shared(value)); + result.push_back(ov::is_type(node) ? ov::as_type_ptr(node) + : make_shared(value)); } return result; } @@ -808,14 +809,15 @@ bool Node::constant_fold(OutputVector& output_values, const OutputVector& input_ // If all the inputs are constants, try to evaluate the outputs bool all_constants = std::all_of(input_values.begin(), input_values.end(), [](const Output& input) { - return as_type_ptr(input.get_node_shared_ptr()); + return ov::as_type_ptr(input.get_node_shared_ptr()); }); if (!all_constants) return false; HostTensorVector input_tensors; for (const auto& input : input_values) { - auto host_tensor = make_shared(as_type_ptr(input.get_node_shared_ptr())); + auto host_tensor = + make_shared(ov::as_type_ptr(input.get_node_shared_ptr())); input_tensors.push_back(host_tensor); } HostTensorVector output_tensors; diff --git a/ngraph/core/src/op/assign.cpp b/ngraph/core/src/op/assign.cpp index 5ec8f6e9b4fe9f..3476abd5d877cb 100644 --- a/ngraph/core/src/op/assign.cpp +++ b/ngraph/core/src/op/assign.cpp @@ -35,7 +35,7 @@ void op::v3::Assign::validate_and_infer_types() { } auto nodes = topological_sort(start_nodes); for (const auto& node : nodes) { - if (auto read_value = as_type_ptr(node)) { + if (auto read_value = ov::as_type_ptr(node)) { if (read_value->get_variable_id() == m_variable_id) m_variable = read_value->get_variable(); } @@ -132,4 +132,4 @@ bool op::v6::Assign::has_evaluate() const { bool op::v6::Assign::constant_fold(OutputVector& output_values, const OutputVector& inputs_values) { return false; -} \ No newline at end of file +} diff --git a/ngraph/core/src/op/loop.cpp b/ngraph/core/src/op/loop.cpp index 1b9648adbb7f72..ededa0bb74ecc1 100644 --- a/ngraph/core/src/op/loop.cpp +++ b/ngraph/core/src/op/loop.cpp @@ -156,7 +156,7 @@ void op::v5::Loop::validate_and_infer_types() { for (const auto& input_description : m_input_descriptions[0]) { auto index = input_description->m_input_index; - if (auto slice_input_description = as_type_ptr(input_description)) { + if (auto slice_input_description = ov::as_type_ptr(input_description)) { auto body_parameter = m_bodies[0]->get_parameters().at(slice_input_description->m_body_parameter_index); const auto& input_partial_shape = inputs().at(index).get_source_output().get_partial_shape(); if (input_partial_shape.rank().is_dynamic()) { @@ -168,7 +168,7 @@ void op::v5::Loop::validate_and_infer_types() { out_shape[axis] = slice_input_description->m_part_size; body_parameter->set_partial_shape(out_shape); } - } else if (auto merged_input_description = as_type_ptr(input_description)) { + } else if (auto merged_input_description = ov::as_type_ptr(input_description)) { auto body_value = m_bodies[0]->get_results().at(merged_input_description->m_body_value_index); auto body_parameter = m_bodies[0]->get_parameters().at(merged_input_description->m_body_parameter_index); @@ -178,7 +178,7 @@ void op::v5::Loop::validate_and_infer_types() { body_parameter->set_partial_shape(input_partial_shape); } else if (auto invariant_input_description = - as_type_ptr(input_description)) { + ov::as_type_ptr(input_description)) { auto body_parameter = m_bodies[0]->get_parameters().at(invariant_input_description->m_body_parameter_index); auto body_param_partial_shape = body_parameter->get_partial_shape(); @@ -197,7 +197,8 @@ void op::v5::Loop::validate_and_infer_types() { auto body_value = m_bodies[0]->get_results().at(output_description->m_body_value_index)->input_value(0); - if (auto concat_output_description = as_type_ptr(output_description)) { + if (auto concat_output_description = + ov::as_type_ptr(output_description)) { const auto& body_value_partial_shape = body_value.get_partial_shape(); auto out_shape = body_value_partial_shape; if (zero_number_of_iter) { @@ -219,7 +220,7 @@ void op::v5::Loop::validate_and_infer_types() { } else if (auto body_output_description = - as_type_ptr(output_description)) { + ov::as_type_ptr(output_description)) { const PartialShape& ps = body_value.get_partial_shape(); if (ps.is_dynamic()) { set_output_type(index, body_value.get_element_type(), ps); diff --git a/ngraph/core/src/op/non_max_suppression.cpp b/ngraph/core/src/op/non_max_suppression.cpp index cfc7d4a9b0a65d..4a02e7e6addda4 100644 --- a/ngraph/core/src/op/non_max_suppression.cpp +++ b/ngraph/core/src/op/non_max_suppression.cpp @@ -772,7 +772,7 @@ bool op::v5::NonMaxSuppression::is_soft_nms_sigma_constant_and_default() const { if (inputs().size() < 6 || !ngraph::op::is_constant(soft_nms_sigma_node)) { return false; } - const auto soft_nms_sigma_input = as_type_ptr(soft_nms_sigma_node); + const auto soft_nms_sigma_input = ov::as_type_ptr(soft_nms_sigma_node); return soft_nms_sigma_input->cast_vector().at(0) == 0.0f; } diff --git a/ngraph/core/src/op/parameter.cpp b/ngraph/core/src/op/parameter.cpp index ae239639a94015..1c3d32ed8fbea9 100644 --- a/ngraph/core/src/op/parameter.cpp +++ b/ngraph/core/src/op/parameter.cpp @@ -68,7 +68,7 @@ bool AttributeAdapter::visit_attributes(AttributeVisitor& visit } visitor.on_attribute(index.str(), id); if (!m_ref[i]) { - m_ref[i] = as_type_ptr(visitor.get_registered_node(id)); + m_ref[i] = ov::as_type_ptr(visitor.get_registered_node(id)); } } return true; diff --git a/ngraph/core/src/op/result.cpp b/ngraph/core/src/op/result.cpp index 9ec4b07129e67f..db23b6adbd2399 100644 --- a/ngraph/core/src/op/result.cpp +++ b/ngraph/core/src/op/result.cpp @@ -82,7 +82,7 @@ bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) } visitor.on_attribute(index.str(), id); if (!m_ref[i]) { - m_ref[i] = as_type_ptr(visitor.get_registered_node(id)); + m_ref[i] = ov::as_type_ptr(visitor.get_registered_node(id)); } } return true; diff --git a/ngraph/core/src/op/tensor_iterator.cpp b/ngraph/core/src/op/tensor_iterator.cpp index 16f41726fafd9f..9669769b8bcd4b 100644 --- a/ngraph/core/src/op/tensor_iterator.cpp +++ b/ngraph/core/src/op/tensor_iterator.cpp @@ -35,7 +35,7 @@ void op::v0::TensorIterator::revalidate_and_infer_types_for_body_ops() { while (nodes_to_do.size() > 0) { auto node = nodes_to_do.top(); if (nodes_done.count(node) == 0) { - NGRAPH_CHECK(as_type_ptr(node) == nullptr, "No nested TensorIterator"); + NGRAPH_CHECK(ov::as_type_ptr(node) == nullptr, "No nested TensorIterator"); bool can_add = true; size_t arg_count = node->get_input_size(); for (size_t i = 0; i < arg_count; ++i) { @@ -84,7 +84,7 @@ void op::v0::TensorIterator::validate_and_infer_types() { for (const auto& input_description : m_input_descriptions[0]) { auto index = input_description->m_input_index; - if (auto slice_input_description = as_type_ptr(input_description)) { + if (auto slice_input_description = ov::as_type_ptr(input_description)) { auto body_parameter = body->get_parameters().at(slice_input_description->m_body_parameter_index); auto input_partial_shape = inputs().at(index).get_source_output().get_partial_shape(); if (input_partial_shape.is_static()) { @@ -105,7 +105,7 @@ void op::v0::TensorIterator::validate_and_infer_types() { } else { body_parameter->set_partial_shape(PartialShape::dynamic(input_partial_shape.rank())); } - } else if (auto merged_input_description = as_type_ptr(input_description)) { + } else if (auto merged_input_description = ov::as_type_ptr(input_description)) { auto body_value = m_bodies[0]->get_results().at(merged_input_description->m_body_value_index)->input(0); ends.push_back(body_value.get_node()->shared_from_this()); @@ -114,7 +114,7 @@ void op::v0::TensorIterator::validate_and_infer_types() { auto body_param_partial_shape = body_parameter->get_partial_shape(); auto input_partial_shape = inputs().at(index).get_source_output().get_partial_shape(); body_parameter->set_partial_shape(input_partial_shape); - } else if (auto invariant_input_description = as_type_ptr(input_description)) { + } else if (auto invariant_input_description = ov::as_type_ptr(input_description)) { auto body_parameter = m_bodies[0]->get_parameters().at(invariant_input_description->m_body_parameter_index); auto body_param_partial_shape = body_parameter->get_partial_shape(); @@ -134,7 +134,7 @@ void op::v0::TensorIterator::validate_and_infer_types() { auto body_value = m_bodies[0]->get_results().at(output_description->m_body_value_index)->input_value(0); - if (auto concat_output_description = as_type_ptr(output_description)) { + if (auto concat_output_description = ov::as_type_ptr(output_description)) { auto body_value_partial_shape = body_value.get_partial_shape(); set_output_type(index, body_value.get_element_type(), PartialShape::dynamic()); if (body_value_partial_shape.is_static()) { @@ -164,7 +164,7 @@ void op::v0::TensorIterator::validate_and_infer_types() { body_value.get_element_type(), PartialShape::dynamic(body_value.get_partial_shape().rank())); } - } else if (auto body_output_description = as_type_ptr(output_description)) { + } else if (auto body_output_description = ov::as_type_ptr(output_description)) { set_output_type(index, body_value.get_element_type(), body_value.get_partial_shape()); } } @@ -178,7 +178,7 @@ namespace { template bool has_slice_input_desc(const Desc& desc) { const auto is_slice_input_desc = +[](typename Desc::const_reference d) { - return is_type(d); + return ov::is_type(d); }; return std::any_of(begin(desc), end(desc), is_slice_input_desc); } @@ -190,7 +190,7 @@ void op::v0::TensorIterator::try_to_set_num_iterations_if_no_slice_inputs() { } for (const auto& output_description : m_output_descriptions[0]) { - if (auto concat = as_type_ptr(output_description)) { + if (auto concat = ov::as_type_ptr(output_description)) { m_num_iterations = ((std::abs(concat->m_end - concat->m_start)) / concat->m_part_size); break; } diff --git a/ngraph/core/src/op/topk.cpp b/ngraph/core/src/op/topk.cpp index a4ee8004da6418..e11457eca43df5 100644 --- a/ngraph/core/src/op/topk.cpp +++ b/ngraph/core/src/op/topk.cpp @@ -281,7 +281,7 @@ size_t op::v1::TopK::read_k_from_constant_node(const shared_ptr& node, k_element_type, ")."); - const auto k_constant = as_type_ptr(node); + const auto k_constant = ov::as_type_ptr(node); size_t k = 0; @@ -471,7 +471,7 @@ void op::v3::TopK::validate_and_infer_types() { size_t op::v3::TopK::read_k_from_constant_node(const shared_ptr& node, const element::Type& k_element_type) const { - const auto k_constant = as_type_ptr(node); + const auto k_constant = ov::as_type_ptr(node); size_t k = 0; diff --git a/ngraph/core/src/op/util/arithmetic_reduction.cpp b/ngraph/core/src/op/util/arithmetic_reduction.cpp index 66fd64912c212b..40b151039906da 100644 --- a/ngraph/core/src/op/util/arithmetic_reduction.cpp +++ b/ngraph/core/src/op/util/arithmetic_reduction.cpp @@ -19,7 +19,7 @@ op::util::ArithmeticReduction::ArithmeticReduction(const Output& arg, cons : ReductionBase(arg, reduction_axes) {} bool op::util::ArithmeticReduction::reduction_axes_constant() const { - return is_type(input_value(1).get_node()); + return ov::is_type(input_value(1).get_node()); } const AxisSet op::util::ArithmeticReduction::get_reduction_axes() const { diff --git a/ngraph/core/src/op/util/broadcast_base.cpp b/ngraph/core/src/op/util/broadcast_base.cpp index 476882b59c17eb..11d088e0bc0767 100644 --- a/ngraph/core/src/op/util/broadcast_base.cpp +++ b/ngraph/core/src/op/util/broadcast_base.cpp @@ -193,7 +193,7 @@ void op::util::BroadcastBase::validate_and_infer_types() { PartialShape output_shape; bool output_shape_defined = evaluate_as_partial_shape(get_input_source_output(1), output_shape); - if (auto concat = as_type_ptr(input_value(1).get_node_shared_ptr())) { + if (auto concat = ov::as_type_ptr(input_value(1).get_node_shared_ptr())) { auto concat_inputs = concat->inputs(); if (!output_shape_defined && concat->get_output_partial_shape(0).is_static() && @@ -201,7 +201,7 @@ void op::util::BroadcastBase::validate_and_infer_types() { auto output_partial_shape = vector{}; for (const auto& concat_input : concat_inputs) { auto source_node_ptr = concat_input.get_source_output().get_node_shared_ptr(); - if (auto source_const_ptr = as_type_ptr(source_node_ptr)) { + if (auto source_const_ptr = ov::as_type_ptr(source_node_ptr)) { output_partial_shape.push_back(source_const_ptr->get_axis_vector_val()[0]); } else { output_partial_shape.push_back(Dimension::dynamic()); @@ -428,7 +428,7 @@ bool op::util::BroadcastBase::evaluate_broadcast(const HostTensorPtr& arg0, Shape op::util::BroadcastBase::get_target_shape(const HostTensorPtr& input1) const { Shape target_shape; - const auto shape_constant = as_type_ptr(input_value(1).get_node_shared_ptr()); + const auto shape_constant = ov::as_type_ptr(input_value(1).get_node_shared_ptr()); if (shape_constant) { target_shape = shape_constant->get_shape_val(); } else { @@ -450,7 +450,7 @@ bool op::util::BroadcastBase::evaluate(const HostTensorVector& outputs, const Ho if (m_mode.m_type == BroadcastType::NONE) { AxisVector axes_mapping_val; - const auto axes_mapping_constant = as_type_ptr(input_value(2).get_node_shared_ptr()); + const auto axes_mapping_constant = ov::as_type_ptr(input_value(2).get_node_shared_ptr()); if (axes_mapping_constant) { axes_mapping_val = axes_mapping_constant->get_axis_vector_val(); } else { diff --git a/ngraph/core/src/op/util/fft_base.cpp b/ngraph/core/src/op/util/fft_base.cpp index cc02453f25c7dc..e1cc47e8d01fe1 100644 --- a/ngraph/core/src/op/util/fft_base.cpp +++ b/ngraph/core/src/op/util/fft_base.cpp @@ -73,7 +73,7 @@ void op::util::FFTBase::validate() { axes_shape.to_shape()[0]); } - if (input_shape.rank().is_static() && is_type(input_value(1).get_node())) { + if (input_shape.rank().is_static() && ov::is_type(input_value(1).get_node())) { const auto input_rank = input_shape.rank().get_length(); const auto& const_axes = get_constant_from_source(input_value(1)); auto axes = const_axes->cast_vector(); @@ -146,7 +146,7 @@ void op::util::FFTBase::validate_and_infer_types() { const auto input_rank = input_shape.rank().get_length(); - if (axes_shape.rank().is_dynamic() || !is_type(input_value(1).get_node())) { + if (axes_shape.rank().is_dynamic() || !ov::is_type(input_value(1).get_node())) { for (int64_t i = 0; i < input_rank - 1; ++i) { output_shape[i] = Dimension::dynamic(); } @@ -179,7 +179,7 @@ void op::util::FFTBase::validate_and_infer_types() { } } - if (!is_type(input_value(2).get_node())) { + if (!ov::is_type(input_value(2).get_node())) { for (int64_t axis : axes) { output_shape[axis] = Dimension::dynamic(); } diff --git a/ngraph/core/src/pass/constant_folding.cpp b/ngraph/core/src/pass/constant_folding.cpp index 311cb121269dd3..f9818321d1f591 100644 --- a/ngraph/core/src/pass/constant_folding.cpp +++ b/ngraph/core/src/pass/constant_folding.cpp @@ -79,7 +79,7 @@ bool ngraph::pass::ConstantFolding::pre_calculated_values_folding(const std::sha while (!nodes.empty()) { auto curr_node = nodes.front(); nodes.pop_front(); - if (visited.count(curr_node) || is_type(curr_node)) + if (visited.count(curr_node) || ov::is_type(curr_node)) continue; visited.insert(curr_node); @@ -100,7 +100,7 @@ bool ngraph::pass::ConstantFolding::pre_calculated_values_folding(const std::sha if (status && input_value.get_tensor().has_and_set_bound()) { auto input_node = input_value.get_node_shared_ptr(); auto replacement = std::make_shared(input_value.get_tensor().get_lower_value()); - if (replacement && !is_type(input_node)) { + if (replacement && !ov::is_type(input_node)) { if (input_node->get_output_size() == 1) { replacement->set_friendly_name(input_node->get_friendly_name()); } else { diff --git a/ngraph/core/src/pass/convert_precision.cpp b/ngraph/core/src/pass/convert_precision.cpp index a638aef5152d0f..6f8c0997b913d6 100644 --- a/ngraph/core/src/pass/convert_precision.cpp +++ b/ngraph/core/src/pass/convert_precision.cpp @@ -293,7 +293,7 @@ bool ngraph::pass::ConvertPrecision::run_on_function(std::shared_ptr& node, element::Type to, size_t idx) { - if (auto shapeof = as_type_ptr(node)) { + if (auto shapeof = ov::as_type_ptr(node)) { if (to == element::i32 || to == element::i64) { shapeof->set_output_type(to); return true; @@ -303,7 +303,7 @@ bool fuse_type_to_shapeof(const std::shared_ptr& node, element::Ty } bool fuse_type_to_range_v4(const std::shared_ptr& node, element::Type to, size_t idx) { - if (auto range = as_type_ptr(node)) { + if (auto range = ov::as_type_ptr(node)) { if (to.is_integral_number() || to.is_real()) { range->set_output_type(to); return true; @@ -313,7 +313,7 @@ bool fuse_type_to_range_v4(const std::shared_ptr& node, element::T } bool fuse_type_to_parameter(const std::shared_ptr& node, element::Type to, size_t idx) { - if (auto param = as_type_ptr(node)) { + if (auto param = ov::as_type_ptr(node)) { param->set_element_type(to); param->validate_and_infer_types(); return true; @@ -322,7 +322,7 @@ bool fuse_type_to_parameter(const std::shared_ptr& node, element:: } bool fuse_type_to_convert(const std::shared_ptr& node, element::Type to, size_t idx) { - if (auto convert = as_type_ptr(node)) { + if (auto convert = ov::as_type_ptr(node)) { convert->set_convert_element_type(to); return true; } @@ -330,7 +330,7 @@ bool fuse_type_to_convert(const std::shared_ptr& node, element::Ty } bool fuse_type_to_nms3(const std::shared_ptr& node, ngraph::element::Type to, size_t idx) { - if (auto nms = as_type_ptr(node)) { + if (auto nms = ov::as_type_ptr(node)) { nms->set_output_type(to); return true; } @@ -338,7 +338,7 @@ bool fuse_type_to_nms3(const std::shared_ptr& node, ngraph::elemen } bool fuse_type_to_nms4(const std::shared_ptr& node, ngraph::element::Type to, size_t idx) { - if (auto nms = as_type_ptr(node)) { + if (auto nms = ov::as_type_ptr(node)) { nms->set_output_type(to); return true; } @@ -346,7 +346,7 @@ bool fuse_type_to_nms4(const std::shared_ptr& node, ngraph::elemen } bool fuse_type_to_nms5(const std::shared_ptr& node, ngraph::element::Type to, size_t idx) { - if (auto nms = as_type_ptr(node)) { + if (auto nms = ov::as_type_ptr(node)) { nms->set_output_type(to); return true; } @@ -354,7 +354,7 @@ bool fuse_type_to_nms5(const std::shared_ptr& node, ngraph::elemen } bool fuse_type_to_topk(const std::shared_ptr& node, ngraph::element::Type to, size_t idx) { - if (auto topk = as_type_ptr(node)) { + if (auto topk = ov::as_type_ptr(node)) { if (idx == 1 && (to == element::i32 || to == element::i64)) { topk->set_index_element_type(to); return true; @@ -366,7 +366,7 @@ bool fuse_type_to_topk(const std::shared_ptr& node, ngraph::elemen bool fuse_type_to_ctc_greedy_decoder_seq_len(const std::shared_ptr& node, ngraph::element::Type to, size_t idx) { - if (auto ctc_decoder = as_type_ptr(node)) { + if (auto ctc_decoder = ov::as_type_ptr(node)) { if (idx == 0 && (to == element::i32 || to == element::i64)) { ctc_decoder->set_classes_index_type(to); return true; @@ -380,7 +380,7 @@ bool fuse_type_to_ctc_greedy_decoder_seq_len(const std::shared_ptr } bool fuse_type_to_nonzero(const std::shared_ptr& node, ngraph::element::Type to, size_t idx) { - if (auto nonzero = as_type_ptr(node)) { + if (auto nonzero = ov::as_type_ptr(node)) { if (to == element::i32 || to == element::i64) { nonzero->set_output_type(to); return true; @@ -390,7 +390,7 @@ bool fuse_type_to_nonzero(const std::shared_ptr& node, ngraph::ele } bool fuse_type_to_bucketize(const std::shared_ptr& node, ngraph::element::Type to, size_t idx) { - if (auto b = as_type_ptr(node)) { + if (auto b = ov::as_type_ptr(node)) { if (to == element::i32 || to == element::i64) { b->set_output_type(to); return true; @@ -682,7 +682,7 @@ std::shared_ptr convert_low_precisions_int(std::shared_ptr& node, element::Type to, const std::vector>& consumers) { - if (auto constant = as_type_ptr(node)) { + if (auto constant = ov::as_type_ptr(node)) { auto from = constant->get_element_type(); std::shared_ptr new_const; if (from == element::u64 && to == element::i32) { diff --git a/ngraph/core/src/pass/visualize_tree.cpp b/ngraph/core/src/pass/visualize_tree.cpp index ae0f30ba2d1b5d..1c1040eb21e588 100644 --- a/ngraph/core/src/pass/visualize_tree.cpp +++ b/ngraph/core/src/pass/visualize_tree.cpp @@ -227,7 +227,7 @@ void pass::VisualizeTree::add_node_arguments(shared_ptr node, for (auto input_value : node->input_values()) { auto arg = input_value.get_node_shared_ptr(); size_t jump_distance = height_maps[arg.get()].max_jump_to(height_maps[node.get()]); - if (is_type(arg) || is_type(arg)) { + if (ov::is_type(arg) || ov::is_type(arg)) { auto clone_name = "CLONE_" + to_string(fake_node_ctr); auto color = string("color=\"") + (arg->description() == "Parameter" ? "blue" : "black") + string("\""); std::vector attributes{"shape=\"box\"", @@ -383,7 +383,7 @@ std::string pass::VisualizeTree::get_constant_value(std::shared_ptr node, return ss.str(); ss << "\nvalue: "; - const auto constant = as_type_ptr(node); + const auto constant = ov::as_type_ptr(node); switch (constant->get_output_element_type(0)) { case element::Type_t::undefined: ss << "[ undefined value ]"; diff --git a/ngraph/core/src/specialize_function.cpp b/ngraph/core/src/specialize_function.cpp index 418b3434129649..3a01a3de00d364 100644 --- a/ngraph/core/src/specialize_function.cpp +++ b/ngraph/core/src/specialize_function.cpp @@ -72,7 +72,7 @@ std::shared_ptr ngraph::specialize_function(std::shared_ptr ParameterVector new_parameters = f->get_parameters(); for (size_t i = 0; i < new_parameters.size(); i++) { auto name = new_parameters[i]->get_friendly_name(); - new_parameters[i] = as_type_ptr(m[new_parameters[i].get()]); + new_parameters[i] = ov::as_type_ptr(m[new_parameters[i].get()]); // If the replacement for a Parameter is not itself a Parameter, we must have replaced it // with a constant. We will insert a dead Parameter into the clone's parameters, in order diff --git a/ngraph/core/src/validation_util.cpp b/ngraph/core/src/validation_util.cpp index 70741cf84cfb7f..c5585e870137ef 100644 --- a/ngraph/core/src/validation_util.cpp +++ b/ngraph/core/src/validation_util.cpp @@ -966,7 +966,7 @@ struct MaxValue { vector exec_constant(Node* node, vector& inputs) { auto result = MaxValue(); - auto op = as_type(node); + auto op = ov::as_type(node); auto element_type = op->get_output_element_type(0); if (element_type.is_integral()) { uint64_t max_val = 0; @@ -1024,7 +1024,7 @@ vector exec_minimum(Node* node, vector& inputs) { } vector exec_concat(Node* node, vector& inputs) { - auto op = as_type(node); + auto op = ov::as_type(node); vector slice_maxen; for (auto input : inputs) { slice_maxen.push_back(input.m_value); @@ -1036,7 +1036,7 @@ vector exec_concat(Node* node, vector& inputs) { vector exec_reduce_min(Node* node, vector& inputs) { auto data = inputs.at(0); if (data.m_slice_axis >= 0 && data.m_slices.size() > 1) { - if (auto indices_const = as_type(node->get_input_node_ptr(1))) { + if (auto indices_const = ov::as_type(node->get_input_node_ptr(1))) { if (indices_const->get_output_element_type(0).is_integral()) { auto indices_shape = indices_const->get_output_shape(0); if (indices_shape == Shape{1}) { @@ -1068,10 +1068,10 @@ vector exec_shape_of(Node* node, vector& inputs) { } vector exec_gather(Node* node, vector& inputs) { - auto gather = as_type(node); + auto gather = ov::as_type(node); - const auto& indices = as_type_ptr(node->input_value(1).get_node_shared_ptr()); - const auto& axis = as_type_ptr(node->input_value(2).get_node_shared_ptr()); + const auto& indices = ov::as_type_ptr(node->input_value(1).get_node_shared_ptr()); + const auto& axis = ov::as_type_ptr(node->input_value(2).get_node_shared_ptr()); if (!indices || !axis) { return {MaxValue()}; @@ -1150,9 +1150,9 @@ bool ngraph::could_propagate(const Output& output, std::vector& ord auto current_node = nodes_to_calculate.front(); nodes_to_calculate.pop_front(); - if (current_node->inputs().empty() && !is_type(current_node)) + if (current_node->inputs().empty() && !ov::is_type(current_node)) status = false; - else if (!is_type(current_node) && !is_type(current_node)) { + else if (!ov::is_type(current_node) && !ov::is_type(current_node)) { // not a leaf, not a shape_of -- continue to search for (const auto& input_value : current_node->input_values()) { const auto& input_node = input_value.get_node(); @@ -1482,7 +1482,7 @@ bool ngraph::host_tensor_is_positive(const HostTensorPtr& bound) { const auto axes = op::Constant::create(element::i64, {axes_vector.size()}, axes_vector); OutputVector all(1); folded = std::make_shared(greater[0], axes)->constant_fold(all, {greater[0], axes}); - NGRAPH_CHECK(folded && is_type(all[0].get_node_shared_ptr())); + NGRAPH_CHECK(folded && ov::is_type(all[0].get_node_shared_ptr())); const auto result = std::dynamic_pointer_cast(all[0].get_node_shared_ptr())->cast_vector(); NGRAPH_CHECK(all[0].get_shape() == Shape{}); return result[0]; @@ -1499,7 +1499,7 @@ bool ngraph::has_and_set_equal_bounds(const Output& source) { shared_ptr ngraph::get_constant_from_source(const Output& source) { if (!has_and_set_equal_bounds(source)) return nullptr; - if (const auto& c = as_type_ptr(source.get_node_shared_ptr())) + if (const auto& c = ov::as_type_ptr(source.get_node_shared_ptr())) return c; return std::make_shared(source.get_tensor().get_upper_value()); } diff --git a/ngraph/frontend/onnx/frontend/src/frontend.cpp b/ngraph/frontend/onnx/frontend/src/frontend.cpp index e433aa44e60d56..8ec3fdf952555c 100644 --- a/ngraph/frontend/onnx/frontend/src/frontend.cpp +++ b/ngraph/frontend/onnx/frontend/src/frontend.cpp @@ -28,9 +28,9 @@ extern "C" ONNX_FRONTEND_API void* GetFrontEndData() { InputModel::Ptr FrontEndONNX::load_impl(const std::vector>& variants) const { NGRAPH_CHECK(variants.size() == 1, "Only one parameter to load function is expected. Got " + std::to_string(variants.size())); - NGRAPH_CHECK(is_type>(variants[0]), + NGRAPH_CHECK(ov::is_type>(variants[0]), "Parameter to load function need to be a std::string"); - auto path = as_type_ptr>(variants[0])->get(); + auto path = ov::as_type_ptr>(variants[0])->get(); return std::make_shared(path); } diff --git a/ngraph/frontend/onnx/frontend/src/op/dropout.cpp b/ngraph/frontend/onnx/frontend/src/op/dropout.cpp index 259d32f5739d35..71c10d0ca89c44 100644 --- a/ngraph/frontend/onnx/frontend/src/op/dropout.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/dropout.cpp @@ -44,7 +44,7 @@ OutputVector dropout(const Node& node) { ngraph::op::is_constant(ng_inputs.at(2).get_node_shared_ptr()), "Non-constant training_mode input is not supported."); training_mode = - as_type_ptr(ng_inputs.at(2).get_node_shared_ptr())->cast_vector()[0]; + ov::as_type_ptr(ng_inputs.at(2).get_node_shared_ptr())->cast_vector()[0]; } return build_dropout(node, training_mode); } diff --git a/ngraph/frontend/onnx/frontend/src/op/loop.cpp b/ngraph/frontend/onnx/frontend/src/op/loop.cpp index 5001b64e8f3e25..430fb85b0853e5 100644 --- a/ngraph/frontend/onnx/frontend/src/op/loop.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/loop.cpp @@ -38,10 +38,10 @@ bool is_termination_condition_always_true(const Output& body_out_c // value of loop_cond - true // Identity op for boolean value is represented by LogicalOr op whose second // input is always false - if (is_type(body_out_cond.get_node_shared_ptr())) { + if (ov::is_type(body_out_cond.get_node_shared_ptr())) { const auto second_input = body_out_cond.get_node_shared_ptr()->input_value(1).get_node_shared_ptr(); if (ngraph::op::is_constant(second_input) && second_input->get_element_type() == element::boolean && - as_type_ptr(second_input)->cast_vector().at(0) == false) { + ov::as_type_ptr(second_input)->cast_vector().at(0) == false) { return true; } } @@ -74,7 +74,7 @@ OutputVector loop(const Node& node) { // trip count skipped or has value max(int64_t) means infinitive loop if (ngraph::op::is_null(ng_inputs.at(0)) || (ngraph::op::is_constant(ng_inputs.at(0).get_node_shared_ptr()) && - as_type_ptr(ng_inputs.at(0).get_node_shared_ptr())->cast_vector()[0] == + ov::as_type_ptr(ng_inputs.at(0).get_node_shared_ptr())->cast_vector()[0] == std::numeric_limits::max())) { // -1 means infinite Loop trip_count = ngraph::op::Constant::create(ngraph::element::i64, {1}, {-1}); @@ -87,8 +87,8 @@ OutputVector loop(const Node& node) { { termination_cond = ngraph::op::Constant::create(ngraph::element::boolean, {1}, {true}); } else if (ngraph::op::is_constant(ng_inputs.at(1).get_node_shared_ptr()) && - as_type_ptr(ng_inputs.at(1).get_node_shared_ptr())->cast_vector()[0] == - false) { + ov::as_type_ptr(ng_inputs.at(1).get_node_shared_ptr()) + ->cast_vector()[0] == false) { // no iteration is performed so initial values are returned OutputVector node_outputs; // final values diff --git a/ngraph/frontend/paddlepaddle/src/frontend.cpp b/ngraph/frontend/paddlepaddle/src/frontend.cpp index 2cd3e2a210a58d..0ef30903455b61 100644 --- a/ngraph/frontend/paddlepaddle/src/frontend.cpp +++ b/ngraph/frontend/paddlepaddle/src/frontend.cpp @@ -109,15 +109,15 @@ bool normalize_framework_node(const std::shared_ptr& node, } std::istream* variant_to_stream_ptr(const std::shared_ptr& variant, std::ifstream& ext_stream) { - if (is_type>(variant)) { - return as_type_ptr>(variant)->get(); - } else if (is_type>(variant)) { - const auto& model_path = as_type_ptr>(variant)->get(); + if (ov::is_type>(variant)) { + return ov::as_type_ptr>(variant)->get(); + } else if (ov::is_type>(variant)) { + const auto& model_path = ov::as_type_ptr>(variant)->get(); ext_stream.open(model_path, std::ios::in | std::ifstream::binary); } #if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - else if (is_type>(variant)) { - const auto& model_path = as_type_ptr>(variant)->get(); + else if (ov::is_type>(variant)) { + const auto& model_path = ov::as_type_ptr>(variant)->get(); ext_stream.open(model_path, std::ios::in | std::ifstream::binary); } #endif @@ -201,9 +201,9 @@ bool FrontEndPDPD::supported_impl(const std::vector>& v return false; // Validating first path, it must contain a model - if (is_type>(variants[0])) { + if (ov::is_type>(variants[0])) { std::string suffix = ".pdmodel"; - std::string model_path = as_type_ptr>(variants[0])->get(); + std::string model_path = ov::as_type_ptr>(variants[0])->get(); if (!pdpd::endsWith(model_path, suffix)) { model_path += pdpd::get_path_sep() + "__model__"; } @@ -213,9 +213,9 @@ bool FrontEndPDPD::supported_impl(const std::vector>& v return model_str && model_str.is_open(); } #if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - else if (is_type>(variants[0])) { + else if (ov::is_type>(variants[0])) { std::wstring suffix = L".pdmodel"; - std::wstring model_path = as_type_ptr>(variants[0])->get(); + std::wstring model_path = ov::as_type_ptr>(variants[0])->get(); if (!pdpd::endsWith(model_path, suffix)) { model_path += pdpd::get_path_sep() + L"__model__"; } @@ -225,9 +225,9 @@ bool FrontEndPDPD::supported_impl(const std::vector>& v return model_str && model_str.is_open(); } #endif - else if (is_type>(variants[0])) { + else if (ov::is_type>(variants[0])) { // Validating first stream, it must contain a model - auto p_model_stream = as_type_ptr>(variants[0])->get(); + auto p_model_stream = ov::as_type_ptr>(variants[0])->get(); paddle::framework::proto::ProgramDesc fw; return fw.ParseFromIstream(p_model_stream); } @@ -237,20 +237,20 @@ bool FrontEndPDPD::supported_impl(const std::vector>& v InputModel::Ptr FrontEndPDPD::load_impl(const std::vector>& variants) const { if (variants.size() == 1) { // The case when folder with __model__ and weight files is provided or .pdmodel file - if (is_type>(variants[0])) { - std::string m_path = as_type_ptr>(variants[0])->get(); + if (ov::is_type>(variants[0])) { + std::string m_path = ov::as_type_ptr>(variants[0])->get(); return std::make_shared(m_path); } #if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - else if (is_type>(variants[0])) { - std::wstring m_path = as_type_ptr>(variants[0])->get(); + else if (ov::is_type>(variants[0])) { + std::wstring m_path = ov::as_type_ptr>(variants[0])->get(); return std::make_shared(m_path); } #endif // The case with only model stream provided and no weights. This means model has // no learnable weights - else if (is_type>(variants[0])) { - auto p_model_stream = as_type_ptr>(variants[0])->get(); + else if (ov::is_type>(variants[0])) { + auto p_model_stream = ov::as_type_ptr>(variants[0])->get(); return std::make_shared(std::vector{p_model_stream}); } } else if (variants.size() == 2) { @@ -279,7 +279,7 @@ std::shared_ptr FrontEndPDPD::convert(InputModel::Ptr model) c void FrontEndPDPD::convert(std::shared_ptr partiallyConverted) const { for (const auto& node : partiallyConverted->get_ordered_ops()) { - if (is_type(node)) { + if (ov::is_type(node)) { pdpd::normalize_framework_node(std::dynamic_pointer_cast(node), pdpd::get_supported_ops()); } @@ -330,4 +330,4 @@ extern "C" PDPD_API void* GetFrontEndData() { return std::make_shared(); }; return res; -} \ No newline at end of file +} diff --git a/ngraph/python/tests/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp b/ngraph/python/tests/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp index 28e402a92a7a36..5e089770ec2f4a 100644 --- a/ngraph/python/tests/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp +++ b/ngraph/python/tests/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp @@ -556,15 +556,15 @@ class MOCK_API FrontEndMockPy : public FrontEnd { FrontEndMockPy() {} InputModel::Ptr load_impl(const std::vector>& params) const override { - if (params.size() > 0 && is_type>(params[0])) - m_stat.m_load_paths.push_back(as_type_ptr>(params[0])->get()); + if (params.size() > 0 && ov::is_type>(params[0])) + m_stat.m_load_paths.push_back(ov::as_type_ptr>(params[0])->get()); return std::make_shared(); } bool supported_impl(const std::vector>& params) const override { m_stat.m_supported++; - if (params.size() > 0 && is_type>(params[0])) { - auto path = as_type_ptr>(params[0])->get(); + if (params.size() > 0 && ov::is_type>(params[0])) { + auto path = ov::as_type_ptr>(params[0])->get(); if (path.find(".test_mock_py_mdl") != std::string::npos) { return true; } diff --git a/ngraph/test/builder_autobroadcast.cpp b/ngraph/test/builder_autobroadcast.cpp index 86ac0ed44d1df9..48c04a7b65cccc 100644 --- a/ngraph/test/builder_autobroadcast.cpp +++ b/ngraph/test/builder_autobroadcast.cpp @@ -321,7 +321,7 @@ TEST(autobroadcast, axes_mapping_from_bcast_axes) { auto axes_mapping = builder::opset1::get_axes_mapping_output(output_shape, broadcast_axes); EXPECT_TRUE(op::is_constant(axes_mapping.get_node())); - Shape axes_mapping_shape = as_type(axes_mapping.get_node())->get_shape_val(); + Shape axes_mapping_shape = ov::as_type(axes_mapping.get_node())->get_shape_val(); EXPECT_EQ(axes_mapping_shape.size(), 2); EXPECT_EQ(axes_mapping_shape, (Shape{1, 3})); } @@ -333,7 +333,7 @@ TEST(autobroadcast, axes_mapping_from_bcast_axes_scalar) { auto axes_mapping = builder::opset1::get_axes_mapping_output(output_shape, broadcast_axes); EXPECT_TRUE(op::is_constant(axes_mapping.get_node())); - Shape axes_mapping_shape = as_type(axes_mapping.get_node())->get_shape_val(); + Shape axes_mapping_shape = ov::as_type(axes_mapping.get_node())->get_shape_val(); EXPECT_EQ(axes_mapping_shape.size(), 0); EXPECT_EQ(axes_mapping_shape, (Shape{})); } @@ -345,7 +345,7 @@ TEST(autobroadcast, axes_mapping_from_bcast_axes_identical) { auto axes_mapping = builder::opset1::get_axes_mapping_output(output_shape, broadcast_axes); EXPECT_TRUE(op::is_constant(axes_mapping.get_node())); - Shape axes_mapping_shape = as_type(axes_mapping.get_node())->get_shape_val(); + Shape axes_mapping_shape = ov::as_type(axes_mapping.get_node())->get_shape_val(); EXPECT_EQ(axes_mapping_shape.size(), output_shape.size()); EXPECT_EQ(axes_mapping_shape, (Shape{0, 1, 2, 3})); } @@ -357,7 +357,7 @@ TEST(autobroadcast, axes_mapping_start_match_axis) { auto axes_mapping = builder::opset1::get_axes_mapping_output(output_shape, input_shape, start_match_axis); EXPECT_TRUE(op::is_constant(axes_mapping.get_node())); - Shape axes_mapping_shape = as_type(axes_mapping.get_node())->get_shape_val(); + Shape axes_mapping_shape = ov::as_type(axes_mapping.get_node())->get_shape_val(); EXPECT_EQ(axes_mapping_shape.size(), 2); EXPECT_EQ(axes_mapping_shape, (Shape{1, 2})); } @@ -369,7 +369,7 @@ TEST(autobroadcast, axes_mapping_start_match_axis_scalar) { auto axes_mapping = builder::opset1::get_axes_mapping_output(output_shape, input_shape, start_match_axis); EXPECT_TRUE(op::is_constant(axes_mapping.get_node())); - Shape axes_mapping_shape = as_type(axes_mapping.get_node())->get_shape_val(); + Shape axes_mapping_shape = ov::as_type(axes_mapping.get_node())->get_shape_val(); EXPECT_EQ(axes_mapping_shape.size(), 0); EXPECT_EQ(axes_mapping_shape, (Shape{})); } @@ -381,7 +381,7 @@ TEST(autobroadcast, axes_mapping_start_match_axis_identical) { auto axes_mapping = builder::opset1::get_axes_mapping_output(output_shape, input_shape, start_match_axis); EXPECT_TRUE(op::is_constant(axes_mapping.get_node())); - Shape axes_mapping_shape = as_type(axes_mapping.get_node())->get_shape_val(); + Shape axes_mapping_shape = ov::as_type(axes_mapping.get_node())->get_shape_val(); EXPECT_EQ(axes_mapping_shape.size(), output_shape.rank().get_length()); EXPECT_EQ(axes_mapping_shape, (Shape{0, 1, 2, 3})); } diff --git a/ngraph/test/constant_folding.cpp b/ngraph/test/constant_folding.cpp index 2daab19e4978f3..2881549eaffca5 100644 --- a/ngraph/test/constant_folding.cpp +++ b/ngraph/test/constant_folding.cpp @@ -16,7 +16,7 @@ using namespace std; template static std::vector get_result_constant(std::shared_ptr f, size_t pos) { - auto new_const = as_type_ptr(f->get_results().at(pos)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(pos)->input_value(0).get_node_shared_ptr()); return new_const->cast_vector(); } @@ -55,7 +55,7 @@ TEST(constant_folding, acosh) { EXPECT_EQ(count_ops_of_type(f), 1); ASSERT_EQ(f->get_results().size(), 1); - auto new_const = as_type_ptr(f->get_results()[0]->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results()[0]->input_value(0).get_node_shared_ptr()); EXPECT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -84,7 +84,7 @@ TEST(constant_folding, asinh) { EXPECT_EQ(count_ops_of_type(f), 1); ASSERT_EQ(f->get_results().size(), 1); - auto new_const = as_type_ptr(f->get_results()[0]->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results()[0]->input_value(0).get_node_shared_ptr()); EXPECT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -113,7 +113,7 @@ TEST(constant_folding, atanh) { EXPECT_EQ(count_ops_of_type(f), 1); ASSERT_EQ(f->get_results().size(), 1); - auto new_const = as_type_ptr(f->get_results()[0]->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results()[0]->input_value(0).get_node_shared_ptr()); EXPECT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -141,7 +141,7 @@ TEST(constant_folding, constant_squeeze) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), shape_out); @@ -170,7 +170,7 @@ TEST(constant_folding, constant_unsqueeze) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), shape_out); @@ -197,7 +197,7 @@ TEST(constant_folding, constant_broadcast_v1) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -222,7 +222,7 @@ TEST(constant_folding, constant_broadcast_v1_with_target_shape) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -247,7 +247,7 @@ TEST(constant_folding, constant_broadcast_v1_numpy) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -409,7 +409,7 @@ static void test_const_convert(const vector& values_in, const vector& valu ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_output_element_type(0), element::from()); @@ -461,7 +461,7 @@ TEST(constant_folding, shape_of_v0) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_output_element_type(0), element::i64); @@ -485,7 +485,7 @@ TEST(constant_folding, shape_of_v3) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_output_element_type(0), element::i64); @@ -509,7 +509,7 @@ TEST(constant_folding, shape_of_i32_v3) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_output_element_type(0), element::i32); @@ -675,7 +675,7 @@ void const_reverse(const element::Type& axes_elem_type) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -717,7 +717,7 @@ TEST(constant_folding, const_reduceprod) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -749,7 +749,7 @@ TEST(constant_folding, const_reduceprod_keepdims) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -781,7 +781,7 @@ TEST(constant_folding, const_reducesum) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -813,7 +813,7 @@ TEST(constant_folding, const_reducesum_keepdims) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -845,7 +845,7 @@ TEST(constant_folding, const_reducemax) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -877,7 +877,7 @@ TEST(constant_folding, const_reducemax_keepdims) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -909,7 +909,7 @@ TEST(constant_folding, const_reducemin) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -941,7 +941,7 @@ TEST(constant_folding, const_reducemin_keepdims) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -973,7 +973,7 @@ TEST(constant_folding, const_reducemean) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -1005,7 +1005,7 @@ TEST(constant_folding, const_reducemean_keepdims) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(new_const->get_shape(), output_shape); @@ -1034,7 +1034,7 @@ TEST(constant_folding, const_reduce_logical_and__no_keepdims) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1065,7 +1065,7 @@ TEST(constant_folding, const_reduce_logical_and__keepdims) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1098,7 +1098,7 @@ TEST(constant_folding, const_reduce_logical_and__keepdims_3d) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1129,7 +1129,7 @@ TEST(constant_folding, const_reduce_logical_or__no_keepdims) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1157,7 +1157,7 @@ TEST(constant_folding, const_concat) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1181,7 +1181,7 @@ TEST(constant_folding, const_concat_3d_single_elem) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1208,7 +1208,7 @@ TEST(constant_folding, const_concat_axis_2) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1235,7 +1235,7 @@ TEST(constant_folding, const_concat_axis_1_bool_type) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1259,7 +1259,7 @@ TEST(constant_folding, const_logical_not) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1283,7 +1283,7 @@ TEST(constant_folding, const_equal) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1307,7 +1307,7 @@ TEST(constant_folding, const_not_equal) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1331,7 +1331,7 @@ TEST(constant_folding, const_greater) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1355,7 +1355,7 @@ TEST(constant_folding, const_greater_eq) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1379,7 +1379,7 @@ TEST(constant_folding, const_less) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1403,7 +1403,7 @@ TEST(constant_folding, const_less_eq) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1427,7 +1427,7 @@ TEST(constant_folding, const_or) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1451,7 +1451,7 @@ TEST(constant_folding, const_xor) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1475,7 +1475,7 @@ TEST(constant_folding, const_ceiling) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1499,7 +1499,7 @@ TEST(constant_folding, const_floor) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1527,7 +1527,7 @@ TEST(constant_folding, const_gather_v1) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1555,7 +1555,7 @@ TEST(constant_folding, const_gather_v1_scalar) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1589,7 +1589,7 @@ TEST(constant_folding, const_gather_v1_subgraph) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1621,7 +1621,7 @@ TEST(constant_folding, const_gather_v1_subgraph_neg_axis) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1781,7 +1781,7 @@ TEST(constant_folding, const_gather_v7) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1809,7 +1809,7 @@ TEST(constant_folding, const_gather_v7_scalar) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -1843,7 +1843,7 @@ TEST(constant_folding, const_gather_v7_subgraph) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -1875,7 +1875,7 @@ TEST(constant_folding, const_gather_v7_subgraph_neg_axis) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -2042,7 +2042,7 @@ TEST(constant_folding, const_strided_slice) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2071,7 +2071,7 @@ TEST(constant_folding, constant_dyn_reshape) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2107,7 +2107,7 @@ TEST(constant_folding, constant_dyn_reshape_shape_not_originally_constant) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2201,7 +2201,7 @@ TEST(constant_folding, constant_transpose) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2230,7 +2230,7 @@ void range_test(T start, T stop, T step, const vector& values_expected) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); @@ -2271,7 +2271,7 @@ TEST(constant_folding, constant_v1_select) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2296,9 +2296,9 @@ TEST(constant_folding, constant_v1_split) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), num_splits); - auto res1 = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); - auto res2 = as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); - auto res3 = as_type_ptr(f->get_results().at(2)->input_value(0).get_node_shared_ptr()); + auto res1 = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res2 = ov::as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); + auto res3 = ov::as_type_ptr(f->get_results().at(2)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res1); ASSERT_TRUE(res2); ASSERT_TRUE(res3); @@ -2327,9 +2327,9 @@ TEST(constant_folding, constant_v1_split_specialized) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), num_splits); - auto res1 = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); - auto res2 = as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); - auto res3 = as_type_ptr(f->get_results().at(2)->input_value(0).get_node_shared_ptr()); + auto res1 = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res2 = ov::as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); + auto res3 = ov::as_type_ptr(f->get_results().at(2)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res1); ASSERT_TRUE(res2); ASSERT_TRUE(res3); @@ -2366,10 +2366,10 @@ TEST(constant_folding, constant_v1_split_axis_1_4_splits) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), num_splits); - auto res1 = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); - auto res2 = as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); - auto res3 = as_type_ptr(f->get_results().at(2)->input_value(0).get_node_shared_ptr()); - auto res4 = as_type_ptr(f->get_results().at(3)->input_value(0).get_node_shared_ptr()); + auto res1 = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res2 = ov::as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); + auto res3 = ov::as_type_ptr(f->get_results().at(2)->input_value(0).get_node_shared_ptr()); + auto res4 = ov::as_type_ptr(f->get_results().at(3)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res1); ASSERT_EQ(res1->get_friendly_name(), "test.0"); ASSERT_TRUE(res2); @@ -2412,8 +2412,8 @@ TEST(constant_folding, constant_v1_split_axis_1_2_splits) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), num_splits); - auto res1 = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); - auto res2 = as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); + auto res1 = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res2 = ov::as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res1); ASSERT_TRUE(res2); @@ -2451,8 +2451,8 @@ TEST(constant_folding, constant_v1_variadic_split_axis_1_2_splits) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), values_lengths.size()); - auto res1 = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); - auto res2 = as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); + auto res1 = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res2 = ov::as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res1); ASSERT_TRUE(res2); @@ -2489,9 +2489,9 @@ TEST(constant_folding, constant_v1_variadic_split_axis_1_3_splits_neg_length) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), values_lengths.size()); - auto res1 = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); - auto res2 = as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); - auto res3 = as_type_ptr(f->get_results().at(2)->input_value(0).get_node_shared_ptr()); + auto res1 = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res2 = ov::as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); + auto res3 = ov::as_type_ptr(f->get_results().at(2)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res1); ASSERT_TRUE(res2); ASSERT_TRUE(res3); @@ -2527,7 +2527,7 @@ TEST(constant_folding, constant_v1_one_hot) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto res = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res); ASSERT_EQ((Shape{3, 3}), res->get_output_shape(0)); @@ -2557,7 +2557,7 @@ TEST(constant_folding, constant_v1_one_hot_negative_axes) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto res = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res); ASSERT_EQ((Shape{4, 3}), res->get_output_shape(0)); @@ -2598,7 +2598,7 @@ TEST(constant_folding, constant_v1_one_hot_negative_axes_2) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto res = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto res = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(res); ASSERT_EQ(res->get_friendly_name(), "test"); @@ -2638,7 +2638,7 @@ TEST(constant_folding, constant_tile_1d) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2667,7 +2667,7 @@ TEST(constant_folding, constant_tile_3d_small_data_rank) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2696,7 +2696,7 @@ TEST(constant_folding, constant_tile_3d_few_repeats) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2725,7 +2725,7 @@ TEST(constant_folding, constant_tile_1d_0_repeats) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2754,7 +2754,7 @@ TEST(constant_folding, constant_tile_0_rank_data) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -2778,7 +2778,7 @@ TEST(constant_folding, constant_non_zero_0D) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); const auto values_out = new_const->get_vector(); @@ -2802,7 +2802,7 @@ TEST(constant_folding, constant_non_zero_1D) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); const auto values_out = new_const->get_vector(); @@ -2826,7 +2826,7 @@ TEST(constant_folding, constant_non_zero_int32_output_type) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(element::i32, new_const->get_element_type()); @@ -2851,7 +2851,7 @@ TEST(constant_folding, constant_non_zero_1D_all_indices) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); const auto values_out = new_const->get_vector(); @@ -2875,7 +2875,7 @@ TEST(constant_folding, constant_non_zero_2D) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); const auto values_out = new_const->get_vector(); @@ -2899,7 +2899,7 @@ TEST(constant_folding, DISABLED_constant_non_zero_2D_all_indices) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); const auto values_out = new_const->get_vector(); @@ -2924,7 +2924,7 @@ TEST(constant_folding, DISABLED_constant_non_zero_2D_all_zeros) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); ASSERT_EQ(shape_size(new_const->get_shape()), 0); @@ -2944,7 +2944,7 @@ TEST(constant_folding, constant_non_zero_3D) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - const auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + const auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); const auto values_out = new_const->get_vector(); @@ -2977,7 +2977,7 @@ TEST(constant_folding, constant_scatter_elements_update_basic) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto result_node = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto result_node = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(result_node); ASSERT_EQ(result_node->get_friendly_name(), "test"); ASSERT_EQ(data_shape, result_node->get_output_shape(0)); @@ -3006,7 +3006,7 @@ TEST(constant_folding, constant_scatter_elements_update_negative_axis) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto result_node = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto result_node = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(result_node); ASSERT_EQ(data_shape, result_node->get_output_shape(0)); std::vector expected{1.1f, 1.0f, 1.2f, 2.0f, 2.2f, 2.1f, 0.0f, 0.0f, 0.0f}; @@ -3034,7 +3034,7 @@ TEST(constant_folding, constant_scatter_elements_update_1d_axis) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto result_node = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto result_node = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(result_node); ASSERT_EQ(data_shape, result_node->get_output_shape(0)); std::vector expected{2.f, 1.1f, 0.0f, 1.f, 0.0f, 2.2f, 0.f, 2.1f, 1.2f}; @@ -3063,7 +3063,7 @@ TEST(constant_folding, constant_scatter_elements_update_3d_i16) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto result_node = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto result_node = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(result_node); ASSERT_EQ(data_shape, result_node->get_output_shape(0)); std::vector expected{4, 2, 0, 1, 0, 6, 0, 5, 3, 10, 0, 12, 0, 11, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -3091,7 +3091,7 @@ TEST(constant_folding, constant_scatter_elements_update_one_elem) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto result_node = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto result_node = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(result_node); ASSERT_EQ(data_shape, result_node->get_output_shape(0)); std::vector expected{input_data}; @@ -3118,7 +3118,7 @@ void test_constant_folding_reshape_v1(Shape& shape_in, ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 1); - auto new_const = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(new_const); ASSERT_EQ(new_const->get_friendly_name(), "test"); auto values_out = new_const->get_vector(); @@ -3205,8 +3205,8 @@ TEST(constant_folding, constant_loop) { ASSERT_EQ(count_ops_of_type(f), 0); ASSERT_EQ(count_ops_of_type(f), 2); - auto result_node_0 = as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); - auto result_node_1 = as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); + auto result_node_0 = ov::as_type_ptr(f->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto result_node_1 = ov::as_type_ptr(f->get_results().at(1)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(result_node_0); ASSERT_TRUE(result_node_1); diff --git a/ngraph/test/copy.cpp b/ngraph/test/copy.cpp index 15959ab67472d9..9185fdfb0cf3ef 100644 --- a/ngraph/test/copy.cpp +++ b/ngraph/test/copy.cpp @@ -74,7 +74,7 @@ TEST(copy, broadcast) { op::Constant::create(element::u64, Shape{new_shape.size()}, new_shape), op::Constant::create(element::i64, Shape{axes.size()}, axes.to_vector())); auto new_node = node->copy_with_new_inputs(new_args); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_NE(nullptr, new_node); @@ -99,7 +99,7 @@ TEST(copy, concat) { int64_t axis = 0; auto node = make_shared(NodeVector{arg0, arg1}, axis); auto new_node = node->clone_with_new_inputs(new_args); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != new_node); @@ -113,7 +113,7 @@ TEST(copy, constant) { auto& et = element::f32; auto node = op::Constant::create(et, shape, c); auto new_node = node->clone_with_new_inputs(OutputVector{}); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != new_node); ASSERT_TRUE(OutputVector{} == new_node->input_values()); @@ -130,7 +130,7 @@ TEST(copy, convert) { auto node = make_shared(arg0, et); auto new_node = node->clone_with_new_inputs(new_args); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != new_node); @@ -206,7 +206,7 @@ TEST(copy, parameter) { Shape shape{1}; auto node = make_shared(element::f32, shape); auto new_node = node->clone_with_new_inputs({}); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != new_node); @@ -228,7 +228,7 @@ TEST(copy, reduce_sum) { OutputVector new_args{make_shared(element::f32, shape), op::Constant::create(element::i64, {axes.size()}, axes.to_vector())}; auto new_node = node->clone_with_new_inputs(new_args); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != new_node); @@ -248,7 +248,7 @@ TEST(copy, reshape) { auto shape_pattern = op::Constant::create(element::u64, {shape_out.size()}, shape_out); auto node = make_shared(arg0, shape_pattern, false); auto new_node = node->clone_with_new_inputs(new_args); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != new_node); @@ -267,7 +267,7 @@ TEST(copy, select) { auto node = make_shared(arg0, arg1, arg2); auto new_node = node->clone_with_new_inputs(new_args); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != new_node); @@ -311,7 +311,7 @@ TEST(copy, strided_slice) { std::vector{0, 0, 1}, std::vector{1, 0, 0}); auto new_node = node->clone_with_new_inputs(new_args); - auto node_cast = as_type_ptr(new_node); + auto node_cast = ov::as_type_ptr(new_node); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != new_node); diff --git a/ngraph/test/graph_rewrite.cpp b/ngraph/test/graph_rewrite.cpp index 68810d1ff90919..13b178840cdb81 100644 --- a/ngraph/test/graph_rewrite.cpp +++ b/ngraph/test/graph_rewrite.cpp @@ -396,7 +396,7 @@ class CheckConsumers : public ngraph::pass::MatcherPass { for (auto output : node->outputs()) { cnt += output.get_target_inputs().size(); } - if (as_type(node) || as_type(node)) { + if (ov::as_type(node) || ov::as_type(node)) { cnt += 1; } return cnt; diff --git a/ngraph/test/onnx/onnx_import_const_folding.in.cpp b/ngraph/test/onnx/onnx_import_const_folding.in.cpp index c6b9554af3fdfa..1599707dd3b9c9 100644 --- a/ngraph/test/onnx/onnx_import_const_folding.in.cpp +++ b/ngraph/test/onnx/onnx_import_const_folding.in.cpp @@ -33,7 +33,7 @@ void test_constant_folding(std::shared_ptr ng_function, for (auto ng_node : ng_function->get_ordered_ops()) { if (op::is_constant(ng_node)) { - const auto folded_node = as_type_ptr(ng_node); + const auto folded_node = ov::as_type_ptr(ng_node); const auto output_values = folded_node->cast_vector(); EXPECT_TRUE(ngraph::test::all_close(expected_output, output_values)); diff --git a/ngraph/test/op.cpp b/ngraph/test/op.cpp index 7529b586b32e5d..c60edaa4c35c4f 100644 --- a/ngraph/test/op.cpp +++ b/ngraph/test/op.cpp @@ -99,17 +99,17 @@ constexpr VariantTypeInfo VariantWrapper::type_info; TEST(op, variant) { shared_ptr var_std_string = make_variant("My string"); - ASSERT_TRUE((is_type>(var_std_string))); - EXPECT_EQ((as_type_ptr>(var_std_string)->get()), "My string"); + ASSERT_TRUE((ov::is_type>(var_std_string))); + EXPECT_EQ((ov::as_type_ptr>(var_std_string)->get()), "My string"); shared_ptr var_int64_t = make_variant(27); - ASSERT_TRUE((is_type>(var_int64_t))); - EXPECT_FALSE((is_type>(var_int64_t))); - EXPECT_EQ((as_type_ptr>(var_int64_t)->get()), 27); + ASSERT_TRUE((ov::is_type>(var_int64_t))); + EXPECT_FALSE((ov::is_type>(var_int64_t))); + EXPECT_EQ((ov::as_type_ptr>(var_int64_t)->get()), 27); shared_ptr var_ship = make_variant(Ship{"Lollipop", 3, 4}); - ASSERT_TRUE((is_type>(var_ship))); - Ship& ship = as_type_ptr>(var_ship)->get(); + ASSERT_TRUE((ov::is_type>(var_ship))); + Ship& ship = ov::as_type_ptr>(var_ship)->get(); EXPECT_EQ(ship.name, "Lollipop"); EXPECT_EQ(ship.x, 3); EXPECT_EQ(ship.y, 4); @@ -118,22 +118,22 @@ TEST(op, variant) { // Check Node RTInfo node->get_rt_info()["A"] = var_ship; auto node_var_ship = node->get_rt_info().at("A"); - ASSERT_TRUE((is_type>(node_var_ship))); - Ship& node_ship = as_type_ptr>(node_var_ship)->get(); + ASSERT_TRUE((ov::is_type>(node_var_ship))); + Ship& node_ship = ov::as_type_ptr>(node_var_ship)->get(); EXPECT_EQ(&node_ship, &ship); // Check Node Input RTInfo auto relu = make_shared(node); relu->input(0).get_rt_info()["A"] = var_ship; auto node_input_var_ship = node->get_rt_info().at("A"); - ASSERT_TRUE((is_type>(node_input_var_ship))); - Ship& node_input_ship = as_type_ptr>(node_input_var_ship)->get(); + ASSERT_TRUE((ov::is_type>(node_input_var_ship))); + Ship& node_input_ship = ov::as_type_ptr>(node_input_var_ship)->get(); EXPECT_EQ(&node_input_ship, &ship); // Check Node Input RTInfo node->output(0).get_rt_info()["A"] = var_ship; auto node_output_var_ship = node->get_rt_info().at("A"); - ASSERT_TRUE((is_type>(node_output_var_ship))); - Ship& node_output_ship = as_type_ptr>(node_input_var_ship)->get(); + ASSERT_TRUE((ov::is_type>(node_output_var_ship))); + Ship& node_output_ship = ov::as_type_ptr>(node_input_var_ship)->get(); EXPECT_EQ(&node_output_ship, &ship); } diff --git a/ngraph/test/pattern.cpp b/ngraph/test/pattern.cpp index 09e03fe776d791..ae653767b21285 100644 --- a/ngraph/test/pattern.cpp +++ b/ngraph/test/pattern.cpp @@ -84,7 +84,7 @@ class TestGraphRewrite : public ngraph::pass::GraphRewrite { size_t const_node_index = m.get_match_root()->input_value(0).get_node_shared_ptr() == pattern_map[pattern]; auto const_node = - as_type_ptr(m.get_match_root()->input_value(const_node_index).get_node_shared_ptr()); + ov::as_type_ptr(m.get_match_root()->input_value(const_node_index).get_node_shared_ptr()); auto second_node = m.get_match_root()->input_value(const_node_index).get_node_shared_ptr(); NGRAPH_DEBUG << "second_node = " << second_node->get_name() << " , pattern = " << pattern_map[pattern]->get_name(); @@ -128,7 +128,7 @@ class TestGraphRewrite : public ngraph::pass::GraphRewrite { size_t const_node_index = m.get_match_root()->input_value(0).get_node_shared_ptr() == pattern_map[pattern]; auto const_node = - as_type_ptr(m.get_match_root()->input_value(const_node_index).get_node_shared_ptr()); + ov::as_type_ptr(m.get_match_root()->input_value(const_node_index).get_node_shared_ptr()); auto second_node = m.get_match_root()->input_value(const_node_index).get_node_shared_ptr(); NGRAPH_DEBUG << "second_node = " << second_node->get_name() << " , pattern = " << pattern_map[pattern]->get_name(); @@ -690,7 +690,7 @@ TEST(pattern, label_on_skip) { auto const_label = std::make_shared(iconst, ngraph::is_zero, NodeVector{iconst}); auto bcst_pred = [](std::shared_ptr n) { - return as_type_ptr(n) != nullptr; + return ov::as_type_ptr(n) != nullptr; }; auto shape_const = op::Constant::create(element::u64, Shape{shape.size()}, shape); diff --git a/ngraph/test/runtime/dynamic/dynamic_backend.cpp b/ngraph/test/runtime/dynamic/dynamic_backend.cpp index a0adc243fa6604..a504d9b9cdb6c9 100644 --- a/ngraph/test/runtime/dynamic/dynamic_backend.cpp +++ b/ngraph/test/runtime/dynamic/dynamic_backend.cpp @@ -75,8 +75,8 @@ runtime::dynamic::DynamicExecutable::DynamicExecutable(shared_ptr wrap // count_dyn_nodes. bool is_dynamic_op(const std::shared_ptr& op) { - return is_type(op) || is_type(op) || - is_type(op); + return ov::is_type(op) || ov::is_type(op) || + ov::is_type(op); } // Helper for a vile hack in DynamicExecutable::call. See body of that function for details. diff --git a/ngraph/test/runtime/interpreter/evaluates_map.cpp b/ngraph/test/runtime/interpreter/evaluates_map.cpp index 6f410d90abfab5..e6a56212f0f677 100644 --- a/ngraph/test/runtime/interpreter/evaluates_map.cpp +++ b/ngraph/test/runtime/interpreter/evaluates_map.cpp @@ -2921,21 +2921,21 @@ namespace const HostTensorVector& inputs) { auto element_type = node->get_output_element_type(0); - if (is_type(node)) + if (ov::is_type(node)) { element_type = node->get_input_element_type(1); } - else if (is_type(node)) + else if (ov::is_type(node)) { element_type = node->get_input_element_type(0); } for (size_t i = 1; i < node->outputs().size(); i++) { - if ((is_type(node) || - is_type(node) || - is_type(node) || - is_type(node) || - is_type(node)) && + if ((ov::is_type(node) || + ov::is_type(node) || + ov::is_type(node) || + ov::is_type(node) || + ov::is_type(node)) && i == 1) { continue; @@ -2944,37 +2944,37 @@ namespace switch (element_type) { case element::Type_t::boolean: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::bf16: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::f16: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::f64: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::f32: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::i4: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::i8: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::i16: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::i32: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::i64: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::u1: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::u4: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::u8: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::u16: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::u32: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); case element::Type_t::u64: - return evaluate(as_type_ptr(node), outputs, inputs); + return evaluate(ov::as_type_ptr(node), outputs, inputs); default: throw ngraph_error(std::string("Unhandled data type ") + node->get_element_type().get_type_name() + diff --git a/ngraph/test/runtime/interpreter/int_executable.cpp b/ngraph/test/runtime/interpreter/int_executable.cpp index 3d2cad83343a74..8d24cd6f088c51 100644 --- a/ngraph/test/runtime/interpreter/int_executable.cpp +++ b/ngraph/test/runtime/interpreter/int_executable.cpp @@ -69,7 +69,7 @@ bool runtime::interpreter::INTExecutable::call(const vector(output)) + if (!ov::is_type(output)) { throw ngraph_error("One of function's outputs isn't op::Result"); } @@ -114,13 +114,13 @@ bool runtime::interpreter::INTExecutable::call(const vector(op) || is_type(op)) + if (ov::is_type(op) || ov::is_type(op)) { type = op->get_input_element_type(0); } - else if (is_type(op) || is_type(op) || - is_type(op) || is_type(op) || - is_type(op) || is_type(op)) + else if (ov::is_type(op) || ov::is_type(op) || + ov::is_type(op) || ov::is_type(op) || + ov::is_type(op) || ov::is_type(op)) { // Get the type of the second input, not the first // All BinaryElementwiseComparision ops have the same type for inputs diff --git a/ngraph/test/specialize_function.cpp b/ngraph/test/specialize_function.cpp index 93b90997d50f3a..95143814cfa416 100644 --- a/ngraph/test/specialize_function.cpp +++ b/ngraph/test/specialize_function.cpp @@ -117,11 +117,11 @@ TEST(specialize_function, et_static_shape_rank_static_dynamic_subst_val) { ASSERT_EQ(g->get_output_shape(0), (Shape{1, 2, 3})); ASSERT_EQ(g->get_output_element_type(0), element::f32); - auto plus_node = as_type_ptr(g->get_results().at(0)->input_value(0).get_node_shared_ptr()); + auto plus_node = ov::as_type_ptr(g->get_results().at(0)->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(plus_node); - auto convert_node = as_type_ptr(plus_node->input_value(1).get_node_shared_ptr()); + auto convert_node = ov::as_type_ptr(plus_node->input_value(1).get_node_shared_ptr()); ASSERT_TRUE(convert_node); - auto const_node = as_type_ptr(convert_node->input_value(0).get_node_shared_ptr()); + auto const_node = ov::as_type_ptr(convert_node->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(const_node); ASSERT_EQ(const_node->get_output_element_type(0), element::i32); diff --git a/ngraph/test/type_prop/loop.cpp b/ngraph/test/type_prop/loop.cpp index ebbae919e86ba3..a92313c19b3c3b 100644 --- a/ngraph/test/type_prop/loop.cpp +++ b/ngraph/test/type_prop/loop.cpp @@ -49,13 +49,13 @@ TEST(type_prop, loop_operation_for_mode_10_iter_static_shapes) { for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -71,10 +71,10 @@ TEST(type_prop, loop_operation_for_mode_10_iter_static_shapes) { for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -134,13 +134,13 @@ TEST(type_prop, loop_operation_dowhile_mode_1_iter_static_shapes) { for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -156,10 +156,10 @@ TEST(type_prop, loop_operation_dowhile_mode_1_iter_static_shapes) { for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -219,13 +219,13 @@ TEST(type_prop, loop_operation_for_and_condition_mode_dynamic_iter_static_shapes for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -238,10 +238,10 @@ TEST(type_prop, loop_operation_for_and_condition_mode_dynamic_iter_static_shapes for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -298,13 +298,13 @@ TEST(type_prop, loop_operation_for_and_condition_mode_dynamic_iter_dynamic_shape for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -318,10 +318,10 @@ TEST(type_prop, loop_operation_for_and_condition_mode_dynamic_iter_dynamic_shape for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -383,13 +383,13 @@ TEST(type_prop, loop_operation_for_and_condition_mode_dynamic_iter_partially_dyn for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -404,10 +404,10 @@ TEST(type_prop, loop_operation_for_and_condition_mode_dynamic_iter_partially_dyn for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -514,13 +514,13 @@ TEST(type_prop, loop_operation_infinite_loop_mode_dynamic_iter_dynamic_shapes) { for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -536,10 +536,10 @@ TEST(type_prop, loop_operation_infinite_loop_mode_dynamic_iter_dynamic_shapes) { for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -600,13 +600,13 @@ TEST(type_prop, loop_operation_for_mode_10_iter_static_shapes_special_body_ports for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -622,10 +622,10 @@ TEST(type_prop, loop_operation_for_mode_10_iter_static_shapes_special_body_ports for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -686,13 +686,13 @@ TEST(type_prop, loop_operation_for_mode_10_iter_static_shapes_special_body_ports for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -708,10 +708,10 @@ TEST(type_prop, loop_operation_for_mode_10_iter_static_shapes_special_body_ports for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -772,13 +772,13 @@ TEST(type_prop, loop_operation_10_iter_static_shapes_sliced_inputs) { for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -795,10 +795,10 @@ TEST(type_prop, loop_operation_10_iter_static_shapes_sliced_inputs) { for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -865,13 +865,13 @@ TEST(type_prop, loop_operation_dynamic_iter_dynamic_batch_shapes_sliced_inputs_c for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -888,10 +888,10 @@ TEST(type_prop, loop_operation_dynamic_iter_dynamic_batch_shapes_sliced_inputs_c for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } @@ -962,13 +962,13 @@ TEST(type_prop, loop_operation_dynamic_iter_dynamic_shapes_sliced_inputs_concate for (auto& desc : loop->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -984,10 +984,10 @@ TEST(type_prop, loop_operation_dynamic_iter_dynamic_shapes_sliced_inputs_concate for (auto& desc : loop->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } diff --git a/ngraph/test/type_prop/ti.cpp b/ngraph/test/type_prop/ti.cpp index 1d27dfe60fa4aa..c2c150deb05b75 100644 --- a/ngraph/test/type_prop/ti.cpp +++ b/ngraph/test/type_prop/ti.cpp @@ -132,13 +132,13 @@ TEST(type_prop, tensor_iterator_2_slice_inputs_part_size_2_dynamic) { for (auto& desc : tensor_iterator->get_input_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "InvariantInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "SliceInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } else if (std::strcmp(type_info.name, "MergedInputDescription") == 0) { - auto input_desc = as_type_ptr(desc); + auto input_desc = ov::as_type_ptr(desc); EXPECT_NE(input_desc, nullptr); } } @@ -153,10 +153,10 @@ TEST(type_prop, tensor_iterator_2_slice_inputs_part_size_2_dynamic) { for (auto& desc : tensor_iterator->get_output_descriptions()) { auto type_info = desc->get_type_info(); if (std::strcmp(type_info.name, "ConcatOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } else if (std::strcmp(type_info.name, "BodyOutputDescription") == 0) { - auto output_desc = as_type_ptr(desc); + auto output_desc = ov::as_type_ptr(desc); EXPECT_NE(output_desc, nullptr); } } diff --git a/ngraph/test/util.cpp b/ngraph/test/util.cpp index d72563970b92e9..83be8232df94b2 100644 --- a/ngraph/test/util.cpp +++ b/ngraph/test/util.cpp @@ -195,11 +195,11 @@ TEST_F(CloneTest, clone_nodes_full) { auto cloned_nodes = clone_nodes(nodes, node_map); ASSERT_TRUE(CompareNodeVector(nodes, cloned_nodes, node_map)); - ASSERT_NE(nullptr, as_type_ptr(node_map.at(A.get()))); - ASSERT_NE(nullptr, as_type_ptr(node_map.at(B.get()))); - ASSERT_NE(nullptr, as_type_ptr(node_map.at(C.get()))); - ASSERT_NE(nullptr, as_type_ptr(node_map.at(AplusB.get()))); - ASSERT_NE(nullptr, as_type_ptr(node_map.at(AplusBtimesC.get()))); + ASSERT_NE(nullptr, ov::as_type_ptr(node_map.at(A.get()))); + ASSERT_NE(nullptr, ov::as_type_ptr(node_map.at(B.get()))); + ASSERT_NE(nullptr, ov::as_type_ptr(node_map.at(C.get()))); + ASSERT_NE(nullptr, ov::as_type_ptr(node_map.at(AplusB.get()))); + ASSERT_NE(nullptr, ov::as_type_ptr(node_map.at(AplusBtimesC.get()))); auto sorted_nodes = topological_sort(nodes); auto sorted_cloned_nodes = topological_sort(cloned_nodes); diff --git a/ngraph/test/visitors/op/adaptive_max_pool.cpp b/ngraph/test/visitors/op/adaptive_max_pool.cpp index dcb4e3d58b38be..730cbc974b0e88 100644 --- a/ngraph/test/visitors/op/adaptive_max_pool.cpp +++ b/ngraph/test/visitors/op/adaptive_max_pool.cpp @@ -19,7 +19,7 @@ TEST(attributes, adaptive_max_pool_op) { const auto adaptive_pool = make_shared(A, out_shape); NodeBuilder builder(adaptive_pool); - auto g_adaptive_pool = as_type_ptr(builder.create()); + auto g_adaptive_pool = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 1; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/batch_norm.cpp b/ngraph/test/visitors/op/batch_norm.cpp index 389849ceb5f691..e138539189f09b 100644 --- a/ngraph/test/visitors/op/batch_norm.cpp +++ b/ngraph/test/visitors/op/batch_norm.cpp @@ -38,7 +38,7 @@ TYPED_TEST_P(BatchNormAttrTest, batch_norm_inference_op) { const auto expected_attr_count = 1; NodeBuilder builder(batch_norm); EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); - auto g_batch_norm = as_type_ptr(builder.create()); + auto g_batch_norm = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_batch_norm->get_eps_value(), batch_norm->get_eps_value()); } diff --git a/ngraph/test/visitors/op/broadcast.cpp b/ngraph/test/visitors/op/broadcast.cpp index 75cd1ecf98a21a..04ba6e2242cd7b 100644 --- a/ngraph/test/visitors/op/broadcast.cpp +++ b/ngraph/test/visitors/op/broadcast.cpp @@ -24,7 +24,7 @@ TEST(attributes, broadcast_v3) { const auto broadcast_v3 = make_shared(arg, shape, broadcast_spec); NodeBuilder builder(broadcast_v3); - auto g_broadcast_v3 = as_type_ptr(builder.create()); + auto g_broadcast_v3 = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_broadcast_v3->get_broadcast_spec(), broadcast_spec); } diff --git a/ngraph/test/visitors/op/bucketize.cpp b/ngraph/test/visitors/op/bucketize.cpp index 3424fc66afe055..244e7361ae015a 100644 --- a/ngraph/test/visitors/op/bucketize.cpp +++ b/ngraph/test/visitors/op/bucketize.cpp @@ -23,7 +23,7 @@ TEST(attributes, bucketize_v3_op_default_attributes) { auto bucketize = make_shared(data, buckets); NodeBuilder builder(bucketize); - auto g_bucketize = as_type_ptr(builder.create()); + auto g_bucketize = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_bucketize->get_output_type(), bucketize->get_output_type()); EXPECT_EQ(g_bucketize->get_with_right_bound(), bucketize->get_with_right_bound()); @@ -39,7 +39,7 @@ TEST(attributes, bucketize_v3_op_custom_attributes) { auto bucketize = make_shared(data, buckets, output_type, with_right_bound); NodeBuilder builder(bucketize); - auto g_bucketize = as_type_ptr(builder.create()); + auto g_bucketize = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_bucketize->get_output_type(), bucketize->get_output_type()); EXPECT_EQ(g_bucketize->get_with_right_bound(), bucketize->get_with_right_bound()); diff --git a/ngraph/test/visitors/op/constant.cpp b/ngraph/test/visitors/op/constant.cpp index 7cd3d72272395f..3f6dec98aace44 100644 --- a/ngraph/test/visitors/op/constant.cpp +++ b/ngraph/test/visitors/op/constant.cpp @@ -20,7 +20,7 @@ TEST(attributes, constant_op) { vector data{5.0f, 4.0f, 3.0f, 2.0f, 1.0f, 0.0f}; auto k = make_shared(element::f32, Shape{2, 3}, data); NodeBuilder builder(k); - auto g_k = as_type_ptr(builder.create()); + auto g_k = ov::as_type_ptr(builder.create()); g_k->validate_and_infer_types(); ASSERT_TRUE(g_k); EXPECT_EQ(k->get_element_type(), g_k->get_element_type()); @@ -33,7 +33,7 @@ TEST(attributes, constant_op_different_elements) { vector data{5, 4, 3, 2, 1, 0}; auto k = make_shared(element::i64, Shape{2, 3}, data); NodeBuilder builder(k); - auto g_k = as_type_ptr(builder.create()); + auto g_k = ov::as_type_ptr(builder.create()); g_k->validate_and_infer_types(); ASSERT_TRUE(g_k); EXPECT_EQ(k->get_element_type(), g_k->get_element_type()); @@ -47,7 +47,7 @@ TEST(attributes, constant_op_identical_elements) { vector data{5, 5, 5, 5, 5, 5}; auto k = make_shared(element::i64, Shape{2, 3}, data); NodeBuilder builder(k); - auto g_k = as_type_ptr(builder.create()); + auto g_k = ov::as_type_ptr(builder.create()); g_k->validate_and_infer_types(); ASSERT_TRUE(g_k); EXPECT_EQ(k->get_element_type(), g_k->get_element_type()); diff --git a/ngraph/test/visitors/op/convert.cpp b/ngraph/test/visitors/op/convert.cpp index d7e40e771dcebb..5857a000add38a 100644 --- a/ngraph/test/visitors/op/convert.cpp +++ b/ngraph/test/visitors/op/convert.cpp @@ -25,6 +25,6 @@ TEST(attributes, convert_op_v0) { EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); // destination_type attribute - const auto g_convert = as_type_ptr(builder.create()); + const auto g_convert = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_convert->get_destination_type(), convert->get_destination_type()); } diff --git a/ngraph/test/visitors/op/convolution_backprop.cpp b/ngraph/test/visitors/op/convolution_backprop.cpp index 4bd8c66ed278fc..7095b303465bd7 100644 --- a/ngraph/test/visitors/op/convolution_backprop.cpp +++ b/ngraph/test/visitors/op/convolution_backprop.cpp @@ -32,7 +32,7 @@ TEST(attributes, convolution_backprop_op) { dilations, op::PadType::VALID); NodeBuilder builder(convolution); - auto g_convolution = as_type_ptr(builder.create()); + auto g_convolution = ov::as_type_ptr(builder.create()); // attribute count const auto expected_attr_count = 6; @@ -75,7 +75,7 @@ TEST(attributes, convolution_backprop_output_shape_output_padding) { padType, output_padding); NodeBuilder builder(convolution); - const auto g_convolution = as_type_ptr(builder.create()); + const auto g_convolution = ov::as_type_ptr(builder.create()); // attribute count const auto expected_attr_count = 6; diff --git a/ngraph/test/visitors/op/cum_sum.cpp b/ngraph/test/visitors/op/cum_sum.cpp index 66ac11a8b8bd1e..e82d3cb3192727 100644 --- a/ngraph/test/visitors/op/cum_sum.cpp +++ b/ngraph/test/visitors/op/cum_sum.cpp @@ -20,7 +20,7 @@ TEST(attributes, cum_sum_op_default_attributes_no_axis_input) { auto cs = make_shared(A); NodeBuilder builder(cs); - auto g_cs = as_type_ptr(builder.create()); + auto g_cs = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 2; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); @@ -38,7 +38,7 @@ TEST(attributes, cum_sum_op_default_attributes) { auto cs = make_shared(A, axis); NodeBuilder builder(cs); - auto g_cs = as_type_ptr(builder.create()); + auto g_cs = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 2; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); @@ -58,7 +58,7 @@ TEST(attributes, cum_sum_op_custom_attributes) { auto cs = make_shared(A, axis, exclusive, reverse); NodeBuilder builder(cs); - auto g_cs = as_type_ptr(builder.create()); + auto g_cs = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 2; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/deformable_convolution.cpp b/ngraph/test/visitors/op/deformable_convolution.cpp index 26361c53ff1527..f76d9b67d0336a 100644 --- a/ngraph/test/visitors/op/deformable_convolution.cpp +++ b/ngraph/test/visitors/op/deformable_convolution.cpp @@ -26,7 +26,7 @@ TEST(attributes, deformable_convolution_default_attributes) { auto convolution = make_shared(data, offsets, filters, strides, pads_begin, pads_end, dilations); NodeBuilder builder(convolution); - auto g_convolution = as_type_ptr(builder.create()); + auto g_convolution = ov::as_type_ptr(builder.create()); // attribute count const auto expected_attr_count = 8; @@ -66,7 +66,7 @@ TEST(attributes, deformable_convolution_attributes) { 2, true); NodeBuilder builder(convolution); - auto g_convolution = as_type_ptr(builder.create()); + auto g_convolution = ov::as_type_ptr(builder.create()); // attribute count const auto expected_attr_count = 8; diff --git a/ngraph/test/visitors/op/deformable_psroi_pooling.cpp b/ngraph/test/visitors/op/deformable_psroi_pooling.cpp index 5a8cd667eb800e..b8104ac0b58452 100644 --- a/ngraph/test/visitors/op/deformable_psroi_pooling.cpp +++ b/ngraph/test/visitors/op/deformable_psroi_pooling.cpp @@ -38,7 +38,7 @@ TEST(attributes, deformable_psroi_pooling_op) { trans_std, part_size); NodeBuilder builder(op); - auto g_op = as_type_ptr(builder.create()); + auto g_op = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_op->get_output_dim(), op->get_output_dim()); EXPECT_EQ(g_op->get_spatial_scale(), op->get_spatial_scale()); diff --git a/ngraph/test/visitors/op/depth_to_space.cpp b/ngraph/test/visitors/op/depth_to_space.cpp index 3bbf66f1909daf..8a9ac3d87b2867 100644 --- a/ngraph/test/visitors/op/depth_to_space.cpp +++ b/ngraph/test/visitors/op/depth_to_space.cpp @@ -24,7 +24,7 @@ TEST(attributes, depth_to_space) { const auto dts = std::make_shared(data, mode, block_size); NodeBuilder builder(dts); - auto g_dts = as_type_ptr(builder.create()); + auto g_dts = ov::as_type_ptr(builder.create()); // attribute count const auto expected_attr_count = 2; diff --git a/ngraph/test/visitors/op/detection_output.cpp b/ngraph/test/visitors/op/detection_output.cpp index aba42f4aecb008..488bbf423d3576 100644 --- a/ngraph/test/visitors/op/detection_output.cpp +++ b/ngraph/test/visitors/op/detection_output.cpp @@ -45,7 +45,7 @@ TEST(attributes, detection_output_op) { auto detection_output = make_shared(box_logits, class_preds, proposals, aux_class_preds, aux_box_pred, attrs); NodeBuilder builder(detection_output); - auto g_detection_output = as_type_ptr(builder.create()); + auto g_detection_output = ov::as_type_ptr(builder.create()); const auto do_attrs = detection_output->get_attrs(); const auto g_do_attrs = g_detection_output->get_attrs(); diff --git a/ngraph/test/visitors/op/einsum.cpp b/ngraph/test/visitors/op/einsum.cpp index 8ec2a8a12bea27..86e0452027b802 100644 --- a/ngraph/test/visitors/op/einsum.cpp +++ b/ngraph/test/visitors/op/einsum.cpp @@ -20,6 +20,6 @@ TEST(attributes, einsum_v7_op) { std::string equation = "ab,bc->ac"; auto einsum = make_shared(OutputVector{input1, input2}, equation); NodeBuilder builder(einsum); - auto g_einsum = as_type_ptr(builder.create()); + auto g_einsum = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_einsum->get_equation(), einsum->get_equation()); } diff --git a/ngraph/test/visitors/op/elu.cpp b/ngraph/test/visitors/op/elu.cpp index 8b7d326121eef4..ecdd82445516c1 100644 --- a/ngraph/test/visitors/op/elu.cpp +++ b/ngraph/test/visitors/op/elu.cpp @@ -24,7 +24,7 @@ TEST(attributes, elu_op) { const auto elu = make_shared(data, alpha); NodeBuilder builder(elu); - auto g_elu = as_type_ptr(builder.create()); + auto g_elu = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_elu->get_alpha(), elu->get_alpha()); } diff --git a/ngraph/test/visitors/op/extractimagepatches.cpp b/ngraph/test/visitors/op/extractimagepatches.cpp index d9142a3757ab02..a19ece5d53ce25 100644 --- a/ngraph/test/visitors/op/extractimagepatches.cpp +++ b/ngraph/test/visitors/op/extractimagepatches.cpp @@ -27,7 +27,7 @@ TEST(attributes, extractimagepatches_op) { auto extractimagepatches = make_shared(data, sizes, strides, rates, padtype_padding); NodeBuilder builder(extractimagepatches); - auto g_extractimagepatches = as_type_ptr(builder.create()); + auto g_extractimagepatches = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 4; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/fake_quantize.cpp b/ngraph/test/visitors/op/fake_quantize.cpp index 0ffe875785ef5d..bbba136cfaa8ac 100644 --- a/ngraph/test/visitors/op/fake_quantize.cpp +++ b/ngraph/test/visitors/op/fake_quantize.cpp @@ -30,7 +30,7 @@ TEST(attributes, fake_quantize_op) { const auto fake_quantize = make_shared(data, input_low, input_high, output_low, output_high, levels, auto_broadcast); NodeBuilder builder(fake_quantize); - auto g_fake_quantize = as_type_ptr(builder.create()); + auto g_fake_quantize = ov::as_type_ptr(builder.create()); // attribute count const auto expected_attr_count = 2; diff --git a/ngraph/test/visitors/op/gather.cpp b/ngraph/test/visitors/op/gather.cpp index 5d646bd2a60e59..b1d4cbdf9710d3 100644 --- a/ngraph/test/visitors/op/gather.cpp +++ b/ngraph/test/visitors/op/gather.cpp @@ -23,7 +23,7 @@ TEST(attributes, gather_v7_op) { auto gather = make_shared(data, indices, axis, batch_dims); NodeBuilder builder(gather); - auto g_gather = as_type_ptr(builder.create()); + auto g_gather = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_gather->get_batch_dims(), gather->get_batch_dims()); } @@ -37,7 +37,7 @@ TEST(attributes, gather_v8_op) { auto gather = make_shared(data, indices, axis, batch_dims); NodeBuilder builder(gather); - auto g_gather = as_type_ptr(builder.create()); + auto g_gather = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_gather->get_batch_dims(), gather->get_batch_dims()); } diff --git a/ngraph/test/visitors/op/gelu.cpp b/ngraph/test/visitors/op/gelu.cpp index ec4b180bfb2733..e1b0cb3461aa8e 100644 --- a/ngraph/test/visitors/op/gelu.cpp +++ b/ngraph/test/visitors/op/gelu.cpp @@ -18,7 +18,7 @@ TEST(attributes, gelu_op) { const auto approximation_mode = op::GeluApproximationMode::ERF; const auto gelu = make_shared(data_input, approximation_mode); NodeBuilder builder(gelu); - auto g_gelu = as_type_ptr(builder.create()); + auto g_gelu = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_gelu->get_approximation_mode(), gelu->get_approximation_mode()); } diff --git a/ngraph/test/visitors/op/grn.cpp b/ngraph/test/visitors/op/grn.cpp index df8b5d6554b9ff..9d71e77520e170 100644 --- a/ngraph/test/visitors/op/grn.cpp +++ b/ngraph/test/visitors/op/grn.cpp @@ -20,7 +20,7 @@ TEST(attributes, grn_op) { auto grn = make_shared(data, bias); NodeBuilder builder(grn); - auto g_grn = as_type_ptr(builder.create()); + auto g_grn = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 1; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/group_conv.cpp b/ngraph/test/visitors/op/group_conv.cpp index 4b826e86c64899..4ee94e6633374e 100644 --- a/ngraph/test/visitors/op/group_conv.cpp +++ b/ngraph/test/visitors/op/group_conv.cpp @@ -32,7 +32,7 @@ TEST(attributes, group_conv_op) { dilations, op::PadType::VALID); NodeBuilder builder(group_conv); - auto g_group_conv = as_type_ptr(builder.create()); + auto g_group_conv = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_group_conv->get_strides(), group_conv->get_strides()); EXPECT_EQ(g_group_conv->get_pads_begin(), group_conv->get_pads_begin()); EXPECT_EQ(g_group_conv->get_pads_end(), group_conv->get_pads_end()); @@ -63,7 +63,7 @@ TEST(attributes, group_conv_backprop_data_op) { auto_pad, output_padding); NodeBuilder builder(gcbd); - const auto g_gcbd = as_type_ptr(builder.create()); + const auto g_gcbd = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_gcbd->get_strides(), gcbd->get_strides()); EXPECT_EQ(g_gcbd->get_pads_begin(), gcbd->get_pads_begin()); diff --git a/ngraph/test/visitors/op/interpolate.cpp b/ngraph/test/visitors/op/interpolate.cpp index dab9d978db051e..2e1f96ff3b8bbf 100644 --- a/ngraph/test/visitors/op/interpolate.cpp +++ b/ngraph/test/visitors/op/interpolate.cpp @@ -31,7 +31,7 @@ TEST(attributes, interpolate_op) { auto interpolate = make_shared(img, out_shape, interp_atrs); NodeBuilder builder(interpolate); - auto g_interpolate = as_type_ptr(builder.create()); + auto g_interpolate = ov::as_type_ptr(builder.create()); const auto i_attrs = interpolate->get_attrs(); const auto g_i_attrs = g_interpolate->get_attrs(); diff --git a/ngraph/test/visitors/op/lrn.cpp b/ngraph/test/visitors/op/lrn.cpp index 5b2485367da020..90f85d4dd1d56a 100644 --- a/ngraph/test/visitors/op/lrn.cpp +++ b/ngraph/test/visitors/op/lrn.cpp @@ -28,7 +28,7 @@ TEST(attributes, lrn_op) { const auto lrn = make_shared(arg, axes, alpha, beta, bias, size); NodeBuilder builder(lrn); - auto g_lrn = as_type_ptr(builder.create()); + auto g_lrn = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_lrn->get_alpha(), lrn->get_alpha()); EXPECT_EQ(g_lrn->get_beta(), lrn->get_beta()); diff --git a/ngraph/test/visitors/op/lstm_cell.cpp b/ngraph/test/visitors/op/lstm_cell.cpp index 7932b5339413c3..71f3be63f76b04 100644 --- a/ngraph/test/visitors/op/lstm_cell.cpp +++ b/ngraph/test/visitors/op/lstm_cell.cpp @@ -41,7 +41,7 @@ TEST(attributes, lstm_cell_op) { activations_beta, clip); NodeBuilder builder(lstm_cell); - auto g_lstm_cell = as_type_ptr(builder.create()); + auto g_lstm_cell = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_lstm_cell->get_hidden_size(), lstm_cell->get_hidden_size()); EXPECT_EQ(g_lstm_cell->get_activations(), lstm_cell->get_activations()); diff --git a/ngraph/test/visitors/op/lstm_sequence.cpp b/ngraph/test/visitors/op/lstm_sequence.cpp index 0dd120768763ae..d9b9d1d976e4e7 100644 --- a/ngraph/test/visitors/op/lstm_sequence.cpp +++ b/ngraph/test/visitors/op/lstm_sequence.cpp @@ -55,7 +55,7 @@ TEST(attributes, lstm_sequence_op) { activations, clip_threshold); NodeBuilder builder(lstm_sequence); - auto g_lstm_sequence = as_type_ptr(builder.create()); + auto g_lstm_sequence = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_lstm_sequence->get_hidden_size(), lstm_sequence->get_hidden_size()); EXPECT_EQ(g_lstm_sequence->get_activations(), lstm_sequence->get_activations()); diff --git a/ngraph/test/visitors/op/matmul.cpp b/ngraph/test/visitors/op/matmul.cpp index e9b9a99c46b9bb..9477333f25499f 100644 --- a/ngraph/test/visitors/op/matmul.cpp +++ b/ngraph/test/visitors/op/matmul.cpp @@ -26,7 +26,7 @@ TEST(attributes, matmul_op) { auto matmul = make_shared(A, B, transpose_a, transpose_b); NodeBuilder builder(matmul); - auto g_matmul = as_type_ptr(builder.create()); + auto g_matmul = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_matmul->get_transpose_a(), matmul->get_transpose_a()); EXPECT_EQ(g_matmul->get_transpose_b(), matmul->get_transpose_b()); diff --git a/ngraph/test/visitors/op/matrix_nms.cpp b/ngraph/test/visitors/op/matrix_nms.cpp index e4252652aefb09..c0d499f70fcafa 100644 --- a/ngraph/test/visitors/op/matrix_nms.cpp +++ b/ngraph/test/visitors/op/matrix_nms.cpp @@ -37,7 +37,7 @@ TEST(attributes, matrix_nms_v8_op_custom_attributes) { auto nms = make_shared(boxes, scores, attrs); NodeBuilder builder(nms); - auto g_nms = as_type_ptr(builder.create()); + auto g_nms = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 11; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); @@ -76,7 +76,7 @@ TEST(attributes, matrix_nms_v8_op_default_attributes) { auto nms = make_shared(boxes, scores, opset8::MatrixNms::Attributes()); NodeBuilder builder(nms); - auto g_nms = as_type_ptr(builder.create()); + auto g_nms = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 11; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/max_pool.cpp b/ngraph/test/visitors/op/max_pool.cpp index 9ff9d0881a195b..1672425612b90c 100644 --- a/ngraph/test/visitors/op/max_pool.cpp +++ b/ngraph/test/visitors/op/max_pool.cpp @@ -27,7 +27,7 @@ TEST(attributes, max_pool_op) { auto max_pool = make_shared(data, strides, pads_begin, pads_end, kernel, rounding_mode, auto_pad); NodeBuilder builder(max_pool); - auto g_max_pool = as_type_ptr(builder.create()); + auto g_max_pool = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_max_pool->get_strides(), max_pool->get_strides()); EXPECT_EQ(g_max_pool->get_pads_begin(), max_pool->get_pads_begin()); @@ -60,7 +60,7 @@ TEST(attributes, max_pool_v8_op) { auto_pad, index_element_type); NodeBuilder builder(max_pool); - auto g_max_pool = as_type_ptr(builder.create()); + auto g_max_pool = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_max_pool->get_strides(), max_pool->get_strides()); EXPECT_EQ(g_max_pool->get_dilations(), max_pool->get_dilations()); diff --git a/ngraph/test/visitors/op/multiclass_nms.cpp b/ngraph/test/visitors/op/multiclass_nms.cpp index 54d8840fda9e72..ce89e731463207 100644 --- a/ngraph/test/visitors/op/multiclass_nms.cpp +++ b/ngraph/test/visitors/op/multiclass_nms.cpp @@ -36,7 +36,7 @@ TEST(attributes, multiclass_nms_v8_op_custom_attributes) { auto nms = make_shared(boxes, scores, attrs); NodeBuilder builder(nms); - auto g_nms = as_type_ptr(builder.create()); + auto g_nms = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 10; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); @@ -73,7 +73,7 @@ TEST(attributes, multiclass_nms_v8_op_default_attributes) { auto nms = make_shared(boxes, scores, opset8::MulticlassNms::Attributes()); NodeBuilder builder(nms); - auto g_nms = as_type_ptr(builder.create()); + auto g_nms = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 10; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/mvn.cpp b/ngraph/test/visitors/op/mvn.cpp index 7bbfefbf7af440..c0c955bbc11570 100644 --- a/ngraph/test/visitors/op/mvn.cpp +++ b/ngraph/test/visitors/op/mvn.cpp @@ -26,7 +26,7 @@ TEST(attributes, mvn_v1_op) { const auto op = make_shared(data, true, false, 0.1); op->set_reduction_axes(axes); NodeBuilder builder(op); - const auto g_op = as_type_ptr(builder.create()); + const auto g_op = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 4; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); @@ -44,7 +44,7 @@ TEST(attributes, mvn_v6_op) { const auto op = make_shared(data, axes, false, 0.1, op::MVNEpsMode::INSIDE_SQRT); NodeBuilder builder(op); - const auto g_op = as_type_ptr(builder.create()); + const auto g_op = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 3; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/non_max_suppression.cpp b/ngraph/test/visitors/op/non_max_suppression.cpp index e9d9b2cb0b3269..5b232302d23566 100644 --- a/ngraph/test/visitors/op/non_max_suppression.cpp +++ b/ngraph/test/visitors/op/non_max_suppression.cpp @@ -26,7 +26,7 @@ TEST(attributes, non_max_suppression_op_custom_attributes) { auto nms = make_shared(boxes, scores, box_encoding, sort_result_descending); NodeBuilder builder(nms); - auto g_nms = as_type_ptr(builder.create()); + auto g_nms = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_nms->get_box_encoding(), nms->get_box_encoding()); EXPECT_EQ(g_nms->get_sort_result_descending(), nms->get_sort_result_descending()); @@ -39,7 +39,7 @@ TEST(attributes, non_max_suppression_op_default_attributes) { auto nms = make_shared(boxes, scores); NodeBuilder builder(nms); - auto g_nms = as_type_ptr(builder.create()); + auto g_nms = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_nms->get_box_encoding(), nms->get_box_encoding()); EXPECT_EQ(g_nms->get_sort_result_descending(), nms->get_sort_result_descending()); @@ -56,7 +56,7 @@ TEST(attributes, non_max_suppression_v3_op_custom_attributes) { auto nms = make_shared(boxes, scores, box_encoding, sort_result_descending, output_type); NodeBuilder builder(nms); - auto g_nms = as_type_ptr(builder.create()); + auto g_nms = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_nms->get_box_encoding(), nms->get_box_encoding()); EXPECT_EQ(g_nms->get_sort_result_descending(), nms->get_sort_result_descending()); @@ -70,7 +70,7 @@ TEST(attributes, non_max_suppression_v3_op_default_attributes) { auto nms = make_shared(boxes, scores); NodeBuilder builder(nms); - auto g_nms = as_type_ptr(builder.create()); + auto g_nms = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_nms->get_box_encoding(), nms->get_box_encoding()); EXPECT_EQ(g_nms->get_sort_result_descending(), nms->get_sort_result_descending()); diff --git a/ngraph/test/visitors/op/normalize_l2.cpp b/ngraph/test/visitors/op/normalize_l2.cpp index d86e708ac927dc..4715c558085e9d 100644 --- a/ngraph/test/visitors/op/normalize_l2.cpp +++ b/ngraph/test/visitors/op/normalize_l2.cpp @@ -19,7 +19,7 @@ void static test_normalize_l2_attributes(float eps, op::EpsMode eps_mode) { auto normalize_l2 = make_shared(data, axes, eps, eps_mode); NodeBuilder builder(normalize_l2); - auto g_normalize_l2 = as_type_ptr(builder.create()); + auto g_normalize_l2 = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 2; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/one_hot.cpp b/ngraph/test/visitors/op/one_hot.cpp index c59482e2aade90..0366c69197e587 100644 --- a/ngraph/test/visitors/op/one_hot.cpp +++ b/ngraph/test/visitors/op/one_hot.cpp @@ -27,7 +27,7 @@ TEST(attributes, one_hot_op) { auto one_hot = make_shared(indices, depth, on_value, off_value, axis); NodeBuilder builder(one_hot); - auto g_one_hot = as_type_ptr(builder.create()); + auto g_one_hot = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_one_hot->get_axis(), one_hot->get_axis()); } diff --git a/ngraph/test/visitors/op/pad.cpp b/ngraph/test/visitors/op/pad.cpp index 314bc1a3d64f06..a2824b41d218e0 100644 --- a/ngraph/test/visitors/op/pad.cpp +++ b/ngraph/test/visitors/op/pad.cpp @@ -26,7 +26,7 @@ TEST(attributes, pad_op) { auto pad = make_shared(arg, pads_begin, pads_end, pad_mode); NodeBuilder builder(pad); - auto g_pad = as_type_ptr(builder.create()); + auto g_pad = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_pad->get_pad_mode(), pad->get_pad_mode()); } diff --git a/ngraph/test/visitors/op/parameter.cpp b/ngraph/test/visitors/op/parameter.cpp index 8eab7293ef86a8..cfa1c8d210e369 100644 --- a/ngraph/test/visitors/op/parameter.cpp +++ b/ngraph/test/visitors/op/parameter.cpp @@ -19,7 +19,7 @@ TEST(attributes, parameter_op) { auto parameter = std::make_shared(element::f32, PartialShape{Dimension{1}, Dimension{4}}); NodeBuilder builder(parameter); - auto g_parameter = as_type_ptr(builder.create()); + auto g_parameter = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 2; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/prior_box.cpp b/ngraph/test/visitors/op/prior_box.cpp index 3e7f072e35ce2c..7ff922c62ce7e6 100644 --- a/ngraph/test/visitors/op/prior_box.cpp +++ b/ngraph/test/visitors/op/prior_box.cpp @@ -37,7 +37,7 @@ TEST(attributes, prior_box_op) { auto prior_box = make_shared(layer_shape, image_shape, attrs); NodeBuilder builder(prior_box); - auto g_prior_box = as_type_ptr(builder.create()); + auto g_prior_box = ov::as_type_ptr(builder.create()); const auto prior_box_attrs = prior_box->get_attrs(); const auto g_prior_box_attrs = g_prior_box->get_attrs(); diff --git a/ngraph/test/visitors/op/prior_box_clustered.cpp b/ngraph/test/visitors/op/prior_box_clustered.cpp index 4544616fc14a64..d99ab449ecf256 100644 --- a/ngraph/test/visitors/op/prior_box_clustered.cpp +++ b/ngraph/test/visitors/op/prior_box_clustered.cpp @@ -29,7 +29,7 @@ TEST(attributes, prior_box_clustered_op) { auto pbc = make_shared(layer_shape, image_shape, attrs); NodeBuilder builder(pbc); - auto g_pbc = as_type_ptr(builder.create()); + auto g_pbc = ov::as_type_ptr(builder.create()); const auto pbc_attrs = pbc->get_attrs(); const auto g_pbc_attrs = g_pbc->get_attrs(); const auto expected_attr_count = 8; diff --git a/ngraph/test/visitors/op/proposal.cpp b/ngraph/test/visitors/op/proposal.cpp index dbb61dec8d0b1a..35a6bf48ee0360 100644 --- a/ngraph/test/visitors/op/proposal.cpp +++ b/ngraph/test/visitors/op/proposal.cpp @@ -40,7 +40,7 @@ TEST(attributes, proposal_op) { auto proposal = make_shared(class_probs, class_logits, image_shape, attrs); NodeBuilder builder(proposal); - auto g_proposal = as_type_ptr(builder.create()); + auto g_proposal = ov::as_type_ptr(builder.create()); const auto proposal_attrs = proposal->get_attrs(); const auto g_proposal_attrs = g_proposal->get_attrs(); diff --git a/ngraph/test/visitors/op/psroi_pooling.cpp b/ngraph/test/visitors/op/psroi_pooling.cpp index 5082efdc0239ec..41b65a7d3356f2 100644 --- a/ngraph/test/visitors/op/psroi_pooling.cpp +++ b/ngraph/test/visitors/op/psroi_pooling.cpp @@ -37,7 +37,7 @@ TEST(attributes, psroi_pooling_op) { spatial_bins_y, mode); NodeBuilder builder(psroi_pool); - auto g_psroi_pool = as_type_ptr(builder.create()); + auto g_psroi_pool = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_psroi_pool->get_output_dim(), psroi_pool->get_output_dim()); EXPECT_EQ(g_psroi_pool->get_group_size(), psroi_pool->get_group_size()); diff --git a/ngraph/test/visitors/op/random_uniform.cpp b/ngraph/test/visitors/op/random_uniform.cpp index 8f020a2683a234..0e6a194915456e 100644 --- a/ngraph/test/visitors/op/random_uniform.cpp +++ b/ngraph/test/visitors/op/random_uniform.cpp @@ -22,7 +22,7 @@ TEST(attributes, random_uniform_op) { const auto random_uniform = make_shared(out_shape, min_val, max_val, element::Type_t::f32, 150, 10); NodeBuilder builder(random_uniform); - auto g_random_uniform = as_type_ptr(builder.create()); + auto g_random_uniform = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 3; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/reduce_ops.hpp b/ngraph/test/visitors/op/reduce_ops.hpp index d70b498fbf42f2..7fc3c2e914b4a4 100644 --- a/ngraph/test/visitors/op/reduce_ops.hpp +++ b/ngraph/test/visitors/op/reduce_ops.hpp @@ -39,7 +39,7 @@ TYPED_TEST_P(ReduceOpsAttrTest, reduce_ops) NodeBuilder builder(reduce_op); const auto expected_attr_count = 1; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); - auto g_reduce_op = as_type_ptr(builder.create()); + auto g_reduce_op = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_reduce_op->get_keep_dims(), reduce_op->get_keep_dims()); } diff --git a/ngraph/test/visitors/op/region_yolo.cpp b/ngraph/test/visitors/op/region_yolo.cpp index 0a3eb85ce6e57b..536774c4d8ed5d 100644 --- a/ngraph/test/visitors/op/region_yolo.cpp +++ b/ngraph/test/visitors/op/region_yolo.cpp @@ -39,7 +39,7 @@ TEST(attributes, region_yolo_op) { end_axis, anchors); NodeBuilder builder(region_yolo); - auto g_region_yolo = as_type_ptr(builder.create()); + auto g_region_yolo = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_region_yolo->get_num_coords(), region_yolo->get_num_coords()); EXPECT_EQ(g_region_yolo->get_num_classes(), region_yolo->get_num_classes()); diff --git a/ngraph/test/visitors/op/reorg_yolo.cpp b/ngraph/test/visitors/op/reorg_yolo.cpp index 3b11bc547b816a..3ad1fc7318ea3f 100644 --- a/ngraph/test/visitors/op/reorg_yolo.cpp +++ b/ngraph/test/visitors/op/reorg_yolo.cpp @@ -22,7 +22,7 @@ TEST(attributes, reorg_yolo_op_stride) { const auto op = make_shared(data, 2); NodeBuilder builder(op); - const auto g_op = as_type_ptr(builder.create()); + const auto g_op = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_op->get_strides(), op->get_strides()); } @@ -33,7 +33,7 @@ TEST(attributes, reorg_yolo_op_strides) { const auto op = make_shared(data, Strides{2}); NodeBuilder builder(op); - const auto g_op = as_type_ptr(builder.create()); + const auto g_op = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_op->get_strides(), op->get_strides()); } diff --git a/ngraph/test/visitors/op/reshape.cpp b/ngraph/test/visitors/op/reshape.cpp index 2877f99fe39df7..c21841623a4e23 100644 --- a/ngraph/test/visitors/op/reshape.cpp +++ b/ngraph/test/visitors/op/reshape.cpp @@ -25,7 +25,7 @@ TEST(attributes, reshape_op) { auto reshape = make_shared(data, pattern, special_zero); NodeBuilder builder(reshape); - auto g_reshape = as_type_ptr(builder.create()); + auto g_reshape = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 1; diff --git a/ngraph/test/visitors/op/reverse.cpp b/ngraph/test/visitors/op/reverse.cpp index af7130f1defaf4..48c24c178ac94f 100644 --- a/ngraph/test/visitors/op/reverse.cpp +++ b/ngraph/test/visitors/op/reverse.cpp @@ -23,7 +23,7 @@ TEST(attributes, reverse_op_enum_mode) { auto reverse = make_shared(data, reversed_axes, opset1::Reverse::Mode::INDEX); NodeBuilder builder(reverse); - auto g_reverse = as_type_ptr(builder.create()); + auto g_reverse = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_reverse->get_mode(), reverse->get_mode()); } @@ -37,7 +37,7 @@ TEST(attributes, reverse_op_string_mode) { auto reverse = make_shared(data, reversed_axes, mode); NodeBuilder builder(reverse); - auto g_reverse = as_type_ptr(builder.create()); + auto g_reverse = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_reverse->get_mode(), reverse->get_mode()); } diff --git a/ngraph/test/visitors/op/reverse_sequence.cpp b/ngraph/test/visitors/op/reverse_sequence.cpp index 55b11d6b730450..75613e26a6caa0 100644 --- a/ngraph/test/visitors/op/reverse_sequence.cpp +++ b/ngraph/test/visitors/op/reverse_sequence.cpp @@ -26,7 +26,7 @@ TEST(attributes, reverse_sequence_op) { auto reverse_sequence = make_shared(data, seq_indices, batch_axis, seq_axis); NodeBuilder builder(reverse_sequence); - auto g_reverse_sequence = as_type_ptr(builder.create()); + auto g_reverse_sequence = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_reverse_sequence->get_origin_batch_axis(), reverse_sequence->get_origin_batch_axis()); EXPECT_EQ(g_reverse_sequence->get_origin_sequence_axis(), reverse_sequence->get_origin_sequence_axis()); diff --git a/ngraph/test/visitors/op/rnn_cell.cpp b/ngraph/test/visitors/op/rnn_cell.cpp index 2a1bf47b868289..ff46fba29d86b1 100644 --- a/ngraph/test/visitors/op/rnn_cell.cpp +++ b/ngraph/test/visitors/op/rnn_cell.cpp @@ -33,7 +33,7 @@ TEST(attributes, rnn_cell_op_custom_attributes) { make_shared(X, H, W, R, hidden_size, activations, activations_alpha, activations_beta, clip); NodeBuilder builder(rnn_cell); - auto g_rnn_cell = as_type_ptr(builder.create()); + auto g_rnn_cell = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_rnn_cell->get_hidden_size(), rnn_cell->get_hidden_size()); EXPECT_EQ(g_rnn_cell->get_clip(), rnn_cell->get_clip()); @@ -54,7 +54,7 @@ TEST(attributes, rnn_cell_op_default_attributes) { auto rnn_cell = make_shared(X, H, W, R, hidden_size); NodeBuilder builder(rnn_cell); - auto g_rnn_cell = as_type_ptr(builder.create()); + auto g_rnn_cell = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_rnn_cell->get_hidden_size(), rnn_cell->get_hidden_size()); EXPECT_EQ(g_rnn_cell->get_clip(), rnn_cell->get_clip()); diff --git a/ngraph/test/visitors/op/roi_pooling.cpp b/ngraph/test/visitors/op/roi_pooling.cpp index cc7baee5499202..553b3420aaa389 100644 --- a/ngraph/test/visitors/op/roi_pooling.cpp +++ b/ngraph/test/visitors/op/roi_pooling.cpp @@ -23,7 +23,7 @@ TEST(attributes, roi_pooling_op) { const auto op = make_shared(data, coords, Shape{5, 5}, 0.123, "bilinear"); NodeBuilder builder(op); - const auto g_op = as_type_ptr(builder.create()); + const auto g_op = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_op->get_output_size(), op->get_output_size()); EXPECT_EQ(g_op->get_spatial_scale(), op->get_spatial_scale()); diff --git a/ngraph/test/visitors/op/round.cpp b/ngraph/test/visitors/op/round.cpp index ccb6004ce08c50..7d4efd98f1b606 100644 --- a/ngraph/test/visitors/op/round.cpp +++ b/ngraph/test/visitors/op/round.cpp @@ -21,7 +21,7 @@ void static test_mode(opset5::Round::RoundMode mode) { auto data = make_shared(element::f32, Shape{200}); auto round = make_shared(data, mode); NodeBuilder builder(round); - auto g_round = as_type_ptr(builder.create()); + auto g_round = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_round->get_mode(), round->get_mode()); } diff --git a/ngraph/test/visitors/op/select.cpp b/ngraph/test/visitors/op/select.cpp index 428897cef3bb2a..c3a5925a88c2fa 100644 --- a/ngraph/test/visitors/op/select.cpp +++ b/ngraph/test/visitors/op/select.cpp @@ -26,6 +26,6 @@ TEST(attributes, select) { const auto expected_attr_count = 1; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); - auto g_select = as_type_ptr(builder.create()); + auto g_select = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_select->get_autob(), select->get_autob()); } diff --git a/ngraph/test/visitors/op/shuffle_channels.cpp b/ngraph/test/visitors/op/shuffle_channels.cpp index 25af8fad75766a..173d451019a223 100644 --- a/ngraph/test/visitors/op/shuffle_channels.cpp +++ b/ngraph/test/visitors/op/shuffle_channels.cpp @@ -20,7 +20,7 @@ TEST(attributes, shuffle_channels_op) { auto groups = 2; auto shuffle_channels = make_shared(data, axis, groups); NodeBuilder builder(shuffle_channels); - auto g_shuffle_channels = as_type_ptr(builder.create()); + auto g_shuffle_channels = ov::as_type_ptr(builder.create()); const auto expected_attr_count = 2; EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); diff --git a/ngraph/test/visitors/op/softmax.cpp b/ngraph/test/visitors/op/softmax.cpp index 70064fd6495aa8..41423e11272cb6 100644 --- a/ngraph/test/visitors/op/softmax.cpp +++ b/ngraph/test/visitors/op/softmax.cpp @@ -22,7 +22,7 @@ TEST(attributes, softmax_op) { auto axis = 0; auto softmax = make_shared(data, axis); NodeBuilder builder(softmax); - auto g_softmax = as_type_ptr(builder.create()); + auto g_softmax = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_softmax->get_axis(), softmax->get_axis()); } diff --git a/ngraph/test/visitors/op/space_to_depth.cpp b/ngraph/test/visitors/op/space_to_depth.cpp index d64f46cf88db1e..f03bbe38079ff8 100644 --- a/ngraph/test/visitors/op/space_to_depth.cpp +++ b/ngraph/test/visitors/op/space_to_depth.cpp @@ -25,7 +25,7 @@ TEST(attributes, space_to_depth_op) { auto space_to_depth = make_shared(data, mode, block_size); NodeBuilder builder(space_to_depth); - auto g_space_to_depth = as_type_ptr(builder.create()); + auto g_space_to_depth = ov::as_type_ptr(builder.create()); // attribute count const auto expected_attr_count = 2; diff --git a/ngraph/test/visitors/op/split.cpp b/ngraph/test/visitors/op/split.cpp index e6e3edfa4292db..8f79676abe6911 100644 --- a/ngraph/test/visitors/op/split.cpp +++ b/ngraph/test/visitors/op/split.cpp @@ -23,7 +23,7 @@ TEST(attributes, split_op) { auto num_splits = 2; auto split = make_shared(data, axis, num_splits); NodeBuilder builder(split); - auto g_split = as_type_ptr(builder.create()); + auto g_split = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_split->get_num_splits(), split->get_num_splits()); } diff --git a/ngraph/test/visitors/op/strided_slice.cpp b/ngraph/test/visitors/op/strided_slice.cpp index 107504e1890c72..d430c18f04006e 100644 --- a/ngraph/test/visitors/op/strided_slice.cpp +++ b/ngraph/test/visitors/op/strided_slice.cpp @@ -39,7 +39,7 @@ TEST(attributes, strided_slice_op) { shrink_axis_mask, ellipsis_mask); NodeBuilder builder(strided_slice); - auto g_strided_slice = as_type_ptr(builder.create()); + auto g_strided_slice = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_strided_slice->get_begin_mask(), strided_slice->get_begin_mask()); EXPECT_EQ(g_strided_slice->get_end_mask(), strided_slice->get_end_mask()); diff --git a/ngraph/test/visitors/op/topk.cpp b/ngraph/test/visitors/op/topk.cpp index 63cab25c71fc1f..8985957d52bddd 100644 --- a/ngraph/test/visitors/op/topk.cpp +++ b/ngraph/test/visitors/op/topk.cpp @@ -27,7 +27,7 @@ TEST(attributes, topk_op) { auto topk = make_shared(data, k, axis, mode, sort_type); NodeBuilder builder(topk); - auto g_topk = as_type_ptr(builder.create()); + auto g_topk = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_topk->get_axis(), topk->get_axis()); EXPECT_EQ(g_topk->get_mode(), topk->get_mode()); diff --git a/ngraph/test/visitors/user_op.cpp b/ngraph/test/visitors/user_op.cpp index 152df20c93b45d..61290870422691 100644 --- a/ngraph/test/visitors/user_op.cpp +++ b/ngraph/test/visitors/user_op.cpp @@ -423,7 +423,7 @@ TEST(attributes, user_op) { saver.register_node(data, "data"); saver.register_node(result, "result"); builder.save_node(oracle); - auto g_oracle = as_type_ptr(builder.create()); + auto g_oracle = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_oracle->get_turing_model(), oracle->get_turing_model()); EXPECT_EQ(g_oracle->get_element_type(), oracle->get_element_type()); From ad40ecec0f1eb42c0b526dc69f467267d940e191 Mon Sep 17 00:00:00 2001 From: Bartosz Lesniewski Date: Fri, 20 Aug 2021 05:53:37 +0200 Subject: [PATCH 038/102] Revise CTCLoss OP (#6953) * Add visitor test to CTCLoss * Add CTC Loss SSLT * Add CTC Loss template tests * Use ngraph rtti macros * Code style fix --- .../functional/op_reference/ctc_loss.cpp | 174 ++++++++++++++++++ .../serialization/single_layer/ctc_loss.cpp | 43 +++++ ngraph/core/include/ngraph/op/ctc_loss.hpp | 6 +- ngraph/core/src/op/ctc_loss.cpp | 2 +- ngraph/test/CMakeLists.txt | 1 + ngraph/test/visitors/op/ctc_loss.cpp | 40 ++++ 6 files changed, 261 insertions(+), 5 deletions(-) create mode 100644 docs/template_plugin/tests/functional/op_reference/ctc_loss.cpp create mode 100644 inference-engine/tests/functional/inference_engine/serialization/single_layer/ctc_loss.cpp create mode 100644 ngraph/test/visitors/op/ctc_loss.cpp diff --git a/docs/template_plugin/tests/functional/op_reference/ctc_loss.cpp b/docs/template_plugin/tests/functional/op_reference/ctc_loss.cpp new file mode 100644 index 00000000000000..5579e17800fda4 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/ctc_loss.cpp @@ -0,0 +1,174 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include +#include +#include + +#include "base_reference_test.hpp" + +using namespace reference_tests; +using namespace ngraph; +using namespace InferenceEngine; + +namespace { + +struct CTCLossParams { + CTCLossParams(const bool collapseRepeated, const bool mergeRepeated, const bool findUnique, const Tensor& logitsTensor, const Tensor& logitsLenTensor, + const Tensor& labelsTensor, const Tensor& labelsLenTensor, const Tensor& blankIdxTensor, const Tensor& expectedTensor) + : preprocessCollapseRepeated(collapseRepeated), + ctcMergeRepeated(mergeRepeated), + unique(findUnique), + logits(logitsTensor), + logitsLen(logitsLenTensor), + labels(labelsTensor), + labelsLen(labelsLenTensor), + blankIdx(blankIdxTensor), + expected(expectedTensor) {} + + bool preprocessCollapseRepeated; + bool ctcMergeRepeated; + bool unique; + Tensor logits; + Tensor logitsLen; + Tensor labels; + Tensor labelsLen; + Tensor blankIdx; + Tensor expected; +}; + +class ReferenceCTCLossLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params); + inputData = {params.logits.data, params.logitsLen.data, params.labels.data, params.labelsLen.data, params.blankIdx.data}; + refOutData = {params.expected.data}; + } + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "fl_pr=" << param.logits.type << "_"; + result << "int_pr=" << param.logitsLen.type << "_"; + result << "collapse=" << param.preprocessCollapseRepeated << "_"; + result << "merge=" << param.ctcMergeRepeated << "_"; + result << "unique=" << param.unique << "_"; + result << "logits_shape=" << param.logits.shape << "_"; + result << "logits_len_shape=" << param.logitsLen.shape << "_"; + result << "labels_shape=" << param.labels.shape << "_"; + result << "labels_len_shape=" << param.labelsLen.shape << "_"; + result << "blank_idx_shape=" << param.blankIdx.shape << "_"; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const CTCLossParams& params) { + const auto A = std::make_shared(params.logits.type, params.logits.shape); // logits + const auto B = std::make_shared(params.logitsLen.type, params.logitsLen.shape); // logitsLen + const auto C = std::make_shared(params.labels.type, params.labels.shape); // labels + const auto D = std::make_shared(params.labelsLen.type, params.labelsLen.shape); // labelsLen + const auto E = std::make_shared(params.blankIdx.type, params.blankIdx.shape); // blankIdx + + const auto ctcLoss = std::make_shared(A, B, C, D, E, params.preprocessCollapseRepeated, params.ctcMergeRepeated, params.unique); + return std::make_shared(NodeVector {ctcLoss}, ParameterVector {A, B, C, D, E}); + } +}; + +TEST_P(ReferenceCTCLossLayerTest, CompareWithRefs) { + Exec(); +} + +INSTANTIATE_TEST_SUITE_P( + smoke_CTCLoss_With_Hardcoded_Refs, ReferenceCTCLossLayerTest, + ::testing::Values(CTCLossParams(false, false, false, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f32, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f32, std::vector {1.41223f, 14.1359f})), // refOut + CTCLossParams(false, false, true, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f32, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f32, std::vector {1.41223f, 14.1359f})), // refOut + CTCLossParams(false, true, false, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f32, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f32, std::vector {1.41156f, 13.2745f})), // refOut + CTCLossParams(true, false, false, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f32, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f32, std::vector {1.41223f, 14.1359f})), // refOut + CTCLossParams(false, true, true, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f32, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f32, std::vector {1.41156f, 13.2745f})), // refOut + CTCLossParams(true, true, true, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f32, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f32, std::vector {1.41223f, 13.2745f})), // refOut + // floating point type - float16 + CTCLossParams(false, false, false, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f16, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f16, std::vector {1.41223f, 14.1359f})), // refOut + CTCLossParams(false, false, true, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f16, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f16, std::vector {1.41223f, 14.1359f})), // refOut + CTCLossParams(false, true, false, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f16, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f16, std::vector {1.41156f, 13.2745f})), // refOut + CTCLossParams(true, false, false, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f16, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f16, std::vector {1.41223f, 14.1359f})), // refOut + CTCLossParams(false, true, true, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f16, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f16, std::vector {1.41156f, 13.2745f})), // refOut + CTCLossParams(true, true, true, // collapse repeated, merge repeated, unique + Tensor({2, 3, 3}, element::f16, std::vector {0, 1, 8, 5, 5, 2, 0, 7, 7, 10, 4, 5, 9, 0, 0, 5, 7, 0}), // logits + Tensor({2}, element::i32, std::vector {3, 3}), // logitsLen + Tensor({2, 3}, element::i32, std::vector {0, 1, 2, 1, 1, 1}), // labels + Tensor({2}, element::i32, std::vector {2, 1}), // labelsLen + Tensor({}, element::i32, std::vector {2}), // blankIdx + Tensor({2}, element::f16, std::vector {1.41223f, 13.2745f}))), // refOut + ReferenceCTCLossLayerTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/inference_engine/serialization/single_layer/ctc_loss.cpp b/inference-engine/tests/functional/inference_engine/serialization/single_layer/ctc_loss.cpp new file mode 100644 index 00000000000000..7055b2c3e96ed0 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/serialization/single_layer/ctc_loss.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "shared_test_classes/single_layer/ctc_loss.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +TEST_P(CTCLossLayerTest, Serialize) { Serialize(); } + +const std::vector fPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16}; +const std::vector iPrecisions = { + InferenceEngine::Precision::I32, + InferenceEngine::Precision::I64}; + +const std::vector preprocessCollapseRepeated = {true, false}; +const std::vector ctcMergeRepeated = {true, false}; +const std::vector unique = {true, false}; + +const auto ctcLossArgsSubset1 = ::testing::Combine( + ::testing::Values(std::vector({2, 3, 3})), // logits shape + ::testing::ValuesIn(std::vector>({{2, 3}, {3, 3}})), // logits length + ::testing::ValuesIn(std::vector>>( + {{{0, 1, 0}, {1, 0, 1}}, {{0, 1, 2}, {1, 1, 1}}})), // labels + ::testing::ValuesIn(std::vector>({{2, 2}, {2, 1}})), // labels length + ::testing::Values(2), // blank index + ::testing::ValuesIn(preprocessCollapseRepeated), + ::testing::ValuesIn(ctcMergeRepeated), + ::testing::ValuesIn(unique)); + +INSTANTIATE_TEST_SUITE_P(smoke_CTCLossSerialization, CTCLossLayerTest, + ::testing::Combine( + ctcLossArgsSubset1, + ::testing::ValuesIn(fPrecisions), + ::testing::ValuesIn(iPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + CTCLossLayerTest::getTestCaseName); +} // namespace diff --git a/ngraph/core/include/ngraph/op/ctc_loss.hpp b/ngraph/core/include/ngraph/op/ctc_loss.hpp index ea42b7186b0841..b4ddf80d5eb3a3 100644 --- a/ngraph/core/include/ngraph/op/ctc_loss.hpp +++ b/ngraph/core/include/ngraph/op/ctc_loss.hpp @@ -11,10 +11,8 @@ namespace op { namespace v4 { class NGRAPH_API CTCLoss : public Op { public: - static constexpr NodeTypeInfo type_info{"CTCLoss", 0}; - const NodeTypeInfo& get_type_info() const override { - return type_info; - } + NGRAPH_RTTI_DECLARATION; + CTCLoss() = default; /// \brief Constructs a CTCLoss operation /// diff --git a/ngraph/core/src/op/ctc_loss.cpp b/ngraph/core/src/op/ctc_loss.cpp index 8f81a69459e04e..6f0da3bfc0868f 100644 --- a/ngraph/core/src/op/ctc_loss.cpp +++ b/ngraph/core/src/op/ctc_loss.cpp @@ -9,7 +9,7 @@ using namespace std; using namespace ngraph; -constexpr NodeTypeInfo op::v4::CTCLoss::type_info; +NGRAPH_RTTI_DEFINITION(op::v4::CTCLoss, "CTCLoss", 4); op::v4::CTCLoss::CTCLoss(const Output& logits, const Output& logit_length, diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 89197aee7aefe4..8a7c7e1a0ba7df 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -256,6 +256,7 @@ set(SRC visitors/op/convolution_backprop.cpp visitors/op/cos.cpp visitors/op/cosh.cpp + visitors/op/ctc_loss.cpp visitors/op/cum_sum.cpp visitors/op/deformable_convolution.cpp visitors/op/deformable_psroi_pooling.cpp diff --git a/ngraph/test/visitors/op/ctc_loss.cpp b/ngraph/test/visitors/op/ctc_loss.cpp new file mode 100644 index 00000000000000..0e35c6af64d95e --- /dev/null +++ b/ngraph/test/visitors/op/ctc_loss.cpp @@ -0,0 +1,40 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "ngraph/op/util/attr_types.hpp" +#include "ngraph/opsets/opset1.hpp" +#include "ngraph/opsets/opset3.hpp" +#include "ngraph/opsets/opset4.hpp" +#include "ngraph/opsets/opset5.hpp" +#include "util/visitor.hpp" + +using namespace std; +using namespace ngraph; +using ngraph::test::NodeBuilder; +using ngraph::test::ValueMap; + +TEST(attributes, ctc_loss) { + NodeBuilder::get_ops().register_factory(); + + auto logits = make_shared(element::f32, Shape{10, 120, 28}); + auto logit_length = make_shared(element::i32, Shape{10}); + auto labels = make_shared(element::i32, Shape{10, 120}); + auto label_length = make_shared(element::i32, Shape{10}); + auto blank_index = make_shared(element::i32, Shape{}); + + auto ctc_loss = make_shared(logits, logit_length, labels, label_length, blank_index); + NodeBuilder builder(ctc_loss); + auto g_ctc_loss = as_type_ptr(builder.create()); + + // attribute count + const auto expected_attr_count = 3; + EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); + + // CTC Loss attributes + EXPECT_EQ(g_ctc_loss->get_preprocess_collapse_repeated(), ctc_loss->get_preprocess_collapse_repeated()); + EXPECT_EQ(g_ctc_loss->get_ctc_merge_repeated(), ctc_loss->get_ctc_merge_repeated()); + EXPECT_EQ(g_ctc_loss->get_unique(), ctc_loss->get_unique()); +} From 0bd6696a6709b36316f092566f7f4913d6ea0a7b Mon Sep 17 00:00:00 2001 From: Bartosz Lesniewski Date: Fri, 20 Aug 2021 05:54:12 +0200 Subject: [PATCH 039/102] Enable PriorBoxClustered tests (#7078) --- .../tests/functional/inference_engine/skip_tests_config.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/skip_tests_config.cpp b/inference-engine/tests/functional/inference_engine/skip_tests_config.cpp index aff04cee6e5eab..124d02ba9d0b05 100644 --- a/inference-engine/tests/functional/inference_engine/skip_tests_config.cpp +++ b/inference-engine/tests/functional/inference_engine/skip_tests_config.cpp @@ -9,9 +9,6 @@ std::vector disabledTestPatterns() { return { - // TODO: FIX BUG 33375 - // Disabled due to rare sporadic failures. - ".*TransformationTests\\.ConstFoldingPriorBoxClustered.*", // TODO: task 32568, enable after supporting constants outputs in plugins ".*TransformationTests\\.ConstFoldingPriorBox.*", // azure is failing after #6199 From 3062be072f2afd1e83cb8545c83202f0a5756a5a Mon Sep 17 00:00:00 2001 From: Katarzyna Mitrus Date: Fri, 20 Aug 2021 05:55:13 +0200 Subject: [PATCH 040/102] CumSum spec revision (#6966) * Update detailed description * Update exclusive attribute description * Update Inputs/Outpu description * Update types * Update descriptions * Update data input rank info --- docs/ops/arithmetic/CumSum_3.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/ops/arithmetic/CumSum_3.md b/docs/ops/arithmetic/CumSum_3.md index 66897acdba8683..4ae6f8bde56bc5 100644 --- a/docs/ops/arithmetic/CumSum_3.md +++ b/docs/ops/arithmetic/CumSum_3.md @@ -6,13 +6,15 @@ **Short description**: *CumSum* performs cumulative summation of the input elements along the given axis. -**Detailed description**: By default, it will do the sum inclusively meaning the first element is copied as is. Through an "exclusive" attribute, this behavior can change to exclude the first element. It can also perform summation in the opposite direction of the axis. For that, set reverse attribute to `true`. +**Detailed description**: *CumSum* performs cumulative summation of the input elements along the `axis` specified by the second input. By default, the `j-th` output element is the inclusive sum of the first `j` elements in the given sequence, and the first element in the sequence is copied to the output as is. +In the `exclusive` mode the `j-th` output element is the sum of the first `j-1` elements and the first element in the output sequence is `0`. +To perform the summation in the opposite direction of the axis, set reverse attribute to `true`. **Attributes**: * *exclusive* - * **Description**: If the attribute is set to `true` then an exclusive sum in which the top element is not included is returned. In other terms, if set to `true`, the `j-th` output element would be the sum of the first `(j-1)` elements. Otherwise, it would be the sum of the first `j` elements. +* **Description**: If the attribute is set to `true`, then exclusive sums are returned, the `j-th` element is not included in the `j-th` sum. Otherwise, the inclusive sum of the first `j` elements for the `j-th` element is calculated. * **Range of values**: * `false` - include the top element * `true` - do not include the top element @@ -32,19 +34,19 @@ **Inputs** -* **1**: An tensor of type *T*. **Required.** +* **1**: A tensor of type *T* and rank greater or equal to 1. **Required.** -* **2**: Scalar axis of type *T_AXIS*. Negative value means counting dimensions from the back. Default value is 0. **Optional.** +* **2**: Axis index along which the cumulative sum is performed. A scalar of type *T_AXIS*. Negative value means counting dimensions from the back. Default value is `0`. **Optional.** **Outputs** -* **1**: Output tensor with cumulative sums of the input's elements. A tensor of type *T* of the same shape as 1st input. +* **1**: Output tensor with cumulative sums of the input elements. A tensor of type *T* of the same shape as the first input. **Types** * *T*: any numeric type. -* *T_AXIS*: any integer number. +* *T_AXIS*: `int64` or `int32`. **Examples** From 5228c41d1636c0fd1509e60ef7aaffa435886f4d Mon Sep 17 00:00:00 2001 From: Anton Pankratv Date: Fri, 20 Aug 2021 07:17:56 +0300 Subject: [PATCH 041/102] Added common.hpp file with aliases (#7158) --- .../include/openvino/runtime/common.hpp | 23 ++++++ .../include/openvino/runtime/core.hpp | 54 +++++++------- .../src/inference_engine/src/ie_core.cpp | 73 +++++++++---------- 3 files changed, 83 insertions(+), 67 deletions(-) create mode 100644 inference-engine/src/inference_engine/include/openvino/runtime/common.hpp diff --git a/inference-engine/src/inference_engine/include/openvino/runtime/common.hpp b/inference-engine/src/inference_engine/include/openvino/runtime/common.hpp new file mode 100644 index 00000000000000..9c0c2e93192817 --- /dev/null +++ b/inference-engine/src/inference_engine/include/openvino/runtime/common.hpp @@ -0,0 +1,23 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/** + * @brief This is a header file for the OpenVINO Runtime common aliases that depend only from external API + * + * @file openvino/runtime/common.hpp + */ +#pragma once + +#include +#include + +namespace ov { +namespace ie = InferenceEngine; +namespace runtime { +/** + * @brief This type of map is commonly used to pass set of parameters + */ +using ConfigMap = std::map; +} // namespace runtime +} // namespace ov \ No newline at end of file diff --git a/inference-engine/src/inference_engine/include/openvino/runtime/core.hpp b/inference-engine/src/inference_engine/include/openvino/runtime/core.hpp index 0ececc87aa5b95..e54babcc3f39d7 100644 --- a/inference-engine/src/inference_engine/include/openvino/runtime/core.hpp +++ b/inference-engine/src/inference_engine/include/openvino/runtime/core.hpp @@ -15,6 +15,7 @@ #include #include +#include "common.hpp" #include "cpp/ie_executable_network.hpp" #include "ie_plugin_config.hpp" #include "ie_version.hpp" @@ -57,7 +58,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * @param deviceName Device name to identify plugin * @return A vector of versions */ - std::map get_versions(const std::string& deviceName) const; + std::map get_versions(const std::string& deviceName) const; #ifdef ENABLE_UNICODE_PATH_SUPPORT /** @@ -101,7 +102,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * @return Function */ std::shared_ptr read_model(const std::string& model, - const std::shared_ptr& weights) const; + const std::shared_ptr& weights) const; /** * @brief Creates an executable network from a network object. @@ -115,9 +116,9 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * operation * @return An executable network reference */ - InferenceEngine::ExecutableNetwork compile_model(const std::shared_ptr& network, - const std::string& deviceName, - const std::map& config = {}); + ie::ExecutableNetwork compile_model(const std::shared_ptr& network, + const std::string& deviceName, + const ConfigMap& config = {}); /** * @brief Reads model and creates an executable network from IR or ONNX file @@ -132,9 +133,9 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * * @return An executable network reference */ - InferenceEngine::ExecutableNetwork compile_model(const std::string& modelPath, - const std::string& deviceName, - const std::map& config = {}); + ie::ExecutableNetwork compile_model(const std::string& modelPath, + const std::string& deviceName, + const ConfigMap& config = {}); /** * @brief Creates an executable network from a network object within a specified remote context. @@ -144,15 +145,15 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * operation * @return An executable network object */ - InferenceEngine::ExecutableNetwork compile_model(const std::shared_ptr& network, - const std::shared_ptr& context, - const std::map& config = {}); + ie::ExecutableNetwork compile_model(const std::shared_ptr& network, + const std::shared_ptr& context, + const ConfigMap& config = {}); /** * @brief Registers extension * @param extension Pointer to already loaded extension */ - void add_extension(const std::shared_ptr& extension); + void add_extension(const std::shared_ptr& extension); /** * @brief Creates an executable network from a previously exported network @@ -162,9 +163,9 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * operation* * @return An executable network reference */ - InferenceEngine::ExecutableNetwork import_model(std::istream& networkModel, - const std::string& deviceName, - const std::map& config = {}); + ie::ExecutableNetwork import_model(std::istream& networkModel, + const std::string& deviceName, + const ConfigMap& config = {}); /** * @brief Creates an executable network from a previously exported network within a specified @@ -176,9 +177,9 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * operation * @return An executable network reference */ - InferenceEngine::ExecutableNetwork import_model(std::istream& networkModel, - const std::shared_ptr& context, - const std::map& config = {}); + ie::ExecutableNetwork import_model(std::istream& networkModel, + const std::shared_ptr& context, + const ConfigMap& config = {}); /** * @brief Query device if it supports specified network with specified configuration @@ -188,9 +189,9 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * @param config Optional map of pairs: (config parameter name, config parameter value) * @return An object containing a map of pairs a layer name -> a device name supporting this layer. */ - InferenceEngine::QueryNetworkResult query_model(const std::shared_ptr& network, - const std::string& deviceName, - const std::map& config = {}) const; + ie::QueryNetworkResult query_model(const std::shared_ptr& network, + const std::string& deviceName, + const ConfigMap& config = {}) const; /** * @brief Sets configuration for device, acceptable keys can be found in ie_plugin_config.hpp @@ -200,7 +201,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * * @param config Map of pairs: (config parameter name, config parameter value) */ - void set_config(const std::map& config, const std::string& deviceName = {}); + void set_config(const ConfigMap& config, const std::string& deviceName = {}); /** * @brief Gets configuration dedicated to device behaviour. @@ -211,7 +212,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * @param name - config key. * @return Value of config corresponding to config key. */ - InferenceEngine::Parameter get_config(const std::string& deviceName, const std::string& name) const; + ie::Parameter get_config(const std::string& deviceName, const std::string& name) const; /** * @brief Gets general runtime metric for dedicated hardware. @@ -223,7 +224,7 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * @param name - metric name to request. * @return Metric value corresponding to metric key. */ - InferenceEngine::Parameter get_metric(const std::string& deviceName, const std::string& name) const; + ie::Parameter get_metric(const std::string& deviceName, const std::string& name) const; /** * @brief Returns devices available for neural networks inference @@ -290,15 +291,14 @@ class INFERENCE_ENGINE_API_CLASS(Core) { * @param params Map of device-specific shared context parameters. * @return A shared pointer to a created remote context. */ - std::shared_ptr create_context(const std::string& deviceName, - const InferenceEngine::ParamMap& params); + std::shared_ptr create_context(const std::string& deviceName, const ie::ParamMap& params); /** * @brief Get a pointer to default(plugin-supplied) shared context object for specified accelerator device. * @param deviceName - A name of a device to get create shared context from. * @return A shared pointer to a default remote context. */ - std::shared_ptr get_default_context(const std::string& deviceName); + std::shared_ptr get_default_context(const std::string& deviceName); }; } // namespace runtime } // namespace ov diff --git a/inference-engine/src/inference_engine/src/ie_core.cpp b/inference-engine/src/inference_engine/src/ie_core.cpp index 5792e6388e016b..0c63b75b2bfe5f 100644 --- a/inference-engine/src/inference_engine/src/ie_core.cpp +++ b/inference-engine/src/inference_engine/src/ie_core.cpp @@ -1218,7 +1218,7 @@ Core::Core(const std::string& xmlConfigFile) { register_plugins(core_detail::parseXmlConfig(xmlConfigFile)); } -std::map Core::get_versions(const std::string& deviceName) const { +std::map Core::get_versions(const std::string& deviceName) const { return _impl->GetVersions(deviceName); } @@ -1232,49 +1232,45 @@ std::shared_ptr Core::read_model(const std::wstring& modelPath std::shared_ptr Core::read_model(const std::string& modelPath, const std::string& binPath) const { return _impl->ReadNetwork(modelPath, binPath).getFunction(); } -std::shared_ptr Core::read_model(const std::string& model, - const InferenceEngine::Blob::CPtr& weights) const { +std::shared_ptr Core::read_model(const std::string& model, const ie::Blob::CPtr& weights) const { return _impl->ReadNetwork(model, weights).getFunction(); } -InferenceEngine::ExecutableNetwork Core::compile_model(const std::shared_ptr& network, - const std::string& deviceName, - const std::map& config) { - auto exec = _impl->LoadNetwork(InferenceEngine::CNNNetwork(std::const_pointer_cast(network)), - deviceName, - config); +ie::ExecutableNetwork Core::compile_model(const std::shared_ptr& network, + const std::string& deviceName, + const ConfigMap& config) { + auto exec = + _impl->LoadNetwork(ie::CNNNetwork(std::const_pointer_cast(network)), deviceName, config); return {exec, exec}; } -InferenceEngine::ExecutableNetwork Core::compile_model(const std::string& modelPath, - const std::string& deviceName, - const std::map& config) { +ie::ExecutableNetwork Core::compile_model(const std::string& modelPath, + const std::string& deviceName, + const ConfigMap& config) { auto exec = _impl->LoadNetwork(modelPath, deviceName, config); return {exec, exec}; } -InferenceEngine::ExecutableNetwork Core::compile_model(const std::shared_ptr& network, - const InferenceEngine::RemoteContext::Ptr& context, - const std::map& config) { - auto exec = _impl->LoadNetwork(InferenceEngine::CNNNetwork(std::const_pointer_cast(network)), - context, - config); +ie::ExecutableNetwork Core::compile_model(const std::shared_ptr& network, + const ie::RemoteContext::Ptr& context, + const ConfigMap& config) { + auto exec = _impl->LoadNetwork(ie::CNNNetwork(std::const_pointer_cast(network)), context, config); return {exec, exec}; } -void Core::add_extension(const InferenceEngine::IExtensionPtr& extension) { +void Core::add_extension(const ie::IExtensionPtr& extension) { _impl->AddExtension(extension); } -InferenceEngine::ExecutableNetwork Core::import_model(std::istream& networkModel, - const std::string& deviceName, - const std::map& config) { +ie::ExecutableNetwork Core::import_model(std::istream& networkModel, + const std::string& deviceName, + const ConfigMap& config) { OV_ITT_SCOPED_TASK(ov::itt::domains::IE, "Core::import_model"); auto exec = _impl->ImportNetwork(networkModel, deviceName, config); return {exec, exec}; } -InferenceEngine::ExecutableNetwork Core::import_model(std::istream& networkModel, - const InferenceEngine::RemoteContext::Ptr& context, - const std::map& config) { +ie::ExecutableNetwork Core::import_model(std::istream& networkModel, + const ie::RemoteContext::Ptr& context, + const ConfigMap& config) { OV_ITT_SCOPED_TASK(ov::itt::domains::IE, "Core::import_model"); using ExportMagic = std::array; @@ -1296,14 +1292,12 @@ InferenceEngine::ExecutableNetwork Core::import_model(std::istream& networkModel return {exec, exec}; } -InferenceEngine::QueryNetworkResult Core::query_model(const std::shared_ptr& network, - const std::string& deviceName, - const std::map& config) const { - return _impl->QueryNetwork(InferenceEngine::CNNNetwork(std::const_pointer_cast(network)), - deviceName, - config); +ie::QueryNetworkResult Core::query_model(const std::shared_ptr& network, + const std::string& deviceName, + const ConfigMap& config) const { + return _impl->QueryNetwork(ie::CNNNetwork(std::const_pointer_cast(network)), deviceName, config); } -void Core::set_config(const std::map& config, const std::string& deviceName) { +void Core::set_config(const ConfigMap& config, const std::string& deviceName) { // HETERO case if (deviceName.find("HETERO:") == 0) { IE_THROW() << "SetConfig is supported only for HETERO itself (without devices). " @@ -1337,7 +1331,7 @@ void Core::set_config(const std::map& config, const st } } -InferenceEngine::Parameter Core::get_config(const std::string& deviceName, const std::string& name) const { +ie::Parameter Core::get_config(const std::string& deviceName, const std::string& name) const { // HETERO case { if (deviceName.find("HETERO:") == 0) { @@ -1363,13 +1357,13 @@ InferenceEngine::Parameter Core::get_config(const std::string& deviceName, const auto parsed = core_detail::parseDeviceNameIntoConfig(deviceName); // we need to return a copy of Parameter object which is created on Core side, - // not in InferenceEngine plugin side, which can be unloaded from Core in a parallel thread + // not in ie plugin side, which can be unloaded from Core in a parallel thread // TODO: remove this WA after *-31417 is resolved return core_detail::copyParameterValue( _impl->GetCPPPluginByName(parsed._deviceName).GetConfig(name, parsed._config)); } -InferenceEngine::Parameter Core::get_metric(const std::string& deviceName, const std::string& name) const { +ie::Parameter Core::get_metric(const std::string& deviceName, const std::string& name) const { return _impl->GetMetric(deviceName, name); } @@ -1382,7 +1376,7 @@ void Core::register_plugin(const std::string& pluginName, const std::string& dev } void Core::unload_plugin(const std::string& deviceName) { - InferenceEngine::DeviceIDParser parser(deviceName); + ie::DeviceIDParser parser(deviceName); std::string devName = parser.getDeviceName(); _impl->UnloadPluginByName(devName); @@ -1392,8 +1386,7 @@ void Core::register_plugins(const std::string& xmlConfigFile) { _impl->RegisterPluginsInRegistry(xmlConfigFile); } -InferenceEngine::RemoteContext::Ptr Core::create_context(const std::string& deviceName, - const InferenceEngine::ParamMap& params) { +ie::RemoteContext::Ptr Core::create_context(const std::string& deviceName, const ie::ParamMap& params) { if (deviceName.find("HETERO") == 0) { IE_THROW() << "HETERO device does not support remote context"; } @@ -1408,7 +1401,7 @@ InferenceEngine::RemoteContext::Ptr Core::create_context(const std::string& devi return _impl->GetCPPPluginByName(parsed._deviceName).CreateContext(parsed._config); } -InferenceEngine::RemoteContext::Ptr Core::get_default_context(const std::string& deviceName) { +ie::RemoteContext::Ptr Core::get_default_context(const std::string& deviceName) { if (deviceName.find("HETERO") == 0) { IE_THROW() << "HETERO device does not support remote context"; } @@ -1419,7 +1412,7 @@ InferenceEngine::RemoteContext::Ptr Core::get_default_context(const std::string& IE_THROW() << "AUTO device does not support remote context"; } - auto parsed = core_detail::parseDeviceNameIntoConfig(deviceName, InferenceEngine::ParamMap()); + auto parsed = core_detail::parseDeviceNameIntoConfig(deviceName, ie::ParamMap()); return _impl->GetCPPPluginByName(parsed._deviceName).GetDefaultContext(parsed._config); } From a9ddf79a4f15e31a3f772c1f4b872f05244bb4a8 Mon Sep 17 00:00:00 2001 From: Katarzyna Mitrus Date: Fri, 20 Aug 2021 08:50:09 +0200 Subject: [PATCH 042/102] CumSum reference implementation revision (#6915) * New CumSum implementation init * Unified ndim approach * Move transpose to separate function * Move transpose to original to separate function * Move slice_count calculation to function * Negative axes support * Refactor redundant copy * Changed copy to move * Temp more backend tests * Add const to shape arg * Use span for slices calculation * Remove unused headers * CumSum new ref tests * Add more ref tests * Add all cumsum modes ref tests * new optimized cum_sum reference * Add reverse mode * Optimized cumsum ref * Remove deprecated cumsum backend tests * Add more CumSum reference tests * Simplify CumSum shared layer tests SetUp * Replace auto to size_t in loop * Change static_cast to T{} --- .../tests/functional/op_reference/cum_sum.cpp | 193 ++++++++++++++++++ .../src/single_layer/cum_sum.cpp | 17 +- .../ngraph/runtime/reference/cum_sum.hpp | 108 ++-------- ngraph/test/CMakeLists.txt | 1 - ngraph/test/backend/cum_sum.in.cpp | 165 --------------- 5 files changed, 220 insertions(+), 264 deletions(-) create mode 100644 docs/template_plugin/tests/functional/op_reference/cum_sum.cpp delete mode 100644 ngraph/test/backend/cum_sum.in.cpp diff --git a/docs/template_plugin/tests/functional/op_reference/cum_sum.cpp b/docs/template_plugin/tests/functional/op_reference/cum_sum.cpp new file mode 100644 index 00000000000000..1539a138c3f75a --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/cum_sum.cpp @@ -0,0 +1,193 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include +#include +#include + +#include "base_reference_test.hpp" + +using namespace reference_tests; +using namespace ngraph; +using namespace InferenceEngine; + +namespace { +struct CumSumParams { + // Custom axis input and attributes + template + CumSumParams(const PartialShape& shape, const element::Type& iType, const std::vector& iValues, const std::vector& oValues, const bool execlusive, + const bool reverse, const element::Type& axisType, AT axisVal, const PartialShape& axisShape) + : execlusive(execlusive), + reverse(reverse), + axisValue(axisVal), + axisShape(axisShape), + inShape(shape), + axisType(axisType), + inType(iType), + outType(iType), + axisData(CreateBlob(axisType, std::vector {axisVal})), + inputData(CreateBlob(iType, iValues)), + refData(CreateBlob(iType, oValues)), + testDefaults(false) {} + + // Default axis input and attributes + template + CumSumParams(const PartialShape& shape, const element::Type& iType, const std::vector& iValues, const std::vector& oValues) + : inShape(shape), + axisType(element::i32), + inType(iType), + outType(iType), + inputData(CreateBlob(iType, iValues)), + refData(CreateBlob(iType, oValues)), + testDefaults(true) {} + + bool execlusive = false; + bool reverse = false; + int64_t axisValue = 0; + + PartialShape axisShape; + PartialShape inShape; + element::Type axisType; + element::Type inType; + element::Type outType; + Blob::Ptr axisData; + Blob::Ptr inputData; + Blob::Ptr refData; + + bool testDefaults = false; +}; + +class ReferenceCumSumLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + if (params.testDefaults) { + function = CreateFunction(params.inShape, params.inType); + inputData = {params.inputData}; + refOutData = {params.refData}; + } else { + function = CreateFunction(params.inShape, params.inType, params.axisShape, params.axisType, params.execlusive, params.reverse); + inputData = {params.inputData, params.axisData}; + refOutData = {params.refData}; + } + } + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "testDefaults=" << param.testDefaults << "_"; + result << "axisValue=" << param.axisValue << "_"; + result << "execlusive=" << param.execlusive << "_"; + result << "reverse=" << param.reverse << "_"; + result << "inShape=" << param.inShape << "_"; + result << "iType=" << param.inType << "_"; + result << "axisType=" << param.axisType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& data_shape, const element::Type& data_type, const PartialShape& axis_shape, + const element::Type& axis_type, const bool execlusive, const bool reverse) { + const auto data_param = std::make_shared(data_type, data_shape); + const auto axis_param = std::make_shared(axis_type, axis_shape); + const auto cum_sum = std::make_shared(data_param, axis_param, execlusive, reverse); + return std::make_shared(NodeVector {cum_sum}, ParameterVector {data_param, axis_param}); + } + + static std::shared_ptr CreateFunction(const PartialShape& data_shape, const element::Type& data_type) { + const auto data_param = std::make_shared(data_type, data_shape); + const auto cum_sum = std::make_shared(data_param); + return std::make_shared(NodeVector {cum_sum}, ParameterVector {data_param}); + } +}; + +TEST_P(ReferenceCumSumLayerTest, CompareWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateCumSumParams(const element::Type& type) { + using T = typename element_type_traits::value_type; + std::vector opParams { + // Default axis input and attributes + CumSumParams(PartialShape {1}, type, std::vector {3}, std::vector {3}), + CumSumParams(PartialShape {6}, type, std::vector {1, 2, 3, 4, 5, 6}, std::vector {1, 3, 6, 10, 15, 21}), + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {0, 1, 2, 3, 4, 6, 8, 10}), + // Custom axis input and attributes + CumSumParams(PartialShape {6}, type, std::vector {1, 2, 3, 4, 5, 6}, std::vector {1, 3, 6, 10, 15, 21}, false, false, element::i32, int32_t(0), + PartialShape {}), // axis i32 + CumSumParams(PartialShape {6}, type, std::vector {1, 2, 3, 4, 5, 6}, std::vector {1, 3, 6, 10, 15, 21}, false, false, element::i64, int64_t(0), + PartialShape {}), // axis i64 + CumSumParams(PartialShape {6}, type, std::vector {1, 2, 3, 4, 5, 6}, std::vector {21, 20, 18, 15, 11, 6}, false, true, element::i64, int64_t(0), + PartialShape {}), + CumSumParams(PartialShape {6}, type, std::vector {1, 2, 3, 4, 5, 6}, std::vector {0, 1, 3, 6, 10, 15}, true, false, element::i64, int64_t(0), + PartialShape {}), + CumSumParams(PartialShape {6}, type, std::vector {1, 2, 3, 4, 5, 6}, std::vector {20, 18, 15, 11, 6, 0}, true, true, element::i64, int64_t(0), + PartialShape {}), + + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {0, 1, 2, 3, 4, 6, 8, 10}, false, false, element::i32, + int32_t(0), PartialShape {}), + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {4, 6, 8, 10, 4, 5, 6, 7}, false, true, element::i32, + int32_t(0), PartialShape {}), + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {0, 0, 0, 0, 0, 1, 2, 3}, true, false, element::i32, + int32_t(0), PartialShape {}), + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {4, 5, 6, 7, 0, 0, 0, 0}, true, true, element::i32, + int32_t(0), PartialShape {}), + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {0, 1, 3, 6, 4, 9, 15, 22}, false, false, element::i32, + int32_t(1), PartialShape {}), + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {0, 0, 1, 3, 0, 4, 9, 15}, true, false, element::i32, + int32_t(1), PartialShape {}), + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {6, 6, 5, 3, 22, 18, 13, 7}, false, true, element::i32, + int32_t(1), PartialShape {}), + CumSumParams(PartialShape {2, 4}, type, std::vector {0, 1, 2, 3, 4, 5, 6, 7}, std::vector {6, 5, 3, 0, 18, 13, 7, 0}, true, true, element::i32, + int32_t(1), PartialShape {}), + + CumSumParams(PartialShape {3, 2, 4}, type, + std::vector {0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23}, + std::vector {0, 1, 2, 3, 4, 5, 6, 7, + 8, 10, 12, 14, 16, 18, 20, 22, + 24, 27, 30, 33, 36, 39, 42, 45}, + false, false, element::i32, int32_t(0), PartialShape {}), + CumSumParams(PartialShape {3, 2, 4}, type, + std::vector {0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23}, + std::vector {0, 1, 2, 3, 4, 6, 8, 10, + 8, 9, 10, 11, 20, 22, 24, 26, + 16, 17, 18, 19, 36, 38, 40, 42}, + false, false, element::i32, int32_t(1), PartialShape {}), + CumSumParams(PartialShape {3, 2, 4}, type, + std::vector {0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23}, + std::vector {0, 1, 3, 6, 4, 9, 15, 22, + 8, 17, 27, 38, 12, 25, 39, 54, + 16, 33, 51, 70, 20, 41, 63, 86}, + false, false, element::i32, int32_t(2), PartialShape {}), + }; + return opParams; +} + +std::vector generateCumSumCombinedParams() { + const std::vector> opTypeParams { + generateCumSumParams(element::bf16), generateCumSumParams(element::f16), + generateCumSumParams(element::f32), generateCumSumParams(element::i32), + generateCumSumParams(element::i64), generateCumSumParams(element::u32), + generateCumSumParams(element::i8)}; + std::vector combinedParams; + std::for_each(opTypeParams.begin(), opTypeParams.end(), [&](std::vector params) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + }); + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P(smoke_CumSum_With_Hardcoded_Refs, ReferenceCumSumLayerTest, ::testing::ValuesIn(generateCumSumCombinedParams()), + ReferenceCumSumLayerTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/shared_test_classes/src/single_layer/cum_sum.cpp b/inference-engine/tests/functional/shared_test_classes/src/single_layer/cum_sum.cpp index ae371c7b229e7a..3d0b62963a6c5c 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/single_layer/cum_sum.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/single_layer/cum_sum.cpp @@ -30,17 +30,12 @@ void CumSumLayerTest::SetUp() { bool exclusive, reverse; int64_t axis; std::tie(inputShapes, inputPrecision, axis, exclusive, reverse, targetDevice) = this->GetParam(); - auto inType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputPrecision); - ngraph::ParameterVector paramVector; - auto paramData = std::make_shared(inType, ngraph::Shape(inputShapes)); - paramVector.push_back(paramData); + const auto inType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputPrecision); + const auto paramData = std::make_shared(inType, ngraph::Shape(inputShapes)); + const auto axisNode = std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{}, std::vector{axis})->output(0); + const auto cumSum = std::make_shared(paramData, axisNode, exclusive, reverse); - auto axisNode = std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{}, std::vector{axis})->output(0); - - auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(paramVector)); - auto cumSum = std::dynamic_pointer_cast(ngraph::builder::makeCumSum(paramOuts[0], axisNode, exclusive, reverse)); - - ngraph::ResultVector results{std::make_shared(cumSum)}; - function = std::make_shared(results, paramVector, "cumsum"); + ngraph::ResultVector results{std::make_shared(cumSum)}; + function = std::make_shared(results, ngraph::ParameterVector{paramData}, "cumsum"); } } // namespace LayerTestsDefinitions diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/cum_sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/cum_sum.hpp index cb304f03b61806..699e0f863adefb 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/cum_sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/cum_sum.hpp @@ -5,17 +5,11 @@ #pragma once #include -#include -#include -#include - -#include "ngraph/coordinate_transform.hpp" -#include "ngraph/type/bfloat16.hpp" -#include "ngraph/type/float16.hpp" namespace ngraph { namespace runtime { namespace reference { + template void cumsum(const T* arg, const P* axis_tensor, @@ -23,89 +17,29 @@ void cumsum(const T* arg, const Shape& tensor_shape, const bool exclusive, const bool reverse) { - NGRAPH_SUPPRESS_DEPRECATED_START - CoordinateTransform temp_transform(tensor_shape); - for (const Coordinate& output_coord : temp_transform) { - out[temp_transform.index(output_coord)] = 0; - } - - P axis = axis_tensor[0]; - P rank = tensor_shape.size(); - - if (axis < -rank || axis > rank) { - throw ngraph_error("axis must be in the range [-rank, rank]"); - } - axis = axis < 0 ? rank + axis : axis; - - auto get_key = [&, axis](const Coordinate& coord) -> Coordinate { - Coordinate result(coord.size(), 0); - result[axis] = coord[axis]; - - for (size_t i = 0; i < coord.size(); i++) { - result[i] = coord[i] - result[i]; - } - return result; - }; - - auto update_output_buffer = - [&](size_t input_index, size_t output_index, T& prev, std::vector>& tensor_vec) -> void { - tensor_vec[input_index].second = prev + tensor_vec[input_index].second; - out[tensor_vec[output_index].first] = tensor_vec[input_index].second; - - // update prev to hold the last result value to compute ruuning sum for - // subsequent iter - prev = out[tensor_vec[output_index].first]; - }; - - auto cum_sum = [&, exclusive, reverse](std::vector>& tensor_vec) { - if (!reverse) { - T prev = 0; - for (size_t i = 0; i < tensor_vec.size(); i++) { - if (exclusive && i == 0) { - out[tensor_vec[i].first] = prev; - continue; - } - // we will compute running sum of j-1 elements if exlusive=1 or else - // for j elements if exclusive = 0 - size_t arg_index = exclusive == 1 ? i - 1 : i; - update_output_buffer(arg_index, i, prev, tensor_vec); + const auto rank = tensor_shape.size(); + const auto axis = axis_tensor[0] >= 0 ? axis_tensor[0] : rank + axis_tensor[0]; + const auto axis_dim = tensor_shape[axis]; + + const auto size_before_axis = shape_size(Shape(tensor_shape.begin(), tensor_shape.begin() + axis)); + const auto size_after_axis = shape_size(Shape(tensor_shape.begin() + axis + 1, tensor_shape.end())); + + const auto reverse_shift = reverse ? -1 : 1; + const auto element_shift = exclusive ? size_after_axis * reverse_shift : 0; + + for (size_t i = 0; i < size_before_axis; ++i) { + const auto slice_idx = i * axis_dim * size_after_axis + reverse * size_after_axis * (axis_dim - 1); + for (size_t j = 0; j < size_after_axis; ++j) { + const auto sequence_start_idx = slice_idx + j; + out[sequence_start_idx] = exclusive ? T{0} : arg[sequence_start_idx]; + for (size_t k = 1; k < axis_dim; ++k) { + const auto element_idx = sequence_start_idx + (k * size_after_axis) * reverse_shift; + const auto in_idx = element_idx - element_shift; + const auto previous_sum_idx = element_idx - size_after_axis * reverse_shift; + out[element_idx] = out[previous_sum_idx] + arg[in_idx]; } - } else // reverse == true - { - T prev = 0; - for (size_t i = tensor_vec.size(); i-- > 0;) { - if (exclusive && i == tensor_vec.size() - 1) { - out[tensor_vec[i].first] = prev; - continue; - } - // we will compute running sum of j-1 elements if exlusive=1 or else - // for j elements if exclusive = 0 - size_t arg_index = exclusive == 1 ? i + 1 : i; - update_output_buffer(arg_index, i, prev, tensor_vec); - } - } - }; - - // Map to collect tensor elements belonging to the same axis - std::map>> map_cooord_to_val; - CoordinateTransform input_transform(tensor_shape); - for (const Coordinate& input_coord : input_transform) { - // points to the current element in the input tensor - T current = arg[input_transform.index(input_coord)]; - auto key = get_key(input_coord); - auto index = input_transform.index(input_coord); - if (map_cooord_to_val.find(key) != map_cooord_to_val.end()) { - map_cooord_to_val[key].push_back(std::make_pair(index, current)); - } else { - map_cooord_to_val.insert({key, std::vector>()}); - map_cooord_to_val[key].push_back(std::make_pair(index, current)); } } - // iterate the map and perform cumulative sum over the give axis - for (auto& it : map_cooord_to_val) { - cum_sum(it.second); - } - NGRAPH_SUPPRESS_DEPRECATED_END } } // namespace reference } // namespace runtime diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 8a7c7e1a0ba7df..28017824f22f2e 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -428,7 +428,6 @@ set(MULTI_TEST_SRC backend/cosh.in.cpp backend/ctc_greedy_decoder.in.cpp backend/ctc_greedy_decoder_seq_len.in.cpp - backend/cum_sum.in.cpp backend/deformable_psroi_pooling.in.cpp backend/detection_output.in.cpp backend/dft.in.cpp diff --git a/ngraph/test/backend/cum_sum.in.cpp b/ngraph/test/backend/cum_sum.in.cpp deleted file mode 100644 index 9f8b1f91b3072e..00000000000000 --- a/ngraph/test/backend/cum_sum.in.cpp +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "runtime/backend.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/ndarray.hpp" -#include "util/random.hpp" -#include "util/test_control.hpp" -#include "util/test_tools.hpp" - -static std::mt19937_64 random_generator; - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; - -NGRAPH_TEST(${BACKEND_NAME}, cum_sum_default) { - Shape shape{1, 4}; - auto A = make_shared(element::f32, shape); - auto axis = make_shared(element::i32, Shape{1}); - auto f = make_shared(make_shared(A, axis), ParameterVector{A, axis}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 2, 3, 4}); - auto axis_tensor = backend->create_tensor(axis->get_element_type(), axis->get_shape()); - copy_data(axis_tensor, vector{1}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, axis_tensor}); - EXPECT_TRUE(test::all_close_f((vector{1, 3, 6, 10}), read_vector(result))); -} - -NGRAPH_TEST(${BACKEND_NAME}, cum_sum_2dim) { - Shape shape{2, 4}; - auto A = make_shared(element::f32, shape); - auto axis = make_shared(element::i64, Shape{1}); - auto f = make_shared(make_shared(A, axis), ParameterVector{A, axis}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{0, 1, 2, 3, 4, 5, 6, 7}); - auto axis_tensor = backend->create_tensor(axis->get_element_type(), axis->get_shape()); - copy_data(axis_tensor, vector{0}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, axis_tensor}); - EXPECT_TRUE(test::all_close_f((vector{0, 1, 2, 3, 4, 6, 8, 10}), read_vector(result))); -} - -NGRAPH_TEST(${BACKEND_NAME}, cum_sum_2dim_default_axis) { - Shape shape{2, 4}; - auto A = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A), ParameterVector{A}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{0, 1, 2, 3, 4, 5, 6, 7}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{0, 1, 2, 3, 4, 6, 8, 10}), read_vector(result))); -} - -NGRAPH_TEST(${BACKEND_NAME}, cum_sum_3d) { - auto test_cumsum_3d = [](const int32_t axis_val) -> void { - Shape shape{3, 2, 4}; - auto A = make_shared(element::f32, shape); - auto axis = make_shared(element::i32, Shape{1}); - auto f = make_shared(make_shared(A, axis), ParameterVector{A, axis}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, - vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}); - auto axis_tensor = backend->create_tensor(axis->get_element_type(), axis->get_shape()); - copy_data(axis_tensor, vector{axis_val}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, axis_tensor}); - - if (axis_val == 0) { - EXPECT_TRUE(test::all_close_f( - (vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 42, 45}), - read_vector(result))); - } else if (axis_val == 1) { - EXPECT_TRUE(test::all_close_f( - (vector{0, 1, 2, 3, 4, 6, 8, 10, 8, 9, 10, 11, 20, 22, 24, 26, 16, 17, 18, 19, 36, 38, 40, 42}), - read_vector(result))); - } else if (axis_val == 2) { - EXPECT_TRUE(test::all_close_f((vector{0, 1, 3, 6, 4, 9, 15, 22, 8, 17, 27, 38, - 12, 25, 39, 54, 16, 33, 51, 70, 20, 41, 63, 86}), - read_vector(result))); - } - }; - test_cumsum_3d(0); - test_cumsum_3d(1); - test_cumsum_3d(2); -} - -NGRAPH_TEST(${BACKEND_NAME}, cum_sum_2dim_allmodes) { - auto test_cum_sum_allmodes = [](const int64_t axis_val, int exclusive, int reverse) { - Shape shape{2, 4}; - auto A = make_shared(element::f32, shape); - auto axis = make_shared(element::i64, Shape{1}); - auto f = make_shared(make_shared(A, axis, exclusive, reverse), ParameterVector{A, axis}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{0, 1, 2, 3, 4, 5, 6, 7}); - auto axis_tensor = backend->create_tensor(axis->get_element_type(), axis->get_shape()); - copy_data(axis_tensor, vector{axis_val}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, axis_tensor}); - if (axis_val == 1 && exclusive == 1 && reverse == 0) { - EXPECT_TRUE(test::all_close_f((vector{0, 0, 1, 3, 0, 4, 9, 15}), read_vector(result))); - } else if (axis_val == 1 && exclusive == 0 && reverse == 1) { - EXPECT_TRUE(test::all_close_f((vector{6, 6, 5, 3, 22, 18, 13, 7}), read_vector(result))); - } else if (axis_val == 1 && exclusive == 1 && reverse == 1) { - EXPECT_TRUE(test::all_close_f((vector{6, 5, 3, 0, 18, 13, 7, 0}), read_vector(result))); - } else if (axis_val == 0 && exclusive == 0 && reverse == 0) { - EXPECT_TRUE(test::all_close_f((vector{0, 1, 2, 3, 4, 6, 8, 10}), read_vector(result))); - } else if (axis_val == 0 && exclusive == 1 && reverse == 1) { - EXPECT_TRUE(test::all_close_f((vector{4, 5, 6, 7, 0, 0, 0, 0}), read_vector(result))); - } else if (axis_val == 0 && exclusive == 0 && reverse == 1) { - EXPECT_TRUE(test::all_close_f((vector{4, 6, 8, 10, 4, 5, 6, 7}), read_vector(result))); - } - }; - - test_cum_sum_allmodes(1, 1, 0); - test_cum_sum_allmodes(-1, 0, 1); - test_cum_sum_allmodes(-1, 1, 1); - test_cum_sum_allmodes(0, 0, 0); - test_cum_sum_allmodes(0, 1, 1); - test_cum_sum_allmodes(0, 0, 1); -} From cf75c3fc29a52e68eb8ae4bc81cdae608ce0ddab Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Fri, 20 Aug 2021 09:58:56 +0300 Subject: [PATCH 043/102] [LPT] MarkupCanBeQuantized: handled unsupported concat (#7045) * [LPT] MarkupCanBeQuantized: added check on unsupported concat * [LPT] ConcatTransformation: added test-case with unsupported concat and convolution * [LPT] added test on rtInfo check for unsupported concat * [LPT] ConcatTransformation: added test-case with unsupported axis to plugin tests --- .../include/low_precision/concat.hpp | 1 + .../src/concat.cpp | 16 +++++++ .../src/markup_can_be_quantized.cpp | 7 +++ .../concat_transformation.cpp | 18 +++---- ...t_with_different_precision_on_children.cpp | 42 +++++++++++++++-- ...t_with_unsupported_axis_transformation.cpp | 37 +++++++++++++++ ...t_with_different_precision_on_children.cpp | 16 +++++-- ...t_with_different_precision_on_children.cpp | 20 +++++--- ...t_with_different_precision_on_children.hpp | 6 +-- ...t_with_different_precision_on_children.cpp | 13 ++--- .../lpt_ngraph_functions/concat_function.hpp | 5 +- .../src/concat_function.cpp | 47 ++++++++----------- 12 files changed, 164 insertions(+), 64 deletions(-) create mode 100644 inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_unsupported_axis_transformation.cpp diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/concat.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/concat.hpp index db16f572224293..65cb9694eb8063 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/concat.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/concat.hpp @@ -26,6 +26,7 @@ class LP_TRANSFORMATIONS_API ConcatTransformation : public LayerTransformation { bool transform(TransformationContext& context, ngraph::pattern::Matcher &m) override; bool isPrecisionPreserved(std::shared_ptr layer) const noexcept override; bool canBeTransformed(const TransformationContext& context, std::shared_ptr layer) const override; + static bool isQuantizedStatic(const std::shared_ptr& layer) noexcept; protected: static bool isHandled( diff --git a/inference-engine/src/low_precision_transformations/src/concat.cpp b/inference-engine/src/low_precision_transformations/src/concat.cpp index 5c0da831b8e7ac..b17846446a12e4 100644 --- a/inference-engine/src/low_precision_transformations/src/concat.cpp +++ b/inference-engine/src/low_precision_transformations/src/concat.cpp @@ -297,6 +297,22 @@ bool ConcatTransformation::isHandled(const TransformationContext& context, const return false; } +bool ConcatTransformation::isQuantizedStatic(const std::shared_ptr& layer) noexcept { + const auto concat = as_type_ptr(layer); + if (concat == nullptr) { + return false; + } + + const auto axis = concat->get_axis(); + const auto outputRank = concat->get_output_partial_shape(0).rank(); + if (axis < 0 && outputRank.is_dynamic()) { + return false; + } + + const size_t normalizedAxis = ngraph::normalize_axis(concat->get_friendly_name(), axis, outputRank); + return normalizedAxis == 1ul; +} + } // namespace low_precision } // namespace pass } // namespace ngraph diff --git a/inference-engine/src/low_precision_transformations/src/markup_can_be_quantized.cpp b/inference-engine/src/low_precision_transformations/src/markup_can_be_quantized.cpp index 3117efc2debd14..10553e07fd7755 100644 --- a/inference-engine/src/low_precision_transformations/src/markup_can_be_quantized.cpp +++ b/inference-engine/src/low_precision_transformations/src/markup_can_be_quantized.cpp @@ -7,6 +7,7 @@ #include #include +#include "low_precision/concat.hpp" #include "low_precision/convolution.hpp" #include "low_precision/convolution_backprop_data.hpp" #include "low_precision/group_convolution.hpp" @@ -54,6 +55,12 @@ bool ngraph::pass::low_precision::MarkupCanBeQuantized::run_on_function(std::sha } continue; } + if (const auto concat = std::dynamic_pointer_cast(node)) { + if (!ConcatTransformation::isQuantizedStatic(concat)) { + setEmptyPrecisions(concat); + } + continue; + } } return true; } diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_transformation.cpp index 9c539b7504a8f8..b901d86203a192 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_transformation.cpp @@ -230,16 +230,18 @@ TEST_P(ConcatTransformation, CompareFunctions) { auto res = compare_functions(referenceFunction, actualFunction, true, true, false, true, false); ASSERT_TRUE(res.first) << res.second; + ConcatTransformationTestValues testValues = std::get<2>(GetParam()); const auto actualFakeQuantizes = LayerTransformation::get(actualFunction); - ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame>(actualFakeQuantizes)) << - "PrecisionsAttribute are not the same"; + if (testValues.axis == 1) { + ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame>(actualFakeQuantizes)) << + "PrecisionsAttribute are not the same"; - ConcatTransformationTestValues testValues = std::get<2>(GetParam()); - if (testValues.checkIntervalsAlignmentAttributes) { - auto operations = LayerTransformation::get(actualFunction); - operations.insert(operations.end(), actualFakeQuantizes.begin(), actualFakeQuantizes.end()); - ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame>(operations)) << - "IntervalsAlignmentAttribute are not the same"; + if (testValues.checkIntervalsAlignmentAttributes) { + auto operations = LayerTransformation::get(actualFunction); + operations.insert(operations.end(), actualFakeQuantizes.begin(), actualFakeQuantizes.end()); + ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame>(operations)) << + "IntervalsAlignmentAttribute are not the same"; + } } } diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_different_precision_on_children.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_different_precision_on_children.cpp index e781b8b258d1a6..5bd1dd8d3792fb 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_different_precision_on_children.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_different_precision_on_children.cpp @@ -11,11 +11,9 @@ #include #include -#include #include #include #include -#include #include "common_test_utils/ngraph_test_utils.hpp" #include "lpt_ngraph_functions/concat_function.hpp" @@ -45,7 +43,8 @@ class ConcatTransformationResultValues { ngraph::builder::subgraph::FakeQuantizeOnData fakeQuantize1; ngraph::builder::subgraph::FakeQuantizeOnData fakeQuantize2; ngraph::element::Type precisionBeforeOp; - ngraph::builder::subgraph::DequantizationOperations dequantizationBefore; + ngraph::builder::subgraph::DequantizationOperations dequantizationBefore1; + ngraph::builder::subgraph::DequantizationOperations dequantizationBefore2; ngraph::element::Type precisionAfterOperation; ngraph::builder::subgraph::DequantizationOperations dequantizationAfter1; ngraph::builder::subgraph::DequantizationOperations dequantizationAfter2; @@ -63,6 +62,7 @@ class ConcatTransformationTestValues { public: TestTransformationParams params; bool multiChannels; + std::int64_t axis; ConcatTransformationActualValues actual; ConcatTransformationResultValues result; }; @@ -87,6 +87,7 @@ class ConcatWithDifferentChildrenTransformation : public LayerTransformation, pu actualFunction = ngraph::builder::subgraph::ConcatFunction::getOriginalWithDifferentPrecisionOnChildren( precision, inputShape, + testValues.axis, testValues.actual.fakeQuantize1, testValues.actual.fakeQuantize2); @@ -100,17 +101,18 @@ class ConcatWithDifferentChildrenTransformation : public LayerTransformation, pu transform.add(testValues.params); transform.add(testValues.params); transform.add(testValues.params); - transform.add(testValues.params); transform.transform(actualFunction); referenceFunction = ngraph::builder::subgraph::ConcatFunction::getReferenceWithDifferentPrecisionOnChildren( precision, inputShape, testValues.multiChannels, + testValues.axis, testValues.result.fakeQuantize1, testValues.result.fakeQuantize2, testValues.result.precisionBeforeOp, - testValues.result.dequantizationBefore, + testValues.result.dequantizationBefore1, + testValues.result.dequantizationBefore2, testValues.result.precisionAfterOperation, testValues.result.dequantizationAfter1, testValues.result.dequantizationAfter2); @@ -153,6 +155,7 @@ const std::vector testValues = { { LayerTransformation::createParamsU8I8(), false, + 1, { { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, { 256ul, ngraph::Shape({}), {0.f}, {2.55f / 2.f}, {0.f}, {2.55f / 2.f} } @@ -162,15 +165,37 @@ const std::vector testValues = { { 256ul, ngraph::Shape({}), {0.f}, {2.55f / 2.f}, {0.f}, { 128.f} }, ngraph::element::u8, {{}, {}, {}}, + {{}, {}, {}}, ngraph::element::u8, { ngraph::element::f32, {}, { 0.01f } }, { ngraph::element::f32, {}, { 0.01f } } } }, + // U8 with unsupported axis + { + LayerTransformation::createParamsU8I8(), + false, + 2, + { + { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, + { 256ul, ngraph::Shape({}), {0.f}, {2.55f / 2.f}, {0.f}, {2.55f / 2.f} } + }, + { + { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {255.f} }, + { 256ul, ngraph::Shape({}), {0.f}, {2.55f / 2.f}, {0.f}, {255.f} }, + ngraph::element::u8, + {{ngraph::element::f32}, {}, {0.01f}}, + {{ngraph::element::f32}, {}, {0.005f}}, + ngraph::element::f32, + {{}, {}, {}}, + {{}, {}, {}} + } + }, // I8 { LayerTransformation::createParamsI8I8(), false, + 1, { { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f}, {1.27f} }, { 256ul, ngraph::Shape({}), {-1.28f / 2.f}, {1.27f / 2.f}, {-1.28f / 2.f}, {1.27f / 2.f} } @@ -180,6 +205,7 @@ const std::vector testValues = { { 256ul, ngraph::Shape({}), {-1.28f / 2.f}, {1.27f / 2.f}, {-64.f}, { 64.f} }, ngraph::element::i8, {{}, {}, {}}, + {{}, {}, {}}, ngraph::element::i8, { ngraph::element::f32, {}, { 0.01f } }, { ngraph::element::f32, {}, { 0.01f } } @@ -189,6 +215,7 @@ const std::vector testValues = { { LayerTransformation::createParamsU8I8(), true, + 1, { { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, { 256ul, ngraph::Shape({}), {0.f}, {2.55f / 2.f}, {0.f}, {2.55f / 2.f} } @@ -198,6 +225,7 @@ const std::vector testValues = { { 256ul, ngraph::Shape({}), {0.f}, {2.55f / 2.f}, {0.f}, { 255.f} }, ngraph::element::u8, {{}, {}, {}}, + {{}, {}, {}}, ngraph::element::u8, { ngraph::element::f32, {}, {{ 0.01f, 0.01f, 0.01f, 0.005f, 0.005f, 0.005f }} }, { ngraph::element::f32, {}, {{ 0.01f, 0.01f, 0.01f, 0.005f, 0.005f, 0.005f }} }, @@ -207,6 +235,7 @@ const std::vector testValues = { { LayerTransformation::createParamsI8I8(), true, + 1, { { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f}, {1.27f} }, { 256ul, ngraph::Shape({}), {-1.28f / 2.f}, {1.27f / 2.f}, {-1.28f / 2.f}, {1.27f / 2.f} } @@ -216,6 +245,7 @@ const std::vector testValues = { { 256ul, ngraph::Shape({}), {-1.28f / 2.f}, {1.27f / 2.f}, {-128.f}, {127.f} }, ngraph::element::i8, {{}, {}, {}}, + {{}, {}, {}}, ngraph::element::i8, { ngraph::element::f32, {}, {{ 0.01f, 0.01f, 0.01f, 0.005f, 0.005f, 0.005f }} }, { ngraph::element::f32, {}, {{ 0.01f, 0.01f, 0.01f, 0.005f, 0.005f, 0.005f }} }, @@ -225,6 +255,7 @@ const std::vector testValues = { { LayerTransformation::createParamsU8I8().setUpdatePrecisions(false), false, + 1, { { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, { 256ul, ngraph::Shape({}), {0.f}, {2.55f / 2.f}, {0.f}, {2.55f / 2.f} } @@ -234,6 +265,7 @@ const std::vector testValues = { { 256ul, ngraph::Shape({}), {0.f}, {2.55f / 2.f}, {0.f}, { 128.f} }, ngraph::element::f32, {{}, {}, {}}, + {{}, {}, {}}, ngraph::element::f32, { {}, {}, { 0.01f } }, { {}, {}, { 0.01f } } diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_unsupported_axis_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_unsupported_axis_transformation.cpp new file mode 100644 index 00000000000000..2ac33c4de302f5 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_unsupported_axis_transformation.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "layer_transformation.hpp" + +#include + +#include "lpt_ngraph_functions/concat_function.hpp" +#include "simple_low_precision_transformer.hpp" + +using namespace ::testing; + +class smoke_LPT_ConcatWithUnsupportedAxis : public Test {}; + +TEST_F(smoke_LPT_ConcatWithUnsupportedAxis, rtInfoCheck) { + using namespace ngraph::builder::subgraph; + + const ngraph::element::Type precision = ngraph::element::f32; + const ngraph::PartialShape inputPShape = PartialShape{ 1, 3, 16, 16 }; + const std::int64_t unsupportedAxis = 2; + const auto fakeQuantize = FakeQuantizeOnData{ 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }; + + std::shared_ptr function = ConcatFunction::getOriginalWithDifferentPrecisionOnChildren( + precision, + inputPShape, + unsupportedAxis, + fakeQuantize, + fakeQuantize); + + SimpleLowPrecisionTransformer transformer; + transformer.transform(function); + + const auto actualConcat = LayerTransformation::get(function)[0]; + const auto& rtInfo = actualConcat->get_rt_info(); + ASSERT_TRUE(rtInfo.empty()) << "Unsupported concat mustn't contain LPT runtime attributes"; +} diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_with_different_precision_on_children.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_with_different_precision_on_children.cpp index b3631fe57d7819..72d30a9b0192ab 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_with_different_precision_on_children.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_with_different_precision_on_children.cpp @@ -16,42 +16,48 @@ const std::vector netPrecisions = { }; const std::vector trasformationParamValues = { - // LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsI8I8(), LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8() }; const std::vector testValues = { // U8 { + 1, + { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, + { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f / 2.f} } + }, + // U8 and unsupported concat axis + { + 2, { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f / 2.f} } }, // I8 { + 1, { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f}, {1.27f} }, { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f / 2.f}, {1.27f / 2.f} } }, // mixed: U8 + I8 { + 1, { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f}, {1.27f} } }, // mixed: I8 + U8 { + 1, { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f}, {1.27f} }, { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} } } }; -const std::vector multiChannel = { true/*, false*/ }; - INSTANTIATE_TEST_SUITE_P(smoke_LPT, ConcatWithDifferentChildrenTransformation, ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(ngraph::PartialShape({ 1, 6, 10, 10 })), ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::ValuesIn(testValues), - ::testing::ValuesIn(trasformationParamValues), - ::testing::ValuesIn(multiChannel)), + ::testing::ValuesIn(trasformationParamValues)), ConcatWithDifferentChildrenTransformation::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_with_different_precision_on_children.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_with_different_precision_on_children.cpp index 731946ef016032..0f09ea78560d93 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_with_different_precision_on_children.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_with_different_precision_on_children.cpp @@ -16,42 +16,48 @@ const std::vector netPrecisions = { }; const std::vector trasformationParamValues = { - // LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsI8I8(), LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8() }; const std::vector testValues = { // U8 { + 1, + { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, + { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f / 2.f} } + }, + // U8 and unsupported concat axis + { + 2, { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f / 2.f} } }, // I8 { - { 256ul, ngraph::Shape({}), {-128.f}, {127.f}, {-1.28f}, {1.27f} }, - { 256ul, ngraph::Shape({}), {-128.f}, {127.f}, {-1.28f / 2}, {1.27f / 2} } + 1, + { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f}, {1.27f} }, + { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f / 2.f}, {1.27f / 2.f} } }, // mixed: U8 + I8 { + 1, { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} }, { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f}, {1.27f} } }, // mixed: I8 + U8 { + 1, { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {-1.28f}, {1.27f} }, { 256ul, ngraph::Shape({}), {0.f}, {2.55f}, {0.f}, {2.55f} } } }; -const std::vector multiChannel = { true/*, false*/ }; - INSTANTIATE_TEST_SUITE_P(smoke_LPT, ConcatWithDifferentChildrenTransformation, ::testing::Combine( ::testing::ValuesIn(netPrecisions), ::testing::Values(ngraph::PartialShape({ 1, 3, 10, 10 })), ::testing::Values(CommonTestUtils::DEVICE_GPU), ::testing::ValuesIn(testValues), - ::testing::ValuesIn(trasformationParamValues), - ::testing::ValuesIn(multiChannel)), + ::testing::ValuesIn(trasformationParamValues)), ConcatWithDifferentChildrenTransformation::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_with_different_precision_on_children.hpp b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_with_different_precision_on_children.hpp index a92974bed4c179..72a7c4b06e871c 100644 --- a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_with_different_precision_on_children.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_with_different_precision_on_children.hpp @@ -13,6 +13,7 @@ namespace LayerTestsDefinitions { class ConcatWithDifferentChildrenTransformationParam { public: + std::int64_t axis; ngraph::builder::subgraph::FakeQuantizeOnData fqOnData1; ngraph::builder::subgraph::FakeQuantizeOnData fqOnData2; }; @@ -22,9 +23,8 @@ typedef std::tuple< ngraph::PartialShape, std::string, // target device: CPU, GPU ConcatWithDifferentChildrenTransformationParam, - ngraph::pass::low_precision::LayerTransformation::Params, // transformation parameters - // multichannel - bool> ConcatWithDifferentChildrenTransformationParams; + ngraph::pass::low_precision::LayerTransformation::Params // transformation parameters + > ConcatWithDifferentChildrenTransformationParams; class ConcatWithDifferentChildrenTransformation : public testing::WithParamInterface, diff --git a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_with_different_precision_on_children.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_with_different_precision_on_children.cpp index 6334b3d644f70a..1bca896058b55f 100644 --- a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_with_different_precision_on_children.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_with_different_precision_on_children.cpp @@ -25,13 +25,12 @@ std::string ConcatWithDifferentChildrenTransformation::getTestCaseName(testing:: std::string targetDevice; ConcatWithDifferentChildrenTransformationParam param; ngraph::pass::low_precision::LayerTransformation::Params params; - bool multiChannel; - std::tie(netPrecision, inputShapes, targetDevice, param, params, multiChannel) = obj.param; + std::tie(netPrecision, inputShapes, targetDevice, param, params) = obj.param; std::ostringstream result; result << getTestCaseNameByParams(netPrecision, inputShapes, targetDevice, params) << - (multiChannel ? "_multichannel" : "") << param.fqOnData1 << param.fqOnData2; + "_axis_" << param.axis << "_" << param.fqOnData1 << param.fqOnData2; return result.str(); } @@ -42,8 +41,7 @@ InferenceEngine::Blob::Ptr ConcatWithDifferentChildrenTransformation::GenerateIn std::string targetDevice; ConcatWithDifferentChildrenTransformationParam param; ngraph::pass::low_precision::LayerTransformation::Params params; - bool multiChannel; - std::tie(netPrecision, inputShapes, targetDevice, param, params, multiChannel) = this->GetParam(); + std::tie(netPrecision, inputShapes, targetDevice, param, params) = this->GetParam(); const float k = (info.name() == "input1") ? 1.f : (info.name() == "input2" ? 2.f : 3.f); return LayerTransformation::GenerateInput(ngraph::element::u8, info.getTensorDesc(), k); @@ -54,11 +52,10 @@ void ConcatWithDifferentChildrenTransformation::SetUp() { ngraph::PartialShape inputShapes; ConcatWithDifferentChildrenTransformationParam param; ngraph::pass::low_precision::LayerTransformation::Params params; - bool multiChannel; - std::tie(netPrecision, inputShapes, targetDevice, param, params, multiChannel) = this->GetParam(); + std::tie(netPrecision, inputShapes, targetDevice, param, params) = this->GetParam(); function = ngraph::builder::subgraph::ConcatFunction::getOriginalWithDifferentPrecisionOnChildren( - netPrecision, inputShapes, param.fqOnData1, param.fqOnData2); + netPrecision, inputShapes, param.axis, param.fqOnData1, param.fqOnData2); } TEST_P(ConcatWithDifferentChildrenTransformation, CompareWithRefImpl) { diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/concat_function.hpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/concat_function.hpp index 241b250bb00256..0aa75c2cfbc9ec 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/concat_function.hpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/concat_function.hpp @@ -82,6 +82,7 @@ class ConcatFunction { static std::shared_ptr getOriginalWithDifferentPrecisionOnChildren( const ngraph::element::Type precision, const ngraph::PartialShape& inputShape, + const std::int64_t axis, const FakeQuantizeOnData& fqOnData1, const FakeQuantizeOnData& fqOnData2); @@ -229,10 +230,12 @@ class ConcatFunction { const ngraph::element::Type precision, const ngraph::PartialShape& inputShape, const bool multiChannel, + const std::int64_t axis, const FakeQuantizeOnData& fqOnData1, const FakeQuantizeOnData& fqOnData2, const ngraph::element::Type precisionBeforeOp, - const DequantizationOperations& dequantizationBefore, + const DequantizationOperations& dequantizationBefore1, + const DequantizationOperations& dequantizationBefore2, const ngraph::element::Type precisionAfterOperation, const DequantizationOperations& dequantizationAfter1, const DequantizationOperations& dequantizationAfter2); diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/concat_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/concat_function.cpp index d07034de213756..28c04e0ed4dd58 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/concat_function.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/concat_function.cpp @@ -600,6 +600,7 @@ std::shared_ptr ConcatFunction::getOriginalWithStridedSlice( std::shared_ptr ConcatFunction::getOriginalWithDifferentPrecisionOnChildren( const ngraph::element::Type precision, const ngraph::PartialShape& inputShape, + const std::int64_t axis, const FakeQuantizeOnData& fqOnData1, const FakeQuantizeOnData& fqOnData2) { const auto input1 = std::make_shared(precision, inputShape); @@ -610,11 +611,7 @@ std::shared_ptr ConcatFunction::getOriginalWithDifferentPrecis input2->set_friendly_name("input2"); const auto fakeQuantize2 = makeFakeQuantize(input2, precision, fqOnData2); - const std::shared_ptr concat = std::make_shared( - ngraph::OutputVector{ fakeQuantize1->output(0), fakeQuantize2->output(0) }, 1); - - auto& rtInfo = concat->get_rt_info(); - rtInfo["Variant::std::string"] = std::make_shared>("concat"); + const auto concat = std::make_shared(OutputVector{ fakeQuantize1->output(0), fakeQuantize2->output(0) }, axis); const std::vector kernel = { 3, 3 }; const std::vector stride = { 1, 1 }; @@ -1687,10 +1684,12 @@ std::shared_ptr ConcatFunction::getReferenceWithDifferentPreci const ngraph::element::Type precision, const ngraph::PartialShape& inputShape, const bool multiChannel, + const std::int64_t axis, const FakeQuantizeOnData& fqOnData1, const FakeQuantizeOnData& fqOnData2, const ngraph::element::Type precisionBeforeOp, - const DequantizationOperations& dequantizationBefore, + const DequantizationOperations& dequantizationBefore1, + const DequantizationOperations& dequantizationBefore2, const ngraph::element::Type precisionAfterOperation, const DequantizationOperations& dequantizationAfter1, const DequantizationOperations& dequantizationAfter2) { @@ -1700,7 +1699,7 @@ std::shared_ptr ConcatFunction::getReferenceWithDifferentPreci const auto fakeQuantize1 = makeFakeQuantizeTypeRelaxed(input1, precision, fqOnData1); low_precision::NetworkHelper::setOutDataPrecisionForTypeRelaxed(fakeQuantize1, precisionBeforeOp); fakeQuantize1->set_friendly_name("fakeQuantize1"); - const auto deqBefore1 = makeDequantization(fakeQuantize1, dequantizationBefore); + const auto deqBefore1 = makeDequantization(fakeQuantize1, dequantizationBefore1); const auto input2 = std::make_shared(precision, inputShape); input2->set_friendly_name("input2"); @@ -1708,16 +1707,12 @@ std::shared_ptr ConcatFunction::getReferenceWithDifferentPreci const auto fakeQuantize2 = makeFakeQuantizeTypeRelaxed(input2, precision, fqOnData2); low_precision::NetworkHelper::setOutDataPrecisionForTypeRelaxed(fakeQuantize2, precisionBeforeOp); fakeQuantize2->set_friendly_name("fakeQuantize2"); - const auto deqBefore2 = makeDequantization(fakeQuantize2, dequantizationBefore); + const auto deqBefore2 = makeDequantization(fakeQuantize2, dequantizationBefore2); - const std::shared_ptr concat = std::make_shared( - ngraph::OutputVector{ deqBefore1, deqBefore2 }, 1); + const auto concat = std::make_shared(OutputVector{ deqBefore1, deqBefore2 }, axis); low_precision::NetworkHelper::setOutDataPrecision(concat, precisionAfterOperation); concat->set_friendly_name("concat"); - auto& rtInfo = concat->get_rt_info(); - rtInfo["Variant::std::string"] = std::make_shared>("concat"); - const auto lastDequantization1 = makeDequantization(concat->output(0), dequantizationAfter1); const std::vector kernel = { 3, 3 }; @@ -1741,20 +1736,18 @@ std::shared_ptr ConcatFunction::getReferenceWithDifferentPreci ngraph::ResultVector results; results.push_back(std::make_shared(avgPool)); - if (!dequantizationAfter2.empty()) { - const std::shared_ptr maxPool = std::make_shared( - concat->output(0), - stride, - padBegin, - padEnd, - kernel, - roundingType, - padType); - - const std::shared_ptr lastDequantization2 = makeDequantization(maxPool, dequantizationAfter2); - lastDequantization2->set_friendly_name("MaxPool"); - results.push_back(std::make_shared(lastDequantization2)); - } + const std::shared_ptr maxPool = std::make_shared( + concat->output(0), + stride, + padBegin, + padEnd, + kernel, + roundingType, + padType); + + const std::shared_ptr lastDequantization2 = makeDequantization(maxPool, dequantizationAfter2); + lastDequantization2->set_friendly_name("MaxPool"); + results.push_back(std::make_shared(lastDequantization2)); std::shared_ptr function = std::make_shared( results, From 866c6935d4e7e3ed72387b406ffb15e7bc602662 Mon Sep 17 00:00:00 2001 From: Anastasiia Urlapova Date: Fri, 20 Aug 2021 11:00:03 +0300 Subject: [PATCH 044/102] CVS-56144 Enable all OMZ scope (#7084) --- .../test_runner/skip_configs/skip_config_cpu.lst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/skip_configs/skip_config_cpu.lst b/inference-engine/tests/functional/plugin/conformance/test_runner/skip_configs/skip_config_cpu.lst index 5065186480c3f7..2bef674590ddba 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/skip_configs/skip_config_cpu.lst +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/skip_configs/skip_config_cpu.lst @@ -1,9 +1,3 @@ -# OMZ: -# Hang: -.*AvgPool_1199829.* -.*AvgPool_1201153.* -.*ROIPooling_1199827.* - # DLB: # Hang: .*Convolution_1301086.* From 319473bdb915bd5a87412f8ded060ca13bd5081c Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Fri, 20 Aug 2021 11:09:42 +0300 Subject: [PATCH 045/102] Install layer tests with CMake (#6892) * add CMakeLists.txt * add copyright docstring * add newline after copyright * set target name * change TARGET to DIRECTORY * Rename layer tests dir to avoid name conflict * cmakelists.txt final version * Change destination to tests\layer_tests_openvino * Add cmake_minimum_required to CMakeLists.txt * Update CMakeLists.txt --- tests/layer_tests/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/layer_tests/CMakeLists.txt diff --git a/tests/layer_tests/CMakeLists.txt b/tests/layer_tests/CMakeLists.txt new file mode 100644 index 00000000000000..4f5b64a7220da7 --- /dev/null +++ b/tests/layer_tests/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.13) + +project(layer_tests) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL) From 01e14915f5d4d0a08d234998ae23bd30f3d1a3db Mon Sep 17 00:00:00 2001 From: Gabriele Galiero Casay Date: Fri, 20 Aug 2021 10:58:16 +0200 Subject: [PATCH 046/102] ReverseSequence specification refactored (#7112) * ReverseSequence specification refactored * Change attribute description to avoid confusion * Allow seq_lenghts input to be of floating-point precision --- docs/ops/movement/ReverseSequence_1.md | 42 ++++++++++++++++---------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/docs/ops/movement/ReverseSequence_1.md b/docs/ops/movement/ReverseSequence_1.md index e5f2c3ff6324ed..63c4fa10e5c875 100644 --- a/docs/ops/movement/ReverseSequence_1.md +++ b/docs/ops/movement/ReverseSequence_1.md @@ -2,35 +2,45 @@ **Versioned name**: *ReverseSequence-1* -**Category**: data movement operation +**Category**: *Data movement* **Short description**: *ReverseSequence* reverses variable length slices of data. -**Detailed description**: *ReverseSequence* slices input along the dimension specified in the *batch_axis*, and for each slice *i*, reverses the first *lengths[i]* (the second input) elements along the dimension specified in the *seq_axis*. +**Detailed description** + +*ReverseSequence* slices a given input tensor `data` along the dimension specified in the *batch_axis* attribute. For each slice `i`, it reverses the first `seq_lengths[i]` elements along the dimension specified in the *seq_axis* attribute. **Attributes** * *batch_axis* - * **Description**: *batch_axis* is the index of the batch dimension. - * **Range of values**: an integer. Can be negative. + * **Description**: *batch_axis* is the index of the batch dimension along which `data` input tensor is sliced. + * **Range of values**: an integer within the range `[-rank(data), rank(data) - 1]` * **Type**: `int` - * **Default value**: 0 + * **Default value**: `0` * **Required**: *no* * *seq_axis* - * **Description**: *seq_axis* is the index of the sequence dimension. - * **Range of values**: an integer. Can be negative. + * **Description**: *seq_axis* is the index of the sequence dimension along which elements of `data` input tensor are reversed. + * **Range of values**: an integer within the range `[-rank(data), rank(data) - 1]` * **Type**: `int` - * **Default value**: 1 + * **Default value**: `1` * **Required**: *no* -**Inputs**: +**Inputs** + +* **1**: `data` - Input data to reverse. A tensor of type *T1* and rank greater or equal to 2. **Required.** +* **2**: `seq_lengths` - Sequence lengths to reverse in the input tensor `data`. A 1D tensor comprising `data_shape[batch_axis]` elements of type *T2*. All element values must be integer values within the range `[1, data_shape[seq_axis]]`. Value `1` means, no elements are reversed. **Required.** + +**Outputs** -* **1**: tensor with input data to reverse. **Required.** +* **1**: The result of slice and reverse `data` input tensor. A tensor of type *T1* and the same shape as `data` input tensor. -* **2**: 1D tensor populated with integers with sequence lengths in the 1st input tensor. **Required.** +**Types** + +* *T1*: any supported type. +* *T2*: any supported numerical type. **Example** @@ -38,19 +48,19 @@ - - 3 - 10 + + 4 + 10 100 200 - 3 + 4 - 3 + 4 10 100 200 From a834881babddfa6ba1f37c7ecbe049df8acbf618 Mon Sep 17 00:00:00 2001 From: Olesya Martinyuk Date: Fri, 20 Aug 2021 12:25:59 +0300 Subject: [PATCH 047/102] MemCheck add INT8 models to pre-commit (#7166) * updated desktop configs with int8 models * updated desktop reference configs with actual values * added commit comments --- .../desktop_references_config.xml | 25 +++++++++++++++++++ .../precommit_configs/desktop_test_config.xml | 5 ++++ 2 files changed, 30 insertions(+) diff --git a/tests/stress_tests/.automation/memcheck_tests/precommit_configs/desktop_references_config.xml b/tests/stress_tests/.automation/memcheck_tests/precommit_configs/desktop_references_config.xml index aee644448b28cc..87e2e36522b659 100644 --- a/tests/stress_tests/.automation/memcheck_tests/precommit_configs/desktop_references_config.xml +++ b/tests/stress_tests/.automation/memcheck_tests/precommit_configs/desktop_references_config.xml @@ -51,5 +51,30 @@ # values from {"commit_id": "2947789b3b18a724096abbd9a5c535ae3128ce05", "commit_date": "2021-07-12 23:30"} and *= 1.3 # values from {"commit_id": "761e571042fa2b291d5954e523fffc1e2dfcafae", "commit_date": "2021-05-20 10:36"} and *= 1.3 # values from {"commit_id": "2947789b3b18a724096abbd9a5c535ae3128ce05", "commit_date": "2021-07-12 23:30"} and *= 1.3 + + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 + # values from {"commit_id": "30a30efbc44f3e74a0283acd0f9ccf2e7caf94b6", "commit_date": "2021-08-19 21:17"} and *= 1.3 diff --git a/tests/stress_tests/.automation/memcheck_tests/precommit_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memcheck_tests/precommit_configs/desktop_test_config.xml index ebb16b7de2dd3c..03ac32f1320f5d 100644 --- a/tests/stress_tests/.automation/memcheck_tests/precommit_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memcheck_tests/precommit_configs/desktop_test_config.xml @@ -14,5 +14,10 @@ + + + + + \ No newline at end of file From 57ca5231e97f6f5fc08e72b039ce114a38ddfd65 Mon Sep 17 00:00:00 2001 From: Rafal Blaczkowski Date: Fri, 20 Aug 2021 11:27:02 +0200 Subject: [PATCH 048/102] parametrize proxy (#7174) --- .ci/openvino-onnx/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/openvino-onnx/Jenkinsfile b/.ci/openvino-onnx/Jenkinsfile index ff2e8a451253c4..2849579dcdbf6b 100644 --- a/.ci/openvino-onnx/Jenkinsfile +++ b/.ci/openvino-onnx/Jenkinsfile @@ -113,8 +113,8 @@ def buildDockerImage(Map configuration, String workdir) { --build-arg BUILD_TYPE=${configuration.build_type} \ --build-arg PROTOBUF_LITE=${configuration.protobuf_lite} \ --file=.ci/openvino-onnx/Dockerfile \ - --build-arg http_proxy=http://proxy-ir.intel.com:911/ \ - --build-arg https_proxy=http://proxy-ir.intel.com:911/ . + --build-arg http_proxy=${HTTP_PROXY} \ + --build-arg https_proxy=${HTTPS_PROXY} . """ } From e849b7523f0ebe55b516299d0135e9a698c73d11 Mon Sep 17 00:00:00 2001 From: Anastasia Popova Date: Fri, 20 Aug 2021 17:03:36 +0300 Subject: [PATCH 049/102] Updated list of supported operations. (#6981) * Updated list of supported layers. * Removed Crop, softsign from Kaldi list. * Updated limitations. * Corrected limitations. * Updated limitations. * Added Einsum, corrected Where. * Apply suggestions from code review Co-authored-by: Anastasiya Ageeva Co-authored-by: Anastasiya Ageeva --- .../Supported_Frameworks_Layers.md | 94 ++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md b/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md index d5383275ad62ea..fdda8f40a0b777 100644 --- a/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md +++ b/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md @@ -10,8 +10,11 @@ Standard Caffe\* layers: | BN | No | | BatchNorm | No | | Bias | No | +| Binarization (Intel experimental) | No | | Concat | No | | Convolution | No | +| ConvolutionBinary | No | +| Crop | No | | Deconvolution | No | | DetectionOutput | No | | Dropout | Not needed for inference | @@ -21,14 +24,25 @@ Standard Caffe\* layers: | InnerProduct | No | | Input | No | | LRN | No | +| Normalize | No | +| Python | Supported only for the Python Proposal operation | | Permute | No | | Pooling | No | | Power | No | +| PReLU | No | +| PriorBox | No | +| PriorBoxClustered | No | +| Proposal | No | +| PSROIPooling | No | | ROIPooling | No | +| RegionYolo | No | +| ReorgYolo | No | | ReLU | No | +| Resample | No | | Reshape | No | | Scale | No | | ShuffleChannel | No | +| Sigmoid | No | | Slice | No | | Softmax | No | | Tile | No | @@ -41,31 +55,44 @@ Standard MXNet\* symbols: | Symbol Name in MXNet\*| Limitations| | :----------| :----------| | _Plus | No | +| _contrib_box_nms | No | +| _contrib_DeformableConvolution | No | +| _contrib_DeformablePSROIPooling | No | | _contrib_MultiBoxDetection | "force_suppress" = 1 is not supported, non-default variances are not supported | | _contrib_MultiBoxPrior | No | | _contrib_Proposal | No | | _copy | Not needed for inference | +| _div_scalar | No | +| _greater_scalar | No | | _minus_scalar | No | | _mul_scalar | No | +| _plus_scalar | No | +| _rnn_param_concat | No | | _arange | No | | _contrib_AdaptiveAvgPooling2D | Converted to the Average Pooling with fixed paddings | | _maximum | No | | _minimum | No | | _np_roll | No | +| _zeros | No | | add_n | No | | arccosh | No | | arcsinh | No | | arctanh | No | | broadcast_add | No | +| broadcast_div | No | | broadcast_mul | No | +| broadcast_sub | No | +| BlockGrad | No | | cumsum | No | | div_scalar | No | | elementwise_sub | No | | elemwise_add | No | | elemwise_mul | No | +| elemwise_sub | No | | exp | No | | expand_dims | No | | greater_scalar | No | +| max | No | | minus_scalar | No | | null | Not needed for inference | | repeat | No | @@ -74,9 +101,11 @@ Standard MXNet\* symbols: | round | No | | sigmoid | No | | slice | No | +| SliceChannel | No | | slice_axis | No | | slice_channel | No | | slice_like | No | +| softmax | No | | stack | No | | swapaxis | No | | tile | No | @@ -100,6 +129,7 @@ Standard MXNet\* symbols: | L2Normalization | only 4D input is supported | | LRN | No | | LeakyReLU | supported "act_type" = "prelu", "elu", "leaky", "gelu" | +| ones_like | No | | Pad | No | | Pooling | No | | ROIPooling | No | @@ -113,6 +143,7 @@ Standard MXNet\* symbols: | Tile | No | | UpSampling | No | | Where | No | +| zeros_like | No | ## TensorFlow\* Supported Operations @@ -123,18 +154,27 @@ Standard TensorFlow\* operations: | Operation Name in TensorFlow\* | Limitations| | :----------| :----------| +| Abs | No | | Acosh | No | | Add | No | | AddV2 | No | | AddN | No | +| All | No | | ArgMax | No | | ArgMin | No | | Asinh | No | +| Assert | Not needed for inference | +| Assign | Not needed for inference | +| AssignSub | Not needed for inference | | Atanh | No | | AvgPool | No | | AvgPoolV2 | Supported only for constant-foldable kernel_size and strides inputs | +| AvgPool3D | No | +| BatchMatMul | No | +| BatchMatMulV2 | No | | BatchToSpaceND | No | | BiasAdd | No | +| BlockLSTM | No | | Bucketize | CPU only | | BroadcastTo | No | | Cast | No | @@ -144,14 +184,21 @@ Standard TensorFlow\* operations: | Const | No | | Conv2D | No | | Conv2DBackpropInput | No | +| Conv3D | No | +| Conv3DBackpropInputV2 | No | | Cos | No | | Cosh | No | | CropAndResize | "method" = "bilinear" only | +| CTCGreedyDecoder | Supported only with decoded indices output in a dense format | +| CTCLoss | Supported only with decoded indices input in a dense format | | CumSum | No | | DepthToSpace| No | | DepthwiseConv2dNative| No | +| Einsum | Supported only with equation that does not contain repeated labels within a subscript | +| Elu | No | | Enter | Supported only when it is fused to the TensorIterator layer | | Equal | No | +| Erf | No | | Exit | Supported only when it is fused to the TensorIterator layer | | Exp | No | | ExpandDims | No | @@ -163,34 +210,43 @@ Standard TensorFlow\* operations: | FFT | Supported only when it is part of a sub-graph of the special form | | FFT2D | Supported only when it is part of a sub-graph of the special form | | FFT3D | Supported only when it is part of a sub-graph of the special form | +| FIFOQueueV2 | Supported only when it is part of a sub-graph of the special form | | Fill | No | | Floor | No | | FloorDiv | No | +| FloorMod | No | | FusedBatchNorm | No | | FusedBatchNormV2 | No | | FusedBatchNormV3 | No | | Gather | No | | GatherNd | No | +| GatherTree | No | | GatherV2 | No | | Greater | No | | GreaterEqual | No | | Identity | Not needed for shape inference | +| IdentityN | No | | IFFT | Supported only when it is part of a sub-graph of the special form | | IFFT2D | Supported only when it is part of a sub-graph of the special form | | IFFT3D | Supported only when it is part of a sub-graph of the special form | +| IteratorGetNext | Supported only when it is part of a sub-graph of the special form | | LRN | No | +| LeakyRelu | No | | Less | No | +| LessEqual | No | | Log | No | | Log1p | No | | LogicalAnd | No | | LogicalOr | No | | LogicalNot | No | | LogSoftmax | No | +| LookupTableInsertV2 | Supported only when it is part of a sub-graph of the special form | | LoopCond | Supported only when it is fused to the TensorIterator layer | | MatMul | No | | Max | No | | MaxPool | No | | MaxPoolV2 | Supported only for constant-foldable kernel_size and strides inputs | +| MaxPool3D | No | | Maximum | No | | Mean | No | | Merge | Supported only when it is fused to the TensorIterator layer | @@ -200,9 +256,11 @@ Standard TensorFlow\* operations: | Mul | No | | Neg | No | | NextIteration | Supported only when it is fused to the TensorIterator layer | +| NonMaxSuppressionV2 | No | | NonMaxSuppressionV3 | No | | NonMaxSuppressionV4 | No | | NonMaxSuppressionV5 | No | +| NotEqual | No | | NoOp | No | | OneHot | No | | Pack | No | @@ -211,9 +269,11 @@ Standard TensorFlow\* operations: | Placeholder | No | | PlaceholderWithDefault | No | | Prod | No | +| QueueDequeueUpToV2 | Supported only when it is part of a sub-graph of the special form | | Range | No | | Rank | No | | RealDiv | No | +| Reciprocal | No | | Relu | No | | Relu6 | No | | Reshape | No | @@ -221,9 +281,12 @@ Standard TensorFlow\* operations: | ResizeNearestNeighbor | No | | ResourceGather| No | | ReverseSequence | No | +| ReverseV2 | Supported only when can be converted to the ReverseSequence operation | | Roll | No | | Round | No | +| Pow | No | | Rsqrt | No | +| Select | No | | Shape | No | | Sigmoid | No | | Sin | No | @@ -234,6 +297,10 @@ Standard TensorFlow\* operations: | Softplus | No | | Softsign | No | | SpaceToBatchND | No | +| SpaceToDepth | No | +| SparseFillEmptyRows | Supported only when it is part of a sub-graph of the special form | +| SparseReshape | Supported only when it is part of a sub-graph of the special form | +| SparseSegmentSum | Supported only when it is part of a sub-graph of the special form | | SparseToDense | CPU only | | Split | No | | SplitV | No | @@ -242,11 +309,13 @@ Standard TensorFlow\* operations: | SquaredDifference | No | | Square| No | | Squeeze | The case when squeeze axis is not specified is not supported | +| StatelessWhile | No | | StopGradient | Not needed for shape inference | | StridedSlice | Supported only for constant-foldable begin, end, and strides inputs | | Sub | No | | Sum | No | | Swish | No | +| swish_f32 | No | | Switch | Control flow propagation | | Tan | No | | Tanh | No | @@ -260,7 +329,9 @@ Standard TensorFlow\* operations: | TopkV2 | No | | Transpose | No | | Unpack | No | -| Where | No | +| Variable | No | +| VariableV2 | No | +| Where | Supported only when it is part of a sub-graph of the special form | | ZerosLike | No | @@ -356,13 +427,15 @@ Standard Kaldi\* Layers: | :----------| :----------| | addshift | No | | affinecomponent | No | +| affinecomponentpreconditionedonline | No | | affinetransform | No | +| backproptruncationcomponent | No | +| batchnormcomponent | No | | clipgradientcomponent | Not needed for inference | | concat | No | | convolutional1dcomponent | No | | convolutionalcomponent | No | | copy | No | -| Crop | No | | elementwiseproductcomponent | No | | fixedaffinecomponent | No | | fixedbiascomponent | No | @@ -383,9 +456,9 @@ Standard Kaldi\* Layers: | rectifiedlinearcomponent | No | | rescale | No | | sigmoid | No | +| sigmoidcomponent | No | | softmax | No | | softmaxComponent | No | -| softsign | No | | specaugmenttimemaskcomponent | Not needed for inference | | splicecomponent | No | | tanhcomponent | No | @@ -404,12 +477,14 @@ Standard ONNX\* operators: | Acosh | No | | Add | No | | Affine | No | +| And | No | | ArgMax | No | | ArgMin | No | | Asin | No | | Asinh | No | | Atan | No | | Atanh | No | +| ATen | Supported only for the 'embedding_bag' operator | | AveragePool | No | | BatchMatMul | No | | BatchNormalization | No | @@ -426,6 +501,7 @@ Standard ONNX\* operators: | Cosh | No | | Crop | No | | CumSum | No | +| DepthToSpace | No | | DequantizeLinear | No | | DetectionOutput (Intel experimental) | No | | Div | No | @@ -433,7 +509,14 @@ Standard ONNX\* operators: | Elu | No | | Equal | No | | Erf | No | +| Exp | No | | Expand | No | +| ExperimentalDetectronDetectionOutput (Intel experimental) | No | +| ExperimentalDetectronGenerateProposalsSingleImage (Intel experimental) | No | +| ExperimentalDetectronGroupNorm (Intel experimental) | No | +| ExperimentalDetectronPriorGridGenerator (Intel experimental) | No | +| ExperimentalDetectronROIFeatureExtractor (Intel experimental) | No | +| ExperimentalDetectronTopKROIs (Intel experimental) | No | | FakeQuantize (Intel experimental) | No | | Fill | No | | Flatten | No | @@ -451,6 +534,7 @@ Standard ONNX\* operators: | HardSigmoid | No | | Identity | Not needed for inference | | ImageScaler | No | +| InstanceNormalization | No | | LRN | No | | LSTM | Peepholes are not supported | | LeakyRelu | No | @@ -461,7 +545,9 @@ Standard ONNX\* operators: | LogicalOr | No | | LogSoftmax | No | | Loop | No | +| LpNormalization | No | | MatMul | No | +| Max | No | | MaxPool | No | | MeanVarianceNormalization | Reduction over the batch dimension is not supported, reduction over all dimensions except batch and channel ones is obligatory | | Min | No | @@ -475,6 +561,7 @@ Standard ONNX\* operators: | Pad | No | | Pow | No | | PriorBox (Intel experimental) | No | +| PriorBoxClustered | No | | QuantizeLinear | No | | RNN | No | | ROIAlign | No | @@ -506,6 +593,7 @@ Standard ONNX\* operators: | Softplus | No | | Softsign | No | | SpaceToDepth | No | +| Split | No | | Sqrt | No | | Squeeze | The case when squeeze axis is not specified is not supported | | Sub | No | From d5be5df55ae4ab14aa0c72ccdaaade4f4fcf37b4 Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Fri, 20 Aug 2021 18:47:45 +0300 Subject: [PATCH 050/102] [MO] turn on MarkSubGraphsWithCorrectLayout for TF NCHW (#7150) * turned on MarkingSubgraphsWithCorrectLayout for TF NCHW * restricted MarkSubgraphsWithCorrectLayout.py only to TF * added comments why need to MarkSubgraphsWithCorrectLayout even for TF NCHW models --- .../extensions/middle/MarkSubgraphsWithCorrectLayout.py | 8 ++++++-- model-optimizer/mo/ops/convolution.py | 3 +++ model-optimizer/mo/ops/deconvolution.py | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py b/model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py index 5017d3e4660a9c..129cd184361db6 100644 --- a/model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py +++ b/model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py @@ -22,10 +22,14 @@ class MarkSubGraphsWithCorrectLayout(MiddleReplacementPattern): 1. Prevents from adding Transpose operations before and after "reinterp_shape" like operations which change rank of the input and output tensors of this layout agnostic op. 2. Disable attributes permutation for all intermediate ops between these "reinterp_shape" nodes. - 3. Marks nodes along the weight path of convolutions as in correct layout to not permute them from NHWC to NCHW + 3. Marks nodes along the weight path of convolutions as in correct layout to not permute them from NHWC to NCHW. + The latest is needed for TF NCHW graphs as well. In Conv/Deconv infer functions "set_permutation()" + ads "permutation" attr to weights data node even for NCHW, it is needed to permute Conv weights from the + original TF layout into IE even for NCHW graphs. Therefore for TF models + to prevent unwarranted permutations need to mark weights path as having correct layout even for NCHW graphs. """ enabled = True - graph_condition = [lambda graph: graph.graph['layout'] == 'NHWC'] + graph_condition = [lambda graph: graph.graph['fw'] == 'tf'] op_conditions = [lambda n: n.soft_get('op') == 'MatMul' and any([len(port.data.get_shape()) in (4, 5) for port in n.in_ports().values()]), ] diff --git a/model-optimizer/mo/ops/convolution.py b/model-optimizer/mo/ops/convolution.py index ee24fcd137069a..3a7ff6cc28882d 100644 --- a/model-optimizer/mo/ops/convolution.py +++ b/model-optimizer/mo/ops/convolution.py @@ -256,6 +256,9 @@ def infer(node: Node): ('output_feature_channel', 'input:{}'.format(weights_index)), ]) + # is needed to permute Conv weights from the original TF [H, W, C_IN, C_OUT] into IE [C_OUT, C_IN, H, W] + # but for other nodes in weights subgraph permutations must turned off + # by marking with MarkSubGraphsWithCorrectLayout even if graph layout is NCHW. PermuteAttrs.set_permutation(node.in_node(weights_index), node, node.soft_get('get_weights_permute', None)) PermuteInputs().set_input_permutation( node.in_node(weights_index), node, 'input:{}'.format(weights_index), 'transpose') diff --git a/model-optimizer/mo/ops/deconvolution.py b/model-optimizer/mo/ops/deconvolution.py index f338267c4db5ff..ba080582d85efe 100644 --- a/model-optimizer/mo/ops/deconvolution.py +++ b/model-optimizer/mo/ops/deconvolution.py @@ -99,7 +99,10 @@ def infer(node: Node): ('input_feature_channel', 'input:1'), ('output_feature_channel', 'input:1'), ]) - + + # is needed to permute Deconv weights from the original TF [H, W, C_OUT, C_IN] into IE [C_IN, C_OUT, H, W] + # but for other nodes in weights subgraph permutations must turned off + # by marking with MarkSubGraphsWithCorrectLayout even if graph layout is NCHW. PermuteAttrs.set_permutation(node.in_node(1), node, node.soft_get('get_weights_permute', None)) PermuteInputs().set_input_permutation(node.in_node(1), node, 'input:1', 'transpose') PermuteInputs().set_input_permutation(node.in_node(2), node, 'input:0', 'shape') From eaa9c123cac6126f4d34025ccf29fc1ff4280968 Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Mon, 23 Aug 2021 08:59:54 +0300 Subject: [PATCH 051/102] [CPU][TESTS][LPT] MatMulTransformations test-cases removed from skip config (#7181) --- .../plugin/cpu/shared_tests_instances/skip_tests_config.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp index f46f975f9791e8..984250795b5386 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp @@ -52,8 +52,6 @@ std::vector disabledTestPatterns() { R"(.*ConvolutionLayerCPUTest.*BF16.*_inFmts=(ndhwc|nhwc).*)", // TODO: 56827. Sporadic test failures R"(.*smoke_Conv.+_FP32.ConvolutionLayerCPUTest\.CompareWithRefs.IS=\(1\.67.+\).*inFmts=n.+c.*_primitive=jit_avx2.*)", - // lpt transformation produce the same names for MatMul and Multiply - R"(.*MatMulTransformation.*)", // incorrect jit_uni_planar_convolution with dilation = {1, 2, 1} and output channel 1 R"(.*smoke_Convolution3D.*D=\(1.2.1\)_O=1.*)", From 555c8b89c1906d21409acdd39b731e7070cf4f1f Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Mon, 23 Aug 2021 09:46:11 +0300 Subject: [PATCH 052/102] Fixed ngraph_onnx_importer compatibility target creation for older cmake (3.10) (#7176) --- cmake/templates/ngraphConfig.cmake.in | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/cmake/templates/ngraphConfig.cmake.in b/cmake/templates/ngraphConfig.cmake.in index b945d0148aa56f..543c14daba606e 100644 --- a/cmake/templates/ngraphConfig.cmake.in +++ b/cmake/templates/ngraphConfig.cmake.in @@ -37,30 +37,27 @@ @PACKAGE_INIT@ -function(set_imported_global target) - get_target_property(IS_IMPORTED_GLOBAL ${target} IMPORTED_GLOBAL) - if (NOT IS_IMPORTED_GLOBAL) - set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE) - endif() -endfunction() - if(NOT TARGET ngraph) include("${CMAKE_CURRENT_LIST_DIR}/ngraphTargets.cmake") - set_imported_global(ngraph::ngraph) - set_imported_global(ngraph::frontend_manager) endif() set(ngraph_ngraph_FOUND ON) set(NGRAPH_LIBRARIES ngraph::ngraph) set(ngraph_onnx_ngraph_frontend_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@) -if (ngraph_onnx_ngraph_frontend_FOUND AND NOT TARGET onnx_ngraph_frontend AND NOT TARGET ngraph::onnx_importer) - set_imported_global(ngraph::onnx_ngraph_frontend) - add_library(ngraph::onnx_importer ALIAS ngraph::onnx_ngraph_frontend) + +# ngraph::onnx_importer target and variables are deprecated +set(ngraph_onnx_importer_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@) +if(ngraph_onnx_importer_FOUND) + set(ONNX_IMPORTER_LIBRARIES ngraph::onnx_ngraph_frontend) + if(NOT TARGET ngraph::onnx_importer) + add_library(ngraph::onnx_importer INTERFACE IMPORTED) + set_target_properties(ngraph::onnx_importer PROPERTIES + INTERFACE_LINK_LIBRARIES ngraph::onnx_ngraph_frontend + ) + endif() endif() + set(ngraph_paddlepaddle_frontend_FOUND @NGRAPH_PDPD_FRONTEND_ENABLE@) -if(ngraph_paddlepaddle_frontend_FOUND AND NOT TARGET paddlepaddle_ngraph_frontend) - set_imported_global(ngraph::paddlepaddle_ngraph_frontend) -endif() check_required_components(ngraph) From 38ac9a292cdf805b01565817ed0e2d246b96ed7b Mon Sep 17 00:00:00 2001 From: Andrew Kwangwoong Park Date: Mon, 23 Aug 2021 16:08:03 +0900 Subject: [PATCH 053/102] [GPU] Fix clBuildProgram failure with ssd_mobilnet_v1_coco and batch=256 (#7121) --- .../detection_output/detection_output_kernel_ref.cpp | 2 +- .../core/cl_kernels/detection_output_gpu_ref.cl | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/detection_output/detection_output_kernel_ref.cpp b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/detection_output/detection_output_kernel_ref.cpp index 8917ecffd7ec5a..aaa51eeccf15b8 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/detection_output/detection_output_kernel_ref.cpp +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/detection_output/detection_output_kernel_ref.cpp @@ -123,7 +123,7 @@ DetectionOutputKernelRef::DispatchData SetDefault(const detection_output_params& dispatchData.lws = {1, 1, 1}; } else { dispatchData.gws = {input.Batch().v, 1, 1}; - dispatchData.lws = {input.Batch().v, 1, 1}; + dispatchData.lws = {1, 1, 1}; } } else { dispatchData.gws = {1, 1, 1}; diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/detection_output_gpu_ref.cl b/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/detection_output_gpu_ref.cl index 6f19536ed68a48..5d9ae37def8d9d 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/detection_output_gpu_ref.cl +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/detection_output_gpu_ref.cl @@ -658,7 +658,7 @@ KERNEL (detection_output_stage_final_caffe)(__global INPUT0_TYPE* input_location __global int *buffer1) { const int batchId = get_global_id(0); - __local int class_offset[LOCAL_BATCHES_NUM * NUM_CLASSES_ACC]; + __local int class_offset[NUM_CLASSES_ACC]; const int total_det = FUNC_CALL(get_accumulated_detections)(buffer1, batchId); buffer1[batchId * NUM_CLASSES_ACC + NUM_CLASSES] = total_det; @@ -689,9 +689,9 @@ KERNEL (detection_output_stage_final_caffe)(__global INPUT0_TYPE* input_location } // calculate starting point of each class - class_offset[scores_size_offset] = 0; + class_offset[0] = 0; for (int i = 1; i < NUM_CLASSES_ACC; ++i) { - class_offset[scores_size_offset + i] = class_offset[scores_size_offset + i - 1] + buffer1[scores_size_offset + i - 1]; + class_offset[i] = class_offset[i - 1] + buffer1[scores_size_offset + i - 1]; } barrier(CLK_LOCAL_MEM_FENCE); @@ -700,7 +700,7 @@ KERNEL (detection_output_stage_final_caffe)(__global INPUT0_TYPE* input_location for (uint idx_num_det = 0; idx_num_det < KEEP_TOP_K; idx_num_det++) { SCORES_INFO score_info; score_info = scoresList[scores_offset + idx_num_det]; - const int idx = startIdx + class_offset[batchId * NUM_CLASSES_ACC + score_info.classId]; + const int idx = startIdx + class_offset[score_info.classId]; output[idx * OUTPUT_ROW_SIZE] = TO_OUTPUT_TYPE(batchId); output[idx * OUTPUT_ROW_SIZE + 1] = TO_OUTPUT_TYPE((DECREASE_LABEL_ID) ? score_info.classId - 1 : score_info.classId); output[idx * OUTPUT_ROW_SIZE + 2] = TO_OUTPUT_TYPE(score_info.score); @@ -719,7 +719,7 @@ KERNEL (detection_output_stage_final_caffe)(__global INPUT0_TYPE* input_location ymax = max(TO_INPUT0_TYPE(0.0), min(TO_INPUT0_TYPE(1.0), ymax)); } vstore4((OUTPUT_TYPE4)(xmin, ymin, xmax, ymax), 0, output + idx * OUTPUT_ROW_SIZE + 3); - class_offset[batchId * NUM_CLASSES_ACC + score_info.classId]++; + class_offset[score_info.classId]++; } } else { const int startIdx = FUNC_CALL(get_start_idx)(buffer1, batchId); @@ -753,7 +753,6 @@ KERNEL (detection_output_stage_final_caffe)(__global INPUT0_TYPE* input_location } } - barrier(CLK_GLOBAL_MEM_FENCE); if(batchId == 0) { const int final_detections = FUNC_CALL(get_final_detections)(buffer1); unroll_for (uint i = final_detections; i < NUM_OF_IMAGES * KEEP_TOP_K; i++) { From 570e4fe3a073dc9d0d4b24f8cdfb0a61899ab5ad Mon Sep 17 00:00:00 2001 From: Katarzyna Mitrus Date: Mon, 23 Aug 2021 10:00:35 +0200 Subject: [PATCH 054/102] Fix v0::MVN default constructor (#7175) --- ngraph/core/include/ngraph/op/mvn.hpp | 2 +- ngraph/core/src/op/mvn.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ngraph/core/include/ngraph/op/mvn.hpp b/ngraph/core/include/ngraph/op/mvn.hpp index 406e289396305e..4b6cd70c63a0df 100644 --- a/ngraph/core/include/ngraph/op/mvn.hpp +++ b/ngraph/core/include/ngraph/op/mvn.hpp @@ -17,7 +17,7 @@ class NGRAPH_API MVN : public Op { public: NGRAPH_RTTI_DECLARATION; - MVN(); + MVN() = default; /// \brief Constructs an MVN operation. /// /// \param data Input tensor with data diff --git a/ngraph/core/src/op/mvn.cpp b/ngraph/core/src/op/mvn.cpp index b70c944a692f1e..6ab313d158355f 100644 --- a/ngraph/core/src/op/mvn.cpp +++ b/ngraph/core/src/op/mvn.cpp @@ -15,8 +15,6 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(op::v0::MVN, "MVN", 0); -op::v0::MVN::MVN() : Op(), m_across_channels(), m_normalize_variance(), m_reduction_axes() {} - op::v0::MVN::MVN(const Output& data, bool across_channels, bool normalize_variance, double eps) : Op({data}), m_eps{eps}, From d84d3bdaadf03fe89b2e1f3aa9fa48bab34ea918 Mon Sep 17 00:00:00 2001 From: Mikhail Letavin Date: Mon, 23 Aug 2021 11:44:51 +0300 Subject: [PATCH 055/102] [GPU] Fixes for correct MultiDevice plugin and inference request behavior (#7161) --- inference-engine/src/cldnn_engine/cldnn_remote_context.cpp | 7 +++++-- inference-engine/thirdparty/clDNN/src/network.cpp | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/inference-engine/src/cldnn_engine/cldnn_remote_context.cpp b/inference-engine/src/cldnn_engine/cldnn_remote_context.cpp index 34c3ae30d295fc..1ee476390d6e6a 100644 --- a/inference-engine/src/cldnn_engine/cldnn_remote_context.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_remote_context.cpp @@ -131,7 +131,7 @@ const std::shared_ptr& CLDNNRemoteBlobImpl::getAllocator() const noe }; std::string CLDNNRemoteBlobImpl::getDeviceName() const noexcept { - return getContextImpl(m_context.lock())->GetPlugin().lock()->GetName(); + return getContextImpl(m_context.lock())->getDeviceName(); }; std::shared_ptr CLDNNRemoteBlobImpl::getContext() const noexcept { @@ -266,7 +266,10 @@ ParamMap CLDNNExecutionContextImpl::getParams() const { } std::string CLDNNExecutionContextImpl::getDeviceName() const noexcept { - return m_plugin.lock()->GetName(); + auto devName = m_plugin.lock()->GetName(); + if (!m_config.device_id.empty()) + devName += "." + m_config.device_id; + return devName; } }; // namespace CLDNNPlugin diff --git a/inference-engine/thirdparty/clDNN/src/network.cpp b/inference-engine/thirdparty/clDNN/src/network.cpp index 1aef6da691c232..9692bd7ee73edf 100644 --- a/inference-engine/thirdparty/clDNN/src/network.cpp +++ b/inference-engine/thirdparty/clDNN/src/network.cpp @@ -418,6 +418,8 @@ void network::set_output_memory(const primitive_id& id, memory::ptr mem_new) { for (auto& prim : o_iter->second) { prim->set_output_memory(eng.reinterpret_buffer(*mem_new, prim->output_memory().get_layout()), false); + if (!_reset_arguments) + prim->set_arguments(); } } From ed1b4bfdb6327cf4f6d4d78aaad9c40f9bdbd370 Mon Sep 17 00:00:00 2001 From: Gabriele Galiero Casay Date: Mon, 23 Aug 2021 12:12:46 +0200 Subject: [PATCH 056/102] Fix op category section in operations spec (#7130) --- docs/ops/activation/HSwish_4.md | 2 +- docs/ops/activation/LogSoftmax_5.md | 2 +- docs/ops/arithmetic/Abs_1.md | 2 +- docs/ops/arithmetic/Acos_1.md | 2 +- docs/ops/arithmetic/Acosh_3.md | 2 +- docs/ops/arithmetic/Add_1.md | 2 +- docs/ops/arithmetic/Asin_1.md | 2 +- docs/ops/arithmetic/Asinh_3.md | 2 +- docs/ops/arithmetic/Atan_1.md | 2 +- docs/ops/arithmetic/Atanh_3.md | 2 +- docs/ops/arithmetic/Ceiling_1.md | 2 +- docs/ops/arithmetic/Cos_1.md | 2 +- docs/ops/arithmetic/Cosh_1.md | 2 +- docs/ops/arithmetic/CumSum_3.md | 2 +- docs/ops/arithmetic/Divide_1.md | 2 +- docs/ops/arithmetic/Erf_1.md | 2 +- docs/ops/arithmetic/FloorMod_1.md | 2 +- docs/ops/arithmetic/Floor_1.md | 2 +- docs/ops/arithmetic/Log_1.md | 2 +- docs/ops/arithmetic/Maximum_1.md | 2 +- docs/ops/arithmetic/Minimum_1.md | 2 +- docs/ops/arithmetic/Mod_1.md | 2 +- docs/ops/arithmetic/Multiply_1.md | 2 +- docs/ops/arithmetic/Negative_1.md | 2 +- docs/ops/arithmetic/Power_1.md | 2 +- docs/ops/arithmetic/Round_5.md | 2 +- docs/ops/arithmetic/Sign_1.md | 2 +- docs/ops/arithmetic/Sin_1.md | 2 +- docs/ops/arithmetic/Sinh_1.md | 2 +- docs/ops/arithmetic/Sqrt_1.md | 2 +- docs/ops/arithmetic/SquaredDifference_1.md | 2 +- docs/ops/arithmetic/Subtract_1.md | 2 +- docs/ops/arithmetic/Tan_1.md | 2 +- docs/ops/arithmetic/Tanh_1.md | 2 +- docs/ops/comparison/Equal_1.md | 2 +- docs/ops/comparison/GreaterEqual_1.md | 2 +- docs/ops/comparison/Greater_1.md | 2 +- docs/ops/comparison/LessEqual_1.md | 2 +- docs/ops/comparison/Less_1.md | 2 +- docs/ops/comparison/NotEqual_1.md | 2 +- docs/ops/condition/Bucketize_3.md | 2 +- docs/ops/condition/If_8.md | 2 +- docs/ops/condition/NonZero_3.md | 2 +- docs/ops/condition/Select_1.md | 2 +- docs/ops/convolution/ConvolutionBackpropData_1.md | 2 +- docs/ops/convolution/Convolution_1.md | 2 +- docs/ops/convolution/DeformableConvolution_1.md | 2 +- docs/ops/convolution/DeformableConvolution_8.md | 2 +- docs/ops/convolution/GroupConvolutionBackpropData_1.md | 2 +- docs/ops/convolution/GroupConvolution_1.md | 2 +- docs/ops/detection/DeformablePSROIPooling_1.md | 2 +- docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md | 2 +- .../ExperimentalDetectronGenerateProposalsSingleImage_6.md | 2 +- docs/ops/detection/ExperimentalDetectronPriorGridGenerator_6.md | 2 +- .../ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md | 2 +- docs/ops/detection/PSROIPooling_1.md | 2 +- docs/ops/detection/PriorBoxClustered_1.md | 2 +- docs/ops/detection/PriorBox_1.md | 2 +- docs/ops/detection/ROIAlign_3.md | 2 +- docs/ops/detection/ROIPooling_1.md | 2 +- docs/ops/generation/RandomUniform_8.md | 2 +- docs/ops/generation/Range_1.md | 2 +- docs/ops/generation/Range_4.md | 2 +- docs/ops/image/Interpolate_1.md | 2 +- docs/ops/image/Interpolate_4.md | 2 +- docs/ops/infrastructure/Loop_5.md | 2 +- docs/ops/infrastructure/TensorIterator_1.md | 2 +- docs/ops/logical/LogicalAnd_1.md | 2 +- docs/ops/logical/LogicalNot_1.md | 2 +- docs/ops/logical/LogicalOr_1.md | 2 +- docs/ops/logical/LogicalXor_1.md | 2 +- docs/ops/matrix/Einsum_7.md | 2 +- docs/ops/matrix/MatMul_1.md | 2 +- docs/ops/movement/Broadcast_1.md | 2 +- docs/ops/movement/Broadcast_3.md | 2 +- docs/ops/movement/Concat_1.md | 2 +- docs/ops/movement/GatherElements_6.md | 2 +- docs/ops/movement/GatherND_5.md | 2 +- docs/ops/movement/Gather_1.md | 2 +- docs/ops/movement/Gather_7.md | 2 +- docs/ops/movement/Gather_8.md | 2 +- docs/ops/movement/Pad_1.md | 2 +- docs/ops/movement/Reverse_1.md | 2 +- docs/ops/movement/Roll_7.md | 2 +- docs/ops/movement/ScatterElementsUpdate_3.md | 2 +- docs/ops/movement/ScatterNDUpdate_3.md | 2 +- docs/ops/movement/ScatterUpdate_3.md | 2 +- docs/ops/movement/ShuffleChannels_1.md | 2 +- docs/ops/movement/Split_1.md | 2 +- docs/ops/movement/StridedSlice_1.md | 2 +- docs/ops/movement/Tile_1.md | 2 +- docs/ops/movement/Transpose_1.md | 2 +- docs/ops/movement/VariadicSplit_1.md | 2 +- docs/ops/quantization/FakeQuantize_1.md | 2 +- docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md | 2 +- docs/ops/sequence/CTCGreedyDecoder_1.md | 2 +- docs/ops/sequence/CTCLoss_4.md | 2 +- docs/ops/sequence/GRUCell_3.md | 2 +- docs/ops/sequence/OneHot_1.md | 2 +- docs/ops/sequence/RNNCell_3.md | 2 +- docs/ops/shape/Reshape_1.md | 2 +- docs/ops/shape/ShapeOf_1.md | 2 +- docs/ops/shape/ShapeOf_3.md | 2 +- docs/ops/shape/Squeeze_1.md | 2 +- docs/ops/shape/Unsqueeze_1.md | 2 +- docs/ops/signals/DFT_7.md | 2 +- docs/ops/signals/IDFT_7.md | 2 +- docs/ops/sort/ExperimentalDetectronTopKROIs_6.md | 2 +- 108 files changed, 108 insertions(+), 108 deletions(-) diff --git a/docs/ops/activation/HSwish_4.md b/docs/ops/activation/HSwish_4.md index 3f27517a44b8a1..b5870983af31f2 100644 --- a/docs/ops/activation/HSwish_4.md +++ b/docs/ops/activation/HSwish_4.md @@ -2,7 +2,7 @@ **Versioned name**: *HSwish-4* -**Category**: *Activation* +**Category**: *Activation function* **Short description**: HSwish takes one input tensor and produces output tensor where the hard version of swish function is applied to the tensor elementwise. diff --git a/docs/ops/activation/LogSoftmax_5.md b/docs/ops/activation/LogSoftmax_5.md index d26488fa968d80..2529657131912e 100644 --- a/docs/ops/activation/LogSoftmax_5.md +++ b/docs/ops/activation/LogSoftmax_5.md @@ -2,7 +2,7 @@ **Versioned name**: *LogSoftmax-5* -**Category**: *Activation* +**Category**: *Activation function* **Short description**: LogSoftmax computes the natural logarithm of softmax values for the given input. diff --git a/docs/ops/arithmetic/Abs_1.md b/docs/ops/arithmetic/Abs_1.md index 1dc73dee933151..457085a36f9329 100644 --- a/docs/ops/arithmetic/Abs_1.md +++ b/docs/ops/arithmetic/Abs_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Abs-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Abs* performs element-wise the absolute value with given tensor. diff --git a/docs/ops/arithmetic/Acos_1.md b/docs/ops/arithmetic/Acos_1.md index 2c274b01c8a69a..5b866047551d25 100644 --- a/docs/ops/arithmetic/Acos_1.md +++ b/docs/ops/arithmetic/Acos_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Acos-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Acos* performs element-wise inverse cosine (arccos) operation with given tensor. diff --git a/docs/ops/arithmetic/Acosh_3.md b/docs/ops/arithmetic/Acosh_3.md index 9f858924d4e01e..20f8dee49695bc 100644 --- a/docs/ops/arithmetic/Acosh_3.md +++ b/docs/ops/arithmetic/Acosh_3.md @@ -2,7 +2,7 @@ **Versioned name**: *Acosh-3* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Acosh* performs element-wise hyperbolic inverse cosine (arccosh) operation with given tensor. diff --git a/docs/ops/arithmetic/Add_1.md b/docs/ops/arithmetic/Add_1.md index d73bdaaea852d5..c71d182cc9fa1c 100644 --- a/docs/ops/arithmetic/Add_1.md +++ b/docs/ops/arithmetic/Add_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Add-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *Add* performs element-wise addition operation with two given tensors applying broadcasting rule specified in the *auto_broacast* attribute. diff --git a/docs/ops/arithmetic/Asin_1.md b/docs/ops/arithmetic/Asin_1.md index 5e7fe068ba768d..69be38d84abd00 100644 --- a/docs/ops/arithmetic/Asin_1.md +++ b/docs/ops/arithmetic/Asin_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Asin-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Asin* performs element-wise inverse sine (arcsin) operation with given tensor. diff --git a/docs/ops/arithmetic/Asinh_3.md b/docs/ops/arithmetic/Asinh_3.md index 6fae01555d00ac..093161399f091e 100644 --- a/docs/ops/arithmetic/Asinh_3.md +++ b/docs/ops/arithmetic/Asinh_3.md @@ -2,7 +2,7 @@ **Versioned name**: *Asinh-3* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Asinh* performs element-wise inverse hyperbolic sine operation (arcsinh) on a given input tensor. diff --git a/docs/ops/arithmetic/Atan_1.md b/docs/ops/arithmetic/Atan_1.md index 7fc9525bf6622c..4439477f2a90fc 100644 --- a/docs/ops/arithmetic/Atan_1.md +++ b/docs/ops/arithmetic/Atan_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Atan-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Atan* performs element-wise inverse tangent (arctangent) operation with given tensor. diff --git a/docs/ops/arithmetic/Atanh_3.md b/docs/ops/arithmetic/Atanh_3.md index d08486c42058a7..57deafc41301d5 100644 --- a/docs/ops/arithmetic/Atanh_3.md +++ b/docs/ops/arithmetic/Atanh_3.md @@ -2,7 +2,7 @@ **Versioned name**: *Atanh-3* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Atanh* performs element-wise hyperbolic inverse tangent (arctangenth) operation with a given tensor. diff --git a/docs/ops/arithmetic/Ceiling_1.md b/docs/ops/arithmetic/Ceiling_1.md index e091824c96da68..4f8a5e983d477b 100644 --- a/docs/ops/arithmetic/Ceiling_1.md +++ b/docs/ops/arithmetic/Ceiling_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Ceiling-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Ceiling* performs element-wise ceiling operation with given tensor. diff --git a/docs/ops/arithmetic/Cos_1.md b/docs/ops/arithmetic/Cos_1.md index 462b98fde2c5c4..6b134d17f9bbaf 100644 --- a/docs/ops/arithmetic/Cos_1.md +++ b/docs/ops/arithmetic/Cos_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Cos-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Cos* performs element-wise cosine operation on a given input tensor. diff --git a/docs/ops/arithmetic/Cosh_1.md b/docs/ops/arithmetic/Cosh_1.md index 7f1e3055dd3d47..e736b2fb11fc67 100644 --- a/docs/ops/arithmetic/Cosh_1.md +++ b/docs/ops/arithmetic/Cosh_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Cosh-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Cosh* performs element-wise hyperbolic cosine operation on a given input tensor. diff --git a/docs/ops/arithmetic/CumSum_3.md b/docs/ops/arithmetic/CumSum_3.md index 4ae6f8bde56bc5..c33524a39f27fe 100644 --- a/docs/ops/arithmetic/CumSum_3.md +++ b/docs/ops/arithmetic/CumSum_3.md @@ -2,7 +2,7 @@ **Versioned name**: *CumSum-3* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *CumSum* performs cumulative summation of the input elements along the given axis. diff --git a/docs/ops/arithmetic/Divide_1.md b/docs/ops/arithmetic/Divide_1.md index b69a07454a130c..ef07ea3e1fa77b 100644 --- a/docs/ops/arithmetic/Divide_1.md +++ b/docs/ops/arithmetic/Divide_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Divide-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *Divide* performs element-wise division operation with two given tensors applying broadcasting rule specified in the *auto_broacast* attribute. diff --git a/docs/ops/arithmetic/Erf_1.md b/docs/ops/arithmetic/Erf_1.md index 52d2d0301cb679..ff1374162542e1 100644 --- a/docs/ops/arithmetic/Erf_1.md +++ b/docs/ops/arithmetic/Erf_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Erf-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Erf* performs element-wise Gauss error function (erf) on a given input tensor. diff --git a/docs/ops/arithmetic/FloorMod_1.md b/docs/ops/arithmetic/FloorMod_1.md index c573dee8304ccb..eccad4177ef63d 100644 --- a/docs/ops/arithmetic/FloorMod_1.md +++ b/docs/ops/arithmetic/FloorMod_1.md @@ -2,7 +2,7 @@ **Versioned name**: *FloorMod-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *FloorMod* performs an element-wise floor modulo operation with two given tensors applying broadcasting rule specified in the *auto_broadcast* attribute. diff --git a/docs/ops/arithmetic/Floor_1.md b/docs/ops/arithmetic/Floor_1.md index 06690f06df83e2..d62c604e32bab4 100644 --- a/docs/ops/arithmetic/Floor_1.md +++ b/docs/ops/arithmetic/Floor_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Floor-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Floor* performs element-wise floor operation with given tensor. diff --git a/docs/ops/arithmetic/Log_1.md b/docs/ops/arithmetic/Log_1.md index b8074316e79171..f24e3d21542ffe 100644 --- a/docs/ops/arithmetic/Log_1.md +++ b/docs/ops/arithmetic/Log_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Log-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Log* performs element-wise natural logarithm operation with given tensor. diff --git a/docs/ops/arithmetic/Maximum_1.md b/docs/ops/arithmetic/Maximum_1.md index 18eb0e757b9ada..8ef87a94552402 100644 --- a/docs/ops/arithmetic/Maximum_1.md +++ b/docs/ops/arithmetic/Maximum_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Maximum-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *Maximum* performs element-wise maximum operation with two given tensors applying broadcasting rule specified in the *auto_broadcast* attribute. diff --git a/docs/ops/arithmetic/Minimum_1.md b/docs/ops/arithmetic/Minimum_1.md index 30204e136dc18e..8131ffa6bc985c 100644 --- a/docs/ops/arithmetic/Minimum_1.md +++ b/docs/ops/arithmetic/Minimum_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Minimum-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *Minimum* performs element-wise minimum operation with two given tensors applying broadcasting rule specified in the *auto_broadcast* attribute. diff --git a/docs/ops/arithmetic/Mod_1.md b/docs/ops/arithmetic/Mod_1.md index df414c0f4fef2a..febac678ed6af4 100644 --- a/docs/ops/arithmetic/Mod_1.md +++ b/docs/ops/arithmetic/Mod_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Mod-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *Mod* performs an element-wise modulo operation with two given tensors applying broadcasting rule specified in the *auto_broadcast* attribute. diff --git a/docs/ops/arithmetic/Multiply_1.md b/docs/ops/arithmetic/Multiply_1.md index a713c9c0eac91f..c6fd0b11ea2576 100644 --- a/docs/ops/arithmetic/Multiply_1.md +++ b/docs/ops/arithmetic/Multiply_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Multiply-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *Multiply* performs element-wise multiplication operation with two given tensors applying broadcasting rule specified in the *auto_broacast* attribute. diff --git a/docs/ops/arithmetic/Negative_1.md b/docs/ops/arithmetic/Negative_1.md index 997342c2d05da1..5fa0e630ddaf57 100644 --- a/docs/ops/arithmetic/Negative_1.md +++ b/docs/ops/arithmetic/Negative_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Negative-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Negative* performs element-wise negative operation on a given input tensor. diff --git a/docs/ops/arithmetic/Power_1.md b/docs/ops/arithmetic/Power_1.md index 571b4445e3dc25..f4de24bf03845a 100644 --- a/docs/ops/arithmetic/Power_1.md +++ b/docs/ops/arithmetic/Power_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Power-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *Power* performs element-wise power operation with two given tensors applying broadcasting rule specified in the *auto_broadcast* attribute. diff --git a/docs/ops/arithmetic/Round_5.md b/docs/ops/arithmetic/Round_5.md index 85cb480cadd44d..ae423dcd091674 100644 --- a/docs/ops/arithmetic/Round_5.md +++ b/docs/ops/arithmetic/Round_5.md @@ -2,7 +2,7 @@ **Versioned name**: *Round-5* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Round* performs element-wise round operation with given tensor. diff --git a/docs/ops/arithmetic/Sign_1.md b/docs/ops/arithmetic/Sign_1.md index 1aa87097e62136..f9691bf54889a8 100644 --- a/docs/ops/arithmetic/Sign_1.md +++ b/docs/ops/arithmetic/Sign_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Sign-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Sign* performs element-wise sign operation on a given input tensor. diff --git a/docs/ops/arithmetic/Sin_1.md b/docs/ops/arithmetic/Sin_1.md index 24b43d2e39d65b..36bef0863154e2 100644 --- a/docs/ops/arithmetic/Sin_1.md +++ b/docs/ops/arithmetic/Sin_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Sin-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Sin* performs element-wise sine operation with given tensor. diff --git a/docs/ops/arithmetic/Sinh_1.md b/docs/ops/arithmetic/Sinh_1.md index 0f0c83b63e1044..aeb99c7918dd07 100644 --- a/docs/ops/arithmetic/Sinh_1.md +++ b/docs/ops/arithmetic/Sinh_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Sinh-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Sinh* performs element-wise hyperbolic sine (sinh) operation on a given input tensor diff --git a/docs/ops/arithmetic/Sqrt_1.md b/docs/ops/arithmetic/Sqrt_1.md index 9f2d1f665d7ad6..a69dfd6458a7fe 100644 --- a/docs/ops/arithmetic/Sqrt_1.md +++ b/docs/ops/arithmetic/Sqrt_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Sqrt-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: Square root element-wise operation. diff --git a/docs/ops/arithmetic/SquaredDifference_1.md b/docs/ops/arithmetic/SquaredDifference_1.md index 509b70c2e14ce4..b20ec7aa1ce7c4 100644 --- a/docs/ops/arithmetic/SquaredDifference_1.md +++ b/docs/ops/arithmetic/SquaredDifference_1.md @@ -2,7 +2,7 @@ **Versioned name**: *SquaredDifference-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *SquaredDifference* performs element-wise subtract and square the result operation with two given tensors applying broadcasting rule specified in the *auto_broadcast* attribute. diff --git a/docs/ops/arithmetic/Subtract_1.md b/docs/ops/arithmetic/Subtract_1.md index 0720bd3415c3ee..6a35d32ac356eb 100644 --- a/docs/ops/arithmetic/Subtract_1.md +++ b/docs/ops/arithmetic/Subtract_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Subtract-1* -**Category**: Arithmetic binary operation +**Category**: *Arithmetic binary* **Short description**: *Subtract* performs element-wise subtraction operation with two given tensors applying broadcasting rule specified in the *auto_broacast* attribute. diff --git a/docs/ops/arithmetic/Tan_1.md b/docs/ops/arithmetic/Tan_1.md index d9086f7ad5fba0..07491c3c9d19b7 100644 --- a/docs/ops/arithmetic/Tan_1.md +++ b/docs/ops/arithmetic/Tan_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Tan-1* -**Category**: Arithmetic unary operation +**Category**: *Arithmetic unary* **Short description**: *Tan* performs element-wise tangent operation with given tensor. diff --git a/docs/ops/arithmetic/Tanh_1.md b/docs/ops/arithmetic/Tanh_1.md index c5c77dbe0abd64..0c90d4b496d869 100644 --- a/docs/ops/arithmetic/Tanh_1.md +++ b/docs/ops/arithmetic/Tanh_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Tanh-1* -**Category**: *Arithmetic function* +**Category**: *Arithmetic unary* **Short description**: *Tanh* performs element-wise hyperbolic tangent (tanh) operation with given tensor. diff --git a/docs/ops/comparison/Equal_1.md b/docs/ops/comparison/Equal_1.md index 9bdd3361c26d03..bf813ca6c8c4a8 100644 --- a/docs/ops/comparison/Equal_1.md +++ b/docs/ops/comparison/Equal_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Equal-1* -**Category**: Comparison binary operation +**Category**: *Comparison binary* **Short description**: *Equal* performs element-wise comparison operation with two given input tensors applying multi-directional broadcast rules specified in the *auto_broadcast* attribute. diff --git a/docs/ops/comparison/GreaterEqual_1.md b/docs/ops/comparison/GreaterEqual_1.md index f4a29c667fe620..c072a9c5923414 100644 --- a/docs/ops/comparison/GreaterEqual_1.md +++ b/docs/ops/comparison/GreaterEqual_1.md @@ -2,7 +2,7 @@ **Versioned name**: *GreaterEqual-1* -**Category**: Comparison binary operation +**Category**: *Comparison binary* **Short description**: *GreaterEqual* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules. diff --git a/docs/ops/comparison/Greater_1.md b/docs/ops/comparison/Greater_1.md index a1fe52e0364f05..2beb0ce3fd0055 100644 --- a/docs/ops/comparison/Greater_1.md +++ b/docs/ops/comparison/Greater_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Greater-1* -**Category**: Comparison binary operation +**Category**: *Comparison binary* **Short description**: *Greater* performs element-wise comparison operation with two given tensors applying broadcast rules specified in the `auto_broadcast` attribute. diff --git a/docs/ops/comparison/LessEqual_1.md b/docs/ops/comparison/LessEqual_1.md index bb7eed13793881..dbdf80c37165b5 100644 --- a/docs/ops/comparison/LessEqual_1.md +++ b/docs/ops/comparison/LessEqual_1.md @@ -2,7 +2,7 @@ **Versioned name**: *LessEqual-1* -**Category**: Comparison binary operation +**Category**: *Comparison binary* **Short description**: *LessEqual* performs element-wise comparison operation with two given tensors applying broadcast rules specified in the *auto_broadcast* attribute. diff --git a/docs/ops/comparison/Less_1.md b/docs/ops/comparison/Less_1.md index dcf210d6579226..ca24f17cd16e08 100644 --- a/docs/ops/comparison/Less_1.md +++ b/docs/ops/comparison/Less_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Less-1* -**Category**: Comparison binary operation +**Category**: *Comparison binary* **Short description**: *Less* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules. diff --git a/docs/ops/comparison/NotEqual_1.md b/docs/ops/comparison/NotEqual_1.md index 691da41c1759ef..dd077b9d2fc5dd 100644 --- a/docs/ops/comparison/NotEqual_1.md +++ b/docs/ops/comparison/NotEqual_1.md @@ -2,7 +2,7 @@ **Versioned name**: *NotEqual-1* -**Category**: Comparison binary operation +**Category**: *Comparison binary* **Short description**: *NotEqual* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules specified in the `auto_broadcast` attribute. diff --git a/docs/ops/condition/Bucketize_3.md b/docs/ops/condition/Bucketize_3.md index 40b9369f1911d0..2de9a166aea8a0 100644 --- a/docs/ops/condition/Bucketize_3.md +++ b/docs/ops/condition/Bucketize_3.md @@ -2,7 +2,7 @@ **Versioned name**: *Bucketize-3* -**Category**: Condition operation +**Category**: *Condition* **Short description**: *Bucketize* bucketizes the input based on boundaries. This is similar to [Reference](https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/bucketize). diff --git a/docs/ops/condition/If_8.md b/docs/ops/condition/If_8.md index 7de2449b1eada1..3d2e9268901c0b 100644 --- a/docs/ops/condition/If_8.md +++ b/docs/ops/condition/If_8.md @@ -2,7 +2,7 @@ **Versioned name**: *If-8* -**Category**: Infrastructure +**Category**: *Condition* **Short description**: *If* operation contains two internal networks(subgraphs) such as `then_body` and `else_body`, and performs one of them depending on `cond` value. If `cond` is `True`, `then_body` is executed. If `cond` is `False`, diff --git a/docs/ops/condition/NonZero_3.md b/docs/ops/condition/NonZero_3.md index 3034936721ccec..6d71ea808f3555 100644 --- a/docs/ops/condition/NonZero_3.md +++ b/docs/ops/condition/NonZero_3.md @@ -2,7 +2,7 @@ **Versioned name**: *NonZero-3* -**Category**: Condition operation +**Category**: *Condition* **Short description**: *NonZero* returns the indices of the non-zero elements of the input tensor. diff --git a/docs/ops/condition/Select_1.md b/docs/ops/condition/Select_1.md index 56e5fde8eab790..78ec5d5a5d22ce 100644 --- a/docs/ops/condition/Select_1.md +++ b/docs/ops/condition/Select_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Select-1* -**Category**: *Conditions* +**Category**: *Condition* **Short description**: *Select* returns a tensor filled with the elements from the second or the third inputs, depending on the condition (the first input) value. diff --git a/docs/ops/convolution/ConvolutionBackpropData_1.md b/docs/ops/convolution/ConvolutionBackpropData_1.md index a69f5e300ad414..a630a113cf75e4 100644 --- a/docs/ops/convolution/ConvolutionBackpropData_1.md +++ b/docs/ops/convolution/ConvolutionBackpropData_1.md @@ -2,7 +2,7 @@ **Versioned name**: *ConvolutionBackpropData-1* -**Category**: Convolution +**Category**: *Convolution* **Short description**: Computes 1D, 2D or 3D *ConvolutionBackpropData* operation with respect to the input and kernel tensors. Also known as a Transposed Convolution. diff --git a/docs/ops/convolution/Convolution_1.md b/docs/ops/convolution/Convolution_1.md index 431575b99c3641..068bad8b210f4c 100644 --- a/docs/ops/convolution/Convolution_1.md +++ b/docs/ops/convolution/Convolution_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Convolution-1* -**Category**: Convolution +**Category**: *Convolution* **Short description**: Computes 1D, 2D or 3D convolution (cross-correlation to be precise) of input and kernel tensors. diff --git a/docs/ops/convolution/DeformableConvolution_1.md b/docs/ops/convolution/DeformableConvolution_1.md index 6c73e202be5764..ed64bb0e71c0fc 100644 --- a/docs/ops/convolution/DeformableConvolution_1.md +++ b/docs/ops/convolution/DeformableConvolution_1.md @@ -2,7 +2,7 @@ **Versioned name**: *DeformableConvolution-1* -**Category**: Convolution +**Category**: *Convolution* **Short description**: Computes 2D deformable convolution of input and kernel tensors. diff --git a/docs/ops/convolution/DeformableConvolution_8.md b/docs/ops/convolution/DeformableConvolution_8.md index fc7c05a235cf83..9ae40f87a9e418 100644 --- a/docs/ops/convolution/DeformableConvolution_8.md +++ b/docs/ops/convolution/DeformableConvolution_8.md @@ -2,7 +2,7 @@ **Versioned name**: *DeformableConvolution-8* -**Category**: Convolution +**Category**: *Convolution* **Short description**: Computes 2D deformable convolution of input and kernel tensors. diff --git a/docs/ops/convolution/GroupConvolutionBackpropData_1.md b/docs/ops/convolution/GroupConvolutionBackpropData_1.md index 6739d5dfcb031b..94f7bdf267c1fc 100644 --- a/docs/ops/convolution/GroupConvolutionBackpropData_1.md +++ b/docs/ops/convolution/GroupConvolutionBackpropData_1.md @@ -2,7 +2,7 @@ **Versioned name**: *GroupConvolutionBackpropData-1* -**Category**: Convolution +**Category**: *Convolution* **Short description**: Computes 1D, 2D or 3D *GroupConvolutionBackpropData* of input and kernel tensors. diff --git a/docs/ops/convolution/GroupConvolution_1.md b/docs/ops/convolution/GroupConvolution_1.md index 619d5f6151dee8..9739274147cdaa 100644 --- a/docs/ops/convolution/GroupConvolution_1.md +++ b/docs/ops/convolution/GroupConvolution_1.md @@ -2,7 +2,7 @@ **Versioned name**: *GroupConvolution-1* -**Category**: Convolution +**Category**: *Convolution* **Short description**: Computes 1D, 2D or 3D GroupConvolution of input and kernel tensors. diff --git a/docs/ops/detection/DeformablePSROIPooling_1.md b/docs/ops/detection/DeformablePSROIPooling_1.md index 856b273da8d3da..1d4fbfb8abe60a 100644 --- a/docs/ops/detection/DeformablePSROIPooling_1.md +++ b/docs/ops/detection/DeformablePSROIPooling_1.md @@ -2,7 +2,7 @@ **Versioned name**: *DeformablePSROIPooling-1* -**Category**: Object detection +**Category**: *Object detection* **Short description**: *DeformablePSROIPooling* computes deformable position-sensitive pooling of regions of interest specified by input. diff --git a/docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md b/docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md index 56e3222e9734dc..a1008ec14beae3 100644 --- a/docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md +++ b/docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md @@ -2,7 +2,7 @@ **Versioned name**: *ExperimentalDetectronDetectionOutput-6* -**Category**: Object detection +**Category**: *Object detection* **Short description**: The *ExperimentalDetectronDetectionOutput* operation performs non-maximum suppression to generate the detection output using information on location and score predictions. diff --git a/docs/ops/detection/ExperimentalDetectronGenerateProposalsSingleImage_6.md b/docs/ops/detection/ExperimentalDetectronGenerateProposalsSingleImage_6.md index c822f74de8d344..915a269d10f847 100644 --- a/docs/ops/detection/ExperimentalDetectronGenerateProposalsSingleImage_6.md +++ b/docs/ops/detection/ExperimentalDetectronGenerateProposalsSingleImage_6.md @@ -2,7 +2,7 @@ **Versioned name**: *ExperimentalDetectronGenerateProposalsSingleImage-6* -**Category**: Object detection +**Category**: *Object detection* **Short description**: The *ExperimentalDetectronGenerateProposalsSingleImage* operation computes ROIs and their scores based on input data. diff --git a/docs/ops/detection/ExperimentalDetectronPriorGridGenerator_6.md b/docs/ops/detection/ExperimentalDetectronPriorGridGenerator_6.md index d3e1caa51557ed..31078c09516ede 100644 --- a/docs/ops/detection/ExperimentalDetectronPriorGridGenerator_6.md +++ b/docs/ops/detection/ExperimentalDetectronPriorGridGenerator_6.md @@ -2,7 +2,7 @@ **Versioned name**: *ExperimentalDetectronPriorGridGenerator-6* -**Category**: Object detection +**Category**: *Object detection* **Short description**: The *ExperimentalDetectronPriorGridGenerator* operation generates prior grids of specified sizes. diff --git a/docs/ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md b/docs/ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md index effa9472ff330a..b6536e71a12266 100644 --- a/docs/ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md +++ b/docs/ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md @@ -2,7 +2,7 @@ **Versioned name**: *ExperimentalDetectronROIFeatureExtractor-6* -**Category**: Object detection +**Category**: *Object detection* **Short description**: *ExperimentalDetectronROIFeatureExtractor* is the [ROIAlign](ROIAlign_3.md) operation applied over a feature pyramid. diff --git a/docs/ops/detection/PSROIPooling_1.md b/docs/ops/detection/PSROIPooling_1.md index 44d4bca2c8e2c6..4b4546f7efb145 100644 --- a/docs/ops/detection/PSROIPooling_1.md +++ b/docs/ops/detection/PSROIPooling_1.md @@ -2,7 +2,7 @@ **Versioned name**: *PSROIPooling-1* -**Category**: Object detection +**Category**: *Object detection* **Short description**: *PSROIPooling* computes position-sensitive pooling on regions of interest specified by input. diff --git a/docs/ops/detection/PriorBoxClustered_1.md b/docs/ops/detection/PriorBoxClustered_1.md index 3049f851949359..1815e5a72b32bb 100644 --- a/docs/ops/detection/PriorBoxClustered_1.md +++ b/docs/ops/detection/PriorBoxClustered_1.md @@ -2,7 +2,7 @@ **Versioned name**: *PriorBoxClustered-1* -**Category**: Object detection +**Category**: *Object detection* **Short description**: *PriorBoxClustered* operation generates prior boxes of specified sizes normalized to the input image size. diff --git a/docs/ops/detection/PriorBox_1.md b/docs/ops/detection/PriorBox_1.md index 57cd936a8f988f..39ea4afecb2188 100644 --- a/docs/ops/detection/PriorBox_1.md +++ b/docs/ops/detection/PriorBox_1.md @@ -2,7 +2,7 @@ **Versioned name**: *PriorBox-1* -**Category**: Object detection +**Category**: *Object detection* **Short description**: *PriorBox* operation generates prior boxes of specified sizes and aspect ratios across all dimensions. diff --git a/docs/ops/detection/ROIAlign_3.md b/docs/ops/detection/ROIAlign_3.md index 13c049f2f7ebfc..23ad2911039e27 100644 --- a/docs/ops/detection/ROIAlign_3.md +++ b/docs/ops/detection/ROIAlign_3.md @@ -2,7 +2,7 @@ **Versioned name**: *ROIAlign-3* -**Category**: Object detection +**Category**: *Object detection* **Short description**: *ROIAlign* is a *pooling layer* used over feature maps of non-uniform input sizes and outputs a feature map of a fixed size. diff --git a/docs/ops/detection/ROIPooling_1.md b/docs/ops/detection/ROIPooling_1.md index 65da4d44e6d40a..2597fa3d20bb75 100644 --- a/docs/ops/detection/ROIPooling_1.md +++ b/docs/ops/detection/ROIPooling_1.md @@ -2,7 +2,7 @@ **Versioned name**: *ROIPooling-1* -**Category**: Object detection +**Category**: *Object detection* **Short description**: *ROIPooling* is a *pooling layer* used over feature maps of non-uniform input sizes and outputs a feature map of a fixed size. diff --git a/docs/ops/generation/RandomUniform_8.md b/docs/ops/generation/RandomUniform_8.md index 4fff2684d6cc71..8f461bdf045859 100644 --- a/docs/ops/generation/RandomUniform_8.md +++ b/docs/ops/generation/RandomUniform_8.md @@ -2,7 +2,7 @@ **Versioned name**: *RandomUniform-8* -**Category**: Generation +**Category**: *Generation* **Short description**: *RandomUniform* operation generates a sequence of random values from a uniform distribution. diff --git a/docs/ops/generation/Range_1.md b/docs/ops/generation/Range_1.md index 3e2f1d37eef719..3852f0215944c6 100644 --- a/docs/ops/generation/Range_1.md +++ b/docs/ops/generation/Range_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Range-1* -**Category**: Generation +**Category**: *Generation* **Short description**: *Range* operation generates a sequence of numbers according input values [start, stop) with a step. diff --git a/docs/ops/generation/Range_4.md b/docs/ops/generation/Range_4.md index 0c36bac7cfd489..bf57e13412f75b 100644 --- a/docs/ops/generation/Range_4.md +++ b/docs/ops/generation/Range_4.md @@ -2,7 +2,7 @@ **Versioned name**: *Range-4* -**Category**: Generation +**Category**: *Generation* **Short description**: *Range* operation generates a sequence of numbers according input values [start, stop) with a step. diff --git a/docs/ops/image/Interpolate_1.md b/docs/ops/image/Interpolate_1.md index e4f998faf4e389..4cb3ad21030bac 100644 --- a/docs/ops/image/Interpolate_1.md +++ b/docs/ops/image/Interpolate_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Interpolate-1* -**Category**: Image processing +**Category**: *Image processing* **Short description**: *Interpolate* layer performs interpolation of independent slices in input tensor by specified dimensions and attributes. diff --git a/docs/ops/image/Interpolate_4.md b/docs/ops/image/Interpolate_4.md index 6e5b6e8f818431..ef159ab2b82bdc 100644 --- a/docs/ops/image/Interpolate_4.md +++ b/docs/ops/image/Interpolate_4.md @@ -2,7 +2,7 @@ **Versioned name**: *Interpolate-4* -**Category**: Image processing +**Category**: *Image processing* **Short description**: *Interpolate* layer performs interpolation of independent slices in input tensor by specified dimensions and attributes. diff --git a/docs/ops/infrastructure/Loop_5.md b/docs/ops/infrastructure/Loop_5.md index 784dc4ca294ba5..3774c1dc68dd8c 100644 --- a/docs/ops/infrastructure/Loop_5.md +++ b/docs/ops/infrastructure/Loop_5.md @@ -2,7 +2,7 @@ **Versioned name**: *Loop-5* -**Category**: Infrastructure +**Category**: *Infrastructure* **Short description**: *Loop* operation performs recurrent execution of the network, which is described in the `body`, iterating through the data. The operation has similar semantic to the ONNX* Loop [operation](https://github.com/onnx/onnx/blob/master/docs/Changelog.md#Loop-13). diff --git a/docs/ops/infrastructure/TensorIterator_1.md b/docs/ops/infrastructure/TensorIterator_1.md index 6edffef5daef25..996b0b1d3219bf 100644 --- a/docs/ops/infrastructure/TensorIterator_1.md +++ b/docs/ops/infrastructure/TensorIterator_1.md @@ -2,7 +2,7 @@ **Versioned name**: *TensorIterator-1* -**Category**: Infrastructure +**Category**: *Infrastructure* **Short description**: *TensorIterator* layer performs recurrent execution of the network, which is described in the `body`, iterating through the data. diff --git a/docs/ops/logical/LogicalAnd_1.md b/docs/ops/logical/LogicalAnd_1.md index 385dd89a3a341d..b8c935a7769b31 100644 --- a/docs/ops/logical/LogicalAnd_1.md +++ b/docs/ops/logical/LogicalAnd_1.md @@ -2,7 +2,7 @@ **Versioned name**: *LogicalAnd-1* -**Category**: Logical binary operation +**Category**: *Logical binary* **Short description**: *LogicalAnd* performs element-wise logical AND operation with two given tensors applying multi-directional broadcast rules. diff --git a/docs/ops/logical/LogicalNot_1.md b/docs/ops/logical/LogicalNot_1.md index 97c41ddb14c4ff..0552da02c7bd6e 100644 --- a/docs/ops/logical/LogicalNot_1.md +++ b/docs/ops/logical/LogicalNot_1.md @@ -2,7 +2,7 @@ **Versioned name**: *LogicalNot-1* -**Category**: Logical unary operation +**Category**: *Logical unary* **Short description**: *LogicalNot* performs element-wise logical negation operation with given tensor. diff --git a/docs/ops/logical/LogicalOr_1.md b/docs/ops/logical/LogicalOr_1.md index 0e88a6c82fa77c..54c6344b0c5a18 100644 --- a/docs/ops/logical/LogicalOr_1.md +++ b/docs/ops/logical/LogicalOr_1.md @@ -2,7 +2,7 @@ **Versioned name**: *LogicalOr-1* -**Category**: Logical binary operation +**Category**: *Logical binary* **Short description**: *LogicalOr* performs element-wise logical OR operation with two given tensors applying multi-directional broadcast rules. diff --git a/docs/ops/logical/LogicalXor_1.md b/docs/ops/logical/LogicalXor_1.md index a6a832308aea6d..52f25caae6708d 100644 --- a/docs/ops/logical/LogicalXor_1.md +++ b/docs/ops/logical/LogicalXor_1.md @@ -2,7 +2,7 @@ **Versioned name**: *LogicalXor-1* -**Category**: Logical binary operation +**Category**: *Logical binary* **Short description**: *LogicalXor* performs element-wise logical XOR operation with two given tensors applying multi-directional broadcast rules. diff --git a/docs/ops/matrix/Einsum_7.md b/docs/ops/matrix/Einsum_7.md index ab8057dfcee163..94cb138728236d 100644 --- a/docs/ops/matrix/Einsum_7.md +++ b/docs/ops/matrix/Einsum_7.md @@ -2,7 +2,7 @@ **Versioned name**: *Einsum-7* -**Category**: Matrix multiplication +**Category**: *Matrix multiplication* **Short description**: *Einsum* performs the Einstein summation convention on the operands. diff --git a/docs/ops/matrix/MatMul_1.md b/docs/ops/matrix/MatMul_1.md index 2299ea01f96ed8..33ed66953244b0 100644 --- a/docs/ops/matrix/MatMul_1.md +++ b/docs/ops/matrix/MatMul_1.md @@ -2,7 +2,7 @@ **Versioned name**: *MatMul-1* -**Category**: Matrix multiplication +**Category**: *Matrix multiplication* **Short description**: Generalized matrix multiplication diff --git a/docs/ops/movement/Broadcast_1.md b/docs/ops/movement/Broadcast_1.md index b224f6dfc53795..be1db9cc658e55 100644 --- a/docs/ops/movement/Broadcast_1.md +++ b/docs/ops/movement/Broadcast_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Broadcast-1* -**Category**: Data movement +**Category**: *Data movement* **Short description**: *Broadcast* replicates data on the first input to fit a given shape on the second input. diff --git a/docs/ops/movement/Broadcast_3.md b/docs/ops/movement/Broadcast_3.md index 51b91e7aee6476..cd24431324ac9e 100644 --- a/docs/ops/movement/Broadcast_3.md +++ b/docs/ops/movement/Broadcast_3.md @@ -2,7 +2,7 @@ **Versioned name**: *Broadcast-3* -**Category**: Data movement +**Category**: *Data movement* **Short description**: *Broadcast* replicates data on the first input to fit a given shape on the second input. diff --git a/docs/ops/movement/Concat_1.md b/docs/ops/movement/Concat_1.md index 36f2ba620c7843..371ae8bd9a8cf9 100644 --- a/docs/ops/movement/Concat_1.md +++ b/docs/ops/movement/Concat_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Concat-1* -**Category**: data movement operation. +**Category**: *Data movement* **Short description**: Concatenates arbitrary number of input tensors to a single output tensor along one axis. diff --git a/docs/ops/movement/GatherElements_6.md b/docs/ops/movement/GatherElements_6.md index 57b67a697cf4d7..153b52e89c123d 100644 --- a/docs/ops/movement/GatherElements_6.md +++ b/docs/ops/movement/GatherElements_6.md @@ -2,7 +2,7 @@ **Versioned name**: *GatherElements-6* -**Category**: Data movement operations +**Category**: *Data movement* **Short description**: *GatherElements* takes elements from the input `data` tensor at positions specified in the `indices` tensor. diff --git a/docs/ops/movement/GatherND_5.md b/docs/ops/movement/GatherND_5.md index 85270d0c463ee7..322c0e8f2ba6f6 100644 --- a/docs/ops/movement/GatherND_5.md +++ b/docs/ops/movement/GatherND_5.md @@ -2,7 +2,7 @@ **Versioned name**: *GatherND-5* -**Category**: Data movement operations +**Category**: *Data movement* **Short description**: *GatherND* gathers slices from input tensor into a tensor of a shape specified by indices. diff --git a/docs/ops/movement/Gather_1.md b/docs/ops/movement/Gather_1.md index f10724c0a56f03..d105a1dfd9bfa3 100644 --- a/docs/ops/movement/Gather_1.md +++ b/docs/ops/movement/Gather_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Gather-1* -**Category**: Data movement operations +**Category**: *Data movement* **Short description**: *Gather* operation takes slices of data in the first input tensor according to the indices specified in the second input tensor and axis from the third input. diff --git a/docs/ops/movement/Gather_7.md b/docs/ops/movement/Gather_7.md index 63f30c9faaa6d3..19e5854f0cace8 100644 --- a/docs/ops/movement/Gather_7.md +++ b/docs/ops/movement/Gather_7.md @@ -2,7 +2,7 @@ **Versioned name**: *Gather-7* -**Category**: Data movement operations +**Category**: *Data movement* **Short description**: *Gather* operation takes slices of data of the first input tensor according to the indices specified with the second input tensor and axis from the third input. Semantics of this operation is identical to diff --git a/docs/ops/movement/Gather_8.md b/docs/ops/movement/Gather_8.md index 9c07397288c9c7..064023af7734c9 100644 --- a/docs/ops/movement/Gather_8.md +++ b/docs/ops/movement/Gather_8.md @@ -2,7 +2,7 @@ **Versioned name**: *Gather-8* -**Category**: Data movement operations +**Category**: *Data movement* **Short description**: *Gather* operation takes slices of data of the first input tensor according to the indices specified with the second input tensor and axis from the third input. Semantics of this operation is identical to diff --git a/docs/ops/movement/Pad_1.md b/docs/ops/movement/Pad_1.md index 4b9d3a3f642317..5aa1fc6fdb243f 100644 --- a/docs/ops/movement/Pad_1.md +++ b/docs/ops/movement/Pad_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Pad-1* -**Category**: *Data movement operations* +**Category**: *Data movement* **Short description**: *Pad* operation extends an input tensor on edges. The amount and value of padded elements are defined by inputs and attributes. diff --git a/docs/ops/movement/Reverse_1.md b/docs/ops/movement/Reverse_1.md index a75bf520bcca78..31f04969953be3 100644 --- a/docs/ops/movement/Reverse_1.md +++ b/docs/ops/movement/Reverse_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Reverse-1* -**Category**: data movement operation +**Category**: *Data movement* **Short description**: *Reverse* operations reverse specified axis in an input tensor. diff --git a/docs/ops/movement/Roll_7.md b/docs/ops/movement/Roll_7.md index 8633d7bc963f73..fc58a033926c48 100644 --- a/docs/ops/movement/Roll_7.md +++ b/docs/ops/movement/Roll_7.md @@ -2,7 +2,7 @@ **Versioned name**: *Roll-7* -**Category**: data movement operation +**Category**: *Data movement* **Short description**: The *Roll* operation shifts elements of a tensor along specified axes. diff --git a/docs/ops/movement/ScatterElementsUpdate_3.md b/docs/ops/movement/ScatterElementsUpdate_3.md index 5a7a81f76b5c5f..271e98a0b0872c 100644 --- a/docs/ops/movement/ScatterElementsUpdate_3.md +++ b/docs/ops/movement/ScatterElementsUpdate_3.md @@ -2,7 +2,7 @@ **Versioned name**: *ScatterElementsUpdate-3* -**Category**: Data movement operations +**Category**: *Data movement* **Short description**: Creates a copy of the first input tensor with updated elements specified with second and third input tensors. diff --git a/docs/ops/movement/ScatterNDUpdate_3.md b/docs/ops/movement/ScatterNDUpdate_3.md index 42376bcb12ef94..242d4d9b37dcf3 100644 --- a/docs/ops/movement/ScatterNDUpdate_3.md +++ b/docs/ops/movement/ScatterNDUpdate_3.md @@ -2,7 +2,7 @@ **Versioned name**: *ScatterNDUpdate-3* -**Category**: Data movement operations +**Category**: *Data movement* **Short description**: Creates a copy of the first input tensor with updated elements specified with second and third input tensors. diff --git a/docs/ops/movement/ScatterUpdate_3.md b/docs/ops/movement/ScatterUpdate_3.md index 74903e2111794e..b004ad1b663f1f 100644 --- a/docs/ops/movement/ScatterUpdate_3.md +++ b/docs/ops/movement/ScatterUpdate_3.md @@ -2,7 +2,7 @@ **Versioned name**: *ScatterUpdate-3* -**Category**: Data movement operations +**Category**: *Data movement* **Short description**: *ScatterUpdate* creates a copy of the first input tensor with updated elements specified with second and third input tensors. diff --git a/docs/ops/movement/ShuffleChannels_1.md b/docs/ops/movement/ShuffleChannels_1.md index 9970fed7c6a8be..47f3518746cbdf 100644 --- a/docs/ops/movement/ShuffleChannels_1.md +++ b/docs/ops/movement/ShuffleChannels_1.md @@ -4,7 +4,7 @@ **Name**: *ShuffleChannels* -**Category**: Data movement +**Category**: *Data movement* **Short description**: *ShuffleChannels* permutes data in the channel dimension of the input tensor. diff --git a/docs/ops/movement/Split_1.md b/docs/ops/movement/Split_1.md index 7dd0ed6f102a8c..0f78b20e0e0291 100644 --- a/docs/ops/movement/Split_1.md +++ b/docs/ops/movement/Split_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Split-1* -**Category**: *Data movement operations* +**Category**: *Data movement* **Short description**: *Split* operation splits an input tensor into pieces of the same length along some axis. diff --git a/docs/ops/movement/StridedSlice_1.md b/docs/ops/movement/StridedSlice_1.md index da3a580e0ecc64..238bd4c0c36611 100644 --- a/docs/ops/movement/StridedSlice_1.md +++ b/docs/ops/movement/StridedSlice_1.md @@ -2,7 +2,7 @@ **Versioned name**: *StridedSlice-1* -**Category**: Data movement operation +**Category**: *Data movement* **Short description**: *StridedSlice* extracts a strided slice of a tensor. diff --git a/docs/ops/movement/Tile_1.md b/docs/ops/movement/Tile_1.md index b0d17a3fb4703d..76ba4f58490c33 100644 --- a/docs/ops/movement/Tile_1.md +++ b/docs/ops/movement/Tile_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Tile-1* -**Category**: Data movement +**Category**: *Data movement* **Short description**: *Tile* operation repeats an input tensor *"data"* the number of times given by *"repeats"* input tensor along each dimension. * If number of elements in *"repeats"* is more than shape of *"data"*, then *"data"* will be promoted to "*repeats*" by prepending new axes, e.g. let's shape of *"data"* is equal to (2, 3) and *"repeats"* is equal to [2, 2, 2], then shape of *"data"* will be promoted to (1, 2, 3) and result shape will be (2, 4, 6). diff --git a/docs/ops/movement/Transpose_1.md b/docs/ops/movement/Transpose_1.md index 5c38171035edbf..d60387dd8b313c 100644 --- a/docs/ops/movement/Transpose_1.md +++ b/docs/ops/movement/Transpose_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Transpose-1* -**Category**: Data movement +**Category**: *Data movement* **Short description**: *Transpose* operation reorders the input tensor dimensions. diff --git a/docs/ops/movement/VariadicSplit_1.md b/docs/ops/movement/VariadicSplit_1.md index d14bce1324f402..da15f9fc8097be 100644 --- a/docs/ops/movement/VariadicSplit_1.md +++ b/docs/ops/movement/VariadicSplit_1.md @@ -2,7 +2,7 @@ **Versioned name**: *VariadicSplit-1* -**Category**: *Data movement operations* +**Category**: *Data movement* **Short description**: *VariadicSplit* operation splits an input tensor into chunks along some axis. The chunks may have variadic lengths depending on `split_lengths` input tensor. diff --git a/docs/ops/quantization/FakeQuantize_1.md b/docs/ops/quantization/FakeQuantize_1.md index 099cdecc9c5606..6598de09d48eaa 100644 --- a/docs/ops/quantization/FakeQuantize_1.md +++ b/docs/ops/quantization/FakeQuantize_1.md @@ -2,7 +2,7 @@ **Versioned name**: *FakeQuantize-1* -**Category**: Quantization +**Category**: *Quantization* **Short description**: *FakeQuantize* is element-wise linear quantization of floating-point input values into a discrete set of floating-point values. diff --git a/docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md b/docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md index 1ff17376926927..c4122cb50fbdec 100644 --- a/docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md +++ b/docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md @@ -2,7 +2,7 @@ **Versioned name**: *CTCGreedyDecoderSeqLen-6* -**Category**: Sequence processing +**Category**: *Sequence processing* **Short description**: *CTCGreedyDecoderSeqLen* performs greedy decoding of the logits provided as the first input. The sequence lengths are provided as the second input. diff --git a/docs/ops/sequence/CTCGreedyDecoder_1.md b/docs/ops/sequence/CTCGreedyDecoder_1.md index ca90cdcae6c715..cfaced502a4bd4 100644 --- a/docs/ops/sequence/CTCGreedyDecoder_1.md +++ b/docs/ops/sequence/CTCGreedyDecoder_1.md @@ -2,7 +2,7 @@ **Versioned name**: *CTCGreedyDecoder-1* -**Category**: Sequence processing +**Category**: *Sequence processing* **Short description**: *CTCGreedyDecoder* performs greedy decoding on the logits given in input (best path). diff --git a/docs/ops/sequence/CTCLoss_4.md b/docs/ops/sequence/CTCLoss_4.md index 66a2b30167fbc3..cb0925110774a7 100644 --- a/docs/ops/sequence/CTCLoss_4.md +++ b/docs/ops/sequence/CTCLoss_4.md @@ -2,7 +2,7 @@ **Versioned name**: *CTCLoss-4* -**Category**: Sequence processing +**Category**: *Sequence processing* **Short description**: *CTCLoss* computes the CTC (Connectionist Temporal Classification) Loss. diff --git a/docs/ops/sequence/GRUCell_3.md b/docs/ops/sequence/GRUCell_3.md index 0c5f40a69168ca..df5b14046d9a67 100644 --- a/docs/ops/sequence/GRUCell_3.md +++ b/docs/ops/sequence/GRUCell_3.md @@ -2,7 +2,7 @@ **Versioned name**: *GRUCell-3* -**Category**: Sequence processing +**Category**: *Sequence processing* **Short description**: *GRUCell* represents a single GRU Cell that computes the output using the formula described in the [paper](https://arxiv.org/abs/1406.1078). diff --git a/docs/ops/sequence/OneHot_1.md b/docs/ops/sequence/OneHot_1.md index 8554779efc05b0..bc1e37a446f4e0 100644 --- a/docs/ops/sequence/OneHot_1.md +++ b/docs/ops/sequence/OneHot_1.md @@ -2,7 +2,7 @@ **Versioned name**: *OneHot-1* -**Category**: Sequence processing +**Category**: *Sequence processing* **Short description**: *OneHot* sets the elements in the output tensor with specified indices to `on_value` and fills all other locations with `off_value`. diff --git a/docs/ops/sequence/RNNCell_3.md b/docs/ops/sequence/RNNCell_3.md index ea678fd4854e4f..dc7418ec1f2ad7 100644 --- a/docs/ops/sequence/RNNCell_3.md +++ b/docs/ops/sequence/RNNCell_3.md @@ -2,7 +2,7 @@ **Versioned name**: *RNNCell-3* -**Category**: Sequence processing +**Category**: *Sequence processing* **Short description**: *RNNCell* represents a single RNN cell that computes the output using the formula described in the [article](https://hackernoon.com/understanding-architecture-of-lstm-cell-from-scratch-with-code-8da40f0b71f4). diff --git a/docs/ops/shape/Reshape_1.md b/docs/ops/shape/Reshape_1.md index ac3cbbb070736b..324a2dab9ecef0 100644 --- a/docs/ops/shape/Reshape_1.md +++ b/docs/ops/shape/Reshape_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Reshape-1* -**Category**: Shape manipulation +**Category**: *Shape manipulation* **Short description**: *Reshape* operation changes dimensions of the input tensor according to the specified order. Input tensor volume is equal to output tensor volume, where volume is the product of dimensions. diff --git a/docs/ops/shape/ShapeOf_1.md b/docs/ops/shape/ShapeOf_1.md index 7711b7424c3fb5..cda4bd74c618c0 100644 --- a/docs/ops/shape/ShapeOf_1.md +++ b/docs/ops/shape/ShapeOf_1.md @@ -2,7 +2,7 @@ **Versioned name**: *ShapeOf-1* -**Category**: Shape manipulation +**Category**: *Shape manipulation* **Short description**: *ShapeOf* produces 1D tensor with the input tensor shape. diff --git a/docs/ops/shape/ShapeOf_3.md b/docs/ops/shape/ShapeOf_3.md index 8952753ef8285d..3ca8013d627be1 100644 --- a/docs/ops/shape/ShapeOf_3.md +++ b/docs/ops/shape/ShapeOf_3.md @@ -2,7 +2,7 @@ **Versioned name**: *ShapeOf-3* -**Category**: Shape manipulation +**Category**: *Shape manipulation* **Short description**: *ShapeOf* produces 1D tensor with the input tensor shape. diff --git a/docs/ops/shape/Squeeze_1.md b/docs/ops/shape/Squeeze_1.md index 7a8b9733be17d5..535e60c4ac9de6 100644 --- a/docs/ops/shape/Squeeze_1.md +++ b/docs/ops/shape/Squeeze_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Squeeze-1* -**Category**: Shape manipulation +**Category**: *Shape manipulation* **Short description**: *Squeeze* removes dimensions equal to 1 from the first input tensor. diff --git a/docs/ops/shape/Unsqueeze_1.md b/docs/ops/shape/Unsqueeze_1.md index 062a933403bc61..f98616c0ba65ac 100644 --- a/docs/ops/shape/Unsqueeze_1.md +++ b/docs/ops/shape/Unsqueeze_1.md @@ -2,7 +2,7 @@ **Versioned name**: *Unsqueeze-1* -**Category**: Shape manipulation +**Category**: *Shape manipulation* **Short description**: *Unsqueeze* adds dimensions of size 1 to the first input tensor. The second input value specifies a list of dimensions that will be inserted. Indices specify dimensions in the output tensor. diff --git a/docs/ops/signals/DFT_7.md b/docs/ops/signals/DFT_7.md index c9a841446a9ca3..aea3f68337eaf8 100644 --- a/docs/ops/signals/DFT_7.md +++ b/docs/ops/signals/DFT_7.md @@ -2,7 +2,7 @@ **Versioned name**: *DFT-7* -**Category**: Signal processing +**Category**: *Signal processing* **Short description**: *DFT* operation performs the discrete complex-to-complex Fourier transformation of input tensor by specified dimensions. diff --git a/docs/ops/signals/IDFT_7.md b/docs/ops/signals/IDFT_7.md index 78f9446626726d..272480d751dc4f 100644 --- a/docs/ops/signals/IDFT_7.md +++ b/docs/ops/signals/IDFT_7.md @@ -2,7 +2,7 @@ **Versioned name**: *IDFT-7* -**Category**: Signal processing +**Category**: *Signal processing* **Short description**: *IDFT* operation performs the inverse discrete Fourier transformation of input tensor by specified dimensions. diff --git a/docs/ops/sort/ExperimentalDetectronTopKROIs_6.md b/docs/ops/sort/ExperimentalDetectronTopKROIs_6.md index 87a561278612d5..389974558c7acc 100644 --- a/docs/ops/sort/ExperimentalDetectronTopKROIs_6.md +++ b/docs/ops/sort/ExperimentalDetectronTopKROIs_6.md @@ -2,7 +2,7 @@ **Versioned name**: *ExperimentalDetectronTopKROIs-6* -**Category**: Sort +**Category**: *Sorting and maximization* **Short description**: The *ExperimentalDetectronTopKROIs* operation is TopK operation applied to probabilities of input ROIs. From 4bbcdc4c4932b3deeb241ebdccbdea9e6a122a2d Mon Sep 17 00:00:00 2001 From: Evgeny Kotov Date: Mon, 23 Aug 2021 17:07:04 +0300 Subject: [PATCH 057/102] add ngraph::pass::LSTMCellDecomposition as mandatory (#7028) * add ngraph::pass::LSTMCellDecomposition as mandatory * move LSTMCellDecomposition just after CommonOptimizations before all convert opset transformations * code review fixes: add flag that prevents some legacy transformations if their ngraph-based analogues were executed * remove isNgraphPassesUsed from ModelQuantizer * cleanups --- inference-engine/src/gna_plugin/gna_plugin.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index e51914c3cc6fa6..651bf075b6d37f 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -66,6 +66,7 @@ #include "transformations/handle_transposes_around_matmul.hpp" #include "transformations/decompose_2d_conv.hpp" #include "transformations/convert_padded2valid_conv.hpp" +#include "transformations/op_conversions/lstm_cell_decomposition.hpp" #include @@ -680,6 +681,8 @@ void GNAPlugin::LoadNetwork(CNNNetwork & _network) { InitGNADevice(); } + bool isNgraphPassesUsed = false; + if (_network.getFunction()) { CNNNetwork clonedNetwork = InferenceEngine::cloneNetwork(_network); const auto& graph = clonedNetwork.getFunction(); @@ -688,6 +691,7 @@ void GNAPlugin::LoadNetwork(CNNNetwork & _network) { // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass manager.register_pass(); manager.register_pass(); + manager.register_pass(); manager.register_pass(); if (config.gnaCompileTarget == InferenceEngine::GNAConfigParams::GNA_TARGET_2_0) { manager.register_pass(); @@ -732,6 +736,8 @@ void GNAPlugin::LoadNetwork(CNNNetwork & _network) { pass_config->disable(); manager.run_passes(graph); convertedNetwork = InferenceEngine::details::convertFunctionToICNNNetwork(graph, clonedNetwork); + + isNgraphPassesUsed = true; } IE_SUPPRESS_DEPRECATED_START InferenceEngine::CNNNetwork network = convertedNetwork ? InferenceEngine::CNNNetwork{convertedNetwork} : _network; @@ -762,7 +768,8 @@ void GNAPlugin::LoadNetwork(CNNNetwork & _network) { passes->registerPass(); passes->registerPass(); passes->registerPass(); - passes->registerPass(); + if (!isNgraphPassesUsed) + passes->registerPass(); passes->registerPass(); // fake quantisation aware passes From d03e142fe6539437db738319bc3f14f2a3b767e3 Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Mon, 23 Aug 2021 18:35:37 +0300 Subject: [PATCH 058/102] [IE] Convert to unsigned NMS:0 ->Gather path (#6474) * inserted Convert to unsigned * moved declarations from hpp into cpp, specification corrected * added static const modifier * updated convert specification * minor corrections * split into 3 passes(Init, Propogate, Update), renamed final pass to ConvertNmsGatherPathToUnsigned * added description why transformation is needed * added matcher for several NMS versions, removed TRANSFORMATIONS_API macros from cpp * applied comments: - used GraphRewrite instead of FunctionPass - simplified some expressions - corrected case when Converts output goes to multiple nodes - added to MOC transformations - other minor corrections * removed redundant namespace prefixes * fixed #include * removed matcher_scope, debug code, and redundant dynamic_cast --- docs/ops/movement/Gather_8.md | 19 ++- docs/ops/type/Convert_1.md | 11 +- .../src/moc_transformations.cpp | 3 + .../convert_nms_gather_path_to_unsigned.hpp | 32 ++++ .../common_optimizations.cpp | 3 +- .../convert_nms_gather_path_to_unsigned.cpp | 128 ++++++++++++++++ ...nvert_nms_gather_path_to_unsigned_test.cpp | 138 ++++++++++++++++++ 7 files changed, 328 insertions(+), 6 deletions(-) create mode 100644 inference-engine/src/transformations/include/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp create mode 100644 inference-engine/src/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp create mode 100644 inference-engine/tests/functional/inference_engine/transformations/convert_nms_gather_path_to_unsigned_test.cpp diff --git a/docs/ops/movement/Gather_8.md b/docs/ops/movement/Gather_8.md index 064023af7734c9..4120d3f3eaf59f 100644 --- a/docs/ops/movement/Gather_8.md +++ b/docs/ops/movement/Gather_8.md @@ -6,7 +6,8 @@ **Short description**: *Gather* operation takes slices of data of the first input tensor according to the indices specified with the second input tensor and axis from the third input. Semantics of this operation is identical to -TensorFlow\* [Gather](https://www.tensorflow.org/api_docs/python/tf/gather) operation. +TensorFlow\* [Gather](https://www.tensorflow.org/api_docs/python/tf/gather) operation but also includes +support of negative indices. **Detailed description** @@ -15,6 +16,8 @@ TensorFlow\* [Gather](https://www.tensorflow.org/api_docs/python/tf/gather) oper Where `data`, `indices` and `axis` are tensors from first, second and third inputs correspondingly, `b` is the number of batch dimensions. `N` and `M` are numbers of dimensions of `data` and `indices` tensors, respectively. +Allowed values for indices are in the range `[-data.shape[axis], data.shape[axis] - 1]`. If index value exceed allowed +range output data for corresponding index will be filled with zeros (Example 7). **Attributes**: * *batch_dims* @@ -142,13 +145,23 @@ data = [1, 2, 3, 4, 5] output = [1, 4, 5] ``` +Example 7 with indices out of the range: +``` +batch_dims = 0 +axis = 0 + +indices = [3, 10, -20] +data = [1, 2, 3, 4, 5] +output = [4, 0, 0] +``` + **Inputs** * **1**: `data` tensor of type *T* with arbitrary data. **Required.** * **2**: `indices` tensor of type *T_IND* with indices to gather. 0D tensor (scalar) for indices is also allowed. - The values for indices are in the range `[-data[axis], data[axis] - 1]`. - Negative values of indices indicate reverse indexing from `data[axis]`. + The values for indices are in the range `[-data.shape[axis], data.shape[axis] - 1]`. + Negative values of indices indicate reverse indexing from `data.shape[axis]`. **Required.** * **3**: Scalar or 1D tensor `axis` of *T_AXIS* type is a dimension index to gather data from. For example, diff --git a/docs/ops/type/Convert_1.md b/docs/ops/type/Convert_1.md index e26575c70baebe..4ee9dfdda433c0 100644 --- a/docs/ops/type/Convert_1.md +++ b/docs/ops/type/Convert_1.md @@ -8,9 +8,16 @@ **Detailed description** -Conversion from one supported type to another supported type is always allowed. User must be aware of precision loss and value change caused by range difference between two types. For example, a 32-bit float `3.141592` may be round to a 32-bit int `3`. The result of unsupported conversions is undefined, e.g. conversion of negative signed integer value to any unsigned integer type. +Conversion from one supported type to another supported type is always allowed. User must be aware of precision loss +and value change caused by range difference between two types. For example, a 32-bit float `3.141592` may be round +to a 32-bit int `3`. -Output elements are represented as follows: +Conversion of negative signed integer to unsigned integer value happens in accordance with c++ standard. Notably, +result is the unique value of the destination unsigned type that is congruent to the source integer modulo 2^N (where +N is the bit width of the destination type). For example, when an int32 value `-1` is converted to uint32 the result +will be `uint32 max` which is `4,294,967,295`. + +The result of unsupported conversions is undefined. Output elements are represented as follows: \f[ o_{i} = Convert(a_{i}) diff --git a/inference-engine/src/offline_transformations/src/moc_transformations.cpp b/inference-engine/src/offline_transformations/src/moc_transformations.cpp index 9852c5e4b995dd..95aae8c819a3f4 100644 --- a/inference-engine/src/offline_transformations/src/moc_transformations.cpp +++ b/inference-engine/src/offline_transformations/src/moc_transformations.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,8 @@ bool ngraph::pass::MOCTransformations::run_on_function(std::shared_ptr(); manager.register_pass(); manager.register_pass(); + // workaround until dynamism in NMS is not supported + manager.register_pass(); auto transpose_sinking = manager.register_pass(); transpose_sinking->add_matcher(); diff --git a/inference-engine/src/transformations/include/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp b/inference-engine/src/transformations/include/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp new file mode 100644 index 00000000000000..06c0dca450cd26 --- /dev/null +++ b/inference-engine/src/transformations/include/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +namespace ngraph { +namespace pass { + +class TRANSFORMATIONS_API ConvertNmsGatherPathToUnsigned; + +} // namespace pass +} // namespace ngraph + +/** + * @ingroup ie_transformation_common_api + * @brief Converts Gather indices to unsigned if indices are from NMS selected indices output. + * NMS returns -1 for not selected boxes, old version of Gather fill corresponding + * output for such indices with zero. + * But new Gather-8 has support of negative indices indicating counting from the end. + * In order to keep such behaviour (until dynamism is not supported) instead of -1 new + * Gather-8 will accept UINT32_MAX which is always outside of the bounds + * and corresponding output for such indices in gather always will be filled with zeros. + */ +class ngraph::pass::ConvertNmsGatherPathToUnsigned: public ngraph::pass::GraphRewrite { +public: + NGRAPH_RTTI_DECLARATION; + ConvertNmsGatherPathToUnsigned(); +}; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 373e34f9a018f0..253c4f113ab073 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -44,6 +44,7 @@ #include "transformations/common_optimizations/split_squeeze_concat_fusion.hpp" #include "transformations/common_optimizations/transpose_to_reshape.hpp" #include "transformations/common_optimizations/strides_optimization.hpp" +#include "transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp" #include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" #include "transformations/op_conversions/convert_pad_to_group_conv.hpp" #include "transformations/op_conversions/convert_divide.hpp" @@ -66,7 +67,6 @@ #include "transformations/op_conversions/reduce_l1_decomposition.hpp" #include "transformations/op_conversions/reduce_l2_decomposition.hpp" #include "transformations/op_conversions/hswish_decomposition.hpp" -#include "transformations/op_conversions/convert_previous_nms_to_nms_5.hpp" #include "transformations/op_conversions/hsigmoid_decomposition.hpp" #include "transformations/op_conversions/log_softmax_decomposition.hpp" #include "transformations/op_conversions/mvn6_decomposition.hpp" @@ -91,6 +91,7 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptr(); manager.register_pass(); manager.register_pass(); // Resolves dynamism (replaces NonZero), CF needed + manager.register_pass(); // workaround until dynamism in NMS is not supported // TODO: move to KMB manager.register_pass(); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp new file mode 100644 index 00000000000000..22cc9f3df2811c --- /dev/null +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp @@ -0,0 +1,128 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "itt.hpp" +#include "ngraph/node.hpp" + +using namespace ngraph; +using namespace std; + +class InitNMSPath: public pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + + InitNMSPath() { + MATCHER_SCOPE(InitNMSPath); + + auto nms_pattern = pattern::wrap_type(); + + matcher_pass_callback callback = [=](pattern::Matcher &m) { + const auto& out_nodes = m.get_match_root()->output(0).get_target_inputs(); + for (const auto& out_node : out_nodes) { + auto& out_rt_info = out_node.get_node()->get_rt_info(); + out_rt_info["NMS_SELECTED_INDICES"] = make_shared>(""); + } + return true; + }; + + auto m = make_shared(nms_pattern, matcher_name); + register_matcher(m, callback); + } +}; + +NGRAPH_RTTI_DEFINITION(InitNMSPath, "InitNMSPath", 0); + + +class PropagateNMSPath: public pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + + PropagateNMSPath(){ + MATCHER_SCOPE(PropagateNMSPath); + + auto node_pattern = pattern::wrap_type< + opset8::Squeeze, + opset8::Unsqueeze, + opset8::Reshape, + op::util::BroadcastBase, + opset8::StridedSlice, + opset8::VariadicSplit, + opset8::Concat, + opset8::Convert>(); + + matcher_pass_callback callback = [=](pattern::Matcher &m) { + auto node = m.get_match_root(); + const auto & inputs = node->input_values(); + if (any_of(inputs.begin(), inputs.end(), [](const Output & output) { + return output.get_node()->get_rt_info().count("NMS_SELECTED_INDICES"); + })) { + auto & rt_info = node->get_rt_info(); + rt_info["NMS_SELECTED_INDICES"] = make_shared>(""); + } + return true; + }; + + auto m = make_shared(node_pattern, matcher_name); + register_matcher(m, callback); + } +}; + +NGRAPH_RTTI_DEFINITION(PropagateNMSPath, "PropagateNMSPath", 0); + +class UpdateConvertGather: public pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + + UpdateConvertGather(){ + MATCHER_SCOPE(UpdateConvertGather); + + auto node_pattern = pattern::wrap_type(); + + matcher_pass_callback callback = [=](pattern::Matcher &m) { + auto gather = m.get_match_root(); + auto indices = gather->input_value(1); + + const auto& rt_info = indices.get_node()->get_rt_info(); + if (!rt_info.count("NMS_SELECTED_INDICES")) + return false; + + auto out_type = (indices.get_element_type() == element::i64 ? element::u64 : element::u32); + auto existing_convert = dynamic_pointer_cast(indices.get_node_shared_ptr()); + if (existing_convert && indices.get_target_inputs().size() == 1) { + existing_convert->set_convert_element_type(out_type); + existing_convert->validate_and_infer_types(); + } else { + auto new_convert_to_unsigned = make_shared(indices, out_type); + gather->input(1).replace_source_output(new_convert_to_unsigned); + copy_runtime_info(gather, new_convert_to_unsigned); + } + return true; + }; + + auto m = make_shared(node_pattern, matcher_name); + register_matcher(m, callback); + } +}; + +NGRAPH_RTTI_DEFINITION(UpdateConvertGather, "UpdateConvertGather", 0); + +pass::ConvertNmsGatherPathToUnsigned::ConvertNmsGatherPathToUnsigned() { + add_matcher(); + add_matcher(); + add_matcher(); +} + +NGRAPH_RTTI_DEFINITION(pass::ConvertNmsGatherPathToUnsigned, "ConvertNmsGatherPathToUnsigned", 0); diff --git a/inference-engine/tests/functional/inference_engine/transformations/convert_nms_gather_path_to_unsigned_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/convert_nms_gather_path_to_unsigned_test.cpp new file mode 100644 index 00000000000000..47ba365ea94c1d --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/transformations/convert_nms_gather_path_to_unsigned_test.cpp @@ -0,0 +1,138 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "common_test_utils/ngraph_test_utils.hpp" +#include "ngraph/pass/visualize_tree.hpp" +#include +#include +#include +#include +#include + +using namespace testing; +using namespace ngraph; +using namespace std; + +TEST(TransformationTests, test_convert_to_unsigned_nms_gather_1) { + // if Convert doesn't exist + shared_ptr f(nullptr), f_ref(nullptr); + { + auto boxes = make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = make_shared(element::f32, Shape{1, 1, 1000}); + auto nms = make_shared(boxes, scores); + + auto begin = opset8::Constant::create(element::i32, Shape{1}, {3}); + auto end = opset8::Constant::create(element::i32, Shape{1}, {4}); + auto strides = opset8::Constant::create(element::i32, Shape{1}, {1}); + auto ss_node = make_shared(nms->output(0), begin, end, strides, vector{1, 0}, vector{1, 0}); + + // squeeze can be represented as reshape + auto squeeze_node = make_shared(ss_node, opset8::Constant::create(element::i32, Shape{1}, {-1}), true); + // usually input to gather data goes after reshape NMS scores + auto reshape_node = make_shared(scores, opset8::Constant::create(element::i32, Shape{1}, {-1}), true); + auto gather = make_shared(reshape_node, squeeze_node, opset8::Constant::create(element::i32, Shape{1}, {0})); + + f = make_shared(NodeVector{gather}, ParameterVector{boxes, scores}); + + pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto boxes = make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = make_shared(element::f32, Shape{1, 1, 1000}); + auto nms = make_shared(boxes, scores); + + auto begin = opset8::Constant::create(element::i32, Shape{1}, {3}); + auto end = opset8::Constant::create(element::i32, Shape{1}, {4}); + auto strides = opset8::Constant::create(element::i32, Shape{1}, {1}); + auto ss_node = make_shared(nms->output(0), begin, end, strides, vector{1, 0}, vector{1, 0}); + + // squeeze can be represented as reshape + auto squeeze_node = make_shared(ss_node, opset8::Constant::create(element::i32, Shape{1}, {-1}), true); + auto convert = make_shared(squeeze_node, element::Type_t::u64); + auto reshape_node = make_shared(scores, opset8::Constant::create(element::i32, Shape{1}, {-1}), true); + auto gather = make_shared(reshape_node, convert, opset8::Constant::create(element::i32, Shape{1}, {0})); + + f_ref = make_shared(NodeVector{gather}, ParameterVector{boxes, scores}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, test_convert_to_unsigned_nms_gather_2) { + // if Convert already exists + shared_ptr f(nullptr), f_ref(nullptr); + { + auto boxes = make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = make_shared(element::f32, Shape{1, 1, 1000}); + auto nms = make_shared(boxes, scores); + + auto begin = opset8::Constant::create(element::i32, Shape{1}, {3}); + auto end = opset8::Constant::create(element::i32, Shape{1}, {4}); + auto strides = opset8::Constant::create(element::i32, Shape{1}, {1}); + auto ss_node = make_shared(nms->output(0), begin, end, strides, vector{1, 0}, vector{1, 0}); + + // squeeze can be represented as reshape + auto squeeze_node = make_shared(ss_node, opset8::Constant::create(element::i32, Shape{1}, {-1}), true); + auto convert = make_shared(squeeze_node, element::Type_t::i32); + // usually input to gather data goes after reshape NMS scores + auto reshape_node = make_shared(scores, opset8::Constant::create(element::i32, Shape{1}, {-1}), true); + auto gather = make_shared(reshape_node, convert, opset8::Constant::create(element::i32, Shape{1}, {0})); + + f = make_shared(NodeVector{gather}, ParameterVector{boxes, scores}); + + pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto boxes = make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = make_shared(element::f32, Shape{1, 1, 1000}); + auto nms = make_shared(boxes, scores); + + auto begin = opset8::Constant::create(element::i32, Shape{1}, {3}); + auto end = opset8::Constant::create(element::i32, Shape{1}, {4}); + auto strides = opset8::Constant::create(element::i32, Shape{1}, {1}); + auto ss_node = make_shared(nms->output(0), begin, end, strides, vector{1, 0}, vector{1, 0}); + + // squeeze can be represented as reshape + auto squeeze_node = make_shared(ss_node, opset8::Constant::create(element::i32, Shape{1}, {-1}), true); + auto convert = make_shared(squeeze_node, element::Type_t::u32); + auto reshape_node = make_shared(scores, opset8::Constant::create(element::i32, Shape{1}, {-1}), true); + auto gather = make_shared(reshape_node, convert, opset8::Constant::create(element::i32, Shape{1}, {0})); + + f_ref = make_shared(NodeVector{gather}, ParameterVector{boxes, scores}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, test_convert_to_unsigned_nms_gather_3) { + // if NMS output goes not into Gather indices no converts should be inserted + auto boxes = make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = make_shared(element::f32, Shape{1, 1, 1000}); + auto nms = make_shared(boxes, scores); + + auto gather = make_shared(nms->output(0), opset8::Constant::create(element::i32, Shape{1}, {2}), + opset8::Constant::create(element::i32, Shape{1}, {0})); + + shared_ptr f = make_shared(NodeVector{gather}, ParameterVector{boxes, scores}); + + pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + ASSERT_EQ(count_ops_of_type(f), 0); +} From 50959e9fa2d8eb8b3c20ebf226eef04233bba6f3 Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Mon, 23 Aug 2021 18:39:00 +0300 Subject: [PATCH 059/102] [nG] [IE] use GatherBase in negative indices resolver (#7145) * updated pattern matcher into GatherBase in negative indices resolver, so that it is triggered in all versions of operation * copy_runtime_info fix * added constant folding --- .../gather_normalize_negative_indices.cpp | 15 ++++++++------- .../gather_normalize_negative_indices_test.cpp | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp index 86713451869345..ad16993c98703d 100644 --- a/inference-engine/src/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp +++ b/inference-engine/src/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include "itt.hpp" @@ -18,11 +19,11 @@ ngraph::pass::GatherNegativeConstIndicesNormalize::GatherNegativeConstIndicesNor auto data_input = ngraph::pattern::any_input(pattern::has_static_rank()); auto axis_input = ngraph::pattern::wrap_type(); auto indices_input = ngraph::pattern::wrap_type(); - auto gather_node = std::make_shared(data_input, indices_input, axis_input); + auto gather_node = ngraph::pattern::wrap_type({data_input, indices_input, axis_input}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto& pattern_to_output = m.get_pattern_value_map(); - auto gather = std::dynamic_pointer_cast(pattern_to_output.at(gather_node).get_node_shared_ptr()); + auto gather = pattern_to_output.at(gather_node).get_node_shared_ptr(); auto data = pattern_to_output.at(data_input); auto axis_constant = std::dynamic_pointer_cast(pattern_to_output.at(axis_input).get_node_shared_ptr()); auto indices_constant = std::dynamic_pointer_cast(pattern_to_output.at(indices_input).get_node_shared_ptr()); @@ -62,12 +63,12 @@ ngraph::pass::GatherNegativeConstIndicesNormalize::GatherNegativeConstIndicesNor auto input_gather = std::make_shared(shape_of, ngraph::opset7::Constant::create(input_type, Shape{}, {axis_value}), ngraph::opset7::Constant::create(input_type, Shape{}, {0})); - auto add = std::make_shared(input_gather, indices_constant); - auto gather_new = gather_node->copy_with_new_inputs({data, add, axis_constant}); - gather_new->set_friendly_name(gather->get_friendly_name()); + std::shared_ptr add = std::make_shared(input_gather, indices_constant); + if (auto folded_const = ngraph::get_constant_from_source(add)) + add = folded_const; + gather->input(1).replace_source_output(add); - ngraph::copy_runtime_info(gather, {shape_of, input_gather, add, gather_new}); - ngraph::replace_node(gather, gather_new); + ngraph::copy_runtime_info(gather, {shape_of, input_gather, add}); return true; }; diff --git a/inference-engine/tests/functional/inference_engine/transformations/gather_normalize_negative_indices_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/gather_normalize_negative_indices_test.cpp index ec6c4204a9b8a0..1e600d5f300893 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/gather_normalize_negative_indices_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/gather_normalize_negative_indices_test.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -46,7 +47,10 @@ TEST(TransformationTests, GatherNegativeIndicesNormalize) { auto input_gather = std::make_shared(shape_of, ngraph::opset7::Constant::create(indices_type, ngraph::Shape{}, {1}), ngraph::opset7::Constant::create(indices_type, ngraph::Shape{}, {0})); auto add = std::make_shared(input_gather, indices); - auto gather = std::make_shared(data, add, axis); + auto const_add = ngraph::get_constant_from_source(add); + if (const_add == nullptr) + throw ngraph::ngraph_error("indices should've been constant folded"); + auto gather = std::make_shared(data, const_add, axis); f_ref = std::make_shared(ngraph::NodeVector{gather}, ngraph::ParameterVector{data}); } @@ -84,7 +88,10 @@ TEST(TransformationTests, GatherNegativeIndicesNormalize_neg_axis) { auto input_gather = std::make_shared(shape_of, ngraph::opset7::Constant::create(indices_type, ngraph::Shape{}, {1}), ngraph::opset7::Constant::create(indices_type, ngraph::Shape{}, {0})); auto add = std::make_shared(input_gather, indices); - auto gather = std::make_shared(data, add, axis); + auto const_add = ngraph::get_constant_from_source(add); + if (const_add == nullptr) + throw ngraph::ngraph_error("indices should've been constant folded"); + auto gather = std::make_shared(data, const_add, axis); f_ref = std::make_shared(ngraph::NodeVector{gather}, ngraph::ParameterVector{data}); } @@ -122,7 +129,10 @@ TEST(TransformationTests, GatherNegativeIndicesNormalize_dif_input_types) { auto input_gather = std::make_shared(shape_of, ngraph::opset7::Constant::create(indices_type, ngraph::Shape{}, {1}), ngraph::opset7::Constant::create(indices_type, ngraph::Shape{}, {0})); auto add = std::make_shared(input_gather, indices); - auto gather = std::make_shared(data, add, axis); + auto const_add = ngraph::get_constant_from_source(add); + if (const_add == nullptr) + throw ngraph::ngraph_error("indices should've been constant folded"); + auto gather = std::make_shared(data, const_add, axis); f_ref = std::make_shared(ngraph::NodeVector{gather}, ngraph::ParameterVector{data}); } From ad366b8045bb25cba7d4ffee3a97aa530cfdcd0b Mon Sep 17 00:00:00 2001 From: Svetlana Dolinina Date: Mon, 23 Aug 2021 23:11:39 +0300 Subject: [PATCH 060/102] Nested loop (#6710) * initial changes to support nested loop * fixed issues * fixed nested loop extraction * added comments * removed unneeded comments * review fix * added tests * turned off loop tests on GPU * set xfail for TF tests * removed TF test to move it in another repo * fix typo in comment * move duplicated code to separate functions; added asserts * add function for onnx constant creation; add function to create body of loop add comments to test * move main change for nested loop to separate function --- .../extensions/front/onnx/loop_ext.py | 163 +++++++--- tests/layer_tests/onnx_tests/test_loop.py | 285 ++++++++++++++++++ 2 files changed, 403 insertions(+), 45 deletions(-) create mode 100644 tests/layer_tests/onnx_tests/test_loop.py diff --git a/model-optimizer/extensions/front/onnx/loop_ext.py b/model-optimizer/extensions/front/onnx/loop_ext.py index 0a8fc3c36a2690..b45dee7dae4fd5 100644 --- a/model-optimizer/extensions/front/onnx/loop_ext.py +++ b/model-optimizer/extensions/front/onnx/loop_ext.py @@ -16,6 +16,95 @@ from mo.utils.error import Error +def create_edge_with_attrs(graph, src_name, src_internal_id, src_port, dst_id, dst_port): + # src_name - name of input for edge + # src_internal_id - input node dst_id. Can be the same as src_name or different if Parameter was created + assert (graph.has_node(src_internal_id)) + edge_attrs = { + 'out': src_port, + 'in': dst_port, + 'name': src_name, + 'fw_tensor_debug_info': [(src_internal_id, src_name)], + 'in_attrs': ['in', 'name'], + 'out_attrs': ['out', 'name'], + 'data_attrs': ['fw_tensor_debug_info'] + } + graph.add_edge(src_internal_id, dst_id, **edge_attrs) + + +def create_parameter_with_empty_attrs(graph, param_name): + graph.add_node(param_name, kind='op', op='Parameter', name=param_name, pb=None, shape=None) + parameter_node = Node(graph, param_name) + # need to manually update necessary attrs for the node because extractor will not be called + # for it because the node does not have .pb attribute + Parameter.update_node_stat(parameter_node, {}) + parameter_node['internal_layer_id'] = len(graph.nodes) + + return parameter_node + + +def create_cross_body_edge(body_graph, external_edges, additional_params, src_internal_id, dst_id, dst_port): + cur_graph = body_graph + counter = 0 + is_finished = False + transit_parameter = None + # go through all levels of nested graphs starting from the deepest + while not is_finished and 'parent_node' in cur_graph.graph: + parent_graph = cur_graph.graph['parent_node'].graph + external_edges.append([]) + additional_params.append({}) + assert 0 <= counter < len(additional_params) + assert 0 <= counter < len(external_edges) + # if parent graph contains input node, create edge from outer to inner graph + if src_internal_id in parent_graph.graph['tensor_mapping']: + log.debug('The edge between outer and inner graphs detected: {} -> {}'.format(src_internal_id, dst_id)) + # if parameter in inner graph already created, use it. Otherwise - create new one + if parent_graph.graph['tensor_mapping'][src_internal_id] not in additional_params[counter - 1]: + # possibly we create edge through several levels and have created transit parameter + if transit_parameter is None: + # create new Parameter body node and connect the body node with the outer graph using it + param_id = str(src_internal_id) + parameter_node = create_parameter_with_empty_attrs(cur_graph, param_id) + src_id, src_port = param_id, 0 + else: + parameter_node = transit_parameter + src_id, src_port = transit_parameter.id, 0 + external_edges[counter].append((parent_graph.graph['tensor_mapping'][src_internal_id], + parameter_node, src_internal_id)) + additional_params[counter][parent_graph.graph['tensor_mapping'][src_internal_id][0]] = parameter_node + else: + src_id, src_port = additional_params[counter - 1][parent_graph.graph['tensor_mapping'][src_internal_id][0]].id, 0 + is_finished = True + else: + # check that we are not in process of creating edge through several borders + # if we have transit node, it becomes destination of edge + # otherwise create new Parameter + if transit_parameter is None: + # create new Parameter in inner graph in hope that we will find node later + param_id = str(src_internal_id).split(':')[0] + parameter_node = create_parameter_with_empty_attrs(cur_graph, param_id) + else: + parameter_node = transit_parameter + param_id = transit_parameter.id + + # create transit parameter in outer graph in hope that real input will be found later + parent_param_id = str(src_internal_id).split(':')[0] + "_transit" + parent_parameter_node = create_parameter_with_empty_attrs(parent_graph, parent_param_id) + + external_edges[counter].append(((parent_param_id, 0), parameter_node, parent_param_id)) + src_id, src_port = param_id, 0 + additional_params[counter][parent_param_id + ":0"] = parameter_node + transit_parameter = parent_parameter_node + + if cur_graph.has_node(dst_id): + create_edge_with_attrs(cur_graph, src_internal_id, src_id, src_port, dst_id, dst_port) + + cur_graph = parent_graph + counter += 1 + + return is_finished + + class LoopExtractor(FrontExtractorOp): op = 'Loop' enabled = True @@ -29,10 +118,14 @@ def extract(cls, loop_node): # create a Graph object for the body and take graph attributes from the main graph body_graph = Graph() - main_graph_attrs_copy = copy.deepcopy(main_graph.graph) - del main_graph_attrs_copy['tensor_mapping'] + main_graph_attrs_copy = {} + for attr_key, attr_value in main_graph.graph.items(): + if attr_key not in ['tensor_mapping', 'parent_node']: + main_graph_attrs_copy[attr_key] = copy.deepcopy(attr_value) body_graph.graph.update(main_graph_attrs_copy) loop_node['body'] = body_graph + # save parent node for nested loops to know which node contains body (and which graph is on upper level) + body_graph.graph['parent_node'] = loop_node # maps a tensor name to a node produced it and the node port: str -> (node_id, node_port) data_nodes_map = {} @@ -41,7 +134,8 @@ def extract(cls, loop_node): body_parameters = add_initializers_and_inputs_to_graph(body_graph, body_graph_proto, data_nodes_map) external_edges = [] # (src_node, src_out_port), dest_body_parameter_node - additional_params = {} # (src_node, src_out_port) -> parameter_node (for manually added Parameters) + # save additional edges information for graph on each level, the first one is the deepest + additional_params = [] # (src_node, src_out_port) -> parameter_node (for manually added Parameters) # Go through all nodes in the original model order because data nodes are defined on-the-fly and order matters for pb_node in body_graph_proto.node: # create an NX node @@ -52,43 +146,21 @@ def extract(cls, loop_node): # add incoming edges based on data_nodes_map for dst_port, inp in enumerate(pb_node.input): - # should add edge inp --> id + # should add edge src_internal_id --> dst_id if inp not in data_nodes_map: if inp == '': # input is omitted; most likely it corresponds to an optional input for an operator continue - elif inp in main_graph.graph['tensor_mapping']: - log.debug('The edge between outer and inner graphs detected: {} -> {}'.format(inp, id)) - if main_graph.graph['tensor_mapping'][inp] not in additional_params: - # create new Parameter body node and connect the body node with the outer graph using it - param_id = str(inp) - body_graph.add_node(param_id, kind='op', op='Parameter', name=param_id, pb=None, shape=None) - parameter_node = Node(body_graph, param_id) - # need to manually update necessary attrs for the node because extractor will not be called - # for it because the node does not have .pb attribute - Parameter.update_node_stat(parameter_node, {}) - external_edges.append((main_graph.graph['tensor_mapping'][inp], parameter_node, inp)) - src_id, src_port = param_id, 0 - additional_params[main_graph.graph['tensor_mapping'][inp]] = parameter_node - else: - src_id, src_port = additional_params[main_graph.graph['tensor_mapping'][inp]].id, 0 else: - raise Error('Reference to "{}" is not satisfied. A node refer not existing data tensor. ONNX ' - 'model is not consistent. Protobuf fragment: {}', inp, pb_node) + is_finished = create_cross_body_edge(body_graph, external_edges, additional_params, + inp, id, dst_port) + if not is_finished: + raise Error( + 'Reference to "{}" is not satisfied. A node refer not existing data tensor. ONNX ' + 'model is not consistent. Protobuf fragment: {}', inp, pb_node) else: src_id, src_port = data_nodes_map[inp] - - assert (body_graph.has_node(src_id)) - edge_attrs = { - 'out': src_port, - 'in': dst_port, - 'name': inp, - 'fw_tensor_debug_info': [(src_id, inp)], - 'in_attrs': ['in', 'name'], - 'out_attrs': ['out', 'name'], - 'data_attrs': ['fw_tensor_debug_info'] - } - body_graph.add_edge(src_id, id, **edge_attrs) + create_edge_with_attrs(body_graph, inp, src_id, src_port, id, dst_port) # add outgoing edges to data_nodes_map for src_port, out in enumerate(pb_node.output): @@ -130,21 +202,22 @@ def extract(cls, loop_node): # 1 .. loop_carried_dependencies_count - loop carried dependencies # loop_carried_dependencies_count + 1 .. - scan outputs - body_graph.stage = 'front' # some of the inputs/outputs may not be connected but the normalization transformation will take care of it # connection Loop body nodes with external input edges next_loop_input_port_idx = sorted(loop_node.in_edges().keys())[-1] + 1 - for (src_node, src_port), body_node, tensor_name in external_edges: - main_graph.add_edge(src_node, loop_node.id, **{'out': src_port, - 'in': next_loop_input_port_idx, - 'name': src_node, - 'fw_tensor_debug_info': [(src_node, tensor_name)], - 'in_attrs': ['in', 'name'], - 'out_attrs': ['out', 'name'], - 'data_attrs': ['fw_tensor_debug_info']} - ) - Loop.connect_body_input(loop_node, next_loop_input_port_idx, body_node) - next_loop_input_port_idx += 1 + cur_graph = body_graph + for external_edges_subg in external_edges: + if 'parent_node' not in cur_graph.graph: + continue + cur_loop_node = cur_graph.graph['parent_node'] + parent_graph = cur_loop_node.graph + for (src_node, src_port), body_node, tensor_name in external_edges_subg: + create_edge_with_attrs(parent_graph, tensor_name, src_node, src_port, + cur_loop_node.id, next_loop_input_port_idx) + + Loop.connect_body_input(cur_loop_node, next_loop_input_port_idx, body_node) + next_loop_input_port_idx += 1 + cur_graph = parent_graph # mark current iteration input Parameter node Loop.mark_current_iteration_parameter_node(loop_node, body_parameters[0]) diff --git a/tests/layer_tests/onnx_tests/test_loop.py b/tests/layer_tests/onnx_tests/test_loop.py new file mode 100644 index 00000000000000..e5fab7b5adbaaa --- /dev/null +++ b/tests/layer_tests/onnx_tests/test_loop.py @@ -0,0 +1,285 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest + +from common.onnx_layer_test_class import OnnxRuntimeLayerTest + + +class TestLoop(OnnxRuntimeLayerTest): + @staticmethod + def create_const(name, tensor_type, value): + import onnx + from onnx import helper + from onnx import TensorProto + + if tensor_type == TensorProto.INT64: + np_type = np.int64 + elif tensor_type == TensorProto.FLOAT: + np_type = np.float + elif tensor_type == TensorProto.BOOL: + np_type = np.bool + else: + return None + return helper.make_node('Constant', inputs=[], outputs=[name], + value=helper.make_tensor(name='const_tensor', + data_type=tensor_type, + dims=value.shape, + vals=value.flatten().astype(np_type))) + + @staticmethod + def create_body_graph(input_nodes, output_nodes, input_names, output_names, input_shape, graph_name): + # input_nodes - list of input nodes with structure {counter, condition, } + # output_nodes - list of output nodes with structure {condition, , }. + # In this function I assume that every have and + # input_shape - shape of all inputs from + import onnx + from onnx import helper + from onnx import TensorProto + + assert len(input_nodes) > 2 + assert len(output_nodes) == (len(input_nodes) - 2) * 2 + 1 + assert len(input_nodes) == len(input_names) + assert len(output_nodes) == len(output_names) + other_inputs_count = len(input_nodes) - 2 + one_value = np.ones(input_shape, dtype=np.float) + + one = TestLoop.create_const('one_'+graph_name, TensorProto.FLOAT, one_value) + one_int = TestLoop.create_const('one_int_'+graph_name, TensorProto.INT64, np.ones([1])) + + # add one to all inputs except counter and condition + add_one_nodes = [] + for i in range(2, len(input_names)): + add_one_nodes.append(helper.make_node('Add', inputs=[input_names[i], 'one_'+graph_name], + outputs=[output_names[other_inputs_count + i - 1]])) + + # add 1 to counter + add_one_to_m_node = helper.make_node( + 'Add', + inputs=[input_names[0], 'one_int_'+graph_name], + outputs=['counter_plus_1_'+graph_name] + ) + + # map inputs to outputs - back edges + identity_nodes = [] + for i in range(1, len(input_nodes)): + identity_nodes.append(helper.make_node('Identity', + inputs=[input_names[i]], outputs=[output_names[i-1]])) + + body_nodes = [one, one_int] + body_nodes.extend(add_one_nodes) + body_nodes.append(add_one_to_m_node) + body_nodes.extend(identity_nodes) + body_graph = helper.make_graph( + body_nodes, + graph_name, + input_nodes, + output_nodes + ) + + return body_graph + + def create_loop(self): + """ + ONNX net + + Input->Loop->Output => Only accuracy check + + """ + import onnx + from onnx import helper + from onnx import TensorProto + + # Create ONNX model + # Input ---> Loop ---> Identity ---> Result + input_shape = [1, 4, 64, 54] + + in_1 = helper.make_tensor_value_info('IN_1', TensorProto.FLOAT, input_shape) + in_1_int = helper.make_tensor_value_info('in_1_int', TensorProto.FLOAT, input_shape) + in_1_int_out = helper.make_tensor_value_info('in_1_int_out', TensorProto.FLOAT, input_shape) + + out_1 = helper.make_tensor_value_info('OUT_1', TensorProto.FLOAT, None) + res = helper.make_tensor_value_info('res', TensorProto.FLOAT, None) + + m_1 = helper.make_tensor_value_info('m_1', TensorProto.INT64, [1]) + + cond_int_1 = helper.make_tensor_value_info('cond_int_1', TensorProto.BOOL, [1]) + cond_out_1 = helper.make_tensor_value_info('cond_out_1', TensorProto.BOOL, [1]) + + m_1_value = np.array([10], dtype=np.int64) + cond_value = np.array([True], np.bool) + + M_1 = self.create_const('M_1', TensorProto.INT64, m_1_value) + cond = self.create_const('cond', TensorProto.BOOL, cond_value) + + body_graph_1 = self.create_body_graph([m_1, cond_int_1, in_1_int], [cond_out_1, in_1_int_out, out_1], + ['m_1', 'cond_int_1', 'in_1_int'], + ['cond_out_1', 'in_1_int_out', 'OUT_1'], + input_shape, 'body_graph_1') + + node_loop_1 = helper.make_node( + 'Loop', + inputs=['M_1', 'cond', 'IN_1'], + outputs=['cond_out_1', 'OUT_1'], + body=body_graph_1 + ) + + res_node = helper.make_node( + 'Identity', + inputs=['OUT_1'], + outputs=['res'], + ) + + graph_def = helper.make_graph( + [M_1, cond, node_loop_1, res_node], + 'graph', + [in_1], + [res] + ) + + onnx_net = helper.make_model(graph_def, producer_name='test_loop_model') + # We do not create reference graph, as it's too complicated to construct it + # So we return None to skip IR comparision + return onnx_net, None + + def create_loop_in_loop(self): + """ + ONNX net + + Input->Loop(Loop)->Output => Only accuracy check + + """ + import onnx + from onnx import helper + from onnx import TensorProto + + # Create ONNX model + input_shape = [1, 4, 64, 54] + + in_1 = helper.make_tensor_value_info('IN_1', TensorProto.FLOAT, input_shape) + in_1_int = helper.make_tensor_value_info('in_1_int', TensorProto.FLOAT, input_shape) + in_1_int_out = helper.make_tensor_value_info('in_1_int_out', TensorProto.FLOAT, input_shape) + + in_2 = helper.make_tensor_value_info('IN_2', TensorProto.FLOAT, input_shape) + in_2_int = helper.make_tensor_value_info('in_2_int', TensorProto.FLOAT, input_shape) + in_2_int_out = helper.make_tensor_value_info('in_2_int_out', TensorProto.FLOAT, input_shape) + + out_1 = helper.make_tensor_value_info('OUT_1', TensorProto.FLOAT, None) + out_2 = helper.make_tensor_value_info('OUT_2', TensorProto.FLOAT, None) + res = helper.make_tensor_value_info('res', TensorProto.FLOAT, None) + + m_1 = helper.make_tensor_value_info('m_1', TensorProto.INT64, [1]) + m_2 = helper.make_tensor_value_info('m_2', TensorProto.INT64, [1]) + + cond_int_1 = helper.make_tensor_value_info('cond_int_1', TensorProto.BOOL, [1]) + cond_out_1 = helper.make_tensor_value_info('cond_out_1', TensorProto.BOOL, [1]) + cond_int_2 = helper.make_tensor_value_info('cond_int_2', TensorProto.BOOL, [1]) + cond_out_2 = helper.make_tensor_value_info('cond_out_2', TensorProto.BOOL, [1]) + + m_1_value = np.array([10], dtype=np.int64) + m_2_value = np.array([5], dtype=np.int64) + cond_value = np.array([True], np.bool) + one_value = np.ones(input_shape, dtype=np.float) + + M_1 = self.create_const('M_1', TensorProto.INT64, m_1_value) + M_2 = self.create_const('M_2', TensorProto.INT64, m_2_value) + cond = self.create_const('cond', TensorProto.BOOL, cond_value) + one = self.create_const('one', TensorProto.FLOAT, one_value) + one_int = self.create_const('one_int', TensorProto.INT64, one_value) + + # create body of external loop + add_one_node = helper.make_node( + 'Add', + inputs=['in_1_int', 'one'], + outputs=['in_1_loop_1'] + ) + + add_one_to_m_node = helper.make_node( + 'Add', + inputs=['m_1', 'one_int'], + outputs=['m_1_loop_1'] + ) + + cond_2 = self.create_const('cond_2', TensorProto.BOOL, cond_value) + + # create body for internal loop + body_graph_2 = self.create_body_graph([m_2, cond_int_2, in_2_int], [cond_out_2, in_2_int_out, out_2], + ['m_2', 'cond_int_2', 'in_2_int'], + ['cond_out_2', 'in_2_int_out', 'OUT_2'], input_shape, 'body_graph_2') + node_loop_2 = helper.make_node( + 'Loop', + inputs=['M_2', 'cond_2', 'IN_2'], + outputs=['cond_out_2', 'OUT_2'], + body=body_graph_2 + ) + # internal loop created + + out_1_node = helper.make_node( + 'Identity', + inputs=['OUT_2'], + outputs=['OUT_1'], + ) + + cond_1_node = helper.make_node( + 'Identity', + inputs=['cond_int_1'], + outputs=['cond_out_1'], + ) + + in_1_int_node = helper.make_node( + 'Identity', + inputs=['in_1_int'], + outputs=['in_1_int_out'], + ) + + body_graph_1 = helper.make_graph( + [one, add_one_node, one_int, add_one_to_m_node, M_2, cond_2, node_loop_2, out_1_node, cond_1_node, + in_1_int_node], + 'body_graph_1', + [m_1, cond_int_1, in_1_int], + [cond_out_1, in_1_int_out, out_1], + ) + + node_loop_1 = helper.make_node( + 'Loop', + inputs=['M_1', 'cond', 'IN_1'], + outputs=['cond_out_1', 'OUT_1'], + body=body_graph_1 + ) + # external loop created + + res_node = helper.make_node( + 'Identity', + inputs=['OUT_1'], + outputs=['res'], + ) + + graph_def = helper.make_graph( + [M_1, cond, node_loop_1, res_node], + 'graph', + [in_1, in_2], + [res], + ) + + onnx_net = helper.make_model(graph_def, producer_name='test_loop_in_loop_model') + # We do not create reference graph, as it's too complicated to construct it + # So we return None to skip IR comparision + + return onnx_net, None + + @pytest.mark.precommit + @pytest.mark.timeout(250) + def test_loop_simple_precommit(self, ie_device, precision, ir_version, temp_dir): + if ie_device == 'GPU': + pytest.skip('Loop not supported on GPU') + self._test(*self.create_loop(), ie_device, precision, ir_version, temp_dir=temp_dir, + infer_timeout=150) + + @pytest.mark.precommit + @pytest.mark.timeout(250) + def test_loop_in_loop_simple_precommit(self, ie_device, precision, ir_version, temp_dir): + if ie_device == 'GPU': + pytest.skip('Loop not supported on GPU') + self._test(*self.create_loop_in_loop(), ie_device, precision, ir_version, temp_dir=temp_dir, + infer_timeout=150) From 42ff8ffa56368c4bffcc0ed63a2455793c8ba7f9 Mon Sep 17 00:00:00 2001 From: Victor Kuznetsov Date: Tue, 24 Aug 2021 00:39:12 +0300 Subject: [PATCH 061/102] install necessary dirs for tests (#7044) * install necessary dirs to tests * rem RUNTIME from install step * fix paths * fix install paths * fix install paths: add destination dirs * add pandas * fix requirements conflict - change pytest version to ~5 * remove comment from requirements.txt * upd numpy version --- tests/stress_tests/CMakeLists.txt | 3 +++ tests/stress_tests/scripts/requirements.txt | 1 + tests/time_tests/CMakeLists.txt | 3 +++ tests/time_tests/test_runner/requirements.txt | 6 +++--- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/stress_tests/CMakeLists.txt b/tests/stress_tests/CMakeLists.txt index 3370d86b5c45d0..7bed0cf1bff049 100644 --- a/tests/stress_tests/CMakeLists.txt +++ b/tests/stress_tests/CMakeLists.txt @@ -20,3 +20,6 @@ add_subdirectory(common) add_subdirectory(unittests) add_subdirectory(memleaks_tests) add_subdirectory(memcheck_tests) + +install(DIRECTORY scripts/ DESTINATION tests/stress_tests/scripts COMPONENT tests EXCLUDE_FROM_ALL) +install(DIRECTORY .automation/ DESTINATION tests/stress_tests/.automation COMPONENT tests EXCLUDE_FROM_ALL) diff --git a/tests/stress_tests/scripts/requirements.txt b/tests/stress_tests/scripts/requirements.txt index 5d067c9229777f..681af3a4261d88 100644 --- a/tests/stress_tests/scripts/requirements.txt +++ b/tests/stress_tests/scripts/requirements.txt @@ -2,5 +2,6 @@ pymongo Jinja2 PyYAML fastjsonschema~=2.15.1 +pandas h5py<3.0.0 # WA for OMZ Keras models. Details: https://github.com/openvinotoolkit/open_model_zoo/issues/1806 \ No newline at end of file diff --git a/tests/time_tests/CMakeLists.txt b/tests/time_tests/CMakeLists.txt index 442e76b99ebde2..69fbb56bd0cc71 100644 --- a/tests/time_tests/CMakeLists.txt +++ b/tests/time_tests/CMakeLists.txt @@ -23,3 +23,6 @@ if(NOT InferenceEngine_FOUND) endif() add_subdirectory(src) + +install(DIRECTORY test_runner/ DESTINATION tests/time_tests/test_runner COMPONENT tests EXCLUDE_FROM_ALL) +install(DIRECTORY scripts/ DESTINATION tests/time_tests/scripts COMPONENT tests EXCLUDE_FROM_ALL) diff --git a/tests/time_tests/test_runner/requirements.txt b/tests/time_tests/test_runner/requirements.txt index 37f153fdf6e976..d8db3f72fb2b33 100644 --- a/tests/time_tests/test_runner/requirements.txt +++ b/tests/time_tests/test_runner/requirements.txt @@ -1,8 +1,8 @@ -pytest==4.0.1 -attrs==19.1.0 # required for pytest==4.0.1 to resolve compatibility issues +pytest~=5.0 +attrs==19.1.0 PyYAML==5.4.1 jsonschema==3.2.0 distro==1.5.0 -numpy==1.18.5 +numpy>=1.19.2 pymongo pytest-html From 86597a417ac6a10e3a6f5e570390169b944d6213 Mon Sep 17 00:00:00 2001 From: Anton Pankratv Date: Tue, 24 Aug 2021 07:14:11 +0300 Subject: [PATCH 062/102] Added openvino infer request API (#7151) --- .../include/openvino/runtime/common.hpp | 3 +- .../openvino/runtime/infer_request.hpp | 178 ++++++++++++++++++ .../openvino/runtime/profiling_info.hpp | 65 +++++++ .../openvino/runtime/variable_state.hpp | 81 ++++++++ .../src/cpp/ie_infer_request.cpp | 132 ++++++++++++- .../src/cpp/ie_variable_state.cpp | 31 ++- .../src/os/lin/lin_shared_object_loader.cpp | 31 +++ .../src/os/win/win_shared_object_loader.cpp | 110 +++++++++++ .../src/plugin_api/shared_object.hpp | 44 +++++ .../ov_infer_request_test.cpp | 75 ++++++++ .../ov_shared_object_test.cpp | 61 ++++++ .../ov_variable_state_test.cpp | 31 +++ 12 files changed, 839 insertions(+), 3 deletions(-) create mode 100644 inference-engine/src/inference_engine/include/openvino/runtime/infer_request.hpp create mode 100644 inference-engine/src/inference_engine/include/openvino/runtime/profiling_info.hpp create mode 100644 inference-engine/src/inference_engine/include/openvino/runtime/variable_state.hpp create mode 100644 inference-engine/src/plugin_api/shared_object.hpp create mode 100644 inference-engine/tests/functional/inference_engine/ov_infer_request_test.cpp create mode 100644 inference-engine/tests/functional/inference_engine/ov_shared_object_test.cpp create mode 100644 inference-engine/tests/functional/inference_engine/ov_variable_state_test.cpp diff --git a/inference-engine/src/inference_engine/include/openvino/runtime/common.hpp b/inference-engine/src/inference_engine/include/openvino/runtime/common.hpp index 9c0c2e93192817..4cb98fa034f2c9 100644 --- a/inference-engine/src/inference_engine/include/openvino/runtime/common.hpp +++ b/inference-engine/src/inference_engine/include/openvino/runtime/common.hpp @@ -3,12 +3,13 @@ // /** - * @brief This is a header file for the OpenVINO Runtime common aliases that depend only from external API + * @brief This is a header file for the OpenVINO Runtime common aliases and data types * * @file openvino/runtime/common.hpp */ #pragma once +#include #include #include diff --git a/inference-engine/src/inference_engine/include/openvino/runtime/infer_request.hpp b/inference-engine/src/inference_engine/include/openvino/runtime/infer_request.hpp new file mode 100644 index 00000000000000..d5993d9a09c7a5 --- /dev/null +++ b/inference-engine/src/inference_engine/include/openvino/runtime/infer_request.hpp @@ -0,0 +1,178 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/** + * @brief A header file that provides wrapper classes for infer requests and callbacks. + * + * @file infer_request.hpp + */ +#pragma once + +#include +#include +#include + +#include "common.hpp" +#include "profiling_info.hpp" +#include "variable_state.hpp" + +namespace InferenceEngine { +class IInferRequestInternal; +class Blob; +} // namespace InferenceEngine + +namespace ov { +namespace runtime { +/** + * @brief This is an interface of asynchronous infer request + * + * It can throw exceptions safely for the application, where it is properly handled. + */ +class INFERENCE_ENGINE_API_CLASS(InferRequest) { + std::shared_ptr _so; + std::shared_ptr _impl; + + /** + * @brief Constructs InferRequest from the initialized std::shared_ptr + * @param so Plugin to use. This is required to ensure that InferRequest can work properly even if plugin object is + * destroyed. + * @param impl Initialized shared pointer + */ + InferRequest(const std::shared_ptr& so, const std::shared_ptr& impl); + friend class ExecutableNetwork; + +public: + /** + * @brief Default constructor + */ + InferRequest() = default; + + /** + * @brief Sets input/output data to infer + * + * @note Memory allocation does not happen + * @param name Name of input or output blob. + * @param data Reference to input or output blob. The type of a blob must match the network input precision and + * size. + */ + void set_blob(const std::string& name, const std::shared_ptr& data); + + /** + * @brief Gets input/output data for inference + * + * @note Memory allocation does not happen + * @param name A name of Blob to get + * @return A shared pointer to a Blob with a name @p name. If a blob is not found, an exception is thrown. + */ + std::shared_ptr get_blob(const std::string& name); + + /** + * @brief Infers specified input(s) in synchronous mode + * + * @note blocks all methods of InferRequest while request is ongoing (running or waiting in queue) + * + */ + void infer(); + + /** + * @brief Cancels inference request + */ + void cancel(); + + /** + * @brief Queries performance measures per layer to get feedback of what is the most time consuming layer + * + * @note not all plugins provide meaningful data + * @return Vector of profiling information for layers in network + */ + std::vector get_profiling_info() const; + + /** + * @brief Sets input data to infer + * + * @note Memory allocation doesn't happen + * @param inputs A reference to a map of input blobs accessed by input names. + * The type of Blob must correspond to the network input precision and size. + */ + void set_input(const std::map>& inputs); + + /** + * @brief Sets data that will contain result of the inference + * + * @note Memory allocation doesn't happen + * @param results - a reference to a map of result blobs accessed by output names. + * The type of Blob must correspond to the network output precision and size. + */ + void set_output(const std::map>& results); + + /** + * @brief Sets new batch size when dynamic batching is enabled in executable network that created this request. + * + * @param batch new batch size to be used by all the following inference calls for this request. + */ + void set_batch(const int batch); + + /** + * @brief Start inference of specified input(s) in asynchronous mode + * + * @note It returns immediately. Inference starts also immediately. + */ + void start_async(); + + /** + * @brief Waits for the result to become available. Blocks until the result + * becomes available + */ + void wait(); + + /** + * @brief Waits for the result to become available. Blocks until specified timeout has elapsed or the result + * becomes available, whichever comes first. + * + * @param timeout Maximum duration in milliseconds to block for + * @return true if inference request is ready and false otherwise + */ + bool wait_for(const std::chrono::milliseconds timeout); + + /** + * @brief Sets a callback function that will be called on success or failure of asynchronous request + * + * @param callback callback object which will be called on when inference finish. + */ + void set_callback(std::function callback); + + /** + * @brief Gets state control interface for given infer request. + * + * State control essential for recurrent networks + * @return A vector of Memory State objects + */ + std::vector query_state(); + + /** + * @brief Checks if current InferRequest object is not initialized + * @return true if current InferRequest object is not initialized, false - otherwise + */ + bool operator!() const noexcept; + + /** + * @brief Checks if current InferRequest object is initialized + * @return true if current InferRequest object is initialized, false - otherwise + */ + explicit operator bool() const noexcept; + + /** + * @brief Compares whether this request wraps the same impl underneath + * @return true if current InferRequest object doesn't wrap the same impl as the operator's arg + */ + bool operator!=(const InferRequest&) const noexcept; + + /** + * @brief Compares whether this request wraps the same impl underneath + * @return true if current InferRequest object wraps the same impl as the operator's arg + */ + bool operator==(const InferRequest&) const noexcept; +}; +} // namespace runtime +} // namespace ov diff --git a/inference-engine/src/inference_engine/include/openvino/runtime/profiling_info.hpp b/inference-engine/src/inference_engine/include/openvino/runtime/profiling_info.hpp new file mode 100644 index 00000000000000..f72255071a966d --- /dev/null +++ b/inference-engine/src/inference_engine/include/openvino/runtime/profiling_info.hpp @@ -0,0 +1,65 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/** + * @brief This is a header file for the ProfilingInfo objects that contains performance + * metric for single node + * + * @file openvino/runtime/profiling_info.hpp + */ +#pragma once + +#include +#include + +namespace ov { +namespace runtime { +/** + * @struct ProfilingInfo + * @brief Represents basic inference profiling information per node. + * + * If the node is executed using tiling, the sum time per each tile is indicated as the total execution time. + * Due to parallel execution, the total execution time for all nodes might be greater than the total inference time. + */ +struct ProfilingInfo { + /** + * @brief Defines the general status of the node + */ + enum class Status { + NOT_RUN, //!< A node is not executed + OPTIMIZED_OUT, //!< A node is optimized out during graph optimization phase + EXECUTED //!< A node is executed + }; + + /** + * @brief Defines a node status + */ + Status status; + + /** + * @brief The absolute time in microseconds that the node ran (in total) + */ + std::chrono::microseconds real_time; + /** + * @brief The net host cpu time that the node ran + */ + std::chrono::microseconds cpu_time; + + /** + * @brief A name of node + */ + std::string node_name; + + /** + * @brief An execution type of unit + */ + std::string exec_type; + + /** + * @brief A node type + */ + std::string node_type; +}; +} // namespace runtime +} // namespace ov \ No newline at end of file diff --git a/inference-engine/src/inference_engine/include/openvino/runtime/variable_state.hpp b/inference-engine/src/inference_engine/include/openvino/runtime/variable_state.hpp new file mode 100644 index 00000000000000..e15679b118b7ab --- /dev/null +++ b/inference-engine/src/inference_engine/include/openvino/runtime/variable_state.hpp @@ -0,0 +1,81 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/** + * @brief A header file that provides VariableState + * + * @file variable_state.hpp + */ + +#pragma once + +#include +#include + +#include +#include + +#include "common.hpp" + +namespace InferenceEngine { +class IVariableStateInternal; +class Blob; +} // namespace InferenceEngine + +namespace ov { +namespace runtime { + +class SharedObject; +class InferRequest; + +/** + * @brief VariableState class + */ +class INFERENCE_ENGINE_API_CLASS(VariableState) { + std::shared_ptr _so; + std::shared_ptr _impl; + + /** + * @brief Constructs VariableState from the initialized std::shared_ptr + * @param impl Initialized shared pointer + * @param so Optional: Plugin to use. This is required to ensure that VariableState can work properly even if plugin + * object is destroyed. + */ + VariableState(const std::shared_ptr& so, const std::shared_ptr& impl); + + friend class ov::runtime::InferRequest; + +public: + /** + * @brief Default constructor + */ + VariableState() = default; + + /** + * @brief Reset internal variable state for relevant infer request, + * to a value specified as default for according ReadValue node + */ + void reset(); + + /** + * @brief Gets name of current variable state, if length of array is not enough name is truncated by len, null + * terminator is inserted as well. As variable state name `variable_id` from according `ReadValue` used. + * @return A string representing a state name + */ + std::string get_name() const; + + /** + * @brief Returns the value of the variable state. + * @return A blob representing a state + */ + std::shared_ptr get_state() const; + + /** + * @brief Sets the new state for the next inference. + * @param state The current state to set + */ + void set_state(const std::shared_ptr& state); +}; +} // namespace runtime +} // namespace ov diff --git a/inference-engine/src/inference_engine/src/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/src/cpp/ie_infer_request.cpp index 135cf2d3391f6d..11937e6309d114 100644 --- a/inference-engine/src/inference_engine/src/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/src/cpp/ie_infer_request.cpp @@ -10,8 +10,10 @@ #include "cpp/exception2status.hpp" #include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" +#include "details/ie_so_loader.h" #include "ie_infer_async_request_base.hpp" #include "ie_remote_context.hpp" +#include "openvino/runtime/infer_request.hpp" namespace InferenceEngine { @@ -21,7 +23,7 @@ namespace InferenceEngine { try { \ __VA_ARGS__ \ } catch (...) { \ - details::Rethrow(); \ + ::InferenceEngine::details::Rethrow(); \ } InferRequest::InferRequest(const details::SharedObjectLoader& so, const IInferRequestInternal::Ptr& impl) @@ -190,3 +192,131 @@ bool InferRequest::operator==(const InferRequest& r) const noexcept { } } // namespace InferenceEngine + +namespace ov { +namespace runtime { + +InferRequest::InferRequest(const std::shared_ptr& so, const ie::IInferRequestInternal::Ptr& impl) + : _so{so}, + _impl{impl} { + IE_ASSERT(_impl != nullptr); +} + +void InferRequest::set_blob(const std::string& name, const ie::Blob::Ptr& data) { + INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data);) +} + +ie::Blob::Ptr InferRequest::get_blob(const std::string& name) { + ie::Blob::Ptr blobPtr; + INFER_REQ_CALL_STATEMENT(blobPtr = _impl->GetBlob(name);) + std::string error = "Internal error: blob with name `" + name + "` is not allocated!"; + const bool remoteBlobPassed = blobPtr->is(); + if (blobPtr == nullptr) + IE_THROW() << error; + if (!remoteBlobPassed && blobPtr->buffer() == nullptr) + IE_THROW() << error; + return blobPtr; +} + +void InferRequest::infer() { + INFER_REQ_CALL_STATEMENT(_impl->Infer();) +} + +void InferRequest::cancel() { + INFER_REQ_CALL_STATEMENT(_impl->Cancel();) +} + +std::vector InferRequest::get_profiling_info() const { + INFER_REQ_CALL_STATEMENT({ + auto ieInfos = _impl->GetPerformanceCounts(); + std::vector infos; + infos.reserve(ieInfos.size()); + while (!ieInfos.empty()) { + auto itIeInfo = std::min_element( + std::begin(ieInfos), + std::end(ieInfos), + [](const decltype(ieInfos)::value_type& lhs, const decltype(ieInfos)::value_type& rhs) { + return lhs.second.execution_index < rhs.second.execution_index; + }); + IE_ASSERT(itIeInfo != ieInfos.end()); + auto& ieInfo = itIeInfo->second; + infos.push_back(ProfilingInfo{}); + auto& info = infos.back(); + switch (ieInfo.status) { + case ie::InferenceEngineProfileInfo::NOT_RUN: + info.status = ProfilingInfo::Status::NOT_RUN; + break; + case ie::InferenceEngineProfileInfo::OPTIMIZED_OUT: + info.status = ProfilingInfo::Status::OPTIMIZED_OUT; + break; + case ie::InferenceEngineProfileInfo::EXECUTED: + info.status = ProfilingInfo::Status::OPTIMIZED_OUT; + break; + } + info.real_time = std::chrono::microseconds{ieInfo.realTime_uSec}; + info.cpu_time = std::chrono::microseconds{ieInfo.cpu_uSec}; + info.node_name = itIeInfo->first; + info.exec_type = std::string{ieInfo.exec_type}; + info.node_type = std::string{ieInfo.layer_type}; + ieInfos.erase(itIeInfo); + } + return infos; + }) +} + +void InferRequest::set_input(const ie::BlobMap& inputs) { + INFER_REQ_CALL_STATEMENT(for (auto&& input : inputs) { _impl->SetBlob(input.first, input.second); }) +} + +void InferRequest::set_output(const ie::BlobMap& results) { + INFER_REQ_CALL_STATEMENT(for (auto&& result : results) { _impl->SetBlob(result.first, result.second); }) +} + +void InferRequest::set_batch(const int batch) { + INFER_REQ_CALL_STATEMENT(_impl->SetBatch(batch);) +} + +void InferRequest::start_async() { + INFER_REQ_CALL_STATEMENT(_impl->StartAsync();) +} + +void InferRequest::wait() { + INFER_REQ_CALL_STATEMENT(_impl->Wait(ie::InferRequest::RESULT_READY);) +} + +bool InferRequest::wait_for(const std::chrono::milliseconds timeout) { + INFER_REQ_CALL_STATEMENT(return _impl->Wait(timeout.count()) == ie::OK;) +} + +void InferRequest::set_callback(std::function callback) { + INFER_REQ_CALL_STATEMENT(_impl->SetCallback(std::move(callback));) +} + +std::vector InferRequest::query_state() { + std::vector variable_states; + INFER_REQ_CALL_STATEMENT({ + for (auto&& state : _impl->QueryState()) { + variable_states.emplace_back(VariableState{_so, state}); + } + }) + return variable_states; +} + +bool InferRequest::operator!() const noexcept { + return !_impl; +} + +InferRequest::operator bool() const noexcept { + return (!!_impl); +} + +bool InferRequest::operator!=(const InferRequest& r) const noexcept { + return !(r == *this); +} + +bool InferRequest::operator==(const InferRequest& r) const noexcept { + return r._impl == _impl; +} + +} // namespace runtime +} // namespace ov \ No newline at end of file diff --git a/inference-engine/src/inference_engine/src/cpp/ie_variable_state.cpp b/inference-engine/src/inference_engine/src/cpp/ie_variable_state.cpp index ff8547f13b33da..e9aeb57d720d2d 100644 --- a/inference-engine/src/inference_engine/src/cpp/ie_variable_state.cpp +++ b/inference-engine/src/inference_engine/src/cpp/ie_variable_state.cpp @@ -6,6 +6,7 @@ #include "cpp_interfaces/interface/ie_ivariable_state_internal.hpp" #include "details/ie_so_loader.h" #include "exception2status.hpp" +#include "openvino/runtime/variable_state.hpp" #define VARIABLE_CALL_STATEMENT(...) \ if (_impl == nullptr) \ @@ -13,7 +14,7 @@ try { \ __VA_ARGS__; \ } catch (...) { \ - details::Rethrow(); \ + ::InferenceEngine::details::Rethrow(); \ } namespace InferenceEngine { @@ -44,3 +45,31 @@ void VariableState::SetState(Blob::Ptr state) { } } // namespace InferenceEngine + +namespace ov { +namespace runtime { + +VariableState::VariableState(const std::shared_ptr& so, const ie::IVariableStateInternal::Ptr& impl) + : _so{so}, + _impl{impl} { + IE_ASSERT(_impl != nullptr); +} + +void VariableState::reset() { + VARIABLE_CALL_STATEMENT(_impl->Reset()); +} + +std::string VariableState::get_name() const { + VARIABLE_CALL_STATEMENT(return _impl->GetName()); +} + +ie::Blob::CPtr VariableState::get_state() const { + VARIABLE_CALL_STATEMENT(return _impl->GetState()); +} + +void VariableState::set_state(const ie::Blob::Ptr& state) { + VARIABLE_CALL_STATEMENT(_impl->SetState(state)); +} + +} // namespace runtime +} // namespace ov diff --git a/inference-engine/src/inference_engine/src/os/lin/lin_shared_object_loader.cpp b/inference-engine/src/inference_engine/src/os/lin/lin_shared_object_loader.cpp index 6d3cfa87e318be..1961c1a713032d 100644 --- a/inference-engine/src/inference_engine/src/os/lin/lin_shared_object_loader.cpp +++ b/inference-engine/src/inference_engine/src/os/lin/lin_shared_object_loader.cpp @@ -8,6 +8,7 @@ #include "details/ie_so_loader.h" #include "file_utils.h" +#include "shared_object.hpp" namespace InferenceEngine { namespace details { @@ -71,3 +72,33 @@ void* SharedObjectLoader::get_symbol(const char* symbolName) const { } // namespace details } // namespace InferenceEngine + +namespace ov { +namespace runtime { +SharedObject::SharedObject(const char* path) { + shared_object = dlopen(path, RTLD_NOW); + + if (shared_object == nullptr) + IE_THROW() << "Cannot load library '" << path << "': " << dlerror(); +} + +#ifdef ENABLE_UNICODE_PATH_SUPPORT +SharedObject::SharedObject(const wchar_t* path) : SharedObject(FileUtils::wStringtoMBCSstringChar(path).c_str()) {} +#endif // ENABLE_UNICODE_PATH_SUPPORT + +SharedObject::~SharedObject() { + if (0 != dlclose(shared_object)) { + std::cerr << "dlclose failed: " << dlerror() << std::endl; + } +} + +void* SharedObject::get_symbol(const char* symbolName) const { + void* procAddr = nullptr; + + procAddr = dlsym(shared_object, symbolName); + if (procAddr == nullptr) + IE_THROW(NotFound) << "dlSym cannot locate method '" << symbolName << "': " << dlerror(); + return procAddr; +} +} // namespace runtime +} // namespace ov diff --git a/inference-engine/src/inference_engine/src/os/win/win_shared_object_loader.cpp b/inference-engine/src/inference_engine/src/os/win/win_shared_object_loader.cpp index 31c148ec111ff9..7896b56e5d28eb 100644 --- a/inference-engine/src/inference_engine/src/os/win/win_shared_object_loader.cpp +++ b/inference-engine/src/inference_engine/src/os/win/win_shared_object_loader.cpp @@ -5,6 +5,7 @@ #include "ie_common.h" #include "details/ie_so_loader.h" #include "file_utils.h" +#include "shared_object.hpp" // // LoadLibraryA, LoadLibraryW: @@ -274,3 +275,112 @@ void* SharedObjectLoader::get_symbol(const char* symbolName) const { } // namespace details } // namespace InferenceEngine + + +namespace ov { +namespace runtime { +SharedObject::SharedObject(const char* path) { + using GetDllDirectoryA_Fnc = DWORD(*)(DWORD, LPSTR); + GetDllDirectoryA_Fnc IEGetDllDirectoryA = nullptr; + if (HMODULE hm = GetModuleHandleW(L"kernel32.dll")) { + IEGetDllDirectoryA = reinterpret_cast(GetProcAddress(hm, "GetDllDirectoryA")); + } +#if !WINAPI_PARTITION_SYSTEM + // ExcludeCurrentDirectory + if (IEGetDllDirectoryA && IEGetDllDirectoryA(0, NULL) <= 1) { + SetDllDirectoryA(""); + } + // LoadPluginFromDirectory + if (IEGetDllDirectoryA) { + DWORD nBufferLength = IEGetDllDirectoryA(0, NULL); + std::vector lpBuffer(nBufferLength); + IEGetDllDirectoryA(nBufferLength, &lpBuffer.front()); + + // GetDirname + auto dirname = [&] { + auto pos = strchr(path, '\\'); + if (pos == nullptr) { + return std::string{path}; + } + std::string original(path); + original[pos - path] = 0; + return original; + } (); + + SetDllDirectoryA(dirname.c_str()); + shared_object = LoadLibraryA(path); + + SetDllDirectoryA(&lpBuffer.front()); + } +#endif + if (!shared_object) { + shared_object = LoadLibraryA(path); + } + if (!shared_object) { + char cwd[1024]; + IE_THROW() << "Cannot load library '" << path << "': " << GetLastError() + << " from cwd: " << _getcwd(cwd, sizeof(cwd)); + } +} + +#ifdef ENABLE_UNICODE_PATH_SUPPORT +SharedObject::SharedObject(const wchar_t* path) { + using GetDllDirectoryW_Fnc = DWORD(*)(DWORD, LPWSTR); + static GetDllDirectoryW_Fnc IEGetDllDirectoryW = nullptr; + if (HMODULE hm = GetModuleHandleW(L"kernel32.dll")) { + IEGetDllDirectoryW = reinterpret_cast(GetProcAddress(hm, "GetDllDirectoryW")); + } + // ExcludeCurrentDirectory +#if !WINAPI_PARTITION_SYSTEM + if (IEGetDllDirectoryW && IEGetDllDirectoryW(0, NULL) <= 1) { + SetDllDirectoryW(L""); + } + if (IEGetDllDirectoryW) { + DWORD nBufferLength = IEGetDllDirectoryW(0, NULL); + std::vector lpBuffer(nBufferLength); + IEGetDllDirectoryW(nBufferLength, &lpBuffer.front()); + + auto dirname = [&] { + auto pos = wcsrchr(path, '\\'); + if (pos == nullptr) { + return std::wstring{path}; + } + std::wstring original(path); + original[pos - path] = 0; + return original; + } (); + SetDllDirectoryW(dirname.c_str()); + shared_object = LoadLibraryW(path); + + SetDllDirectoryW(&lpBuffer.front()); + } +#endif + if (!shared_object) { + shared_object = LoadLibraryW(path); + } + if (!shared_object) { + char cwd[1024]; + IE_THROW() << "Cannot load library '" << FileUtils::wStringtoMBCSstringChar(std::wstring(path)) << "': " << GetLastError() + << " from cwd: " << _getcwd(cwd, sizeof(cwd)); + } +} +#endif + +SharedObject::~SharedObject() { + FreeLibrary(reinterpret_cast(shared_object)); +} + +void* SharedObject::get_symbol(const char* symbolName) const { + if (!shared_object) { + IE_THROW() << "Cannot get '" << symbolName << "' content from unknown library!"; + } + auto procAddr = reinterpret_cast(GetProcAddress( + reinterpret_cast(const_cast(shared_object)), symbolName)); + if (procAddr == nullptr) + IE_THROW(NotFound) + << "GetProcAddress cannot locate method '" << symbolName << "': " << GetLastError(); + + return procAddr; +} +} // namespace runtime +} // namespace ov diff --git a/inference-engine/src/plugin_api/shared_object.hpp b/inference-engine/src/plugin_api/shared_object.hpp new file mode 100644 index 00000000000000..de2523375c7661 --- /dev/null +++ b/inference-engine/src/plugin_api/shared_object.hpp @@ -0,0 +1,44 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/** + * @brief A header file for definition of abstraction over platform specific shared objects + * @file ie_system_conf.h + */ + +#pragma once + +#include "ie_api.h" + +namespace ov { +namespace runtime { +struct INFERENCE_ENGINE_API_CLASS(SharedObject) { + void* shared_object = nullptr; + + /** + * @brief Loads a library with the name specified. + * @param path Full or relative path to the plugin library + */ + explicit SharedObject(const char* path); + +#ifdef ENABLE_UNICODE_PATH_SUPPORT + /** + * @brief Loads a library with the wide char name specified. + * @param path Full or relative path to the plugin library + */ + explicit SharedObject(const wchar_t* path); +#endif // ENABLE_UNICODE_PATH_SUPPORT + + ~SharedObject(); + + /** + * @brief Searches for a function symbol in the loaded module + * @param symbolName Name of the function to find + * @return A pointer to the function if found + * @throws Exception if the function is not found + */ + void* get_symbol(const char* symbolName) const; +}; +} // namespace runtime +} // namespace ov diff --git a/inference-engine/tests/functional/inference_engine/ov_infer_request_test.cpp b/inference-engine/tests/functional/inference_engine/ov_infer_request_test.cpp new file mode 100644 index 00000000000000..1cfdb17941cc0d --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/ov_infer_request_test.cpp @@ -0,0 +1,75 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include + +using namespace ::testing; +using namespace std; +using namespace InferenceEngine; +using namespace InferenceEngine::details; + + +TEST(InferRequestOVTests, throwsOnUninitializedSetBlob) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.set_blob({}, {}), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedGetBlob) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.get_blob({}), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedInfer) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.infer(), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedGetPerformanceCounts) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.get_profiling_info(), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedSetInput) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.set_input({{}}), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedSetOutput) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.set_output({{}}), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedSetBatch) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.set_batch({}), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedStartAsync) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.start_async(), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedWait) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.wait(), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedWaitFor) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.wait_for({}), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedSetCompletionCallback) { + ov::runtime::InferRequest req; + std::function f; + ASSERT_THROW(req.set_callback(f), InferenceEngine::NotAllocated); +} + +TEST(InferRequestOVTests, throwsOnUninitializedQueryState) { + ov::runtime::InferRequest req; + ASSERT_THROW(req.query_state(), InferenceEngine::NotAllocated); +} diff --git a/inference-engine/tests/functional/inference_engine/ov_shared_object_test.cpp b/inference-engine/tests/functional/inference_engine/ov_shared_object_test.cpp new file mode 100644 index 00000000000000..a396df7afc9ba6 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/ov_shared_object_test.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include "shared_object.hpp" +#include + +using namespace ::testing; +using namespace std; + +class SharedObjectOVTests: public ::testing::Test { +protected: + std::string get_mock_engine_name() { + return FileUtils::makePluginLibraryName(InferenceEngine::getIELibraryPath(), + std::string("mock_engine") + IE_BUILD_POSTFIX); + } + + void loadDll(const string &libraryName) { + sharedObject.reset(new ov::runtime::SharedObject(libraryName.c_str())); + } + unique_ptr sharedObject; + + using CreateF = void(std::shared_ptr&); + + std::function make_std_function(const std::string& functionName) { + std::function ptr(reinterpret_cast(sharedObject->get_symbol(functionName.c_str()))); + return ptr; + } +}; + +TEST_F(SharedObjectOVTests, canLoadExistedPlugin) { + loadDll(get_mock_engine_name()); + EXPECT_NE(nullptr, sharedObject.get()); +} + +TEST_F(SharedObjectOVTests, loaderThrowsIfNoPlugin) { + EXPECT_THROW(loadDll("wrong_name"), InferenceEngine::Exception); +} + +TEST_F(SharedObjectOVTests, canFindExistedMethod) { + loadDll(get_mock_engine_name()); + + auto factory = make_std_function("CreatePluginEngine"); + EXPECT_NE(nullptr, factory); +} + +TEST_F(SharedObjectOVTests, throwIfMethodNofFoundInLibrary) { + loadDll(get_mock_engine_name()); + EXPECT_THROW(make_std_function("wrong_function"), InferenceEngine::Exception); +} + +TEST_F(SharedObjectOVTests, canCallExistedMethod) { + loadDll(get_mock_engine_name()); + + auto factory = make_std_function("CreatePluginEngine"); + std::shared_ptr ptr; + EXPECT_NO_THROW(factory(ptr)); +} diff --git a/inference-engine/tests/functional/inference_engine/ov_variable_state_test.cpp b/inference-engine/tests/functional/inference_engine/ov_variable_state_test.cpp new file mode 100644 index 00000000000000..f9233e5eebc9b0 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/ov_variable_state_test.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include + +using namespace ::testing; +using namespace std; + +TEST(VariableStateOVTests, throwsOnUninitializedReset) { + ov::runtime::VariableState state; + ASSERT_THROW(state.reset(), InferenceEngine::NotAllocated); +} + +TEST(VariableStateOVTests, throwsOnUninitializedGetname) { + ov::runtime::VariableState state; + ASSERT_THROW(state.get_name(), InferenceEngine::NotAllocated); +} + +TEST(VariableStateOVTests, throwsOnUninitializedGetState) { + ov::runtime::VariableState state; + ASSERT_THROW(state.get_state(), InferenceEngine::NotAllocated); +} + +TEST(VariableStateOVTests, throwsOnUninitializedSetState) { + ov::runtime::VariableState state; + InferenceEngine::Blob::Ptr blob; + ASSERT_THROW(state.set_state(blob), InferenceEngine::NotAllocated); +} From c3de89f3a2c6fb740c531efb80ec3f6c118c4084 Mon Sep 17 00:00:00 2001 From: Alexandra Sidorova Date: Tue, 24 Aug 2021 09:44:25 +0300 Subject: [PATCH 063/102] [CPU] Removed eltwise overhead on execution stage (#6760) --- .../mkldnn_plugin/mkldnn_graph_optimizer.cpp | 3 +- .../nodes/mkldnn_eltwise_node.cpp | 167 +++++++++--------- .../mkldnn_plugin/nodes/mkldnn_eltwise_node.h | 30 ++-- .../single_layer_tests/activation.cpp | 4 +- 4 files changed, 106 insertions(+), 98 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp index 9cbc9b79aeb983..0cad8e15e3b543 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp @@ -330,7 +330,8 @@ void MKLDNNGraphOptimizer::FuseMultiplyAndAdd(MKLDNNGraph &graph) { if (childNode->getAlgorithm() != EltwiseAdd || !childNode->getFusedWith().empty() || childNode->getParentEdges().size() != 2) return false; - return isSutableSecondInput(childNode->getParentEdgesAtPort(1)[0]->getParent(), childNode->getParentEdgesAtPort(0)[0]->getShape().getDims()); + return isSutableSecondInput(childNode->getParentEdgesAtPort(1)[0]->getParent(), childNode->getParentEdgesAtPort(0)[0]->getShape().getDims()) && + parentNode->canFuse(childNode); }; auto parent = graphNodes.begin(); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp index d777e22210f324..1bba69c7cfbb28 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp @@ -45,7 +45,7 @@ using namespace mkldnn::impl::cpu; using namespace mkldnn::impl::cpu::x64; using namespace Xbyak; -#define GET_OFF(field) offsetof(jit_eltwise_call_args, field) +#define GET_OFF(field) offsetof(jit_eltwise_call_args_ptrs, field) namespace { @@ -140,11 +140,31 @@ struct jit_uni_eltwise_generic : public MKLDNNPlugin::jit_uni_eltwise_kernel, pu this->preamble(); - for (int i = 0; i < jep.inputs_number; i++) - mov(get_src_reg(i), ptr[reg_params + GET_OFF(src_ptr[0]) + i * sizeof(size_t)]); - mov(reg_dst, ptr[reg_params + GET_OFF(dst)]); - mov(reg_work_amount, ptr[reg_params + GET_OFF(work_amount)]); - mov(reg_oc_off, ptr[reg_params + GET_OFF(oc_off)]); + const int offset_count = jep.input_size - 1; + + // ptrs initializing + auto init_ptrs_with_offsets = [this, offset_count](Reg64 pointer, const std::vector& offsets) { + for (int j = 0; j < offset_count; j++) { + if (jep_.dims[j] != 1 && offsets[j] != 0) { + mov(reg_tmp_64, offsets[j]); + imul(reg_tmp_64, ptr[reg_indexes + j * sizeof(size_t)]); + add(pointer, reg_tmp_64); + } + } + }; + + for (int i = 0; i < jep.inputs_number; i++) { + mov(get_src_reg(i), ptr[reg_const_params + GET_OFF(src_ptr[0]) + i * sizeof(size_t)]); + init_ptrs_with_offsets(get_src_reg(i), jep.src_offsets[i]); + } + + mov(reg_dst, ptr[reg_const_params + GET_OFF(dst_ptr)]); + init_ptrs_with_offsets(reg_dst, jep.dst_offsets); + + xor_(reg_oc_off, reg_oc_off); + init_ptrs_with_offsets(reg_oc_off, jep.oc_offsets); + + mov(reg_work_amount, jep.work_amount); Xbyak::Label unroll_loop_label; Xbyak::Label unroll_loop_end_label; @@ -335,7 +355,8 @@ struct jit_uni_eltwise_generic : public MKLDNNPlugin::jit_uni_eltwise_kernel, pu Reg64 reg_work_amount = rdx; Reg64 reg_oc_off = abi_not_param1; - Reg64 reg_params = abi_param1; + Reg64 reg_const_params = abi_param1; + Reg64 reg_indexes = abi_param2; // reg_d_bias Reg8 reg_tmp_8 = Reg8(r15.getIdx()); Reg32 reg_tmp_32 = Reg32(r15.getIdx()); @@ -996,7 +1017,8 @@ void MKLDNNEltwiseNode::initSupportedPrimitiveDescriptors() { if (!supportedPrimitiveDescriptors.empty()) return; - canUseOptimizedImpl = mayiuse(x64::sse41); + // if dim rank is greater than the maximum possible, we should use the reference execution + canUseOptimizedImpl = mayiuse(x64::sse41) && inputShapes[0].getRank() <= MAX_ELTWISE_DIM_RANK; size_t expectedInputsNum = getOpInputsNum(); for (auto& postOp : fusedWith) { @@ -1180,9 +1202,10 @@ void MKLDNNEltwiseNode::initSupportedPrimitiveDescriptors() { } void MKLDNNEltwiseNode::createPrimitive() { - auto initDims = [this](size_t maxInputSize) { - size_t inputNum = getParentEdges().size(); + auto config = getSelectedPrimitiveDescriptor()->getConfig(); + inputNum = getParentEdges().size(); + auto initDims = [this, config](size_t maxInputSize) { dims_in.resize(inputNum); for (int i = 0; i < inputNum; i++) { dims_in[i].resize(maxInputSize, 1); @@ -1232,9 +1255,7 @@ void MKLDNNEltwiseNode::createPrimitive() { } }; - auto initOffsets = [this](size_t maxInputSize) { - size_t inputNum = getParentEdges().size(); - + auto initOffsets = [this, config](size_t maxInputSize) { offsets_out.resize(maxInputSize, 1); offset_out_calc(offsets_out, dims_out); for (int j = 0; j < maxInputSize; j++) { @@ -1381,24 +1402,33 @@ void MKLDNNEltwiseNode::createPrimitive() { initOffsets(tensorRank); - const size_t inpuPortsCount = getSelectedPrimitiveDescriptor()->getConfig().inConfs.size(); + for (auto i = 0; i < inputNum; i++) + memPtrs.push_back(getParentEdgeAt(i)->getMemoryPtr()); + memPtrs.push_back(getChildEdgeAt(0)->getMemoryPtr()); - jep.inputs_number = inpuPortsCount; + if (!canUseOptimizedImpl) + return; + + jep.inputs_number = inputNum; jep.input_size = tensorRank; - for (int i = 0; i < inpuPortsCount; i++) { + for (int i = 0; i < inputNum; i++) { jep.src_size[i] = dims_in[i][dims_in[i].size() - 1]; jep.src_prc[i] = getParentEdgesAtPort(i).front()->getMemory().GetDesc().getPrecision(); } jep.dst_size = dims_out[dims_out.size() - 1]; jep.dst_prc = getChildEdgesAtPort(0).front()->getMemory().GetDesc().getPrecision(); - for (int i = 0; i < inpuPortsCount; i++) { + jep.oc_size = oc_size; + jep.work_amount = dims_out.back(); + + jep.dims = dims_out; + for (size_t i = 0; i < inputNum; i++) jep.src_offsets[i] = offsets_in[i]; - } jep.dst_offsets = offsets_out; - - jep.oc_size = oc_size; + jep.oc_offsets = offsets_oc; + std::transform(jep.oc_offsets.begin(), jep.oc_offsets.end(), jep.oc_offsets.begin(), + [](size_t& offset) { return offset * sizeof(float);}); if (mayiuse(x64::avx512_common)) { eltwise_kernel.reset(new jit_uni_eltwise_generic(jep, *this)); @@ -1452,42 +1482,27 @@ void MKLDNNEltwiseNode::offset_in_calc(std::vector& offset, std::vector< } } -void MKLDNNEltwiseNode::executeOptimized6D(const std::vector& src_ptrs, uint8_t *dst_ptr) { - size_t inputNum = src_ptrs.size(); - +void MKLDNNEltwiseNode::executeOptimized6D() { parallel_for5d(dims_out[0], dims_out[1], dims_out[2], dims_out[3], dims_out[4], [&](size_t i0, size_t i1, size_t i2, size_t i3, size_t i4) { - // TODO: reimplement initializer via jit approach - size_t index_in[MAX_ELTWISE_INPUTS] = {0}; - for (int i = 0; i < inputNum; i++) { - index_in[i] = i0 * offsets_in[i][0] + i1 * offsets_in[i][1] + i2 * offsets_in[i][2] + - i3 * offsets_in[i][3] + i4 * offsets_in[i][4]; - } - size_t index_out = i0 * offsets_out[0] + i1 * offsets_out[1] + i2 * offsets_out[2] + - i3 * offsets_out[3] + i4 * offsets_out[4]; - - auto arg = jit_eltwise_call_args(); - for (int i = 0; i < inputNum; i++) { - arg.src_ptr[i] = src_ptrs[i] + index_in[i]; - } - arg.dst = dst_ptr + index_out; - arg.work_amount = static_cast(dims_out[dims_out.size() - 1]); - arg.oc_off = (i0 * offsets_oc[0] + i1 * offsets_oc[1] + i2 * offsets_oc[2] + - i3 * offsets_oc[3] + i4 * offsets_oc[4]) * sizeof(float); - - (*eltwise_kernel)(&arg); + auto args = jit_eltwise_call_args_indexes(); + args.indexes[0] = i0; + args.indexes[1] = i1; + args.indexes[2] = i2; + args.indexes[3] = i3; + args.indexes[4] = i4; + + (*eltwise_kernel)(&args_ptrs, &args); }); } -void MKLDNNEltwiseNode::executeOptimizedGeneric(const std::vector& src_ptrs, uint8_t *dst_ptr) { - size_t inputNum = src_ptrs.size(); - +void MKLDNNEltwiseNode::executeOptimizedGeneric() { parallel_nt(0, [&](const int ithr, const int nthr) { size_t start = 0, end = 0; splitter(schedulerWorkAmount, nthr, ithr, start, end); std::vector counters(dims_out.size() - 1, 0); - + auto args = jit_eltwise_call_args_indexes(); for (size_t iwork = start; iwork < end; ++iwork) { size_t tmp = iwork; for (ptrdiff_t j = dims_out.size() - 2; j >= 0; j--) { @@ -1495,39 +1510,15 @@ void MKLDNNEltwiseNode::executeOptimizedGeneric(const std::vector(dims_out[dims_out.size() - 1]); - - arg.oc_off = 0; - for (int j = 0; j < counters.size(); j++) { - arg.oc_off += counters[j] * offsets_oc[j] * sizeof(float); - } + for (size_t j = 0; j < counters.size(); j++) + args.indexes[j] = counters[j]; - (*eltwise_kernel)(&arg); + (*eltwise_kernel)(&args_ptrs, &args); } }); } -void MKLDNNEltwiseNode::executeReference(const std::vector& src_ptrs, uint8_t *dst_ptr) { - size_t inputNum = src_ptrs.size(); - +void MKLDNNEltwiseNode::executeReference() { std::shared_ptr ref_eltwise_injector = nullptr; if (getMKLDNNAlgorithm() != mkldnn::algorithm::undef) { ref_eltwise_injector = std::make_shared(static_cast(getMKLDNNAlgorithm()), alpha, beta, 1.f); @@ -1552,18 +1543,20 @@ void MKLDNNEltwiseNode::executeReference(const std::vector& src for (int j = 0; j < counters.size(); j++) { index_in[i] += counters[j] * offsets_in[i][j]; } + index_in[i] /= sizeof(float); } size_t index_out = 0; for (int j = 0; j < counters.size(); j++) { index_out += counters[j] * offsets_out[j]; } + index_out /= sizeof(float); std::vector src_f(inputNum); for (int i = 0; i < inputNum; i++) { - src_f[i] = reinterpret_cast(src_ptrs[i] + index_in[i])[0]; + src_f[i] = (reinterpret_cast(args_ptrs.src_ptr[i]) + index_in[i])[0]; } - float* dst_ptr_f = reinterpret_cast(dst_ptr + index_out); + float* dst_ptr_f = reinterpret_cast(args_ptrs.dst_ptr) + index_out; switch (getAlgorithm()) { case EltwiseRelu: case EltwiseGelu: case EltwiseElu: case EltwiseTanh: case EltwiseSigmoid: case EltwiseAbs: @@ -1593,6 +1586,7 @@ void MKLDNNEltwiseNode::executeReference(const std::vector& src case EltwiseLogicalNot: *dst_ptr_f = !src_f[0]; break; case EltwisePowerStatic: *dst_ptr_f = powf(beta * src_f[0] + gamma, alpha); break; case EltwisePrelu: *dst_ptr_f = src_f[0] > 0 ? src_f[0] : src_f[0] * src_f[1]; break; + case EltwiseErf: *dst_ptr_f = std::erf(src_f[0]); break; default: IE_THROW() << "Unsupported operation type for Eltwise node with name `" << getName() << "`"; } } @@ -1600,13 +1594,10 @@ void MKLDNNEltwiseNode::executeReference(const std::vector& src } void MKLDNNEltwiseNode::execute(mkldnn::stream strm) { - size_t inputNum = getParentEdges().size(); - std::vector src_ptrs(inputNum); - for (int i = 0; i < inputNum; i++) { - src_ptrs[i] = reinterpret_cast(getParentEdgeAt(i)->getMemory().GetData()) + start_offset_in[i]; - } - uint8_t *dst_ptr = reinterpret_cast(getChildEdgeAt(0)->getMemory().GetData()) + start_offset_out; + for (int i = 0; i < inputNum; i++) + args_ptrs.src_ptr[i] = reinterpret_cast(memPtrs[i]->GetData()) + start_offset_in[i]; + args_ptrs.dst_ptr = reinterpret_cast(memPtrs.back()->GetData()) + start_offset_out; // In general case we need to recompute offsets as well but currently all supported layout assumes batch to be outermost dimension if (isDynBatchEnabled) @@ -1614,12 +1605,12 @@ void MKLDNNEltwiseNode::execute(mkldnn::stream strm) { if (eltwise_kernel) { if (tensorRank == optimalTensorRank) { - executeOptimized6D(src_ptrs, dst_ptr); + executeOptimized6D(); } else { - executeOptimizedGeneric(src_ptrs, dst_ptr); + executeOptimizedGeneric(); } } else { - executeReference(src_ptrs, dst_ptr); + executeReference(); } } @@ -1727,7 +1718,7 @@ bool MKLDNNEltwiseNode::canFuse(const MKLDNNNodePtr& node) const { return true; }; - if (!mayiuse(x64::sse41)) + if (!mayiuse(x64::sse41) || inputShapes[0].getRank() > MAX_ELTWISE_DIM_RANK) return false; if (!isSuitableNode(this)) { @@ -1756,6 +1747,10 @@ bool MKLDNNEltwiseNode::canFuse(const MKLDNNNodePtr& node) const { } } + // We can use optimized execution with fusions only in cases when dim rank is less or equal to the maximum possible + if (node->getParentEdgesAtPort(0).front()->getShape().getRank() > MAX_ELTWISE_DIM_RANK) + return false; + return true; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.h index 34e95d45ae06e8..e1719be037fac5 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.h @@ -14,6 +14,7 @@ namespace MKLDNNPlugin { #define MAX_ELTWISE_INPUTS 7 +#define MAX_ELTWISE_DIM_RANK 12 struct jit_eltwise_params { size_t inputs_number; @@ -22,30 +23,35 @@ struct jit_eltwise_params { InferenceEngine::Precision src_prc[MAX_ELTWISE_INPUTS]; InferenceEngine::Precision dst_prc; + std::vector dims; std::vector src_offsets[MAX_ELTWISE_INPUTS]; std::vector dst_offsets; + std::vector oc_offsets; size_t src_size[MAX_ELTWISE_INPUTS]; size_t dst_size; size_t oc_size; + + size_t work_amount; }; -struct jit_eltwise_call_args { +struct jit_eltwise_call_args_ptrs { const void *src_ptr[MAX_ELTWISE_INPUTS]; - void *dst; + void *dst_ptr; +}; - size_t work_amount; - size_t oc_off; +struct jit_eltwise_call_args_indexes { + size_t indexes[MAX_ELTWISE_DIM_RANK]; }; class MKLDNNEltwiseNode; struct jit_uni_eltwise_kernel { - void (*ker_)(const jit_eltwise_call_args *); + void (*ker_)(const jit_eltwise_call_args_ptrs*, const jit_eltwise_call_args_indexes*); - void operator()(const jit_eltwise_call_args *args) { + void operator()(const jit_eltwise_call_args_ptrs* const_args, const jit_eltwise_call_args_indexes* indexes) { assert(ker_); - ker_(args); + ker_(const_args, indexes); } explicit jit_uni_eltwise_kernel(jit_eltwise_params jep, MKLDNNEltwiseNode& node) : ker_(nullptr), jep_(jep), eltwiseNode(node) {} @@ -87,6 +93,7 @@ class MKLDNNEltwiseNode : public MKLDNNNode { std::shared_ptr eltwise_kernel = nullptr; jit_eltwise_params jep = {}; + jit_eltwise_call_args_ptrs args_ptrs = {}; int optimalTensorRank = 6; bool canUseOptimizedImpl = false; @@ -96,6 +103,7 @@ class MKLDNNEltwiseNode : public MKLDNNNode { size_t tensorRank = 0; size_t fullWorkAmount = 0; size_t schedulerWorkAmount = 0; + size_t inputNum = 0; std::vector> dims_in = {}; std::vector> offsets_in = {}; std::vector dims_out = {}; @@ -111,11 +119,13 @@ class MKLDNNEltwiseNode : public MKLDNNNode { std::vector scales = {}; std::vector shifts = {}; + std::vector memPtrs = {}; + static std::map&, MKLDNNEltwiseNode& node)>> initializers; - inline void executeOptimized6D(const std::vector& src_ptrs, uint8_t *dst_ptr); - inline void executeOptimizedGeneric(const std::vector& src_ptrs, uint8_t *dst_ptr); - inline void executeReference(const std::vector& src_ptrs, uint8_t *dst_ptr); + inline void executeOptimized6D(); + inline void executeOptimizedGeneric(); + inline void executeReference(); void offset_out_calc(std::vector& offset, std::vector& dims); void offset_in_calc(std::vector& offset, std::vector& dims_in, std::vector& dims_out); diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp index f78179275e2877..78b536b5acf265 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp @@ -88,7 +88,8 @@ const std::map>> activationParam std::map, std::vector>> basic = { {{1, 50}, {{}}}, - {{1, 128}, {{}}}, + {{5, 128}, {{}}}, + {{2, 2, 2, 2, 2, 2, 2, 2}, {{}}}, }; std::map, std::vector>> preluBasic = { @@ -100,6 +101,7 @@ std::map, std::vector>> preluBasic = { {{3, 2, 5}, {{1}, {2}, {5}, {2, 5}, {3, 1, 5}, {1, 2, 1}, {1, 1, 5}, {3, 1, 1}, {3, 2, 5}}}, {{2, 1, 2}, {{2}, {2, 1, 1}}}, {{3, 2, 5, 7}, {{1}, {7}, {2}, {5, 7}, {2, 5, 7}, {2, 1, 1}, {1, 2, 1, 1}, {3, 2, 1, 1}, {3, 2, 5, 7}}}, + {{2, 2, 2, 2, 2, 2, 2, 2}, {{2}, {2, 2}, {2, 1, 1, 2}}}, }; const auto basicCases = ::testing::Combine( From 5ac7011686f16902b7fab62366cc9f6c10190386 Mon Sep 17 00:00:00 2001 From: Dmitrii Khurtin Date: Tue, 24 Aug 2021 10:30:47 +0300 Subject: [PATCH 064/102] [GNA] For similar records, the pattern length was increased to 4 in the algorithm for determining infinite cycles. (#7165) * for similar records, the pattern length was increased to 4 * Added comments --- .../gna_plugin/frontend/model_quantizer.hpp | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/inference-engine/src/gna_plugin/frontend/model_quantizer.hpp b/inference-engine/src/gna_plugin/frontend/model_quantizer.hpp index cd15b1c1b13631..a2e638c9d7589b 100644 --- a/inference-engine/src/gna_plugin/frontend/model_quantizer.hpp +++ b/inference-engine/src/gna_plugin/frontend/model_quantizer.hpp @@ -115,7 +115,8 @@ class ModelQuantizer { } } - // looking for infinite loop by using algorithm of compute prefix function, complexity O(N) + // We are looking for infinite loop by using algorithm of compute prefix function, complexity O(N) + // (a part of the Knuth–Morris–Pratt algorithm). std::map prefixFunction; int k = infiniteLoopHistory.size(); for (int i = infiniteLoopHistory.size() - 2; i >= 0; i--) { @@ -128,12 +129,36 @@ class ModelQuantizer { k--; } - if ((infiniteLoopHistory.size() - i) % 2 == 0 && (infiniteLoopHistory.size() - i) / 2 == infiniteLoopHistory.size() - k) { + // The pattern length is a length of a repeating string sequence (it is 2 in the example below). + // concat_14_input_0_reshape#concat_15 + // concat_15_input_1_reshape#add_12 + // add_12#Add_16 + // Reshape_41#add_12 + // add_12#Add_16 + // Reshape_41#add_12 + // + // In the case of pattern length is 1, an infinite loop can be found on 2 consecutive strings. + // To avoid this, we will expect the appearance of 4 equal strings for the case pattern length is 1. + if ((infiniteLoopHistory.size() - i) % 2 == 0 && + (infiniteLoopHistory.size() - i) / 2 == infiniteLoopHistory.size() - k && + ((infiniteLoopHistory.size() - i) / 2 > 1 || + std::distance(infiniteLoopHistory.rbegin(), + std::find_if_not(infiniteLoopHistory.rbegin(), infiniteLoopHistory.rend(), + [&infiniteLoopHistory](const std::string& str) { return str == infiniteLoopHistory.back(); })) > 3)) { + gnalog() << "infiniteLoopPattern:\n"; + for (const auto& s : infiniteLoopPattern) { + gnalog() << "\t " << s << '\n'; + } infiniteLoopPattern.clear(); - int patternLength = (infiniteLoopHistory.size() - i)/2; + int patternLength = (infiniteLoopHistory.size() - i) / 2; + gnalog() << "patternLength: " << patternLength << '\n'; for (int j = 0; j < patternLength; j++) { infiniteLoopPattern.emplace_back(infiniteLoopHistory[infiniteLoopHistory.size() - patternLength + j]); } + gnalog() << "infiniteLoopHistory:\n"; + for (const auto& s : infiniteLoopHistory) { + gnalog() << "\t " << s << '\n'; + } infiniteLoopHistory.clear(); gnalog() << "infinite loop detected\n"; break; From ecf5280e6e66fbe07e5b889582bd9a80fe887593 Mon Sep 17 00:00:00 2001 From: Ivan Novoselov Date: Tue, 24 Aug 2021 10:50:07 +0300 Subject: [PATCH 065/102] [CPU] Enable direct copy implementation for u8->u8 reorder. (#7043) --- inference-engine/thirdparty/mkl-dnn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/thirdparty/mkl-dnn b/inference-engine/thirdparty/mkl-dnn index 7e4430d9398af6..aa5a4685377992 160000 --- a/inference-engine/thirdparty/mkl-dnn +++ b/inference-engine/thirdparty/mkl-dnn @@ -1 +1 @@ -Subproject commit 7e4430d9398af63e94943815dace4b44f12ddbee +Subproject commit aa5a4685377992ae0733372c1568146872706670 From c4e873d5fbf15665be45c80906c02c9a322bbc55 Mon Sep 17 00:00:00 2001 From: Aleksandr Pertovsky Date: Tue, 24 Aug 2021 10:58:10 +0300 Subject: [PATCH 066/102] [CPU] Fix not expected No-Preprocess Exception with RGB to BGR conversion (#6954) --- .../mkldnn_plugin/mkldnn_infer_request.cpp | 14 ++++---- .../include/behavior/set_preprocess.hpp | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp index 77dbe3e1215792..1ce31f3ecb882c 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp @@ -247,12 +247,14 @@ InferenceEngine::Blob::Ptr MKLDNNPlugin::MKLDNNInferRequest::GetBlob(const std:: checkBlob(data, name, true); // check if preprocess required, but still wasn't set auto preProcessedInput = std::find_if(std::begin(_networkInputs), std::end(_networkInputs), - [&](const std::pair& pair) - {return pair.first == name;}); - if (preProcessedInput!= std::end(_networkInputs)) { - auto preProcess = preProcessedInput->second->getPreProcess(); - if (preProcess.getColorFormat() != InferenceEngine::ColorFormat::RAW || - preProcess.getResizeAlgorithm() != InferenceEngine::ResizeAlgorithm::NO_RESIZE) { + [&](const std::pair& pair) { + return pair.first == name; + }); + if (preProcessedInput != std::end(_networkInputs)) { + InferenceEngine::InputInfo::Ptr foundInput; + InferenceEngine::DataPtr foundOutput; + findInputAndOutputBlobByName(name, foundInput, foundOutput); + if (preProcessingRequired(foundInput, data)) { _preProcData.emplace(name, InferenceEngine::CreatePreprocDataHelper()); _preProcData[name]->isApplicable(data, _inputs[name]); _preProcData[name]->setRoiBlob(data); diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/set_preprocess.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/set_preprocess.hpp index ff2948668588b4..a3a53f160ede97 100644 --- a/inference-engine/tests/functional/plugin/shared/include/behavior/set_preprocess.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/set_preprocess.hpp @@ -992,4 +992,38 @@ TEST_P(PreprocessDynamicallyInSetBlobTest, Infer) { } } +TEST_P(PreprocessTest, InferWithRGB2BGRConversion) { + // Skip test according to plugin specific disabledTestPatterns() (if any) + SKIP_IF_CURRENT_TEST_IS_DISABLED() + std::shared_ptr ngraphFunc; + const unsigned int shape_size = 9, channels = 3, batch = 1; + { + ngraph::PartialShape shape({batch, channels, shape_size, shape_size}); + ngraph::element::Type type(InferenceEngine::details::convertPrecision(netPrecision)); + auto param = std::make_shared(type, shape); + param->set_friendly_name("param"); + auto relu = std::make_shared(param); + relu->set_friendly_name("relu"); + auto result = std::make_shared(relu); + result->set_friendly_name("result"); + + ngraph::ParameterVector params = {param}; + ngraph::ResultVector results = {result}; + + ngraphFunc = std::make_shared(results, params); + } + + // Create CNNNetwork from ngraph::Function + InferenceEngine::CNNNetwork cnnNet(ngraphFunc); + + auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess(); + preProcess.setColorFormat(InferenceEngine::ColorFormat::BGR); + // Load CNNNetwork to target plugins + auto execNet = ie->LoadNetwork(cnnNet, targetDevice, configuration); + // Create InferRequest + auto req = execNet.CreateInferRequest(); + + ASSERT_NO_THROW(req.Infer()); +} + } // namespace BehaviorTestsDefinitions From 94003a2b511c0bf53b76e3ead8fc451fde865229 Mon Sep 17 00:00:00 2001 From: Nikolay Shchegolev Date: Tue, 24 Aug 2021 12:28:23 +0300 Subject: [PATCH 067/102] [CPU] Avoid inserting additional transpose + reorder after RNN node. (#5921) --- .../mkldnn_plugin/mkldnn_graph_optimizer.cpp | 49 ++++++++++++++++++- .../mkldnn_plugin/mkldnn_graph_optimizer.h | 1 + .../rnn_sequences_optimization.cpp | 25 ++-------- .../nodes/mkldnn_reshape_node.cpp | 9 ++++ .../mkldnn_plugin/nodes/mkldnn_reshape_node.h | 6 +++ .../src/mkldnn_plugin/nodes/mkldnn_rnn.cpp | 9 +++- .../src/mkldnn_plugin/nodes/mkldnn_rnn.h | 4 ++ .../cpu/single_layer_tests/gru_sequence.cpp | 11 ++--- .../cpu/single_layer_tests/lstm_sequence.cpp | 11 ++--- .../cpu/single_layer_tests/rnn_sequence.cpp | 4 +- .../plugin/cpu/test_utils/cpu_test_utils.cpp | 16 +++++- 11 files changed, 102 insertions(+), 43 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp index 0cad8e15e3b543..c450fc63ece68e 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp @@ -17,6 +17,7 @@ #include #include "nodes/mkldnn_interpolate_node.h" #include "nodes/mkldnn_input_node.h" +#include "nodes/mkldnn_rnn.h" #include "nodes/common/cpu_convert.h" #include "mkldnn/ie_mkldnn.h" @@ -132,6 +133,10 @@ void MKLDNNGraphOptimizer::ApplyCommonGraphOptimizations(MKLDNNGraph &graph) { FuseEltwiseAndSimple(graph); graph.RemoveDroppedNodes(); + OV_ITT_SCOPE_NEXT(FIRST_INFERENCE, taskChain, "reshapeRnnSeq"); + reshapeRnnSeq(graph); + graph.RemoveDroppedNodes(); + OV_ITT_SCOPE_NEXT(FIRST_INFERENCE, taskChain, "RemoveDroppedEdges"); graph.RemoveDroppedEdges(); } @@ -973,7 +978,7 @@ static bool is_data_dependency(const std::shared_ptr &parent, */ void MKLDNNGraphOptimizer::FuseConvolutionSumAndConvolutionSumActivation(MKLDNNGraph &graph) { - std::vector &graphNodes = graph.GetNodes(); + auto &graphNodes = graph.GetNodes(); auto isFusingSupported = [&](MKLDNNNodePtr conv, MKLDNNNodePtr child) { return child->getType() == Eltwise && @@ -1444,7 +1449,7 @@ void MKLDNNGraphOptimizer::DropDoubleReorders(MKLDNNGraph &graph) { } void MKLDNNGraphOptimizer::FuseBroadcastAndEltwise(MKLDNNGraph &graph) { - std::vector& graphNodes = graph.GetNodes(); + auto& graphNodes = graph.GetNodes(); for (auto &graphNode : graphNodes) { if (graphNode->getType() != Generic @@ -1816,3 +1821,43 @@ void MKLDNNGraphOptimizer::MergeTransposeAndReorder(MKLDNNGraph &graph) { } } } + +void MKLDNNGraphOptimizer::reshapeRnnSeq(MKLDNNGraph &graph) { + auto& graphNodes = graph.GetNodes(); + + auto isSutableParentNode = [](MKLDNNNodePtr node) { + if (node->type != RNNSeq) + return false; + auto rnnNode = std::dynamic_pointer_cast(node); + return rnnNode && !rnnNode->hasNativeOrder() && node->outputShapes[0].getRank() == 4 && node->outputShapes[0].getDims()[1] == 1; + }; + + for (int i = 0; i < graphNodes.size(); i++) { + auto& parentNode = graphNodes[i]; + if (!isSutableParentNode(parentNode)) { + continue; + } + + auto childrenEdges = parentNode->getChildEdgesAtPort(0); + auto newRnnOutDims = parentNode->outputShapes[0].getDims(); + newRnnOutDims.erase(newRnnOutDims.begin() + 1); + parentNode->outputShapes[0] = Shape{newRnnOutDims}; + + for (size_t i = 0; i < childrenEdges.size(); i++) { + auto edge = childrenEdges[i]; + auto childNode = edge->getChild(); + + const MKLDNNNodePtr newReshape = std::make_shared( + parentNode->getName() + "_abc_a1bc_" + std::to_string(i), + parentNode->outputShapes[0], + childNode->inputShapes[edge->getOutputNum()], + parentNode->getOriginalOutputPrecisionAtPort(0), + graph.getEngine(), graph.weightsCache); + + graph.InsertNode(parentNode, childNode, newReshape, edge->getInputNum(), edge->getOutputNum(), false); + + edge->drop(); + graph.RemoveEdge(edge); + } + } +} diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.h b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.h index cd26354775083c..a28f7c73431790 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.h +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.h @@ -39,6 +39,7 @@ class MKLDNNGraphOptimizer { void FusePerformedAsScaleShiftAndFakeQuantize(MKLDNNGraph &graph); void FuseClampAndFakeQuantize(MKLDNNGraph &graph); void MergeTransposeAndReorder(MKLDNNGraph &graph); + void reshapeRnnSeq(MKLDNNGraph &graph); }; } // namespace MKLDNNPlugin diff --git a/inference-engine/src/mkldnn_plugin/ngraph_transformations/rnn_sequences_optimization.cpp b/inference-engine/src/mkldnn_plugin/ngraph_transformations/rnn_sequences_optimization.cpp index 196af3640bd548..0b81fdcc81e154 100644 --- a/inference-engine/src/mkldnn_plugin/ngraph_transformations/rnn_sequences_optimization.cpp +++ b/inference-engine/src/mkldnn_plugin/ngraph_transformations/rnn_sequences_optimization.cpp @@ -56,34 +56,15 @@ namespace { auto reshape1 = std::make_shared(in_0, newInShape, false); ngraph::replace_node(sequenceOp->get_input_node_shared_ptr(0), {reshape1->output(0)}); - const auto &gruTargetInputs = sequenceOp->output(0).get_target_inputs(); - if (gruTargetInputs.empty()) + const auto &seqTargetInputs = sequenceOp->output(0).get_target_inputs(); + if (seqTargetInputs.empty()) return false; - auto transposeAfter = gruTargetInputs.begin()->get_node()->shared_from_this(); + auto transposeAfter = seqTargetInputs.begin()->get_node()->shared_from_this(); auto newOutShape = ngraph::op::v0::Constant::create(ngraph::element::i32, ngraph::Shape{4}, transposeAfter->get_output_shape(0)); auto reshape2 = std::make_shared(sequenceOp->output(0), newOutShape, false); reshape2->set_friendly_name(transposeAfter->get_friendly_name()); ngraph::replace_node(transposeAfter, {reshape2->output(0)}); - } else { - auto originShape = sequenceOp->get_output_shape(0); - const auto targetInputs = sequenceOp->get_output_target_inputs(0); - if (targetInputs.empty()) { - return false; - } - auto seqOut = targetInputs.begin()->get_node()->shared_from_this(); - - auto tncShape = ngraph::op::v0::Constant::create(ngraph::element::i32, ngraph::Shape{3}, {originShape[2], originShape[0], originShape[3]}); - auto reshape1 = std::make_shared(sequenceOp->output(0), tncShape, false); - - auto order = ngraph::op::v0::Constant::create(ngraph::element::i32, ngraph::Shape{3}, {1, 0, 2}); - auto transpose = std::make_shared(reshape1->output(0), order); - - auto ndtcShape = ngraph::op::v0::Constant::create(ngraph::element::i32, ngraph::Shape{4}, originShape); - auto reshape2 = std::make_shared(transpose->output(0), ndtcShape, false); - reshape2->set_friendly_name(sequenceOp->get_friendly_name()+".0"); - - ngraph::insert_new_node_between(sequenceOp, seqOut, reshape2); } sequenceOp->get_rt_info()["seqAxis"] = std::make_shared>(seqAxis); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reshape_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reshape_node.cpp index 81175dcaf41a96..f4256042379500 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reshape_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reshape_node.cpp @@ -14,6 +14,15 @@ using namespace InferenceEngine; MKLDNNReshapeNode::MKLDNNReshapeNode(const std::shared_ptr& op, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache) : MKLDNNNode(op, eng, cache) {} +MKLDNNReshapeNode::MKLDNNReshapeNode(const std::string& name, const Shape& inDims, const Shape& outDims, Precision precision, + const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &wCache) + : MKLDNNNode("Reshape", name, eng, wCache) { + this->inputShapes.push_back(inDims); + this->outputShapes.push_back(outDims); + addOriginalInputPrecision(precision); + addOriginalOutputPrecision(precision); +} + void MKLDNNReshapeNode::getSupportedDescriptors() { if (getParentEdges().size() != 1 && getParentEdges().size() != 2) IE_THROW() << "Incorrect number of input edges for layer " << getName(); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reshape_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reshape_node.h index fcd44b3ba03a88..cf88872f195701 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reshape_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reshape_node.h @@ -15,6 +15,12 @@ namespace MKLDNNPlugin { class MKLDNNReshapeNode : public MKLDNNNode { public: MKLDNNReshapeNode(const std::shared_ptr& op, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache); + MKLDNNReshapeNode(const std::string& name, + const Shape& inDims, + const Shape& outDims, + InferenceEngine::Precision precision, + const mkldnn::engine& eng, + MKLDNNWeightsSharing::Ptr &wCache); void getSupportedDescriptors() override; void initSupportedPrimitiveDescriptors() override; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp index 91201da8592dc6..6e9086274d5a7d 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp @@ -412,6 +412,9 @@ void MKLDNNRNN::fillSeqDesc() { if (nativeOrder) in_candidate.emplace_back(inputShapes[RNNInOutKind::Layer].getStaticDims(), dataType, memory::format_tag::tnc); + else if (N == 1) + // WA to avoid reorder before sequence for some models + in_candidate.emplace_back(std::vector{N, T, DC}, dataType, memory::format_tag::tnc); else in_candidate.emplace_back(std::vector{N, T, DC}, dataType, memory::format_tag::ntc); @@ -428,9 +431,11 @@ void MKLDNNRNN::fillSeqDesc() { if (nativeOrder) { out_candidate.emplace_back(out_data_d[RNNInOutKind::Layer]); + } else if (N == 1) { + // WA to avoid reorder after sequence for some models + out_candidate.emplace_back(std::vector{N, T, SC}, dataType, memory::format_tag::tnc); } else { - // TODO reorder ntc -> ndtc does not work, thus use tnc(plain) + transformation reshape-transpose-reshape for now. - out_candidate.emplace_back(std::vector{T, N, SC}, dataType, memory::format_tag::tnc); + out_candidate.emplace_back(std::vector{N, T, SC}, dataType, memory::format_tag::ntc); } out_candidate.emplace_back(std::vector{N, D, SC}, dataType, memory::format_tag::ntc); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.h index 0a2bd93d3d9d3a..9e47637235f583 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.h @@ -24,6 +24,10 @@ class MKLDNNRNN : public MKLDNNNode { void execute(mkldnn::stream strm) override; + inline bool hasNativeOrder() const { + return nativeOrder; + } + private: void initCell(const std::shared_ptr& op); void initSeq(const std::shared_ptr& op); diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_sequence.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_sequence.cpp index b34136facf9ccc..a7b6163af45763 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_sequence.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_sequence.cpp @@ -115,13 +115,10 @@ class GRUSequenceCPUTest : public testing::WithParamInterfaceget_output_shape(0)) == 1) { outFmts[0] = tnc; - } else if (ngraph::shape_size(gru_sequence->get_output_shape(1)) == 1) { + } else if (ngraph::shape_size(gru_sequence->get_output_shape(1)) == 1 || + gru_sequence->get_output_shape(0)[0] == 1) { outFmts[1] = tnc; } - // if output format equals for all outputs, runtime info return only one formats - if (outFmts[0] == outFmts[1]) { - outFmts.erase(outFmts.begin()); - } ngraph::ResultVector results{std::make_shared(gru_sequence->output(0)), std::make_shared(gru_sequence->output(1))}; @@ -170,8 +167,8 @@ namespace { std::vector> additionalConfig = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}}; -CPUSpecificParams cpuParams{{ntc, ntc}, {tnc, ntc}, {"ref_any"}, "ref_any"}; -CPUSpecificParams cpuParamsBatchSizeOne{{ntc, ntc}, {tnc, ntc}, {"ref_any"}, "ref_any"};; +CPUSpecificParams cpuParams{{ntc, ntc}, {ntc, ntc}, {"ref_any"}, "ref_any"}; +CPUSpecificParams cpuParamsBatchSizeOne{{tnc, ntc}, {tnc, ntc}, {"ref_any"}, "ref_any"};; std::vector mode{ngraph::helpers::SequenceTestsMode::PURE_SEQ}; // output values increase rapidly without clip, so use only seq_lengths = 2 diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_sequence.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_sequence.cpp index 47453bde9ee5cc..044a70f820b996 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_sequence.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_sequence.cpp @@ -119,15 +119,12 @@ class LSTMSequenceCPUTest : public testing::WithParamInterface= 3) { for (size_t i = 1; i < 3; i++) { - if (ngraph::shape_size(lstm_sequence->get_output_shape(i)) == 1) { + if (ngraph::shape_size(lstm_sequence->get_output_shape(i)) == 1 || + lstm_sequence->get_output_shape(0) == ngraph::Shape{1, 1, 2, 10}) { outFmts[i] = tnc; } } } - // if output format equals for all outputs, runtime info return only one formats - if (std::adjacent_find(outFmts.begin(), outFmts.end(), std::not_equal_to()) == outFmts.end()) { - outFmts.resize(1); - } ngraph::ResultVector results{std::make_shared(lstm_sequence->output(0)), std::make_shared(lstm_sequence->output(1)), @@ -179,8 +176,8 @@ std::vector> additionalConfig = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}}; -CPUSpecificParams cpuParams{{ntc, ntc, ntc}, {tnc, ntc, ntc}, {"ref_any"}, "ref_any"}; -CPUSpecificParams cpuParamsBatchSizeOne{{ntc, ntc, ntc}, {tnc, ntc, ntc}, {"ref_any"}, "ref_any"}; +CPUSpecificParams cpuParams{{ntc, ntc, ntc}, {ntc, ntc, ntc}, {"ref_any"}, "ref_any"}; +CPUSpecificParams cpuParamsBatchSizeOne{{tnc, ntc, ntc}, {tnc, ntc, ntc}, {"ref_any"}, "ref_any"}; std::vector mode{ngraph::helpers::SequenceTestsMode::PURE_SEQ}; std::vector seq_lengths_zero_clip{2}; diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_sequence.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_sequence.cpp index f2030fe8c0e0da..f70eace878c21c 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_sequence.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_sequence.cpp @@ -148,8 +148,8 @@ namespace { std::vector> additionalConfig = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}}; -CPUSpecificParams cpuParams{{ntc, ntc}, {tnc, ntc}, {"ref_any"}, "ref_any"}; -CPUSpecificParams cpuParamsBatchSizeOne{{ntc, ntc}, {tnc, ntc}, {"ref_any"}, "ref_any"}; +CPUSpecificParams cpuParams{{ntc, ntc}, {ntc, ntc}, {"ref_any"}, "ref_any"}; +CPUSpecificParams cpuParamsBatchSizeOne{{tnc, ntc}, {tnc, tnc}, {"ref_any"}, "ref_any"}; std::vector mode{ngraph::helpers::SequenceTestsMode::PURE_SEQ}; // output values increase rapidly without clip, so use only seq_lengths = 2 diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp index 39bae3546eeb36..dba15ff1d48eba 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp @@ -176,7 +176,21 @@ void CPUTestsBase::CheckPluginRelatedResults(InferenceEngine::ExecutableNetwork auto actualOutputMemoryFormats = getActualOutputMemoryFormats(getExecValueOutputsLayout(node)); - for (size_t i = 0; i < outFmts.size(); i++) { + bool isAllEqual = true; + for (size_t i = 1; i < outFmts.size(); i++) { + if (outFmts[i - 1] != outFmts[i]) { + isAllEqual = false; + break; + } + } + size_t fmtsNum = outFmts.size(); + if (isAllEqual) { + fmtsNum = fmtsNum == 0 ? 0 : 1; + } else { + ASSERT_EQ(fmtsNum, actualOutputMemoryFormats.size()); + } + + for (size_t i = 0; i < fmtsNum; i++) { const auto actualOutputMemoryFormat = getExecValue(ExecGraphInfoSerialization::OUTPUT_LAYOUTS); const auto shape = node->get_output_shape(i); From f989b33f1b9604479f967a088da53ddf8b4bd0bd Mon Sep 17 00:00:00 2001 From: Yegor Kruglov Date: Tue, 24 Aug 2021 13:19:40 +0300 Subject: [PATCH 068/102] [MO] Replacing StridedSlice with Squeeze/Unsqueeze (#6693) * added reinterp_shape parameter to tf ss extractor * removed reinterp_shape * added transformation to replace ss * updated bom * fix for e2e tests * updated a case when shrink_axis_mask and new_axis_mask are both initialized * unittests * added comments * updated graph_condition * comments resolving * updated the case, when shrink_axis_mask and new_axis_mask are both initialized * added layer tests for squeeze/unsqueeze cases * remove case when shrink and new axis masks are both set --- model-optimizer/automation/package_BOM.txt | 1 + .../extensions/middle/StridedSliceReplacer.py | 64 +++++++++++ .../middle/StridedSliceReplacer_test.py | 108 ++++++++++++++++++ .../tensorflow_tests/test_tf_StridedSlice.py | 90 +++++++++++++++ 4 files changed, 263 insertions(+) create mode 100644 model-optimizer/extensions/middle/StridedSliceReplacer.py create mode 100644 model-optimizer/unit_tests/extensions/middle/StridedSliceReplacer_test.py create mode 100644 tests/layer_tests/tensorflow_tests/test_tf_StridedSlice.py diff --git a/model-optimizer/automation/package_BOM.txt b/model-optimizer/automation/package_BOM.txt index 7ab49918925cc4..50c5dadb4980ec 100644 --- a/model-optimizer/automation/package_BOM.txt +++ b/model-optimizer/automation/package_BOM.txt @@ -640,6 +640,7 @@ extensions/middle/sparse_reshape.py extensions/middle/split_tdnn_memoryoffset.py extensions/middle/SplitConcatPairToInterpolate.py extensions/middle/StridedSliceNormalizer.py +extensions/middle/StridedSliceReplacer.py extensions/middle/SwapAxesMiddleReplacer.py extensions/middle/TensorIterator_utils.py extensions/middle/TensorIteratorBackEdge.py diff --git a/model-optimizer/extensions/middle/StridedSliceReplacer.py b/model-optimizer/extensions/middle/StridedSliceReplacer.py new file mode 100644 index 00000000000000..4dd26baac18b61 --- /dev/null +++ b/model-optimizer/extensions/middle/StridedSliceReplacer.py @@ -0,0 +1,64 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np + +from extensions.middle.InsertLayoutPropagationTransposes import InsertLayoutPropagationTranspose +from extensions.middle.StridedSliceNormalizer import StridedSliceNormalizer +from mo.front.common.partial_infer.utils import int64_array +from mo.front.tf.graph_utils import create_op_node_with_second_input +from mo.graph.graph import Graph, rename_nodes, Node +from mo.middle.replacement import MiddleReplacementPattern +from mo.ops.squeeze import Squeeze +from mo.ops.unsqueeze import Unsqueeze + + +def replace_strided_slice(node: Node, mask: np.ndarray, op: callable): + node_name = node.soft_get('name', node.id) + axes = np.where(mask == 1)[0] + new_node = create_op_node_with_second_input(node.graph, op, int64_array(axes)) + node.in_port(0).get_connection().set_destination(new_node.in_port(0)) + node.out_port(0).get_connection().set_source(new_node.out_port(0)) + + rename_nodes([(node, node_name + '/ShouldBeDeleted'), (new_node, node_name)]) + node.graph.remove_node(node.id) + + +class ReplaceStridedSliceWithSqueezeUnsqueeze(MiddleReplacementPattern): + r""" + The transformation replaces StridedSlice with a Squeeze/Unsqueeze node if StridedSlice executes like a Squeeze/Unsqueeze + and does not slice values. This is necessary if StridedSlice is to be executed in original N(D)HWC layout, because + the operation does not have reinterp_shape attribute and MO can not insert NC(D)HW -> N(D)HWC Transpose in + extensions/middle/InsertLayoutPropagationTransposes.py. + """ + enabled = True + + graph_condition = [lambda graph: graph.graph['layout'] == 'NHWC'] + + def run_before(self): + return [InsertLayoutPropagationTranspose] + + def run_after(self): + return [StridedSliceNormalizer] + + def find_and_replace_pattern(self, graph: Graph): + for node in graph.get_op_nodes(op='StridedSlice'): + input_shape = node.in_port(0).data.get_shape() + output_shape = node.out_port(0).data.get_shape() + + if np.prod(input_shape) != np.prod(output_shape): + continue + + shrink_axis_mask = node.soft_get('shrink_axis_mask', np.zeros(len(input_shape))) + new_axis_mask = node.soft_get('new_axis_mask', np.zeros(len(input_shape))) + + is_shrink_axis_mask = any(x == 1 for x in shrink_axis_mask) + is_new_axis_mask = any(x == 1 for x in new_axis_mask) + + if is_shrink_axis_mask and is_new_axis_mask: + # TODO: make it in a separate ticket + continue + elif is_shrink_axis_mask and not is_new_axis_mask: + replace_strided_slice(node, shrink_axis_mask, Squeeze) + elif not is_shrink_axis_mask and is_new_axis_mask: + replace_strided_slice(node, new_axis_mask, Unsqueeze) diff --git a/model-optimizer/unit_tests/extensions/middle/StridedSliceReplacer_test.py b/model-optimizer/unit_tests/extensions/middle/StridedSliceReplacer_test.py new file mode 100644 index 00000000000000..917fd923debafd --- /dev/null +++ b/model-optimizer/unit_tests/extensions/middle/StridedSliceReplacer_test.py @@ -0,0 +1,108 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import unittest + +from extensions.middle.StridedSliceReplacer import ReplaceStridedSliceWithSqueezeUnsqueeze +from mo.utils.ir_engine.compare_graphs import compare_graphs +from unit_tests.utils.graph import regular_op_with_shaped_data, regular_op_with_empty_data, shaped_const_with_data, \ + result, connect, build_graph + +nodes = { + **regular_op_with_shaped_data('input', [1, 3, 5, 5], {'type': 'Parameter', 'op': 'Parameter'}), + **regular_op_with_empty_data('strided_slice', {'type': 'StridedSlice', 'op': 'StridedSlice', + 'begin_mask': [0, 0, 0, 0], 'end_mask': [0, 0, 0, 0]}), + **shaped_const_with_data('begin', [4]), + **shaped_const_with_data('end', [4]), + **result('result'), + + **regular_op_with_empty_data('squeeze', {'type': 'Squeeze', 'op': 'Squeeze'}), + **shaped_const_with_data('squeeze_axes', None), + + **regular_op_with_empty_data('unsqueeze', {'type': 'Unsqueeze', 'op': 'Unsqueeze'}), + **shaped_const_with_data('unsqueeze_axes', None) +} + +pattern_edges = [ + *connect('input', '0:strided_slice'), + *connect('begin', '1:strided_slice'), + *connect('end', '2:strided_slice'), + *connect('strided_slice', 'result') +] + + +class TestStridedSliceReplacer(unittest.TestCase): + + def test_negative_different_input_and_output_shapes(self): + graph = build_graph( + nodes_attrs=nodes, + edges=pattern_edges, + update_attributes={ + 'strided_slice_d': {'shape': [1, 3, 3, 3]} + }, + nodes_with_edges_only=True + ) + + ref_graph = graph.copy() + + ReplaceStridedSliceWithSqueezeUnsqueeze().find_and_replace_pattern(graph) + (flag, resp) = compare_graphs(graph, ref_graph, 'result', check_op_attrs=True) + self.assertTrue(flag, resp) + + def test_replace_with_squeeze(self): + graph = build_graph( + nodes_attrs=nodes, + edges=pattern_edges, + update_attributes={ + 'strided_slice': {'shrink_axis_mask': [1, 0, 0, 0], 'new_axis_mask': [0, 0, 0, 0]}, + 'strided_slice_d': {'shape': [3, 5, 5]} + }, + nodes_with_edges_only=True + ) + + ref_graph = build_graph( + nodes_attrs=nodes, + edges=[ + *connect('input', '0:squeeze'), + *connect('squeeze_axes', '1:squeeze'), + *connect('squeeze', 'result') + ], + update_attributes={ + 'squeeze_axes_d': {'value': [0]}, + 'squeeze_d': {'shape': [3, 5, 5]} + }, + nodes_with_edges_only=True + ) + + ReplaceStridedSliceWithSqueezeUnsqueeze().find_and_replace_pattern(graph) + (flag, resp) = compare_graphs(graph, ref_graph, 'result', check_op_attrs=True) + self.assertTrue(flag, resp) + + def test_replace_with_unsqueeze(self): + graph = build_graph( + nodes_attrs=nodes, + edges=pattern_edges, + update_attributes={ + 'strided_slice': {'shrink_axis_mask': [0, 0, 0, 0], 'new_axis_mask': [1, 0, 0, 0]}, + 'strided_slice_d': {'shape': [1, 1, 3, 5, 5]} + }, + nodes_with_edges_only=True + ) + + ref_graph = build_graph( + nodes_attrs=nodes, + edges=[ + *connect('input', '0:unsqueeze'), + *connect('unsqueeze_axes', '1:unsqueeze'), + *connect('unsqueeze', 'result') + ], + update_attributes={ + 'unsqueeze_axes_d': {'value': [0]}, + 'unsqueeze_d': {'shape': [1, 1, 3, 5, 5]} + }, + nodes_with_edges_only=True + ) + + ReplaceStridedSliceWithSqueezeUnsqueeze().find_and_replace_pattern(graph) + (flag, resp) = compare_graphs(graph, ref_graph, 'result', check_op_attrs=True) + self.assertTrue(flag, resp) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_StridedSlice.py b/tests/layer_tests/tensorflow_tests/test_tf_StridedSlice.py new file mode 100644 index 00000000000000..d03994c7052c13 --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_StridedSlice.py @@ -0,0 +1,90 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import pytest + +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestStridedSlice(CommonTFLayerTest): + + @staticmethod + def create_strided_slice_net(input_shape, begin, end, strides, begin_mask, end_mask, ellipsis_mask, + new_axis_mask, shrink_axis_mask, ir_version): + + # + # Create Tensorflow model + # + import tensorflow as tf + + tf.compat.v1.reset_default_graph() + + with tf.compat.v1.Session() as sess: + input_node = tf.compat.v1.placeholder(tf.float32, input_shape, 'Input') + strided_slice = tf.compat.v1.strided_slice(input_node, begin=begin, end=end, strides=strides, + begin_mask=begin_mask, end_mask=end_mask, + ellipsis_mask=ellipsis_mask, new_axis_mask=new_axis_mask, + shrink_axis_mask=shrink_axis_mask) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + ref_net = None + return tf_net, ref_net + + test_squeeze_data = [ + dict(input_shape=[1, 5], begin=[0, 0], end=[1, 5], strides=[1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=1), + dict(input_shape=[5, 1], begin=[0, 0], end=[5, 1], strides=[1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=2), + dict(input_shape=[1, 5, 3], begin=[0, 0, 0], end=[1, 5, 3], strides=[1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=1), + dict(input_shape=[1, 1, 3], begin=[0, 0, 0], end=[1, 1, 3], strides=[1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=2), + dict(input_shape=[1, 5, 1], begin=[0, 0, 0], end=[1, 5, 1], strides=[1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=4), + dict(input_shape=[1, 5, 5, 3], begin=[0, 0, 0, 0], end=[1, 5, 5, 3], strides=[1, 1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=1), + dict(input_shape=[1, 1, 5, 3], begin=[0, 0, 0, 0], end=[1, 1, 5, 3], strides=[1, 1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=2), + dict(input_shape=[1, 5, 1, 3], begin=[0, 0, 0, 0], end=[1, 5, 1, 3], strides=[1, 1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=4), + dict(input_shape=[1, 5, 5, 1], begin=[0, 0, 0, 0], end=[1, 5, 1, 1], strides=[1, 1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=8), + dict(input_shape=[1, 1, 5, 5, 3], begin=[0, 0, 0, 0, 0], end=[1, 1, 5, 5, 3], strides=[1, 1, 1, 1, 1], + begin_mask=0, end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=3), + dict(input_shape=[1, 5, 1, 5, 3], begin=[0, 0, 0, 0, 0], end=[1, 5, 1, 5, 3], strides=[1, 1, 1, 1, 1], + begin_mask=0, end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=5), + dict(input_shape=[1, 5, 1, 5, 1], begin=[0, 0, 0, 0, 0], end=[1, 5, 1, 5, 1], strides=[1, 1, 1, 1, 1], + begin_mask=0, end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=21), + ] + + @pytest.mark.parametrize('params', test_squeeze_data) + @pytest.mark.nightly + def test_strided_slice_replace_with_squeeze(self, params, ie_device, precision, ir_version, temp_dir): + self._test(*self.create_strided_slice_net(**params, ir_version=ir_version), + ie_device, precision, ir_version, temp_dir=temp_dir) + + test_unsqueeze_data = [ + dict(input_shape=[1, 5], begin=[0, 0], end=[1, 5], strides=[1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=1, shrink_axis_mask=0), + dict(input_shape=[1, 5], begin=[0, 0], end=[1, 5], strides=[1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=3, shrink_axis_mask=0), + dict(input_shape=[1, 5, 3], begin=[0, 0, 0], end=[1, 5, 3], strides=[1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=3, shrink_axis_mask=0), + dict(input_shape=[1, 5, 3], begin=[0, 0, 0], end=[1, 5, 3], strides=[1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=4, shrink_axis_mask=0), + dict(input_shape=[1, 5, 3], begin=[0, 0, 0], end=[1, 5, 3], strides=[1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=5, shrink_axis_mask=0), + dict(input_shape=[1, 5, 5, 3], begin=[0, 0, 0, 0], end=[1, 5, 5, 3], strides=[1, 1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=8, shrink_axis_mask=0), + dict(input_shape=[1, 5, 5, 3], begin=[0, 0, 0, 0], end=[1, 5, 5, 3], strides=[1, 1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=4, shrink_axis_mask=0), + dict(input_shape=[1, 5, 5, 3], begin=[0, 0, 0, 0], end=[1, 5, 5, 3], strides=[1, 1, 1, 1], begin_mask=0, + end_mask=0, ellipsis_mask=0, new_axis_mask=2, shrink_axis_mask=0), + ] + + @pytest.mark.parametrize('params', test_unsqueeze_data) + @pytest.mark.nightly + def test_strided_slice_replace_with_unsqueeze(self, params, ie_device, precision, ir_version, temp_dir): + self._test(*self.create_strided_slice_net(**params, ir_version=ir_version), + ie_device, precision, ir_version, temp_dir=temp_dir) From 4ce9d96ff5ce6d727a85dc62677914d48d33d2c4 Mon Sep 17 00:00:00 2001 From: Polina Brzezinskaya Date: Tue, 24 Aug 2021 13:43:08 +0300 Subject: [PATCH 069/102] [VPU] Added ConvertGather7ToGather1 pass to frontend (#7183) This pr adds ConvertGather7ToGather1 pass to frontend before MergeGatherGatherElements pass, to make it so that when MergeGatherGatherElements is ran, any v7::Gather will be replaced with v1::Gather --- .../src/vpu/graph_transformer/src/frontend/frontend.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp b/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp index c2e5c054de40fa..0fc9a4f6b01b89 100644 --- a/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -181,6 +182,7 @@ ie::CNNNetwork FrontEnd::convertNetwork(ie::CNNNetwork& network) { manager.register_pass(); manager.register_pass(); manager.register_pass(); + manager.register_pass(); manager.register_pass(); manager.register_pass(); From b4b0bf7a24f222b5fc2dc0126d04692b38679196 Mon Sep 17 00:00:00 2001 From: Anton Chetverikov Date: Tue, 24 Aug 2021 15:42:27 +0300 Subject: [PATCH 070/102] [MO] Add transformation for single CTCGreedyDecoder operation (#7023) * Add transformation for single CTCGreedyDecoder operation * Fix style in op specification * Update transformation logic * refactor old tests and add tests for new transformation * Move tf specific front transformations to tf folder * Update transformation logic and comments * Add run_after function and update comments * Add output_sparse_format attribute to extractor * Update transformation conditions and tests * Fix incorrect comment * Move sparse_to_dense_replacer to front/tf folder to fix problems with class registration * Update import * Update output ports handling in transformation * Update test * Fix BOM file * Update pattern for ctcloss transformation * Fix and refactor tests for ctcloss transform * Update transformation conditions --- docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md | 3 +- model-optimizer/automation/package_BOM.txt | 6 +- .../front/CTCGreedyDecoderReplacement.py | 91 ---------- .../front/tf/CTCGreedyDecoderReplacement.py | 155 ++++++++++++++++++ .../front/tf/CTCGreedyDecoder_ext.py | 1 + .../front/{ => tf}/CTCLossReplacement.py | 4 +- .../{ => tf}/sparse_to_dense_replacer.py | 4 +- .../front/CTCGreedyDecoderReplacement_test.py | 96 ----------- .../front/CTCLossReplacement_test.py | 115 ------------- .../tf/CTCGreedyDecoderReplacement_test.py | 149 +++++++++++++++++ .../front/tf/CTCLossReplacement_test.py | 107 ++++++++++++ .../{ => tf}/sparse_to_dense_replacer_test.py | 2 +- 12 files changed, 422 insertions(+), 311 deletions(-) delete mode 100644 model-optimizer/extensions/front/CTCGreedyDecoderReplacement.py create mode 100644 model-optimizer/extensions/front/tf/CTCGreedyDecoderReplacement.py rename model-optimizer/extensions/front/{ => tf}/CTCLossReplacement.py (97%) rename model-optimizer/extensions/front/{ => tf}/sparse_to_dense_replacer.py (93%) delete mode 100644 model-optimizer/unit_tests/extensions/front/CTCGreedyDecoderReplacement_test.py delete mode 100644 model-optimizer/unit_tests/extensions/front/CTCLossReplacement_test.py create mode 100644 model-optimizer/unit_tests/extensions/front/tf/CTCGreedyDecoderReplacement_test.py create mode 100644 model-optimizer/unit_tests/extensions/front/tf/CTCLossReplacement_test.py rename model-optimizer/unit_tests/extensions/front/{ => tf}/sparse_to_dense_replacer_test.py (96%) diff --git a/docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md b/docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md index c4122cb50fbdec..956ca032179248 100644 --- a/docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md +++ b/docs/ops/sequence/CTCGreedyDecoderSeqLen_6.md @@ -74,7 +74,8 @@ The main difference between [CTCGreedyDecoder](CTCGreedyDecoder_1.md) and CTCGre **Example** ```xml - + + 8 diff --git a/model-optimizer/automation/package_BOM.txt b/model-optimizer/automation/package_BOM.txt index 50c5dadb4980ec..87976b571179be 100644 --- a/model-optimizer/automation/package_BOM.txt +++ b/model-optimizer/automation/package_BOM.txt @@ -133,8 +133,6 @@ extensions/front/caffe/split_to_identity.py extensions/front/caffe/tanh.py extensions/front/ChangePlaceholderTypes.py extensions/front/create_tensor_nodes.py -extensions/front/CTCGreedyDecoderReplacement.py -extensions/front/CTCLossReplacement.py extensions/front/disable_weights_quantize_value_propagation.py extensions/front/div.py extensions/front/DropoutWithRandomUniformReplacer.py @@ -370,7 +368,6 @@ extensions/front/scatter_normalizer.py extensions/front/SizeReplacer.py extensions/front/softmax.py extensions/front/softsign_replacer.py -extensions/front/sparse_to_dense_replacer.py extensions/front/split_normalizer.py extensions/front/SqueezeNormalize.py extensions/front/sub.py @@ -401,7 +398,9 @@ extensions/front/tf/CorrectRollAxes.py extensions/front/tf/crop_and_resize_ext.py extensions/front/tf/CropAndResizeReplacement.py extensions/front/tf/CTCGreedyDecoder_ext.py +extensions/front/tf/CTCGreedyDecoderReplacement.py extensions/front/tf/CTCLoss_ext.py +extensions/front/tf/CTCLossReplacement.py extensions/front/tf/cumsum_ext.py extensions/front/tf/deconv_ext.py extensions/front/tf/depth_to_space.py @@ -496,6 +495,7 @@ extensions/front/tf/sparse_fill_empty_rows_ext.py extensions/front/tf/sparse_segment_mean_ext.py extensions/front/tf/sparse_segment_sqrtn_ext.py extensions/front/tf/sparse_segment_sum_ext.py +extensions/front/tf/sparse_to_dense_replacer.py extensions/front/tf/split_ext.py extensions/front/tf/ssd_support.json extensions/front/tf/ssd_support_api_v1.14.json diff --git a/model-optimizer/extensions/front/CTCGreedyDecoderReplacement.py b/model-optimizer/extensions/front/CTCGreedyDecoderReplacement.py deleted file mode 100644 index 143509a0a2ff10..00000000000000 --- a/model-optimizer/extensions/front/CTCGreedyDecoderReplacement.py +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -from extensions.ops.ctc_greedy_decoder_seq_len import CTCGreedyDecoderSeqLenOp -from extensions.ops.transpose import Transpose -from mo.front.common.partial_infer.utils import int64_array -from mo.front.common.replacement import FrontReplacementSubgraph -from mo.front.tf.graph_utils import create_op_with_const_inputs -from mo.graph.graph import Graph, rename_nodes - - -def replace_ctc_greedy_decoder(graph: Graph, match: dict): - ctc_greedy_decoder_tf = match['decoder'] - cast = match['cast'] - sparse_to_dense = match['sparse_to_dense'] - sparse_to_dense_name = sparse_to_dense.soft_get('name', sparse_to_dense.id) - ctc_greedy_decoder_tf_name = ctc_greedy_decoder_tf.soft_get('name', ctc_greedy_decoder_tf.id) - - # for normalizing input chanel need to transpose input data from [T, N, C] to [N, T, C] - # which supported CTCGreedyDecoderSeqLen op. - ctc_data_permute = create_op_with_const_inputs(graph, Transpose, {1: int64_array([1, 0, 2])}, - {'name': ctc_greedy_decoder_tf_name + '/ctc_data_permute'}) - - assert ctc_greedy_decoder_tf.has_valid('merge_repeated'), \ - 'The CTCGreedyDecoderSeqLen node "{}" misses "merge_repeated" attribute'.format(ctc_greedy_decoder_tf_name) - - ctc_greedy_decoder_tf.in_port(0).get_source().connect(ctc_data_permute.in_port(0)) - merge_repeated_tf = ctc_greedy_decoder_tf.merge_repeated - ctc_greedy_decoder = CTCGreedyDecoderSeqLenOp(graph, {'name': sparse_to_dense_name, - 'merge_repeated': merge_repeated_tf}).create_node() - rename_nodes( - [(sparse_to_dense, sparse_to_dense_name + '/AbandonedName'), (ctc_greedy_decoder, sparse_to_dense_name)]) - ctc_greedy_decoder.in_port(0).connect(ctc_data_permute.out_port(0)) - ctc_greedy_decoder_tf.in_port(1).get_source().connect(ctc_greedy_decoder.in_port(1)) - - # set output of the new sub-graph as a source for SparseToDense consumer - sparse_to_dense.out_port(0).get_connection().set_source(ctc_greedy_decoder.out_port(0)) - - # remove no longer needed nodes - graph.remove_nodes_from([sparse_to_dense.id, cast.id, ctc_greedy_decoder_tf.id]) - - -class CTCGreedyDecoderReplacement(FrontReplacementSubgraph): - """ - TensorFlow CTCGreedyDecoder produces output in a sparse tensor that is not supported by Inference Engine and - Inference Engine's CTCGreedyDecoderSeqLen has different output that is in a dense format. So this transformation - intents to replace TF CTCGreedyDecoder+SparseToDense where SparseToDense third input get from input parameter - to CTCGreedyDecoderSeqLen which compatible with IE. - """ - enabled = True - - @staticmethod - def pattern(**kwargs): - return dict( - nodes=[('decoder', dict(op='CTCGreedyDecoderSeqLen')), - ('cast', dict(op='Cast')), - ('sparse_to_dense', dict(op='SparseToDense')) - ], - edges=[('decoder', 'sparse_to_dense', {'out': 0}), - ('decoder', 'cast', {'out': 1}), - ('cast', 'sparse_to_dense', {'out': 0})] - ) - - def replace_sub_graph(self, graph: Graph, match: dict): - replace_ctc_greedy_decoder(graph, match) - - -class CTCGreedyDecoderWithSparseToDenseShapeReplacement(FrontReplacementSubgraph): - """ - TensorFlow CTCGreedyDecoder produces output in a sparse tensor that is not supported by Inference Engine and - Inference Engine's CTCGreedyDecoderSeqLen has different output that is in a dense format. So this transformation - intents to replace TF CTCGreedyDecoder+SparseToDense where SparseToDense third input get from CTCGreedyDecoder - second output to CTCGreedyDecoderSeqLen which compatible with IE. - """ - enabled = True - - @staticmethod - def pattern(**kwargs): - return dict( - nodes=[('decoder', dict(op='CTCGreedyDecoderSeqLen')), - ('cast', dict(op='Cast')), - ('sparse_to_dense', dict(op='SparseToDense')) - ], - edges=[('decoder', 'sparse_to_dense', {'out': 0}), - ('decoder', 'cast', {'out': 1}), - ('decoder', 'sparse_to_dense', {'out': 2}), - ('cast', 'sparse_to_dense', {'out': 0})] - ) - - def replace_sub_graph(self, graph: Graph, match: dict): - replace_ctc_greedy_decoder(graph, match) diff --git a/model-optimizer/extensions/front/tf/CTCGreedyDecoderReplacement.py b/model-optimizer/extensions/front/tf/CTCGreedyDecoderReplacement.py new file mode 100644 index 00000000000000..070c98d7bc8914 --- /dev/null +++ b/model-optimizer/extensions/front/tf/CTCGreedyDecoderReplacement.py @@ -0,0 +1,155 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import logging as log + +from extensions.ops.ctc_greedy_decoder_seq_len import CTCGreedyDecoderSeqLenOp +from extensions.ops.transpose import Transpose +from mo.front.common.partial_infer.utils import int64_array +from mo.front.common.replacement import FrontReplacementSubgraph, FrontReplacementPattern +from mo.front.tf.graph_utils import create_op_with_const_inputs +from mo.graph.graph import Graph, rename_nodes +from mo.ops.result import Result + + +def replace_ctc_greedy_decoder(graph: Graph, match: dict): + ctc_greedy_decoder_tf = match['decoder'] + cast = match['cast'] + sparse_to_dense = match['sparse_to_dense'] + sparse_to_dense_name = sparse_to_dense.soft_get('name', sparse_to_dense.id) + ctc_greedy_decoder_tf_name = ctc_greedy_decoder_tf.soft_get('name', ctc_greedy_decoder_tf.id) + + # For normalizing input channel needs to transpose input data from [T, N, C] to [N, T, C] + # which supported CTCGreedyDecoderSeqLen op. + ctc_data_permute = create_op_with_const_inputs(graph, Transpose, {1: int64_array([1, 0, 2])}, + {'name': ctc_greedy_decoder_tf_name + '/ctc_data_permute'}) + + assert ctc_greedy_decoder_tf.has_valid('merge_repeated'), \ + 'The CTCGreedyDecoderSeqLen node "{}" misses "merge_repeated" attribute'.format(ctc_greedy_decoder_tf_name) + + ctc_greedy_decoder_tf.in_port(0).get_source().connect(ctc_data_permute.in_port(0)) + merge_repeated_tf = ctc_greedy_decoder_tf.merge_repeated + ctc_greedy_decoder = CTCGreedyDecoderSeqLenOp(graph, {'name': sparse_to_dense_name, + 'merge_repeated': merge_repeated_tf}).create_node() + rename_nodes( + [(sparse_to_dense, sparse_to_dense_name + '/AbandonedName'), (ctc_greedy_decoder, sparse_to_dense_name)]) + ctc_greedy_decoder.in_port(0).connect(ctc_data_permute.out_port(0)) + ctc_greedy_decoder_tf.in_port(1).get_source().connect(ctc_greedy_decoder.in_port(1)) + + # Set output of the new sub-graph as a source for SparseToDense consumer + sparse_to_dense.out_port(0).get_connection().set_source(ctc_greedy_decoder.out_port(0)) + + # Remove no longer needed nodes + graph.remove_nodes_from([sparse_to_dense.id, cast.id, ctc_greedy_decoder_tf.id]) + + +class CTCGreedyDecoderReplacement(FrontReplacementSubgraph): + """ + TensorFlow CTCGreedyDecoder produces output in a sparse tensor that is not supported by Inference Engine, and + Inference Engine's CTCGreedyDecoderSeqLen has a different output that is in a dense format. So this transformation + intents to replace TF CTCGreedyDecoder+SparseToDense where SparseToDense third input get from input parameter + to CTCGreedyDecoderSeqLen which compatible with IE. + """ + enabled = True + + @staticmethod + def pattern(**kwargs): + return dict( + nodes=[('decoder', dict(op='CTCGreedyDecoderSeqLen', output_sparse_format=True)), + ('cast', dict(op='Cast')), + ('sparse_to_dense', dict(op='SparseToDense')) + ], + edges=[('decoder', 'sparse_to_dense', {'out': 0}), + ('decoder', 'cast', {'out': 1}), + ('cast', 'sparse_to_dense', {'out': 0})] + ) + + def replace_sub_graph(self, graph: Graph, match: dict): + replace_ctc_greedy_decoder(graph, match) + + +class CTCGreedyDecoderWithSparseToDenseShapeReplacement(FrontReplacementSubgraph): + """ + TensorFlow CTCGreedyDecoder produces output in a sparse tensor that is not supported by Inference Engine, and + Inference Engine's CTCGreedyDecoderSeqLen has a different output that is in a dense format. So this transformation + intents to replace TF CTCGreedyDecoder+SparseToDense where SparseToDense third input get from CTCGreedyDecoder + second output to CTCGreedyDecoderSeqLen which compatible with IE. + """ + enabled = True + + @staticmethod + def pattern(**kwargs): + return dict( + nodes=[('decoder', dict(op='CTCGreedyDecoderSeqLen', output_sparse_format=True)), + ('cast', dict(op='Cast')), + ('sparse_to_dense', dict(op='SparseToDense')) + ], + edges=[('decoder', 'sparse_to_dense', {'out': 0}), + ('decoder', 'cast', {'out': 1}), + ('decoder', 'sparse_to_dense', {'out': 2}), + ('cast', 'sparse_to_dense', {'out': 0})] + ) + + def replace_sub_graph(self, graph: Graph, match: dict): + replace_ctc_greedy_decoder(graph, match) + + +class CTCGreedyDecoderSingleReplacement(FrontReplacementPattern): + """ + TensorFlow CTCGreedyDecoder produces output in a sparse tensor that is not supported by Inference Engine, and + Inference Engine's CTCGreedyDecoderSeqLen has a different output that is in a dense format. So this transformation + handles a single TF CTCGreedyDecoder and warns the user about another format of the output + """ + enabled = True + + def run_after(self): + return [CTCGreedyDecoderReplacement, CTCGreedyDecoderWithSparseToDenseShapeReplacement] + + def find_and_replace_pattern(self, graph: Graph): + for ctc_greedy_decoder_tf in graph.get_op_nodes(op='CTCGreedyDecoderSeqLen', output_sparse_format=True): + ctc_greedy_decoder_tf_name = ctc_greedy_decoder_tf.soft_get('name', ctc_greedy_decoder_tf.id) + + # TF CTCGreedyDecoder have 4 output tensors. If any of them connected to not Result operation then + # transformation in not applicable + for port_num in ctc_greedy_decoder_tf.out_ports(): + if not ctc_greedy_decoder_tf.out_port(port_num).disconnected()\ + and ctc_greedy_decoder_tf.out_port(port_num).get_destination().node.soft_get('op') != 'Result': + return + + # If the first and second output are not connected to Result operations - + # create Result operation and connect it to appropriate output + if ctc_greedy_decoder_tf.out_port(0).disconnected(): + first_result = Result(graph, + {'name': ctc_greedy_decoder_tf_name + '/decoded_classes'} + ).create_node() + ctc_greedy_decoder_tf.out_port(0).connect(first_result.in_port(0)) + + if ctc_greedy_decoder_tf.out_port(1).disconnected(): + second_result = Result(graph, + {'name': ctc_greedy_decoder_tf_name + '/seq_lengths_output'} + ).create_node() + ctc_greedy_decoder_tf.out_port(1).connect(second_result.in_port(0)) + + + # For normalizing input channel needs to transpose input data from [T, N, C] to [N, T, C] + # which supported CTCGreedyDecoderSeqLen op. + log.warning('Found TF CTCGreedyDecoder operation at the end of network. ' + 'PLEASE NOTE, appropriate network output operation CTCGreedyDecoderSeqLen {} ' + 'will have dense format, not sparse format!'.format(ctc_greedy_decoder_tf_name)) + ctc_data_permute = create_op_with_const_inputs(graph, Transpose, {1: int64_array([1, 0, 2])}, + {'name': ctc_greedy_decoder_tf_name + '/ctc_data_permute'}) + + assert ctc_greedy_decoder_tf.has_valid('merge_repeated'), \ + 'The CTCGreedyDecoderSeqLen node "{}" misses "merge_repeated" attribute'.format( + ctc_greedy_decoder_tf_name) + + ctc_greedy_decoder_tf.in_port(0).get_source().connect(ctc_data_permute.in_port(0)) + ctc_greedy_decoder_tf.in_port(0).disconnect() + ctc_data_permute.out_port(0).connect(ctc_greedy_decoder_tf.in_port(0)) + + del ctc_greedy_decoder_tf['output_sparse_format'] + + for port_num in [2, 3]: # MO CTCGreedyDecoderSeqLen may have 2 outputs + if port_num in ctc_greedy_decoder_tf.out_ports(): + if not ctc_greedy_decoder_tf.out_port(port_num).disconnected(): + ctc_greedy_decoder_tf.out_port(port_num).disconnect() diff --git a/model-optimizer/extensions/front/tf/CTCGreedyDecoder_ext.py b/model-optimizer/extensions/front/tf/CTCGreedyDecoder_ext.py index 5efbaed7aa3324..4e2577da98e138 100644 --- a/model-optimizer/extensions/front/tf/CTCGreedyDecoder_ext.py +++ b/model-optimizer/extensions/front/tf/CTCGreedyDecoder_ext.py @@ -13,6 +13,7 @@ class CTCCGreedyDecoderFrontExtractor(FrontExtractorOp): def extract(cls, node): attrs = { 'merge_repeated': bool(node.pb.attr['merge_repeated'].b), + 'output_sparse_format': True, # Special argument for TF CTCGreedyDecoder replacement transformations } CTCGreedyDecoderSeqLenOp.update_node_stat(node, attrs) return cls.enabled diff --git a/model-optimizer/extensions/front/CTCLossReplacement.py b/model-optimizer/extensions/front/tf/CTCLossReplacement.py similarity index 97% rename from model-optimizer/extensions/front/CTCLossReplacement.py rename to model-optimizer/extensions/front/tf/CTCLossReplacement.py index ea2e6cbd3bc135..55045b8de2958e 100644 --- a/model-optimizer/extensions/front/CTCLossReplacement.py +++ b/model-optimizer/extensions/front/tf/CTCLossReplacement.py @@ -20,14 +20,14 @@ class CTCLossReplacement(FrontReplacementSubgraph): enabled = True def run_before(self): - from extensions.front.CTCGreedyDecoderReplacement import CTCGreedyDecoderReplacement + from extensions.front.tf.CTCGreedyDecoderReplacement import CTCGreedyDecoderReplacement return [CTCGreedyDecoderReplacement] def pattern(self): return dict( nodes=[ ('transpose', dict(op='Transpose')), - ('ctc_greedy_decoder', dict(op='CTCGreedyDecoderSeqLen')), + ('ctc_greedy_decoder', dict(op='CTCGreedyDecoderSeqLen', output_sparse_format=True)), ('cast', dict(op='Cast')), ('sparse_to_dense', dict(op='SparseToDense')), ('const', dict(op='Const')), diff --git a/model-optimizer/extensions/front/sparse_to_dense_replacer.py b/model-optimizer/extensions/front/tf/sparse_to_dense_replacer.py similarity index 93% rename from model-optimizer/extensions/front/sparse_to_dense_replacer.py rename to model-optimizer/extensions/front/tf/sparse_to_dense_replacer.py index f285192a5a009c..1440b150696a94 100644 --- a/model-optimizer/extensions/front/sparse_to_dense_replacer.py +++ b/model-optimizer/extensions/front/tf/sparse_to_dense_replacer.py @@ -21,8 +21,8 @@ class SparseToDenseReplacer(FrontReplacementOp): enabled = True def run_after(self): - from extensions.front.CTCGreedyDecoderReplacement import CTCGreedyDecoderReplacement - from extensions.front.CTCLossReplacement import CTCLossReplacement + from extensions.front.tf.CTCGreedyDecoderReplacement import CTCGreedyDecoderReplacement + from extensions.front.tf.CTCLossReplacement import CTCLossReplacement return [CTCGreedyDecoderReplacement, CTCLossReplacement] def replace_op(self, graph: Graph, node: Node): diff --git a/model-optimizer/unit_tests/extensions/front/CTCGreedyDecoderReplacement_test.py b/model-optimizer/unit_tests/extensions/front/CTCGreedyDecoderReplacement_test.py deleted file mode 100644 index 063d71173e1f7e..00000000000000 --- a/model-optimizer/unit_tests/extensions/front/CTCGreedyDecoderReplacement_test.py +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -import unittest - -from extensions.front.CTCGreedyDecoderReplacement import CTCGreedyDecoderReplacement, CTCGreedyDecoderWithSparseToDenseShapeReplacement -from mo.front.common.partial_infer.utils import int64_array -from mo.utils.ir_engine.compare_graphs import compare_graphs -from unit_tests.utils.graph import build_graph, const - - -class CTCGreedyDecoderReplacementTests(unittest.TestCase): - def test1(self): - nodes_attributes = { - # nodes from original graph - 'logits': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, - 'seq_len': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, - 'order_arr': {'kind': 'op', 'op': 'Const'}, - 'transpose': {'type': 'Transpose', 'kind': 'op', 'op': 'Transpose'}, - 'decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'merge_repeated': True}, - 'cast': {'kind': 'op', 'op': 'Cast'}, - 'sparse_to_dense': {'kind': 'op', 'op': 'SparseToDense'}, - 'last': {'type': None, 'value': None, 'kind': 'op', 'op': 'Result'}, - - # new nodes - 'new_decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'use_mask_format': True}, - **const('squeeze_axes', int64_array([2, 3])), - 'squeeze_dec_seq': {'kind': 'op', 'op': 'Squeeze'}, - 'cast_to_int': {'kind': 'op', 'op': 'Cast'}, - } - - graph = build_graph(nodes_attributes, - [('logits', 'decoder', {'out': 0, 'in': 0}), - ('seq_len', 'decoder', {'out': 0, 'in': 1}), - ('decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), - ('decoder', 'sparse_to_dense', {'out': 2, 'in': 1}), - ('decoder', 'cast', {'out': 1, 'in': 0}), - ('cast', 'sparse_to_dense', {'out': 0}), - ('sparse_to_dense', 'last', {'out': 0, 'in': 0}), - ], nodes_with_edges_only=True) - graph.stage = 'front' - CTCGreedyDecoderWithSparseToDenseShapeReplacement().find_and_replace_pattern(graph) - - graph_ref = build_graph(nodes_attributes, - [('logits', 'transpose', {'out': 0, 'in': 0}), - ('order_arr', 'transpose', {'out': 0, 'in': 1}), - ('transpose', 'decoder', {'out': 0, 'in': 0}), - ('seq_len', 'decoder', {'out': 0, 'in': 1}), - ('decoder', 'last', {'out': 0, 'in': 0}), - ], - nodes_with_edges_only=True) - - (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) - self.assertTrue(flag, resp) - - def test2(self): - nodes_attributes = { - # nodes from original graph - 'logits': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, - 'seq_len': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, - 'order_arr': {'kind': 'op', 'op': 'Const'}, - 'transpose': {'type': 'Transpose', 'kind': 'op', 'op': 'Transpose'}, - 'decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'merge_repeated': True}, - 'cast': {'kind': 'op', 'op': 'Cast'}, - 'sparse_to_dense': {'kind': 'op', 'op': 'SparseToDense'}, - 'last': {'type': None, 'value': None, 'kind': 'op', 'op': 'Result'}, - - # new nodes - 'new_decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'use_mask_format': True}, - **const('squeeze_axes', int64_array([2, 3])), - 'squeeze_dec_seq': {'kind': 'op', 'op': 'Squeeze'}, - 'cast_to_int': {'kind': 'op', 'op': 'Cast'}, - } - - graph = build_graph(nodes_attributes, - [('logits', 'decoder', {'out': 0, 'in': 0}), - ('seq_len', 'decoder', {'out': 0, 'in': 1}), - ('decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), - ('decoder', 'cast', {'out': 1, 'in': 0}), - ('cast', 'sparse_to_dense', {'out': 0}), - ('sparse_to_dense', 'last', {'out': 0, 'in': 0}), - ], nodes_with_edges_only=True) - graph.stage = 'front' - CTCGreedyDecoderReplacement().find_and_replace_pattern(graph) - - graph_ref = build_graph(nodes_attributes, - [('logits', 'transpose', {'out': 0, 'in': 0}), - ('order_arr', 'transpose', {'out': 0, 'in': 1}), - ('transpose', 'decoder', {'out': 0, 'in': 0}), - ('seq_len', 'decoder', {'out': 0, 'in': 1}), - ('decoder', 'last', {'out': 0, 'in': 0}), - ], - nodes_with_edges_only=True) - - (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) - self.assertTrue(flag, resp) diff --git a/model-optimizer/unit_tests/extensions/front/CTCLossReplacement_test.py b/model-optimizer/unit_tests/extensions/front/CTCLossReplacement_test.py deleted file mode 100644 index 77ecfc8fa1afd9..00000000000000 --- a/model-optimizer/unit_tests/extensions/front/CTCLossReplacement_test.py +++ /dev/null @@ -1,115 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -import numpy as np -import unittest -from argparse import Namespace - -from extensions.front.CTCLossReplacement import CTCLossReplacement -from mo.front.common.partial_infer.utils import int64_array -from mo.utils.ir_engine.compare_graphs import compare_graphs -from unit_tests.utils.graph import build_graph, const - - -class CTCLossFrontReplacementTest(unittest.TestCase): - def test1(self): - nodes_attributes = { - 'logits': {'shape': int64_array([2, 6, 100]), 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, - 'seq_mask': {'shape': int64_array([2]), 'data_type': np.int32, 'kind': 'op', 'op': 'Parameter'}, - 'transpose': {'kind': 'op', 'op': 'Transpose'}, - 'ctc_greedy_decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'merge_repeated': True}, - 'cast': {'kind': 'op', 'op': 'Cast'}, - 'sparse_to_dense': {'kind': 'op', 'op': 'SparseToDense'}, - 'tf_ctc_loss': {'kind': 'op', 'op': 'CTCLoss', 'preprocess_collapse_repeated': False, - 'ctc_merge_repeated': True, 'unique': False, 'logits_time_major': True}, - 'ctc_loss': {'kind': 'op', 'op': 'CTCLoss', 'preprocess_collapse_repeated': False, - 'ctc_merge_repeated': True, 'unique': False}, - **const('default_value', int64_array(-1)), - 'last': {'type': None, 'value': None, 'kind': 'op', 'op': 'Result'}, - 'transpose2': {'kind': 'op', 'op': 'Transpose'}, - **const('transpose2_axis', int64_array([1, 0, 2])), - } - graph = build_graph(nodes_attributes, [('logits', 'transpose', {'out': 0, 'in': 0}), - ('transpose', 'ctc_greedy_decoder', {'out': 0, 'in': 0}), - ('seq_mask', 'ctc_greedy_decoder', {'out': 0, 'in': 1}), - ('transpose', 'tf_ctc_loss', {'out': 0, 'in': 0}), - ('seq_mask', 'tf_ctc_loss', {'out': 0, 'in': 3}), - ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), - ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 2, 'in': 1}), - ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 1, 'in': 2}), - ('default_value', 'sparse_to_dense', {'out': 0, 'in': 3}), - ('ctc_greedy_decoder', 'cast', {'out': 1, 'in': 0}), - ('ctc_greedy_decoder', 'tf_ctc_loss', {'out': 0, 'in': 1}), - ('cast', 'tf_ctc_loss', {'out': 0, 'in': 2}), - ('tf_ctc_loss', 'last', {'out': 0, 'in': 0})], - nodes_with_edges_only=True) - graph.graph['cmd_params'] = Namespace(data_type='FP32') - graph.stage = 'front' - CTCLossReplacement().find_and_replace_pattern(graph) - - graph_ref = build_graph(nodes_attributes, - [('logits', 'transpose', {'out': 0, 'in': 0}), - ('transpose', 'transpose2', {'out': 0, 'in': 0}), - ('transpose2_axis', 'transpose2', {'out': 0, 'in': 1}), - ('transpose2', 'ctc_greedy_decoder', {'out': 0, 'in': 0}), - ('seq_mask', 'ctc_greedy_decoder', {'out': 0, 'in': 1}), - ('transpose2', 'ctc_loss', {'out': 0, 'in': 0}), - ('ctc_greedy_decoder', 'ctc_loss', {'out': 0, 'in': 2}), - ('ctc_greedy_decoder', 'ctc_loss', {'out': 1, 'in': 3}), - ('seq_mask', 'ctc_loss', {'out': 0, 'in': 1}), - ('ctc_loss', 'last', {'out': 0, 'in': 0})], - nodes_with_edges_only=True) - - (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) - self.assertTrue(flag, resp) - - def test2(self): - nodes_attributes = { - 'logits': {'shape': int64_array([2, 6, 100]), 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, - 'seq_mask': {'shape': int64_array([2]), 'data_type': np.int32, 'kind': 'op', 'op': 'Parameter'}, - 'transpose': {'kind': 'op', 'op': 'Transpose'}, - 'ctc_greedy_decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'merge_repeated': True}, - 'cast': {'kind': 'op', 'op': 'Cast'}, - 'sparse_to_dense': {'kind': 'op', 'op': 'SparseToDense'}, - 'tf_ctc_loss': {'kind': 'op', 'op': 'CTCLoss', 'preprocess_collapse_repeated': False, - 'ctc_merge_repeated': True, 'unique': False, 'logits_time_major': False}, - 'ctc_loss': {'kind': 'op', 'op': 'CTCLoss', 'preprocess_collapse_repeated': False, - 'ctc_merge_repeated': True, 'unique': False}, - **const('default_value', int64_array(-1)), - 'last': {'type': None, 'value': None, 'kind': 'op', 'op': 'Result'}, - 'transpose2': {'kind': 'op', 'op': 'Transpose'}, - **const('transpose2_axis', int64_array([1, 0, 2])), - } - graph = build_graph(nodes_attributes, [('logits', 'transpose', {'out': 0, 'in': 0}), - ('transpose', 'ctc_greedy_decoder', {'out': 0, 'in': 0}), - ('seq_mask', 'ctc_greedy_decoder', {'out': 0, 'in': 1}), - ('transpose', 'tf_ctc_loss', {'out': 0, 'in': 0}), - ('seq_mask', 'tf_ctc_loss', {'out': 0, 'in': 3}), - ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), - ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 2, 'in': 1}), - ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 1, 'in': 2}), - ('default_value', 'sparse_to_dense', {'out': 0, 'in': 3}), - ('ctc_greedy_decoder', 'cast', {'out': 1, 'in': 0}), - ('ctc_greedy_decoder', 'tf_ctc_loss', {'out': 0, 'in': 1}), - ('cast', 'tf_ctc_loss', {'out': 0, 'in': 2}), - ('tf_ctc_loss', 'last', {'out': 0, 'in': 0})], - nodes_with_edges_only=True) - graph.graph['cmd_params'] = Namespace(data_type='FP32') - graph.stage = 'front' - CTCLossReplacement().find_and_replace_pattern(graph) - - graph_ref = build_graph(nodes_attributes, - [('logits', 'transpose', {'out': 0, 'in': 0}), - ('transpose', 'transpose2', {'out': 0, 'in': 0}), - ('transpose2_axis', 'transpose2', {'out': 0, 'in': 1}), - ('transpose2', 'ctc_greedy_decoder', {'out': 0, 'in': 0}), - ('seq_mask', 'ctc_greedy_decoder', {'out': 0, 'in': 1}), - ('transpose', 'ctc_loss', {'out': 0, 'in': 0}), - ('ctc_greedy_decoder', 'ctc_loss', {'out': 0, 'in': 2}), - ('ctc_greedy_decoder', 'ctc_loss', {'out': 1, 'in': 3}), - ('seq_mask', 'ctc_loss', {'out': 0, 'in': 1}), - ('ctc_loss', 'last', {'out': 0, 'in': 0})], - nodes_with_edges_only=True) - - (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) - self.assertTrue(flag, resp) diff --git a/model-optimizer/unit_tests/extensions/front/tf/CTCGreedyDecoderReplacement_test.py b/model-optimizer/unit_tests/extensions/front/tf/CTCGreedyDecoderReplacement_test.py new file mode 100644 index 00000000000000..ff93aa30240ed0 --- /dev/null +++ b/model-optimizer/unit_tests/extensions/front/tf/CTCGreedyDecoderReplacement_test.py @@ -0,0 +1,149 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import unittest + +from extensions.front.tf.CTCGreedyDecoderReplacement import CTCGreedyDecoderReplacement, \ + CTCGreedyDecoderWithSparseToDenseShapeReplacement, CTCGreedyDecoderSingleReplacement +from mo.front.common.partial_infer.utils import int64_array +from mo.utils.ir_engine.compare_graphs import compare_graphs +from unit_tests.utils.graph import build_graph, const + + +class CTCGreedyDecoderReplacementTests(unittest.TestCase): + nodes_attributes = { + # nodes from original graph + 'logits': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, + 'seq_len': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, + 'order_arr': {'kind': 'op', 'op': 'Const'}, + 'transpose': {'type': 'Transpose', 'kind': 'op', 'op': 'Transpose'}, + 'decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'merge_repeated': True, 'output_sparse_format': True}, + 'cast': {'kind': 'op', 'op': 'Cast'}, + 'sparse_to_dense': {'kind': 'op', 'op': 'SparseToDense'}, + 'last': {'type': None, 'value': None, 'kind': 'op', 'op': 'Result'}, + 'last_1': {'type': None, 'value': None, 'kind': 'op', 'op': 'Result'}, + + # new nodes + 'new_decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'merge_repeated': True}, + **const('squeeze_axes', int64_array([2, 3])), + 'squeeze_dec_seq': {'kind': 'op', 'op': 'Squeeze'}, + 'cast_to_int': {'kind': 'op', 'op': 'Cast'}, + 'out_seq_len': {'type': None, 'value': None, 'kind': 'op', 'op': 'Result'}, + } + + def test_CTCGreedyDecoderWithSparseToDenseShape(self): + graph = build_graph(self.nodes_attributes, + [('logits', 'decoder', {'out': 0, 'in': 0}), + ('seq_len', 'decoder', {'out': 0, 'in': 1}), + ('decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), + ('decoder', 'sparse_to_dense', {'out': 2, 'in': 1}), + ('decoder', 'cast', {'out': 1, 'in': 0}), + ('cast', 'sparse_to_dense', {'out': 0}), + ('sparse_to_dense', 'last', {'out': 0, 'in': 0}), + ], nodes_with_edges_only=True) + graph.stage = 'front' + CTCGreedyDecoderWithSparseToDenseShapeReplacement().find_and_replace_pattern(graph) + + graph_ref = build_graph(self.nodes_attributes, + [('logits', 'transpose', {'out': 0, 'in': 0}), + ('order_arr', 'transpose', {'out': 0, 'in': 1}), + ('transpose', 'new_decoder', {'out': 0, 'in': 0}), + ('seq_len', 'new_decoder', {'out': 0, 'in': 1}), + ('new_decoder', 'last', {'out': 0, 'in': 0}), + ], + nodes_with_edges_only=True) + + (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) + self.assertTrue(flag, resp) + + def test_CTCGreedyDecoderReplacement(self): + graph = build_graph(self.nodes_attributes, + [('logits', 'decoder', {'out': 0, 'in': 0}), + ('seq_len', 'decoder', {'out': 0, 'in': 1}), + ('decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), + ('decoder', 'cast', {'out': 1, 'in': 0}), + ('cast', 'sparse_to_dense', {'out': 0}), + ('sparse_to_dense', 'last', {'out': 0, 'in': 0}), + ], nodes_with_edges_only=True) + graph.stage = 'front' + CTCGreedyDecoderReplacement().find_and_replace_pattern(graph) + + graph_ref = build_graph(self.nodes_attributes, + [('logits', 'transpose', {'out': 0, 'in': 0}), + ('order_arr', 'transpose', {'out': 0, 'in': 1}), + ('transpose', 'new_decoder', {'out': 0, 'in': 0}), + ('seq_len', 'new_decoder', {'out': 0, 'in': 1}), + ('new_decoder', 'last', {'out': 0, 'in': 0}), + ], + nodes_with_edges_only=True) + + (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) + self.assertTrue(flag, resp) + + def test_CTCGreedyDecoderSingle(self): + graph = build_graph(self.nodes_attributes, + [('logits', 'decoder', {'out': 0, 'in': 0}), + ('seq_len', 'decoder', {'out': 0, 'in': 1}), + ('decoder', 'last', {'out': 0, 'in': 0}), + ('decoder', 'last_1', {'out': 1, 'in': 0}), + ], nodes_with_edges_only=True) + graph.stage = 'front' + CTCGreedyDecoderSingleReplacement().find_and_replace_pattern(graph) + + graph_ref = build_graph(self.nodes_attributes, + [('logits', 'transpose', {'out': 0, 'in': 0}), + ('order_arr', 'transpose', {'out': 0, 'in': 1}), + ('transpose', 'new_decoder', {'out': 0, 'in': 0}), + ('seq_len', 'new_decoder', {'out': 0, 'in': 1}), + ('new_decoder', 'last', {'out': 0, 'in': 0}), + ('new_decoder', 'last_1', {'out': 1, 'in': 0}), + ], + nodes_with_edges_only=True) + + (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) + self.assertTrue(flag, resp) + + def test_CTCGreedyDecoderSingle_negative(self): + edges = [('logits', 'decoder', {'out': 0, 'in': 0}), + ('seq_len', 'decoder', {'out': 0, 'in': 1}), + ('decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), + ('decoder', 'cast', {'out': 1, 'in': 0}), + ('cast', 'sparse_to_dense', {'out': 0}), + ('sparse_to_dense', 'last', {'out': 0, 'in': 0}), + ] + graph = build_graph(self.nodes_attributes, + edges, nodes_with_edges_only=True) + graph.stage = 'front' + CTCGreedyDecoderSingleReplacement().find_and_replace_pattern(graph) + + graph_ref = build_graph(self.nodes_attributes, + edges, nodes_with_edges_only=True) + + (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) + self.assertTrue(flag, resp) + + def test_CTCGreedyDecoder_no_consequent_transforms(self): + graph = build_graph(self.nodes_attributes, + [('logits', 'decoder', {'out': 0, 'in': 0}), + ('seq_len', 'decoder', {'out': 0, 'in': 1}), + ('decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), + ('decoder', 'sparse_to_dense', {'out': 2, 'in': 1}), + ('decoder', 'cast', {'out': 1, 'in': 0}), + ('cast', 'sparse_to_dense', {'out': 0}), + ('sparse_to_dense', 'last', {'out': 0, 'in': 0}), + ], nodes_with_edges_only=True) + graph.stage = 'front' + CTCGreedyDecoderWithSparseToDenseShapeReplacement().find_and_replace_pattern(graph) + CTCGreedyDecoderSingleReplacement().find_and_replace_pattern(graph) + + graph_ref = build_graph(self.nodes_attributes, + [('logits', 'transpose', {'out': 0, 'in': 0}), + ('order_arr', 'transpose', {'out': 0, 'in': 1}), + ('transpose', 'new_decoder', {'out': 0, 'in': 0}), + ('seq_len', 'new_decoder', {'out': 0, 'in': 1}), + ('new_decoder', 'last', {'out': 0, 'in': 0}), + ], + nodes_with_edges_only=True) + + (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) + self.assertTrue(flag, resp) diff --git a/model-optimizer/unit_tests/extensions/front/tf/CTCLossReplacement_test.py b/model-optimizer/unit_tests/extensions/front/tf/CTCLossReplacement_test.py new file mode 100644 index 00000000000000..3367a94fe85161 --- /dev/null +++ b/model-optimizer/unit_tests/extensions/front/tf/CTCLossReplacement_test.py @@ -0,0 +1,107 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import unittest +from argparse import Namespace + +from extensions.front.tf.CTCLossReplacement import CTCLossReplacement +from mo.front.common.partial_infer.utils import int64_array +from mo.utils.ir_engine.compare_graphs import compare_graphs +from unit_tests.utils.graph import build_graph, const + + +class CTCLossFrontReplacementTest(unittest.TestCase): + nodes_attributes = { + 'logits': {'shape': int64_array([2, 6, 100]), 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, + 'seq_mask': {'shape': int64_array([2]), 'data_type': np.int32, 'kind': 'op', 'op': 'Parameter'}, + 'transpose': {'kind': 'op', 'op': 'Transpose'}, + 'ctc_greedy_decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'merge_repeated': True, + 'output_sparse_format': True}, + 'cast': {'kind': 'op', 'op': 'Cast'}, + 'sparse_to_dense': {'kind': 'op', 'op': 'SparseToDense'}, + 'tf_ctc_loss_true_logits': {'kind': 'op', 'op': 'CTCLoss', 'preprocess_collapse_repeated': False, + 'ctc_merge_repeated': True, 'unique': False, 'logits_time_major': True}, + 'tf_ctc_loss_false_logits': {'kind': 'op', 'op': 'CTCLoss', 'preprocess_collapse_repeated': False, + 'ctc_merge_repeated': True, 'unique': False, 'logits_time_major': False}, + 'ctc_loss': {'kind': 'op', 'op': 'CTCLoss', 'preprocess_collapse_repeated': False, + 'ctc_merge_repeated': True, 'unique': False}, + **const('default_value', int64_array(-1)), + 'last': {'type': None, 'value': None, 'kind': 'op', 'op': 'Result'}, + 'transpose2': {'kind': 'op', 'op': 'Transpose'}, + **const('transpose2_axis', int64_array([1, 0, 2])), + + 'new_ctc_greedy_decoder': {'kind': 'op', 'op': 'CTCGreedyDecoderSeqLen', 'merge_repeated': True}, + } + + def CTCLossReplacement_test_true_logits(self): + graph = build_graph(self.nodes_attributes, + [('logits', 'transpose', {'out': 0, 'in': 0}), + ('transpose', 'ctc_greedy_decoder', {'out': 0, 'in': 0}), + ('seq_mask', 'ctc_greedy_decoder', {'out': 0, 'in': 1}), + ('transpose', 'tf_ctc_loss_true_logits', {'out': 0, 'in': 0}), + ('seq_mask', 'tf_ctc_loss_true_logits', {'out': 0, 'in': 3}), + ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), + ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 2, 'in': 1}), + ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 1, 'in': 2}), + ('default_value', 'sparse_to_dense', {'out': 0, 'in': 3}), + ('ctc_greedy_decoder', 'cast', {'out': 1, 'in': 0}), + ('ctc_greedy_decoder', 'tf_ctc_loss_true_logits', {'out': 0, 'in': 1}), + ('cast', 'tf_ctc_loss_true_logits', {'out': 0, 'in': 2}), + ('tf_ctc_loss_true_logits', 'last', {'out': 0, 'in': 0})], + nodes_with_edges_only=True) + graph.graph['cmd_params'] = Namespace(data_type='FP32') + graph.stage = 'front' + CTCLossReplacement().find_and_replace_pattern(graph) + + graph_ref = build_graph(self.nodes_attributes, + [('logits', 'transpose', {'out': 0, 'in': 0}), + ('transpose', 'transpose2', {'out': 0, 'in': 0}), + ('transpose2_axis', 'transpose2', {'out': 0, 'in': 1}), + ('transpose2', 'new_ctc_greedy_decoder', {'out': 0, 'in': 0}), + ('seq_mask', 'new_ctc_greedy_decoder', {'out': 0, 'in': 1}), + ('transpose2', 'ctc_loss', {'out': 0, 'in': 0}), + ('new_ctc_greedy_decoder', 'ctc_loss', {'out': 0, 'in': 2}), + ('new_ctc_greedy_decoder', 'ctc_loss', {'out': 1, 'in': 3}), + ('seq_mask', 'ctc_loss', {'out': 0, 'in': 1}), + ('ctc_loss', 'last', {'out': 0, 'in': 0})], + nodes_with_edges_only=True) + + (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) + self.assertTrue(flag, resp) + + def CTCLossReplacement_test_false_logits(self): + graph = build_graph(self.nodes_attributes, + [('logits', 'transpose', {'out': 0, 'in': 0}), + ('transpose', 'ctc_greedy_decoder', {'out': 0, 'in': 0}), + ('seq_mask', 'ctc_greedy_decoder', {'out': 0, 'in': 1}), + ('transpose', 'tf_ctc_loss_false_logits', {'out': 0, 'in': 0}), + ('seq_mask', 'tf_ctc_loss_false_logits', {'out': 0, 'in': 3}), + ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 0, 'in': 0}), + ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 2, 'in': 1}), + ('ctc_greedy_decoder', 'sparse_to_dense', {'out': 1, 'in': 2}), + ('default_value', 'sparse_to_dense', {'out': 0, 'in': 3}), + ('ctc_greedy_decoder', 'cast', {'out': 1, 'in': 0}), + ('ctc_greedy_decoder', 'tf_ctc_loss_false_logits', {'out': 0, 'in': 1}), + ('cast', 'tf_ctc_loss_false_logits', {'out': 0, 'in': 2}), + ('tf_ctc_loss_false_logits', 'last', {'out': 0, 'in': 0})], + nodes_with_edges_only=True) + graph.graph['cmd_params'] = Namespace(data_type='FP32') + graph.stage = 'front' + CTCLossReplacement().find_and_replace_pattern(graph) + + graph_ref = build_graph(self.nodes_attributes, + [('logits', 'transpose', {'out': 0, 'in': 0}), + ('transpose', 'transpose2', {'out': 0, 'in': 0}), + ('transpose2_axis', 'transpose2', {'out': 0, 'in': 1}), + ('transpose2', 'new_ctc_greedy_decoder', {'out': 0, 'in': 0}), + ('seq_mask', 'new_ctc_greedy_decoder', {'out': 0, 'in': 1}), + ('transpose', 'ctc_loss', {'out': 0, 'in': 0}), + ('new_ctc_greedy_decoder', 'ctc_loss', {'out': 0, 'in': 2}), + ('new_ctc_greedy_decoder', 'ctc_loss', {'out': 1, 'in': 3}), + ('seq_mask', 'ctc_loss', {'out': 0, 'in': 1}), + ('ctc_loss', 'last', {'out': 0, 'in': 0})], + nodes_with_edges_only=True) + + (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) + self.assertTrue(flag, resp) diff --git a/model-optimizer/unit_tests/extensions/front/sparse_to_dense_replacer_test.py b/model-optimizer/unit_tests/extensions/front/tf/sparse_to_dense_replacer_test.py similarity index 96% rename from model-optimizer/unit_tests/extensions/front/sparse_to_dense_replacer_test.py rename to model-optimizer/unit_tests/extensions/front/tf/sparse_to_dense_replacer_test.py index 588d52198c9c16..4e624dfd069c1e 100644 --- a/model-optimizer/unit_tests/extensions/front/sparse_to_dense_replacer_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/sparse_to_dense_replacer_test.py @@ -3,7 +3,7 @@ import unittest -from extensions.front.sparse_to_dense_replacer import SparseToDenseReplacer +from extensions.front.tf.sparse_to_dense_replacer import SparseToDenseReplacer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph, const From bd958bddd8656e1a2eebfbf0252b175800dbef84 Mon Sep 17 00:00:00 2001 From: iliya mironov Date: Tue, 24 Aug 2021 15:43:19 +0300 Subject: [PATCH 071/102] Add support opset11 for gemm normalizer (#6733) * Add support opset11 for gemm normolizer * Add layer test for gemm opset 11 * Fix layer test * Fix layer test * Refactoring according to code review * Fix * Update biases norm * Refactoring matmul norm * Fix accoding to review * Fix alpha parameter * Fix variable naming * Refactoring according to code review --- .../extensions/front/MatMul_normalizer.py | 63 +++++++++---------- tests/layer_tests/onnx_tests/test_gemm.py | 53 ++++++++++------ 2 files changed, 63 insertions(+), 53 deletions(-) diff --git a/model-optimizer/extensions/front/MatMul_normalizer.py b/model-optimizer/extensions/front/MatMul_normalizer.py index 81588336d681da..44bd5dce3184e8 100644 --- a/model-optimizer/extensions/front/MatMul_normalizer.py +++ b/model-optimizer/extensions/front/MatMul_normalizer.py @@ -11,6 +11,7 @@ from mo.front.common.partial_infer.utils import int64_array from mo.front.common.replacement import FrontReplacementSubgraph from mo.front.subgraph_matcher import SubgraphMatch +from mo.front.tf.graph_utils import create_op_with_const_inputs from mo.graph.graph import Graph, rename_nodes from mo.ops.reshape import Reshape @@ -72,36 +73,32 @@ class GemmDecomposer(FrontReplacementSubgraph): """ enabled = True - def pattern(self): - return dict( - nodes=[('op', dict(kind='op', op='Gemm'))], - edges=[], - ) - - def replace_sub_graph(self, graph: Graph, match: [dict, SubgraphMatch]): - node = match['op'] - name = node.soft_get('name', node.id) - - # biases normalization - bias_node = Add(graph, {'name': name + '/Bias_', 'can_be_scaleshift': False}).create_node() - node_name = node.name + '/WithoutBiases' - bias_node_name = node.name - rename_nodes([(node, node_name), (bias_node, bias_node_name)]) - node.out_port(0).get_connection().set_source(bias_node.out_port(0)) - node.in_port(2).get_connection().set_destination(bias_node.in_port(1)) - node.out_port(0).connect(bias_node.in_port(0)) - - if node.has_valid('alpha') and not math.isclose(node.alpha, 1): - bias_node.insert_op_on_input_port(in_port_idx=0, new_op_class=Mul, value=np.array(node.alpha), - new_op_attrs={'name': name + '/Alpha_', 'can_be_scaleshift': False}) - del node['alpha'] - - if node.has_valid('beta') and not math.isclose(node.beta, 1): - bias_node.insert_op_on_input_port(in_port_idx=1, new_op_class=Mul, value=np.array(node.beta), - new_op_attrs={'name': name + '/Beta_', 'can_be_scaleshift': False}) - del node['beta'] - - MatMul.update_node_stat(node, { - 'transpose_a': node.has_and_set('transpose_a'), - 'transpose_b': node.has_and_set('transpose_b'), - }) + def find_and_replace_pattern(self, graph: Graph): + for node in graph.get_op_nodes(op='Gemm'): + name = node.soft_get('name', node.id) + node_output_port = node.out_port(0) + if node.has_valid('alpha') and not math.isclose(node.alpha, 1): + mul_alpha = create_op_with_const_inputs(graph, Mul, {1: np.array(node.alpha)}, + {'name': name + '/Alpha', 'can_be_scaleshift': False}) + node_output_port.get_connection().insert_node(mul_alpha) + node_output_port = mul_alpha.out_port(0) + del node['alpha'] + + if node.is_in_port_connected(2): + # biases normalization + bias_node = Add(graph, {'name': name + '/Bias_', 'can_be_scaleshift': False}).create_node() + without_biases_node_name = name + '/WithoutBiases' + rename_nodes([(node, without_biases_node_name), (bias_node, name)]) + node_output_port.get_connection().set_source(bias_node.out_port(0)) + node.in_port(2).get_connection().set_destination(bias_node.in_port(1)) + node_output_port.connect(bias_node.in_port(0)) + if node.has_valid('beta') and not math.isclose(node.beta, 1): + bias_node.insert_op_on_input_port(in_port_idx=1, new_op_class=Mul, value=np.array(node.beta), + new_op_attrs={'name': name + '/Beta', + 'can_be_scaleshift': False}) + del node['beta'] + + MatMul.update_node_stat(node, { + 'transpose_a': node.has_and_set('transpose_a'), + 'transpose_b': node.has_and_set('transpose_b'), + }) diff --git a/tests/layer_tests/onnx_tests/test_gemm.py b/tests/layer_tests/onnx_tests/test_gemm.py index 83bbe411c04959..2aa78eca591b48 100644 --- a/tests/layer_tests/onnx_tests/test_gemm.py +++ b/tests/layer_tests/onnx_tests/test_gemm.py @@ -16,7 +16,7 @@ def _prepare_input(self, inputs_dict): inputs_dict[input] = np.random.randn(*inputs_dict[input]).astype(np.float32) return inputs_dict - def create_net(self, shapeA, shapeB, shapeC, alpha, beta, trans_a, trans_b, precision, ir_version): + def create_net(self, shapeA, shapeB, shapeC, alpha, beta, trans_a, trans_b, precision, opset, ir_version,): """ ONNX net IR net @@ -46,6 +46,7 @@ def create_net(self, shapeA, shapeB, shapeC, alpha, beta, trans_a, trans_b, prec const1 = np.random.ranf(_shapeB).astype(np.float) const2 = np.random.ranf(shapeC).astype(np.float) + nodes = list() node_const1_def = onnx.helper.make_node( 'Constant', inputs=[], @@ -57,18 +58,24 @@ def create_net(self, shapeA, shapeB, shapeC, alpha, beta, trans_a, trans_b, prec vals=const1.flatten(), ), ) - - node_const2_def = onnx.helper.make_node( - 'Constant', - inputs=[], - outputs=['const2'], - value=helper.make_tensor( - name='const_tensor', - data_type=TensorProto.FLOAT, - dims=const2.shape, - vals=const2.flatten(), - ), - ) + nodes.append(node_const1_def) + + inputs = ['input', 'const1'] + + if opset is None or opset < 11: + node_const2_def = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['const2'], + value=helper.make_tensor( + name='const_tensor', + data_type=TensorProto.FLOAT, + dims=const2.shape, + vals=const2.flatten(), + ), + ) + inputs.append('const2') + nodes.append(node_const2_def) attrs = dict() if alpha: @@ -81,21 +88,25 @@ def create_net(self, shapeA, shapeB, shapeC, alpha, beta, trans_a, trans_b, prec attrs['transB'] = trans_b node_def = onnx.helper.make_node( 'Gemm', - inputs=['input', 'const1', 'const2'], + inputs=inputs, outputs=['output'], **attrs ) + nodes.append(node_def) # Create the graph (GraphProto) graph_def = helper.make_graph( - [node_const1_def, node_const2_def, node_def], + nodes, 'test_model', [input], [output], ) # Create the model (ModelProto) - onnx_net = helper.make_model(graph_def, producer_name='test_model') + args = dict(producer_name='test_model') + if opset: + args['opset_imports'] = [helper.make_opsetid("", opset)] + onnx_net = helper.make_model(graph_def, **args) # # Create reference IR net @@ -209,11 +220,12 @@ def create_net_double(self, shapeA, shapeB, shapeC, alpha, beta, trans_a, trans_ @pytest.mark.parametrize("beta", [None, 0.1, 2.0]) @pytest.mark.parametrize("trans_a", [None]) @pytest.mark.parametrize("trans_b", [None, 1]) + @pytest.mark.parametrize("opset", [None, 11]) @pytest.mark.nightly @pytest.mark.precommit - def test_gemm(self, params, alpha, beta, trans_a, trans_b, ie_device, precision, ir_version, temp_dir): + def test_gemm(self, params, alpha, beta, trans_a, trans_b, ie_device, precision, opset, ir_version, temp_dir): self._test(*self.create_net(params['shapeA'], params['shapeB'], params['shapeC'], alpha, beta, trans_a, - trans_b, precision, ir_version), ie_device, precision, ir_version, + trans_b, precision, opset, ir_version), ie_device, precision, ir_version, temp_dir=temp_dir) @pytest.mark.parametrize("params", test_data_bc) @@ -221,11 +233,12 @@ def test_gemm(self, params, alpha, beta, trans_a, trans_b, ie_device, precision, @pytest.mark.parametrize("beta", [None, 0.1, 2.0]) @pytest.mark.parametrize("trans_a", [None]) # transA is not supported @pytest.mark.parametrize("trans_b", [None, 1]) + @pytest.mark.parametrize("opset", [None, 11]) @pytest.mark.nightly @pytest.mark.precommit - def test_gemm_bc(self, params, alpha, beta, trans_a, trans_b, ie_device, precision, ir_version, temp_dir): + def test_gemm_bc(self, params, alpha, beta, trans_a, trans_b, ie_device, precision, opset, ir_version, temp_dir): self._test(*self.create_net(params['shapeA'], params['shapeB'], params['shapeC'], alpha, beta, trans_a, - trans_b, precision, ir_version), ie_device, precision, ir_version, + trans_b, precision, opset, ir_version), ie_device, precision, ir_version, temp_dir=temp_dir) @pytest.mark.parametrize("params", test_data) From a2b03e2bcf7740e7b69ffffb7c5b64726e116dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Karzy=C5=84ski?= Date: Tue, 24 Aug 2021 16:36:30 +0200 Subject: [PATCH 072/102] Add support for ONNX RandomUniform and RandomUniformLike ops (#7190) --- .../onnx/frontend/src/op/random_uniform.cpp | 50 ++++++++++++++++ .../onnx/frontend/src/op/random_uniform.hpp | 20 +++++++ .../frontend/src/op/random_uniform_like.cpp | 56 +++++++++++++++++ .../frontend/src/op/random_uniform_like.hpp | 20 +++++++ .../frontend/onnx/frontend/src/ops_bridge.cpp | 4 ++ .../test/models/onnx/random_uniform.prototxt | 49 +++++++++++++++ .../models/onnx/random_uniform_like.prototxt | 60 +++++++++++++++++++ ngraph/test/onnx/onnx_import.in.cpp | 24 ++++++++ ngraph/test/runtime/ie/unit_test.manifest | 4 ++ .../runtime/interpreter/unit_test.manifest | 4 ++ 10 files changed, 291 insertions(+) create mode 100644 ngraph/frontend/onnx/frontend/src/op/random_uniform.cpp create mode 100644 ngraph/frontend/onnx/frontend/src/op/random_uniform.hpp create mode 100644 ngraph/frontend/onnx/frontend/src/op/random_uniform_like.cpp create mode 100644 ngraph/frontend/onnx/frontend/src/op/random_uniform_like.hpp create mode 100644 ngraph/test/models/onnx/random_uniform.prototxt create mode 100644 ngraph/test/models/onnx/random_uniform_like.prototxt diff --git a/ngraph/frontend/onnx/frontend/src/op/random_uniform.cpp b/ngraph/frontend/onnx/frontend/src/op/random_uniform.cpp new file mode 100644 index 00000000000000..cf01a8edef8677 --- /dev/null +++ b/ngraph/frontend/onnx/frontend/src/op/random_uniform.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "op/random_uniform.hpp" + +#include "default_opset.hpp" +#include "exceptions.hpp" +#include "ngraph/op/constant.hpp" +#include "ngraph/opsets/opset8.hpp" +#include "ngraph/shape.hpp" +#include "utils/common.hpp" + +namespace ngraph { +namespace onnx_import { +namespace op { +namespace set_1 { + +OutputVector random_uniform(const Node& node) { + CHECK_VALID_NODE(node, node.has_attribute("shape"), "RandomUniform operator must specify a 'shape' attribute."); + + const auto dtype = + node.get_attribute_value("dtype", static_cast(ONNX_NAMESPACE::TensorProto_DataType_FLOAT)); + const auto high = node.get_attribute_value("high", 1.0f); + const auto low = node.get_attribute_value("low", 0.0f); + const auto seed = node.get_attribute_value("seed", 0); + const auto shape = node.get_attribute_value>("shape"); + + const auto target_shape_const = default_opset::Constant::create(ngraph::element::i64, Shape{shape.size()}, shape); + const auto high_const = default_opset::Constant::create(ngraph::element::f32, Shape{1}, {high}); + const auto low_const = default_opset::Constant::create(ngraph::element::f32, Shape{1}, {low}); + + const auto target_type = common::get_ngraph_element_type(dtype); + const uint64_t global_seed = 0; + + return {std::make_shared(target_shape_const, + low_const, + high_const, + target_type, + global_seed, + seed)}; +} + +} // namespace set_1 + +} // namespace op + +} // namespace onnx_import + +} // namespace ngraph diff --git a/ngraph/frontend/onnx/frontend/src/op/random_uniform.hpp b/ngraph/frontend/onnx/frontend/src/op/random_uniform.hpp new file mode 100644 index 00000000000000..e0015bba92e2bf --- /dev/null +++ b/ngraph/frontend/onnx/frontend/src/op/random_uniform.hpp @@ -0,0 +1,20 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "ngraph/node.hpp" +#include "onnx_import/core/node.hpp" + +namespace ngraph { +namespace onnx_import { +namespace op { +namespace set_1 { + +OutputVector random_uniform(const Node& node); + +} // namespace set_1 +} // namespace op +} // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx/frontend/src/op/random_uniform_like.cpp b/ngraph/frontend/onnx/frontend/src/op/random_uniform_like.cpp new file mode 100644 index 00000000000000..0ca673622478b4 --- /dev/null +++ b/ngraph/frontend/onnx/frontend/src/op/random_uniform_like.cpp @@ -0,0 +1,56 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "op/random_uniform_like.hpp" + +#include "default_opset.hpp" +#include "exceptions.hpp" +#include "ngraph/op/constant.hpp" +#include "ngraph/opsets/opset8.hpp" +#include "ngraph/shape.hpp" +#include "utils/common.hpp" + +namespace ngraph { +namespace onnx_import { +namespace op { +namespace set_1 { + +OutputVector random_uniform_like(const Node& node) { + OutputVector inputs{node.get_ng_inputs()}; + auto input = inputs.at(0); + + ngraph::element::Type target_type; + if (node.has_attribute("dtype")) { + const auto dtype = node.get_attribute_value("dtype"); + target_type = common::get_ngraph_element_type(dtype); + } else { + target_type = input.get_element_type(); + } + + const auto target_shape = std::make_shared(input); + + const auto high = node.get_attribute_value("high", 1.0f); + const auto low = node.get_attribute_value("low", 0.0f); + const auto seed = node.get_attribute_value("seed", 0); + + const auto high_const = default_opset::Constant::create(ngraph::element::f32, Shape{1}, {high}); + const auto low_const = default_opset::Constant::create(ngraph::element::f32, Shape{1}, {low}); + + const uint64_t global_seed = 0; + + return {std::make_shared(target_shape, + low_const, + high_const, + target_type, + global_seed, + seed)}; +} + +} // namespace set_1 + +} // namespace op + +} // namespace onnx_import + +} // namespace ngraph diff --git a/ngraph/frontend/onnx/frontend/src/op/random_uniform_like.hpp b/ngraph/frontend/onnx/frontend/src/op/random_uniform_like.hpp new file mode 100644 index 00000000000000..759ae3c26141c7 --- /dev/null +++ b/ngraph/frontend/onnx/frontend/src/op/random_uniform_like.hpp @@ -0,0 +1,20 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "ngraph/node.hpp" +#include "onnx_import/core/node.hpp" + +namespace ngraph { +namespace onnx_import { +namespace op { +namespace set_1 { + +OutputVector random_uniform_like(const Node& node); + +} // namespace set_1 +} // namespace op +} // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp b/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp index bab0825909c8c0..6d5fd9b3467e43 100644 --- a/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp @@ -106,6 +106,8 @@ #include "op/org.openvinotoolkit/prior_box.hpp" #include "op/org.openvinotoolkit/swish.hpp" #include "op/quantize_linear.hpp" +#include "op/random_uniform.hpp" +#include "op/random_uniform_like.hpp" #include "op/range.hpp" #include "op/reciprocal.hpp" #include "op/reduce.hpp" @@ -366,6 +368,8 @@ OperatorsBridge::OperatorsBridge() { REGISTER_OPERATOR("QuantizeLinear", 1, quantize_linear); REGISTER_OPERATOR("QuantizeLinear", 13, quantize_linear); REGISTER_OPERATOR("Range", 1, range); + REGISTER_OPERATOR("RandomUniform", 1, random_uniform); + REGISTER_OPERATOR("RandomUniformLike", 1, random_uniform_like); REGISTER_OPERATOR("Reciprocal", 1, reciprocal); REGISTER_OPERATOR("ReduceLogSum", 1, reduce_log_sum); REGISTER_OPERATOR("ReduceLogSumExp", 1, reduce_log_sum_exp); diff --git a/ngraph/test/models/onnx/random_uniform.prototxt b/ngraph/test/models/onnx/random_uniform.prototxt new file mode 100644 index 00000000000000..00b7d8ee3a5ae9 --- /dev/null +++ b/ngraph/test/models/onnx/random_uniform.prototxt @@ -0,0 +1,49 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + output: "y" + op_type: "RandomUniform" + attribute { + name: "shape" + ints: 2 + ints: 2 + type: INTS + } + attribute { + name: "high" + f: 50 + type: FLOAT + } + attribute { + name: "low" + f: 40 + type: FLOAT + } + attribute { + name: "seed" + i: 100 + type: INT + } + } + name: "test_model" + output { + name: "y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/models/onnx/random_uniform_like.prototxt b/ngraph/test/models/onnx/random_uniform_like.prototxt new file mode 100644 index 00000000000000..c90a94c7eca2fc --- /dev/null +++ b/ngraph/test/models/onnx/random_uniform_like.prototxt @@ -0,0 +1,60 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + input: "x" + output: "y" + op_type: "RandomUniformLike" + attribute { + name: "high" + f: 50 + type: FLOAT + } + attribute { + name: "low" + f: 40 + type: FLOAT + } + attribute { + name: "seed" + i: 100 + type: INT + } + } + name: "test_model" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index e1cdd310cc03fa..ae74c4cbe6deb6 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -4022,3 +4022,27 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_float16_tensor_as_int32) { // clang-format on test_case.run(); } + +NGRAPH_TEST(${BACKEND_NAME}, onnx_model_random_uniform) { + const auto function = + onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/random_uniform.onnx")); + + auto test_case = test::TestCase(function); + // These output values are unknown at this time as we don't have a reference implementation of random number + // generator + test_case.add_expected_output(Shape{2, 2}, {41, 42, 43, 44}); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_model_random_uniform_like) { + const auto function = + onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/random_uniform_like.onnx")); + + auto test_case = test::TestCase(function); + test_case.add_expected_output(Shape{2, 2}, {0, 0, 0, 0}); + + // These output values are unknown at this time as we don't have a reference implementation of random number + // generator + test_case.add_input(Shape{2, 2}, {41, 42, 43, 44}); + test_case.run(); +} diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 625da7075517a0..88ba3166cb6303 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -41,6 +41,10 @@ onnx_model_matmul_integer_4d_no_zero_point onnx_model_qlinear_matmul onnx_model_qlinear_matmul_3d +# No support yet for RandomUniform +onnx_model_random_uniform +onnx_model_random_uniform_like + # Result mismatch onnx_model_shape onnx_model_split_equal_parts_default diff --git a/ngraph/test/runtime/interpreter/unit_test.manifest b/ngraph/test/runtime/interpreter/unit_test.manifest index 97183b4f61b758..8ce07a2dcea8f6 100644 --- a/ngraph/test/runtime/interpreter/unit_test.manifest +++ b/ngraph/test/runtime/interpreter/unit_test.manifest @@ -153,3 +153,7 @@ onnx_model_deformable_conv_2d # No support for unsigned types INTERPRETER.zero_sized_negative + +# No support yet for RandomUniform +INTERPRETER.onnx_model_random_uniform +INTERPRETER.onnx_model_random_uniform_like \ No newline at end of file From 58c58eb99faca23ec6255398d92c464967d71b45 Mon Sep 17 00:00:00 2001 From: "mei, yang" Date: Wed, 25 Aug 2021 11:39:59 +0800 Subject: [PATCH 073/102] remove adaptive pool2d shape check in ngraph paddle frontend (#7074) * remove adaptive pool2d shape check in ngraph paddle frontend * add ngraph paddle frontend dynamic pool2d test --- .../frontend/paddlepaddle/src/op/pool2d.cpp | 4 +-- .../frontend/paddlepaddle/convert_model.cpp | 1 + .../gen_scripts/generate_dynamic_pool2d.py | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 ngraph/test/frontend/paddlepaddle/test_models/gen_scripts/generate_dynamic_pool2d.py diff --git a/ngraph/frontend/paddlepaddle/src/op/pool2d.cpp b/ngraph/frontend/paddlepaddle/src/op/pool2d.cpp index dcd068434d517f..a2c22983f016a5 100644 --- a/ngraph/frontend/paddlepaddle/src/op/pool2d.cpp +++ b/ngraph/frontend/paddlepaddle/src/op/pool2d.cpp @@ -100,8 +100,6 @@ NamedOutputs pool2d(const NodeContext& node) { {"Out"}); } } else if (adaptive) { - PDPD_ASSERT(input_shape[2].is_static() && input_shape[3].is_static(), - "pool2d: spatial dim must be static when using adaptive pool"); auto pool_size = std::vector(2, 0); if (kernel_shape.size() == 1) { @@ -187,4 +185,4 @@ NamedOutputs pool2d(const NodeContext& node) { } // namespace op } // namespace pdpd } // namespace frontend -} // namespace ngraph \ No newline at end of file +} // namespace ngraph diff --git a/ngraph/test/frontend/paddlepaddle/convert_model.cpp b/ngraph/test/frontend/paddlepaddle/convert_model.cpp index b7b207b755f91e..d3a68116e39e37 100644 --- a/ngraph/test/frontend/paddlepaddle/convert_model.cpp +++ b/ngraph/test/frontend/paddlepaddle/convert_model.cpp @@ -18,6 +18,7 @@ static const std::vector models{ std::string("2in_2out/2in_2out.pdmodel"), std::string("multi_tensor_split/multi_tensor_split.pdmodel"), std::string("2in_2out_dynbatch/2in_2out_dynbatch.pdmodel"), + std::string("pool2d_dyn_hw/pool2d_dyn_hw.pdmodel"), }; INSTANTIATE_TEST_SUITE_P(PDPDConvertModelTest, diff --git a/ngraph/test/frontend/paddlepaddle/test_models/gen_scripts/generate_dynamic_pool2d.py b/ngraph/test/frontend/paddlepaddle/test_models/gen_scripts/generate_dynamic_pool2d.py new file mode 100644 index 00000000000000..7a10194599bb3e --- /dev/null +++ b/ngraph/test/frontend/paddlepaddle/test_models/gen_scripts/generate_dynamic_pool2d.py @@ -0,0 +1,32 @@ +# +# pool2d paddle dynamic model generator +# + +import paddle +from paddle import fluid +import numpy as np +import sys +import os +from save_model import saveModel + +paddle.enable_static() +inp_blob1 = np.random.randn(1, 1, 224, 224).astype(np.float32) + +x1 = fluid.data(name='inputX1', shape=[1, 1, -1, -1], dtype='float32') + +adative_pool2d = paddle.fluid.layers.adaptive_pool2d( + input=x1, + pool_size=[3,3], + pool_type='avg', + require_index=False) + +cpu = paddle.static.cpu_places(1) +exe = paddle.static.Executor(cpu[0]) +# startup program will call initializer to initialize the parameters. +exe.run(paddle.static.default_startup_program()) + +outs = exe.run( + feed={'inputX1': inp_blob1}, + fetch_list=[adative_pool2d]) + +saveModel("pool2d_dyn_hw", exe, feedkeys=['inputX1'], fetchlist=adative_pool2d, inputs=[inp_blob1], outputs=outs, target_dir=sys.argv[1]) From a1f1a831673afdb41b855b43791dec621007c963 Mon Sep 17 00:00:00 2001 From: Gabriele Galiero Casay Date: Wed, 25 Aug 2021 06:09:41 +0200 Subject: [PATCH 074/102] Revise ReverseSequence reference implementation (#7117) * ReverseSequence ngraph op shell revision with type_prop tests * Add attribute count check in visitor test * Refactor backend tests to template plugin test with reference values * Rename cpu SLT instances * Add op to list of trusted operations * Rewrite validation check for input type due to backward compatibility * Reference implementation speed up by replacing index function call of CoordinateTransform by precalculated strides --- .../op_reference/reverse_sequence.cpp | 153 +++++++++ .../single_layer_tests/reverse_sequence.cpp | 2 +- .../layer_tests_summary/utils/constants.py | 1 + .../include/ngraph/op/reverse_sequence.hpp | 5 +- .../runtime/reference/reverse_sequence.hpp | 16 +- ngraph/core/src/op/reverse_sequence.cpp | 54 +-- ngraph/test/CMakeLists.txt | 1 - ngraph/test/backend/reverse_sequence.in.cpp | 179 ---------- ngraph/test/type_prop/reverse_sequence.cpp | 325 +++++++++++------- ngraph/test/visitors/op/reverse_sequence.cpp | 4 + 10 files changed, 403 insertions(+), 337 deletions(-) create mode 100644 docs/template_plugin/tests/functional/op_reference/reverse_sequence.cpp delete mode 100644 ngraph/test/backend/reverse_sequence.in.cpp diff --git a/docs/template_plugin/tests/functional/op_reference/reverse_sequence.cpp b/docs/template_plugin/tests/functional/op_reference/reverse_sequence.cpp new file mode 100644 index 00000000000000..26e2289a5287bf --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/reverse_sequence.cpp @@ -0,0 +1,153 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include +#include +#include +#include + +#include "base_reference_test.hpp" + +using namespace reference_tests; +using namespace ngraph; +using namespace InferenceEngine; + +namespace { +struct ReverseSequenceParams { + ReverseSequenceParams(const int64_t batchAxis, const int64_t seqAxis, const Tensor& dataTensor, const Tensor& seqLengthsTensor, + const Tensor& expectedTensor) : mBatchAxis(batchAxis), mSeqAxis(seqAxis), mDataTensor(dataTensor), + mSeqLengthsTensor(seqLengthsTensor), mExpectedTensor(expectedTensor) {} +int64_t mBatchAxis; +int64_t mSeqAxis; +Tensor mDataTensor; +Tensor mSeqLengthsTensor; +Tensor mExpectedTensor; +}; +class ReferenceReverseSequenceTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params); + inputData = {params.mDataTensor.data, params.mSeqLengthsTensor.data}; + refOutData = {params.mExpectedTensor.data}; + } + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "dataType=" << param.mDataTensor.type << "_"; + result << "dataShape=" << param.mDataTensor.shape << "_"; + result << "seqLenType=" << param.mSeqLengthsTensor.type << "_"; + result << "seqLenShape=" << param.mSeqLengthsTensor.shape << "_"; + result << "batchAxis=" << param.mBatchAxis << "_"; + result << "seqAxis=" << param.mSeqAxis; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const ReverseSequenceParams& params) { + const auto data = std::make_shared(params.mDataTensor.type, params.mDataTensor.shape); + const auto seqLengths = std::make_shared(params.mSeqLengthsTensor.type, params.mSeqLengthsTensor.shape); + const auto reverseSequence = std::make_shared(data, seqLengths, params.mBatchAxis, params.mSeqAxis); + return std::make_shared(NodeVector {reverseSequence}, ParameterVector {data, seqLengths}); + } +}; + +TEST_P(ReferenceReverseSequenceTest, CompareWithRefs) { + Exec(); +} + +template +std::vector generateReverseSeqParams() { + using T = typename element_type_traits::value_type; + std::vector reverseSeqParams { + // 2D + ReverseSequenceParams(1, 0, + Tensor({4, 4}, IN_ET, std::vector{0, 4, 8, 12, + 1, 5, 9, 13, + 2, 6, 10, 14, + 3, 7, 11, 15}), + Tensor({4}, element::i32, std::vector{4, 3, 2, 1}), + Tensor({4, 4}, IN_ET, std::vector{3, 6, 9, 12, + 2, 5, 8, 13, + 1, 4, 10, 14, + 0, 7, 11, 15})), + ReverseSequenceParams(0, 1, + Tensor({4, 4}, IN_ET, std::vector{0, 1, 2, 3, + 4, 5, 6, 7, + 8, 9, 10, 11, + 12, 13, 14, 15}), + Tensor({4}, element::i32, std::vector{1, 2, 3, 4}), + Tensor({4, 4}, IN_ET, std::vector{0, 1, 2, 3, + 5, 4, 6, 7, + 10, 9, 8, 11, + 15, 14, 13, 12})), + // 4D + ReverseSequenceParams(2, 1, + Tensor({2, 3, 4, 2}, IN_ET, std::vector{ + 0, 0, 3, 0, 6, 0, 9, 0, 1, 0, 4, 0, 7, 0, 10, 0, 2, 0, 5, 0, 8, 0, 11, 0, + 12, 0, 15, 0, 18, 0, 21, 0, 13, 0, 16, 0, 19, 0, 22, 0, 14, 0, 17, 0, 20, 0, 23, 0}), + Tensor({4}, element::i32, std::vector{1, 2, 1, 2}), + Tensor({2, 3, 4, 2}, IN_ET, std::vector{ + 0, 0, 4, 0, 6, 0, 10, 0, 1, 0, 3, 0, 7, 0, 9, 0, 2, 0, 5, 0, 8, 0, 11, 0, + 12, 0, 16, 0, 18, 0, 22, 0, 13, 0, 15, 0, 19, 0, 21, 0, 14, 0, 17, 0, 20, 0, 23, 0})), + ReverseSequenceParams(-2, -3, + Tensor({2, 3, 4, 2}, IN_ET, std::vector{ + 0, 0, 3, 0, 6, 0, 9, 0, 1, 0, 4, 0, 7, 0, 10, 0, 2, 0, 5, 0, 8, 0, 11, 0, + 12, 0, 15, 0, 18, 0, 21, 0, 13, 0, 16, 0, 19, 0, 22, 0, 14, 0, 17, 0, 20, 0, 23, 0}), + Tensor({4}, element::i32, std::vector{1, 2, 1, 2}), + Tensor({2, 3, 4, 2}, IN_ET, std::vector{ + 0, 0, 4, 0, 6, 0, 10, 0, 1, 0, 3, 0, 7, 0, 9, 0, 2, 0, 5, 0, 8, 0, 11, 0, + 12, 0, 16, 0, 18, 0, 22, 0, 13, 0, 15, 0, 19, 0, 21, 0, 14, 0, 17, 0, 20, 0, 23, 0})), + ReverseSequenceParams(0, 1, + Tensor({4, 3, 2, 2}, IN_ET, std::vector{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}), + Tensor({4}, element::i32, std::vector{1, 2, 3, 3}), + Tensor({4, 3, 2, 2}, IN_ET, std::vector{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, + 12, 13, 14, 15, 20, 21, 22, 23, 32, 33, 34, 35, 28, 29, 30, 31, + 24, 25, 26, 27, 44, 45, 46, 47, 40, 41, 42, 43, 36, 37, 38, 39})), + // 5D + ReverseSequenceParams(0, 2, + Tensor({4, 2, 3, 2, 2}, IN_ET, std::vector{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95}), + Tensor({4}, element::i32, std::vector{1, 2, 1, 2}), + Tensor({4, 3, 2, 2}, IN_ET, std::vector{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 28, 29, 30, 31, 24, 25, 26, 27, 32, 33, 34, 35, 40, 41, 42, 43, + 36, 37, 38, 39, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 76, 77, 78, 79, 72, 73, 74, 75, + 80, 81, 82, 83, 88, 89, 90, 91, 84, 85, 86, 87, 92, 93, 94, 95})) + }; + return reverseSeqParams; +} + +std::vector generateReverseSeqCombinedParams() { + const std::vector> reverseSeqTypeParams { + generateReverseSeqParams(), + generateReverseSeqParams(), + generateReverseSeqParams(), + generateReverseSeqParams(), + generateReverseSeqParams(), + generateReverseSeqParams()}; + std::vector combinedParams; + + for (const auto& params : reverseSeqTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P(smoke_ReverseSequence_With_Hardcoded_Refs, ReferenceReverseSequenceTest, + testing::ValuesIn(generateReverseSeqCombinedParams()), ReferenceReverseSequenceTest::getTestCaseName); +} // namespace \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/reverse_sequence.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/reverse_sequence.cpp index b1f864d12ae14f..b95660e3349b95 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/reverse_sequence.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/reverse_sequence.cpp @@ -33,7 +33,7 @@ const std::vector secondaryInputTypes = { ngraph::helpers::InputLayerType::PARAMETER }; -INSTANTIATE_TEST_SUITE_P(Basic_smoke, ReverseSequenceLayerTest, +INSTANTIATE_TEST_SUITE_P(smoke_ReverseSequence, ReverseSequenceLayerTest, ::testing::Combine( ::testing::ValuesIn(batchAxisIndices), ::testing::ValuesIn(seqAxisIndices), diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py index e3693da7e53f6a..515e768ecb3958 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py @@ -100,6 +100,7 @@ 'Relu-1', 'ReorgYOLO-2', 'Result-1' + 'ReverseSequence-1', 'Round-5', 'SpaceToDepth-1', 'ScatterNDUpdate-4', diff --git a/ngraph/core/include/ngraph/op/reverse_sequence.hpp b/ngraph/core/include/ngraph/op/reverse_sequence.hpp index 5c8b37f41ade3c..836c89e11ea98b 100644 --- a/ngraph/core/include/ngraph/op/reverse_sequence.hpp +++ b/ngraph/core/include/ngraph/op/reverse_sequence.hpp @@ -21,7 +21,10 @@ class NGRAPH_API ReverseSequence : public Op { /// tensor. /// \param batch_axis index of the batch dimension. /// \param seq_axis index of the sequence dimension. - ReverseSequence(const Output& arg, const Output& seq_lengths, int64_t batch_axis, int64_t seq_axis); + ReverseSequence(const Output& arg, + const Output& seq_lengths, + int64_t batch_axis = 0, + int64_t seq_axis = 1); bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/reverse_sequence.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/reverse_sequence.hpp index b84fe400120f26..e9762132283d22 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/reverse_sequence.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/reverse_sequence.hpp @@ -20,16 +20,14 @@ void reverse_sequence(const T* arg, size_t batch_axis, size_t sequence_axis, const U* sequence_lengths) { - NGRAPH_SUPPRESS_DEPRECATED_START - CoordinateTransform input_transform(arg_shape); + const auto strides = row_major_strides(arg_shape); + CoordinateTransformBasic input_transform(arg_shape); for (const Coordinate& in_coord : input_transform) { size_t batch_index = in_coord[batch_axis]; auto orig_seq_index = static_cast(sequence_lengths[batch_index]); - if (orig_seq_index > arg_shape.at(sequence_axis)) { - throw ngraph_error("One of the elements of sequence lengths is greater than sequence axis " - "dimension"); - } + NGRAPH_CHECK(orig_seq_index <= arg_shape.at(sequence_axis), + "One of the elements of sequence lengths is greater than sequence axis dimension"); if (orig_seq_index == 0) { orig_seq_index = 1; @@ -41,9 +39,11 @@ void reverse_sequence(const T* arg, // make a copy of in_coord and update sequence_index Coordinate out_coord = in_coord; out_coord[sequence_axis] = sequence_index; - out[input_transform.index(out_coord)] = arg[input_transform.index(in_coord)]; + + const size_t in_idx = std::inner_product(in_coord.begin(), in_coord.end(), strides.begin(), 0); + const size_t out_idx = std::inner_product(out_coord.begin(), out_coord.end(), strides.begin(), 0); + out[out_idx] = arg[in_idx]; } - NGRAPH_SUPPRESS_DEPRECATED_END } } // namespace reference } // namespace runtime diff --git a/ngraph/core/src/op/reverse_sequence.cpp b/ngraph/core/src/op/reverse_sequence.cpp index 711180e7db0a22..1eda1f50b1c8c4 100644 --- a/ngraph/core/src/op/reverse_sequence.cpp +++ b/ngraph/core/src/op/reverse_sequence.cpp @@ -38,43 +38,49 @@ bool ngraph::op::v0::ReverseSequence::visit_attributes(AttributeVisitor& visitor void op::ReverseSequence::validate_and_infer_types() { NGRAPH_OP_SCOPE(v0_ReverseSequence_validate_and_infer_types); - auto input_shape = get_input_partial_shape(0); - auto input_rank = input_shape.rank(); + const auto& data_pshape = get_input_partial_shape(0); + const auto& data_rank = data_pshape.rank(); - m_normalized_batch_axis = ngraph::normalize_axis(this, m_batch_axis, input_rank); - m_normalized_seq_axis = ngraph::normalize_axis(this, m_seq_axis, input_rank); + NODE_VALIDATION_CHECK(this, + data_rank.is_dynamic() || data_rank.get_length() >= 2, + "Data input rank should be equal or greater than 2. Got: ", + data_pshape); + + m_normalized_batch_axis = ngraph::normalize_axis(this, m_batch_axis, data_rank); + m_normalized_seq_axis = ngraph::normalize_axis(this, m_seq_axis, data_rank); - auto indices_shape = get_input_partial_shape(1); - auto indices_rank = indices_shape.rank(); + const auto& seq_lengths_et = get_input_element_type(1); + const auto& seq_lengths_pshape = get_input_partial_shape(1); + const auto& seq_lengths_rank = seq_lengths_pshape.rank(); NODE_VALIDATION_CHECK(this, - indices_rank.is_dynamic() || indices_rank.get_length() == 1, - "Sequence indices must be a 1-dimensional tensor (sequence indices shape: ", - indices_shape, - ")."); + seq_lengths_et.is_real() || seq_lengths_et.is_integral_number(), + "Sequence lengths element type must be numeric type. Got: ", + seq_lengths_et); - PartialShape output_shape{input_shape}; + NODE_VALIDATION_CHECK(this, + seq_lengths_rank.compatible(1), + "Sequence lengths rank must be equal to 1. Got: ", + seq_lengths_pshape); - if (input_rank.is_static() && indices_rank.is_static()) { + PartialShape output_pshape{data_pshape}; + if (data_rank.is_static() && seq_lengths_rank.is_static()) { Dimension merged_sequence_length; - NODE_VALIDATION_CHECK( this, - Dimension::merge(merged_sequence_length, input_shape[m_normalized_batch_axis], indices_shape[0]), - "Sequence length (", - indices_shape[0], - ") is not equal to batch axis ", - "dimension (", - input_shape[m_normalized_batch_axis], + Dimension::merge(merged_sequence_length, data_pshape[m_normalized_batch_axis], seq_lengths_pshape[0]), + "Sequence lengths input size (", + seq_lengths_pshape[0], + ") is not equal to batch axis dimension of data input (", + data_pshape[m_normalized_batch_axis], ") (argument shape: ", - input_shape, + data_pshape, ", sequence indices shape: ", - indices_shape, + seq_lengths_pshape, ")."); - output_shape[m_normalized_batch_axis] = merged_sequence_length; + output_pshape[m_normalized_batch_axis] = merged_sequence_length; } - - set_output_type(0, get_input_element_type(0), output_shape); + set_output_type(0, get_input_element_type(0), output_pshape); } shared_ptr op::ReverseSequence::clone_with_new_inputs(const OutputVector& new_args) const { diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 28017824f22f2e..20fc2a0a184ce5 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -501,7 +501,6 @@ set(MULTI_TEST_SRC backend/reorg_yolo.in.cpp backend/reshape.in.cpp backend/result.in.cpp - backend/reverse_sequence.in.cpp backend/reverse.in.cpp backend/roll.in.cpp backend/round.in.cpp diff --git a/ngraph/test/backend/reverse_sequence.in.cpp b/ngraph/test/backend/reverse_sequence.in.cpp deleted file mode 100644 index 75cf47ff127a5a..00000000000000 --- a/ngraph/test/backend/reverse_sequence.in.cpp +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "runtime/backend.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/known_element_types.hpp" -#include "util/ndarray.hpp" -#include "util/test_control.hpp" -#include "util/test_tools.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; - -NGRAPH_TEST(${BACKEND_NAME}, reverse_sequence_n2c3h4w2) { - Shape shape{2, 3, 4, 2}; - Shape seq_len_shape{4}; - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, seq_len_shape); - - size_t batch_axis = 2; - size_t sequence_axis = 1; - auto rs = std::make_shared(A, B, batch_axis, sequence_axis); - - auto f = make_shared(rs, ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - shared_ptr a = backend->create_tensor(element::i32, shape); - shared_ptr b = backend->create_tensor(element::i32, seq_len_shape); - - shared_ptr result = backend->create_tensor(element::i32, shape); - - std::vector input{ - 0, 0, 3, 0, 6, 0, 9, 0, 1, 0, 4, 0, 7, 0, 10, 0, 2, 0, 5, 0, 8, 0, 11, 0, - 12, 0, 15, 0, 18, 0, 21, 0, 13, 0, 16, 0, 19, 0, 22, 0, 14, 0, 17, 0, 20, 0, 23, 0, - }; - - std::vector seq_lengths{1, 2, 1, 2}; - copy_data(b, seq_lengths); - - std::vector expected{0, 0, 4, 0, 6, 0, 10, 0, 1, 0, 3, 0, 7, 0, 9, 0, 2, 0, 5, 0, 8, 0, 11, 0, - - 12, 0, 16, 0, 18, 0, 22, 0, 13, 0, 15, 0, 19, 0, 21, 0, 14, 0, 17, 0, 20, 0, 23, 0}; - - copy_data(a, input); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(read_vector(result), expected); -} - -NGRAPH_TEST(${BACKEND_NAME}, reverse_sequence_n4c3h2w2) { - Shape shape{4, 3, 2, 2}; - auto A = make_shared(element::i32, shape); - Shape seq_len_shape{4}; - auto B = make_shared(element::i32, seq_len_shape); - - size_t batch_axis = 0; - size_t sequence_axis = 1; - - auto rs = std::make_shared(A, B, batch_axis, sequence_axis); - - auto f = make_shared(rs, ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - shared_ptr a = backend->create_tensor(element::i32, shape); - shared_ptr b = backend->create_tensor(element::i32, seq_len_shape); - - shared_ptr result = backend->create_tensor(element::i32, shape); - - std::vector seq_lengths{1, 2, 3, 3}; - copy_data(b, seq_lengths); - - std::vector input{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; - - std::vector expected{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, - 12, 13, 14, 15, 20, 21, 22, 23, 32, 33, 34, 35, 28, 29, 30, 31, - 24, 25, 26, 27, 44, 45, 46, 47, 40, 41, 42, 43, 36, 37, 38, 39}; - - copy_data(a, input); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(read_vector(result), expected); -} - -NGRAPH_TEST(${BACKEND_NAME}, reverse_sequence_n4d2c3h2w2) { - Shape shape{4, 2, 3, 2, 2}; - auto A = make_shared(element::i32, shape); - Shape seq_len_shape{4}; - auto B = make_shared(element::i32, seq_len_shape); - - size_t batch_axis = 0; - size_t sequence_axis = 2; - - auto rs = std::make_shared(A, B, batch_axis, sequence_axis); - - auto f = make_shared(rs, ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - shared_ptr a = backend->create_tensor(element::i32, shape); - shared_ptr b = backend->create_tensor(element::i32, seq_len_shape); - - shared_ptr result = backend->create_tensor(element::i32, shape); - - std::vector input{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95}; - - std::vector expected{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 28, 29, 30, 31, 24, 25, 26, 27, 32, 33, 34, 35, 40, 41, 42, 43, - 36, 37, 38, 39, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 76, 77, 78, 79, 72, 73, 74, 75, - 80, 81, 82, 83, 88, 89, 90, 91, 84, 85, 86, 87, 92, 93, 94, 95}; - - copy_data(a, input); - - std::vector seq_lengths{1, 2, 1, 2}; - copy_data(b, seq_lengths); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(read_vector(result), expected); -} - -NGRAPH_TEST(${BACKEND_NAME}, reverse_sequence_negative_axes) { - Shape shape{2, 3, 4, 2}; - Shape seq_len_shape{4}; - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, seq_len_shape); - - int64_t batch_axis = -2; - int64_t sequence_axis = -3; - auto rs = std::make_shared(A, B, batch_axis, sequence_axis); - - auto f = make_shared(rs, ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - shared_ptr a = backend->create_tensor(element::i32, shape); - shared_ptr b = backend->create_tensor(element::i32, seq_len_shape); - - shared_ptr result = backend->create_tensor(element::i32, shape); - - std::vector input{ - 0, 0, 3, 0, 6, 0, 9, 0, 1, 0, 4, 0, 7, 0, 10, 0, 2, 0, 5, 0, 8, 0, 11, 0, - 12, 0, 15, 0, 18, 0, 21, 0, 13, 0, 16, 0, 19, 0, 22, 0, 14, 0, 17, 0, 20, 0, 23, 0, - }; - - std::vector seq_lengths{1, 2, 1, 2}; - copy_data(b, seq_lengths); - - std::vector expected{0, 0, 4, 0, 6, 0, 10, 0, 1, 0, 3, 0, 7, 0, 9, 0, 2, 0, 5, 0, 8, 0, 11, 0, - - 12, 0, 16, 0, 18, 0, 22, 0, 13, 0, 15, 0, 19, 0, 21, 0, 14, 0, 17, 0, 20, 0, 23, 0}; - - copy_data(a, input); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(read_vector(result), expected); -} diff --git a/ngraph/test/type_prop/reverse_sequence.cpp b/ngraph/test/type_prop/reverse_sequence.cpp index 6b470d3d0e4afc..9f88013506b69c 100644 --- a/ngraph/test/type_prop/reverse_sequence.cpp +++ b/ngraph/test/type_prop/reverse_sequence.cpp @@ -9,232 +9,311 @@ using namespace std; using namespace ngraph; -TEST(type_prop, reverse_sequence_1_dim) { - auto data = make_shared(element::f32, Shape{4, 3, 2}); - auto seq_lengths = make_shared(element::f32, Shape{4, 4}); +TEST(type_prop, reverse_sequence_default_attributes) { + auto data = make_shared(element::f32, PartialShape{4, 3, 2}); + auto seq_lengths = make_shared(element::i32, PartialShape{4}); + auto reverse_seq = make_shared(data, seq_lengths); + + EXPECT_EQ(reverse_seq->get_batch_axis(), 0); + EXPECT_EQ(reverse_seq->get_sequence_axis(), 1); + EXPECT_EQ(reverse_seq->get_input_size(), 2); + EXPECT_EQ(reverse_seq->get_output_size(), 1); + EXPECT_EQ(reverse_seq->get_output_element_type(0), (element::f32)); + EXPECT_EQ(reverse_seq->get_output_partial_shape(0), (PartialShape{4, 3, 2})); +} + +TEST(type_prop, reverse_sequence_negative_attribute_axes) { + int64_t batch_axis = -3; + int64_t seq_axis = -2; + auto data = make_shared(element::f32, PartialShape{1, 2, 3, 4, 5}); + auto seq_lengths = make_shared(element::i32, PartialShape{3}); + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + + EXPECT_EQ(reverse_seq->get_batch_axis(), 2); + EXPECT_EQ(reverse_seq->get_sequence_axis(), 3); + EXPECT_EQ(reverse_seq->get_input_size(), 2); + EXPECT_EQ(reverse_seq->get_output_size(), 1); + EXPECT_EQ(reverse_seq->get_output_element_type(0), (element::f32)); + EXPECT_EQ(reverse_seq->get_output_partial_shape(0), (PartialShape{1, 2, 3, 4, 5})); +} + +TEST(type_prop, reverse_sequence_data_et) { + std::vector element_types{element::u4, + element::u8, + element::u16, + element::u32, + element::i8, + element::i16, + element::i32, + element::i64, + element::f16, + element::f32, + element::boolean}; + for (auto& et : element_types) { + try { + auto data = std::make_shared(et, PartialShape{4, 4}); + auto seq_lengths = std::make_shared(element::i32, PartialShape{4}); + + EXPECT_NO_THROW(std::make_shared(data, seq_lengths)); + } catch (...) { + FAIL() << "Data input element type validation check failed for unexpected reason"; + } + } +} + +TEST(type_prop, reverse_sequence_invalid_seq_lengths_et) { + int64_t batch_axis = 0; + int64_t seq_axis = 1; + std::vector invalid_et{element::bf16, element::f16, element::f32, element::boolean}; + auto data = make_shared(element::f32, PartialShape{4, 3, 2}); + auto seq_lengths = make_shared(element::boolean, PartialShape{4}); try { - size_t batch_axis = 0; - size_t seq_axis = 1; - auto bc = make_shared(data, seq_lengths, batch_axis, seq_axis); - FAIL() << "ReverseSequence c-tor should throw for seq_lengths whose rank isn't equal to 1"; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + FAIL() << "Invalid element type of seq_lengths input not detected"; } catch (const NodeValidationFailure& error) { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Sequence indices must be a 1-dimensional tensor")); + EXPECT_HAS_SUBSTRING(error.what(), std::string("Sequence lengths element type must be numeric type.")); } catch (...) { - FAIL() << "Deduced type check failed for unexpected reason"; + FAIL() << "Element type validation check of seq_lengths input failed for unexpected reason"; + } +} + +TEST(type_prop, reverse_sequence_invalid_data_rank) { + std::vector invalid_pshapes = {{}, {4}}; + for (auto& pshape : invalid_pshapes) { + try { + auto data = make_shared(element::f32, pshape); + auto seq_lengths = make_shared(element::i32, PartialShape{1}); + auto reverse_seq = make_shared(data, seq_lengths); + FAIL() << "Invalid rank of data input not detected"; + } catch (const NodeValidationFailure& error) { + EXPECT_HAS_SUBSTRING(error.what(), std::string("Data input rank should be equal or greater than 2.")); + } catch (...) { + FAIL() << "Rank check of data input failed for unexpected reason"; + } } } -TEST(type_prop, reverse_sequence_batch_index_oob) { - auto data = make_shared(element::f32, Shape{4, 3, 2}); - auto seq_lengths = make_shared(element::f32, Shape{3}); +TEST(type_prop, reverse_sequence_invalid_seq_lengths_rank) { + std::vector invalid_pshapes = {{}, {4, 1}, {1, 1, 4}}; + int64_t batch_axis = 0; + int64_t seq_axis = 1; + auto data = make_shared(element::f32, PartialShape{4, 3, 2}); + for (auto& pshape : invalid_pshapes) { + try { + auto seq_lengths = make_shared(element::i32, pshape); + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + FAIL() << "Invalid rank of seq_lengths input not detected"; + } catch (const NodeValidationFailure& error) { + EXPECT_HAS_SUBSTRING(error.what(), std::string("Sequence lengths rank must be equal to 1.")); + } catch (...) { + FAIL() << "Rank check of seq_lengths input failed for unexpected reason"; + } + } +} + +TEST(type_prop, reverse_sequence_invalid_batch_axis_value) { + int64_t batch_axis = 3; + int64_t seq_axis = 1; + auto data = make_shared(element::f32, PartialShape{4, 3, 2}); + auto seq_lengths = make_shared(element::i32, PartialShape{3}); try { - size_t batch_axis = 3; - size_t seq_axis = 1; - auto bc = make_shared(data, seq_lengths, batch_axis, seq_axis); - FAIL() << "ReverseSequence c-tor should throw for out-of-bounds batch axis index"; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + FAIL() << "Invalid value of batch_axis attribute not detected"; } catch (const ngraph_error& error) { EXPECT_HAS_SUBSTRING(error.what(), std::string("Parameter axis 3 out of the tensor rank")); } catch (...) { - FAIL() << "Deduced type check failed for unexpected reason"; + FAIL() << "Out of bounds check of batch_axis attribute failed for unexpected reason"; } } -TEST(type_prop, reverse_sequence_sequence_index_oob) { - auto data = make_shared(element::f32, Shape{4, 3, 2}); - auto seq_lengths = make_shared(element::f32, Shape{3}); +TEST(type_prop, reverse_sequence_invalid_seq_axis_value) { + int64_t batch_axis = 1; + int64_t seq_axis = 3; + auto data = make_shared(element::f32, PartialShape{4, 3, 2}); + auto seq_lengths = make_shared(element::i32, PartialShape{3}); try { - size_t batch_axis = 1; - size_t seq_axis = 3; - auto bc = make_shared(data, seq_lengths, batch_axis, seq_axis); - FAIL() << "ReverseSequence c-tor should throw for out-of-bounds sequence axis index"; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + FAIL() << "Invalid value of seq_axis attribute not detected"; } catch (const ngraph_error& error) { EXPECT_HAS_SUBSTRING(error.what(), std::string("Parameter axis 3 out of the tensor rank")); } catch (...) { - FAIL() << "Deduced type check failed for unexpected reason"; + FAIL() << "Out of bounds check of seq_axis attribute failed for unexpected reason"; } } -TEST(type_prop, reverse_sequence_seq_len_size_equal_to_batch_dim) { - auto data = make_shared(element::f32, Shape{4, 3, 2}); - auto seq_lengths = make_shared(element::f32, Shape{3}); +TEST(type_prop, reverse_sequence_incompatible_seq_len_size_with_batch_dim) { + auto data = make_shared(element::f32, PartialShape{4, 3, 2}); + auto seq_lengths = make_shared(element::i32, PartialShape{3}); try { - size_t batch_axis = 0; - size_t seq_axis = 1; - auto bc = make_shared(data, seq_lengths, batch_axis, seq_axis); - FAIL() << "ReverseSequence c-tor should throw when sequence length size isn't equal to " - "batch dimension"; + auto reverse_seq = make_shared(data, seq_lengths); + FAIL() << "Incompatible number of elements between seq_lengths and batch dimension of data input not detected"; } catch (const NodeValidationFailure& error) { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Sequence length (3) is not equal to batch axis dimension (4)")); + EXPECT_HAS_SUBSTRING( + error.what(), + std::string("Sequence lengths input size (3) is not equal to batch axis dimension of data input (4)")); } catch (...) { - FAIL() << "Deduced type check failed for unexpected reason"; + FAIL() << "Number of elements of input seq_lengths check with respect batch dimension of input failed for " + "unexpected reason"; } } -TEST(type_prop, reverse_sequence_partial_both_rank_dynamic) { +TEST(type_prop, reverse_sequence_dynamic_inputs_with_dynamic_rank) { auto data = make_shared(element::f32, PartialShape::dynamic()); - auto seq_lengths = make_shared(element::f32, PartialShape::dynamic()); + auto seq_lengths = make_shared(element::i32, PartialShape::dynamic()); // Unrealistic values, but they don't matter here. - size_t batch_axis = 202; - size_t seq_axis = 909; - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); + int64_t batch_axis = 202; + int64_t seq_axis = 909; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); - EXPECT_TRUE(rs->get_output_partial_shape(0).is_dynamic()); - EXPECT_EQ(rs->get_output_element_type(0), element::f32); + EXPECT_EQ(reverse_seq->get_output_partial_shape(0), (PartialShape::dynamic())); + EXPECT_EQ(reverse_seq->get_output_element_type(0), element::f32); } -TEST(type_prop, reverse_sequence_partial_left_rank_dynamic) { +TEST(type_prop, reverse_sequence_dynamic_data_input_dynamic_rank) { auto data = make_shared(element::f32, PartialShape::dynamic()); - auto seq_lengths = make_shared(element::f32, PartialShape{3}); + auto seq_lengths = make_shared(element::i32, PartialShape{3}); // Unrealistic values, but they don't matter here. - size_t batch_axis = 202; - size_t seq_axis = 909; - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); + int64_t batch_axis = 202; + int64_t seq_axis = 909; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); - EXPECT_TRUE(rs->get_output_partial_shape(0).is_dynamic()); - EXPECT_EQ(rs->get_output_element_type(0), element::f32); + EXPECT_EQ(reverse_seq->get_output_partial_shape(0), (PartialShape::dynamic())); + EXPECT_EQ(reverse_seq->get_output_element_type(0), element::f32); } -TEST(type_prop, reverse_sequence_partial_right_rank_dynamic) { +TEST(type_prop, reverse_sequence_dynamic_seq_lenghts_input_dynamic_rank) { auto data = make_shared(element::f32, PartialShape{2, 4, 6, 8}); - auto seq_lengths = make_shared(element::f32, PartialShape::dynamic()); - size_t batch_axis = 0; - size_t seq_axis = 1; - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); + auto seq_lengths = make_shared(element::i32, PartialShape::dynamic()); + int64_t batch_axis = 0; + int64_t seq_axis = 1; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); - EXPECT_TRUE(rs->get_output_partial_shape(0).same_scheme(PartialShape{2, 4, 6, 8})); - EXPECT_EQ(rs->get_output_element_type(0), element::f32); + EXPECT_TRUE(reverse_seq->get_output_partial_shape(0).same_scheme(PartialShape{2, 4, 6, 8})); + EXPECT_EQ(reverse_seq->get_output_element_type(0), element::f32); } -TEST(type_prop, reverse_sequence_partial_both_rank_static_dynamic) { +TEST(type_prop, reverse_sequence_dynamic_data_input_static_rank_and_seq_lengths_dynamic_rank) { auto data = make_shared( element::f32, PartialShape{Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic()}); - auto seq_lengths = make_shared(element::f32, PartialShape::dynamic()); - size_t batch_axis = 0; - size_t seq_axis = 1; - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); + auto seq_lengths = make_shared(element::i32, PartialShape::dynamic()); + int64_t batch_axis = 0; + int64_t seq_axis = 1; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); - EXPECT_TRUE(rs->get_output_partial_shape(0).same_scheme( + EXPECT_TRUE(reverse_seq->get_output_partial_shape(0).same_scheme( PartialShape{Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic()})); - EXPECT_EQ(rs->get_output_element_type(0), element::f32); + EXPECT_EQ(reverse_seq->get_output_element_type(0), element::f32); } -TEST(type_prop, reverse_sequence_partial_both_rank_static_dynamic_batch_axis_oob) { +TEST(type_prop, reverse_sequence_dynamic_invalid_batch_axis) { auto data = make_shared( element::f32, PartialShape{Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic()}); - auto seq_lengths = make_shared(element::f32, PartialShape{Dimension::dynamic()}); - size_t batch_axis = 4; - size_t seq_axis = 1; + auto seq_lengths = make_shared(element::i32, PartialShape{Dimension::dynamic()}); + int64_t batch_axis = 4; + int64_t seq_axis = 1; try { - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); - FAIL() << "Batch axis out of bounds not detected (rank-static dynamic shape)"; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + FAIL() << "Invalid batch_axis attribute value not detected (rank-static dynamic shape)"; } catch (const ngraph_error& error) { EXPECT_HAS_SUBSTRING(error.what(), std::string("Parameter axis 4 out of the tensor rank")); } catch (...) { - FAIL() << "Deduced type check failed for unexpected reason"; + FAIL() << "Out of bounds check of batch_axis attribute failed for unexpected reason"; } } -TEST(type_prop, reverse_sequence_partial_both_rank_static_dynamic_sequence_axis_oob) { +TEST(type_prop, reverse_sequence_dynamic_invalid_seq_axis) { auto data = make_shared( element::f32, PartialShape{Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic()}); - auto seq_lengths = make_shared(element::f32, PartialShape{Dimension::dynamic()}); - size_t batch_axis = 1; - size_t seq_axis = 4; + auto seq_lengths = make_shared(element::i32, PartialShape{Dimension::dynamic()}); + int64_t batch_axis = 1; + int64_t seq_axis = 4; try { - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); - FAIL() << "Sequence axis out of bounds not detected (rank-static dynamic shape)"; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + FAIL() << "Invalid seq_axis attribute value not detected (rank-static dynamic shape)"; } catch (const ngraph_error& error) { EXPECT_HAS_SUBSTRING(error.what(), std::string("Parameter axis 4 out of the tensor rank")); } catch (...) { - FAIL() << "Deduced type check failed for unexpected reason"; + FAIL() << "Out of bounds check of seq_axis attribute failed for unexpected reason"; } } -TEST(type_prop, reverse_sequence_partial_left_rank_static_dynamic_right_static_left_seq_length_dynamic) { +TEST(type_prop, reverse_sequence_dynamic_data_input_static_rank) { auto data = make_shared( element::f32, PartialShape{Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic(), Dimension::dynamic()}); - auto seq_lengths = make_shared(element::f32, PartialShape{3}); - size_t batch_axis = 2; - size_t seq_axis = 1; - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); + auto seq_lengths = make_shared(element::i32, PartialShape{3}); + int64_t batch_axis = 2; + int64_t seq_axis = 1; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); - EXPECT_TRUE(rs->get_output_partial_shape(0).same_scheme( + EXPECT_TRUE(reverse_seq->get_output_partial_shape(0).same_scheme( PartialShape{Dimension::dynamic(), Dimension::dynamic(), 3, Dimension::dynamic()})); - EXPECT_EQ(rs->get_output_element_type(0), element::f32); + EXPECT_EQ(reverse_seq->get_output_element_type(0), element::f32); } -TEST(type_prop, reverse_sequence_partial_both_rank_static_dynamic_right_seq_length_dynamic) { +TEST(type_prop, reverse_sequence_dynamic_data_input_static_rank_seq_lengths_input_dynamic_rank) { auto data = make_shared(element::f32, PartialShape{Dimension::dynamic(), Dimension::dynamic(), 3, Dimension::dynamic()}); - auto seq_lengths = make_shared(element::f32, PartialShape{Dimension::dynamic()}); - size_t batch_axis = 2; - size_t seq_axis = 1; - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); + auto seq_lengths = make_shared(element::i32, PartialShape{Dimension::dynamic()}); + int64_t batch_axis = 2; + int64_t seq_axis = 1; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); - EXPECT_TRUE(rs->get_output_partial_shape(0).same_scheme( + EXPECT_TRUE(reverse_seq->get_output_partial_shape(0).same_scheme( PartialShape{Dimension::dynamic(), Dimension::dynamic(), 3, Dimension::dynamic()})); - EXPECT_EQ(rs->get_output_element_type(0), element::f32); + EXPECT_EQ(reverse_seq->get_output_element_type(0), element::f32); } -TEST(type_prop, reverse_sequence_partial_left_rank_static_dynamic_right_static_left_seq_length_static) { +TEST(type_prop, reverse_sequence_dynamic_data_input_static_rank_with_static_batch_dim) { auto data = make_shared(element::f32, PartialShape{Dimension::dynamic(), Dimension::dynamic(), 3, Dimension::dynamic()}); - auto seq_lengths = make_shared(element::f32, PartialShape{3}); - size_t batch_axis = 2; - size_t seq_axis = 1; - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); + auto seq_lengths = make_shared(element::i32, PartialShape{3}); + int64_t batch_axis = 2; + int64_t seq_axis = 1; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); - EXPECT_TRUE(rs->get_output_partial_shape(0).same_scheme( + EXPECT_TRUE(reverse_seq->get_output_partial_shape(0).same_scheme( PartialShape{Dimension::dynamic(), Dimension::dynamic(), 3, Dimension::dynamic()})); - EXPECT_EQ(rs->get_output_element_type(0), element::f32); + EXPECT_EQ(reverse_seq->get_output_element_type(0), element::f32); } -TEST(type_prop, reverse_sequence_partial_left_rank_static_dynamic_right_static_left_seq_length_static_inconsistent) { +TEST(type_prop, reverse_sequence_dynamic_incompatible_data_input_static_rank_with_static_batch_dim) { auto data = make_shared(element::f32, PartialShape{Dimension::dynamic(), Dimension::dynamic(), 3, Dimension::dynamic()}); - auto seq_lengths = make_shared(element::f32, PartialShape{4}); - size_t batch_axis = 2; - size_t seq_axis = 1; + auto seq_lengths = make_shared(element::i32, PartialShape{4}); + int64_t batch_axis = 2; + int64_t seq_axis = 1; try { - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); - FAIL() << "Inconsistent sequence length not detected (rank-static dynamic shape)"; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + FAIL() << "Incompatible number of elements between seq_lengths and batch dimension of data input not detected " + "(rank-static dynamic shape)"; } catch (const NodeValidationFailure& error) { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Sequence length (4) is not equal to batch axis dimension (3)")); + EXPECT_HAS_SUBSTRING( + error.what(), + std::string("Sequence lengths input size (4) is not equal to batch axis dimension of data input (3)")); } catch (...) { - FAIL() << "Deduced type check failed for unexpected reason"; + FAIL() << "Number of elements of input seq_lengths check with respect batch dimension of input failed for " + "unexpected reason"; } } -TEST(type_prop, reverse_sequence_negative_axis_dynamic_input_rank) { +TEST(type_prop, reverse_sequence_dynamic_invalid_negative_axis_and_data_input_dynamic_rank) { auto data = make_shared(element::f32, PartialShape::dynamic()); - auto seq_lengths = make_shared(element::f32, PartialShape{1}); + auto seq_lengths = make_shared(element::i32, PartialShape{1}); int64_t batch_axis = 1; int64_t seq_axis = -2; try { - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); - FAIL() << "Dynamic input rank for negative axis not detected"; + auto reverse_seq = make_shared(data, seq_lengths, batch_axis, seq_axis); + FAIL() << "Dynamic rank of data input for negative axis not detected"; } catch (const CheckFailure& error) { EXPECT_HAS_SUBSTRING(error.what(), std::string("Rank must be static in order to normalize negative axis=-2")); } catch (...) { - FAIL() << "Deduced type check failed for unexpected reason"; + FAIL() << "Static rank of data input for negative axis validation check failed for unexpected reason"; } } - -TEST(type_prop, reverse_sequence_negative_axes_support) { - auto data = make_shared(element::f32, PartialShape{1, 2, 3, 4, 5}); - auto seq_lengths = make_shared(element::f32, PartialShape{3}); - int64_t batch_axis = -3; - int64_t seq_axis = -2; - - auto rs = make_shared(data, seq_lengths, batch_axis, seq_axis); - - EXPECT_EQ(rs->get_batch_axis(), 2); - EXPECT_EQ(rs->get_sequence_axis(), 3); -} diff --git a/ngraph/test/visitors/op/reverse_sequence.cpp b/ngraph/test/visitors/op/reverse_sequence.cpp index 75613e26a6caa0..22318779f2264a 100644 --- a/ngraph/test/visitors/op/reverse_sequence.cpp +++ b/ngraph/test/visitors/op/reverse_sequence.cpp @@ -25,7 +25,11 @@ TEST(attributes, reverse_sequence_op) { auto seq_axis = 1; auto reverse_sequence = make_shared(data, seq_indices, batch_axis, seq_axis); + NodeBuilder builder(reverse_sequence); + const auto expected_attr_count = 2; + EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); + auto g_reverse_sequence = ov::as_type_ptr(builder.create()); EXPECT_EQ(g_reverse_sequence->get_origin_batch_axis(), reverse_sequence->get_origin_batch_axis()); From e925f1f79933f52d8d4703baa536342b0b25e05d Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Wed, 25 Aug 2021 07:13:01 +0300 Subject: [PATCH 075/102] Moved attribute_adapter, attribute_visitor files to ov namespave (#7179) * Fixed nGraph build * Fixed nGraph unit tests * Fixed func tests * Fix some operators * Fixed build * Try to fix specialization in different namespace * Try to fix build * Fixed element_type --- .../include/legacy/ngraph_ops/eltwise.hpp | 6 +- .../src/legacy_api/src/ngraph_ops/eltwise.cpp | 10 +- .../include/ngraph_ops/framework_node.hpp | 12 +- .../src/ngraph_ops/framework_node.cpp | 4 +- .../compare_functions_test.cpp | 6 +- .../core/include/ngraph/attribute_adapter.hpp | 455 +---------------- .../core/include/ngraph/attribute_visitor.hpp | 124 +---- ngraph/core/include/ngraph/axis_set.hpp | 18 +- ngraph/core/include/ngraph/axis_vector.hpp | 16 +- ngraph/core/include/ngraph/coordinate.hpp | 16 +- .../core/include/ngraph/coordinate_diff.hpp | 18 +- ngraph/core/include/ngraph/distributed.hpp | 11 +- ngraph/core/include/ngraph/enum_names.hpp | 55 +- ngraph/core/include/ngraph/node.hpp | 64 +-- .../include/ngraph/op/binary_convolution.hpp | 14 +- .../core/include/ngraph/op/depth_to_space.hpp | 15 +- ngraph/core/include/ngraph/op/gelu.hpp | 15 +- ngraph/core/include/ngraph/op/interpolate.hpp | 75 +-- ngraph/core/include/ngraph/op/loop.hpp | 14 +- ngraph/core/include/ngraph/op/lstm_cell.hpp | 16 +- ngraph/core/include/ngraph/op/matrix_nms.hpp | 14 +- ngraph/core/include/ngraph/op/mvn.hpp | 14 +- .../include/ngraph/op/non_max_suppression.hpp | 42 +- ngraph/core/include/ngraph/op/parameter.hpp | 12 +- ngraph/core/include/ngraph/op/result.hpp | 14 +- ngraph/core/include/ngraph/op/reverse.hpp | 14 +- ngraph/core/include/ngraph/op/roi_align.hpp | 18 +- ngraph/core/include/ngraph/op/round.hpp | 15 +- .../core/include/ngraph/op/space_to_depth.hpp | 16 +- .../include/ngraph/op/util/attr_types.hpp | 263 +++++----- .../ngraph/op/util/multi_subgraph_base.hpp | 6 +- .../core/include/ngraph/op/util/nms_base.hpp | 14 +- .../core/include/ngraph/op/util/variable.hpp | 13 +- .../include/ngraph/runtime/aligned_buffer.hpp | 12 +- ngraph/core/include/ngraph/shape.hpp | 28 +- ngraph/core/include/ngraph/strides.hpp | 16 +- .../openvino/core/attribute_adapter.hpp | 474 ++++++++++++++++++ .../openvino/core/attribute_visitor.hpp | 140 ++++++ .../core/include/openvino/core/enum_names.hpp | 70 +++ .../core/include/openvino/core/function.hpp | 4 +- .../include/openvino/core/partial_shape.hpp | 5 +- .../openvino/core/type/element_type.hpp | 6 +- ngraph/core/src/attribute_adapter.cpp | 4 +- ngraph/core/src/attribute_visitor.cpp | 72 +-- ngraph/core/src/axis_set.cpp | 8 +- ngraph/core/src/axis_vector.cpp | 2 +- ngraph/core/src/coordinate.cpp | 3 +- ngraph/core/src/coordinate_diff.cpp | 2 +- ngraph/core/src/distributed.cpp | 23 +- ngraph/core/src/node.cpp | 2 + ngraph/core/src/op/binary_convolution.cpp | 4 +- ngraph/core/src/op/depth_to_space.cpp | 12 +- ngraph/core/src/op/gelu.cpp | 5 +- ngraph/core/src/op/interpolate.cpp | 47 +- ngraph/core/src/op/loop.cpp | 2 +- ngraph/core/src/op/lstm_cell.cpp | 5 +- ngraph/core/src/op/matrix_nms.cpp | 11 +- ngraph/core/src/op/mvn.cpp | 5 +- ngraph/core/src/op/non_max_suppression.cpp | 25 +- ngraph/core/src/op/parameter.cpp | 6 +- ngraph/core/src/op/result.cpp | 6 +- ngraph/core/src/op/reverse.cpp | 12 +- ngraph/core/src/op/roi_align.cpp | 5 +- ngraph/core/src/op/round.cpp | 12 +- ngraph/core/src/op/space_to_depth.cpp | 12 +- ngraph/core/src/op/util/attr_types.cpp | 233 ++++----- .../core/src/op/util/multi_subgraph_base.cpp | 4 +- ngraph/core/src/op/util/nms_base.cpp | 12 +- ngraph/core/src/op/util/variable.cpp | 4 +- ngraph/core/src/partial_shape.cpp | 44 +- ngraph/core/src/runtime/aligned_buffer.cpp | 4 +- ngraph/core/src/shape.cpp | 2 +- ngraph/core/src/strides.cpp | 2 +- ngraph/core/src/type/element_type.cpp | 60 +-- ngraph/test/visitors/user_op.cpp | 12 +- 75 files changed, 1513 insertions(+), 1323 deletions(-) create mode 100644 ngraph/core/include/openvino/core/attribute_adapter.hpp create mode 100644 ngraph/core/include/openvino/core/attribute_visitor.hpp create mode 100644 ngraph/core/include/openvino/core/enum_names.hpp diff --git a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/eltwise.hpp b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/eltwise.hpp index e9b7e04cc41166..706d554980cbf5 100644 --- a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/eltwise.hpp +++ b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/eltwise.hpp @@ -40,6 +40,9 @@ class INFERENCE_ENGINE_API_CLASS(Eltwise) : public Op { } // namespace op std::ostream &operator<<(std::ostream &s, const ELTWISE_TYPE &type); +} // namespace ngraph + +namespace ov { template <> class AttributeAdapter @@ -52,4 +55,5 @@ class AttributeAdapter 1}; const DiscreteTypeInfo &get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/eltwise.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/eltwise.cpp index ed10c65989507e..fbc7546dacd7d6 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/eltwise.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/eltwise.cpp @@ -80,8 +80,11 @@ bool op::Eltwise::visit_attributes(AttributeVisitor &visitor) { visitor.on_attribute("operation", eltwise_type); return true; } +std::ostream &operator<<(std::ostream &s, const ELTWISE_TYPE &type) { + return s << as_string(type); +} -namespace ngraph { +namespace ov { template <> EnumNames &EnumNames::get() { static auto enum_names = EnumNames("ELTWISE_TYPE", {{"sum", ELTWISE_TYPE::Sum}, @@ -95,7 +98,4 @@ template <> EnumNames &EnumNames::get() { constexpr DiscreteTypeInfo AttributeAdapter::type_info; -std::ostream &operator<<(std::ostream &s, const ELTWISE_TYPE &type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/inference-engine/src/transformations/include/ngraph_ops/framework_node.hpp b/inference-engine/src/transformations/include/ngraph_ops/framework_node.hpp index 8abda399c9c049..fdc0060846d68f 100644 --- a/inference-engine/src/transformations/include/ngraph_ops/framework_node.hpp +++ b/inference-engine/src/transformations/include/ngraph_ops/framework_node.hpp @@ -80,14 +80,18 @@ class TRANSFORMATIONS_API FrameworkNode : public Op { FrameworkNodeAttrs m_attrs; }; } // namespace op +} // namespace ngraph + +namespace ov { template <> -class TRANSFORMATIONS_API AttributeAdapter - : public DirectValueAccessor { +class TRANSFORMATIONS_API AttributeAdapter + : public DirectValueAccessor { public: - AttributeAdapter(op::FrameworkNodeAttrs& value); + AttributeAdapter(ngraph::op::FrameworkNodeAttrs& value); static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/inference-engine/src/transformations/src/ngraph_ops/framework_node.cpp b/inference-engine/src/transformations/src/ngraph_ops/framework_node.cpp index 94d0008c11064e..75d7faa0dd90bb 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/framework_node.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/framework_node.cpp @@ -95,8 +95,8 @@ void op::FrameworkNode::validate_and_infer_types() { } } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr ov::DiscreteTypeInfo ov::AttributeAdapter::type_info; -AttributeAdapter::AttributeAdapter( +ov::AttributeAdapter::AttributeAdapter( op::FrameworkNodeAttrs& value) : DirectValueAccessor(value) {} diff --git a/inference-engine/tests/functional/inference_engine/transformations/compare_functions_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/compare_functions_test.cpp index 8a0660f199b9b3..a886bc359727f3 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/compare_functions_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/compare_functions_test.cpp @@ -620,7 +620,7 @@ TEST(TransformationTests, DummyOpNegativeDifferentStringVector) { EXPECT_THAT(res.message, HasSubstr(" mismatch in value: 'member' : [a, ba] vs [b, ab]")); } -namespace ngraph { +namespace ov { struct TestDummyDataTypeTransformationTests_NO_NGRAPH_NAME_COLISION {}; @@ -643,10 +643,10 @@ class AttributeAdapter::type_info; -} // namespace ngraph +} // namespace ov TEST(TransformationTests, DummyOpNegativeNotSupportedType) { - TestDummyDataTypeTransformationTests_NO_NGRAPH_NAME_COLISION m{}; + ov::TestDummyDataTypeTransformationTests_NO_NGRAPH_NAME_COLISION m{}; const auto& f1 = createDummyFunc(m); const auto& f2 = createDummyFunc(m); diff --git a/ngraph/core/include/ngraph/attribute_adapter.hpp b/ngraph/core/include/ngraph/attribute_adapter.hpp index b2e78548808ffd..075738a3449a46 100644 --- a/ngraph/core/include/ngraph/attribute_adapter.hpp +++ b/ngraph/core/include/ngraph/attribute_adapter.hpp @@ -10,464 +10,27 @@ #include "ngraph/enum_names.hpp" #include "ngraph/type.hpp" +#include "openvino/core/attribute_adapter.hpp" /// namespace ngraph { -class AttributeVisitor; -/// \brief Provides access to an attribute of type AT as a value accessor type VAT -template -class ValueAccessor; +using ov::ValueAccessor; -/// \brief ValueAccessor provides an accessor for values that do not have get/set methonds -/// via AttributeVistor.on_adapter. -/// -/// All ValueAccessors must be derived from ValueAccessor so that an AttributeVisitor -/// only needs to implement a subset of the on_adapter methods. -template <> -class NGRAPH_API ValueAccessor { -public: - /// \brief type info enables identification of the value accessor, as well as is_type and - /// as_type. - virtual const DiscreteTypeInfo& get_type_info() const = 0; - virtual ~ValueAccessor() {} -}; - -/// \brief Provides access to values via get/set methods from an m_value, typically from -/// ValueReference -/// -/// The m_buffer holds a VAT, which may be wider than the attribute AT. For example, serializers -/// that only -/// support int64_t integers would use a ValueAccessor> to reference a -/// vector attribute. Destruction moves the value back to the attribute if it was -/// changed. -/// \tparam VAT The adapter value type; may be wider than the value being accessed. -template -class ValueAccessor : public ValueAccessor { -public: - /// Returns the value - virtual const VAT& get() = 0; - /// Sets the value - virtual void set(const VAT& value) = 0; -}; - -template <> -class ValueAccessor : public ValueAccessor { -public: - virtual void* get_ptr() = 0; - virtual size_t size() = 0; -}; - -template -class DirectValueAccessor : public ValueAccessor { -public: - DirectValueAccessor(AT& ref) : m_ref(ref) {} - const AT& get() override { - return m_ref; - } - void set(const AT& value) override { - m_ref = value; - } - -protected: - AT& m_ref; -}; - -template -class IndirectScalarValueAccessor : public ValueAccessor { -public: - IndirectScalarValueAccessor(AT& ref) : m_ref(ref), m_buffer() {} - - const VAT& get() override { - if (!m_buffer_valid) { - m_buffer = static_cast(m_ref); - m_buffer_valid = true; - } - return m_buffer; - } - - void set(const VAT& value) override { - m_ref = static_cast(value); - m_buffer_valid = false; - } +using ov::DirectValueAccessor; -protected: - AT& m_ref; - VAT m_buffer; - bool m_buffer_valid{false}; -}; +using ov::IndirectScalarValueAccessor; template A copy_from(B& b) { - A result(b.size()); - for (size_t i = 0; i < b.size(); ++i) { - result[i] = static_cast::type>(b[i]); - } - return result; + return ov::copy_from(b); } -template -class IndirectVectorValueAccessor : public ValueAccessor { -public: - IndirectVectorValueAccessor(AT& ref) : m_ref(ref) {} - - const VAT& get() override { - if (!m_buffer_valid) { - m_buffer = copy_from::type>(m_ref); - m_buffer_valid = true; - } - return m_buffer; - } - - void set(const VAT& value) override { - m_ref = copy_from(value); - m_buffer_valid = false; - } - - operator AT&() { - return m_ref; - } - -protected: - AT& m_ref; - VAT m_buffer; - bool m_buffer_valid{false}; -}; - -/// \brief An AttributeAdapter "captures" an attribute as an AT& and makes it available as a -/// ValueAccessor. -template -class AttributeAdapter {}; - -/// \brief Access an enum via a string -/// \tparam AT The attribute type enum class -template -class EnumAttributeAdapterBase : public ValueAccessor { -public: - EnumAttributeAdapterBase(AT& value) : m_ref(value) {} - - const std::string& get() override { - return as_string(m_ref); - } - void set(const std::string& value) override { - m_ref = as_enum(value); - } - operator AT&() { - return m_ref; - } - -protected: - AT& m_ref; -}; - -/// Adapters will see visitor -class VisitorAdapter : public ValueAccessor { -public: - virtual bool visit_attributes(AttributeVisitor& visitor) = 0; -}; - -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(float& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a double as a double -template <> -class NGRAPH_API AttributeAdapter : public DirectValueAccessor { -public: - AttributeAdapter(double& value) : DirectValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a string as a string -template <> -class NGRAPH_API AttributeAdapter : public DirectValueAccessor { -public: - AttributeAdapter(std::string& value) : DirectValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a bool as a bool -template <> -class NGRAPH_API AttributeAdapter : public DirectValueAccessor { -public: - AttributeAdapter(bool& value) : DirectValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access an int8_t and an int64_t -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(int8_t& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access an int16_t as an int64_t -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(int16_t& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access an int32_t as an int64_t -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(int32_t& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access an int64_t as an int64_t -template <> -class NGRAPH_API AttributeAdapter : public DirectValueAccessor { -public: - AttributeAdapter(int64_t& value) : DirectValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a uint8_t as an int64_t -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(uint8_t& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a uint16_t as an int64_t -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(uint16_t& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a uint32_t as an int64_t -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(uint32_t& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a uint64_t as an int64_t -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(uint64_t& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -#ifdef __APPLE__ -// size_t is one of the uint types on _WIN32 -template <> -class NGRAPH_API AttributeAdapter : public IndirectScalarValueAccessor { -public: - AttributeAdapter(size_t& value) : IndirectScalarValueAccessor(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -template <> -class NGRAPH_API AttributeAdapter> - : public IndirectVectorValueAccessor, std::vector> { -public: - AttributeAdapter(std::vector& value) - : IndirectVectorValueAccessor, std::vector>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; -#endif - -/// Note: These class bodies cannot be defined with templates because of interactions -/// between dllexport and templates on Windows. - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} +using ov::IndirectVectorValueAccessor; - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; +using ov::AttributeAdapter; +using ov::EnumAttributeAdapterBase; -/// \brief Access a vector -template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { -public: - AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} +using ov::VisitorAdapter; - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/attribute_visitor.hpp b/ngraph/core/include/ngraph/attribute_visitor.hpp index 5fd9a62a2ef54e..267d1c3a98c36a 100644 --- a/ngraph/core/include/ngraph/attribute_visitor.hpp +++ b/ngraph/core/include/ngraph/attribute_visitor.hpp @@ -11,128 +11,8 @@ #include "ngraph/partial_shape.hpp" #include "ngraph/type.hpp" #include "ngraph/type/element_type.hpp" +#include "openvino/core/attribute_visitor.hpp" -namespace ov { -class Function; -} namespace ngraph { -template -class ValueAccessor; -class VisitorAdapter; -class Node; - -/// \brief Visits the attributes of a node, primarily for serialization-like tasks. -/// -/// Attributes are the node parameters that are always compile-time constants. -/// Values computed from the graph topology and attributes during compilation are not -/// attributes. -/// -/// Attributes have a wide variety of types, but serialization formats are more restricted. -/// We asume serialation easily supports scalar types of bool 64-bit signed, string, and double, -/// and has specialized ways to support numeric arrays and raw data+size. The visitor and -/// adapter convert between the limited serialization types and the unlimited attribute types. -/// -/// A visitor is passed to an op's visit_attributes method. The visit_attributes method calls -/// the template method visitor.on_attribute(const std::string& name, AT& value) on each -/// attribute. The visitor can read or write the attribute's value. The on_attribute -/// method creates an AttributeAdapter for the value and passes it to one of the visitors -/// on_adapter methods. The on_adapter methods expect a reference to a ValueAccessor or a -/// VisitorAdapter. A ValueAccessor has get/set methods that can be used to read/write the -/// attribute value as type VAT. These methods are triggered by deriving AttributeAdapter -/// from ValueAccessor. For more complex cases, such as structs, the on_adapter method for -/// VisitorAdapter passes the name and visitor to the adapter, so that the adapter can perform -/// additional work such as visiting struct members or sequence values. -/// -/// When a node visits an attribute with structure, the node's on_attribute passes a name for -/// the entire attribute, but the struct will have its own methods to be visited. Similarly, a -/// vector will have a sequence of members to be visited. The adapter may use the visitor -/// methods start_struct/finish_struct and start_vector/next_vector/finish_vector to inidicate -/// nexted members. -/// -/// The visitor method get_name_with_context creates a generic nested version of the name. -/// Visitors can override according to their serialization requirements. -/// -/// Attributes that are shared_ptr are special. They must have been already been -/// registered with the visitor using register_node, which needs a shared pointer to a node and -/// a string ID. The ID string will be used to serialize the node or find the node during -/// deserialization. -class NGRAPH_API AttributeVisitor { -public: - virtual ~AttributeVisitor() {} - // Must implement these methods - /// \brief handles all specialized on_adapter methods implemented by the visitor. - /// - /// The adapter implements get_type_info(), which can be used to determine the adapter - /// directly - /// or via is_type and as_type on any platform - virtual void on_adapter(const std::string& name, ValueAccessor& adapter) = 0; - // The remaining adapter methods fall back on the void adapter if not implemented - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - /// \brief Hook for adapters that need visitor access - virtual void on_adapter(const std::string& name, VisitorAdapter& adapter); - - /// \brief Provides API to handle nGraph Function attribute type, accessed as ValueAccessor - /// \param name attribute name - /// \param adapter reference to a Function ValueAccessor - virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); - - /// The generic visitor. There must be a definition of AttributeAdapter that can convert - /// to a ValueAccessor for one of the on_adpater methods. - template - void on_attribute(const std::string& name, AT& value) { - AttributeAdapter adapter(value); - start_structure(name); - on_adapter(get_name_with_context(), adapter); - finish_structure(); - } - /// \returns The nested context of visits - const std::vector& get_context() const { - return m_context; - } - /// \returns context prepended to names - virtual std::string get_name_with_context(); - /// \brief Start visiting a nested structure - virtual void start_structure(const std::string& name); - /// \brief Finish visiting a nested structure - virtual std::string finish_structure(); - using node_id_t = std::string; - static const node_id_t invalid_node_id; - /// \brief Associate a node with an id. - /// - /// No node may be used as an attribute unless it has already been registered with an ID. - /// References to nodes are visited with a ValueAccessor of their ID. - virtual void register_node(const std::shared_ptr& node, node_id_t id = invalid_node_id); - /// Returns the node with the given id, or nullptr if there is no registered node - virtual std::shared_ptr get_registered_node(node_id_t id); - /// Returns the id for the node, or -1 if the node is not registered - virtual node_id_t get_registered_node_id(const std::shared_ptr& node); - -protected: - std::vector m_context; - std::unordered_map, node_id_t> m_node_id_map; - std::unordered_map> m_id_node_map; -}; +using ov::AttributeVisitor; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/axis_set.hpp b/ngraph/core/include/ngraph/axis_set.hpp index 03bf736e0ef823..9a1c72b8abee33 100644 --- a/ngraph/core/include/ngraph/axis_set.hpp +++ b/ngraph/core/include/ngraph/axis_set.hpp @@ -33,10 +33,16 @@ class AxisSet : public std::set { NGRAPH_API std::vector to_vector() const; }; +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const AxisSet& axis_set); +} // namespace ngraph + +namespace ov { + template <> -class NGRAPH_API AttributeAdapter : public ValueAccessor> { +class NGRAPH_API AttributeAdapter : public ValueAccessor> { public: - AttributeAdapter(AxisSet& value) : m_ref(value) {} + AttributeAdapter(ngraph::AxisSet& value) : m_ref(value) {} const std::vector& get() override; void set(const std::vector& value) override; @@ -44,16 +50,14 @@ class NGRAPH_API AttributeAdapter : public ValueAccessor m_buffer; bool m_buffer_valid{false}; }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const AxisSet& axis_set); -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/ngraph/axis_vector.hpp b/ngraph/core/include/ngraph/axis_vector.hpp index ac98561145d921..f7215d0c88f8ba 100644 --- a/ngraph/core/include/ngraph/axis_vector.hpp +++ b/ngraph/core/include/ngraph/axis_vector.hpp @@ -35,10 +35,18 @@ class AxisVector : public std::vector { NGRAPH_API AxisVector& operator=(AxisVector&& v) noexcept; }; +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const AxisVector& axis_vector); +} // namespace ngraph + +namespace ov { + template <> -class NGRAPH_API AttributeAdapter : public IndirectVectorValueAccessor> { +class NGRAPH_API AttributeAdapter + : public IndirectVectorValueAccessor> { public: - AttributeAdapter(AxisVector& value) : IndirectVectorValueAccessor>(value) {} + AttributeAdapter(ngraph::AxisVector& value) + : IndirectVectorValueAccessor>(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { @@ -46,6 +54,4 @@ class NGRAPH_API AttributeAdapter : public IndirectVectorValueAccess } }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const AxisVector& axis_vector); -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/ngraph/coordinate.hpp b/ngraph/core/include/ngraph/coordinate.hpp index 3d26523ea7bbc4..56535fdeb18c28 100644 --- a/ngraph/core/include/ngraph/coordinate.hpp +++ b/ngraph/core/include/ngraph/coordinate.hpp @@ -36,17 +36,21 @@ class Coordinate : public std::vector { NGRAPH_API Coordinate& operator=(Coordinate&& v) noexcept; }; +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const Coordinate& coordinate); +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter : public IndirectVectorValueAccessor> { +class NGRAPH_API AttributeAdapter + : public IndirectVectorValueAccessor> { public: - AttributeAdapter(Coordinate& value) : IndirectVectorValueAccessor>(value) {} + AttributeAdapter(ngraph::Coordinate& value) + : IndirectVectorValueAccessor>(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; - -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const Coordinate& coordinate); -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/ngraph/coordinate_diff.hpp b/ngraph/core/include/ngraph/coordinate_diff.hpp index 2f51c0e8400bc2..77fb5c365ffe07 100644 --- a/ngraph/core/include/ngraph/coordinate_diff.hpp +++ b/ngraph/core/include/ngraph/coordinate_diff.hpp @@ -35,14 +35,20 @@ class CoordinateDiff : public std::vector { NGRAPH_API CoordinateDiff& operator=(CoordinateDiff&& v) noexcept; }; +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const CoordinateDiff& coordinate_diff); +} // namespace ngraph + +namespace ov { + template <> -class NGRAPH_API AttributeAdapter - : public IndirectVectorValueAccessor> +class NGRAPH_API AttributeAdapter + : public IndirectVectorValueAccessor> { public: - AttributeAdapter(CoordinateDiff& value) - : IndirectVectorValueAccessor>(value) {} + AttributeAdapter(ngraph::CoordinateDiff& value) + : IndirectVectorValueAccessor>(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { @@ -50,6 +56,4 @@ class NGRAPH_API AttributeAdapter } }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const CoordinateDiff& coordinate_diff); -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/ngraph/distributed.hpp b/ngraph/core/include/ngraph/distributed.hpp index c67e72a408bcb9..f36c318cf058b2 100644 --- a/ngraph/core/include/ngraph/distributed.hpp +++ b/ngraph/core/include/ngraph/distributed.hpp @@ -25,14 +25,19 @@ NGRAPH_API std::ostream& operator<<(std::ostream& out, const Type& obj); } // namespace reduction +} // namespace ngraph + +namespace ov { + template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { public: - AttributeAdapter(reduction::Type& value) : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::reduction::Type& value) : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/enum_names.hpp b/ngraph/core/include/ngraph/enum_names.hpp index 13c9d487ce0fc3..91b95745cd0ae0 100644 --- a/ngraph/core/include/ngraph/enum_names.hpp +++ b/ngraph/core/include/ngraph/enum_names.hpp @@ -4,67 +4,20 @@ #pragma once -#include -#include -#include - #include "ngraph/check.hpp" +#include "openvino/core/enum_names.hpp" namespace ngraph { -/// Uses a pairings defined by EnumTypes::get() to convert between strings -/// and enum values. -template -class EnumNames { -public: - /// Converts strings to enum values - static EnumType as_enum(const std::string& name) { - auto to_lower = [](const std::string& s) { - std::string rc = s; - std::transform(rc.begin(), rc.end(), rc.begin(), [](char c) { - return static_cast(::tolower(static_cast(c))); - }); - return rc; - }; - for (const auto& p : get().m_string_enums) { - if (to_lower(p.first) == to_lower(name)) { - return p.second; - } - } - NGRAPH_CHECK(false, "\"", name, "\"", " is not a member of enum ", get().m_enum_name); - } - - /// Converts enum values to strings - static const std::string& as_string(EnumType e) { - for (const auto& p : get().m_string_enums) { - if (p.second == e) { - return p.first; - } - } - NGRAPH_CHECK(false, " invalid member of enum ", get().m_enum_name); - } - -private: - /// Creates the mapping. - EnumNames(const std::string& enum_name, const std::vector> string_enums) - : m_enum_name(enum_name), - m_string_enums(string_enums) {} - - /// Must be defined to returns a singleton for each supported enum class - static EnumNames& get(); - - const std::string m_enum_name; - std::vector> m_string_enums; -}; - +using ov::EnumNames; /// Returns the enum value matching the string template typename std::enable_if::value, Type>::type as_enum(const Value& value) { - return EnumNames::as_enum(value); + return ov::as_enum(value); } /// Returns the string matching the enum value template const std::string& as_string(Value value) { - return EnumNames::as_string(value); + return ov::as_string(value); } } // namespace ngraph diff --git a/ngraph/core/include/ngraph/node.hpp b/ngraph/core/include/ngraph/node.hpp index e3c4b1a39e4193..e72e1e8e1b1996 100644 --- a/ngraph/core/include/ngraph/node.hpp +++ b/ngraph/core/include/ngraph/node.hpp @@ -44,7 +44,6 @@ class Input; template class Output; -class AttributeVisitor; class Node; namespace runtime { @@ -649,11 +648,37 @@ struct RawNodeOutput { } }; +using RawNodeOutputMap = std::map>; + +class NGRAPH_API NodeValidationFailure : public CheckFailure { +public: + NodeValidationFailure(const CheckLocInfo& check_loc_info, const Node* node, const std::string& explanation) + : CheckFailure(check_loc_info, node_validation_failure_loc_string(node), explanation) {} +}; +} // namespace ngraph +#define NODE_VALIDATION_CHECK(node, ...) NGRAPH_CHECK_HELPER(::ngraph::NodeValidationFailure, (node), __VA_ARGS__) + +namespace ngraph { +template +void check_new_args_count(const Node* node, T new_args) { + NODE_VALIDATION_CHECK(node, + new_args.size() == node->input_values().size(), + "clone_with_new_inputs() expected ", + node->input_values().size(), + " argument", + (node->input_values().size() == 1 ? "" : "s"), + " but got ", + new_args.size()); +} + +} // namespace ngraph + +namespace ov { /// \brief Visits a reference to a node that has been registered with the visitor. template <> -class NGRAPH_API AttributeAdapter> : public VisitorAdapter { +class NGRAPH_API AttributeAdapter> : public VisitorAdapter { public: - AttributeAdapter(std::shared_ptr& value); + AttributeAdapter(std::shared_ptr& value); bool visit_attributes(AttributeVisitor& visitor) override; static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; @@ -662,13 +687,13 @@ class NGRAPH_API AttributeAdapter> : public VisitorAdapter } protected: - std::shared_ptr& m_ref; + std::shared_ptr& m_ref; }; template <> -class NGRAPH_API AttributeAdapter : public VisitorAdapter { +class NGRAPH_API AttributeAdapter : public VisitorAdapter { public: - AttributeAdapter(NodeVector& ref); + AttributeAdapter(ngraph::NodeVector& ref); bool visit_attributes(AttributeVisitor& visitor) override; @@ -678,30 +703,7 @@ class NGRAPH_API AttributeAdapter : public VisitorAdapter { } protected: - NodeVector& m_ref; + ngraph::NodeVector& m_ref; }; -using RawNodeOutputMap = std::map>; - -class NGRAPH_API NodeValidationFailure : public CheckFailure { -public: - NodeValidationFailure(const CheckLocInfo& check_loc_info, const Node* node, const std::string& explanation) - : CheckFailure(check_loc_info, node_validation_failure_loc_string(node), explanation) {} -}; -} // namespace ngraph -#define NODE_VALIDATION_CHECK(node, ...) NGRAPH_CHECK_HELPER(::ngraph::NodeValidationFailure, (node), __VA_ARGS__) - -namespace ngraph { -template -void check_new_args_count(const Node* node, T new_args) { - NODE_VALIDATION_CHECK(node, - new_args.size() == node->input_values().size(), - "clone_with_new_inputs() expected ", - node->input_values().size(), - " argument", - (node->input_values().size() == 1 ? "" : "s"), - " but got ", - new_args.size()); -} - -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/binary_convolution.hpp b/ngraph/core/include/ngraph/op/binary_convolution.hpp index fbe02f9fbb7db3..14f7ccf6c05dad 100644 --- a/ngraph/core/include/ngraph/op/binary_convolution.hpp +++ b/ngraph/core/include/ngraph/op/binary_convolution.hpp @@ -126,12 +126,16 @@ class NGRAPH_API BinaryConvolution : public Op { NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v1::BinaryConvolution::BinaryConvolutionMode& type); +} // namespace ngraph + +namespace ov { + template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v1::BinaryConvolution::BinaryConvolutionMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v1::BinaryConvolution::BinaryConvolutionMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; @@ -140,4 +144,4 @@ class NGRAPH_API AttributeAdapter clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; void validate_and_infer_types() override; bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; bool has_evaluate() const override; @@ -62,17 +62,20 @@ using v0::DepthToSpace; NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v0::DepthToSpace::DepthToSpaceMode& type); +} // namespace ngraph +namespace ov { template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v0::DepthToSpace::DepthToSpaceMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v0::DepthToSpace::DepthToSpaceMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/gelu.hpp b/ngraph/core/include/ngraph/op/gelu.hpp index 78f683120c2eda..e662bada82f9a1 100644 --- a/ngraph/core/include/ngraph/op/gelu.hpp +++ b/ngraph/core/include/ngraph/op/gelu.hpp @@ -27,7 +27,7 @@ class NGRAPH_API Gelu : public Op { void validate_and_infer_types() override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; } // namespace v0 using v0::Gelu; @@ -68,15 +68,20 @@ class NGRAPH_API Gelu : public util::UnaryElementwiseArithmetic { }; } // namespace v7 } // namespace op +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::GeluApproximationMode& value) : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::GeluApproximationMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/interpolate.hpp b/ngraph/core/include/ngraph/op/interpolate.hpp index c4a84dee8e08ec..e2104a8dda778b 100644 --- a/ngraph/core/include/ngraph/op/interpolate.hpp +++ b/ngraph/core/include/ngraph/op/interpolate.hpp @@ -283,30 +283,42 @@ using v0::InterpolateAttrs; NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v0::Interpolate::InterpolateMode& type); +//---------------------------------------- v4 -------------------------------------------------- + +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::InterpolateMode& type); + +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::CoordinateTransformMode& type); + +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::NearestMode& type); + +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::ShapeCalcMode& type); + +} // namespace ngraph + +namespace ov { + template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v0::Interpolate::InterpolateMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v0::Interpolate::InterpolateMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; - -//---------------------------------------- v4 -------------------------------------------------- - -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::InterpolateMode& type); - template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v4::Interpolate::InterpolateMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v4::Interpolate::InterpolateMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 4}; const DiscreteTypeInfo& get_type_info() const override { @@ -314,15 +326,12 @@ class NGRAPH_API AttributeAdapter } }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::CoordinateTransformMode& type); - template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v4::Interpolate::CoordinateTransformMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v4::Interpolate::CoordinateTransformMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 4}; const DiscreteTypeInfo& get_type_info() const override { @@ -330,15 +339,12 @@ class NGRAPH_API AttributeAdapter } }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::NearestMode& type); - template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v4::Interpolate::NearestMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v4::Interpolate::NearestMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 4}; const DiscreteTypeInfo& get_type_info() const override { @@ -346,19 +352,16 @@ class NGRAPH_API AttributeAdapter } }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::ShapeCalcMode& type); - template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v4::Interpolate::ShapeCalcMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v4::Interpolate::ShapeCalcMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 4}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/loop.hpp b/ngraph/core/include/ngraph/op/loop.hpp index a90e150a43f700..8d037c9bd37391 100644 --- a/ngraph/core/include/ngraph/op/loop.hpp +++ b/ngraph/core/include/ngraph/op/loop.hpp @@ -75,17 +75,21 @@ class NGRAPH_API Loop : public op::util::SubGraphOp { }; } // namespace v5 } // namespace op +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter - : public DirectValueAccessor { +class NGRAPH_API AttributeAdapter + : public DirectValueAccessor { public: - AttributeAdapter(op::v5::Loop::SpecialBodyPorts& value) - : DirectValueAccessor(value) {} + AttributeAdapter(ngraph::op::v5::Loop::SpecialBodyPorts& value) + : DirectValueAccessor(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/lstm_cell.hpp b/ngraph/core/include/ngraph/op/lstm_cell.hpp index eabcd319bf7392..b6d9a4f16de753 100644 --- a/ngraph/core/include/ngraph/op/lstm_cell.hpp +++ b/ngraph/core/include/ngraph/op/lstm_cell.hpp @@ -192,9 +192,9 @@ class NGRAPH_API LSTMCell : public util::RNNCellBase { float clip = 0.f, bool input_forget = false); - virtual void validate_and_infer_types() override; + void validate_and_infer_types() override; bool visit_attributes(AttributeVisitor& visitor) override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; bool get_input_forget() const { return m_input_forget; @@ -383,15 +383,21 @@ class NGRAPH_API LSTMCell : public util::RNNCellBase { NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::LSTMWeightsFormat& type); +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::LSTMWeightsFormat& value) : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::LSTMWeightsFormat& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/matrix_nms.hpp b/ngraph/core/include/ngraph/op/matrix_nms.hpp index b3998dc2a3b793..e77b7b439c31aa 100644 --- a/ngraph/core/include/ngraph/op/matrix_nms.hpp +++ b/ngraph/core/include/ngraph/op/matrix_nms.hpp @@ -74,17 +74,21 @@ class NGRAPH_API MatrixNms : public util::NmsBase { } // namespace op NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v8::MatrixNms::DecayFunction& type); +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v8::MatrixNms::DecayFunction& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v8::MatrixNms::DecayFunction& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/mvn.hpp b/ngraph/core/include/ngraph/op/mvn.hpp index 4b6cd70c63a0df..8795a7cbb8f2db 100644 --- a/ngraph/core/include/ngraph/op/mvn.hpp +++ b/ngraph/core/include/ngraph/op/mvn.hpp @@ -41,11 +41,11 @@ class NGRAPH_API MVN : public Op { /// MVN(const Output& data, AxisSet reduction_axes, bool normalize_variance = true, double eps = 1e-9); - virtual void validate_and_infer_types() override; + void validate_and_infer_types() override; bool visit_attributes(AttributeVisitor& visitor) override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; double get_eps() const { return m_eps; @@ -129,15 +129,19 @@ class NGRAPH_API MVN : public ngraph::op::Op { }; } // namespace v6 } // namespace op +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::MVNEpsMode& value) : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::MVNEpsMode& value) : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/non_max_suppression.hpp b/ngraph/core/include/ngraph/op/non_max_suppression.hpp index 0a75980b5ee7f5..ef6e6178139189 100644 --- a/ngraph/core/include/ngraph/op/non_max_suppression.hpp +++ b/ngraph/core/include/ngraph/op/non_max_suppression.hpp @@ -366,12 +366,21 @@ class NGRAPH_API NonMaxSuppression : public Op { NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v1::NonMaxSuppression::BoxEncodingType& type); +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const op::v3::NonMaxSuppression::BoxEncodingType& type); + +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const op::v5::NonMaxSuppression::BoxEncodingType& type); +} // namespace ngraph + +namespace ov { + template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v1::NonMaxSuppression::BoxEncodingType& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v1::NonMaxSuppression::BoxEncodingType& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { @@ -379,15 +388,12 @@ class NGRAPH_API AttributeAdapter } }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const op::v3::NonMaxSuppression::BoxEncodingType& type); - template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v3::NonMaxSuppression::BoxEncodingType& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v3::NonMaxSuppression::BoxEncodingType& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { @@ -395,19 +401,17 @@ class NGRAPH_API AttributeAdapter } }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const op::v5::NonMaxSuppression::BoxEncodingType& type); - template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v5::NonMaxSuppression::BoxEncodingType& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v5::NonMaxSuppression::BoxEncodingType& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/parameter.hpp b/ngraph/core/include/ngraph/op/parameter.hpp index 0795cc5cc7f215..9ac3feb7b8faf8 100644 --- a/ngraph/core/include/ngraph/op/parameter.hpp +++ b/ngraph/core/include/ngraph/op/parameter.hpp @@ -59,11 +59,14 @@ class NGRAPH_API Parameter : public op::Op { using v0::Parameter; } // namespace op using ParameterVector = std::vector>; +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter : public VisitorAdapter { +class NGRAPH_API AttributeAdapter : public VisitorAdapter { public: - AttributeAdapter(ParameterVector& ref); + AttributeAdapter(ngraph::ParameterVector& ref); bool visit_attributes(AttributeVisitor& visitor) override; @@ -73,6 +76,7 @@ class NGRAPH_API AttributeAdapter : public VisitorAdapter { } protected: - ParameterVector& m_ref; + ngraph::ParameterVector& m_ref; }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/result.hpp b/ngraph/core/include/ngraph/op/result.hpp index 3f63ac07efe7a8..da47ff4b83fb3d 100644 --- a/ngraph/core/include/ngraph/op/result.hpp +++ b/ngraph/core/include/ngraph/op/result.hpp @@ -25,7 +25,7 @@ class NGRAPH_API Result : public Op { bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; void set_needs_default_layout(bool val) { m_needs_default_layout = val; @@ -45,11 +45,14 @@ class NGRAPH_API Result : public Op { using v0::Result; } // namespace op using ResultVector = std::vector>; +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter : public VisitorAdapter { +class NGRAPH_API AttributeAdapter : public VisitorAdapter { public: - AttributeAdapter(ResultVector& ref); + AttributeAdapter(ngraph::ResultVector& ref); bool visit_attributes(AttributeVisitor& visitor) override; @@ -59,6 +62,7 @@ class NGRAPH_API AttributeAdapter : public VisitorAdapter { } protected: - ResultVector& m_ref; + ngraph::ResultVector& m_ref; }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/reverse.hpp b/ngraph/core/include/ngraph/op/reverse.hpp index 1acff71b394e46..cbbdb7500131f3 100644 --- a/ngraph/core/include/ngraph/op/reverse.hpp +++ b/ngraph/core/include/ngraph/op/reverse.hpp @@ -29,7 +29,7 @@ class NGRAPH_API Reverse : public Op { bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; /// \return The second input data interpretation mode. Mode get_mode() const { @@ -60,15 +60,21 @@ class NGRAPH_API Reverse : public Op { NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v1::Reverse::Mode& type); +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v1::Reverse::Mode& value) : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v1::Reverse::Mode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/roi_align.hpp b/ngraph/core/include/ngraph/op/roi_align.hpp index ae4656a9d53a34..03f333c98a1dd9 100644 --- a/ngraph/core/include/ngraph/op/roi_align.hpp +++ b/ngraph/core/include/ngraph/op/roi_align.hpp @@ -48,9 +48,9 @@ class NGRAPH_API ROIAlign : public Op { const float spatial_scale, const PoolingMode mode); - virtual void validate_and_infer_types() override; + void validate_and_infer_types() override; bool visit_attributes(AttributeVisitor& visitor) override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; int get_pooled_h() const { return m_pooled_h; @@ -85,17 +85,21 @@ using v3::ROIAlign; } // namespace op std::ostream& operator<<(std::ostream& s, const op::v3::ROIAlign::PoolingMode& mode); +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v3::ROIAlign::PoolingMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v3::ROIAlign::PoolingMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 3}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/round.hpp b/ngraph/core/include/ngraph/op/round.hpp index 5efed5aa9cf8de..38a462132f0631 100644 --- a/ngraph/core/include/ngraph/op/round.hpp +++ b/ngraph/core/include/ngraph/op/round.hpp @@ -34,7 +34,7 @@ class NGRAPH_API Round : public ngraph::op::Op { bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; bool has_evaluate() const override; @@ -50,16 +50,21 @@ class NGRAPH_API Round : public ngraph::op::Op { } // namespace op NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v5::Round::RoundMode& type); +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v5::Round::RoundMode& value) : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v5::Round::RoundMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 5}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/space_to_depth.hpp b/ngraph/core/include/ngraph/op/space_to_depth.hpp index 4037faa1e5b84d..d72c725f60efda 100644 --- a/ngraph/core/include/ngraph/op/space_to_depth.hpp +++ b/ngraph/core/include/ngraph/op/space_to_depth.hpp @@ -46,7 +46,7 @@ class NGRAPH_API SpaceToDepth : public Op { return m_mode; } void validate_and_infer_types() override; - virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; bool has_evaluate() const override; @@ -61,17 +61,21 @@ using v0::SpaceToDepth; NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v0::SpaceToDepth::SpaceToDepthMode& type); +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::v0::SpaceToDepth::SpaceToDepthMode& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::v0::SpaceToDepth::SpaceToDepthMode& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/util/attr_types.hpp b/ngraph/core/include/ngraph/op/util/attr_types.hpp index 679a432ac5c2b7..c14e996e8a5571 100644 --- a/ngraph/core/include/ngraph/op/util/attr_types.hpp +++ b/ngraph/core/include/ngraph/op/util/attr_types.hpp @@ -18,20 +18,7 @@ enum class PadMode { CONSTANT = 0, EDGE, REFLECT, SYMMETRIC }; NGRAPH_API std::ostream& operator<<(std::ostream& s, const PadMode& type); -} // namespace op - -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(op::PadMode& value) : EnumAttributeAdapterBase(value) {} - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -namespace op { /// \brief Padding Type used for `Convolution` and `Pooling` /// /// Follows ONNX padding type definitions @@ -57,20 +44,7 @@ enum class PadType { NGRAPH_API std::ostream& operator<<(std::ostream& s, const PadType& type); -} // namespace op - -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(op::PadType& value) : EnumAttributeAdapterBase(value) {} - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -namespace op { /// \brief Rounding Type used for `Pooling` operators. enum class RoundingType { FLOOR = 0, @@ -79,20 +53,7 @@ enum class RoundingType { NGRAPH_API std::ostream& operator<<(std::ostream& s, const RoundingType& type); -} // namespace op - -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(op::RoundingType& value) : EnumAttributeAdapterBase(value) {} - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -namespace op { /// \brief Specifies the algorithm to use for implicit broadcasting of a tensor /// to align with another tensor /// @@ -140,8 +101,6 @@ enum class AutoBroadcastType { NGRAPH_API std::ostream& operator<<(std::ostream& s, const AutoBroadcastType& type); -} // namespace op -namespace op { /// \brief BroadcastType specifies rules used for mapping of input tensor axes to output /// shape axes. /// @@ -162,31 +121,7 @@ enum class BroadcastType { NONE, EXPLICIT = NONE, NUMPY, PDPD, BIDIRECTIONAL }; NGRAPH_API std::ostream& operator<<(std::ostream& s, const BroadcastType& type); -} // namespace op - -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(op::AutoBroadcastType& value) : EnumAttributeAdapterBase(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(op::BroadcastType& value) : EnumAttributeAdapterBase(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; -namespace op { /// \brief Specifies how eps is combined with L2 value enum class EpsMode { // Add bias to norm @@ -197,20 +132,7 @@ enum class EpsMode { NGRAPH_API std::ostream& operator<<(std::ostream& s, const EpsMode& type); -} // namespace op - -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(op::EpsMode& value) : EnumAttributeAdapterBase(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; -namespace op { enum class TopKSortType { // Returned values are not sorte NONE, @@ -222,20 +144,7 @@ enum class TopKSortType { NGRAPH_API std::ostream& operator<<(std::ostream& s, const TopKSortType& type); -} // namespace op -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(op::TopKSortType& value) : EnumAttributeAdapterBase(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -namespace op { enum class TopKMode { MAX, MIN, @@ -243,20 +152,7 @@ enum class TopKMode { NGRAPH_API std::ostream& operator<<(std::ostream& s, const TopKMode& type); -} // namespace op - -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(op::TopKMode& value) : EnumAttributeAdapterBase(value) {} - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -namespace op { /// \brief Implicit broadcast specification struct NGRAPH_API AutoBroadcastSpec { AutoBroadcastSpec() : m_type(AutoBroadcastType::NONE), m_axis(0) {} @@ -280,24 +176,7 @@ struct NGRAPH_API AutoBroadcastSpec { private: AutoBroadcastType type_from_string(const std::string& type) const; }; -} // namespace op -template <> -class AttributeAdapter : public VisitorAdapter { -public: - AttributeAdapter(op::AutoBroadcastSpec& value) : m_ref(value) {} - bool visit_attributes(AttributeVisitor& visitor) override; - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } - -protected: - op::AutoBroadcastSpec& m_ref; -}; - -namespace op { /// \brief Implicit broadcast specification struct NGRAPH_API BroadcastModeSpec { BroadcastModeSpec() : m_type(BroadcastType::NUMPY), m_axis(0) {} @@ -312,43 +191,151 @@ struct NGRAPH_API BroadcastModeSpec { return a.m_type == m_type && a.m_axis == m_axis; } }; + +/// +/// \brief This class defines possible recurrent sequence directions. +/// +enum class RecurrentSequenceDirection { FORWARD, REVERSE, BIDIRECTIONAL }; + +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const RecurrentSequenceDirection& direction); } // namespace op +} // namespace ngraph + +namespace ov { +template <> +class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ngraph::op::PadMode& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ngraph::op::PadType& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ngraph::op::RoundingType& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ngraph::op::AutoBroadcastType& value) + : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ngraph::op::BroadcastType& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ngraph::op::EpsMode& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ngraph::op::TopKSortType& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; template <> -class AttributeAdapter : public VisitorAdapter { +class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::BroadcastModeSpec& value) : m_ref(value) {} + AttributeAdapter(ngraph::op::TopKMode& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class AttributeAdapter : public VisitorAdapter { +public: + AttributeAdapter(ngraph::op::AutoBroadcastSpec& value) : m_ref(value) {} bool visit_attributes(AttributeVisitor& visitor) override; - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } protected: - op::BroadcastModeSpec& m_ref; + ngraph::op::AutoBroadcastSpec& m_ref; }; -namespace op { -/// -/// \brief This class defines possible recurrent sequence directions. -/// -enum class RecurrentSequenceDirection { FORWARD, REVERSE, BIDIRECTIONAL }; +template <> +class AttributeAdapter : public VisitorAdapter { +public: + AttributeAdapter(ngraph::op::BroadcastModeSpec& value) : m_ref(value) {} + bool visit_attributes(AttributeVisitor& visitor) override; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const RecurrentSequenceDirection& direction); -} // namespace op + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } + +protected: + ngraph::op::BroadcastModeSpec& m_ref; +}; template <> -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::RecurrentSequenceDirection& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::RecurrentSequenceDirection& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 0cc89d9c387825..16919a8a21b5f0 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -295,6 +295,9 @@ using MultiSubgraphOutputDescriptionVector = util::MultiSubGraphOp::MultiSubgrap } // namespace util } // namespace op +} // namespace ngraph + +namespace ov { template <> class NGRAPH_API AttributeAdapter>> @@ -317,4 +320,5 @@ class NGRAPH_API AttributeAdapter -class NGRAPH_API AttributeAdapter - : public EnumAttributeAdapterBase { +class NGRAPH_API AttributeAdapter + : public EnumAttributeAdapterBase { public: - AttributeAdapter(op::util::NmsBase::SortResultType& value) - : EnumAttributeAdapterBase(value) {} + AttributeAdapter(ngraph::op::util::NmsBase::SortResultType& value) + : EnumAttributeAdapterBase(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/op/util/variable.hpp b/ngraph/core/include/ngraph/op/util/variable.hpp index 3deabe11fea90d..04c873bb3ab85c 100644 --- a/ngraph/core/include/ngraph/op/util/variable.hpp +++ b/ngraph/core/include/ngraph/op/util/variable.hpp @@ -40,16 +40,21 @@ class NGRAPH_API Variable { }; using VariablePtr = std::shared_ptr; using VariableVector = std::vector; +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { +class NGRAPH_API AttributeAdapter> + : public DirectValueAccessor> { public: - explicit AttributeAdapter(std::shared_ptr& value) - : DirectValueAccessor>(value) {} + explicit AttributeAdapter(std::shared_ptr& value) + : DirectValueAccessor>(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/runtime/aligned_buffer.hpp b/ngraph/core/include/ngraph/runtime/aligned_buffer.hpp index 729bb47c217743..2dde201c20bd92 100644 --- a/ngraph/core/include/ngraph/runtime/aligned_buffer.hpp +++ b/ngraph/core/include/ngraph/runtime/aligned_buffer.hpp @@ -63,15 +63,19 @@ class NGRAPH_API AlignedBuffer { size_t m_byte_size; }; } // namespace runtime +} // namespace ngraph + +namespace ov { template <> -class NGRAPH_API AttributeAdapter> - : public DirectValueAccessor> { +class NGRAPH_API AttributeAdapter> + : public DirectValueAccessor> { public: - AttributeAdapter(std::shared_ptr& value); + AttributeAdapter(std::shared_ptr& value); static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} // namespace ngraph + +} // namespace ov diff --git a/ngraph/core/include/ngraph/shape.hpp b/ngraph/core/include/ngraph/shape.hpp index ffd3fc05faa737..ae3b25b261e18d 100644 --- a/ngraph/core/include/ngraph/shape.hpp +++ b/ngraph/core/include/ngraph/shape.hpp @@ -35,18 +35,6 @@ class Shape : public std::vector { NGRAPH_API Shape& operator=(Shape&& v) noexcept; }; -template <> -class NGRAPH_API AttributeAdapter : public IndirectVectorValueAccessor> - -{ -public: - AttributeAdapter(Shape& value) : IndirectVectorValueAccessor>(value) {} - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - /// Number of elements in spanned by a shape template size_t shape_size(const SHAPE_TYPE& shape) { @@ -92,3 +80,19 @@ inline bool is_vector(const SHAPE_TYPE& shape) { NGRAPH_API std::ostream& operator<<(std::ostream& s, const Shape& shape); } // namespace ngraph + +namespace ov { + +template <> +class NGRAPH_API AttributeAdapter + : public IndirectVectorValueAccessor> + +{ +public: + AttributeAdapter(ngraph::Shape& value) : IndirectVectorValueAccessor>(value) {} + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; +} // namespace ov diff --git a/ngraph/core/include/ngraph/strides.hpp b/ngraph/core/include/ngraph/strides.hpp index 67f73829110420..c07c2d79c8acb3 100644 --- a/ngraph/core/include/ngraph/strides.hpp +++ b/ngraph/core/include/ngraph/strides.hpp @@ -33,18 +33,24 @@ class Strides : public std::vector { NGRAPH_API Strides& operator=(Strides&& v) noexcept; }; +NGRAPH_API +std::ostream& operator<<(std::ostream& s, const Strides& strides); +} // namespace ngraph + +namespace ov { + template <> -class NGRAPH_API AttributeAdapter : public IndirectVectorValueAccessor> +class NGRAPH_API AttributeAdapter + : public IndirectVectorValueAccessor> { public: - AttributeAdapter(Strides& value) : IndirectVectorValueAccessor>(value) {} + AttributeAdapter(ngraph::Strides& value) + : IndirectVectorValueAccessor>(value) {} static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -NGRAPH_API -std::ostream& operator<<(std::ostream& s, const Strides& strides); -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/openvino/core/attribute_adapter.hpp b/ngraph/core/include/openvino/core/attribute_adapter.hpp new file mode 100644 index 00000000000000..1cab9a7299d572 --- /dev/null +++ b/ngraph/core/include/openvino/core/attribute_adapter.hpp @@ -0,0 +1,474 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" +#include "openvino/core/enum_names.hpp" +#include "openvino/core/type.hpp" + +/// +namespace ov { +class AttributeVisitor; + +/// \brief Provides access to an attribute of type AT as a value accessor type VAT +template +class ValueAccessor; + +/// \brief ValueAccessor provides an accessor for values that do not have get/set methonds +/// via AttributeVistor.on_adapter. +/// +/// All ValueAccessors must be derived from ValueAccessor so that an AttributeVisitor +/// only needs to implement a subset of the on_adapter methods. +template <> +class OPENVINO_API ValueAccessor { +public: + /// \brief type info enables identification of the value accessor, as well as is_type and + /// as_type. + virtual const DiscreteTypeInfo& get_type_info() const = 0; + virtual ~ValueAccessor() = default; +}; + +/// \brief Provides access to values via get/set methods from an m_value, typically from +/// ValueReference +/// +/// The m_buffer holds a VAT, which may be wider than the attribute AT. For example, serializers +/// that only +/// support int64_t integers would use a ValueAccessor> to reference a +/// vector attribute. Destruction moves the value back to the attribute if it was +/// changed. +/// \tparam VAT The adapter value type; may be wider than the value being accessed. +template +class ValueAccessor : public ValueAccessor { +public: + /// Returns the value + virtual const VAT& get() = 0; + /// Sets the value + virtual void set(const VAT& value) = 0; +}; + +template <> +class ValueAccessor : public ValueAccessor { +public: + virtual void* get_ptr() = 0; + virtual size_t size() = 0; +}; + +template +class DirectValueAccessor : public ValueAccessor { +public: + DirectValueAccessor(AT& ref) : m_ref(ref) {} + const AT& get() override { + return m_ref; + } + void set(const AT& value) override { + m_ref = value; + } + +protected: + AT& m_ref; +}; + +template +class IndirectScalarValueAccessor : public ValueAccessor { +public: + IndirectScalarValueAccessor(AT& ref) : m_ref(ref), m_buffer() {} + + const VAT& get() override { + if (!m_buffer_valid) { + m_buffer = static_cast(m_ref); + m_buffer_valid = true; + } + return m_buffer; + } + + void set(const VAT& value) override { + m_ref = static_cast(value); + m_buffer_valid = false; + } + +protected: + AT& m_ref; + VAT m_buffer; + bool m_buffer_valid{false}; +}; + +template +A copy_from(B& b) { + A result(b.size()); + for (size_t i = 0; i < b.size(); ++i) { + result[i] = static_cast::type>(b[i]); + } + return result; +} + +template +class IndirectVectorValueAccessor : public ValueAccessor { +public: + IndirectVectorValueAccessor(AT& ref) : m_ref(ref) {} + + const VAT& get() override { + if (!m_buffer_valid) { + m_buffer = ov::copy_from::type>(m_ref); + m_buffer_valid = true; + } + return m_buffer; + } + + void set(const VAT& value) override { + m_ref = copy_from(value); + m_buffer_valid = false; + } + + operator AT&() { + return m_ref; + } + +protected: + AT& m_ref; + VAT m_buffer; + bool m_buffer_valid{false}; +}; + +/// \brief An AttributeAdapter "captures" an attribute as an AT& and makes it available as a +/// ValueAccessor. +template +class AttributeAdapter {}; + +/// \brief Access an enum via a string +/// \tparam AT The attribute type enum class +template +class EnumAttributeAdapterBase : public ValueAccessor { +public: + EnumAttributeAdapterBase(AT& value) : m_ref(value) {} + + const std::string& get() override { + return as_string(m_ref); + } + void set(const std::string& value) override { + m_ref = as_enum(value); + } + operator AT&() { + return m_ref; + } + +protected: + AT& m_ref; +}; + +/// Adapters will see visitor +class VisitorAdapter : public ValueAccessor { +public: + virtual bool visit_attributes(AttributeVisitor& visitor) = 0; +}; + +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(float& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a double as a double +template <> +class OPENVINO_API AttributeAdapter : public DirectValueAccessor { +public: + AttributeAdapter(double& value) : DirectValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a string as a string +template <> +class OPENVINO_API AttributeAdapter : public DirectValueAccessor { +public: + AttributeAdapter(std::string& value) : DirectValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a bool as a bool +template <> +class OPENVINO_API AttributeAdapter : public DirectValueAccessor { +public: + AttributeAdapter(bool& value) : DirectValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access an int8_t and an int64_t +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(int8_t& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access an int16_t as an int64_t +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(int16_t& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access an int32_t as an int64_t +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(int32_t& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access an int64_t as an int64_t +template <> +class OPENVINO_API AttributeAdapter : public DirectValueAccessor { +public: + AttributeAdapter(int64_t& value) : DirectValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a uint8_t as an int64_t +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(uint8_t& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a uint16_t as an int64_t +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(uint16_t& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a uint32_t as an int64_t +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(uint32_t& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a uint64_t as an int64_t +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(uint64_t& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +#ifdef __APPLE__ +// size_t is one of the uint types on _WIN32 +template <> +class OPENVINO_API AttributeAdapter : public IndirectScalarValueAccessor { +public: + AttributeAdapter(size_t& value) : IndirectScalarValueAccessor(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class OPENVINO_API AttributeAdapter> + : public IndirectVectorValueAccessor, std::vector> { +public: + AttributeAdapter(std::vector& value) + : IndirectVectorValueAccessor, std::vector>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; +#endif + +/// Note: These class bodies cannot be defined with templates because of interactions +/// between dllexport and templates on Windows. + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +/// \brief Access a vector +template <> +class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { +public: + AttributeAdapter(std::vector& value) : DirectValueAccessor>(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; +} // namespace ov diff --git a/ngraph/core/include/openvino/core/attribute_visitor.hpp b/ngraph/core/include/openvino/core/attribute_visitor.hpp new file mode 100644 index 00000000000000..fa23b48901f83d --- /dev/null +++ b/ngraph/core/include/openvino/core/attribute_visitor.hpp @@ -0,0 +1,140 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "openvino/core/partial_shape.hpp" +#include "openvino/core/type.hpp" +#include "openvino/core/type/element_type.hpp" + +namespace ngraph { +class Node; +} +namespace ov { +class Function; +template +class ValueAccessor; +template +class AttributeAdapter; +class VisitorAdapter; + +/// \brief Visits the attributes of a node, primarily for serialization-like tasks. +/// +/// Attributes are the node parameters that are always compile-time constants. +/// Values computed from the graph topology and attributes during compilation are not +/// attributes. +/// +/// Attributes have a wide variety of types, but serialization formats are more restricted. +/// We asume serialation easily supports scalar types of bool 64-bit signed, string, and double, +/// and has specialized ways to support numeric arrays and raw data+size. The visitor and +/// adapter convert between the limited serialization types and the unlimited attribute types. +/// +/// A visitor is passed to an op's visit_attributes method. The visit_attributes method calls +/// the template method visitor.on_attribute(const std::string& name, AT& value) on each +/// attribute. The visitor can read or write the attribute's value. The on_attribute +/// method creates an AttributeAdapter for the value and passes it to one of the visitors +/// on_adapter methods. The on_adapter methods expect a reference to a ValueAccessor or a +/// VisitorAdapter. A ValueAccessor has get/set methods that can be used to read/write the +/// attribute value as type VAT. These methods are triggered by deriving AttributeAdapter +/// from ValueAccessor. For more complex cases, such as structs, the on_adapter method for +/// VisitorAdapter passes the name and visitor to the adapter, so that the adapter can perform +/// additional work such as visiting struct members or sequence values. +/// +/// When a node visits an attribute with structure, the node's on_attribute passes a name for +/// the entire attribute, but the struct will have its own methods to be visited. Similarly, a +/// vector will have a sequence of members to be visited. The adapter may use the visitor +/// methods start_struct/finish_struct and start_vector/next_vector/finish_vector to inidicate +/// nexted members. +/// +/// The visitor method get_name_with_context creates a generic nested version of the name. +/// Visitors can override according to their serialization requirements. +/// +/// Attributes that are shared_ptr are special. They must have been already been +/// registered with the visitor using register_node, which needs a shared pointer to a node and +/// a string ID. The ID string will be used to serialize the node or find the node during +/// deserialization. +class OPENVINO_API AttributeVisitor { +public: + virtual ~AttributeVisitor() = default; + // Must implement these methods + /// \brief handles all specialized on_adapter methods implemented by the visitor. + /// + /// The adapter implements get_type_info(), which can be used to determine the adapter + /// directly + /// or via is_type and as_type on any platform + virtual void on_adapter(const std::string& name, ValueAccessor& adapter) = 0; + // The remaining adapter methods fall back on the void adapter if not implemented + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + /// \brief Hook for adapters that need visitor access + virtual void on_adapter(const std::string& name, VisitorAdapter& adapter); + + /// \brief Provides API to handle nGraph Function attribute type, accessed as ValueAccessor + /// \param name attribute name + /// \param adapter reference to a Function ValueAccessor + virtual void on_adapter(const std::string& name, ValueAccessor>& adapter); + + /// The generic visitor. There must be a definition of AttributeAdapter that can convert + /// to a ValueAccessor for one of the on_adpater methods. + template + void on_attribute(const std::string& name, AT& value) { + AttributeAdapter adapter(value); + start_structure(name); + on_adapter(get_name_with_context(), adapter); + finish_structure(); + } + /// \returns The nested context of visits + const std::vector& get_context() const { + return m_context; + } + /// \returns context prepended to names + virtual std::string get_name_with_context(); + /// \brief Start visiting a nested structure + virtual void start_structure(const std::string& name); + /// \brief Finish visiting a nested structure + virtual std::string finish_structure(); + using node_id_t = std::string; + static const node_id_t invalid_node_id; + /// \brief Associate a node with an id. + /// + /// No node may be used as an attribute unless it has already been registered with an ID. + /// References to nodes are visited with a ValueAccessor of their ID. + virtual void register_node(const std::shared_ptr& node, node_id_t id = invalid_node_id); + /// Returns the node with the given id, or nullptr if there is no registered node + virtual std::shared_ptr get_registered_node(node_id_t id); + /// Returns the id for the node, or -1 if the node is not registered + virtual node_id_t get_registered_node_id(const std::shared_ptr& node); + +protected: + std::vector m_context; + std::unordered_map, node_id_t> m_node_id_map; + std::unordered_map> m_id_node_map; +}; +} // namespace ov diff --git a/ngraph/core/include/openvino/core/enum_names.hpp b/ngraph/core/include/openvino/core/enum_names.hpp new file mode 100644 index 00000000000000..be32a7bdea8b92 --- /dev/null +++ b/ngraph/core/include/openvino/core/enum_names.hpp @@ -0,0 +1,70 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "ngraph/check.hpp" + +namespace ov { +/// Uses a pairings defined by EnumTypes::get() to convert between strings +/// and enum values. +template +class EnumNames { +public: + /// Converts strings to enum values + static EnumType as_enum(const std::string& name) { + auto to_lower = [](const std::string& s) { + std::string rc = s; + std::transform(rc.begin(), rc.end(), rc.begin(), [](char c) { + return static_cast(::tolower(static_cast(c))); + }); + return rc; + }; + for (const auto& p : get().m_string_enums) { + if (to_lower(p.first) == to_lower(name)) { + return p.second; + } + } + NGRAPH_CHECK(false, "\"", name, "\"", " is not a member of enum ", get().m_enum_name); + } + + /// Converts enum values to strings + static const std::string& as_string(EnumType e) { + for (const auto& p : get().m_string_enums) { + if (p.second == e) { + return p.first; + } + } + NGRAPH_CHECK(false, " invalid member of enum ", get().m_enum_name); + } + +private: + /// Creates the mapping. + EnumNames(const std::string& enum_name, const std::vector> string_enums) + : m_enum_name(enum_name), + m_string_enums(string_enums) {} + + /// Must be defined to returns a singleton for each supported enum class + static EnumNames& get(); + + const std::string m_enum_name; + std::vector> m_string_enums; +}; + +/// Returns the enum value matching the string +template +typename std::enable_if::value, Type>::type as_enum(const Value& value) { + return EnumNames::as_enum(value); +} + +/// Returns the string matching the enum value +template +const std::string& as_string(Value value) { + return EnumNames::as_string(value); +} +} // namespace ov diff --git a/ngraph/core/include/openvino/core/function.hpp b/ngraph/core/include/openvino/core/function.hpp index 81607040deae82..76f7a904591265 100644 --- a/ngraph/core/include/openvino/core/function.hpp +++ b/ngraph/core/include/openvino/core/function.hpp @@ -272,8 +272,6 @@ class OPENVINO_API Function { ngraph::VariableVector m_variables; }; -} // namespace ov -namespace ngraph { template <> class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> { @@ -286,4 +284,4 @@ class NGRAPH_API AttributeAdapter> return type_info; } }; -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/openvino/core/partial_shape.hpp b/ngraph/core/include/openvino/core/partial_shape.hpp index 34b59d7ab47016..eff5c651d36574 100644 --- a/ngraph/core/include/openvino/core/partial_shape.hpp +++ b/ngraph/core/include/openvino/core/partial_shape.hpp @@ -375,9 +375,6 @@ PartialShape operator+(const PartialShape& s1, const PartialShape& s2); OPENVINO_API std::ostream& operator<<(std::ostream& str, const PartialShape& shape); -} // namespace ov -namespace ngraph { - template <> class OPENVINO_API AttributeAdapter : public ValueAccessor> { public: @@ -398,4 +395,4 @@ class OPENVINO_API AttributeAdapter : public ValueAccessor m_buffer; bool m_buffer_valid{false}; }; -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/include/openvino/core/type/element_type.hpp b/ngraph/core/include/openvino/core/type/element_type.hpp index b3ccc0e02199be..88fb9d70327588 100644 --- a/ngraph/core/include/openvino/core/type/element_type.hpp +++ b/ngraph/core/include/openvino/core/type/element_type.hpp @@ -165,10 +165,6 @@ OPENVINO_API std::ostream& operator<<(std::ostream& out, const ov::element::Type& obj); } // namespace element -} // namespace ov - -namespace ngraph { - template <> class OPENVINO_API AttributeAdapter : public EnumAttributeAdapterBase { public: @@ -199,4 +195,4 @@ class OPENVINO_API AttributeAdapter : public ValueAccessor::type_info; constexpr DiscreteTypeInfo AttributeAdapter::type_info; constexpr DiscreteTypeInfo AttributeAdapter::type_info; @@ -47,4 +47,4 @@ constexpr DiscreteTypeInfo AttributeAdapter>::type_info; constexpr DiscreteTypeInfo AttributeAdapter>::type_info; constexpr DiscreteTypeInfo AttributeAdapter>::type_info; constexpr DiscreteTypeInfo AttributeAdapter>::type_info; -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/attribute_visitor.cpp b/ngraph/core/src/attribute_visitor.cpp index 9beec812c2bae0..23bc044ae66cdb 100644 --- a/ngraph/core/src/attribute_visitor.cpp +++ b/ngraph/core/src/attribute_visitor.cpp @@ -9,135 +9,134 @@ #include "ngraph/node.hpp" using namespace std; -using namespace ngraph; -void AttributeVisitor::start_structure(const string& name) { +void ov::AttributeVisitor::start_structure(const string& name) { m_context.push_back(name); } -string AttributeVisitor::finish_structure() { +string ov::AttributeVisitor::finish_structure() { string result = m_context.back(); m_context.pop_back(); return result; } -string AttributeVisitor::get_name_with_context() { +string ov::AttributeVisitor::get_name_with_context() { ostringstream result; string sep = ""; - for (auto c : m_context) { + for (const auto& c : m_context) { result << sep << c; sep = "."; } return result.str(); } -void AttributeVisitor::on_adapter(const std::string& name, VisitorAdapter& adapter) { +void ov::AttributeVisitor::on_adapter(const std::string& name, VisitorAdapter& adapter) { adapter.visit_attributes(*this); } -void AttributeVisitor::on_adapter(const std::string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const std::string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); }; -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); }; -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -void AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { +void ov::AttributeVisitor::on_adapter(const string& name, ValueAccessor>& adapter) { on_adapter(name, static_cast&>(adapter)); } -const AttributeVisitor::node_id_t AttributeVisitor::invalid_node_id = ""; +const ov::AttributeVisitor::node_id_t ov::AttributeVisitor::invalid_node_id = ""; -void AttributeVisitor::register_node(const std::shared_ptr& node, node_id_t id) { +void ov::AttributeVisitor::register_node(const std::shared_ptr& node, node_id_t id) { if (id == invalid_node_id) { id = node->get_friendly_name(); } @@ -145,12 +144,13 @@ void AttributeVisitor::register_node(const std::shared_ptr& node, node_id_ m_node_id_map[node] = id; } -std::shared_ptr AttributeVisitor::get_registered_node(node_id_t id) { +std::shared_ptr ov::AttributeVisitor::get_registered_node(node_id_t id) { auto it = m_id_node_map.find(id); - return it == m_id_node_map.end() ? shared_ptr() : it->second; + return it == m_id_node_map.end() ? shared_ptr() : it->second; } -AttributeVisitor::node_id_t AttributeVisitor::get_registered_node_id(const std::shared_ptr& node) { +ov::AttributeVisitor::node_id_t ov::AttributeVisitor::get_registered_node_id( + const std::shared_ptr& node) { auto it = m_node_id_map.find(node); return it == m_node_id_map.end() ? invalid_node_id : it->second; } diff --git a/ngraph/core/src/axis_set.cpp b/ngraph/core/src/axis_set.cpp index 38dd5e29354b9b..fcc623dc646ead 100644 --- a/ngraph/core/src/axis_set.cpp +++ b/ngraph/core/src/axis_set.cpp @@ -37,7 +37,7 @@ std::ostream& ngraph::operator<<(std::ostream& s, const AxisSet& axis_set) { return s; } -const std::vector& ngraph::AttributeAdapter::get() { +const std::vector& ov::AttributeAdapter::get() { if (!m_buffer_valid) { m_buffer.clear(); for (auto elt : m_ref) { @@ -48,12 +48,12 @@ const std::vector& ngraph::AttributeAdapter::get() { return m_buffer; } -void ngraph::AttributeAdapter::set(const std::vector& value) { - m_ref = AxisSet(); +void ov::AttributeAdapter::set(const std::vector& value) { + m_ref = ngraph::AxisSet(); for (auto elt : value) { m_ref.insert(elt); } m_buffer_valid = false; } -constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; +constexpr ov::DiscreteTypeInfo ov::AttributeAdapter::type_info; diff --git a/ngraph/core/src/axis_vector.cpp b/ngraph/core/src/axis_vector.cpp index 5bf209c5386aef..33052a964968fc 100644 --- a/ngraph/core/src/axis_vector.cpp +++ b/ngraph/core/src/axis_vector.cpp @@ -35,4 +35,4 @@ ngraph::AxisVector& ngraph::AxisVector::operator=(AxisVector&& v) noexcept { return *this; } -constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; +constexpr ov::DiscreteTypeInfo ov::AttributeAdapter::type_info; diff --git a/ngraph/core/src/coordinate.cpp b/ngraph/core/src/coordinate.cpp index a3353e5461ffc8..f1b9c17feca70a 100644 --- a/ngraph/core/src/coordinate.cpp +++ b/ngraph/core/src/coordinate.cpp @@ -7,7 +7,6 @@ #include "ngraph/util.hpp" using namespace std; -using namespace ngraph; std::ostream& ngraph::operator<<(std::ostream& s, const Coordinate& coordinate) { s << "Coordinate{"; @@ -41,4 +40,4 @@ ngraph::Coordinate& ngraph::Coordinate::operator=(Coordinate&& v) noexcept { return *this; } -constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; +constexpr ov::DiscreteTypeInfo ov::AttributeAdapter::type_info; diff --git a/ngraph/core/src/coordinate_diff.cpp b/ngraph/core/src/coordinate_diff.cpp index 849a9e21ca04c0..856a4e2ead9bda 100644 --- a/ngraph/core/src/coordinate_diff.cpp +++ b/ngraph/core/src/coordinate_diff.cpp @@ -40,4 +40,4 @@ ngraph::CoordinateDiff& ngraph::CoordinateDiff::operator=(CoordinateDiff&& v) no return *this; } -constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; +constexpr ov::DiscreteTypeInfo ov::AttributeAdapter::type_info; diff --git a/ngraph/core/src/distributed.cpp b/ngraph/core/src/distributed.cpp index ee4d014457514f..5849ef9d2b59d3 100644 --- a/ngraph/core/src/distributed.cpp +++ b/ngraph/core/src/distributed.cpp @@ -7,22 +7,19 @@ #include "ngraph/log.hpp" #include "ngraph/type.hpp" -using namespace ngraph; - -namespace ngraph { +namespace ov { template <> -EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("reduction::Type", - {{"SUM", reduction::Type::SUM}, - {"PROD", reduction::Type::PROD}, - {"MIN", reduction::Type::MIN}, - {"MAX", reduction::Type::MAX}}); +EnumNames& EnumNames::get() { + static auto enum_names = ov::EnumNames("reduction::Type", + {{"SUM", ngraph::reduction::Type::SUM}, + {"PROD", ngraph::reduction::Type::PROD}, + {"MIN", ngraph::reduction::Type::MIN}, + {"MAX", ngraph::reduction::Type::MAX}}); return enum_names; } +constexpr DiscreteTypeInfo AttributeAdapter::type_info; +} // namespace ov -constexpr DiscreteTypeInfo AttributeAdapter::type_info; -} // namespace ngraph - -std::ostream& reduction::operator<<(std::ostream& out, const reduction::Type& obj) { +std::ostream& ngraph::reduction::operator<<(std::ostream& out, const ngraph::reduction::Type& obj) { return out << as_string(obj); } diff --git a/ngraph/core/src/node.cpp b/ngraph/core/src/node.cpp index 87524021306f78..96253cf4ba09c6 100644 --- a/ngraph/core/src/node.cpp +++ b/ngraph/core/src/node.cpp @@ -835,6 +835,7 @@ bool Node::constant_fold(OutputVector& output_values, const OutputVector& input_ return false; } +namespace ov { constexpr DiscreteTypeInfo AttributeAdapter>::type_info; AttributeAdapter>::AttributeAdapter(std::shared_ptr& value) : m_ref(value) {} @@ -874,3 +875,4 @@ bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { } return true; } +} // namespace ov diff --git a/ngraph/core/src/op/binary_convolution.cpp b/ngraph/core/src/op/binary_convolution.cpp index c8775d6bca42e5..ff5c804e288365 100644 --- a/ngraph/core/src/op/binary_convolution.cpp +++ b/ngraph/core/src/op/binary_convolution.cpp @@ -117,7 +117,7 @@ bool op::v1::BinaryConvolution::visit_attributes(AttributeVisitor& visitor) { return true; } -namespace ngraph { +namespace ov { template <> NGRAPH_API EnumNames& EnumNames::get() { @@ -128,11 +128,11 @@ EnumNames::get() { } constexpr DiscreteTypeInfo AttributeAdapter::type_info; +} // namespace ov std::ostream& operator<<(std::ostream& s, const op::v1::BinaryConvolution::BinaryConvolutionMode& type) { return s << as_string(type); } -} // namespace ngraph op::v1::BinaryConvolution::BinaryConvolutionMode op::v1::BinaryConvolution::mode_from_string( const std::string& mode) const { diff --git a/ngraph/core/src/op/depth_to_space.cpp b/ngraph/core/src/op/depth_to_space.cpp index 8e25c41865d56d..8b6eee758dd6b5 100644 --- a/ngraph/core/src/op/depth_to_space.cpp +++ b/ngraph/core/src/op/depth_to_space.cpp @@ -113,7 +113,11 @@ bool op::DepthToSpace::has_evaluate() const { return !get_input_partial_shape(0).is_dynamic(); } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::DepthToSpace::DepthToSpaceMode& type) { + return s << as_string(type); +} + +namespace ov { template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -124,8 +128,4 @@ NGRAPH_API EnumNames& EnumNames::type_info; - -std::ostream& operator<<(std::ostream& s, const op::DepthToSpace::DepthToSpaceMode& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/gelu.cpp b/ngraph/core/src/op/gelu.cpp index 272023cdfe2d23..27152cedf2425e 100644 --- a/ngraph/core/src/op/gelu.cpp +++ b/ngraph/core/src/op/gelu.cpp @@ -51,7 +51,7 @@ void op::v0::Gelu::validate_and_infer_types() { // ------------------------------ V7 ------------------------------ -namespace ngraph { +namespace ov { template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -61,11 +61,10 @@ NGRAPH_API EnumNames& EnumNames::type_info; - +} // namespace ov std::ostream& op::operator<<(std::ostream& s, const op::GeluApproximationMode& type) { return s << as_string(type); } -} // namespace ngraph NGRAPH_RTTI_DEFINITION(op::v7::Gelu, "Gelu", 7); diff --git a/ngraph/core/src/op/interpolate.cpp b/ngraph/core/src/op/interpolate.cpp index 42359cde32ca26..8aff95c9b8e56a 100644 --- a/ngraph/core/src/op/interpolate.cpp +++ b/ngraph/core/src/op/interpolate.cpp @@ -69,7 +69,11 @@ shared_ptr op::v0::Interpolate::clone_with_new_inputs(const OutputVector& return make_shared(new_args.at(0), new_args.at(1), m_attrs); } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::v0::Interpolate::InterpolateMode& type) { + return s << as_string(type); +} + +namespace ov { template <> EnumNames& EnumNames::get() { static auto enum_names = @@ -83,10 +87,7 @@ EnumNames& EnumNames::type_info; -std::ostream& operator<<(std::ostream& s, const op::v0::Interpolate::InterpolateMode& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov // Interpolate v4 @@ -479,7 +480,23 @@ bool op::v4::Interpolate::has_evaluate() const { return false; } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::v4::Interpolate::InterpolateMode& type) { + return s << as_string(type); +} + +std::ostream& ngraph::operator<<(std::ostream& s, const op::v4::Interpolate::ShapeCalcMode& type) { + return s << as_string(type); +} + +std::ostream& ngraph::operator<<(std::ostream& s, const op::v4::Interpolate::CoordinateTransformMode& type) { + return s << as_string(type); +} + +std::ostream& ngraph::operator<<(std::ostream& s, const op::v4::Interpolate::NearestMode& type) { + return s << as_string(type); +} + +namespace ov { template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -493,10 +510,6 @@ NGRAPH_API EnumNames& EnumNames::type_info; -std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::InterpolateMode& type) { - return s << as_string(type); -} - template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -507,10 +520,6 @@ NGRAPH_API EnumNames& EnumNames::type_info; -std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::ShapeCalcMode& type) { - return s << as_string(type); -} - template <> NGRAPH_API EnumNames& EnumNames::get() { @@ -526,10 +535,6 @@ EnumNames::get() { constexpr DiscreteTypeInfo AttributeAdapter::type_info; -std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::CoordinateTransformMode& type) { - return s << as_string(type); -} - template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -543,8 +548,4 @@ NGRAPH_API EnumNames& EnumNames::type_info; - -std::ostream& operator<<(std::ostream& s, const op::v4::Interpolate::NearestMode& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/loop.cpp b/ngraph/core/src/op/loop.cpp index ededa0bb74ecc1..3b1b1b2064d22d 100644 --- a/ngraph/core/src/op/loop.cpp +++ b/ngraph/core/src/op/loop.cpp @@ -306,6 +306,6 @@ op::v5::Loop::Loop(const op::v5::Loop& other) : SubGraphOp() { other.clone_to(*this, other.input_values()); } -namespace ngraph { +namespace ov { constexpr DiscreteTypeInfo AttributeAdapter::type_info; } diff --git a/ngraph/core/src/op/lstm_cell.cpp b/ngraph/core/src/op/lstm_cell.cpp index 39ef9be673208c..9dfd9b2a4e7ed1 100644 --- a/ngraph/core/src/op/lstm_cell.cpp +++ b/ngraph/core/src/op/lstm_cell.cpp @@ -333,7 +333,7 @@ shared_ptr op::v0::LSTMCell::clone_with_new_inputs(const OutputVector& new } } -namespace ngraph { +namespace ov { template <> EnumNames& EnumNames::get() { static auto enum_names = EnumNames("op::LSTMWeightsFormat", @@ -347,10 +347,11 @@ EnumNames& EnumNames::get() { constexpr DiscreteTypeInfo AttributeAdapter::type_info; +} // namespace ov + std::ostream& operator<<(std::ostream& s, const op::LSTMWeightsFormat& type) { return s << as_string(type); } -} // namespace ngraph op::v4::LSTMCell::LSTMCell() { m_activations = {"sigmoid", "tanh", "tanh"}; diff --git a/ngraph/core/src/op/matrix_nms.cpp b/ngraph/core/src/op/matrix_nms.cpp index 117ed5e2e120af..6a5af0f0d47492 100644 --- a/ngraph/core/src/op/matrix_nms.cpp +++ b/ngraph/core/src/op/matrix_nms.cpp @@ -64,7 +64,11 @@ bool ngraph::op::v8::MatrixNms::visit_attributes(AttributeVisitor& visitor) { return true; } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::v8::MatrixNms::DecayFunction& type) { + return s << as_string(type); +} + +namespace ov { template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = @@ -76,7 +80,4 @@ NGRAPH_API EnumNames& EnumNames::type_info; -std::ostream& operator<<(std::ostream& s, const op::v8::MatrixNms::DecayFunction& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/mvn.cpp b/ngraph/core/src/op/mvn.cpp index 6ab313d158355f..ed53701375dc71 100644 --- a/ngraph/core/src/op/mvn.cpp +++ b/ngraph/core/src/op/mvn.cpp @@ -70,7 +70,7 @@ bool op::v0::MVN::visit_attributes(AttributeVisitor& visitor) { // ------------------------------ V6 ------------------------------ -namespace ngraph { +namespace ov { template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -81,10 +81,11 @@ NGRAPH_API EnumNames& EnumNames::get() { constexpr DiscreteTypeInfo AttributeAdapter::type_info; +} // namespace ov + std::ostream& op::operator<<(std::ostream& s, const op::MVNEpsMode& type) { return s << as_string(type); } -} // namespace ngraph NGRAPH_RTTI_DEFINITION(op::v6::MVN, "MVN", 6); diff --git a/ngraph/core/src/op/non_max_suppression.cpp b/ngraph/core/src/op/non_max_suppression.cpp index 4a02e7e6addda4..9a124547051622 100644 --- a/ngraph/core/src/op/non_max_suppression.cpp +++ b/ngraph/core/src/op/non_max_suppression.cpp @@ -174,7 +174,7 @@ int64_t op::v1::NonMaxSuppression::max_boxes_output_from_input() const { return max_output_boxes; } -namespace ngraph { +namespace ov { template <> EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -186,10 +186,11 @@ EnumNames& EnumNames::type_info; -std::ostream& operator<<(std::ostream& s, const op::v1::NonMaxSuppression::BoxEncodingType& type) { +} // namespace ov + +std::ostream& ngraph::operator<<(std::ostream& s, const op::v1::NonMaxSuppression::BoxEncodingType& type) { return s << as_string(type); } -} // namespace ngraph // ------------------------------ V3 ------------------------------ @@ -360,7 +361,7 @@ int64_t op::v3::NonMaxSuppression::max_boxes_output_from_input() const { return max_output_boxes; } -namespace ngraph { +namespace ov { template <> EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -372,10 +373,11 @@ EnumNames& EnumNames::type_info; -std::ostream& operator<<(std::ostream& s, const op::v3::NonMaxSuppression::BoxEncodingType& type) { +} // namespace ov + +std::ostream& ngraph::operator<<(std::ostream& s, const op::v3::NonMaxSuppression::BoxEncodingType& type) { return s << as_string(type); } -} // namespace ngraph // ------------------------------ V4 ------------------------------ @@ -813,7 +815,11 @@ void op::v5::NonMaxSuppression::validate_and_infer_types() { set_output_type(2, m_output_type, Shape{1}); } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::v5::NonMaxSuppression::BoxEncodingType& type) { + return s << as_string(type); +} + +namespace ov { template <> EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -825,7 +831,4 @@ EnumNames& EnumNames::type_info; -std::ostream& operator<<(std::ostream& s, const op::v5::NonMaxSuppression::BoxEncodingType& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/parameter.cpp b/ngraph/core/src/op/parameter.cpp index 1c3d32ed8fbea9..5f8ee481704756 100644 --- a/ngraph/core/src/op/parameter.cpp +++ b/ngraph/core/src/op/parameter.cpp @@ -48,11 +48,11 @@ void op::Parameter::set_is_relevant_to_shapes(bool is_relevant) { m_is_relevant_to_shapes = is_relevant; } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr DiscreteTypeInfo ov::AttributeAdapter::type_info; -AttributeAdapter::AttributeAdapter(ParameterVector& ref) : m_ref(ref) {} +ov::AttributeAdapter::AttributeAdapter(ParameterVector& ref) : m_ref(ref) {} -bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { +bool ov::AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { size_t size = m_ref.size(); visitor.on_attribute("size", size); if (size != m_ref.size()) { diff --git a/ngraph/core/src/op/result.cpp b/ngraph/core/src/op/result.cpp index db23b6adbd2399..8111965cbc946d 100644 --- a/ngraph/core/src/op/result.cpp +++ b/ngraph/core/src/op/result.cpp @@ -62,11 +62,11 @@ bool op::Result::constant_fold(OutputVector& output_values, const OutputVector& return false; } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr DiscreteTypeInfo ov::AttributeAdapter::type_info; -AttributeAdapter::AttributeAdapter(ResultVector& ref) : m_ref(ref) {} +ov::AttributeAdapter::AttributeAdapter(ResultVector& ref) : m_ref(ref) {} -bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { +bool ov::AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { size_t size = m_ref.size(); visitor.on_attribute("size", size); if (size != m_ref.size()) { diff --git a/ngraph/core/src/op/reverse.cpp b/ngraph/core/src/op/reverse.cpp index 078099e2eecca4..abb3f1e4bda096 100644 --- a/ngraph/core/src/op/reverse.cpp +++ b/ngraph/core/src/op/reverse.cpp @@ -197,7 +197,11 @@ bool op::v1::Reverse::has_evaluate() const { } } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::v1::Reverse::Mode& type) { + return s << as_string(type); +} + +namespace ov { template <> EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -207,8 +211,4 @@ EnumNames& EnumNames::get() { } constexpr DiscreteTypeInfo AttributeAdapter::type_info; - -std::ostream& operator<<(std::ostream& s, const op::v1::Reverse::Mode& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/roi_align.cpp b/ngraph/core/src/op/roi_align.cpp index 410b06b8f18b3e..34376a43997d2b 100644 --- a/ngraph/core/src/op/roi_align.cpp +++ b/ngraph/core/src/op/roi_align.cpp @@ -161,7 +161,7 @@ shared_ptr op::v3::ROIAlign::clone_with_new_inputs(const OutputVector& new m_mode); } -namespace ngraph { +namespace ov { constexpr DiscreteTypeInfo AttributeAdapter::type_info; template <> @@ -172,10 +172,11 @@ NGRAPH_API EnumNames& EnumNames diff --git a/ngraph/core/src/op/round.cpp b/ngraph/core/src/op/round.cpp index f06e364bc788ee..3323ec6596ac30 100644 --- a/ngraph/core/src/op/round.cpp +++ b/ngraph/core/src/op/round.cpp @@ -113,7 +113,11 @@ bool op::v5::Round::has_evaluate() const { return false; } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::v5::Round::RoundMode& type) { + return s << as_string(type); +} + +namespace ov { template <> EnumNames& EnumNames::get() { static auto enum_names = @@ -124,8 +128,4 @@ EnumNames& EnumNames::get() } constexpr DiscreteTypeInfo AttributeAdapter::type_info; - -std::ostream& operator<<(std::ostream& s, const op::v5::Round::RoundMode& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/space_to_depth.cpp b/ngraph/core/src/op/space_to_depth.cpp index 6e5db6a93da146..102beee02ed99e 100644 --- a/ngraph/core/src/op/space_to_depth.cpp +++ b/ngraph/core/src/op/space_to_depth.cpp @@ -116,7 +116,11 @@ bool ngraph::op::v0::SpaceToDepth::has_evaluate() const { return !get_input_partial_shape(0).is_dynamic(); } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::v0::SpaceToDepth::SpaceToDepthMode& type) { + return s << as_string(type); +} + +namespace ov { template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = EnumNames( @@ -127,8 +131,4 @@ NGRAPH_API EnumNames& EnumNames::type_info; - -std::ostream& operator<<(std::ostream& s, const op::v0::SpaceToDepth::SpaceToDepthMode& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/util/attr_types.cpp b/ngraph/core/src/op/util/attr_types.cpp index 2637d4437787a7..36814edc3217f1 100644 --- a/ngraph/core/src/op/util/attr_types.cpp +++ b/ngraph/core/src/op/util/attr_types.cpp @@ -11,127 +11,173 @@ #include "ngraph/check.hpp" #include "ngraph/enum_names.hpp" -using namespace ngraph; +namespace ov { -const op::AutoBroadcastSpec op::AutoBroadcastSpec::NUMPY(AutoBroadcastType::NUMPY, 0); -const op::AutoBroadcastSpec op::AutoBroadcastSpec::NONE{AutoBroadcastType::NONE, 0}; - -namespace ngraph { template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("op::PadMode", - {{"constant", op::PadMode::CONSTANT}, - {"edge", op::PadMode::EDGE}, - {"reflect", op::PadMode::REFLECT}, - {"symmetric", op::PadMode::SYMMETRIC}}); +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames("ngraph::op::PadMode", + {{"constant", ngraph::op::PadMode::CONSTANT}, + {"edge", ngraph::op::PadMode::EDGE}, + {"reflect", ngraph::op::PadMode::REFLECT}, + {"symmetric", ngraph::op::PadMode::SYMMETRIC}}); return enum_names; } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr DiscreteTypeInfo AttributeAdapter::type_info; -std::ostream& op::operator<<(std::ostream& s, const op::PadMode& type) { - return s << as_string(type); -} template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("op::PadType", - {{"explicit", op::PadType::EXPLICIT}, - {"same_lower", op::PadType::SAME_LOWER}, - {"same_upper", op::PadType::SAME_UPPER}, - {"valid", op::PadType::VALID}}); +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames("ngraph::op::PadType", + {{"explicit", ngraph::op::PadType::EXPLICIT}, + {"same_lower", ngraph::op::PadType::SAME_LOWER}, + {"same_upper", ngraph::op::PadType::SAME_UPPER}, + {"valid", ngraph::op::PadType::VALID}}); return enum_names; } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr DiscreteTypeInfo AttributeAdapter::type_info; -std::ostream& op::operator<<(std::ostream& s, const op::PadType& type) { - return s << as_string(type); +template <> +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames( + "ngraph::op::RoundingType", + {{"floor", ngraph::op::RoundingType::FLOOR}, {"ceil", ngraph::op::RoundingType::CEIL}}); + return enum_names; } + +constexpr DiscreteTypeInfo AttributeAdapter::type_info; + template <> -NGRAPH_API EnumNames& EnumNames::get() { +NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = - EnumNames("op::RoundingType", - {{"floor", op::RoundingType::FLOOR}, {"ceil", op::RoundingType::CEIL}}); + EnumNames("ngraph::op::AutoBroadcastType", + {{"none", ngraph::op::AutoBroadcastType::NONE}, + {"explicit", ngraph::op::AutoBroadcastType::EXPLICIT}, + {"numpy", ngraph::op::AutoBroadcastType::NUMPY}, + {"pdpd", ngraph::op::AutoBroadcastType::PDPD}}); return enum_names; } +constexpr DiscreteTypeInfo AttributeAdapter::type_info; -constexpr DiscreteTypeInfo AttributeAdapter::type_info; - -std::ostream& op::operator<<(std::ostream& s, const op::RoundingType& type) { - return s << as_string(type); +template <> +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = + EnumNames("ngraph::op::BroadcastType", + {{"none", ngraph::op::BroadcastType::NONE}, + {"numpy", ngraph::op::BroadcastType::NUMPY}, + {"explicit", ngraph::op::BroadcastType::EXPLICIT}, + {"pdpd", ngraph::op::BroadcastType::PDPD}, + {"bidirectional", ngraph::op::BroadcastType::BIDIRECTIONAL}}); + return enum_names; } +constexpr DiscreteTypeInfo AttributeAdapter::type_info; template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("op::AutoBroadcastType", - {{"none", op::AutoBroadcastType::NONE}, - {"explicit", op::AutoBroadcastType::EXPLICIT}, - {"numpy", op::AutoBroadcastType::NUMPY}, - {"pdpd", op::AutoBroadcastType::PDPD}}); +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = + EnumNames("ngraph::op::EpsMode", + {{"add", ngraph::op::EpsMode::ADD}, {"max", ngraph::op::EpsMode::MAX}}); return enum_names; } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; + +constexpr DiscreteTypeInfo AttributeAdapter::type_info; template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("op::BroadcastType", - {{"none", op::BroadcastType::NONE}, - {"numpy", op::BroadcastType::NUMPY}, - {"explicit", op::BroadcastType::EXPLICIT}, - {"pdpd", op::BroadcastType::PDPD}, - {"bidirectional", op::BroadcastType::BIDIRECTIONAL}}); +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames("ngraph::op::TopKSortType", + {{"none", ngraph::op::TopKSortType::NONE}, + {"index", ngraph::op::TopKSortType::SORT_INDICES}, + {"value", ngraph::op::TopKSortType::SORT_VALUES}}); + return enum_names; +} +template <> +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = + EnumNames("ngraph::op::TopKMode", + {{"min", ngraph::op::TopKMode::MIN}, {"max", ngraph::op::TopKMode::MAX}}); return enum_names; } -std::ostream& op::operator<<(std::ostream& s, const op::BroadcastType& type) { - return s << as_string(type); +constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr DiscreteTypeInfo AttributeAdapter::type_info; + +bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { + // Maintain back-compatibility + std::string name = visitor.finish_structure(); + visitor.on_attribute(name, m_ref.m_type); + visitor.start_structure(name); + if (m_ref.m_type == ngraph::op::AutoBroadcastType::PDPD) { + visitor.on_attribute("auto_broadcast_axis", m_ref.m_axis); + } + return true; } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr DiscreteTypeInfo AttributeAdapter::type_info; -std::ostream& op::operator<<(std::ostream& s, const op::AutoBroadcastType& type) { - return s << as_string(type); +bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { + // Maintain back-compatibility + std::string name = visitor.finish_structure(); + visitor.on_attribute(name, m_ref.m_type); + visitor.start_structure(name); + if (m_ref.m_type == ngraph::op::BroadcastType::PDPD) { + visitor.start_structure(name); + visitor.on_attribute("axis", m_ref.m_axis); + visitor.finish_structure(); + } + return true; } + +constexpr DiscreteTypeInfo AttributeAdapter::type_info; + +NGRAPH_API +constexpr DiscreteTypeInfo AttributeAdapter::type_info; template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = - EnumNames("op::EpsMode", {{"add", op::EpsMode::ADD}, {"max", op::EpsMode::MAX}}); +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames( + "ngraph::op::RecurrentSequenceDirection", + {{"forward", ngraph::op::RecurrentSequenceDirection::FORWARD}, + {"reverse", ngraph::op::RecurrentSequenceDirection::REVERSE}, + {"bidirectional", ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL}}); return enum_names; } +} // namespace ov -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +const ngraph::op::AutoBroadcastSpec ngraph::op::AutoBroadcastSpec::NUMPY(AutoBroadcastType::NUMPY, 0); +const ngraph::op::AutoBroadcastSpec ngraph::op::AutoBroadcastSpec::NONE{AutoBroadcastType::NONE, 0}; -std::ostream& op::operator<<(std::ostream& s, const op::EpsMode& type) { +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::PadMode& type) { return s << as_string(type); } -template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("op::TopKSortType", - {{"none", op::TopKSortType::NONE}, - {"index", op::TopKSortType::SORT_INDICES}, - {"value", op::TopKSortType::SORT_VALUES}}); - return enum_names; +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::PadType& type) { + return s << as_string(type); } -template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = - EnumNames("op::TopKMode", {{"min", op::TopKMode::MIN}, {"max", op::TopKMode::MAX}}); - return enum_names; + +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::RoundingType& type) { + return s << as_string(type); +} + +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::BroadcastType& type) { + return s << as_string(type); +} + +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::AutoBroadcastType& type) { + return s << as_string(type); } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::EpsMode& type) { + return s << as_string(type); +} -std::ostream& op::operator<<(std::ostream& s, const op::TopKSortType& type) { +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::TopKSortType& type) { return s << as_string(type); } -std::ostream& op::operator<<(std::ostream& s, const op::TopKMode& type) { +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::TopKMode& type) { return s << as_string(type); } -op::AutoBroadcastType op::AutoBroadcastSpec::type_from_string(const std::string& type) const { +ngraph::op::AutoBroadcastType ngraph::op::AutoBroadcastSpec::type_from_string(const std::string& type) const { auto lowercase_type = type; std::transform(lowercase_type.begin(), lowercase_type.end(), lowercase_type.begin(), [](char c) { return std::tolower(c); @@ -147,47 +193,6 @@ op::AutoBroadcastType op::AutoBroadcastSpec::type_from_string(const std::string& return allowed_values.at(lowercase_type); } -bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { - // Maintain back-compatibility - std::string name = visitor.finish_structure(); - visitor.on_attribute(name, m_ref.m_type); - visitor.start_structure(name); - if (m_ref.m_type == op::AutoBroadcastType::PDPD) { - visitor.on_attribute("auto_broadcast_axis", m_ref.m_axis); - } - return true; -} - -constexpr DiscreteTypeInfo AttributeAdapter::type_info; - -bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { - // Maintain back-compatibility - std::string name = visitor.finish_structure(); - visitor.on_attribute(name, m_ref.m_type); - visitor.start_structure(name); - if (m_ref.m_type == op::BroadcastType::PDPD) { - visitor.start_structure(name); - visitor.on_attribute("axis", m_ref.m_axis); - visitor.finish_structure(); - } - return true; -} - -constexpr DiscreteTypeInfo AttributeAdapter::type_info; - -NGRAPH_API -constexpr DiscreteTypeInfo AttributeAdapter::type_info; - -std::ostream& op::operator<<(std::ostream& s, const op::RecurrentSequenceDirection& direction) { +std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::RecurrentSequenceDirection& direction) { return s << as_string(direction); } -template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = - EnumNames("op::RecurrentSequenceDirection", - {{"forward", op::RecurrentSequenceDirection::FORWARD}, - {"reverse", op::RecurrentSequenceDirection::REVERSE}, - {"bidirectional", op::RecurrentSequenceDirection::BIDIRECTIONAL}}); - return enum_names; -} -} // namespace ngraph diff --git a/ngraph/core/src/op/util/multi_subgraph_base.cpp b/ngraph/core/src/op/util/multi_subgraph_base.cpp index 9f58fb52707848..fea33f2f653302 100644 --- a/ngraph/core/src/op/util/multi_subgraph_base.cpp +++ b/ngraph/core/src/op/util/multi_subgraph_base.cpp @@ -153,7 +153,7 @@ Output op::util::MultiSubGraphOp::set_body_outputs(const ResultVector& bod return Output(shared_from_this(), output_index); } -namespace ngraph { +namespace ov { NGRAPH_RTTI_DEFINITION(AttributeAdapter>>, "AttributeAdapter>>", @@ -163,4 +163,4 @@ NGRAPH_RTTI_DEFINITION(AttributeAdapter>>", 0); -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/util/nms_base.cpp b/ngraph/core/src/op/util/nms_base.cpp index be9671be970f1f..22b848707ffad5 100644 --- a/ngraph/core/src/op/util/nms_base.cpp +++ b/ngraph/core/src/op/util/nms_base.cpp @@ -145,7 +145,11 @@ void op::util::NmsBase::validate_and_infer_types() { } } -namespace ngraph { +std::ostream& ngraph::operator<<(std::ostream& s, const op::util::NmsBase::SortResultType& type) { + return s << as_string(type); +} + +namespace ov { template <> NGRAPH_API EnumNames& EnumNames::get() { static auto enum_names = @@ -157,8 +161,4 @@ NGRAPH_API EnumNames& EnumNames::type_info; - -std::ostream& operator<<(std::ostream& s, const op::util::NmsBase::SortResultType& type) { - return s << as_string(type); -} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/op/util/variable.cpp b/ngraph/core/src/op/util/variable.cpp index ae434cf8f3462d..3886f94d6c6e00 100644 --- a/ngraph/core/src/op/util/variable.cpp +++ b/ngraph/core/src/op/util/variable.cpp @@ -4,6 +4,4 @@ #include -namespace ngraph { -constexpr DiscreteTypeInfo AttributeAdapter>::type_info; -} +constexpr ov::DiscreteTypeInfo ov::AttributeAdapter>::type_info; diff --git a/ngraph/core/src/partial_shape.cpp b/ngraph/core/src/partial_shape.cpp index 9803d84e93b9eb..da93eb1ba15f0b 100644 --- a/ngraph/core/src/partial_shape.cpp +++ b/ngraph/core/src/partial_shape.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/partial_shape.hpp" +#include "openvino/core/partial_shape.hpp" #include #include @@ -10,7 +10,7 @@ #include "ngraph/check.hpp" -using namespace ngraph; +using namespace ov; PartialShape::PartialShape() : PartialShape(std::initializer_list{}) {} @@ -20,7 +20,7 @@ PartialShape::PartialShape(const std::vector& dimensions) : m_rank_is_static(true), m_dimensions(dimensions.begin(), dimensions.end()) {} -PartialShape::PartialShape(const Shape& shape) +PartialShape::PartialShape(const ngraph::Shape& shape) : m_rank_is_static(true), m_shape_type(ShapeType::SHAPE_IS_STATIC), m_dimensions(shape.begin(), shape.end()) {} @@ -33,7 +33,7 @@ PartialShape::PartialShape(std::vector dimensions) : m_rank_is_static(true), m_dimensions(std::move(dimensions)) {} -bool ngraph::PartialShape::is_static() const { +bool PartialShape::is_static() const { ShapeType shape_type = m_shape_type; if (m_shape_type == ShapeType::SHAPE_IS_UNKNOWN || m_shape_type == ShapeType::SHAPE_IS_UPDATED) { @@ -52,7 +52,7 @@ bool ngraph::PartialShape::is_static() const { return shape_type == ShapeType::SHAPE_IS_STATIC; } -bool ngraph::PartialShape::operator==(const PartialShape& partial_shape) const { +bool PartialShape::operator==(const PartialShape& partial_shape) const { if (rank() != partial_shape.rank()) { return false; } @@ -67,15 +67,15 @@ bool ngraph::PartialShape::operator==(const PartialShape& partial_shape) const { return true; } -bool ngraph::PartialShape::operator!=(const PartialShape& partial_shape) const { +bool PartialShape::operator!=(const PartialShape& partial_shape) const { return !(*this == partial_shape); } -Shape ngraph::PartialShape::get_max_shape() const { +ngraph::Shape PartialShape::get_max_shape() const { if (rank().is_dynamic()) { - return Shape(); + return ngraph::Shape(); } else { - Shape shape; + ngraph::Shape shape; for (auto dimension : m_dimensions) { shape.push_back(dimension.get_interval().get_max_val()); } @@ -83,11 +83,11 @@ Shape ngraph::PartialShape::get_max_shape() const { } } -Shape ngraph::PartialShape::get_min_shape() const { +ngraph::Shape PartialShape::get_min_shape() const { if (rank().is_dynamic()) { - return Shape(); + return ngraph::Shape(); } else { - Shape shape; + ngraph::Shape shape; for (auto dimension : m_dimensions) { shape.push_back(dimension.get_interval().get_min_val()); } @@ -95,9 +95,9 @@ Shape ngraph::PartialShape::get_min_shape() const { } } -Shape ngraph::PartialShape::get_shape() const { +ngraph::Shape PartialShape::get_shape() const { NGRAPH_CHECK(rank().is_static(), "get_shape() must be called on a static shape"); - Shape shape; + ngraph::Shape shape; for (auto dimension : m_dimensions) { auto min_val = dimension.get_interval().get_min_val(); auto max_val = dimension.get_interval().get_max_val(); @@ -234,7 +234,7 @@ bool PartialShape::merge_rank(Rank r) { } } -Shape PartialShape::to_shape() const { +ngraph::Shape PartialShape::to_shape() const { if (is_dynamic()) { throw std::invalid_argument("to_shape was called on a dynamic shape."); } @@ -269,11 +269,11 @@ bool PartialShape::merge_into(PartialShape& dst, const PartialShape& src) { bool PartialShape::broadcast_merge_into(PartialShape& dst, const PartialShape& src, - const op::AutoBroadcastSpec& autob) { + const ngraph::op::AutoBroadcastSpec& autob) { switch (autob.m_type) { - case op::AutoBroadcastType::NONE: + case ngraph::op::AutoBroadcastType::NONE: return true; - case op::AutoBroadcastType::NUMPY: { + case ngraph::op::AutoBroadcastType::NUMPY: { if (dst.rank().is_dynamic() || src.rank().is_dynamic()) { dst = PartialShape::dynamic(); return true; @@ -293,7 +293,7 @@ bool PartialShape::broadcast_merge_into(PartialShape& dst, return success; } } - case op::AutoBroadcastType::PDPD: { + case ngraph::op::AutoBroadcastType::PDPD: { if (dst.rank().is_dynamic() || src.rank().is_dynamic()) { return true; } else { @@ -357,7 +357,7 @@ Dimension& PartialShape::operator[](size_t i) { return m_dimensions[i]; } -const std::vector& ngraph::AttributeAdapter::get() { +const std::vector& ov::AttributeAdapter::get() { if (!m_buffer_valid) { m_buffer.clear(); if (m_ref.rank().is_dynamic()) { @@ -373,7 +373,7 @@ const std::vector& ngraph::AttributeAdapter::get( return m_buffer; } -void ngraph::AttributeAdapter::set(const std::vector& value) { +void ov::AttributeAdapter::set(const std::vector& value) { m_ref = PartialShape(); if (value.size() == 1 && value[0] == -2) { m_ref = PartialShape::dynamic(); @@ -387,4 +387,4 @@ void ngraph::AttributeAdapter::set(const std::vector::type_info; +NGRAPH_API constexpr DiscreteTypeInfo ov::AttributeAdapter::type_info; diff --git a/ngraph/core/src/runtime/aligned_buffer.cpp b/ngraph/core/src/runtime/aligned_buffer.cpp index f11980dc361cce..b901bc992040c9 100644 --- a/ngraph/core/src/runtime/aligned_buffer.cpp +++ b/ngraph/core/src/runtime/aligned_buffer.cpp @@ -56,9 +56,9 @@ runtime::AlignedBuffer& runtime::AlignedBuffer::operator=(AlignedBuffer&& other) return *this; } -namespace ngraph { +namespace ov { constexpr DiscreteTypeInfo AttributeAdapter>::type_info; AttributeAdapter>::AttributeAdapter(shared_ptr& value) : DirectValueAccessor>(value) {} -} // namespace ngraph +} // namespace ov diff --git a/ngraph/core/src/shape.cpp b/ngraph/core/src/shape.cpp index 87a2a396a465fd..3b7b1aab445aa5 100644 --- a/ngraph/core/src/shape.cpp +++ b/ngraph/core/src/shape.cpp @@ -38,4 +38,4 @@ ngraph::Shape& ngraph::Shape::operator=(Shape&& v) noexcept { return *this; } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr DiscreteTypeInfo ov::AttributeAdapter::type_info; diff --git a/ngraph/core/src/strides.cpp b/ngraph/core/src/strides.cpp index 946f29282631c1..123ad53bc8e635 100644 --- a/ngraph/core/src/strides.cpp +++ b/ngraph/core/src/strides.cpp @@ -36,4 +36,4 @@ ngraph::Strides& ngraph::Strides::operator=(Strides&& v) noexcept { return *this; } -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr DiscreteTypeInfo ov::AttributeAdapter::type_info; diff --git a/ngraph/core/src/type/element_type.cpp b/ngraph/core/src/type/element_type.cpp index cc5042a81d6f34..4dd724832d0cd6 100644 --- a/ngraph/core/src/type/element_type.cpp +++ b/ngraph/core/src/type/element_type.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/type/element_type.hpp" +#include "openvino/core/type/element_type.hpp" #include #include @@ -147,7 +147,7 @@ Type from() { return Type_t::boolean; } template <> -Type from() { +Type from() { return Type_t::f16; } template <> @@ -191,7 +191,7 @@ Type from() { return Type_t::u64; } template <> -Type from() { +Type from() { return Type_t::bf16; } } // namespace element @@ -276,38 +276,38 @@ size_t compiler_byte_size(ov::element::Type_t et) { std::to_string(static_cast(et))); } -namespace ngraph { +namespace ov { template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("ov::element::Type_t", - {{"undefined", ov::element::Type_t::undefined}, - {"dynamic", ov::element::Type_t::dynamic}, - {"boolean", ov::element::Type_t::boolean}, - {"bf16", ov::element::Type_t::bf16}, - {"f16", ov::element::Type_t::f16}, - {"f32", ov::element::Type_t::f32}, - {"f64", ov::element::Type_t::f64}, - {"i4", ov::element::Type_t::i4}, - {"i8", ov::element::Type_t::i8}, - {"i16", ov::element::Type_t::i16}, - {"i32", ov::element::Type_t::i32}, - {"i64", ov::element::Type_t::i64}, - {"u1", ov::element::Type_t::u1}, - {"u4", ov::element::Type_t::u4}, - {"u8", ov::element::Type_t::u8}, - {"u16", ov::element::Type_t::u16}, - {"u32", ov::element::Type_t::u32}, - {"u64", ov::element::Type_t::u64}}); +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames("element::Type_t", + {{"undefined", element::Type_t::undefined}, + {"dynamic", element::Type_t::dynamic}, + {"boolean", element::Type_t::boolean}, + {"bf16", element::Type_t::bf16}, + {"f16", element::Type_t::f16}, + {"f32", element::Type_t::f32}, + {"f64", element::Type_t::f64}, + {"i4", element::Type_t::i4}, + {"i8", element::Type_t::i8}, + {"i16", element::Type_t::i16}, + {"i32", element::Type_t::i32}, + {"i64", element::Type_t::i64}, + {"u1", element::Type_t::u1}, + {"u4", element::Type_t::u4}, + {"u8", element::Type_t::u8}, + {"u16", element::Type_t::u16}, + {"u32", element::Type_t::u32}, + {"u64", element::Type_t::u64}}); return enum_names; } -} // namespace ngraph -constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; +constexpr DiscreteTypeInfo AttributeAdapter::type_info; -const std::string& ngraph::AttributeAdapter::get() { - return as_string(static_cast(m_ref)); +const std::string& AttributeAdapter::get() { + return as_string(static_cast(m_ref)); } -void ngraph::AttributeAdapter::set(const std::string& value) { - m_ref = as_enum(value); +void AttributeAdapter::set(const std::string& value) { + m_ref = as_enum(value); } +} // namespace ov diff --git a/ngraph/test/visitors/user_op.cpp b/ngraph/test/visitors/user_op.cpp index 61290870422691..4ccaffd5bf2939 100644 --- a/ngraph/test/visitors/user_op.cpp +++ b/ngraph/test/visitors/user_op.cpp @@ -18,7 +18,7 @@ using ngraph::test::ValueMap; enum class TuringModel { XL400, XL1200 }; -namespace ngraph { +namespace ov { template <> EnumNames& EnumNames::get() { static auto enum_names = @@ -74,7 +74,7 @@ class AttributeAdapter : public VisitorAdapter { }; constexpr DiscreteTypeInfo AttributeAdapter::type_info; -} // namespace ngraph +} // namespace ov // Given a Turing machine program and data, return scalar 1 if the program would // complete, 1 if it would not. @@ -110,7 +110,7 @@ class Oracle : public op::Op { const std::vector& vec_int32_t, const std::vector& vec_int64_t, const std::vector& vec_size_t, - const Position& position, + const ov::Position& position, const shared_ptr& node, const NodeVector& node_vector, const ParameterVector& parameter_vector, @@ -240,7 +240,7 @@ class Oracle : public op::Op { const vector& get_vec_size_t() const { return m_vec_size_t; } - const Position& get_position() const { + const ov::Position& get_position() const { return m_position; } const shared_ptr& get_node() const { @@ -362,7 +362,7 @@ class Oracle : public op::Op { vector m_vec_int32_t; vector m_vec_int64_t; vector m_vec_size_t; - Position m_position; + ov::Position m_position; shared_ptr m_node; NodeVector m_node_vector; ParameterVector m_parameter_vector; @@ -406,7 +406,7 @@ TEST(attributes, user_op) { vector{1, 2, 4, 8}, vector{1, 2, 4, 8}, vector{1, 3, 8, 4, 2}, - Position{1.3f, 5.1f, 2.3f}, + ov::Position{1.3f, 5.1f, 2.3f}, data, NodeVector{program, result, data}, ParameterVector{data, data, program}, From d4691133047ba71e83df4bc79043d7e164128220 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 30 Aug 2021 18:02:43 +0300 Subject: [PATCH 076/102] memleaks multimodel supporting --- .../precommit_configs/desktop_test_config.xml | 8 +-- tests/stress_tests/common/tests_utils.cpp | 25 ++++--- tests/stress_tests/common/tests_utils.h | 3 +- tests/stress_tests/memleaks_tests/tests.cpp | 70 +++++++++++-------- tests/stress_tests/scripts/get_testdata.py | 19 ++++- 5 files changed, 75 insertions(+), 50 deletions(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml index 7e9169bf4a7ac7..06e2a4639c338f 100644 --- a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml @@ -1,8 +1,6 @@ - - - - - + + + \ No newline at end of file diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index c49af7536a011a..97271354b9a795 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -80,14 +80,14 @@ std::vector generateTestsParams(std::initializer_list fie } std::vector generateTestsParamsMemLeaks() { - std::vector tests_cases; + std::vector tests_cases; const pugi::xml_document & test_config = Environment::Instance().getTestConfig(); - int numprocesses, numthreads, numiteration, - std::string device; + int numprocesses, numthreads, numiterations; + std::string device_name; pugi::xml_node cases; - cases = test_config.child("cases").child("device"); + cases = test_config.child("cases"); for (pugi::xml_node device = cases.first_child(); device; device = device.next_sibling()) { device_name = device.attribute("name").as_string("NULL"); @@ -95,23 +95,18 @@ std::vector generateTestsParamsMemLeaks() { numthreads = device.attribute("threads").as_int(1); numiterations = device.attribute("iterations").as_int(1); - std::vector> models; + std::vector > models; for (pugi::xml_node model = device.first_child(); model; model = model.next_sibling()){ - std::map models; std::string full_path = model.attribute("full_path").as_string(); std::string path = model.attribute("path").as_string(); if (full_path.empty() || path.empty()) throw std::logic_error("One of the 'model' records from test config doesn't contain 'full_path' or 'path' attributes"); - else { - model["path"] = full_path; - model["name"] = path; - } std::string precision = model.attribute("precision").as_string(); - model["precision"] = precision; - models.push_back(model); + std::map model_map { {"name", path}, {"path", full_path}, {"path", precision} }; + models.push_back(model_map); } - tests_cases.push_back(TestCaseMemLeaks(numprocesses, numthreads, numiters, device_name, models)) + tests_cases.push_back(TestCaseMemLeaks(numprocesses, numthreads, numiterations, device_name, models)); } return tests_cases; @@ -121,6 +116,10 @@ std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj) { + return obj.param.test_case_name; +} + void test_wrapper(const std::function &tests_pipeline, const TestCase ¶ms) { tests_pipeline(params.model, params.device, params.numiters); } diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 16ad8c1aca6b45..eb933a74dc3813 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -69,7 +69,7 @@ class TestCaseMemLeaks { "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device); int i = 1; for (auto model: models){ - test_case_name += "_Model" + std::to_string(i) + "_" + update_item_for_name(model["name"]) "_Precision_" + update_item_for_name(model["precision"]); + test_case_name += "_Model" + std::to_string(i) + "_" + update_item_for_name(model["name"]) + "_Precision_" + update_item_for_name(model["precision"]); models_names += update_item_for_name(model["path"]) + "\n"; i += 1; } @@ -107,6 +107,7 @@ class Environment { std::vector generateTestsParams(std::initializer_list items); std::vector generateTestsParamsMemLeaks(); std::string getTestCaseName(const testing::TestParamInfo &obj); +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); void _runTest(const std::function &tests_pipeline, const TestCase ¶ms); diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 92b81bcd512678..3b96e156199b99 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -13,13 +13,13 @@ using namespace InferenceEngine; -class MemLeaksTestSuiteNoModel : public ::testing::TestWithParam { +class MemLeaksTestSuiteNoModel : public ::testing::TestWithParam { }; -class MemLeaksTestSuiteNoDevice : public ::testing::TestWithParam { +class MemLeaksTestSuiteNoDevice : public ::testing::TestWithParam { }; -class MemLeaksTestSuite : public ::testing::TestWithParam { +class MemLeaksTestSuite : public ::testing::TestWithParam { }; inline void test_runner(int numthreads, const std::function &test_function) { @@ -42,7 +42,7 @@ inline void test_runner(int numthreads, const std::function &test_ // tests_pipelines/tests_pipelines.cpp TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { auto test_params = GetParam(); - std::vector pipeline {load_unload_plugin(test_params.device)}; + std::vector> pipeline = { load_unload_plugin(test_params.device) }; auto test = [&] { log_info("Load/unload plugin for device: " << test_params.device << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); @@ -52,8 +52,10 @@ TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { TEST_P(MemLeaksTestSuiteNoDevice, read_network) { auto test_params = GetParam(); - std::vector pipeline; - for (auto model: test_params.models) pipeline.push_back(read_cnnnetwork(model["path"])); + std::vector> pipeline; + std::string path; + for (int i = 0; i < test_params.models.size(); i++) + pipeline.push_back(read_cnnnetwork(test_params.models[i]["path"])); auto test = [&] { log_info("Read network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); @@ -63,8 +65,9 @@ TEST_P(MemLeaksTestSuiteNoDevice, read_network) { TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { auto test_params = GetParam(); - std::vector pipeline; - for (auto model: test_params.models) pipeline.push_back(cnnnetwork_reshape_batch_x2(model["path"])); + std::vector> pipeline; + for (int i = 0; i < test_params.models.size(); i++) + pipeline.push_back(cnnnetwork_reshape_batch_x2(test_params.models[i]["path"])); auto test = [&] { log_info("Reshape to batch*=2 of CNNNetwork created from network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); @@ -74,8 +77,9 @@ TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { auto test_params = GetParam(); - std::vector pipeline; - for (auto model: test_params.models) pipeline.push_back(set_input_params(model["path"])); + std::vector> pipeline; + for (int i = 0; i < test_params.models.size(); i++) + pipeline.push_back(set_input_params(test_params.models[i]["path"])); auto test = [&] { log_info("Apply preprocessing for CNNNetwork from network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); @@ -86,8 +90,9 @@ TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { TEST_P(MemLeaksTestSuite, recreate_exenetwork) { auto test_params = GetParam(); Core ie; - std::vector pipeline; - for (auto model: test_params.models) pipeline.push_back(recreate_exenetwork(ie, model["path"], test_params.device)); + std::vector> pipeline; + for (int i = 0; i < test_params.models.size(); i++) + pipeline.push_back(recreate_exenetwork(ie, test_params.models[i]["path"], test_params.device)); auto test = [&] { log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); @@ -99,12 +104,15 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { TEST_P(MemLeaksTestSuite, recreate_infer_request) { auto test_params = GetParam(); Core ie; - std::vector pipeline; + std::vector exeNetworks; + std::vector> pipeline; for (auto model: test_params.models){ CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); - - pipeline.push_back(recreate_infer_request(exeNetwork)); + exeNetworks.push_back(exeNetwork); + } + for (int i = 0; i < exeNetworks.size(); i++){ + pipeline.push_back(recreate_infer_request(exeNetworks[i])); } auto test = [&] { log_info("Create InferRequest from network: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " << test_params.numiters @@ -117,7 +125,9 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { TEST_P(MemLeaksTestSuite, reinfer_request_inference) { auto test_params = GetParam(); Core ie; - std::vector pipeline; + std::vector infer_requests; + std::vector outputs_info; + std::vector> pipeline; for (auto model: test_params.models){ CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); @@ -128,8 +138,11 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { batchSize = batchSize != 0 ? batchSize : 1; const InferenceEngine::ConstInputsDataMap inputsInfo(exeNetwork.GetInputsInfo()); fillBlobs(infer_request, inputsInfo, batchSize); - - pipeline.push_back(reinfer_request_inference(infer_request, output_info)); + outputs_info.push_back(output_info); + infer_requests.push_back((infer_request)); + } + for (int i = 0; i < infer_requests.size(); i++){ + pipeline.push_back(reinfer_request_inference(infer_requests[i], outputs_info[i])); } auto test = [&] { log_info("Inference of InferRequest from networks: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " @@ -141,13 +154,12 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { TEST_P(MemLeaksTestSuite, infer_request_inference) { auto test_params = GetParam(); - std::vector pipeline; - for (auto model: test_params.models){ - pipeline.push_back(infer_request_inference(model["path"], test_params.device)); - } + std::vector> pipeline; + for (int i = 0; i < test_params.models.size(); i++) + pipeline.push_back(infer_request_inference(test_params.models[i]["path"], test_params.device)); auto test = [&] { log_info("Inference of InferRequest from networks: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " - << n << " times"); + << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -156,9 +168,9 @@ TEST_P(MemLeaksTestSuite, infer_request_inference) { TEST_P(MemLeaksTestSuite, inference_with_streams) { auto test_params = GetParam(); const auto nstreams = 2; - std::vector pipeline; - for (auto model: test_params.models){ - pipeline.push_back(inference_with_streams(model["path"], test_params.device, nstreams)); + std::vector> pipeline; + for (int i = 0; i < test_params.models.size(); i++){ + pipeline.push_back(inference_with_streams(test_params.models[i]["path"], test_params.device, nstreams)); } auto test = [&] { log_info("Inference of InferRequest from networks: \"" << test_params.models_names @@ -173,13 +185,13 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoModel, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoDevice, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuite, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index cae9de7bec032a..0b51dbe74c1871 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -85,6 +85,18 @@ def run_in_subprocess(cmd, check_call=True): else: subprocess.call(cmd, shell=True) +def get_model_recs(test_conf_root, test_framework): + """Pparse models from test config.""" + if test_framework == "memleak": + model_recs = [] + for device_rec in test_conf_root.findall("device"): + for model_rec in device_rec.findall("model"): + model_recs.append(model_rec) + + return model_recs + + return test_conf_root.findall("model") + def main(): """Main entry point. @@ -95,6 +107,8 @@ def main(): parser.add_argument('--test_conf', required=True, type=Path, help='Path to a test config .xml file containing models ' 'which will be downloaded and converted to IRs via OMZ.') + parser.add_argument('--test_framework', required=False, type=str, + help='Test config framework') parser.add_argument('--omz_repo', required=False, help='Path to Open Model Zoo (OMZ) repository. It will be used to skip cloning step.') parser.add_argument('--mo_tool', type=Path, @@ -141,10 +155,11 @@ def main(): Venv.create_n_install_requirements(*requirements) python_executable = Venv.get_venv_executable() - # parse models from test config test_conf_obj = ET.parse(str(args.test_conf)) test_conf_root = test_conf_obj.getroot() - for model_rec in test_conf_root.find("models"): + model_recs = get_model_recs(test_conf_root, args.test_framework) + + for model_rec in model_recs: if "name" not in model_rec.attrib or model_rec.attrib.get("source") != "omz": continue model_name = model_rec.attrib["name"] From ed5b5650eb0cbc7fd9038746b08291cd22caea7c Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Sun, 5 Sep 2021 20:16:45 +0300 Subject: [PATCH 077/102] revert rebase mistake --- ngraph/core/src/validation_util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ngraph/core/src/validation_util.cpp b/ngraph/core/src/validation_util.cpp index c1bbd351f70afc..ff69f511059f92 100644 --- a/ngraph/core/src/validation_util.cpp +++ b/ngraph/core/src/validation_util.cpp @@ -1151,9 +1151,9 @@ bool ngraph::could_propagate(const Output& output, std::vector& ord auto current_node = nodes_to_calculate.front(); nodes_to_calculate.pop_front(); - if (current_node->inputs().empty() && !ov::is_type(current_node)) + if (current_node->inputs().empty() && !is_type(current_node)) status = false; - else if (!ov::is_type(current_node) && !ov::is_type(current_node)) { + else if (!is_type(current_node) && !is_type(current_node)) { // not a leaf, not a shape_of -- continue to search for (const auto& input_value : current_node->input_values()) { const auto& input_node = input_value.get_node(); From 46da1dd423443630f95ba89231285d642509557c Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Sun, 5 Sep 2021 20:17:47 +0300 Subject: [PATCH 078/102] add newline at the end of config file --- .../memleaks_tests/precommit_configs/desktop_test_config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml index 11ae1ca2d4cd96..b23c2b3ff77de1 100644 --- a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml @@ -5,4 +5,4 @@ - \ No newline at end of file + From 30878f235c3bb3a47a72ead4f1e9b1e560ca41c8 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Sun, 5 Sep 2021 22:29:53 +0300 Subject: [PATCH 079/102] fix log messages --- tests/stress_tests/memleaks_tests/tests.cpp | 41 +++++++++++---------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 2dbdc9ef98c6c1..825ba715fc9cab 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -13,13 +13,13 @@ using namespace InferenceEngine; -class MemLeaksTestSuiteNoModel : public ::testing::TestWithParam { +class MemLeaksTestSuiteNoModel : public ::testing::TestWithParam { }; -class MemLeaksTestSuiteNoDevice : public ::testing::TestWithParam { +class MemLeaksTestSuiteNoDevice : public ::testing::TestWithParam { }; -class MemLeaksTestSuite : public ::testing::TestWithParam { +class MemLeaksTestSuite : public ::testing::TestWithParam { }; inline void test_runner(int numthreads, const std::function &test_function) { @@ -44,7 +44,8 @@ TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { auto test_params = GetParam(); std::vector> pipeline = { load_unload_plugin(test_params.device) }; auto test = [&] { - log_info("Load/unload plugin for device: " << test_params.device << " for " << test_params.numiters << " times"); + log_info("Load/unload plugin for device: " << test_params.device + << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -57,7 +58,8 @@ TEST_P(MemLeaksTestSuiteNoDevice, read_network) { for (int i = 0; i < test_params.models.size(); i++) pipeline.push_back(read_cnnnetwork(test_params.models[i]["path"])); auto test = [&] { - log_info("Read network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); + log_info("Read networks: " << test_params.models_names + << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -69,7 +71,8 @@ TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { for (int i = 0; i < test_params.models.size(); i++) pipeline.push_back(cnnnetwork_reshape_batch_x2(test_params.models[i]["path"])); auto test = [&] { - log_info("Reshape to batch*=2 of CNNNetwork created from network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); + log_info("Reshape to batch*=2 of CNNNetwork created from networks: " << test_params.models_names + << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -77,10 +80,11 @@ TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { auto test_params = GetParam(); - std::vector pipeline; + std::vector> pipeline; for (auto model: test_params.models) pipeline.push_back(set_input_params(model["path"])); auto test = [&] { - log_info("Apply preprocessing for CNNNetwork from network: \"" << test_params.models_names << "\" for " << test_params.numiters << " times"); + log_info("Apply preprocessing for CNNNetwork from networks: " << test_params.models_names + << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -93,8 +97,8 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { for (int i = 0; i < test_params.models.size(); i++) pipeline.push_back(recreate_exenetwork(ie, test_params.models[i]["path"], test_params.device)); auto test = [&] { - log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: \"" - << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); + log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: " << test_params.models_names + << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -114,8 +118,8 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { pipeline.push_back(recreate_infer_request(exeNetworks[i])); } auto test = [&] { - log_info("Create InferRequest from network: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " << test_params.numiters - << " times"); + log_info("Create InferRequest from networks: " << test_params.models_names + << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -144,8 +148,8 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { pipeline.push_back(reinfer_request_inference(infer_requests[i], outputs_info[i])); } auto test = [&] { - log_info("Inference of InferRequest from networks: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " - << test_params.numiters << " times"); + log_info("Inference of InferRequest from networks: " << test_params.models_names + << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -157,8 +161,8 @@ TEST_P(MemLeaksTestSuite, infer_request_inference) { for (int i = 0; i < test_params.models.size(); i++) pipeline.push_back(infer_request_inference(test_params.models[i]["path"], test_params.device)); auto test = [&] { - log_info("Inference of InferRequest from networks: \"" << test_params.models_names << "\" for device: \"" << test_params.device << "\" for " - << test_params.numiters << " times"); + log_info("Inference of InferRequest from networks: " << test_params.models_names + << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -172,9 +176,8 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { pipeline.push_back(inference_with_streams(test_params.models[i]["path"], test_params.device, nstreams)); } auto test = [&] { - log_info("Inference of InferRequest from networks: \"" << test_params.models_names - << "\" for device: \"" << test_params.device - << "\" with streams: " << nstreams << " for " << test_params.numiters << " times"); + log_info("Inference of InferRequest from networks: " << test_params.models_names + << " for device: \"" << test_params.device << "\" with streams: " << nstreams << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); From 5bf59357dc79e6d5a92bee6504e0ad25e8861b15 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Sun, 5 Sep 2021 22:30:46 +0300 Subject: [PATCH 080/102] refine memelaks test case class --- tests/stress_tests/common/tests_utils.cpp | 8 ++-- tests/stress_tests/common/tests_utils.h | 52 ++++++++++------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 97271354b9a795..5dbd2b4891d88a 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -79,8 +79,8 @@ std::vector generateTestsParams(std::initializer_list fie return tests_cases; } -std::vector generateTestsParamsMemLeaks() { - std::vector tests_cases; +std::vector generateTestsParamsMemLeaks() { + std::vector tests_cases; const pugi::xml_document & test_config = Environment::Instance().getTestConfig(); int numprocesses, numthreads, numiterations; @@ -106,7 +106,7 @@ std::vector generateTestsParamsMemLeaks() { std::map model_map { {"name", path}, {"path", full_path}, {"path", precision} }; models.push_back(model_map); } - tests_cases.push_back(TestCaseMemLeaks(numprocesses, numthreads, numiterations, device_name, models)); + tests_cases.push_back(MemLeaksTestCase(numprocesses, numthreads, numiterations, device_name, models)); } return tests_cases; @@ -116,7 +116,7 @@ std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } -std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj) { +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index eb933a74dc3813..e6fd17a5d0f8a8 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -22,7 +22,19 @@ enum TestStatus using TestResult = std::pair; -class TestCase { +class TestCaseBase { +protected: + std::string update_item_for_name(const std::string &item) { + std::string _item(item); + for (std::string::size_type index = 0; index < _item.size(); ++index) { + if (!isalnum(_item[index]) && _item[index] != '_') + _item[index] = '_'; + } + return _item; + } +}; + +class TestCase: TestCaseBase { public: int numprocesses; int numthreads; @@ -40,19 +52,9 @@ class TestCase { "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + "_Precision_" + update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); } - -private: - std::string update_item_for_name(const std::string &item) { - std::string _item(item); - for (std::string::size_type index = 0; index < _item.size(); ++index) { - if (!isalnum(_item[index]) && _item[index] != '_') - _item[index] = '_'; - } - return _item; - } }; -class TestCaseMemLeaks { +class MemLeaksTestCase: TestCaseBase { public: int numprocesses; int numthreads; @@ -62,28 +64,18 @@ class TestCaseMemLeaks { std::string test_case_name; std::string models_names; - TestCaseMemLeaks(int _numprocesses, int _numthreads, int _numiters, std::string _device, std::vector> _models) { + MemLeaksTestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, std::vector> _models) { numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, models = _models; test_case_name = "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device); - int i = 1; - for (auto model: models){ - test_case_name += "_Model" + std::to_string(i) + "_" + update_item_for_name(model["name"]) + "_Precision_" + update_item_for_name(model["precision"]); - models_names += update_item_for_name(model["path"]) + "\n"; - i += 1; + for (int i = 0; i < models.size(); i++){ + test_case_name += + "_Model" + std::to_string(i) + "_" + update_item_for_name(models[i]["name"]) + + "_Precision_" + update_item_for_name(models[i]["precision"]); + models_names += "\"" + models[i]["name"] + "\"" + (i < models.size() - 1 ? ", " : ""); } } - -private: - std::string update_item_for_name(const std::string &item) { - std::string _item(item); - for (std::string::size_type index = 0; index < _item.size(); ++index) { - if (!isalnum(_item[index]) && _item[index] != '_') - _item[index] = '_'; - } - return _item; - } }; class Environment { @@ -105,9 +97,9 @@ class Environment { }; std::vector generateTestsParams(std::initializer_list items); -std::vector generateTestsParamsMemLeaks(); +std::vector generateTestsParamsMemLeaks(); std::string getTestCaseName(const testing::TestParamInfo &obj); -std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj); +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); void _runTest(const std::function &tests_pipeline, const TestCase ¶ms); From 14dcf2a18b3ed1c4cecceba90f4e435abcf25760 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Sun, 5 Sep 2021 23:21:57 +0300 Subject: [PATCH 081/102] remove temporary decision designed to save in memory pipeline functions parameters --- tests/stress_tests/memleaks_tests/tests.cpp | 25 +++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 825ba715fc9cab..df2352cdcc3948 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -10,6 +10,7 @@ #include #include +#include using namespace InferenceEngine; @@ -107,15 +108,12 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { TEST_P(MemLeaksTestSuite, recreate_infer_request) { auto test_params = GetParam(); Core ie; - std::vector exeNetworks; std::vector> pipeline; for (auto model: test_params.models){ CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); - ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); - exeNetworks.push_back(exeNetwork); - } - for (int i = 0; i < exeNetworks.size(); i++){ - pipeline.push_back(recreate_infer_request(exeNetworks[i])); + std::unique_ptr exeNetwork(new ExecutableNetwork); + * exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); + pipeline.push_back(recreate_infer_request(* exeNetwork)); } auto test = [&] { log_info("Create InferRequest from networks: " << test_params.models_names @@ -129,23 +127,20 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { auto test_params = GetParam(); Core ie; std::vector infer_requests; + std::vector outputs_info; std::vector> pipeline; for (auto model: test_params.models){ CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); - InferRequest infer_request = exeNetwork.CreateInferRequest(); - - OutputsDataMap output_info(cnnNetwork.getOutputsInfo()); + std::unique_ptr infer_request(new InferRequest); + * infer_request = exeNetwork.CreateInferRequest(); + std::unique_ptr output_info(new OutputsDataMap(cnnNetwork.getOutputsInfo())); auto batchSize = cnnNetwork.getBatchSize(); batchSize = batchSize != 0 ? batchSize : 1; const InferenceEngine::ConstInputsDataMap inputsInfo(exeNetwork.GetInputsInfo()); - fillBlobs(infer_request, inputsInfo, batchSize); - outputs_info.push_back(output_info); - infer_requests.push_back((infer_request)); - } - for (int i = 0; i < infer_requests.size(); i++){ - pipeline.push_back(reinfer_request_inference(infer_requests[i], outputs_info[i])); + fillBlobs(* infer_request, inputsInfo, batchSize); + pipeline.push_back(reinfer_request_inference(* infer_request, * output_info)); } auto test = [&] { log_info("Inference of InferRequest from networks: " << test_params.models_names From 77f33b722892934c6573750442c11c80254b2277 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Sun, 5 Sep 2021 23:27:26 +0300 Subject: [PATCH 082/102] code consistency --- tests/stress_tests/memleaks_tests/tests.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index df2352cdcc3948..f339c98838cafa 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -109,11 +109,11 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { auto test_params = GetParam(); Core ie; std::vector> pipeline; - for (auto model: test_params.models){ - CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); + for (int i = 0; i < test_params.models.size(); i++){ + CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["path"]); std::unique_ptr exeNetwork(new ExecutableNetwork); - * exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); - pipeline.push_back(recreate_infer_request(* exeNetwork)); + *exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); + pipeline.push_back(recreate_infer_request(*exeNetwork)); } auto test = [&] { log_info("Create InferRequest from networks: " << test_params.models_names @@ -130,17 +130,17 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { std::vector outputs_info; std::vector> pipeline; - for (auto model: test_params.models){ - CNNNetwork cnnNetwork = ie.ReadNetwork(model["path"]); + for (int i = 0; i < test_params.models.size(); i++){ + CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); std::unique_ptr infer_request(new InferRequest); - * infer_request = exeNetwork.CreateInferRequest(); + *infer_request = exeNetwork.CreateInferRequest(); std::unique_ptr output_info(new OutputsDataMap(cnnNetwork.getOutputsInfo())); auto batchSize = cnnNetwork.getBatchSize(); batchSize = batchSize != 0 ? batchSize : 1; const InferenceEngine::ConstInputsDataMap inputsInfo(exeNetwork.GetInputsInfo()); fillBlobs(* infer_request, inputsInfo, batchSize); - pipeline.push_back(reinfer_request_inference(* infer_request, * output_info)); + pipeline.push_back(reinfer_request_inference(*infer_request, *output_info)); } auto test = [&] { log_info("Inference of InferRequest from networks: " << test_params.models_names From b97ce27c314ebc3cf04d14865154c336f66db1d0 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Sun, 5 Sep 2021 23:35:10 +0300 Subject: [PATCH 083/102] rework example of new memleak tests config format --- .../nightly_configs/desktop_test_config.xml | 27 +++++++------------ .../precommit_configs/desktop_test_config.xml | 26 ++++++++++++------ tests/stress_tests/scripts/get_testdata.py | 5 ++-- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml index 060fffc897c0e7..a4501fcb786538 100644 --- a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml @@ -1,21 +1,14 @@ - - - 1 - - - 1 - - - 1000 - - - CPU - GPU - - + + - - \ No newline at end of file + + + + + + + + diff --git a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml index b23c2b3ff77de1..12cd28c0c8cd7c 100644 --- a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml @@ -1,8 +1,18 @@ - - - - - - - - + + + 1 + + + 1 + + + 30 + + + CPU + GPU + + + + + \ No newline at end of file diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index 0b51dbe74c1871..1493e3158e607c 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -85,6 +85,7 @@ def run_in_subprocess(cmd, check_call=True): else: subprocess.call(cmd, shell=True) + def get_model_recs(test_conf_root, test_framework): """Pparse models from test config.""" if test_framework == "memleak": @@ -107,8 +108,8 @@ def main(): parser.add_argument('--test_conf', required=True, type=Path, help='Path to a test config .xml file containing models ' 'which will be downloaded and converted to IRs via OMZ.') - parser.add_argument('--test_framework', required=False, type=str, - help='Test config framework') + parser.add_argument('--test_framework', required=False, default=None, + help='Test config framework.') parser.add_argument('--omz_repo', required=False, help='Path to Open Model Zoo (OMZ) repository. It will be used to skip cloning step.') parser.add_argument('--mo_tool', type=Path, From b3980aed3a47a76d6a89b2d0fce21162931f7809 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 6 Sep 2021 00:00:13 +0300 Subject: [PATCH 084/102] oop in testcases --- tests/stress_tests/common/tests_utils.cpp | 2 +- tests/stress_tests/common/tests_utils.h | 29 +++++++++------------ tests/stress_tests/memleaks_tests/tests.cpp | 8 +++--- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 5dbd2b4891d88a..9b3ac7ff5619ab 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -116,7 +116,7 @@ std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } -std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj) { +std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index e6fd17a5d0f8a8..32c2c1aedaad2a 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -23,6 +23,14 @@ enum TestStatus using TestResult = std::pair; class TestCaseBase { +public: + int numprocesses; + int numthreads; + int numiters; + std::string precision; + std::string test_case_name; + std::string model_name; + std::string device; protected: std::string update_item_for_name(const std::string &item) { std::string _item(item); @@ -34,16 +42,9 @@ class TestCaseBase { } }; -class TestCase: TestCaseBase { +class TestCase: public TestCaseBase { public: - int numprocesses; - int numthreads; - int numiters; - std::string device; - std::string model_name; std::string model; - std::string precision; - std::string test_case_name; TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string& _model, const std::string& _model_name, const std::string& _precision) { numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, model_name = _model_name, precision = _precision; @@ -54,15 +55,9 @@ class TestCase: TestCaseBase { } }; -class MemLeaksTestCase: TestCaseBase { +class MemLeaksTestCase: public TestCaseBase { public: - int numprocesses; - int numthreads; - int numiters; - std::string device; std::vector> models; - std::string test_case_name; - std::string models_names; MemLeaksTestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, std::vector> _models) { numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, models = _models; @@ -73,7 +68,7 @@ class MemLeaksTestCase: TestCaseBase { test_case_name += "_Model" + std::to_string(i) + "_" + update_item_for_name(models[i]["name"]) + "_Precision_" + update_item_for_name(models[i]["precision"]); - models_names += "\"" + models[i]["name"] + "\"" + (i < models.size() - 1 ? ", " : ""); + model_name += "\"" + models[i]["name"] + "\"" + (i < models.size() - 1 ? ", " : ""); } } }; @@ -99,7 +94,7 @@ class Environment { std::vector generateTestsParams(std::initializer_list items); std::vector generateTestsParamsMemLeaks(); std::string getTestCaseName(const testing::TestParamInfo &obj); -std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj); +std::string getTestCaseName(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); void _runTest(const std::function &tests_pipeline, const TestCase ¶ms); diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index f339c98838cafa..1334571199b02f 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -143,7 +143,7 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { pipeline.push_back(reinfer_request_inference(*infer_request, *output_info)); } auto test = [&] { - log_info("Inference of InferRequest from networks: " << test_params.models_names + log_info("Inference of InferRequest from networks: " << test_params.model_name << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -182,13 +182,13 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoModel, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseNameMemLeaks); + getTestCaseName); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoDevice, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseNameMemLeaks); + getTestCaseName); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuite, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseNameMemLeaks); + getTestCaseName); From 5ce759254ab20fdf888699ddc59b4961735e9625 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 6 Sep 2021 00:03:33 +0300 Subject: [PATCH 085/102] mistype --- tests/stress_tests/scripts/get_testdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index 1493e3158e607c..88b6c90a0956f5 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -87,7 +87,7 @@ def run_in_subprocess(cmd, check_call=True): def get_model_recs(test_conf_root, test_framework): - """Pparse models from test config.""" + """Parse models from test config.""" if test_framework == "memleak": model_recs = [] for device_rec in test_conf_root.findall("device"): From fa306793d1602d212802836289f2339b9b0488b7 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 6 Sep 2021 00:14:06 +0300 Subject: [PATCH 086/102] set num of iterations in example test config to previous value --- .../memleaks_tests/nightly_configs/desktop_test_config.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml index a4501fcb786538..a2d4bd8fa9747e 100644 --- a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml @@ -1,11 +1,11 @@ - + - + From ed20ade0fec3ec0dc813aac3e21dd2d241ab0028 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Thu, 9 Sep 2021 19:08:40 +0300 Subject: [PATCH 087/102] . --- .../nightly_configs/desktop_test_config.xml | 18 +++++++++--------- tests/stress_tests/memleaks_tests/tests.cpp | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml index a2d4bd8fa9747e..e1441085403acc 100644 --- a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml @@ -1,14 +1,14 @@ - - - - + + + + - - - - + + + + - + \ No newline at end of file diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 1334571199b02f..563d8d53df8e51 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -59,7 +59,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, read_network) { for (int i = 0; i < test_params.models.size(); i++) pipeline.push_back(read_cnnnetwork(test_params.models[i]["path"])); auto test = [&] { - log_info("Read networks: " << test_params.models_names + log_info("Read networks: " << test_params.model_name << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -72,7 +72,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { for (int i = 0; i < test_params.models.size(); i++) pipeline.push_back(cnnnetwork_reshape_batch_x2(test_params.models[i]["path"])); auto test = [&] { - log_info("Reshape to batch*=2 of CNNNetwork created from networks: " << test_params.models_names + log_info("Reshape to batch*=2 of CNNNetwork created from networks: " << test_params.model_name << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -84,7 +84,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { std::vector> pipeline; for (auto model: test_params.models) pipeline.push_back(set_input_params(model["path"])); auto test = [&] { - log_info("Apply preprocessing for CNNNetwork from networks: " << test_params.models_names + log_info("Apply preprocessing for CNNNetwork from networks: " << test_params.model_name << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -98,7 +98,7 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { for (int i = 0; i < test_params.models.size(); i++) pipeline.push_back(recreate_exenetwork(ie, test_params.models[i]["path"], test_params.device)); auto test = [&] { - log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: " << test_params.models_names + log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: " << test_params.model_name << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -116,7 +116,7 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { pipeline.push_back(recreate_infer_request(*exeNetwork)); } auto test = [&] { - log_info("Create InferRequest from networks: " << test_params.models_names + log_info("Create InferRequest from networks: " << test_params.model_name << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -156,7 +156,7 @@ TEST_P(MemLeaksTestSuite, infer_request_inference) { for (int i = 0; i < test_params.models.size(); i++) pipeline.push_back(infer_request_inference(test_params.models[i]["path"], test_params.device)); auto test = [&] { - log_info("Inference of InferRequest from networks: " << test_params.models_names + log_info("Inference of InferRequest from networks: " << test_params.model_name << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -171,7 +171,7 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { pipeline.push_back(inference_with_streams(test_params.models[i]["path"], test_params.device, nstreams)); } auto test = [&] { - log_info("Inference of InferRequest from networks: " << test_params.models_names + log_info("Inference of InferRequest from networks: " << test_params.model_name << " for device: \"" << test_params.device << "\" with streams: " << nstreams << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; From 560cc8116f7af7c05773414a298d935abd2e7afe Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Thu, 9 Sep 2021 19:15:16 +0300 Subject: [PATCH 088/102] add multiproc stress unit tests --- .../unittests/nightly_configs/desktop_test_config.xml | 2 ++ .../unittests/nightly_configs/myriad_test_config.xml | 2 ++ .../unittests/weekly_configs/desktop_test_config.xml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/stress_tests/.automation/unittests/nightly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/unittests/nightly_configs/desktop_test_config.xml index fdb3e2746ca1ad..cfe20b5a0b484b 100644 --- a/tests/stress_tests/.automation/unittests/nightly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/unittests/nightly_configs/desktop_test_config.xml @@ -1,6 +1,8 @@ 1 + 4 + 16 1 diff --git a/tests/stress_tests/.automation/unittests/nightly_configs/myriad_test_config.xml b/tests/stress_tests/.automation/unittests/nightly_configs/myriad_test_config.xml index 979194a991ac26..77b3e00765387c 100644 --- a/tests/stress_tests/.automation/unittests/nightly_configs/myriad_test_config.xml +++ b/tests/stress_tests/.automation/unittests/nightly_configs/myriad_test_config.xml @@ -1,6 +1,8 @@ 1 + 4 + 16 1 diff --git a/tests/stress_tests/.automation/unittests/weekly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/unittests/weekly_configs/desktop_test_config.xml index 2ada874cccb268..081c8a6b829f8c 100644 --- a/tests/stress_tests/.automation/unittests/weekly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/unittests/weekly_configs/desktop_test_config.xml @@ -1,6 +1,8 @@ 1 + 4 + 16 1 From a1001a2acda4fb19827e8a84f2c8400c37db6079 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Thu, 9 Sep 2021 19:21:46 +0300 Subject: [PATCH 089/102] Add more cases --- .../unittests/nightly_configs/desktop_test_config.xml | 2 ++ .../unittests/nightly_configs/myriad_test_config.xml | 2 ++ .../unittests/weekly_configs/desktop_test_config.xml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/stress_tests/.automation/unittests/nightly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/unittests/nightly_configs/desktop_test_config.xml index cfe20b5a0b484b..941caf8c21eaf7 100644 --- a/tests/stress_tests/.automation/unittests/nightly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/unittests/nightly_configs/desktop_test_config.xml @@ -1,7 +1,9 @@ 1 + 2 4 + 8 16 diff --git a/tests/stress_tests/.automation/unittests/nightly_configs/myriad_test_config.xml b/tests/stress_tests/.automation/unittests/nightly_configs/myriad_test_config.xml index 77b3e00765387c..f9a43413f0b4ae 100644 --- a/tests/stress_tests/.automation/unittests/nightly_configs/myriad_test_config.xml +++ b/tests/stress_tests/.automation/unittests/nightly_configs/myriad_test_config.xml @@ -1,7 +1,9 @@ 1 + 2 4 + 8 16 diff --git a/tests/stress_tests/.automation/unittests/weekly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/unittests/weekly_configs/desktop_test_config.xml index 081c8a6b829f8c..10990b978ab312 100644 --- a/tests/stress_tests/.automation/unittests/weekly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/unittests/weekly_configs/desktop_test_config.xml @@ -1,7 +1,9 @@ 1 + 2 4 + 8 16 From a2a2106c99f3a4a726cbf7e9b2306aa2204dcb2b Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Sun, 12 Sep 2021 21:00:49 +0300 Subject: [PATCH 090/102] . --- tests/stress_tests/common/tests_utils.cpp | 2 +- tests/stress_tests/common/tests_utils.h | 2 +- tests/stress_tests/memleaks_tests/tests.cpp | 6 +++--- tests/stress_tests/scripts/get_testdata.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 9b3ac7ff5619ab..5dbd2b4891d88a 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -116,7 +116,7 @@ std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } -std::string getTestCaseName(const testing::TestParamInfo &obj) { +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 32c2c1aedaad2a..922a76d2f4936b 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -94,7 +94,7 @@ class Environment { std::vector generateTestsParams(std::initializer_list items); std::vector generateTestsParamsMemLeaks(); std::string getTestCaseName(const testing::TestParamInfo &obj); -std::string getTestCaseName(const testing::TestParamInfo &obj); +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); void _runTest(const std::function &tests_pipeline, const TestCase ¶ms); diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 563d8d53df8e51..b751a79f5f57dd 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -182,13 +182,13 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoModel, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoDevice, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuite, ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseName); + getTestCaseNameMemLeaks); diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index 86dc712b516342..7e3ed22ba411f1 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -108,7 +108,7 @@ def main(): help='Path to a test config .xml file containing models ' 'which will be downloaded and converted to IRs via OMZ.') parser.add_argument('--test_framework', required=False, default=None, - help='Test config framework.') + help='Test framework name. Test config file format depends on the test framework.') parser.add_argument('--omz_repo', required=False, help='Path to Open Model Zoo (OMZ) repository. It will be used to skip cloning step.') parser.add_argument('--mo_tool', type=Path, From 0157e3cacf926ffecf35b2a5adf12a8f949206b3 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 13 Sep 2021 17:04:30 +0300 Subject: [PATCH 091/102] remove unique_ptr test objects saving logic --- tests/stress_tests/common/tests_utils.cpp | 2 +- tests/stress_tests/memleaks_tests/tests.cpp | 85 ++++++++++++--------- 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 5dbd2b4891d88a..9b3ac7ff5619ab 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -116,7 +116,7 @@ std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } -std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj) { +std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index b751a79f5f57dd..1f9b3e77d09fa3 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -10,7 +10,6 @@ #include #include -#include using namespace InferenceEngine; @@ -39,13 +38,13 @@ inline void test_runner(int numthreads, const std::function &test_ } } - // tests_pipelines/tests_pipelines.cpp TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { auto test_params = GetParam(); + std::vector> pipeline = { load_unload_plugin(test_params.device) }; auto test = [&] { - log_info("Load/unload plugin for device: " << test_params.device + log_info("Load/unload plugin for \"" << test_params.device << "\" device" << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -55,9 +54,10 @@ TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { TEST_P(MemLeaksTestSuiteNoDevice, read_network) { auto test_params = GetParam(); std::vector> pipeline; - std::string path; - for (int i = 0; i < test_params.models.size(); i++) + + for (int i = 0; i < test_params.models.size(); i++){ pipeline.push_back(read_cnnnetwork(test_params.models[i]["path"])); + } auto test = [&] { log_info("Read networks: " << test_params.model_name << " for " << test_params.numiters << " times"); @@ -69,10 +69,12 @@ TEST_P(MemLeaksTestSuiteNoDevice, read_network) { TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { auto test_params = GetParam(); std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++) + + for (int i = 0; i < test_params.models.size(); i++){ pipeline.push_back(cnnnetwork_reshape_batch_x2(test_params.models[i]["path"])); + } auto test = [&] { - log_info("Reshape to batch*=2 of CNNNetwork created from networks: " << test_params.model_name + log_info("Reshape to batch*=2 of CNNNetworks created from networks: " << test_params.model_name << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -82,9 +84,12 @@ TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { auto test_params = GetParam(); std::vector> pipeline; - for (auto model: test_params.models) pipeline.push_back(set_input_params(model["path"])); + + for (int i = 0; i < test_params.models.size(); i++){ + pipeline.push_back(set_input_params(test_params.models[i]["path"])); + } auto test = [&] { - log_info("Apply preprocessing for CNNNetwork from networks: " << test_params.model_name + log_info("Apply preprocessing for CNNNetworks from networks: " << test_params.model_name << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; @@ -95,11 +100,13 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { auto test_params = GetParam(); Core ie; std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++) + + for (int i = 0; i < test_params.models.size(); i++){ pipeline.push_back(recreate_exenetwork(ie, test_params.models[i]["path"], test_params.device)); + } auto test = [&] { - log_info("Recreate ExecutableNetwork from network within existing InferenceEngine::Core: " << test_params.model_name - << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); + log_info("Recreate ExecutableNetworks within existing InferenceEngine::Core from networks: " << test_params.model_name + << " for \"" << test_params.device << "\" device for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -109,15 +116,20 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { auto test_params = GetParam(); Core ie; std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++){ + std::vector exeNetworks; + + int n_models = test_params.models.size(); + exeNetworks.reserve(n_models); + + for (int i = 0; i < n_models; i++){ CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["path"]); - std::unique_ptr exeNetwork(new ExecutableNetwork); - *exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); - pipeline.push_back(recreate_infer_request(*exeNetwork)); + ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); + exeNetworks.push_back(exeNetwork); + pipeline.push_back(recreate_infer_request(exeNetworks[i])); } auto test = [&] { - log_info("Create InferRequest from networks: " << test_params.model_name - << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); + log_info("Create InferRequests from networks: " << test_params.model_name + << " for \"" << test_params.device << "\" device for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -126,25 +138,30 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { TEST_P(MemLeaksTestSuite, reinfer_request_inference) { auto test_params = GetParam(); Core ie; + std::vector> pipeline; std::vector infer_requests; - std::vector outputs_info; - std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++){ + + int n_models = test_params.models.size(); + infer_requests.reserve(n_models); + outputs_info.reserve(n_models); + + for (int i = 0; i < n_models; i++){ CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); - std::unique_ptr infer_request(new InferRequest); - *infer_request = exeNetwork.CreateInferRequest(); - std::unique_ptr output_info(new OutputsDataMap(cnnNetwork.getOutputsInfo())); + InferRequest infer_request = exeNetwork.CreateInferRequest(); + infer_requests.push_back(infer_request); + OutputsDataMap output_info(cnnNetwork.getOutputsInfo()); + outputs_info.push_back(output_info); auto batchSize = cnnNetwork.getBatchSize(); batchSize = batchSize != 0 ? batchSize : 1; const InferenceEngine::ConstInputsDataMap inputsInfo(exeNetwork.GetInputsInfo()); - fillBlobs(* infer_request, inputsInfo, batchSize); - pipeline.push_back(reinfer_request_inference(*infer_request, *output_info)); + fillBlobs(infer_requests[i], inputsInfo, batchSize); + pipeline.push_back(reinfer_request_inference(infer_requests[i], outputs_info[i])); } auto test = [&] { - log_info("Inference of InferRequest from networks: " << test_params.model_name - << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); + log_info("Inference of InferRequests from networks: " << test_params.model_name + << " for \"" << test_params.device << "\" device for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -153,11 +170,12 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { TEST_P(MemLeaksTestSuite, infer_request_inference) { auto test_params = GetParam(); std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++) + for (int i = 0; i < test_params.models.size(); i++){ pipeline.push_back(infer_request_inference(test_params.models[i]["path"], test_params.device)); + } auto test = [&] { - log_info("Inference of InferRequest from networks: " << test_params.model_name - << " for device: \"" << test_params.device << "\" for " << test_params.numiters << " times"); + log_info("Inference of InferRequests from networks: " << test_params.model_name + << " for \"" << test_params.device << "\" device for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -171,8 +189,8 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { pipeline.push_back(inference_with_streams(test_params.models[i]["path"], test_params.device, nstreams)); } auto test = [&] { - log_info("Inference of InferRequest from networks: " << test_params.model_name - << " for device: \"" << test_params.device << "\" with streams: " << nstreams << " for " << test_params.numiters << " times"); + log_info("Inference of InferRequests from networks: " << test_params.model_name + << " for \"" << test_params.device << "\" device with " << nstreams << " streams for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -191,4 +209,3 @@ INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoDevice, INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuite, ::testing::ValuesIn(generateTestsParamsMemLeaks()), getTestCaseNameMemLeaks); - From deac5dca5f763c1b28e3fa42c69b7b0e9593e189 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 13 Sep 2021 17:04:55 +0300 Subject: [PATCH 092/102] switch memleak test configs to new format --- .../nightly_configs/desktop_test_config.xml | 23 +++++++------- .../nightly_configs/myriad_test_config.xml | 22 ++++---------- .../precommit_configs/desktop_test_config.xml | 27 +++++++---------- .../weekly_configs/desktop_test_config.xml | 30 ++++++++----------- 4 files changed, 40 insertions(+), 62 deletions(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml index e1441085403acc..4ecda8c7807001 100644 --- a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/desktop_test_config.xml @@ -1,14 +1,15 @@ - - - - - + + + + + - - - - - + + + + + - \ No newline at end of file + + diff --git a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/myriad_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/myriad_test_config.xml index 3718751b253d7d..2b8848cee9f395 100644 --- a/tests/stress_tests/.automation/memleaks_tests/nightly_configs/myriad_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/nightly_configs/myriad_test_config.xml @@ -1,19 +1,9 @@ - - - 1 - - - 1 - - - 1000 - - - MYRIAD - - + + + - - \ No newline at end of file + + + diff --git a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml index 12cd28c0c8cd7c..4909b6411f1fa9 100644 --- a/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/precommit_configs/desktop_test_config.xml @@ -1,18 +1,11 @@ - - - 1 - - - 1 - - - 30 - - - CPU - GPU - - + + + - - \ No newline at end of file + + + + + + + diff --git a/tests/stress_tests/.automation/memleaks_tests/weekly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/weekly_configs/desktop_test_config.xml index 95bced89a1f2cd..2fa27ee043885e 100644 --- a/tests/stress_tests/.automation/memleaks_tests/weekly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/weekly_configs/desktop_test_config.xml @@ -1,21 +1,15 @@ - - - 1 - - - 1 - - - 5000 - - - CPU - GPU - - - + + + - - \ No newline at end of file + + + + + + + + + From e338f21b00fda005a985c47b33bdee4550707139 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 13 Sep 2021 17:10:10 +0300 Subject: [PATCH 093/102] swith weekly memleak test config to new format --- .../memleaks_tests/weekly_configs/desktop_test_config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stress_tests/.automation/memleaks_tests/weekly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memleaks_tests/weekly_configs/desktop_test_config.xml index 2fa27ee043885e..d0862a42b8c8c3 100644 --- a/tests/stress_tests/.automation/memleaks_tests/weekly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memleaks_tests/weekly_configs/desktop_test_config.xml @@ -11,5 +11,5 @@ - + From b43800c760d346bbe90bac96da000f98862ddaf8 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Mon, 13 Sep 2021 17:10:52 +0300 Subject: [PATCH 094/102] Clarify new get_testdata script arg --- tests/stress_tests/scripts/get_testdata.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index 7e3ed22ba411f1..f3cf544174d691 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -108,7 +108,8 @@ def main(): help='Path to a test config .xml file containing models ' 'which will be downloaded and converted to IRs via OMZ.') parser.add_argument('--test_framework', required=False, default=None, - help='Test framework name. Test config file format depends on the test framework.') + help='Test framework name.' + 'Set the "memleak" value to preprocess memLeakTest configs and skip in other cases.') parser.add_argument('--omz_repo', required=False, help='Path to Open Model Zoo (OMZ) repository. It will be used to skip cloning step.') parser.add_argument('--mo_tool', type=Path, From fbcc0a1ce5851d3ca2f2dcd04ed9df2d8a75744b Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Tue, 14 Sep 2021 12:08:28 +0300 Subject: [PATCH 095/102] clang-format --- tests/stress_tests/.clang-format | 66 +++++++++++++++ tests/stress_tests/common/tests_utils.cpp | 48 +++++------ tests/stress_tests/common/tests_utils.h | 73 +++++----------- tests/stress_tests/memleaks_tests/tests.cpp | 84 +++++++++---------- .../tests_pipelines/tests_pipelines.cpp | 67 +++++++-------- .../tests_pipelines/tests_pipelines.h | 4 +- 6 files changed, 182 insertions(+), 160 deletions(-) create mode 100644 tests/stress_tests/.clang-format diff --git a/tests/stress_tests/.clang-format b/tests/stress_tests/.clang-format new file mode 100644 index 00000000000000..92399ef0e71558 --- /dev/null +++ b/tests/stress_tests/.clang-format @@ -0,0 +1,66 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: None +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 9b3ac7ff5619ab..53fde7fa96fefc 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -5,23 +5,19 @@ #include "tests_utils.h" #include +#include #include #include -#include #define DEBUG_MODE false -const pugi::xml_document & Environment::getTestConfig() { - return _test_config; -} +const pugi::xml_document &Environment::getTestConfig() { return _test_config; } -void Environment::setTestConfig(const pugi::xml_document &test_config) { - _test_config.reset(test_config); -} +void Environment::setTestConfig(const pugi::xml_document &test_config) { _test_config.reset(test_config); } std::vector generateTestsParams(std::initializer_list fields) { std::vector tests_cases; - const pugi::xml_document & test_config = Environment::Instance().getTestConfig(); + const pugi::xml_document &test_config = Environment::Instance().getTestConfig(); std::vector processes, threads, iterations; std::vector devices, models, models_names, precisions; @@ -50,7 +46,8 @@ std::vector generateTestsParams(std::initializer_list fie std::string full_path = val.attribute("full_path").as_string(); std::string path = val.attribute("path").as_string(); if (full_path.empty() || path.empty()) - throw std::logic_error("One of the 'model' records from test config doesn't contain 'full_path' or 'path' attributes"); + throw std::logic_error("One of the 'model' records from test config doesn't contain 'full_path' or " + "'path' attributes"); else { models.push_back(full_path); models_names.push_back(path); @@ -62,9 +59,9 @@ std::vector generateTestsParams(std::initializer_list fie } // Initialize variables with default value if it weren't filled - processes = !processes.empty() ? processes: std::vector{1}; - threads = !threads.empty() ? threads: std::vector{1}; - iterations = !iterations.empty() ? iterations: std::vector{1}; + processes = !processes.empty() ? processes : std::vector{1}; + threads = !threads.empty() ? threads : std::vector{1}; + iterations = !iterations.empty() ? iterations : std::vector{1}; devices = !devices.empty() ? devices : std::vector{"NULL"}; models = !models.empty() ? models : std::vector{"NULL"}; precisions = !precisions.empty() ? precisions : std::vector{"NULL"}; @@ -75,13 +72,14 @@ std::vector generateTestsParams(std::initializer_list fie for (auto &numiters : iterations) for (auto &device : devices) for (int i = 0; i < models.size(); i++) - tests_cases.push_back(TestCase(numprocesses, numthreads, numiters, device, models[i], models_names[i], precisions[i])); - return tests_cases; + tests_cases.push_back(TestCase(numprocesses, numthreads, numiters, device, models[i], + models_names[i], precisions[i])); + return tests_cases; } std::vector generateTestsParamsMemLeaks() { std::vector tests_cases; - const pugi::xml_document & test_config = Environment::Instance().getTestConfig(); + const pugi::xml_document &test_config = Environment::Instance().getTestConfig(); int numprocesses, numthreads, numiterations; std::string device_name; @@ -95,15 +93,16 @@ std::vector generateTestsParamsMemLeaks() { numthreads = device.attribute("threads").as_int(1); numiterations = device.attribute("iterations").as_int(1); - std::vector > models; + std::vector> models; - for (pugi::xml_node model = device.first_child(); model; model = model.next_sibling()){ + for (pugi::xml_node model = device.first_child(); model; model = model.next_sibling()) { std::string full_path = model.attribute("full_path").as_string(); std::string path = model.attribute("path").as_string(); if (full_path.empty() || path.empty()) - throw std::logic_error("One of the 'model' records from test config doesn't contain 'full_path' or 'path' attributes"); + throw std::logic_error( + "One of the 'model' records from test config doesn't contain 'full_path' or 'path' attributes"); std::string precision = model.attribute("precision").as_string(); - std::map model_map { {"name", path}, {"path", full_path}, {"path", precision} }; + std::map model_map{{"name", path}, {"path", full_path}, {"path", precision}}; models.push_back(model_map); } tests_cases.push_back(MemLeaksTestCase(numprocesses, numthreads, numiterations, device_name, models)); @@ -112,13 +111,9 @@ std::vector generateTestsParamsMemLeaks() { return tests_cases; } -std::string getTestCaseName(const testing::TestParamInfo &obj) { - return obj.param.test_case_name; -} +std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } -std::string getTestCaseName(const testing::TestParamInfo &obj) { - return obj.param.test_case_name; -} +std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } void test_wrapper(const std::function &tests_pipeline, const TestCase ¶ms) { tests_pipeline(params.model, params.device, params.numiters); @@ -132,8 +127,7 @@ void runTest(const std::function &tests_pip #if DEBUG_MODE tests_pipeline(params.model, params.device, params.numiters); #else - int status = run_in_processes(params.numprocesses, [&](){ _runTest(tests_pipeline, params); }); + int status = run_in_processes(params.numprocesses, [&]() { _runTest(tests_pipeline, params); }); ASSERT_EQ(status, 0) << "Test failed with exitcode " << std::to_string(status); #endif } - diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 922a76d2f4936b..33d8222b54add4 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -9,92 +9,65 @@ #include #include #include -#include #include +#include -enum TestStatus -{ - TEST_NOT_STARTED = 0, - TEST_FAILED, - TEST_OK -}; +enum TestStatus { TEST_NOT_STARTED = 0, TEST_FAILED, TEST_OK }; using TestResult = std::pair; -class TestCaseBase { +class TestCase { public: int numprocesses; int numthreads; int numiters; + std::string device; + std::string model_name; + std::string model; std::string precision; std::string test_case_name; - std::string model_name; - std::string device; -protected: + + TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string &_model, + const std::string &_model_name, const std::string &_precision) { + numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, + model_name = _model_name, precision = _precision; + test_case_name = "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + + "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + + "_Precision_" + update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); + } + +private: std::string update_item_for_name(const std::string &item) { std::string _item(item); for (std::string::size_type index = 0; index < _item.size(); ++index) { - if (!isalnum(_item[index]) && _item[index] != '_') - _item[index] = '_'; + if (!isalnum(_item[index]) && _item[index] != '_') _item[index] = '_'; } return _item; } }; -class TestCase: public TestCaseBase { -public: - std::string model; - - TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string& _model, const std::string& _model_name, const std::string& _precision) { - numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, model_name = _model_name, precision = _precision; - test_case_name = - "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + - "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + "_Precision_" + - update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); - } -}; - -class MemLeaksTestCase: public TestCaseBase { -public: - std::vector> models; - - MemLeaksTestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, std::vector> _models) { - numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, models = _models; - test_case_name = - "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + - "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device); - for (int i = 0; i < models.size(); i++){ - test_case_name += - "_Model" + std::to_string(i) + "_" + update_item_for_name(models[i]["name"]) + - "_Precision_" + update_item_for_name(models[i]["precision"]); - model_name += "\"" + models[i]["name"] + "\"" + (i < models.size() - 1 ? ", " : ""); - } - } -}; - class Environment { private: pugi::xml_document _test_config; bool _collect_results_only = false; Environment() = default; - Environment(const Environment&) = delete; - Environment& operator=(const Environment&) = delete; + Environment(const Environment &) = delete; + Environment &operator=(const Environment &) = delete; + public: - static Environment& Instance(){ + static Environment &Instance() { static Environment env; return env; } - const pugi::xml_document & getTestConfig(); + const pugi::xml_document &getTestConfig(); void setTestConfig(const pugi::xml_document &test_config); }; std::vector generateTestsParams(std::initializer_list items); -std::vector generateTestsParamsMemLeaks(); std::string getTestCaseName(const testing::TestParamInfo &obj); -std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); void _runTest(const std::function &tests_pipeline, const TestCase ¶ms); diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 1f9b3e77d09fa3..2b1d7693a00284 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "../common/managers/thread_manager.h" #include "../common/tests_utils.h" #include "common_utils.h" -#include "../common/managers/thread_manager.h" #include "tests_pipelines/tests_pipelines.h" #include @@ -13,19 +13,15 @@ using namespace InferenceEngine; -class MemLeaksTestSuiteNoModel : public ::testing::TestWithParam { -}; +class MemLeaksTestSuiteNoModel : public ::testing::TestWithParam {}; -class MemLeaksTestSuiteNoDevice : public ::testing::TestWithParam { -}; +class MemLeaksTestSuiteNoDevice : public ::testing::TestWithParam {}; -class MemLeaksTestSuite : public ::testing::TestWithParam { -}; +class MemLeaksTestSuite : public ::testing::TestWithParam {}; inline void test_runner(int numthreads, const std::function &test_function) { ThreadManager thr_manager; - for (int i = 0; i < numthreads; i++) - thr_manager.add_task(test_function); + for (int i = 0; i < numthreads; i++) thr_manager.add_task(test_function); thr_manager.run_parallel_n_wait(); std::vector statuses = thr_manager.get_all_statuses(); @@ -33,7 +29,7 @@ inline void test_runner(int numthreads, const std::function &test_ for (int i = 0; i < numthreads; i++) { EXPECT_EQ(statuses[i], ManagerStatus::FINISHED_SUCCESSFULLY) - << "[Thread " << i << "] Thread not finished successfully"; + << "[Thread " << i << "] Thread not finished successfully"; EXPECT_EQ(results[i].first, TestStatus::TEST_OK) << "[Thread " << i << "] " << results[i].second; } } @@ -42,10 +38,10 @@ inline void test_runner(int numthreads, const std::function &test_ TEST_P(MemLeaksTestSuiteNoModel, load_unload_plugin) { auto test_params = GetParam(); - std::vector> pipeline = { load_unload_plugin(test_params.device) }; + std::vector> pipeline = {load_unload_plugin(test_params.device)}; auto test = [&] { log_info("Load/unload plugin for \"" << test_params.device << "\" device" - << " for " << test_params.numiters << " times"); + << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -55,12 +51,11 @@ TEST_P(MemLeaksTestSuiteNoDevice, read_network) { auto test_params = GetParam(); std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++){ + for (int i = 0; i < test_params.models.size(); i++) { pipeline.push_back(read_cnnnetwork(test_params.models[i]["path"])); } auto test = [&] { - log_info("Read networks: " << test_params.model_name - << " for " << test_params.numiters << " times"); + log_info("Read networks: " << test_params.model_name << " for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -70,12 +65,12 @@ TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { auto test_params = GetParam(); std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++){ + for (int i = 0; i < test_params.models.size(); i++) { pipeline.push_back(cnnnetwork_reshape_batch_x2(test_params.models[i]["path"])); } auto test = [&] { - log_info("Reshape to batch*=2 of CNNNetworks created from networks: " << test_params.model_name - << " for " << test_params.numiters << " times"); + log_info("Reshape to batch*=2 of CNNNetworks created from networks: " << test_params.model_name << " for " + << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -85,12 +80,12 @@ TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { auto test_params = GetParam(); std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++){ + for (int i = 0; i < test_params.models.size(); i++) { pipeline.push_back(set_input_params(test_params.models[i]["path"])); } auto test = [&] { - log_info("Apply preprocessing for CNNNetworks from networks: " << test_params.model_name - << " for " << test_params.numiters << " times"); + log_info("Apply preprocessing for CNNNetworks from networks: " << test_params.model_name << " for " + << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -101,12 +96,13 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { Core ie; std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++){ + for (int i = 0; i < test_params.models.size(); i++) { pipeline.push_back(recreate_exenetwork(ie, test_params.models[i]["path"], test_params.device)); } auto test = [&] { - log_info("Recreate ExecutableNetworks within existing InferenceEngine::Core from networks: " << test_params.model_name - << " for \"" << test_params.device << "\" device for " << test_params.numiters << " times"); + log_info("Recreate ExecutableNetworks within existing InferenceEngine::Core from networks: " + << test_params.model_name << " for \"" << test_params.device << "\" device for " + << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -121,15 +117,15 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { int n_models = test_params.models.size(); exeNetworks.reserve(n_models); - for (int i = 0; i < n_models; i++){ + for (int i = 0; i < n_models; i++) { CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); exeNetworks.push_back(exeNetwork); pipeline.push_back(recreate_infer_request(exeNetworks[i])); } auto test = [&] { - log_info("Create InferRequests from networks: " << test_params.model_name - << " for \"" << test_params.device << "\" device for " << test_params.numiters << " times"); + log_info("Create InferRequests from networks: " << test_params.model_name << " for \"" << test_params.device + << "\" device for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -146,7 +142,7 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { infer_requests.reserve(n_models); outputs_info.reserve(n_models); - for (int i = 0; i < n_models; i++){ + for (int i = 0; i < n_models; i++) { CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); InferRequest infer_request = exeNetwork.CreateInferRequest(); @@ -160,8 +156,9 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { pipeline.push_back(reinfer_request_inference(infer_requests[i], outputs_info[i])); } auto test = [&] { - log_info("Inference of InferRequests from networks: " << test_params.model_name - << " for \"" << test_params.device << "\" device for " << test_params.numiters << " times"); + log_info("Inference of InferRequests from networks: " << test_params.model_name << " for \"" + << test_params.device << "\" device for " + << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -170,12 +167,13 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { TEST_P(MemLeaksTestSuite, infer_request_inference) { auto test_params = GetParam(); std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++){ + for (int i = 0; i < test_params.models.size(); i++) { pipeline.push_back(infer_request_inference(test_params.models[i]["path"], test_params.device)); } auto test = [&] { - log_info("Inference of InferRequests from networks: " << test_params.model_name - << " for \"" << test_params.device << "\" device for " << test_params.numiters << " times"); + log_info("Inference of InferRequests from networks: " << test_params.model_name << " for \"" + << test_params.device << "\" device for " + << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -185,12 +183,13 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { auto test_params = GetParam(); const auto nstreams = 2; std::vector> pipeline; - for (int i = 0; i < test_params.models.size(); i++){ + for (int i = 0; i < test_params.models.size(); i++) { pipeline.push_back(inference_with_streams(test_params.models[i]["path"], test_params.device, nstreams)); } auto test = [&] { - log_info("Inference of InferRequests from networks: " << test_params.model_name - << " for \"" << test_params.device << "\" device with " << nstreams << " streams for " << test_params.numiters << " times"); + log_info("Inference of InferRequests from networks: " << test_params.model_name << " for \"" + << test_params.device << "\" device with " << nstreams + << " streams for " << test_params.numiters << " times"); return common_test_pipeline(pipeline, test_params.numiters); }; test_runner(test_params.numthreads, test); @@ -198,14 +197,11 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { // tests_pipelines/tests_pipelines.cpp -INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoModel, - ::testing::ValuesIn(generateTestsParamsMemLeaks()), +INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoModel, ::testing::ValuesIn(generateTestsParamsMemLeaks()), getTestCaseNameMemLeaks); -INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoDevice, - ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseNameMemLeaks); +INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuiteNoDevice, ::testing::ValuesIn(generateTestsParamsMemLeaks()), + getTestCaseNameMemLeaks); -INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuite, - ::testing::ValuesIn(generateTestsParamsMemLeaks()), - getTestCaseNameMemLeaks); +INSTANTIATE_TEST_SUITE_P(MemLeaksTests, MemLeaksTestSuite, ::testing::ValuesIn(generateTestsParamsMemLeaks()), + getTestCaseNameMemLeaks); diff --git a/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.cpp b/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.cpp index 37f4f7241560ab..e670e09631517c 100644 --- a/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.cpp +++ b/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.cpp @@ -31,30 +31,30 @@ using namespace InferenceEngine; enum MeasureValue { VMRSS = 0, VMHWM, VMSIZE, VMPEAK, THREADS, MeasureValueMax }; namespace util { -template -void transform(const In& in, Out& out, const Func& func) { - std::transform(std::begin(in), std::end(in), std::begin(out), func); -} + template + void transform(const In &in, Out &out, const Func &func) { + std::transform(std::begin(in), std::end(in), std::begin(out), func); + } -template -void transform(const In1& in1, const In2& in2, Out& out, const Func& func) { - std::transform(std::begin(in1), std::end(in1), std::begin(in2), std::begin(out), func); -} -} // namespace util + template + void transform(const In1 &in1, const In2 &in2, Out &out, const Func &func) { + std::transform(std::begin(in1), std::end(in1), std::begin(in2), std::begin(out), func); + } +}// namespace util -TestResult common_test_pipeline(std::vector> test_pipeline, const int& n) { +TestResult common_test_pipeline(std::vector> test_pipeline, const int &n) { if (AVERAGE_NUM > n) return TestResult(TestStatus::TEST_FAILED, "Test failed: number of iterations less than defined AVERAGE_NUM"); int retry_count = 0; - std::array cur {}; // measured for current iteration - std::array ref = {-1}; // recorded reference - std::array diff {}; // difference between current and reference - std::array outlier {}; // flag if current does not fit threshold - std::array outlier_count {}; // counter for how many times current does not fit threshold - std::array threshold {}; // ref * THRESHOLD - std::vector> past; // past measures - std::array sliding_avg {}; // sliding average computed as avg of past AVERAGE_NUM values + std::array cur{}; // measured for current iteration + std::array ref = {-1}; // recorded reference + std::array diff{}; // difference between current and reference + std::array outlier{}; // flag if current does not fit threshold + std::array outlier_count{}; // counter for how many times current does not fit threshold + std::array threshold{}; // ref * THRESHOLD + std::vector> past;// past measures + std::array sliding_avg{}; // sliding average computed as avg of past AVERAGE_NUM values std::string progress_str; progress_str.reserve(LOG_LINE_RESERVE); @@ -63,9 +63,9 @@ TestResult common_test_pipeline(std::vector> test_pipeline log_info("Warming up for " << WARMUP_STEPS << " iterations"); log_info("i\tVMRSS\tVMHWM\tVMSIZE\tVMPEAK\tTHREADS"); - for (size_t iteration = 1, measure_count = n / AVERAGE_NUM; ; iteration++) { + for (size_t iteration = 1, measure_count = n / AVERAGE_NUM;; iteration++) { // run test pipeline and collect metrics - for (auto step: test_pipeline) step(); + for (auto step : test_pipeline) step(); getVmValues(cur[VMSIZE], cur[VMPEAK], cur[VMRSS], cur[VMHWM]); cur[THREADS] = getThreadsNum(); @@ -77,14 +77,11 @@ TestResult common_test_pipeline(std::vector> test_pipeline for (size_t i = 0; i < AVERAGE_NUM; i++) { // sliding_avg = sliding_avg + past util::transform(sliding_avg, past[i], sliding_avg, - [](long sliding_avg_val, long past_val) -> long { - return sliding_avg_val + past_val; - }); + [](long sliding_avg_val, long past_val) -> long { return sliding_avg_val + past_val; }); } // sliding_avg = sliding_avg / AVERAGE_NUM - util::transform(sliding_avg, sliding_avg, [](long sliding_avg_val) -> float { - return sliding_avg_val / AVERAGE_NUM; - }); + util::transform(sliding_avg, sliding_avg, + [](long sliding_avg_val) -> float { return sliding_avg_val / AVERAGE_NUM; }); progress_str = std::to_string(iteration) + "\t" + std::to_string(sliding_avg[VMRSS]) + "\t" + std::to_string(sliding_avg[VMHWM]) + "\t" + std::to_string(sliding_avg[VMSIZE]) + "\t" + @@ -93,9 +90,9 @@ TestResult common_test_pipeline(std::vector> test_pipeline // compute test info if (iteration >= WARMUP_STEPS) { // set reference - if ((ref == std::array {-1}) || - (retry_count <= MAX_RETRY && - (outlier_count[VMRSS] > MAX_OUTLIERS || outlier_count[VMHWM] > MAX_OUTLIERS))) { + if ((ref == std::array{-1}) || + (retry_count <= MAX_RETRY && + (outlier_count[VMRSS] > MAX_OUTLIERS || outlier_count[VMHWM] > MAX_OUTLIERS))) { if (0 != retry_count) log_info("Retrying " << retry_count << " of " << MAX_RETRY); retry_count++; @@ -104,14 +101,11 @@ TestResult common_test_pipeline(std::vector> test_pipeline // set reference as current `sliding_avg` ref = sliding_avg; // threshold = THRESHOLD * ref - util::transform(ref, threshold, [](long ref_val) -> float { - return THRESHOLD * ref_val; - }); + util::transform(ref, threshold, [](long ref_val) -> float { return THRESHOLD * ref_val; }); log_info("Setting thresholds:" << " VMRSS=" << ref[VMRSS] << "(+-" << static_cast(threshold[VMRSS]) << ")," << " VMHWM=" << ref[VMHWM] << "(+-" << static_cast(threshold[VMHWM]) << ")"); - } - else if (measure_count <= 0) { + } else if (measure_count <= 0) { // exit from main loop break; } @@ -123,9 +117,8 @@ TestResult common_test_pipeline(std::vector> test_pipeline return sliding_avg_val - ref_val; }); // outlier = diff > threshold - util::transform(diff, threshold, outlier, [](long diff_val, float threshold_val) -> bool { - return diff_val > threshold_val; - }); + util::transform(diff, threshold, outlier, + [](long diff_val, float threshold_val) -> bool { return diff_val > threshold_val; }); // outlier_count = outlier_count + (outlier ? 1 : 0) util::transform(outlier, outlier_count, outlier_count, [](bool outlier_val, long outlier_count_val) -> long { diff --git a/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.h b/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.h index cf5e83c485f131..d0c7650b53051e 100644 --- a/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.h +++ b/tests/stress_tests/memleaks_tests/tests_pipelines/tests_pipelines.h @@ -4,14 +4,14 @@ #pragma once +#include "../../common/ie_pipelines/pipelines.h" #include "../../common/tests_utils.h" #include "../../common/utils.h" -#include "../../common/ie_pipelines/pipelines.h" #include #include // tests_pipelines/tests_pipelines.cpp -TestResult common_test_pipeline(std::vector> test_pipeline, const int& n); +TestResult common_test_pipeline(std::vector> test_pipeline, const int &n); // tests_pipelines/tests_pipelines.cpp From a75389aabf7024d2c6baac3f0b6e1d35c69bb986 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Tue, 14 Sep 2021 12:14:08 +0300 Subject: [PATCH 096/102] wrong changes --- tests/stress_tests/.clang-format | 66 ---------------------- tests/stress_tests/common/tests_utils.h | 73 +++++++++++++++++-------- 2 files changed, 50 insertions(+), 89 deletions(-) delete mode 100644 tests/stress_tests/.clang-format diff --git a/tests/stress_tests/.clang-format b/tests/stress_tests/.clang-format deleted file mode 100644 index 92399ef0e71558..00000000000000 --- a/tests/stress_tests/.clang-format +++ /dev/null @@ -1,66 +0,0 @@ -# Generated from CLion C/C++ Code Style settings -BasedOnStyle: LLVM -AccessModifierOffset: -4 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: None -AlignOperands: Align -AllowAllArgumentsOnNextLine: false -AllowAllConstructorInitializersOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: Always -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Always -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterReturnType: None -AlwaysBreakTemplateDeclarations: Yes -BreakBeforeBraces: Custom -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: true -BreakBeforeBinaryOperators: None -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: BeforeColon -BreakInheritanceList: BeforeColon -ColumnLimit: 0 -CompactNamespaces: false -ContinuationIndentWidth: 8 -IndentCaseLabels: true -IndentPPDirectives: None -IndentWidth: 4 -KeepEmptyLinesAtTheStartOfBlocks: true -MaxEmptyLinesToKeep: 2 -NamespaceIndentation: All -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PointerAlignment: Right -ReflowComments: false -SpaceAfterCStyleCast: true -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 0 -SpacesInAngles: false -SpacesInCStyleCastParentheses: false -SpacesInContainerLiterals: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -TabWidth: 4 -UseTab: Never diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 33d8222b54add4..922a76d2f4936b 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -9,65 +9,92 @@ #include #include #include -#include #include +#include -enum TestStatus { TEST_NOT_STARTED = 0, TEST_FAILED, TEST_OK }; +enum TestStatus +{ + TEST_NOT_STARTED = 0, + TEST_FAILED, + TEST_OK +}; using TestResult = std::pair; -class TestCase { +class TestCaseBase { public: int numprocesses; int numthreads; int numiters; - std::string device; - std::string model_name; - std::string model; std::string precision; std::string test_case_name; - - TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string &_model, - const std::string &_model_name, const std::string &_precision) { - numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, - model_name = _model_name, precision = _precision; - test_case_name = "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + - "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + - "_Precision_" + update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); - } - -private: + std::string model_name; + std::string device; +protected: std::string update_item_for_name(const std::string &item) { std::string _item(item); for (std::string::size_type index = 0; index < _item.size(); ++index) { - if (!isalnum(_item[index]) && _item[index] != '_') _item[index] = '_'; + if (!isalnum(_item[index]) && _item[index] != '_') + _item[index] = '_'; } return _item; } }; +class TestCase: public TestCaseBase { +public: + std::string model; + + TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string& _model, const std::string& _model_name, const std::string& _precision) { + numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, model_name = _model_name, precision = _precision; + test_case_name = + "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + + "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + "_Precision_" + + update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); + } +}; + +class MemLeaksTestCase: public TestCaseBase { +public: + std::vector> models; + + MemLeaksTestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, std::vector> _models) { + numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, models = _models; + test_case_name = + "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + + "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device); + for (int i = 0; i < models.size(); i++){ + test_case_name += + "_Model" + std::to_string(i) + "_" + update_item_for_name(models[i]["name"]) + + "_Precision_" + update_item_for_name(models[i]["precision"]); + model_name += "\"" + models[i]["name"] + "\"" + (i < models.size() - 1 ? ", " : ""); + } + } +}; + class Environment { private: pugi::xml_document _test_config; bool _collect_results_only = false; Environment() = default; - Environment(const Environment &) = delete; - Environment &operator=(const Environment &) = delete; - + Environment(const Environment&) = delete; + Environment& operator=(const Environment&) = delete; public: - static Environment &Instance() { + static Environment& Instance(){ static Environment env; return env; } - const pugi::xml_document &getTestConfig(); + const pugi::xml_document & getTestConfig(); void setTestConfig(const pugi::xml_document &test_config); }; std::vector generateTestsParams(std::initializer_list items); +std::vector generateTestsParamsMemLeaks(); std::string getTestCaseName(const testing::TestParamInfo &obj); +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj); void runTest(const std::function &tests_pipeline, const TestCase ¶ms); void _runTest(const std::function &tests_pipeline, const TestCase ¶ms); From f928936f72e127a9ba1aeae8478a380134c84b2f Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Tue, 14 Sep 2021 12:43:20 +0300 Subject: [PATCH 097/102] Add docstring to generateTestsParamsMemLeaks() --- tests/stress_tests/common/tests_utils.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 53fde7fa96fefc..4d77c416555b9d 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -78,6 +78,9 @@ std::vector generateTestsParams(std::initializer_list fie } std::vector generateTestsParamsMemLeaks() { + /* + * Generate multi-model test cases from config file with static test definition. + */ std::vector tests_cases; const pugi::xml_document &test_config = Environment::Instance().getTestConfig(); @@ -111,9 +114,13 @@ std::vector generateTestsParamsMemLeaks() { return tests_cases; } -std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } +std::string getTestCaseName(const testing::TestParamInfo &obj) { + return obj.param.test_case_name; +} -std::string getTestCaseName(const testing::TestParamInfo &obj) { return obj.param.test_case_name; } +std::string getTestCaseNameMemLeaks(const testing::TestParamInfo &obj) { + return obj.param.test_case_name; +} void test_wrapper(const std::function &tests_pipeline, const TestCase ¶ms) { tests_pipeline(params.model, params.device, params.numiters); From 950e34f9623622c0c8209d4e91f64cde2823354b Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Tue, 14 Sep 2021 12:53:24 +0300 Subject: [PATCH 098/102] add explanation what update_item_for_name() doing --- tests/stress_tests/common/tests_utils.cpp | 4 +--- tests/stress_tests/common/tests_utils.h | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index 4d77c416555b9d..ede7560d719bb5 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -77,10 +77,8 @@ std::vector generateTestsParams(std::initializer_list fie return tests_cases; } +// Generate multi-model test cases from config file with static test definition. std::vector generateTestsParamsMemLeaks() { - /* - * Generate multi-model test cases from config file with static test definition. - */ std::vector tests_cases; const pugi::xml_document &test_config = Environment::Instance().getTestConfig(); diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 922a76d2f4936b..8f7beaa3b35eb1 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -32,6 +32,7 @@ class TestCaseBase { std::string model_name; std::string device; protected: + // Swap non-alphabetic/numeric symbols with "_" to prevent logging errors std::string update_item_for_name(const std::string &item) { std::string _item(item); for (std::string::size_type index = 0; index < _item.size(); ++index) { From 0749734fd9ae2a3dd7e76f1a0d1b1285d63d60ae Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Tue, 14 Sep 2021 13:08:09 +0300 Subject: [PATCH 099/102] Autodetect stress framework while parsing models --- tests/stress_tests/scripts/get_testdata.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index f3cf544174d691..6bc78ead8212b9 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -85,11 +85,14 @@ def run_in_subprocess(cmd, check_call=True): subprocess.call(cmd, shell=True) -def get_model_recs(test_conf_root, test_framework): - """Parse models from test config.""" - if test_framework == "memleak": +def get_model_recs(test_conf_root): + """Parse models from test config. + Model records in multi-model configs with static test definition are members of "device" sections + """ + device_recs = test_conf_root.findall("device") + if device_recs: model_recs = [] - for device_rec in test_conf_root.findall("device"): + for device_rec in device_recs: for model_rec in device_rec.findall("model"): model_recs.append(model_rec) @@ -107,9 +110,6 @@ def main(): parser.add_argument('--test_conf', required=True, type=Path, help='Path to a test config .xml file containing models ' 'which will be downloaded and converted to IRs via OMZ.') - parser.add_argument('--test_framework', required=False, default=None, - help='Test framework name.' - 'Set the "memleak" value to preprocess memLeakTest configs and skip in other cases.') parser.add_argument('--omz_repo', required=False, help='Path to Open Model Zoo (OMZ) repository. It will be used to skip cloning step.') parser.add_argument('--mo_tool', type=Path, @@ -158,7 +158,7 @@ def main(): test_conf_obj = ET.parse(str(args.test_conf)) test_conf_root = test_conf_obj.getroot() - model_recs = get_model_recs(test_conf_root, args.test_framework) + model_recs = get_model_recs(test_conf_root) for model_rec in model_recs: if "name" not in model_rec.attrib or model_rec.attrib.get("source") != "omz": From 66a6d2bcb81e82957ffd8be67ad1ec777b330ad8 Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Tue, 14 Sep 2021 13:09:50 +0300 Subject: [PATCH 100/102] adjust the wording --- tests/stress_tests/common/tests_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 8f7beaa3b35eb1..e81be678d9f660 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -32,7 +32,7 @@ class TestCaseBase { std::string model_name; std::string device; protected: - // Swap non-alphabetic/numeric symbols with "_" to prevent logging errors + // Replace non-alphabetic/numeric symbols with "_" to prevent logging errors std::string update_item_for_name(const std::string &item) { std::string _item(item); for (std::string::size_type index = 0; index < _item.size(); ++index) { From 91b3231bd7dc84ad897e8e014bb09d765903d70b Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Wed, 15 Sep 2021 09:05:25 +0300 Subject: [PATCH 101/102] Shorten test cases names --- tests/stress_tests/common/tests_utils.cpp | 6 ++- tests/stress_tests/common/tests_utils.h | 59 ++++++++++----------- tests/stress_tests/memleaks_tests/tests.cpp | 16 +++--- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index ede7560d719bb5..9592119cdce3a7 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -102,8 +102,12 @@ std::vector generateTestsParamsMemLeaks() { if (full_path.empty() || path.empty()) throw std::logic_error( "One of the 'model' records from test config doesn't contain 'full_path' or 'path' attributes"); + std::string name = model.attribute("name").as_string(); std::string precision = model.attribute("precision").as_string(); - std::map model_map{{"name", path}, {"path", full_path}, {"path", precision}}; + std::map model_map{{"name", name}, + {"path", path}, + {"full_path", full_path}, + {"precision", precision}}; models.push_back(model_map); } tests_cases.push_back(MemLeaksTestCase(numprocesses, numthreads, numiterations, device_name, models)); diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index e81be678d9f660..83e490702bf143 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -9,16 +9,11 @@ #include #include #include -#include #include +#include -enum TestStatus -{ - TEST_NOT_STARTED = 0, - TEST_FAILED, - TEST_OK -}; +enum TestStatus { TEST_NOT_STARTED = 0, TEST_FAILED, TEST_OK }; using TestResult = std::pair; @@ -31,45 +26,46 @@ class TestCaseBase { std::string test_case_name; std::string model_name; std::string device; + protected: // Replace non-alphabetic/numeric symbols with "_" to prevent logging errors std::string update_item_for_name(const std::string &item) { std::string _item(item); for (std::string::size_type index = 0; index < _item.size(); ++index) { - if (!isalnum(_item[index]) && _item[index] != '_') - _item[index] = '_'; + if (!isalnum(_item[index]) && _item[index] != '_') _item[index] = '_'; } return _item; } }; -class TestCase: public TestCaseBase { +class TestCase : public TestCaseBase { public: std::string model; - TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string& _model, const std::string& _model_name, const std::string& _precision) { - numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, model_name = _model_name, precision = _precision; - test_case_name = - "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + - "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + "_Precision_" + - update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); + TestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, const std::string &_model, + const std::string &_model_name, const std::string &_precision) { + numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, model = _model, + model_name = _model_name, precision = _precision; + test_case_name = "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + + "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device) + + "_Precision_" + update_item_for_name(precision) + "_Model_" + update_item_for_name(model_name); } }; -class MemLeaksTestCase: public TestCaseBase { +class MemLeaksTestCase : public TestCaseBase { public: std::vector> models; - MemLeaksTestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, std::vector> _models) { - numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, models = _models; - test_case_name = - "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + - "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device); - for (int i = 0; i < models.size(); i++){ - test_case_name += - "_Model" + std::to_string(i) + "_" + update_item_for_name(models[i]["name"]) + - "_Precision_" + update_item_for_name(models[i]["precision"]); - model_name += "\"" + models[i]["name"] + "\"" + (i < models.size() - 1 ? ", " : ""); + MemLeaksTestCase(int _numprocesses, int _numthreads, int _numiters, std::string _device, + std::vector> _models) { + numprocesses = _numprocesses, numthreads = _numthreads, numiters = _numiters, device = _device, + models = _models; + test_case_name = "Numprocesses_" + std::to_string(numprocesses) + "_Numthreads_" + std::to_string(numthreads) + + "_Numiters_" + std::to_string(numiters) + "_Device_" + update_item_for_name(device); + for (int i = 0; i < models.size(); i++) { + test_case_name += "_Model" + std::to_string(i + 1) + "_" + update_item_for_name(models[i]["name"]) + "_" + + update_item_for_name(models[i]["precision"]); + model_name += "\"" + models[i]["path"] + "\"" + (i < models.size() - 1 ? ", " : ""); } } }; @@ -80,15 +76,16 @@ class Environment { bool _collect_results_only = false; Environment() = default; - Environment(const Environment&) = delete; - Environment& operator=(const Environment&) = delete; + Environment(const Environment &) = delete; + Environment &operator=(const Environment &) = delete; + public: - static Environment& Instance(){ + static Environment &Instance() { static Environment env; return env; } - const pugi::xml_document & getTestConfig(); + const pugi::xml_document &getTestConfig(); void setTestConfig(const pugi::xml_document &test_config); }; diff --git a/tests/stress_tests/memleaks_tests/tests.cpp b/tests/stress_tests/memleaks_tests/tests.cpp index 2b1d7693a00284..a24881590ee461 100644 --- a/tests/stress_tests/memleaks_tests/tests.cpp +++ b/tests/stress_tests/memleaks_tests/tests.cpp @@ -52,7 +52,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, read_network) { std::vector> pipeline; for (int i = 0; i < test_params.models.size(); i++) { - pipeline.push_back(read_cnnnetwork(test_params.models[i]["path"])); + pipeline.push_back(read_cnnnetwork(test_params.models[i]["full_path"])); } auto test = [&] { log_info("Read networks: " << test_params.model_name << " for " << test_params.numiters << " times"); @@ -66,7 +66,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, cnnnetwork_reshape_batch_x2) { std::vector> pipeline; for (int i = 0; i < test_params.models.size(); i++) { - pipeline.push_back(cnnnetwork_reshape_batch_x2(test_params.models[i]["path"])); + pipeline.push_back(cnnnetwork_reshape_batch_x2(test_params.models[i]["full_path"])); } auto test = [&] { log_info("Reshape to batch*=2 of CNNNetworks created from networks: " << test_params.model_name << " for " @@ -81,7 +81,7 @@ TEST_P(MemLeaksTestSuiteNoDevice, set_input_params) { std::vector> pipeline; for (int i = 0; i < test_params.models.size(); i++) { - pipeline.push_back(set_input_params(test_params.models[i]["path"])); + pipeline.push_back(set_input_params(test_params.models[i]["full_path"])); } auto test = [&] { log_info("Apply preprocessing for CNNNetworks from networks: " << test_params.model_name << " for " @@ -97,7 +97,7 @@ TEST_P(MemLeaksTestSuite, recreate_exenetwork) { std::vector> pipeline; for (int i = 0; i < test_params.models.size(); i++) { - pipeline.push_back(recreate_exenetwork(ie, test_params.models[i]["path"], test_params.device)); + pipeline.push_back(recreate_exenetwork(ie, test_params.models[i]["full_path"], test_params.device)); } auto test = [&] { log_info("Recreate ExecutableNetworks within existing InferenceEngine::Core from networks: " @@ -118,7 +118,7 @@ TEST_P(MemLeaksTestSuite, recreate_infer_request) { exeNetworks.reserve(n_models); for (int i = 0; i < n_models; i++) { - CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["path"]); + CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["full_path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); exeNetworks.push_back(exeNetwork); pipeline.push_back(recreate_infer_request(exeNetworks[i])); @@ -143,7 +143,7 @@ TEST_P(MemLeaksTestSuite, reinfer_request_inference) { outputs_info.reserve(n_models); for (int i = 0; i < n_models; i++) { - CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["path"]); + CNNNetwork cnnNetwork = ie.ReadNetwork(test_params.models[i]["full_path"]); ExecutableNetwork exeNetwork = ie.LoadNetwork(cnnNetwork, test_params.device); InferRequest infer_request = exeNetwork.CreateInferRequest(); infer_requests.push_back(infer_request); @@ -168,7 +168,7 @@ TEST_P(MemLeaksTestSuite, infer_request_inference) { auto test_params = GetParam(); std::vector> pipeline; for (int i = 0; i < test_params.models.size(); i++) { - pipeline.push_back(infer_request_inference(test_params.models[i]["path"], test_params.device)); + pipeline.push_back(infer_request_inference(test_params.models[i]["full_path"], test_params.device)); } auto test = [&] { log_info("Inference of InferRequests from networks: " << test_params.model_name << " for \"" @@ -184,7 +184,7 @@ TEST_P(MemLeaksTestSuite, inference_with_streams) { const auto nstreams = 2; std::vector> pipeline; for (int i = 0; i < test_params.models.size(); i++) { - pipeline.push_back(inference_with_streams(test_params.models[i]["path"], test_params.device, nstreams)); + pipeline.push_back(inference_with_streams(test_params.models[i]["full_path"], test_params.device, nstreams)); } auto test = [&] { log_info("Inference of InferRequests from networks: " << test_params.model_name << " for \"" From 89b6880996cd35149b3a069f43da42e104d1287c Mon Sep 17 00:00:00 2001 From: Alexander Shchepetov Date: Wed, 15 Sep 2021 13:46:49 +0300 Subject: [PATCH 102/102] fix get_testdata for memcheck tests --- tests/stress_tests/scripts/get_testdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index 6bc78ead8212b9..a18c6045d0208c 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -98,7 +98,7 @@ def get_model_recs(test_conf_root): return model_recs - return test_conf_root.findall("model") + return test_conf_root.find("models") def main():