* Mk/ov pybind poc (#48)
* Move _pyngraph module to ngraph.pyngraph
* Stub for IECore and IENetwork classes
* Additional API classes
* passing test, extended functions and added blob
* worksave
* [POC Python API] Add IECore methods
* [POC Python API] Add iecore tests
* ienetwork
* ienet, input_info, dataptr
* irequest and exeecnet
* adapted benchmark
* Move _pyngraph module to ngraph.pyngraph
* Stub for IECore and IENetwork classes
* Additional API classes
* passing test, extended functions and added blob
* worksave
* [POC Python API] Add IECore methods
* [POC Python API] Add iecore tests
* ienetwork
* ienet, input_info, dataptr
* irequest and exeecnet
* adapted benchmark
* Added suport for InputInfo bindings
* Add Blob support for different types
* fix typo
* Fixed InputInfo maps
* Add keys() to inputs maps
* add uint8 blob
* return read_network as it should be
* return read_network as it should be
* fix blob buffer
* remove const input_info files and fix codestyle
* add mode parameter in benchmark app
* return _pyngraph
* delete benchmark copy
* return pyngraph as in master
* fix benchmark working
* add comment with api which need to implement
* remove unnecessary code from benchmark
* remove hardcoded path from setup.py
* Rename vars in setup.py
* working wheel
* fix wheel building
* Revert "working wheel"
This reverts commit 11d03a1833.
* fix tests
* Added async infer
* pass by ref
* add ccompiler to requirements
* fix blob creation and view
* replace abscent method with working code in benchmark
* fix building
* worksave
* worksave queue
* no-deadlock async infer
* add lock handle in waitAll
* fix building issues with includes
* update of setup and cmakelist
* fix setup.py way of building
* add new methods for ie_core
* add ienetwork methods: serizlize and getfunction
* add methods for exec net and infer request class
* remove ccompiler from requirements
* remove set from cmake
* Update Blob class with precisions
* Rewrite test_write_numpy_scalar_int64
* Generic Blob casting in infer queue
* implementation of preprocess_info
* update license
* add set_blob method
* worksave
* added template for setblob
* Added blob convert in infer request
* move blob casting to common namespace
* add_outputs method
* work with func from pyopenvino
* add user_id to callbacks
* remove hardcoded root dir
* refactor code and comments
* [Python API] use parametrize in blob tests
* move common functions to conftest file
* Add tests for blob
* Update test_blob and test_network
* add parametrize in blob tests
* blob refactoring
* Fix sync in InferQueue and add default callbacks
* patch for protobuf cmake
* blob refactoring
* rename convert_to_blob to cast_to_blob
* rename to cast_to_blob in infer queue
* add missing cast_to_blob
* remove boost
* change license
* undo in cmake
* fix building
* [IE PYTHON API POC] Add fixed InferQueue and modification in async part of benchmark
* Add read_network(model,blob)
* Add blob_from_file helper
* Add read from Path
* Add tests
* Add read_network from bytes
* Error throwing in Common IE functions
* Cleaning samples
* Changes in ConstInputInfoWrapper class
* Add StatusCode to callback function for InferRequest
* Add random image generation and model path getting
* Move example model to examples path
* Adapt sync and async examples to new helpers
* Return request info containing StatusCode and ID from InferQueue for top idle request.
* Update benchmark app to use new API with request info
* Update examples to use two different approaches to InferQueue
* reset new line
* Add is_ready() to InferQueue
* fix building
* remove benchmark
* temporary add separate flag for building poc
* refactoring
* Remove GIL acquire in default callback and latencies
* Adapt benchmark to Core()
* Codestyle
* fix building
* [Python API] Move ngraph python api to the new destination
* fix building tests
* fix code-style checks
* building in azure
* fix building wheels
* apply fixes
* new structure
* fix building
* Add support for InferRequest::Cancel in pyopenvino
* fixes
remove gil release
add async infer after cancel
* remove extra files
* remove examples and benchmark
* fix code style
* fix building
* fix tests
* merge inits from old and new api
* fix azure ci
* fix setup.py
* fix setup.py building
* try to fix mac
Co-authored-by: Michal Karzynski <michal.karzynski@intel.com>
Co-authored-by: jiwaszki <jan.iwaszkiewicz@intel.com>
Co-authored-by: anastasia.kuporosova <akuporos@akuporos.inn.intel.com>
Co-authored-by: Alexey Lebedev <alexey.lebedev@intel.com>
Co-authored-by: Mateusz Tabaka <mateusz.tabaka@intel.com>
* Fix comments
* fix comments: cmakelist
* fix building on arm
* permission for merge script
* permission for merge script
Co-authored-by: Michal Karzynski <michal.karzynski@intel.com>
Co-authored-by: jiwaszki <jan.iwaszkiewicz@intel.com>
Co-authored-by: anastasia.kuporosova <akuporos@akuporos.inn.intel.com>
Co-authored-by: Alexey Lebedev <alexey.lebedev@intel.com>
Co-authored-by: Mateusz Tabaka <mateusz.tabaka@intel.com>
232 lines
8.5 KiB
Python
232 lines
8.5 KiB
Python
# Copyright (C) 2018-2021 Intel Corporation
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import os
|
|
import pathlib
|
|
import shutil
|
|
import glob
|
|
import sysconfig
|
|
import sys
|
|
import multiprocessing
|
|
|
|
from setuptools import Extension, setup
|
|
from setuptools.command.build_ext import build_ext
|
|
from setuptools.command.install_lib import install_lib
|
|
from setuptools.command.install import install as _install
|
|
from setuptools.command.develop import develop as _develop
|
|
from distutils.command.build import build as _build
|
|
|
|
__version__ = os.environ.get("NGRAPH_VERSION", "0.0.0.dev0")
|
|
PYNGRAPH_ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
|
|
OPENVINO_ROOT_DIR = os.path.normpath(os.path.join(PYNGRAPH_ROOT_DIR, "../../.."))
|
|
# Change current working directory to runtime/bindings/python
|
|
os.chdir(PYNGRAPH_ROOT_DIR)
|
|
|
|
NGRAPH_LIBS = ["ngraph", "onnx_ngraph_frontend", "openvino"]
|
|
|
|
packages = [
|
|
"ngraph",
|
|
"ngraph.opset1",
|
|
"ngraph.opset2",
|
|
"ngraph.opset3",
|
|
"ngraph.opset4",
|
|
"ngraph.opset5",
|
|
"ngraph.opset6",
|
|
"ngraph.opset7",
|
|
"ngraph.opset8",
|
|
"ngraph.utils",
|
|
"ngraph.impl",
|
|
"ngraph.impl.op",
|
|
"ngraph.impl.op.util",
|
|
"ngraph.impl.passes",
|
|
"ngraph.frontend",
|
|
"openvino"
|
|
]
|
|
|
|
|
|
data_files = []
|
|
|
|
with open(os.path.join(PYNGRAPH_ROOT_DIR, "requirements.txt")) as req:
|
|
requirements = req.read().splitlines()
|
|
|
|
cmdclass = {}
|
|
for super_class in [_build, _install, _develop]:
|
|
class command(super_class):
|
|
"""Add user options for build, install and develop commands."""
|
|
|
|
cmake_build_types = ["Release", "Debug", "RelWithDebInfo", "MinSizeRel"]
|
|
user_options = super_class.user_options + [
|
|
("config=", None, f"Build configuration [{'|'.join(cmake_build_types)}]."),
|
|
("jobs=", None, "Specifies the number of jobs to use with make."),
|
|
("cmake-args=", None, "Additional options to be passed to CMake.")
|
|
]
|
|
|
|
def initialize_options(self):
|
|
"""Set default values for all the options that this command supports."""
|
|
super().initialize_options()
|
|
self.config = None
|
|
self.jobs = None
|
|
self.cmake_args = None
|
|
|
|
cmdclass[super_class.__name__] = command
|
|
|
|
|
|
class CMakeExtension(Extension):
|
|
"""Build extension stub."""
|
|
|
|
def __init__(self, name, sources=None):
|
|
if sources is None:
|
|
sources = []
|
|
super().__init__(name=name, sources=sources)
|
|
|
|
|
|
class BuildCMakeExt(build_ext):
|
|
"""Builds module using cmake instead of the python setuptools implicit build."""
|
|
|
|
cmake_build_types = ["Release", "Debug", "RelWithDebInfo", "MinSizeRel"]
|
|
user_options = [
|
|
("config=", None, f"Build configuration [{'|'.join(cmake_build_types)}]."),
|
|
("jobs=", None, "Specifies the number of jobs to use with make."),
|
|
("cmake-args=", None, "Additional options to be passed to CMake.")
|
|
]
|
|
|
|
def initialize_options(self):
|
|
"""Set default values for all the options that this command supports."""
|
|
super().initialize_options()
|
|
self.build_base = "build"
|
|
self.config = None
|
|
self.jobs = None
|
|
self.cmake_args = None
|
|
|
|
def finalize_options(self):
|
|
"""Set final values for all the options that this command supports."""
|
|
super().finalize_options()
|
|
|
|
for cmd in ["build", "install", "develop"]:
|
|
self.set_undefined_options(cmd, ("config", "config"),
|
|
("jobs", "jobs"),
|
|
("cmake_args", "cmake_args"))
|
|
|
|
if not self.config:
|
|
if self.debug:
|
|
self.config = "Debug"
|
|
else:
|
|
self.announce("Set default value for CMAKE_BUILD_TYPE = Release.", level=4)
|
|
self.config = "Release"
|
|
else:
|
|
build_types = [item.lower() for item in self.cmake_build_types]
|
|
try:
|
|
i = build_types.index(str(self.config).lower())
|
|
self.config = self.cmake_build_types[i]
|
|
self.debug = True if "Debug" == self.config else False
|
|
except ValueError:
|
|
self.announce("Unsupported CMAKE_BUILD_TYPE value: " + self.config, level=4)
|
|
self.announce(f"Supported values: {', '.join(self.cmake_build_types)}", level=4)
|
|
sys.exit(1)
|
|
if self.jobs is None and os.getenv("MAX_JOBS") is not None:
|
|
self.jobs = os.getenv("MAX_JOBS")
|
|
self.jobs = multiprocessing.cpu_count() if self.jobs is None else int(self.jobs)
|
|
|
|
def run(self):
|
|
"""Run CMake build for modules."""
|
|
for extension in self.extensions:
|
|
if extension.name == "pyopenvino":
|
|
self.build_cmake(extension)
|
|
if extension.name == "_pyngraph":
|
|
self.build_cmake(extension)
|
|
|
|
def build_cmake(self, extension: Extension):
|
|
"""Cmake configure and build steps."""
|
|
self.announce("Preparing the build environment", level=3)
|
|
plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
|
|
self.build_temp = os.path.join(self.build_base, "temp" + plat_specifier, self.config)
|
|
build_dir = pathlib.Path(self.build_temp)
|
|
|
|
extension_path = pathlib.Path(self.get_ext_fullpath(extension.name))
|
|
|
|
os.makedirs(build_dir, exist_ok=True)
|
|
os.makedirs(extension_path.parent.absolute(), exist_ok=True)
|
|
|
|
# If OpenVINO_DIR is set, try to build Python only,
|
|
# otherwise build from scratch using OpenVINO root
|
|
root_dir = OPENVINO_ROOT_DIR
|
|
bin_dir = os.path.join(OPENVINO_ROOT_DIR, "bin")
|
|
if os.environ.get("OpenVINO_DIR") is not None:
|
|
root_dir = PYNGRAPH_ROOT_DIR
|
|
bin_dir = build_dir
|
|
|
|
self.announce("Configuring cmake project", level=3)
|
|
ext_args = self.cmake_args.split() if self.cmake_args else []
|
|
self.spawn(["cmake", "-S" + root_dir, "-B" + self.build_temp,
|
|
f"-DCMAKE_BUILD_TYPE={self.config}",
|
|
f"-DInferenceEngine_DIR={os.path.join(OPENVINO_ROOT_DIR, 'build')}",
|
|
"-DENABLE_PYTHON=ON",
|
|
"-DNGRAPH_ONNX_FRONTEND_ENABLE=ON"] + ext_args)
|
|
|
|
self.announce("Building binaries", level=3)
|
|
|
|
self.spawn(["cmake", "--build", self.build_temp, "--target", extension.name,
|
|
"--config", self.config, "-j", str(self.jobs)])
|
|
|
|
self.announce("Moving built python module to " + str(extension_path), level=3)
|
|
pyds = list(glob.iglob(f"{bin_dir}/**/{extension.name}*{sysconfig.get_config_var('EXT_SUFFIX')}",
|
|
recursive=True))
|
|
for name in pyds:
|
|
self.announce("copy " + os.path.join(name), level=3)
|
|
shutil.copy(name, extension_path)
|
|
|
|
|
|
class InstallCMakeLibs(install_lib):
|
|
"""Finds and installs NGraph libraries to a package location."""
|
|
|
|
def run(self):
|
|
"""Copy libraries from the bin directory and place them as appropriate."""
|
|
self.announce("Adding library files", level=3)
|
|
|
|
root_dir = os.path.join(OPENVINO_ROOT_DIR, "bin")
|
|
if os.environ.get("OpenVINO_DIR") is not None:
|
|
root_dir = pathlib.Path(PYNGRAPH_ROOT_DIR)
|
|
|
|
lib_ext = ""
|
|
if "linux" in sys.platform:
|
|
lib_ext = ".so"
|
|
elif sys.platform == "darwin":
|
|
lib_ext = ".dylib"
|
|
elif sys.platform == "win32":
|
|
lib_ext = ".dll"
|
|
|
|
libs = []
|
|
print(root_dir)
|
|
for ngraph_lib in NGRAPH_LIBS:
|
|
libs.extend(list(glob.iglob(f"{root_dir}/**/*{ngraph_lib}*{lib_ext}", recursive=True)))
|
|
print(libs)
|
|
if not libs:
|
|
raise Exception("NGraph libs not found.")
|
|
|
|
self.announce("Adding library files" + str(libs), level=3)
|
|
|
|
self.distribution.data_files.extend([("lib", [os.path.normpath(lib) for lib in libs])])
|
|
self.distribution.run_command("install_data")
|
|
super().run()
|
|
|
|
|
|
cmdclass["build_ext"] = BuildCMakeExt
|
|
cmdclass["install_lib"] = InstallCMakeLibs
|
|
|
|
setup(
|
|
name="ngraph-core",
|
|
description="nGraph - Intel's graph compiler and runtime for Neural Networks",
|
|
version=__version__,
|
|
author="Intel Corporation",
|
|
url="https://github.com/openvinotoolkit/openvino",
|
|
license="License :: OSI Approved :: Apache Software License",
|
|
ext_modules=[CMakeExtension(name="_pyngraph"), CMakeExtension(name="pyopenvino")],
|
|
package_dir={"": "src/compatibility", "openvino": "src/openvino"},
|
|
packages=packages,
|
|
install_requires=requirements,
|
|
data_files=data_files,
|
|
zip_safe=False,
|
|
extras_require={},
|
|
cmdclass=cmdclass
|
|
)
|