[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 <anastasia.kuporosova@intel.com> Co-authored-by: y <ilya.lavrenov@intel.com>
This commit is contained in:
parent
fa1d9867f2
commit
4e6eeea6ff
@ -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)
|
||||
|
@ -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__":
|
||||
|
@ -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):
|
||||
|
@ -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'))
|
||||
|
@ -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__":
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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, "
|
||||
|
@ -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, "
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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)
|
||||
|
@ -1,17 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
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);
|
||||
|
@ -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);
|
||||
|
50
src/bindings/python/src/openvino/frontend/__init__.py
Normal file
50
src/bindings/python/src/openvino/frontend/__init__.py
Normal file
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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_<FrontEnd, std::shared_ptr<FrontEnd>> 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<std::shared_ptr<ngraph::Function> (FrontEnd::*)(InputModel::Ptr) const>(&FrontEnd::convert),
|
||||
static_cast<std::shared_ptr<ov::Function> (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<void (FrontEnd::*)(std::shared_ptr<ngraph::Function>) const>(&FrontEnd::convert),
|
||||
static_cast<void (FrontEnd::*)(std::shared_ptr<ov::Function>) 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_<ov::Extension, std::shared_ptr<ov::Extension>> ext(m, "Extension", py::dynamic_attr());
|
||||
}
|
||||
|
||||
void regclass_pyngraph_TelemetryExtension(py::module m) {
|
||||
void regclass_frontend_TelemetryExtension(py::module m) {
|
||||
{
|
||||
py::class_<TelemetryExtension, std::shared_ptr<TelemetryExtension>, ov::Extension> ext(m,
|
||||
"TelemetryExtension",
|
@ -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);
|
@ -13,12 +13,11 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
void regclass_pyngraph_FrontEndManager(py::module m) {
|
||||
void regclass_frontend_FrontEndManager(py::module m) {
|
||||
py::class_<ov::frontend::FrontEndManager, std::shared_ptr<ov::frontend::FrontEndManager>> 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<ov::frontend::GeneralFailure> 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<ov::frontend::OpValidationFailure> 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<ov::frontend::OpConversionFailure> 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<ov::frontend::InitializationFailure> 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<ov::frontend::NotImplementedFailure> exc(std::move(m), "NotImplementedFailure");
|
||||
py::register_exception_translator([](std::exception_ptr p) {
|
||||
try {
|
@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
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);
|
||||
|
@ -11,12 +11,11 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
void regclass_pyngraph_InputModel(py::module m) {
|
||||
void regclass_frontend_InputModel(py::module m) {
|
||||
py::class_<ov::frontend::InputModel, std::shared_ptr<ov::frontend::InputModel>> 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,
|
@ -8,4 +8,4 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
void regclass_pyngraph_InputModel(py::module m);
|
||||
void regclass_frontend_InputModel(py::module m);
|
@ -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_<ov::frontend::Place, std::shared_ptr<ov::frontend::Place>> 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_<ov::frontend::Place, std::shared_ptr<ov::frontend::Place>> place(m, "Place", py::dynamic_attr());
|
||||
place.doc() = "openvino.frontend.Place wraps ov::frontend::Place";
|
||||
|
||||
place.def("is_input",
|
||||
&ov::frontend::Place::is_input,
|
@ -8,4 +8,4 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
void regclass_pyngraph_Place(py::module m);
|
||||
void regclass_frontend_Place(py::module m);
|
@ -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);
|
||||
}
|
||||
|
@ -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():
|
@ -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------
|
@ -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
|
||||
|
@ -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)
|
@ -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<FrontEndMockPy>();
|
||||
};
|
||||
|
||||
return res;
|
||||
}
|
@ -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<std::string> get_names() const override {
|
||||
m_stat.m_get_names++;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<Place::Ptr> get_consuming_operations() const override {
|
||||
m_stat.m_get_consuming_operations++;
|
||||
m_stat.m_lastArgInt = -1;
|
||||
m_stat.m_lastArgString = "";
|
||||
return {std::make_shared<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
std::vector<Place::Ptr> 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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
std::vector<Place::Ptr> 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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
std::vector<Place::Ptr> 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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
Place::Ptr get_target_tensor() const override {
|
||||
m_stat.m_get_target_tensor++;
|
||||
m_stat.m_lastArgInt = -1;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
Place::Ptr get_target_tensor(int outputPortIndex) const override {
|
||||
m_stat.m_get_target_tensor++;
|
||||
m_stat.m_lastArgInt = outputPortIndex;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
Place::Ptr get_producing_operation() const override {
|
||||
m_stat.m_get_producing_operation++;
|
||||
m_stat.m_lastArgInt = -1;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
Place::Ptr get_producing_operation(int inputPortIndex) const override {
|
||||
m_stat.m_get_producing_operation++;
|
||||
m_stat.m_lastArgInt = inputPortIndex;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
Place::Ptr get_producing_port() const override {
|
||||
m_stat.m_get_producing_port++;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
Place::Ptr get_input_port() const override {
|
||||
m_stat.m_get_input_port++;
|
||||
m_stat.m_lastArgInt = -1;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
Place::Ptr get_input_port(int inputPortIndex) const override {
|
||||
m_stat.m_get_input_port++;
|
||||
m_stat.m_lastArgInt = inputPortIndex;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
Place::Ptr get_output_port() const override {
|
||||
m_stat.m_get_output_port++;
|
||||
m_stat.m_lastArgInt = -1;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
Place::Ptr get_output_port(int outputPortIndex) const override {
|
||||
m_stat.m_get_output_port++;
|
||||
m_stat.m_lastArgInt = outputPortIndex;
|
||||
return std::make_shared<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
std::vector<Place::Ptr> get_consuming_ports() const override {
|
||||
m_stat.m_get_consuming_ports++;
|
||||
return {std::make_shared<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
Place::Ptr get_source_tensor() const override {
|
||||
m_stat.m_get_source_tensor++;
|
||||
m_stat.m_lastArgInt = -1;
|
||||
return {std::make_shared<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
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<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
//---------------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<Place::Ptr> m_lastArgInputPlaces;
|
||||
std::vector<Place::Ptr> 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<Place::Ptr> get_lastArgInputPlaces() const {
|
||||
return m_lastArgInputPlaces;
|
||||
}
|
||||
std::vector<Place::Ptr> 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<Place::Ptr> get_inputs() const override {
|
||||
m_stat.m_get_inputs++;
|
||||
return {std::make_shared<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
std::vector<Place::Ptr> get_outputs() const override {
|
||||
m_stat.m_get_outputs++;
|
||||
return {std::make_shared<PlaceMockPy>()};
|
||||
}
|
||||
|
||||
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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
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<int>(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<PlaceMockPy>();
|
||||
}
|
||||
|
||||
void remove_output(Place::Ptr place) override {
|
||||
m_stat.m_remove_output++;
|
||||
m_stat.m_lastArgPlace = place;
|
||||
}
|
||||
|
||||
void override_all_outputs(const std::vector<Place::Ptr>& outputs) override {
|
||||
m_stat.m_override_all_outputs++;
|
||||
m_stat.m_lastArgOutputPlaces = outputs;
|
||||
}
|
||||
|
||||
void override_all_inputs(const std::vector<Place::Ptr>& inputs) override {
|
||||
m_stat.m_override_all_inputs++;
|
||||
m_stat.m_lastArgInputPlaces = inputs;
|
||||
}
|
||||
|
||||
void extract_subgraph(const std::vector<Place::Ptr>& inputs, const std::vector<Place::Ptr>& 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<std::string> 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<std::string> 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<std::shared_ptr<Variant>>& params) const override {
|
||||
if (params.size() > 0 && ov::is_type<VariantWrapper<std::string>>(params[0]))
|
||||
m_stat.m_load_paths.push_back(ov::as_type_ptr<VariantWrapper<std::string>>(params[0])->get());
|
||||
return std::make_shared<InputModelMockPy>();
|
||||
}
|
||||
|
||||
bool supported_impl(const std::vector<std::shared_ptr<Variant>>& params) const override {
|
||||
m_stat.m_supported++;
|
||||
if (params.size() > 0 && ov::is_type<VariantWrapper<std::string>>(params[0])) {
|
||||
auto path = ov::as_type_ptr<VariantWrapper<std::string>>(params[0])->get();
|
||||
if (path.find(".test_mock_py_mdl") != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<ngraph::Function> convert(InputModel::Ptr model) const override {
|
||||
m_stat.m_convert_model++;
|
||||
return std::make_shared<ngraph::Function>(NodeVector{}, ParameterVector{});
|
||||
}
|
||||
|
||||
void convert(std::shared_ptr<ngraph::Function> func) const override {
|
||||
m_stat.m_convert++;
|
||||
}
|
||||
|
||||
std::shared_ptr<ngraph::Function> convert_partially(InputModel::Ptr model) const override {
|
||||
m_stat.m_convert_partially++;
|
||||
return std::make_shared<ngraph::Function>(NodeVector{}, ParameterVector{});
|
||||
}
|
||||
|
||||
std::shared_ptr<ngraph::Function> decode(InputModel::Ptr model) const override {
|
||||
m_stat.m_decode++;
|
||||
return std::make_shared<ngraph::Function>(NodeVector{}, ParameterVector{});
|
||||
}
|
||||
|
||||
void normalize(std::shared_ptr<ngraph::Function> 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;
|
||||
}
|
||||
};
|
@ -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)
|
@ -1,127 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#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<FrontEnd>& fe) {
|
||||
std::shared_ptr<FrontEndMockPy> ptr = std::dynamic_pointer_cast<FrontEndMockPy>(fe);
|
||||
if (ptr) {
|
||||
auto stat = ptr->get_stat();
|
||||
return stat;
|
||||
}
|
||||
return FeStat();
|
||||
},
|
||||
py::arg("frontend"));
|
||||
|
||||
py::class_<FeStat> 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<InputModel>& mdl) {
|
||||
std::shared_ptr<InputModelMockPy> ptr = std::dynamic_pointer_cast<InputModelMockPy>(mdl);
|
||||
if (ptr) {
|
||||
auto stat = ptr->get_stat();
|
||||
return stat;
|
||||
}
|
||||
return ModelStat();
|
||||
},
|
||||
py::arg("model"));
|
||||
|
||||
py::class_<ModelStat> 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<PlaceMockPy> ptr = std::dynamic_pointer_cast<PlaceMockPy>(fe);
|
||||
if (ptr) {
|
||||
auto stat = ptr->get_stat();
|
||||
return stat;
|
||||
}
|
||||
return PlaceStat();
|
||||
},
|
||||
py::arg("place"));
|
||||
|
||||
py::class_<PlaceStat> 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user