Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[request] onnxruntime/1.7.1 #4806

Closed
chausner opened this issue Mar 6, 2021 · 11 comments · Fixed by #16849
Closed

[request] onnxruntime/1.7.1 #4806

chausner opened this issue Mar 6, 2021 · 11 comments · Fixed by #16849

Comments

@chausner
Copy link
Contributor

chausner commented Mar 6, 2021

Package Details

Description Of The Library / Tool

ONNX Runtime is a cross-platform inference and training machine-learning accelerator compatible with deep learning frameworks, PyTorch and TensorFlow/Keras, as well as classical machine learning libraries such as scikit-learn, and more.

@CAMOBAP
Copy link
Contributor

CAMOBAP commented Apr 4, 2021

@chausner

I have the one which works for Linux and Android

conanfile.py (ONNXRuntimeConan)

import os
import sys
from six import StringIO # Python 2 and 3 compatible
from conans import ConanFile, tools

class ONNXRuntimeConan(ConanFile):
    name = "OnnxRuntime"
    version = "1.7.1"
    license = "MIT License"
    author = "https://github.com/microsoft/onnxruntime/graphs/contributors"
    description = "ONNX Runtime: cross-platform, high performance scoring engine" \
                  " for ML models https://aka.ms/onnxruntime"
    topics = ("deep-learning", "onnx", "neural-networks", "machine-learning", "ai-framework", "hardware-acceleration")
    settings = "os", "compiler", "build_type", "arch"

    options = {
        "shared": [True, False],
        "parallel": [True, False],
        "force_min_size_rel": [True, False],
        "with_dml": [True, False],
        "with_openmp": [True, False],
        "with_dnnl": [True, False],
        "with_nnapi": [True, False],
        "with_winml": [True, False],
        "with_python_wheel": [True, False],
        "with_csharp": [True, False],
        "with_java": [True, False],
        "with_tests": [True, False]
    }
    default_options = { k : False for k, v in options.items() }

    source_subfolder = name
    required_protoc_version = "libprotoc 3.11.3"

    def source(self):
        git = tools.Git(folder=self.source_subfolder)
        git.clone("https://github.com/microsoft/onnxruntime.git")
        git.checkout("v{}".format(self.version), submodule="recursive")

    def build(self):
        build_script = '.\\build.bat' if sys.platform == 'win32' else './build.sh'
        build_args = []

        if self.options.force_min_size_rel:
            build_args.extend(['--config', 'MinSizeRel'])
        elif self.settings.build_type is not None:
            build_args.extend(['--config', str(self.settings.build_type)])

        if self.options.shared:
            build_args.append('--build_shared_lib')

        if self.options.parallel:
            build_args.append('--parallel')

        if self.options.with_openmp:
            build_args.append('--use_openmp')

        if self.options.with_dnnl:
            build_args.append('--use_dnnl')

        if self.options.with_nnapi:
            build_args.append('--use_nnapi')

        if self.options.with_winml:
            build_args.append('--use_winml')

        if self.options.with_dml:
            build_args.append('--use_dml')

        if self.options.with_python_wheel:
            build_args.append('--build_wheel')

        if self.options.with_csharp:
            build_args.append('--build_csharp')

        if self.options.with_java:
            build_args.append('--use_java')

        if self.options.with_tests:
            build_args.append('--tests')
        else:
            build_args.append('--skip_tests')

        build_args.extend(['--cmake_extra_defines', 'CMAKE_INSTALL_PREFIX={}'.format(self.package_folder)])

        # TODO full list of options https://github.com/microsoft/onnxruntime/blob/master/BUILD.md
        # REVISIT Maybe better call cmake directly

        if self.settings.os == "Android":
            build_args.append('--android')

            android_ndk_root = None
            android_sdk_root = None
            if 'ANDROID_NDK_ROOT' in os.environ:
                android_ndk_root = os.environ.get('ANDROID_NDK_ROOT')
            elif 'ANDROID_NDK_HOME' in os.environ:
                android_ndk_root = os.environ.get('ANDROID_NDK_HOME')

            if 'ANDROID_SDK_ROOT' in os.environ:
                android_sdk_root = os.environ.get('ANDROID_SDK_ROOT')
            elif 'ANDROID_SDK_HOME' in os.environ:
                android_sdk_root = os.environ.get('ANDROID_SDK_HOME')
            elif 'ANDROID_HOME' in os.environ:
                android_sdk_root = os.environ.get('ANDROID_HOME')

            if android_ndk_root is None:
                ndk_bundle_path = os.path.join(android_sdk_root, 'ndk-bundle')
                if os.path.isdir(ndk_bundle_path):
                    android_ndk_root = ndk_bundle_path

            if android_ndk_root is None:
                raise Exception("ANDROID_NDK_ROOT env not defined")
            if android_sdk_root is None:
                raise Exception("ANDROID_SDK_ROOT env not defined")

            build_args.extend(['--android_sdk_path', android_sdk_root])
            build_args.extend(['--android_ndk_path', android_ndk_root])
            build_args.extend(['--android_abi', tools.to_android_abi(self.settings.arch)])

            if self.settings.os.api_level:
                build_args.extend(['--android_api', str(self.settings.os.api_level)])

        build_args.extend(['--path_to_protoc_exe', self._which_protoc()])

        with tools.chdir(self.source_subfolder):
            self.run(" ".join([build_script] + build_args))

    def package(self):
        build_type = "MinSizeRel" if self.options.force_min_size_rel else str(self.settings.build_type)
        os_subdir = str(self.settings.os)
        onnx_build_output = os.path.join(self.build_folder, self.source_subfolder, 'build', os_subdir, build_type)
        self.run('cmake --build {} --target install'.format(onnx_build_output))

        if not self.options.shared:
            self.copy(pattern="*.a", dst="lib", src=onnx_build_output, keep_path=False)

        self.copy(pattern="onnxruntime_perf_test", dst="bin", src=onnx_build_output, keep_path=False)

        providers_inc = 'include/onnxruntime/core/providers'
        if self.options.with_nnapi:
            self.copy("*.h", f"{providers_inc}/nnapi", f"{self.name}/{providers_inc}/nnapi")

        if self.options.with_dnnl:
            self.copy("*.h", f"{providers_inc}/dnnl", f"{self.name}/{providers_inc}/dnnl")

    def package_info(self):
        if self.options.shared:
            self.cpp_info.libs = ['onnxruntime']
        else:
            debug_suffix = "d" if self.settings.build_type == "Debug" else ""

            onnxruntime_libs = []

            if self.options.with_nnapi:
                onnxruntime_libs.append('providers_nnapi')

            onnxruntime_libs.extend([
                'session',
                'optimizer',
                'providers',
                'framework',
                'graph',
                'util',
                'mlas',
                'common',
                'flatbuffers',
            ])

            self.cpp_info.libs = ['onnxruntime_' + lib for lib in onnxruntime_libs]

            self.cpp_info.libs.extend([
                'onnx',
                'onnx_proto',
                'flatbuffers',
                're2',
                'nsync_cpp',
                'protobuf-lite' + debug_suffix,
            ])

            if self.options.with_dnnl:
                self.cpp_info.libs.append('dnnl')

        if self.options.with_nnapi:
            self.cpp_info.includedirs.append('include/onnxruntime/core/session')

    def _which_protoc(self):
        protoc_path = tools.which("protoc")
        if protoc_path is None:
            raise Exception("No protoc found in PATH")
        else:
            protoc_version_buf = StringIO()
            self.run('{} --version'.format(protoc_path), output=protoc_version_buf)
            protoc_version = protoc_version_buf.getvalue().strip()
            if protoc_version == self.required_protoc_version:
                return protoc_path
            else:
                raise Exception("Inappropriate version of protoc was found. Required: '{}' found: '{}'".format(self.required_protoc_version, protoc_version))

Unfortunatelly it's not ready to push yet (I hope I will finalize it a couple next weeks). List of the issues which need to be fixed:

  • migrate to conandata.yml
  • add test_package
  • add config.yml
  • add build_require(protobuf)
  • add [email protected] version

If you need OnnxRuntime ASAP you can try the script above (use it locally and export)

@chausner
Copy link
Contributor Author

chausner commented Apr 4, 2021

Thanks a lot! We also have a preliminary recipe ready which has been tested on Windows, macOS and iOS (but your recipe is more generic and closer to being universally usable). If you want to publish your current state in a fork, I may be able to contribute with some enhancements.

@CAMOBAP
Copy link
Contributor

CAMOBAP commented Apr 4, 2021

@chausner forgot to mention that I tested on macOS too, unfortunately, didn't test on iOS and Windows yet

CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Apr 5, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Apr 5, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Apr 5, 2021
@SpaceIm
Copy link
Contributor

SpaceIm commented Apr 5, 2021

It doesn't work with latest versions of protobuf?

conan-center-bot pushed a commit that referenced this issue Apr 6, 2021
* [boost] Add 'algorithm' lib #3961

* Revert "[boost] Add 'algorithm' lib #3961"

This reverts commit 5f1419d.

* #4806 add protobuf/3.11.3 to be used by onnxruntime/1.7.1 later
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Apr 10, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Apr 10, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Apr 10, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Apr 10, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Apr 10, 2021
AlvaroFS pushed a commit to AlvaroFS/conan-center-index that referenced this issue May 7, 2021
* [boost] Add 'algorithm' lib conan-io#3961

* Revert "[boost] Add 'algorithm' lib conan-io#3961"

This reverts commit 5f1419d.

* conan-io#4806 add protobuf/3.11.3 to be used by onnxruntime/1.7.1 later
@chausner-audeering
Copy link
Contributor

@CAMOBAP I see you've been pushing your work to https://github.com/CAMOBAP/conan-center-index and it looks really great already! Thanks a lot for that. I have a few comments on some things but commenting on single commits is a bit cumbersome. If you want to open a merge request in your fork it would be great.

@CAMOBAP
Copy link
Contributor

CAMOBAP commented May 14, 2021

@chausner-audeering I have checked my fork settings and it allows to create PR to my form. Also you can report issues to my fork with your comment/suggestions

@chausner-audeering
Copy link
Contributor

chausner-audeering commented May 14, 2021

@chausner-audeering I have checked my fork settings and it allows to create PR to my form. Also you can report issues to my fork with your comment/suggestions

Thanks, I added a couple of comments at CAMOBAP@122ceaf for now.

CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Jun 28, 2021
@CAMOBAP
Copy link
Contributor

CAMOBAP commented Jun 29, 2021

onnxruntime depends on https://github.com/google/nsync - I will add it first

CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Jun 29, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Jun 29, 2021
This was referenced Jun 29, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Jun 30, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Jun 30, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Jun 30, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Jun 30, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 11, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 11, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 15, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 15, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 15, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 16, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 16, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 16, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 16, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 16, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 16, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 16, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 16, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 17, 2021
conan-center-bot pushed a commit that referenced this issue Sep 25, 2021
* [boost] Add 'algorithm' lib #3961

* Revert "[boost] Add 'algorithm' lib #3961"

This reverts commit 5f1419d.

* #4806 add nsync because required by onnxruntime

* #4806 nsync add LICENSE file package

* Add homepage, update source dowload, using components to seaprate nsync and nsync_cpp

* #4806 nsync: add pthread as system_lib for Linux

* #4806 nsync: simplify tests

* #4806 nsync: fix missing nsync_mu_init in tests

* #4806 nsync: add missing CMakeLists.txt wrapper with conan_basic_setup

* #4806 nsync remove with_tests option

Co-authored-by: Uilian Ries <[email protected]>

* #4806 nsync remove with_tests option

Co-authored-by: Uilian Ries <[email protected]>

* #4806 nsync: remove chdir from test receipt

Co-authored-by: Uilian Ries <[email protected]>

* #4806 nsync: improve test CMakeLists.txt

Co-authored-by: Uilian Ries <[email protected]>

* #4806 nsync: add build_folder to cmake.configure

Co-authored-by: Uilian Ries <[email protected]>

* #4806 nsync: remove redundant pthread flags

Co-authored-by: Uilian Ries <[email protected]>

* #4806 nsync: replace cmake_find_package generator with cmake_find_package_multi

Co-authored-by: Uilian Ries <[email protected]>

* #4806 nsync: fix include(conanbuildinfo.cmake)

* #4806 nsync: fix test c library

* #4806 nsync: add shared and fPIC options

Co-authored-by: Uilian Ries <[email protected]>

* #4806 nsync: fix redundant semaphore_mutex.c compilation during nsync_cpp.so build

* #4806 nsync: fix copy dlls to lib

* #4806 nsync: remove code duplication in nsync_c and nsync_cpp components

* #4806 nsync: add CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS

* #4806 nsync: remove unnecessary code

Co-authored-by: Uilian Ries <[email protected]>

* Apply suggestions from code review

Move base_path to conandata.yaml

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/nsync/all/conanfile.py

Fix typo in receipt description

Co-authored-by: Eric Riff <[email protected]>

Co-authored-by: Uilian Ries <[email protected]>
Co-authored-by: Chris Mc <[email protected]>
Co-authored-by: Eric Riff <[email protected]>
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Sep 25, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Oct 2, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Oct 2, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Oct 2, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Oct 2, 2021
CAMOBAP added a commit to CAMOBAP/conan-center-index that referenced this issue Oct 3, 2021
@vdsbenoit
Copy link
Contributor

Hi 👋 ,

Thank you for the effort you're making here, it is much appreciated.

May I ask you what is the status of this package ? Can we fetch it somehow? I don't see it when searching on https://conan.io/center

@CAMOBAP
Copy link
Contributor

CAMOBAP commented Oct 27, 2021

@vdsbenoit it's not published yet, because not all configurations pass the CI, unfortunately, I haven't time in near month to work on it(

@vdsbenoit
Copy link
Contributor

All right, thank you for your quick answer. Wouldn't it be possible to reduce the scope of the configuration and limit it to the ones passing the CI ?

@elejke elejke mentioned this issue Mar 25, 2023
3 tasks
gmeeker added a commit to gmeeker/conan-center-index that referenced this issue Mar 29, 2023
@gmeeker gmeeker mentioned this issue Apr 1, 2023
3 tasks
@mayeut mayeut mentioned this issue Apr 1, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants