microsoft/onnxruntime-extensions
Publicmirrored from https://github.com/microsoft/onnxruntime-extensionsAvailable
docs/development.md
89lines · modeblame
0647ce6dWenbing Li3 years ago | 1 | # Build and Development |
| 2 | | |
| 3 | This project supports Python and can be built from source easily, or a simple cmake build without Python dependency. | |
fb2a8c28Wenbing Li2 years ago | 4 | |
0647ce6dWenbing Li3 years ago | 5 | ## Python package |
fb2a8c28Wenbing Li2 years ago | 6 | |
e710d80fWenbing Li1 years ago | 7 | ### **Nightly Build** |
| 8 | | |
| 9 | #### <strong>Windows</strong> | |
| 10 | Ensure that the prerequisite packages for onnxruntime-extensions (e.g., onnx and onnxruntime) are installed in your Python environment. | |
| 11 | ```cmd | |
| 12 | pip install --index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ onnxruntime-extensions | |
| 13 | ``` | |
| 14 | #### <strong>Linux/macOS</strong> | |
| 15 | Ensure the compiler toolkit like gcc(later than g++ 8.0) or clang, and cmake are installed before the following command | |
| 16 | ```bash | |
| 17 | python -m pip install git+https://github.com/microsoft/onnxruntime-extensions.git | |
| 18 | ``` | |
| 19 | | |
| 20 | | |
0647ce6dWenbing Li3 years ago | 21 | The package contains all custom operators and some Python scripts to manipulate the ONNX models. |
fb2a8c28Wenbing Li2 years ago | 22 | |
e710d80fWenbing Li1 years ago | 23 | ### Build from source |
| 24 | | |
972cb17aWenbing Li2 years ago | 25 | - Install Visual Studio with C++ development tools on Windows, or gcc(>8.0) for Linux or xcode for macOS, and cmake on the unix-like platform. |
| 26 | - If running on Windows, ensure that long file names are enabled, both for the [operating system](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd) and for git: `git config --system core.longpaths true` | |
| 27 | - Make sure the Python development header/library files be installed, (like `apt-get install python3-dev` for Ubuntu Linux) | |
| 28 | - `pip install .` to build and install the package.<br/> OR `pip install -e .` to install the package in the development mode, which is more friendly for the developer since the Python code change will take effect without having to copy the files to a different location in the disk.(**hints**: debug=1 in setup.cfg wil make C++ code be debuggable in a Python process.) | |
| 29 | - Add the following argument `--config-settings "ortx-user-option=use-cuda"` in the pip command line to enable **CUDA** kernels for the package. | |
| 30 | - The flags that can be used in --config-settings are: | |
fb2a8c28Wenbing Li2 years ago | 31 | - use-cuda: enable CUDA kernel build in Python package. |
| 32 | - no-azure: disable AzureOp kernel build in Python package. | |
| 33 | - no-opencv: disable operators based on OpenCV in build. | |
5d558bd3Wenbing Li2 years ago | 34 | - cc-debug: generate debug info for extensions binaries and disable C/C++ compiler optimization. |
2d02a687Wenbing Li1 years ago | 35 | - pp-api: enable pre-processing C ABI Python wrapper, `from onnxruntime_extensions.pp_api import *` |
5d558bd3Wenbing Li2 years ago | 36 | - cuda-archs: specify the CUDA architectures(like 70, 85, etc.), and the multiple values can be combined with semicolon. The default value is nvidia-smi util output of GPU-0 |
3649db06cao lei2 years ago | 37 | - ort\_pkg\_dir: specify ONNXRuntime package directory the extension project is depending on. This is helpful if you want to use some ONNXRuntime latest function which has not been involved in the official build |
fb2a8c28Wenbing Li2 years ago | 38 | |
5d558bd3Wenbing Li2 years ago | 39 | For example:`pip install . --config-settings "ortx-user-option=use-cuda,cc-debug" `, This command builds CUDA kernels into the package and installs it, accompanied by the generation of debug information. |
0647ce6dWenbing Li3 years ago | 40 | |
| 41 | Test: | |
fb2a8c28Wenbing Li2 years ago | 42 | |
0647ce6dWenbing Li3 years ago | 43 | - 'pip install -r requirements-dev.txt' to install pip packages for development. |
| 44 | - run `pytest test` in the project root directory. | |
| 45 | | |
| 46 | For a complete list of verified build configurations see [here](<./ci_matrix.md>) | |
| 47 | | |
| 48 | ## Java package | |
fb2a8c28Wenbing Li2 years ago | 49 | |
0647ce6dWenbing Li3 years ago | 50 | `bash ./build.sh -DOCOS_BUILD_JAVA=ON` to build jar package in out/<OS>/Release folder |
| 51 | | |
| 52 | ## Android package | |
fb2a8c28Wenbing Li2 years ago | 53 | |
0647ce6dWenbing Li3 years ago | 54 | - pre-requisites: [Android Studio](https://developer.android.com/studio) |
| 55 | | |
63fe165eEdward Chen3 years ago | 56 | Use `./tools/android/build_aar.py` to build an Android AAR package. |
0647ce6dWenbing Li3 years ago | 57 | |
| 58 | ## iOS package | |
fb2a8c28Wenbing Li2 years ago | 59 | |
63fe165eEdward Chen3 years ago | 60 | Use `./tools/ios/build_xcframework.py` to build an iOS xcframework package. |
0647ce6dWenbing Li3 years ago | 61 | |
5fd6bcf4Sayan Shaw2 years ago | 62 | ## NuGet package |
| 63 | | |
972cb17aWenbing Li2 years ago | 64 | In order to build a local NuGet package for testing, run `nuget.exe pack ./nuget/WinOnlyNuget.nuspec` to build a NuGet package for Windows. |
fb2a8c28Wenbing Li2 years ago | 65 | |
972cb17aWenbing Li2 years ago | 66 | Note: you might need to update the src paths in the ./nuget/WinOnlyNuget.nuspec file if the appropriate ortextensions.dll files do not exist/are not in the given location. |
5fd6bcf4Sayan Shaw2 years ago | 67 | |
0647ce6dWenbing Li3 years ago | 68 | ## Web-Assembly |
fb2a8c28Wenbing Li2 years ago | 69 | |
972cb17aWenbing Li2 years ago | 70 | ONNXRuntime-Extensions will be built as a static library and linked with ONNXRuntime due to the lack of a good dynamic linking mechanism in WASM. Here are two additional arguments [–-use_extensions and --extensions_overridden_path](https://github.com/microsoft/onnxruntime/blob/860ba8820b72d13a61f0d08b915cd433b738ffdc/tools/ci_build/build.py#L416) on building onnxruntime to include ONNXRuntime-Extensions footprint in the ONNXRuntime package. |
0647ce6dWenbing Li3 years ago | 71 | |
a6012b38Wenbing Li3 years ago | 72 | ## The C++ shared library |
b5dce955Wenbing Li3 years ago | 73 | |
fb2a8c28Wenbing Li2 years ago | 74 | For any alternative scenarios, execute the following commands: |
| 75 | | |
| 76 | - On Windows: Run `build.bat`. | |
| 77 | - On Unix-based systems: Execute `bash ./build.sh`. | |
| 78 | | |
972cb17aWenbing Li2 years ago | 79 | The generated DLL or library is typically located in the `out/<OS>/<FLAVOR>` directory. To validate the build, utilize the unit tests available in the `test/test_static_test` and `test/shared_test` directories. |
a6012b38Wenbing Li3 years ago | 80 | |
5d558bd3Wenbing Li2 years ago | 81 | **CUDA Build** |
| 82 | The cuda build can be enabled with -DOCOS_USE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=<arch> | |
| 83 | | |
a6012b38Wenbing Li3 years ago | 84 | **VC Runtime static linkage** |
972cb17aWenbing Li2 years ago | 85 | If you want to build the binary with VC Runtime static linkage, please add a parameter _-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>"_ when running build.bat |
a6012b38Wenbing Li3 years ago | 86 | |
b5dce955Wenbing Li3 years ago | 87 | ## Copyright guidance |
fb2a8c28Wenbing Li2 years ago | 88 | |
972cb17aWenbing Li2 years ago | 89 | Check this link [here](https://docs.opensource.microsoft.com/releasing/general-guidance/copyright-headers/) for source file copyright header. |