From 4e6eeea6ffdfc4a58d648fe5f663f66abc99bef2 Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Wed, 1 Dec 2021 21:31:16 +0300 Subject: [PATCH] [PYTHON API] move frontend bindings to pyopenvino + move MO to use new Python API (#8301) * move frontend folder to pyopenvino * rename includes and add compile options * include frontend to pyopenvino * move __init__.py * move tests * remove mock from tests_compatibility * rename import module * Fix code style cpp * refactor a few lines * update few lines in mo * Add pyopenvino to dependencies * Fix mock * update docstring * Fix mo test * remove module local * fix code style * update comment * fix return type * update docs * fix code style * fix building * fix code style * try to move MO to use new api * Export more enum names from nrgaph * [Python API] quick fix of packaging * update tests * fix setup.py * small fix * small fixes according to comments * skip mo frontend tests * update mo to new imports * try to fix win wheel * fix win wheel * fix code style Co-authored-by: Anastasia Kuporosova Co-authored-by: y --- model-optimizer/CMakeLists.txt | 2 +- .../mo/back/offline_transformations.py | 46 +- model-optimizer/mo/main.py | 2 +- model-optimizer/mo/main_onnx.py | 2 +- model-optimizer/mo/main_paddle.py | 2 +- model-optimizer/mo/moc_frontend/extractor.py | 2 +- model-optimizer/mo/moc_frontend/pipeline.py | 6 +- model-optimizer/mo/moc_frontend/serialize.py | 14 +- model-optimizer/mo/utils/check_ie_bindings.py | 35 +- model-optimizer/mo/utils/ie_version.py | 2 +- .../mo/frontend_ngraph_test_actual.py | 6 +- .../moc_frontend/moc_extractor_test_actual.py | 2 +- src/bindings/python/CMakeLists.txt | 4 +- src/bindings/python/setup.py | 2 +- .../src/compatibility/ngraph/__init__.py | 9 - .../compatibility/ngraph/frontend/__init__.py | 24 - .../src/compatibility/pyngraph/CMakeLists.txt | 2 +- .../pyngraph/frontend/frontend_manager.hpp | 17 - .../src/compatibility/pyngraph/pyngraph.cpp | 15 - .../python/src/openvino/frontend/__init__.py | 50 ++ .../__init__.py | 27 + .../src/openvino/preprocess/__init__.py | 27 + .../python/src/openvino/runtime/__init__.py | 26 + .../python/src/pyopenvino/CMakeLists.txt | 22 +- .../frontend/frontend.cpp | 11 +- .../frontend/frontend.hpp | 6 +- .../frontend/frontend_manager.cpp | 17 +- .../pyopenvino/frontend/frontend_manager.hpp | 17 + .../frontend/inputmodel.cpp | 7 +- .../frontend/inputmodel.hpp | 2 +- .../frontend/place.cpp | 11 +- .../frontend/place.hpp | 2 +- .../python/src/pyopenvino/pyopenvino.cpp | 16 + .../test_frontend/test_frontend_onnx.py | 4 +- .../test_frontend_onnx_editor.py | 4 +- .../test_frontend/test_frontendmanager.py | 6 +- .../mock_py_ngraph_frontend/CMakeLists.txt | 24 - .../mock_py_frontend.cpp | 25 - .../mock_py_frontend.hpp | 665 ------------------ .../mock/pyngraph_fe_mock_api/CMakeLists.txt | 20 - .../pyngraph_mock_frontend_api.cpp | 127 ---- 41 files changed, 277 insertions(+), 1033 deletions(-) delete mode 100644 src/bindings/python/src/compatibility/ngraph/frontend/__init__.py delete mode 100644 src/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.hpp create mode 100644 src/bindings/python/src/openvino/frontend/__init__.py rename src/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/frontend.cpp (93%) rename src/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/frontend.hpp (51%) rename src/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/frontend_manager.cpp (87%) create mode 100644 src/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp rename src/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/inputmodel.cpp (97%) rename src/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/inputmodel.hpp (76%) rename src/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/place.cpp (96%) rename src/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/place.hpp (78%) rename src/bindings/python/{tests_compatibility => tests}/test_frontend/test_frontend_onnx.py (97%) rename src/bindings/python/{tests_compatibility => tests}/test_frontend/test_frontend_onnx_editor.py (99%) rename src/bindings/python/{tests_compatibility => tests}/test_frontend/test_frontendmanager.py (99%) delete mode 100644 src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/CMakeLists.txt delete mode 100644 src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.cpp delete mode 100644 src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp delete mode 100644 src/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/CMakeLists.txt delete mode 100644 src/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/pyngraph_mock_frontend_api.cpp diff --git a/model-optimizer/CMakeLists.txt b/model-optimizer/CMakeLists.txt index 8e95e364adf..dd62af9a1bf 100644 --- a/model-optimizer/CMakeLists.txt +++ b/model-optimizer/CMakeLists.txt @@ -4,7 +4,7 @@ if(NOT ENABLE_PYTHON) message(WARNING "Please enable IE & nGraph Python API (ie_api and offline_transformations_api) targets to enable Model Optimizer target") else() - add_custom_target(model_optimizer DEPENDS ie_api offline_transformations_api ir_ov_frontend) + add_custom_target(model_optimizer DEPENDS ie_api offline_transformations_api ir_ov_frontend pyopenvino) if(ENABLE_TESTS) add_subdirectory(unit_tests/mock_mo_frontend/mock_mo_ov_frontend) add_dependencies(model_optimizer mock_mo_ov_frontend) diff --git a/model-optimizer/mo/back/offline_transformations.py b/model-optimizer/mo/back/offline_transformations.py index 79f9d847323..34f0acd100e 100644 --- a/model-optimizer/mo/back/offline_transformations.py +++ b/model-optimizer/mo/back/offline_transformations.py @@ -9,65 +9,63 @@ from mo.utils.cli_parser import parse_transform def get_available_transformations(): try: - from openvino.offline_transformations import ApplyLowLatencyTransformation, ApplyMakeStatefulTransformation # pylint: disable=import-error,no-name-in-module + from openvino.offline_transformations_pybind import apply_low_latency_transformation, apply_make_stateful_transformation # pylint: disable=import-error,no-name-in-module return { - 'MakeStateful': ApplyMakeStatefulTransformation, - 'LowLatency2': ApplyLowLatencyTransformation, + 'MakeStateful': apply_make_stateful_transformation, + 'LowLatency2': apply_low_latency_transformation, } except Exception as e: return {} # net should be openvino.inference_engine.IENetwork type, but IE Engine is still optional dependency -def apply_user_transformations(net: object, transforms: list): +def apply_user_transformations(func: object, transforms: list): available_transformations = get_available_transformations() for name, args in transforms: if name not in available_transformations.keys(): raise Error("Transformation {} is not available.".format(name)) - available_transformations[name](net, **args) + available_transformations[name](func, **args) -def apply_moc_transformations(net: object): - from openvino.offline_transformations import ApplyMOCTransformations # pylint: disable=import-error,no-name-in-module - ApplyMOCTransformations(net, False) +def apply_moc_transformations(func: object): + from openvino.offline_transformations_pybind import apply_moc_transformations # pylint: disable=import-error,no-name-in-module + apply_moc_transformations(func, False) -def compress_model(net:object): - from openvino.offline_transformations import CompressModelTransformation # pylint: disable=import-error,no-name-in-module - CompressModelTransformation(net) +def compress_model(func: object): + from openvino.offline_transformations_pybind import compress_model_transformation # pylint: disable=import-error,no-name-in-module + compress_model_transformation(func) def apply_offline_transformations(input_model: str, framework: str, transforms: list, compress_fp16=False): # This variable is only needed by GenerateMappingFile transformation # to produce correct mapping extract_names = framework in ['tf', 'mxnet', 'kaldi'] - from openvino.offline_transformations import GenerateMappingFile, Serialize # pylint: disable=import-error,no-name-in-module - from openvino.inference_engine import IENetwork # pylint: disable=import-error,no-name-in-module - from ngraph.frontend import FrontEndManager, FrontEnd # pylint: disable=no-name-in-module,import-error - from ngraph.impl import Function # pylint: disable=no-name-in-module,import-error + from openvino.offline_transformations_pybind import generate_mapping_file, serialize # pylint: disable=import-error,no-name-in-module + from openvino.frontend import FrontEndManager, FrontEnd # pylint: disable=no-name-in-module,import-error fem = FrontEndManager() # We have to separate fe object lifetime from fem to # avoid segfault during object destruction. So fe must # be destructed before fem object explicitly. - def read_network(path_to_xml): + def read_model(path_to_xml): fe = fem.load_by_framework(framework="ir") - f = fe.convert(fe.load(path_to_xml)) - return IENetwork(Function.to_capsule(f)) + function = fe.convert(fe.load(path_to_xml)) + return function - net = read_network(input_model + "_tmp.xml") + func = read_model(input_model + "_tmp.xml") - apply_user_transformations(net, transforms) - apply_moc_transformations(net) + apply_user_transformations(func, transforms) + apply_moc_transformations(func) if compress_fp16: - compress_model(net) + compress_model(func) - Serialize(net, str(input_model + ".xml").encode('utf-8'), (input_model + ".bin").encode('utf-8')) + serialize(func, str(input_model + ".xml").encode('utf-8'), (input_model + ".bin").encode('utf-8')) path_to_mapping = input_model + ".mapping" - GenerateMappingFile(net, path_to_mapping.encode('utf-8'), extract_names) + generate_mapping_file(func, path_to_mapping.encode('utf-8'), extract_names) if __name__ == "__main__": diff --git a/model-optimizer/mo/main.py b/model-optimizer/mo/main.py index d5b7657ce76..b81d50a3c99 100644 --- a/model-optimizer/mo/main.py +++ b/model-optimizer/mo/main.py @@ -45,7 +45,7 @@ from mo.utils.versions_checker import check_requirements # pylint: disable=no-n from mo.utils.telemetry_utils import get_tid # pylint: disable=no-name-in-module,import-error -from ngraph.frontend import FrontEndManager, TelemetryExtension +from openvino.frontend import FrontEndManager, TelemetryExtension def replace_ext(name: str, old: str, new: str): diff --git a/model-optimizer/mo/main_onnx.py b/model-optimizer/mo/main_onnx.py index 3f2fbb870bc..51bcc5bcd28 100644 --- a/model-optimizer/mo/main_onnx.py +++ b/model-optimizer/mo/main_onnx.py @@ -7,6 +7,6 @@ from mo.utils.cli_parser import get_onnx_cli_parser if __name__ == "__main__": from mo.main import main - from ngraph.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error + from openvino.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error sys.exit(main(get_onnx_cli_parser(), FrontEndManager(), 'onnx')) diff --git a/model-optimizer/mo/main_paddle.py b/model-optimizer/mo/main_paddle.py index a7d590ecfce..963652a578c 100644 --- a/model-optimizer/mo/main_paddle.py +++ b/model-optimizer/mo/main_paddle.py @@ -5,7 +5,7 @@ import sys from mo.utils.cli_parser import get_all_cli_parser -from ngraph.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error +from openvino.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error if __name__ == "__main__": diff --git a/model-optimizer/mo/moc_frontend/extractor.py b/model-optimizer/mo/moc_frontend/extractor.py index 4f40a898726..6d6d7611e1e 100644 --- a/model-optimizer/mo/moc_frontend/extractor.py +++ b/model-optimizer/mo/moc_frontend/extractor.py @@ -6,7 +6,7 @@ import re from mo.front.extractor import raise_no_node, raise_node_name_collision from mo.utils.error import Error -from ngraph.frontend import InputModel # pylint: disable=no-name-in-module,import-error +from openvino.frontend import InputModel # pylint: disable=no-name-in-module,import-error import numpy as np diff --git a/model-optimizer/mo/moc_frontend/pipeline.py b/model-optimizer/mo/moc_frontend/pipeline.py index ca6924824af..d9e1c1da43f 100644 --- a/model-optimizer/mo/moc_frontend/pipeline.py +++ b/model-optimizer/mo/moc_frontend/pipeline.py @@ -8,9 +8,9 @@ from typing import List from mo.moc_frontend.extractor import fe_user_data_repack from mo.middle.passes.infer import validate_batch_in_shape -from ngraph import Dimension, PartialShape # pylint: disable=no-name-in-module,import-error -from ngraph.frontend import FrontEnd, Place # pylint: disable=no-name-in-module,import-error -from ngraph.utils.types import get_element_type # pylint: disable=no-name-in-module,import-error +from openvino.runtime import Dimension, PartialShape # pylint: disable=no-name-in-module,import-error +from openvino.frontend import FrontEnd, Place # pylint: disable=no-name-in-module,import-error +from openvino.runtime.utils.types import get_element_type # pylint: disable=no-name-in-module,import-error def moc_pipeline(argv: argparse.Namespace, moc_front_end: FrontEnd): diff --git a/model-optimizer/mo/moc_frontend/serialize.py b/model-optimizer/mo/moc_frontend/serialize.py index 2de7c800d02..75104318e41 100644 --- a/model-optimizer/mo/moc_frontend/serialize.py +++ b/model-optimizer/mo/moc_frontend/serialize.py @@ -7,24 +7,24 @@ from mo.pipeline.common import get_ir_version from mo.back.ie_ir_ver_2.emitter import append_ir_info from mo.utils.cli_parser import get_meta_info, parse_transform -from ngraph import Function # pylint: disable=no-name-in-module,import-error -from ngraph import function_to_cnn # pylint: disable=no-name-in-module,import-error +from openvino.runtime import Function # pylint: disable=no-name-in-module,import-error def moc_emit_ir(ngraph_function: Function, argv: argparse.Namespace): output_dir = argv.output_dir if argv.output_dir != '.' else os.getcwd() - network = function_to_cnn(ngraph_function) from mo.back.offline_transformations import apply_user_transformations, apply_moc_transformations - apply_user_transformations(network, parse_transform(argv.transform)) - apply_moc_transformations(network) + apply_user_transformations(ngraph_function, parse_transform(argv.transform)) + apply_moc_transformations(ngraph_function) if argv.compress_fp16: from mo.back.offline_transformations import compress_model - compress_model(network) + compress_model(ngraph_function) orig_model_name = os.path.normpath(os.path.join(output_dir, argv.model_name)) - network.serialize(orig_model_name + ".xml", orig_model_name + ".bin") + + from openvino.offline_transformations_pybind import serialize # pylint: disable=import-error,no-name-in-module + serialize(ngraph_function, (orig_model_name + ".xml").encode('utf-8'), (orig_model_name + ".bin").encode('utf-8')) del argv.feManager diff --git a/model-optimizer/mo/utils/check_ie_bindings.py b/model-optimizer/mo/utils/check_ie_bindings.py index 1525767aab1..dc6b6a3d162 100644 --- a/model-optimizer/mo/utils/check_ie_bindings.py +++ b/model-optimizer/mo/utils/check_ie_bindings.py @@ -39,7 +39,7 @@ def send_telemetry(mo_version: str, message: str, event_type: str): def import_core_modules(silent: bool, path_to_module: str): """ - This function checks that InferenceEngine Python API is available + This function checks that OpenVINO Python API is available and necessary python modules exists. So the next list of imports must contain all IE/NG Python API imports that are used inside MO. @@ -48,21 +48,16 @@ def import_core_modules(silent: bool, path_to_module: str): :return: True if all imports were successful and False otherwise """ try: - from openvino.inference_engine import get_version, IENetwork # pylint: disable=import-error,no-name-in-module - from openvino.offline_transformations import ApplyMOCTransformations, ApplyLowLatencyTransformation # pylint: disable=import-error,no-name-in-module - from openvino.offline_transformations import ApplyMakeStatefulTransformation, GenerateMappingFile # pylint: disable=import-error,no-name-in-module - from openvino.offline_transformations import GenerateMappingFile, ApplyMakeStatefulTransformation, Serialize # pylint: disable=import-error,no-name-in-module + from openvino.offline_transformations_pybind import apply_moc_transformations, apply_low_latency_transformation # pylint: disable=import-error,no-name-in-module + from openvino.offline_transformations_pybind import apply_make_stateful_transformation, generate_mapping_file # pylint: disable=import-error,no-name-in-module + from openvino.offline_transformations_pybind import generate_mapping_file, apply_make_stateful_transformation, serialize # pylint: disable=import-error,no-name-in-module - # TODO: it is temporary import to check that nGraph python API is available. But in future - # we need to replace it with Frontend imports - from ngraph.impl import Function # pylint: disable=import-error,no-name-in-module - from ngraph.impl.op import Parameter # pylint: disable=import-error,no-name-in-module - from _pyngraph import PartialShape, Dimension # pylint: disable=import-error,no-name-in-module - from ngraph.frontend import FrontEndManager, FrontEnd # pylint: disable=no-name-in-module,import-error + from openvino.runtime import Function, get_version # pylint: disable=import-error,no-name-in-module + from openvino.runtime.impl.op import Parameter # pylint: disable=import-error,no-name-in-module + from openvino.runtime import PartialShape, Dimension # pylint: disable=import-error,no-name-in-module + from openvino.frontend import FrontEndManager, FrontEnd # pylint: disable=no-name-in-module,import-error - import openvino # pylint: disable=import-error,no-name-in-module - import ngraph # pylint: disable=import-error,no-name-in-module - import ngraph.frontend # pylint: disable=import-error,no-name-in-module + import openvino.frontend # pylint: disable=import-error,no-name-in-module if silent: return True @@ -70,10 +65,8 @@ def import_core_modules(silent: bool, path_to_module: str): ie_version = str(get_version()) mo_version = str(v.get_version()) # pylint: disable=no-member,no-name-in-module - print("\t- {}: \t{}".format("Inference Engine found in", os.path.dirname(openvino.__file__))) - # TODO: when nGraph version will be available we need to start compare it to IE and MO versions. Ticket: 58091 - print("\t- {}: \t{}".format("nGraph found in", os.path.dirname(ngraph.__file__))) - print("{}: \t{}".format("Inference Engine version", ie_version)) + print("\t- {}: \t{}".format("OpenVINO runtime found in", os.path.dirname(openvino.__file__))) + print("{}: \t{}".format("OpenVINO runtime version", ie_version)) print("{}: \t{}".format("Model Optimizer version", mo_version)) versions_mismatch = False @@ -82,8 +75,8 @@ def import_core_modules(silent: bool, path_to_module: str): extracted_mo_release_version = v.extract_release_version(mo_version) mo_is_custom = extracted_mo_release_version == (None, None) - print("[ WARNING ] Model Optimizer and Inference Engine versions do no match.") - print("[ WARNING ] Consider building the Inference Engine Python API from sources or reinstall OpenVINO " + print("[ WARNING ] Model Optimizer and OpenVINO runtime versions do no match.") + print("[ WARNING ] Consider building the OpenVINO Python API from sources or reinstall OpenVINO " "(TM) toolkit using", end=" ") if mo_is_custom: print("\"pip install openvino\" (may be incompatible with the current Model Optimizer version)") @@ -103,7 +96,7 @@ def import_core_modules(silent: bool, path_to_module: str): except Exception as e: # Do not print a warning if module wasn't found or silent mode is on if "No module named 'openvino" not in str(e): - print("[ WARNING ] Failed to import Inference Engine Python API in: {}".format(path_to_module)) + print("[ WARNING ] Failed to import OpenVINO Python API in: {}".format(path_to_module)) print("[ WARNING ] {}".format(e)) # Send telemetry message about warning diff --git a/model-optimizer/mo/utils/ie_version.py b/model-optimizer/mo/utils/ie_version.py index dbe4a2f5ae1..06ed5660fe9 100644 --- a/model-optimizer/mo/utils/ie_version.py +++ b/model-optimizer/mo/utils/ie_version.py @@ -3,7 +3,7 @@ def get_ie_version(): try: - from openvino.inference_engine import get_version # pylint: disable=import-error,no-name-in-module + from openvino.runtime import get_version # pylint: disable=import-error,no-name-in-module return get_version() except: return None diff --git a/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py b/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py index d09f8df90c9..c1947c9a6e4 100644 --- a/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py +++ b/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py @@ -24,9 +24,9 @@ try: mock_return_partial_shape # pylint: disable=no-name-in-module,import-error - from ngraph import PartialShape - from ngraph.frontend import FrontEndManager - from ngraph.utils.types import get_element_type + from openvino.runtime import PartialShape + from openvino.frontend import FrontEndManager + from openvino.runtime.utils.types import get_element_type except Exception: print("No mock frontend API available, " diff --git a/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py b/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py index 1b3226dd0a4..ee003d150d8 100644 --- a/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py +++ b/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py @@ -18,7 +18,7 @@ try: clear_setup, set_equal_data, set_max_port_counts # pylint: disable=no-name-in-module,import-error - from ngraph.frontend import FrontEndManager + from openvino.frontend import FrontEndManager except Exception: print("No mock frontend API available, " diff --git a/src/bindings/python/CMakeLists.txt b/src/bindings/python/CMakeLists.txt index 29c467eae9d..86df56bdb0d 100644 --- a/src/bindings/python/CMakeLists.txt +++ b/src/bindings/python/CMakeLists.txt @@ -18,7 +18,7 @@ add_subdirectory(src) if(NGRAPH_UNIT_TEST_ENABLE) add_subdirectory(tests/mock/mock_py_ov_frontend) - add_dependencies(_pyngraph mock_py_ov_frontend) + add_dependencies(pyopenvino mock_py_ov_frontend) set_target_properties(mock_py_ov_frontend PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_DIRECTORY_BIN} ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_DIRECTORY_BIN} @@ -26,7 +26,7 @@ if(NGRAPH_UNIT_TEST_ENABLE) PDB_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_DIRECTORY_BIN}) add_subdirectory(tests/mock/pyngraph_fe_mock_api) - add_dependencies(_pyngraph pybind_mock_frontend) + add_dependencies(pyopenvino pybind_mock_frontend) endif() if(InferenceEngineDeveloperPackage_FOUND) diff --git a/src/bindings/python/setup.py b/src/bindings/python/setup.py index 5ce6b95ddbe..6262ff4f9ce 100644 --- a/src/bindings/python/setup.py +++ b/src/bindings/python/setup.py @@ -39,9 +39,9 @@ packages = [ "ngraph.impl.op", "ngraph.impl.op.util", "ngraph.impl.passes", - "ngraph.frontend", "openvino", # TODO: change the module name according to the description in 69196 + "openvino.frontend", "openvino.offline_transformations_pybind", "openvino.runtime.opset1", "openvino.runtime.opset2", diff --git a/src/bindings/python/src/compatibility/ngraph/__init__.py b/src/bindings/python/src/compatibility/ngraph/__init__.py index 201621256e6..6e864d756e3 100644 --- a/src/bindings/python/src/compatibility/ngraph/__init__.py +++ b/src/bindings/python/src/compatibility/ngraph/__init__.py @@ -15,15 +15,6 @@ from ngraph.impl import Dimension from ngraph.impl import Function from ngraph.impl import Node from ngraph.impl import PartialShape -from ngraph.frontend import FrontEnd -from ngraph.frontend import FrontEndManager -from ngraph.frontend import GeneralFailure -from ngraph.frontend import NotImplementedFailure -from ngraph.frontend import InitializationFailure -from ngraph.frontend import InputModel -from ngraph.frontend import OpConversionFailure -from ngraph.frontend import OpValidationFailure -from ngraph.frontend import Place from ngraph.helpers import function_from_cnn from ngraph.helpers import function_to_cnn from ngraph.helpers import partial_shape_from_data diff --git a/src/bindings/python/src/compatibility/ngraph/frontend/__init__.py b/src/bindings/python/src/compatibility/ngraph/frontend/__init__.py deleted file mode 100644 index 339887581e6..00000000000 --- a/src/bindings/python/src/compatibility/ngraph/frontend/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -""" -Package: ngraph -Low level wrappers for the FrontEnd c++ api. -""" - -# flake8: noqa - -# main classes -from _pyngraph import FrontEndManager -from _pyngraph import FrontEnd -from _pyngraph import InputModel -from _pyngraph import Place - -from _pyngraph import TelemetryExtension - -# exceptions -from _pyngraph import NotImplementedFailure -from _pyngraph import InitializationFailure -from _pyngraph import OpConversionFailure -from _pyngraph import OpValidationFailure -from _pyngraph import GeneralFailure diff --git a/src/bindings/python/src/compatibility/pyngraph/CMakeLists.txt b/src/bindings/python/src/compatibility/pyngraph/CMakeLists.txt index b75e01bf30f..a0870de63f8 100644 --- a/src/bindings/python/src/compatibility/pyngraph/CMakeLists.txt +++ b/src/bindings/python/src/compatibility/pyngraph/CMakeLists.txt @@ -54,7 +54,7 @@ pybind11_add_module(_${PROJECT_NAME} MODULE ${SOURCES}) target_include_directories(_${PROJECT_NAME} PRIVATE "../") -target_link_libraries(_${PROJECT_NAME} PRIVATE openvino::core openvino::frontend::common) +target_link_libraries(_${PROJECT_NAME} PRIVATE openvino::core) # perform copy if(OpenVINO_SOURCE_DIR) diff --git a/src/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.hpp b/src/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.hpp deleted file mode 100644 index 969ddd6859a..00000000000 --- a/src/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace py = pybind11; - -void regclass_pyngraph_FrontEndManager(py::module m); -void regclass_pyngraph_NotImplementedFailureFrontEnd(py::module m); -void regclass_pyngraph_InitializationFailureFrontEnd(py::module m); -void regclass_pyngraph_OpConversionFailureFrontEnd(py::module m); -void regclass_pyngraph_OpValidationFailureFrontEnd(py::module m); -void regclass_pyngraph_GeneralFailureFrontEnd(py::module m); - diff --git a/src/bindings/python/src/compatibility/pyngraph/pyngraph.cpp b/src/bindings/python/src/compatibility/pyngraph/pyngraph.cpp index 5f5e0433315..dbd49306441 100644 --- a/src/bindings/python/src/compatibility/pyngraph/pyngraph.cpp +++ b/src/bindings/python/src/compatibility/pyngraph/pyngraph.cpp @@ -10,10 +10,6 @@ #include "pyngraph/coordinate_diff.hpp" #include "pyngraph/dimension.hpp" #include "pyngraph/discrete_type_info.hpp" -#include "pyngraph/frontend/frontend.hpp" -#include "pyngraph/frontend/frontend_manager.hpp" -#include "pyngraph/frontend/inputmodel.hpp" -#include "pyngraph/frontend/place.hpp" #include "pyngraph/function.hpp" #include "pyngraph/node.hpp" #include "pyngraph/node_factory.hpp" @@ -42,17 +38,6 @@ PYBIND11_MODULE(_pyngraph, m) { regclass_pyngraph_Shape(m); regclass_pyngraph_PartialShape(m); regclass_pyngraph_Node(m); - regclass_pyngraph_Place(m); - regclass_pyngraph_InitializationFailureFrontEnd(m); - regclass_pyngraph_GeneralFailureFrontEnd(m); - regclass_pyngraph_OpConversionFailureFrontEnd(m); - regclass_pyngraph_OpValidationFailureFrontEnd(m); - regclass_pyngraph_NotImplementedFailureFrontEnd(m); - regclass_pyngraph_FrontEndManager(m); - regclass_pyngraph_FrontEnd(m); - regclass_pyngraph_Extension(m); - regclass_pyngraph_TelemetryExtension(m); - regclass_pyngraph_InputModel(m); regclass_pyngraph_Input(m); regclass_pyngraph_Output(m); regclass_pyngraph_NodeFactory(m); diff --git a/src/bindings/python/src/openvino/frontend/__init__.py b/src/bindings/python/src/openvino/frontend/__init__.py new file mode 100644 index 00000000000..a008675fce0 --- /dev/null +++ b/src/bindings/python/src/openvino/frontend/__init__.py @@ -0,0 +1,50 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +""" +Package: openvino +Low level wrappers for the FrontEnd c++ api. +""" + +# flake8: noqa + +import os +import sys + +if sys.platform == "win32": + # Installer, yum, pip installs openvino dlls to the different directories + # and those paths need to be visible to the openvino modules + # + # If you're using a custom installation of openvino, + # add the location of openvino dlls to your system PATH. + # + # looking for the libs in the pip installation path by default. + openvino_libs = [os.path.join(os.path.dirname(__file__), "..", "..", ".."), + os.path.join(os.path.dirname(__file__), "..", "..", "openvino", "libs")] + # setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable. + openvino_libs_installer = os.getenv("OPENVINO_LIB_PATHS") + if openvino_libs_installer: + openvino_libs.extend(openvino_libs_installer.split(";")) + for lib in openvino_libs: + lib_path = os.path.join(os.path.dirname(__file__), lib) + if os.path.isdir(lib_path): + # On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. + if (3, 8) <= sys.version_info: + os.add_dll_directory(os.path.abspath(lib_path)) + else: + os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] + + +# main classes +from openvino.pyopenvino import FrontEndManager +from openvino.pyopenvino import FrontEnd +from openvino.pyopenvino import InputModel +from openvino.pyopenvino import Place +from openvino.pyopenvino import TelemetryExtension + +# exceptions +from openvino.pyopenvino import NotImplementedFailure +from openvino.pyopenvino import InitializationFailure +from openvino.pyopenvino import OpConversionFailure +from openvino.pyopenvino import OpValidationFailure +from openvino.pyopenvino import GeneralFailure diff --git a/src/bindings/python/src/openvino/offline_transformations_pybind/__init__.py b/src/bindings/python/src/openvino/offline_transformations_pybind/__init__.py index 3b77f599de0..47795b8382b 100644 --- a/src/bindings/python/src/openvino/offline_transformations_pybind/__init__.py +++ b/src/bindings/python/src/openvino/offline_transformations_pybind/__init__.py @@ -2,6 +2,33 @@ # Copyright (C) 2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import os +import sys + +if sys.platform == "win32": + # Installer, yum, pip installs openvino dlls to the different directories + # and those paths need to be visible to the openvino modules + # + # If you're using a custom installation of openvino, + # add the location of openvino dlls to your system PATH. + # + # looking for the libs in the pip installation path by default. + openvino_libs = [os.path.join(os.path.dirname(__file__), "..", "..", ".."), + os.path.join(os.path.dirname(__file__), "..", "..", "openvino", "libs")] + # setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable. + openvino_libs_installer = os.getenv("OPENVINO_LIB_PATHS") + if openvino_libs_installer: + openvino_libs.extend(openvino_libs_installer.split(";")) + for lib in openvino_libs: + lib_path = os.path.join(os.path.dirname(__file__), lib) + if os.path.isdir(lib_path): + # On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. + if (3, 8) <= sys.version_info: + os.add_dll_directory(os.path.abspath(lib_path)) + else: + os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] + + from openvino.pyopenvino.offline_transformations_pybind import apply_moc_transformations from openvino.pyopenvino.offline_transformations_pybind import apply_pot_transformations from openvino.pyopenvino.offline_transformations_pybind import apply_low_latency_transformation diff --git a/src/bindings/python/src/openvino/preprocess/__init__.py b/src/bindings/python/src/openvino/preprocess/__init__.py index 2a8c449ca88..c9ce2ba8a3d 100644 --- a/src/bindings/python/src/openvino/preprocess/__init__.py +++ b/src/bindings/python/src/openvino/preprocess/__init__.py @@ -8,6 +8,33 @@ Low level wrappers for the PrePostProcessing c++ api. # flake8: noqa +import os +import sys + +if sys.platform == "win32": + # Installer, yum, pip installs openvino dlls to the different directories + # and those paths need to be visible to the openvino modules + # + # If you're using a custom installation of openvino, + # add the location of openvino dlls to your system PATH. + # + # looking for the libs in the pip installation path by default. + openvino_libs = [os.path.join(os.path.dirname(__file__), "..", "..", ".."), + os.path.join(os.path.dirname(__file__), "..", "..", "openvino", "libs")] + # setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable. + openvino_libs_installer = os.getenv("OPENVINO_LIB_PATHS") + if openvino_libs_installer: + openvino_libs.extend(openvino_libs_installer.split(";")) + for lib in openvino_libs: + lib_path = os.path.join(os.path.dirname(__file__), lib) + if os.path.isdir(lib_path): + # On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. + if (3, 8) <= sys.version_info: + os.add_dll_directory(os.path.abspath(lib_path)) + else: + os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] + + # main classes from openvino.pyopenvino.preprocess import InputInfo from openvino.pyopenvino.preprocess import OutputInfo diff --git a/src/bindings/python/src/openvino/runtime/__init__.py b/src/bindings/python/src/openvino/runtime/__init__.py index dab5025cb8e..d62a22a9333 100644 --- a/src/bindings/python/src/openvino/runtime/__init__.py +++ b/src/bindings/python/src/openvino/runtime/__init__.py @@ -4,6 +4,9 @@ """openvino module namespace, exposing factory functions for all ops and other classes.""" # noqa: F401 +import os +import sys + from pkg_resources import get_distribution, DistributionNotFound try: @@ -11,6 +14,29 @@ try: except DistributionNotFound: __version__ = "0.0.0.dev0" +if sys.platform == "win32": + # Installer, yum, pip installs openvino dlls to the different directories + # and those paths need to be visible to the openvino modules + # + # If you're using a custom installation of openvino, + # add the location of openvino dlls to your system PATH. + # + # looking for the libs in the pip installation path by default. + openvino_libs = [os.path.join(os.path.dirname(__file__), "..", "..", ".."), + os.path.join(os.path.dirname(__file__), "..", "..", "openvino", "libs")] + # setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable. + openvino_libs_installer = os.getenv("OPENVINO_LIB_PATHS") + if openvino_libs_installer: + openvino_libs.extend(openvino_libs_installer.split(";")) + for lib in openvino_libs: + lib_path = os.path.join(os.path.dirname(__file__), lib) + if os.path.isdir(lib_path): + # On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. + if (3, 8) <= sys.version_info: + os.add_dll_directory(os.path.abspath(lib_path)) + else: + os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] + # Openvino pybind bindings and python extended classes from openvino.runtime.impl import Dimension diff --git a/src/bindings/python/src/pyopenvino/CMakeLists.txt b/src/bindings/python/src/pyopenvino/CMakeLists.txt index 5e7c5b12b19..36bf8300152 100644 --- a/src/bindings/python/src/pyopenvino/CMakeLists.txt +++ b/src/bindings/python/src/pyopenvino/CMakeLists.txt @@ -24,6 +24,26 @@ if(OpenVINO_SOURCE_DIR) set(CMAKE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) endif() +# compile options + +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # disable warning: This operator was deprecated and will be removed with v0 operation. + add_compile_options(/wd4996) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options(-Wno-deprecated-register -Wno-range-loop-analysis) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + add_link_options(-stdlib=libc++) + add_compile_options(-Wno-unused-value -Wno-range-loop-analysis) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # WA for GCC 7.5 "PYBIND11_NOINLINE inline" warning + add_compile_options(-Wno-error=attributes) +endif() + +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # for proper fix need to update pybind to version which does not use PyEval_InitThreads() + add_compile_options(-Wno-deprecated-declarations -Wno-undef) +endif() + # create target file(GLOB_RECURSE SOURCES *.cpp) @@ -37,7 +57,7 @@ else() endif() target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") -target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime ${OFFLINE_TRANSFORMATIONS_LIB}) +target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime ${OFFLINE_TRANSFORMATIONS_LIB} openvino::frontend::common) # perform copy if(OpenVINO_SOURCE_DIR) diff --git a/src/bindings/python/src/compatibility/pyngraph/frontend/frontend.cpp b/src/bindings/python/src/pyopenvino/frontend/frontend.cpp similarity index 93% rename from src/bindings/python/src/compatibility/pyngraph/frontend/frontend.cpp rename to src/bindings/python/src/pyopenvino/frontend/frontend.cpp index e1233b36a40..8e3c2d4b10c 100644 --- a/src/bindings/python/src/compatibility/pyngraph/frontend/frontend.cpp +++ b/src/bindings/python/src/pyopenvino/frontend/frontend.cpp @@ -10,12 +10,13 @@ #include "common/frontend_exceptions.hpp" #include "common/telemetry_extension.hpp" #include "manager.hpp" +#include "pyopenvino/graph/function.hpp" namespace py = pybind11; using namespace ov::frontend; -void regclass_pyngraph_FrontEnd(py::module m) { +void regclass_frontend_FrontEnd(py::module m) { py::class_> fem(m, "FrontEnd", py::dynamic_attr(), py::module_local()); fem.doc() = "ngraph.impl.FrontEnd wraps ngraph::frontend::FrontEnd"; @@ -40,7 +41,7 @@ void regclass_pyngraph_FrontEnd(py::module m) { )"); fem.def("convert", - static_cast (FrontEnd::*)(InputModel::Ptr) const>(&FrontEnd::convert), + static_cast (FrontEnd::*)(InputModel::Ptr) const>(&FrontEnd::convert), py::arg("model"), R"( Completely convert and normalize entire function, throws if it is not possible. @@ -57,7 +58,7 @@ void regclass_pyngraph_FrontEnd(py::module m) { )"); fem.def("convert", - static_cast) const>(&FrontEnd::convert), + static_cast) const>(&FrontEnd::convert), py::arg("function"), R"( Completely convert the remaining, not converted part of a function. @@ -143,11 +144,11 @@ void regclass_pyngraph_FrontEnd(py::module m) { }); } -void regclass_pyngraph_Extension(py::module m) { +void regclass_frontend_Extension(py::module m) { py::class_> ext(m, "Extension", py::dynamic_attr()); } -void regclass_pyngraph_TelemetryExtension(py::module m) { +void regclass_frontend_TelemetryExtension(py::module m) { { py::class_, ov::Extension> ext(m, "TelemetryExtension", diff --git a/src/bindings/python/src/compatibility/pyngraph/frontend/frontend.hpp b/src/bindings/python/src/pyopenvino/frontend/frontend.hpp similarity index 51% rename from src/bindings/python/src/compatibility/pyngraph/frontend/frontend.hpp rename to src/bindings/python/src/pyopenvino/frontend/frontend.hpp index 442cc3ffcd4..b6df63e9c26 100644 --- a/src/bindings/python/src/compatibility/pyngraph/frontend/frontend.hpp +++ b/src/bindings/python/src/pyopenvino/frontend/frontend.hpp @@ -8,6 +8,6 @@ namespace py = pybind11; -void regclass_pyngraph_FrontEnd(py::module m); -void regclass_pyngraph_Extension(py::module m); -void regclass_pyngraph_TelemetryExtension(py::module m); +void regclass_frontend_FrontEnd(py::module m); +void regclass_frontend_Extension(py::module m); +void regclass_frontend_TelemetryExtension(py::module m); diff --git a/src/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.cpp b/src/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp similarity index 87% rename from src/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.cpp rename to src/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp index 2f59c415688..2f0a40903e3 100644 --- a/src/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.cpp +++ b/src/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp @@ -13,12 +13,11 @@ namespace py = pybind11; -void regclass_pyngraph_FrontEndManager(py::module m) { +void regclass_frontend_FrontEndManager(py::module m) { py::class_> fem(m, "FrontEndManager", - py::dynamic_attr(), - py::module_local()); - fem.doc() = "ngraph.impl.FrontEndManager wraps ngraph::frontend::FrontEndManager"; + py::dynamic_attr()); + fem.doc() = "openvino.frontend.FrontEndManager wraps ov::frontend::FrontEndManager"; fem.def(py::init<>()); @@ -84,7 +83,7 @@ void regclass_pyngraph_FrontEndManager(py::module m) { }); } -void regclass_pyngraph_GeneralFailureFrontEnd(py::module m) { +void regclass_frontend_GeneralFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "GeneralFailure"); py::register_exception_translator([](std::exception_ptr p) { try { @@ -96,7 +95,7 @@ void regclass_pyngraph_GeneralFailureFrontEnd(py::module m) { }); } -void regclass_pyngraph_OpValidationFailureFrontEnd(py::module m) { +void regclass_frontend_OpValidationFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "OpValidationFailure"); py::register_exception_translator([](std::exception_ptr p) { try { @@ -108,7 +107,7 @@ void regclass_pyngraph_OpValidationFailureFrontEnd(py::module m) { }); } -void regclass_pyngraph_OpConversionFailureFrontEnd(py::module m) { +void regclass_frontend_OpConversionFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "OpConversionFailure"); py::register_exception_translator([](std::exception_ptr p) { try { @@ -120,7 +119,7 @@ void regclass_pyngraph_OpConversionFailureFrontEnd(py::module m) { }); } -void regclass_pyngraph_InitializationFailureFrontEnd(py::module m) { +void regclass_frontend_InitializationFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "InitializationFailure"); py::register_exception_translator([](std::exception_ptr p) { try { @@ -132,7 +131,7 @@ void regclass_pyngraph_InitializationFailureFrontEnd(py::module m) { }); } -void regclass_pyngraph_NotImplementedFailureFrontEnd(py::module m) { +void regclass_frontend_NotImplementedFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "NotImplementedFailure"); py::register_exception_translator([](std::exception_ptr p) { try { diff --git a/src/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp b/src/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp new file mode 100644 index 00000000000..aa2e0a16a04 --- /dev/null +++ b/src/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp @@ -0,0 +1,17 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +namespace py = pybind11; + +void regclass_frontend_FrontEndManager(py::module m); +void regclass_frontend_NotImplementedFailureFrontEnd(py::module m); +void regclass_frontend_InitializationFailureFrontEnd(py::module m); +void regclass_frontend_OpConversionFailureFrontEnd(py::module m); +void regclass_frontend_OpValidationFailureFrontEnd(py::module m); +void regclass_frontend_GeneralFailureFrontEnd(py::module m); + diff --git a/src/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.cpp b/src/bindings/python/src/pyopenvino/frontend/inputmodel.cpp similarity index 97% rename from src/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.cpp rename to src/bindings/python/src/pyopenvino/frontend/inputmodel.cpp index b5d693f713e..45ba73c7fbf 100644 --- a/src/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.cpp +++ b/src/bindings/python/src/pyopenvino/frontend/inputmodel.cpp @@ -11,12 +11,11 @@ namespace py = pybind11; -void regclass_pyngraph_InputModel(py::module m) { +void regclass_frontend_InputModel(py::module m) { py::class_> im(m, "InputModel", - py::dynamic_attr(), - py::module_local()); - im.doc() = "ngraph.impl.InputModel wraps ngraph::frontend::InputModel"; + py::dynamic_attr()); + im.doc() = "openvino.frontend.InputModel wraps ov::frontend::InputModel"; im.def("get_place_by_tensor_name", &ov::frontend::InputModel::get_place_by_tensor_name, diff --git a/src/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.hpp b/src/bindings/python/src/pyopenvino/frontend/inputmodel.hpp similarity index 76% rename from src/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.hpp rename to src/bindings/python/src/pyopenvino/frontend/inputmodel.hpp index e95179c4a8c..6759aaff499 100644 --- a/src/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.hpp +++ b/src/bindings/python/src/pyopenvino/frontend/inputmodel.hpp @@ -8,4 +8,4 @@ namespace py = pybind11; -void regclass_pyngraph_InputModel(py::module m); +void regclass_frontend_InputModel(py::module m); diff --git a/src/bindings/python/src/compatibility/pyngraph/frontend/place.cpp b/src/bindings/python/src/pyopenvino/frontend/place.cpp similarity index 96% rename from src/bindings/python/src/compatibility/pyngraph/frontend/place.cpp rename to src/bindings/python/src/pyopenvino/frontend/place.cpp index 0af0ea5fdf0..f0f00972c0b 100644 --- a/src/bindings/python/src/compatibility/pyngraph/frontend/place.cpp +++ b/src/bindings/python/src/pyopenvino/frontend/place.cpp @@ -9,16 +9,13 @@ #include "common/frontend_exceptions.hpp" #include "frontend_manager.hpp" #include "manager.hpp" -#include "pyngraph/function.hpp" +#include "pyopenvino/graph/function.hpp" namespace py = pybind11; -void regclass_pyngraph_Place(py::module m) { - py::class_> place(m, - "Place", - py::dynamic_attr(), - py::module_local()); - place.doc() = "ngraph.impl.Place wraps ngraph::frontend::Place"; +void regclass_frontend_Place(py::module m) { + py::class_> place(m, "Place", py::dynamic_attr()); + place.doc() = "openvino.frontend.Place wraps ov::frontend::Place"; place.def("is_input", &ov::frontend::Place::is_input, diff --git a/src/bindings/python/src/compatibility/pyngraph/frontend/place.hpp b/src/bindings/python/src/pyopenvino/frontend/place.hpp similarity index 78% rename from src/bindings/python/src/compatibility/pyngraph/frontend/place.hpp rename to src/bindings/python/src/pyopenvino/frontend/place.hpp index 1a52e21f028..68c371de095 100644 --- a/src/bindings/python/src/compatibility/pyngraph/frontend/place.hpp +++ b/src/bindings/python/src/pyopenvino/frontend/place.hpp @@ -8,4 +8,4 @@ namespace py = pybind11; -void regclass_pyngraph_Place(py::module m); +void regclass_frontend_Place(py::module m); diff --git a/src/bindings/python/src/pyopenvino/pyopenvino.cpp b/src/bindings/python/src/pyopenvino/pyopenvino.cpp index 37be85661c4..7f5181f59b5 100644 --- a/src/bindings/python/src/pyopenvino/pyopenvino.cpp +++ b/src/bindings/python/src/pyopenvino/pyopenvino.cpp @@ -30,6 +30,10 @@ #include "pyopenvino/core/tensor.hpp" #include "pyopenvino/core/variable_state.hpp" #include "pyopenvino/core/version.hpp" +#include "pyopenvino/frontend/frontend.hpp" +#include "pyopenvino/frontend/frontend_manager.hpp" +#include "pyopenvino/frontend/inputmodel.hpp" +#include "pyopenvino/frontend/place.hpp" #include "pyopenvino/graph/descriptors/tensor.hpp" #include "pyopenvino/graph/dimension.hpp" #include "pyopenvino/graph/layout.hpp" @@ -113,5 +117,17 @@ PYBIND11_MODULE(pyopenvino, m) { regclass_AsyncInferQueue(m); regclass_ProfilingInfo(m); + regclass_frontend_Place(m); + regclass_frontend_InitializationFailureFrontEnd(m); + regclass_frontend_GeneralFailureFrontEnd(m); + regclass_frontend_OpConversionFailureFrontEnd(m); + regclass_frontend_OpValidationFailureFrontEnd(m); + regclass_frontend_NotImplementedFailureFrontEnd(m); + regclass_frontend_Extension(m); + regclass_frontend_FrontEndManager(m); + regclass_frontend_FrontEnd(m); + regclass_frontend_InputModel(m); + regclass_frontend_TelemetryExtension(m); + regmodule_offline_transformations(m); } diff --git a/src/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx.py b/src/bindings/python/tests/test_frontend/test_frontend_onnx.py similarity index 97% rename from src/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx.py rename to src/bindings/python/tests/test_frontend/test_frontend_onnx.py index 221a5aa3372..7c36999c9cd 100644 --- a/src/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx.py +++ b/src/bindings/python/tests/test_frontend/test_frontend_onnx.py @@ -7,8 +7,8 @@ import numpy as np from onnx.helper import make_graph, make_model, make_tensor_value_info import pytest -from ngraph.frontend import FrontEndManager -from tests_compatibility.runtime import get_runtime +from openvino.frontend import FrontEndManager +from tests.runtime import get_runtime def create_onnx_model(): diff --git a/src/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx_editor.py b/src/bindings/python/tests/test_frontend/test_frontend_onnx_editor.py similarity index 99% rename from src/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx_editor.py rename to src/bindings/python/tests/test_frontend/test_frontend_onnx_editor.py index a52260909bf..66a8f2d82cf 100644 --- a/src/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx_editor.py +++ b/src/bindings/python/tests/test_frontend/test_frontend_onnx_editor.py @@ -5,8 +5,8 @@ import os import onnx import pytest from onnx.helper import make_graph, make_model, make_tensor_value_info -from ngraph import PartialShape -from ngraph.frontend import FrontEndManager +from openvino.runtime import PartialShape +from openvino.frontend import FrontEndManager # ------Test input model 1------ diff --git a/src/bindings/python/tests_compatibility/test_frontend/test_frontendmanager.py b/src/bindings/python/tests/test_frontend/test_frontendmanager.py similarity index 99% rename from src/bindings/python/tests_compatibility/test_frontend/test_frontendmanager.py rename to src/bindings/python/tests/test_frontend/test_frontendmanager.py index 8ecece7404a..4d8994514d2 100644 --- a/src/bindings/python/tests_compatibility/test_frontend/test_frontendmanager.py +++ b/src/bindings/python/tests/test_frontend/test_frontendmanager.py @@ -3,9 +3,9 @@ import pickle -from ngraph import PartialShape -from ngraph.frontend import FrontEndManager, InitializationFailure -from ngraph.utils.types import get_element_type +from openvino.runtime import PartialShape +from openvino.frontend import FrontEndManager, InitializationFailure +from openvino.runtime.utils.types import get_element_type import numpy as np diff --git a/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/CMakeLists.txt b/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/CMakeLists.txt deleted file mode 100644 index b5b2b65351e..00000000000 --- a/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -set(TARGET_FE_NAME "mock_py_ov_frontend") - -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -file(GLOB_RECURSE LIBRARY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) - -source_group("src" FILES ${LIBRARY_SRC}) -source_group("include" FILES ${LIBRARY_HEADERS}) - -# Create shared library -add_library(${TARGET_FE_NAME} SHARED ${LIBRARY_SRC} ${LIBRARY_HEADERS}) - -target_include_directories(${TARGET_FE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - -target_link_libraries(${TARGET_FE_NAME} PRIVATE frontend_common::static) - -add_clang_format_target(${TARGET_FE_NAME}_clang FOR_TARGETS ${TARGET_FE_NAME}) - -install(TARGETS ${TARGET_FE_NAME} - RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT tests_compatibility EXCLUDE_FROM_ALL - LIBRARY DESTINATION ${IE_CPACK_LIBRARY_PATH} COMPONENT tests_compatibility EXCLUDE_FROM_ALL) diff --git a/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.cpp b/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.cpp deleted file mode 100644 index 2285f6b7b40..00000000000 --- a/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "mock_py_frontend.hpp" - -#include "manager.hpp" -#include "common/frontend_defs.hpp" - -using namespace ngraph; -using namespace ngraph::frontend; - -extern "C" MOCK_API FrontEndVersion GetAPIVersion() { - return OV_FRONTEND_API_VERSION; -} - -extern "C" MOCK_API void* GetFrontEndData() { - FrontEndPluginInfo* res = new FrontEndPluginInfo(); - res->m_name = "mock_py"; - res->m_creator = []() { - return std::make_shared(); - }; - - return res; -} diff --git a/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp b/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp deleted file mode 100644 index c14b0a2138a..00000000000 --- a/src/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp +++ /dev/null @@ -1,665 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "manager.hpp" -#include "frontend_manager/frontend_defs.hpp" -#include "ngraph/visibility.hpp" - -// Defined if we are building the plugin DLL (instead of using it) -#ifdef mock_py_ov_frontend_EXPORTS -# define MOCK_API OPENVINO_CORE_EXPORTS -#else -# define MOCK_API OPENVINO_CORE_IMPORTS -#endif // mock_py_ov_frontend_EXPORTS - -// OK to have 'using' in mock header - -using namespace ngraph; -using namespace ngraph::frontend; - -//////////////////////////////// - -struct MOCK_API PlaceStat { - int m_get_names = 0; - int m_get_consuming_operations = 0; - int m_get_target_tensor = 0; - int m_get_producing_operation = 0; - int m_get_producing_port = 0; - int m_get_input_port = 0; - int m_get_output_port = 0; - int m_get_consuming_ports = 0; - int m_is_input = 0; - int m_is_output = 0; - int m_is_equal = 0; - int m_is_equal_data = 0; - int m_get_source_tensor = 0; - - // Arguments tracking - std::string m_lastArgString; - int m_lastArgInt; - Place::Ptr m_lastArgPlace = nullptr; - - // Getters - int get_names() const { - return m_get_names; - } - int get_consuming_operations() const { - return m_get_consuming_operations; - } - int get_target_tensor() const { - return m_get_target_tensor; - } - int get_producing_operation() const { - return m_get_producing_operation; - } - int get_producing_port() const { - return m_get_producing_port; - } - int get_input_port() const { - return m_get_input_port; - } - int get_output_port() const { - return m_get_output_port; - } - int get_consuming_ports() const { - return m_get_consuming_ports; - } - int is_input() const { - return m_is_input; - } - int is_output() const { - return m_is_output; - } - int is_equal() const { - return m_is_equal; - } - int is_equal_data() const { - return m_is_equal_data; - } - int get_source_tensor() const { - return m_get_source_tensor; - } - - // Arguments getters - std::string get_lastArgString() const { - return m_lastArgString; - } - int get_lastArgInt() const { - return m_lastArgInt; - } - Place::Ptr get_lastArgPlace() const { - return m_lastArgPlace; - } -}; - -class MOCK_API PlaceMockPy : public Place { - mutable PlaceStat m_stat; - -public: - std::vector get_names() const override { - m_stat.m_get_names++; - return {}; - } - - std::vector get_consuming_operations() const override { - m_stat.m_get_consuming_operations++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = ""; - return {std::make_shared()}; - } - - std::vector get_consuming_operations(int outputPortIndex) const override { - m_stat.m_get_consuming_operations++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = ""; - return {std::make_shared()}; - } - - std::vector get_consuming_operations(const std::string& outputName) const override { - m_stat.m_get_consuming_operations++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = outputName; - return {std::make_shared()}; - } - - std::vector get_consuming_operations(const std::string& outputName, - int outputPortIndex) const override { - m_stat.m_get_consuming_operations++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = outputName; - return {std::make_shared()}; - } - - Place::Ptr get_target_tensor() const override { - m_stat.m_get_target_tensor++; - m_stat.m_lastArgInt = -1; - return std::make_shared(); - } - - Place::Ptr get_target_tensor(int outputPortIndex) const override { - m_stat.m_get_target_tensor++; - m_stat.m_lastArgInt = outputPortIndex; - return std::make_shared(); - } - - Place::Ptr get_target_tensor(const std::string& outputName) const override { - m_stat.m_get_target_tensor++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = outputName; - return {std::make_shared()}; - } - - Place::Ptr get_target_tensor(const std::string& outputName, int outputPortIndex) const override { - m_stat.m_get_target_tensor++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = outputName; - return {std::make_shared()}; - } - - Place::Ptr get_producing_operation() const override { - m_stat.m_get_producing_operation++; - m_stat.m_lastArgInt = -1; - return std::make_shared(); - } - - Place::Ptr get_producing_operation(int inputPortIndex) const override { - m_stat.m_get_producing_operation++; - m_stat.m_lastArgInt = inputPortIndex; - return std::make_shared(); - } - - Place::Ptr get_producing_operation(const std::string& inputName) const override { - m_stat.m_get_producing_operation++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = inputName; - return {std::make_shared()}; - } - - Place::Ptr get_producing_operation(const std::string& inputName, int inputPortIndex) const override { - m_stat.m_get_producing_operation++; - m_stat.m_lastArgInt = inputPortIndex; - m_stat.m_lastArgString = inputName; - return {std::make_shared()}; - } - - Place::Ptr get_producing_port() const override { - m_stat.m_get_producing_port++; - return std::make_shared(); - } - - Place::Ptr get_input_port() const override { - m_stat.m_get_input_port++; - m_stat.m_lastArgInt = -1; - return std::make_shared(); - } - - Place::Ptr get_input_port(int inputPortIndex) const override { - m_stat.m_get_input_port++; - m_stat.m_lastArgInt = inputPortIndex; - return std::make_shared(); - } - - Place::Ptr get_input_port(const std::string& inputName) const override { - m_stat.m_get_input_port++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = inputName; - return std::make_shared(); - } - - Place::Ptr get_input_port(const std::string& inputName, int inputPortIndex) const override { - m_stat.m_get_input_port++; - m_stat.m_lastArgInt = inputPortIndex; - m_stat.m_lastArgString = inputName; - return std::make_shared(); - } - - Place::Ptr get_output_port() const override { - m_stat.m_get_output_port++; - m_stat.m_lastArgInt = -1; - return std::make_shared(); - } - - Place::Ptr get_output_port(int outputPortIndex) const override { - m_stat.m_get_output_port++; - m_stat.m_lastArgInt = outputPortIndex; - return std::make_shared(); - } - - Place::Ptr get_output_port(const std::string& outputName) const override { - m_stat.m_get_output_port++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = outputName; - return std::make_shared(); - } - - Place::Ptr get_output_port(const std::string& outputName, int outputPortIndex) const override { - m_stat.m_get_output_port++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = outputName; - return std::make_shared(); - } - - std::vector get_consuming_ports() const override { - m_stat.m_get_consuming_ports++; - return {std::make_shared()}; - } - - bool is_input() const override { - m_stat.m_is_input++; - return false; - } - - bool is_output() const override { - m_stat.m_is_output++; - return false; - } - - bool is_equal(Ptr another) const override { - m_stat.m_is_equal++; - m_stat.m_lastArgPlace = another; - return false; - } - - bool is_equal_data(Ptr another) const override { - m_stat.m_is_equal_data++; - m_stat.m_lastArgPlace = another; - return false; - } - - Place::Ptr get_source_tensor(int inputPortIndex) const override { - m_stat.m_get_source_tensor++; - m_stat.m_lastArgInt = inputPortIndex; - return {std::make_shared()}; - } - - Place::Ptr get_source_tensor() const override { - m_stat.m_get_source_tensor++; - m_stat.m_lastArgInt = -1; - return {std::make_shared()}; - } - - Place::Ptr get_source_tensor(const std::string& inputName) const override { - m_stat.m_get_source_tensor++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = inputName; - return {std::make_shared()}; - } - - Place::Ptr get_source_tensor(const std::string& inputName, int inputPortIndex) const override { - m_stat.m_get_source_tensor++; - m_stat.m_lastArgInt = inputPortIndex; - m_stat.m_lastArgString = inputName; - return {std::make_shared()}; - } - - //---------------Stat-------------------- - PlaceStat get_stat() const { - return m_stat; - } -}; - -//////////////////////////////// - -struct MOCK_API ModelStat { - int m_get_inputs = 0; - int m_get_outputs = 0; - int m_get_place_by_tensor_name = 0; - int m_get_place_by_operation_name = 0; - int m_get_place_by_operation_and_input_port = 0; - int m_get_place_by_operation_and_output_port = 0; - int m_set_name_for_tensor = 0; - int m_add_name_for_tensor = 0; - int m_set_name_for_operation = 0; - int m_free_name_for_tensor = 0; - int m_free_name_for_operation = 0; - int m_set_name_for_dimension = 0; - int m_cut_and_add_new_input = 0; - int m_cut_and_add_new_output = 0; - int m_add_output = 0; - int m_remove_output = 0; - int m_set_partial_shape = 0; - int m_get_partial_shape = 0; - int m_set_element_type = 0; - - int m_extract_subgraph = 0; - int m_override_all_inputs = 0; - int m_override_all_outputs = 0; - - // Arguments tracking - std::string m_lastArgString; - int m_lastArgInt; - Place::Ptr m_lastArgPlace = nullptr; - std::vector m_lastArgInputPlaces; - std::vector m_lastArgOutputPlaces; - ngraph::element::Type m_lastArgElementType; - ngraph::PartialShape m_lastArgPartialShape; - - // Getters - int get_inputs() const { - return m_get_inputs; - } - int get_outputs() const { - return m_get_outputs; - } - int extract_subgraph() const { - return m_extract_subgraph; - } - int override_all_inputs() const { - return m_override_all_inputs; - } - int override_all_outputs() const { - return m_override_all_outputs; - } - int get_place_by_tensor_name() const { - return m_get_place_by_tensor_name; - } - int get_place_by_operation_name() const { - return m_get_place_by_operation_name; - } - int get_place_by_operation_and_input_port() const { - return m_get_place_by_operation_and_input_port; - } - int get_place_by_operation_and_output_port() const { - return m_get_place_by_operation_and_output_port; - } - int set_name_for_tensor() const { - return m_set_name_for_tensor; - } - int add_name_for_tensor() const { - return m_add_name_for_tensor; - } - int set_name_for_operation() const { - return m_set_name_for_operation; - } - int free_name_for_tensor() const { - return m_free_name_for_tensor; - } - int free_name_for_operation() const { - return m_free_name_for_operation; - } - int set_name_for_dimension() const { - return m_set_name_for_dimension; - } - int cut_and_add_new_input() const { - return m_cut_and_add_new_input; - } - int cut_and_add_new_output() const { - return m_cut_and_add_new_output; - } - int add_output() const { - return m_add_output; - } - int remove_output() const { - return m_remove_output; - } - int set_partial_shape() const { - return m_set_partial_shape; - } - int get_partial_shape() const { - return m_get_partial_shape; - } - int set_element_type() const { - return m_set_element_type; - } - - // Arguments getters - std::string get_lastArgString() const { - return m_lastArgString; - } - int get_lastArgInt() const { - return m_lastArgInt; - } - Place::Ptr get_lastArgPlace() const { - return m_lastArgPlace; - } - std::vector get_lastArgInputPlaces() const { - return m_lastArgInputPlaces; - } - std::vector get_lastArgOutputPlaces() const { - return m_lastArgOutputPlaces; - } - ngraph::element::Type get_lastArgElementType() const { - return m_lastArgElementType; - } - ngraph::PartialShape get_lastArgPartialShape() const { - return m_lastArgPartialShape; - } -}; - -class MOCK_API InputModelMockPy : public InputModel { - mutable ModelStat m_stat; - -public: - std::vector get_inputs() const override { - m_stat.m_get_inputs++; - return {std::make_shared()}; - } - - std::vector get_outputs() const override { - m_stat.m_get_outputs++; - return {std::make_shared()}; - } - - Place::Ptr get_place_by_tensor_name(const std::string& tensorName) const override { - m_stat.m_get_place_by_tensor_name++; - m_stat.m_lastArgString = tensorName; - return std::make_shared(); - } - - Place::Ptr get_place_by_operation_name(const std::string& operationName) const override { - m_stat.m_get_place_by_operation_name++; - m_stat.m_lastArgString = operationName; - return std::make_shared(); - } - - Place::Ptr get_place_by_operation_name_and_input_port(const std::string& operationName, - int inputPortIndex) override { - m_stat.m_get_place_by_operation_and_input_port++; - m_stat.m_lastArgInt = inputPortIndex; - m_stat.m_lastArgString = operationName; - return std::make_shared(); - } - - Place::Ptr get_place_by_operation_name_and_output_port(const std::string& operationName, - int outputPortIndex) override { - m_stat.m_get_place_by_operation_and_output_port++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = operationName; - return std::make_shared(); - } - - void set_name_for_tensor(Place::Ptr tensor, const std::string& newName) override { - m_stat.m_set_name_for_tensor++; - m_stat.m_lastArgPlace = tensor; - m_stat.m_lastArgString = newName; - } - - void add_name_for_tensor(Place::Ptr tensor, const std::string& newName) override { - m_stat.m_add_name_for_tensor++; - m_stat.m_lastArgPlace = tensor; - m_stat.m_lastArgString = newName; - } - - void set_name_for_operation(Place::Ptr operation, const std::string& newName) override { - m_stat.m_set_name_for_operation++; - m_stat.m_lastArgPlace = operation; - m_stat.m_lastArgString = newName; - } - - void free_name_for_tensor(const std::string& name) override { - m_stat.m_free_name_for_tensor++; - m_stat.m_lastArgString = name; - } - - void free_name_for_operation(const std::string& name) override { - m_stat.m_free_name_for_operation++; - m_stat.m_lastArgString = name; - } - - void set_name_for_dimension(Place::Ptr place, size_t shapeDimIndex, const std::string& dimName) override { - m_stat.m_set_name_for_dimension++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgInt = static_cast(shapeDimIndex); - m_stat.m_lastArgString = dimName; - } - - void cut_and_add_new_input(Place::Ptr place, const std::string& newNameOptional) override { - m_stat.m_cut_and_add_new_input++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgString = newNameOptional; - } - - void cut_and_add_new_output(Place::Ptr place, const std::string& newNameOptional) override { - m_stat.m_cut_and_add_new_output++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgString = newNameOptional; - } - - Place::Ptr add_output(Place::Ptr place) override { - m_stat.m_add_output++; - m_stat.m_lastArgPlace = place; - return std::make_shared(); - } - - void remove_output(Place::Ptr place) override { - m_stat.m_remove_output++; - m_stat.m_lastArgPlace = place; - } - - void override_all_outputs(const std::vector& outputs) override { - m_stat.m_override_all_outputs++; - m_stat.m_lastArgOutputPlaces = outputs; - } - - void override_all_inputs(const std::vector& inputs) override { - m_stat.m_override_all_inputs++; - m_stat.m_lastArgInputPlaces = inputs; - } - - void extract_subgraph(const std::vector& inputs, const std::vector& outputs) override { - m_stat.m_extract_subgraph++; - m_stat.m_lastArgInputPlaces = inputs; - m_stat.m_lastArgOutputPlaces = outputs; - } - - // Setting tensor properties - void set_partial_shape(Place::Ptr place, const ngraph::PartialShape& shape) override { - m_stat.m_set_partial_shape++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgPartialShape = shape; - } - - ngraph::PartialShape get_partial_shape(Place::Ptr place) const override { - m_stat.m_get_partial_shape++; - m_stat.m_lastArgPlace = place; - return {}; - } - - void set_element_type(Place::Ptr place, const ngraph::element::Type& type) override { - m_stat.m_set_element_type++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgElementType = type; - } - - //---------------Stat-------------------- - ModelStat get_stat() const { - return m_stat; - } -}; - -///////////////////////////////////////////////////////// - -struct MOCK_API FeStat { - std::vector m_load_paths; - int m_convert_model = 0; - int m_convert = 0; - int m_convert_partially = 0; - int m_decode = 0; - int m_normalize = 0; - int m_get_name = 0; - int m_supported = 0; - // Getters - std::vector load_paths() const { - return m_load_paths; - } - int convert_model() const { - return m_convert_model; - } - int convert() const { - return m_convert; - } - int convert_partially() const { - return m_convert_partially; - } - int decode() const { - return m_decode; - } - int normalize() const { - return m_normalize; - } - int get_name() const { - return m_get_name; - } - int supported() const { - return m_supported; - } -}; - -class MOCK_API FrontEndMockPy : public FrontEnd { - mutable FeStat m_stat; - -public: - FrontEndMockPy() {} - - InputModel::Ptr load_impl(const std::vector>& params) const override { - 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 && 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; - } - } - return false; - } - - std::shared_ptr convert(InputModel::Ptr model) const override { - m_stat.m_convert_model++; - return std::make_shared(NodeVector{}, ParameterVector{}); - } - - void convert(std::shared_ptr func) const override { - m_stat.m_convert++; - } - - std::shared_ptr convert_partially(InputModel::Ptr model) const override { - m_stat.m_convert_partially++; - return std::make_shared(NodeVector{}, ParameterVector{}); - } - - std::shared_ptr decode(InputModel::Ptr model) const override { - m_stat.m_decode++; - return std::make_shared(NodeVector{}, ParameterVector{}); - } - - void normalize(std::shared_ptr function) const override { - m_stat.m_normalize++; - } - - std::string get_name() const override { - m_stat.m_get_name++; - return "mock_py"; - } - - FeStat get_stat() const { - return m_stat; - } -}; diff --git a/src/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/CMakeLists.txt b/src/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/CMakeLists.txt deleted file mode 100644 index f91531fdac2..00000000000 --- a/src/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -set(TARGET_FE_NAME "mock_py_ov_frontend") -set(PYBIND_FE_NAME "pybind_mock_frontend") - -set(PYBIND_FE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/pyngraph_mock_frontend_api.cpp) - -source_group("src" FILES ${PYBIND_FE_SRC}) - -pybind11_add_module(${PYBIND_FE_NAME} MODULE ${PYBIND_FE_SRC}) - -target_link_libraries(${PYBIND_FE_NAME} PRIVATE ${TARGET_FE_NAME} frontend_common::static) - -add_clang_format_target(${PYBIND_FE_NAME}_clang FOR_TARGETS ${PYBIND_FE_NAME}) - -install(TARGETS ${PYBIND_FE_NAME} - DESTINATION python/${PYTHON_VERSION} - COMPONENT tests_compatibility EXCLUDE_FROM_ALL) diff --git a/src/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/pyngraph_mock_frontend_api.cpp b/src/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/pyngraph_mock_frontend_api.cpp deleted file mode 100644 index 7701c85ff35..00000000000 --- a/src/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/pyngraph_mock_frontend_api.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include - -#include "../mock_py_ov_frontend/mock_py_frontend.hpp" - -namespace py = pybind11; -using namespace ngraph; -using namespace ngraph::frontend; - -static void register_mock_frontend_stat(py::module m) { - m.def( - "get_fe_stat", - [](const std::shared_ptr& fe) { - std::shared_ptr ptr = std::dynamic_pointer_cast(fe); - if (ptr) { - auto stat = ptr->get_stat(); - return stat; - } - return FeStat(); - }, - py::arg("frontend")); - - py::class_ feStat(m, "FeStat", py::dynamic_attr()); - feStat.def_property_readonly("load_paths", &FeStat::load_paths); - feStat.def_property_readonly("convert_model", &FeStat::convert_model); - feStat.def_property_readonly("convert", &FeStat::convert); - feStat.def_property_readonly("convert_partially", &FeStat::convert_partially); - feStat.def_property_readonly("decode", &FeStat::decode); - feStat.def_property_readonly("normalize", &FeStat::normalize); - feStat.def_property_readonly("get_name", &FeStat::get_name); - feStat.def_property_readonly("supported", &FeStat::supported); -} - -static void register_mock_model_stat(py::module m) { - m.def( - "get_mdl_stat", - [](const std::shared_ptr& mdl) { - std::shared_ptr ptr = std::dynamic_pointer_cast(mdl); - if (ptr) { - auto stat = ptr->get_stat(); - return stat; - } - return ModelStat(); - }, - py::arg("model")); - - py::class_ mdlStat(m, "ModelStat", py::dynamic_attr()); - mdlStat.def_property_readonly("get_inputs", &ModelStat::get_inputs); - mdlStat.def_property_readonly("get_outputs", &ModelStat::get_outputs); - mdlStat.def_property_readonly("get_place_by_tensor_name", &ModelStat::get_place_by_tensor_name); - mdlStat.def_property_readonly("get_place_by_operation_name", &ModelStat::get_place_by_operation_name); - mdlStat.def_property_readonly("get_place_by_operation_and_input_port", - &ModelStat::get_place_by_operation_and_input_port); - mdlStat.def_property_readonly("get_place_by_operation_and_output_port", - &ModelStat::get_place_by_operation_and_output_port); - - mdlStat.def_property_readonly("set_name_for_tensor", &ModelStat::set_name_for_tensor); - mdlStat.def_property_readonly("add_name_for_tensor", &ModelStat::add_name_for_tensor); - mdlStat.def_property_readonly("set_name_for_operation", &ModelStat::set_name_for_operation); - mdlStat.def_property_readonly("free_name_for_tensor", &ModelStat::free_name_for_tensor); - mdlStat.def_property_readonly("free_name_for_operation", &ModelStat::free_name_for_operation); - mdlStat.def_property_readonly("set_name_for_dimension", &ModelStat::set_name_for_dimension); - mdlStat.def_property_readonly("cut_and_add_new_input", &ModelStat::cut_and_add_new_input); - mdlStat.def_property_readonly("cut_and_add_new_output", &ModelStat::cut_and_add_new_output); - mdlStat.def_property_readonly("add_output", &ModelStat::add_output); - mdlStat.def_property_readonly("remove_output", &ModelStat::remove_output); - mdlStat.def_property_readonly("set_partial_shape", &ModelStat::set_partial_shape); - mdlStat.def_property_readonly("get_partial_shape", &ModelStat::get_partial_shape); - mdlStat.def_property_readonly("set_element_type", &ModelStat::set_element_type); - mdlStat.def_property_readonly("extract_subgraph", &ModelStat::extract_subgraph); - mdlStat.def_property_readonly("override_all_inputs", &ModelStat::override_all_inputs); - mdlStat.def_property_readonly("override_all_outputs", &ModelStat::override_all_outputs); - - // Arguments tracking - mdlStat.def_property_readonly("lastArgString", &ModelStat::get_lastArgString); - mdlStat.def_property_readonly("lastArgInt", &ModelStat::get_lastArgInt); - mdlStat.def_property_readonly("lastArgPlace", &ModelStat::get_lastArgPlace); - mdlStat.def_property_readonly("lastArgInputPlaces", &ModelStat::get_lastArgInputPlaces); - mdlStat.def_property_readonly("lastArgOutputPlaces", &ModelStat::get_lastArgOutputPlaces); - mdlStat.def_property_readonly("lastArgElementType", &ModelStat::get_lastArgElementType); - mdlStat.def_property_readonly("lastArgPartialShape", &ModelStat::get_lastArgPartialShape); -} - -static void register_mock_place_stat(py::module m) { - m.def( - "get_place_stat", - [](const Place::Ptr& fe) { - std::shared_ptr ptr = std::dynamic_pointer_cast(fe); - if (ptr) { - auto stat = ptr->get_stat(); - return stat; - } - return PlaceStat(); - }, - py::arg("place")); - - py::class_ placeStat(m, "PlaceStat", py::dynamic_attr()); - - placeStat.def_property_readonly("lastArgString", &PlaceStat::get_lastArgString); - placeStat.def_property_readonly("lastArgInt", &PlaceStat::get_lastArgInt); - placeStat.def_property_readonly("lastArgPlace", &PlaceStat::get_lastArgPlace); - - placeStat.def_property_readonly("get_names", &PlaceStat::get_names); - placeStat.def_property_readonly("get_consuming_operations", &PlaceStat::get_consuming_operations); - placeStat.def_property_readonly("get_target_tensor", &PlaceStat::get_target_tensor); - placeStat.def_property_readonly("get_producing_operation", &PlaceStat::get_producing_operation); - placeStat.def_property_readonly("get_producing_port", &PlaceStat::get_producing_port); - placeStat.def_property_readonly("get_input_port", &PlaceStat::get_input_port); - placeStat.def_property_readonly("get_output_port", &PlaceStat::get_output_port); - placeStat.def_property_readonly("get_consuming_ports", &PlaceStat::get_consuming_ports); - placeStat.def_property_readonly("is_input", &PlaceStat::is_input); - placeStat.def_property_readonly("is_output", &PlaceStat::is_output); - placeStat.def_property_readonly("is_equal", &PlaceStat::is_equal); - placeStat.def_property_readonly("is_equal_data", &PlaceStat::is_equal_data); - placeStat.def_property_readonly("get_source_tensor", &PlaceStat::get_source_tensor); -} - -PYBIND11_MODULE(pybind_mock_frontend, m) { - m.doc() = "Mock frontend call counters for testing Pyngraph frontend bindings"; - register_mock_frontend_stat(m); - register_mock_model_stat(m); - register_mock_place_stat(m); -}