Compilation

1. 拉取源代码

git clone https://github.com/nndeploy/nndeploy.git
git submodule update --init --recursive

2. 编译宏介绍

  • Refer to the detailed introduction of compilation macro documentation

Includes the following types of configurations:

  1. Basic build options (recommended to use default configurations): such as whether to build as a shared library, the C++ standard used, etc.

  2. Core module options (recommended to use default configurations): controls the enabling of core functionalities such as base modules, thread pools, device modules, etc.

  3. Device backend options (enable as needed, default all closed, does not depend on any device backend): such as CUDA, OpenCL, various NPU hardware acceleration supports

  4. Operator backend options (enable as needed, default all closed, does not depend on any operator backend): such as cudnn

  5. Inference backend options (enable as needed, default all closed, does not depend on any inference backend): such as TensorRT, OpenVINO, ONNX Runtime inference framework support

  6. Algorithm plugin options (recommended to use default configurations, traditional CV algorithms are enabled by default, language and biomedical image algorithms are closed by default): such as detection, segmentation, llm, biomedical image algorithm plugins

    • Among them, traditional CV algorithms depend on OpenCV, such as detection, segmentation, classification, etc., need to enable ENABLE_NNDEPLOY_OPENCV

    • Among them, language and biomedical image models depend on C++ tokenizer tokenizer-cpp, so need to enable ENABLE_NNDEPLOY_PLUGIN_TOKENIZER_CPP, before enabling refer to precompile_tokenizer_cpp.md

3. 编译方法

config.cmake is the compilation configuration file of nndeploy, used to control the project’s compilation options.

Compared to native cmake -D options, user-configured compilation option files can be saved for multiple uses, and comments can be added to the file for easy future maintenance.

Compared to compilation scripts, there is no need to write multiple types of scripts for each platform, nor will script environment issues be encountered. Just create a build directory in the root directory, copy config.cmake to this directory, then modify the config.cmake file, and compilation can begin.

Assuming you are in the root directory, the specific command line is as follows:

mkdir build                 # 创建build目录
cp cmake/config.cmake build # 将编译配置模板复制到build目录
cd build                    # 进入build目录
vim config.cmake            # 使用编辑器vscode等工具直接修改config.cmake文件
cmake ..                    # 生成构建文件
make -j                     # 使用8个线程并行编译

4. 主库编译

  • Default compilation product is: libnndeploy_framework.so

  • Algorithm plugin compilation product is: libnndeploy_plugin_xxx.so

  • Executable program compilation product is: nndeploy_demo_xxx

Note: xxx represents specific algorithm plugins and specific executable programs, for example: nndeploy_plugin_detect.so, nndeploy_demo_detect, nndeploy_demo_dag

5. Windows

  • Environment requirements

    • cmake >= 3.12

    • Microsoft Visual Studio >= 2017

  • Third-party libraries provided by nndeploy

第三方库 主版本 Windows下载链接 备注
opencv 4.8.0 下载链接
OpenVINO 2023.0.1 下载链接
ONNXRuntime v1.15.1 下载链接
MNN 2.6.2 下载链接
TNN v0.3.0 下载链接
ncnn v0.3.0 下载链接

Note: Package all the above libraries into a compressed file windows_x64.7z, stored on huggingface, please decompress the windows_x64.7z before use

  • Specific steps

    • Create a build directory in the root directory, copy cmake/config.cmake to this directory

      mkdir build
      cp cmake/config.cmake build
      cd build
      
    • Start cmake

      cmake ..
      
    • Open build/nndeploy.sln through visual studio, start compilation, installation, execution

6. Linux

  • Environment requirements

    • cmake >= 3.12

    • gcc >= 5.1

  • Third-party libraries provided by nndeploy

第三方库 主版本 Linux下载链接 备注
OpenVINO 2023.0.1 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/ubuntu22.04_x64.tar
ONNXRuntime v1.15.1 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/ubuntu22.04_x64.tar
MNN 2.6.2 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/ubuntu22.04_x64.tar
TNN v0.3.0 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/ubuntu22.04_x64.tar
ncnn v0.3.0 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/ubuntu22.04_x64.tar

Note: Package all the above libraries into a compressed file ubuntu22.04_x64.tar, stored on huggingface, please decompress the ubuntu22.04_x64.tar before use

  • Install opencv

    • sudo apt install libopencv-dev reference link

  • Install TensorRT cpp sdk reference link, cudnn, cuda, GPU driver

  • Specific steps

    • Create a build directory in the root directory, copy cmake/config.cmake to this directory

      mkdir build
      cp cmake/config.cmake build
      cd build
      
    • cmake

      cmake ..
      
    • Compilation

      make -j
      
    • Install, place nndeploy’s libraries, executable files, third-party libraries into build/install/lib

      make install
      

7. Android

  • Environment requirements

    • cmake >= 3.12

    • ndk

  • Third-party libraries provided by nndeploy

第三方库 主版本 Android下载链接 备注
opencv 4.8.0 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/android.tar
MNN 2.6.2 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/android.tar
TNN v0.3.0 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/android.tar
ncnn v0.3.0 wget https://huggingface.co/alwaysssss/nndeploy/blob/main/third_party/android.tar

Note: Package all the above libraries into a compressed file android.tar, stored on huggingface, please decompress the android.tar before use

  • Specific steps

    • Create a build directory in the root directory, copy cmake/config.cmake to this directory

      mkdir build
      cp cmake/config.cmake build
      cd build
      
    • Start cmake, need to specify ndk

      cmake .. -DCMAKE_TOOLCHAIN_FILE=/snap/android-ndk-r25c/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_STL=c++_static -DANDROID_NATIVE_API_LEVEL=android-14 -DANDROID_TOOLCHAIN=clang -DBUILD_FOR_ANDROID_COMMAND=true
      
    • Start compilation

      make -j8
      
    • Start installation, place nndeploy related libraries executable files, third-party libraries into build/install/lib

      make install
      

8. Mac(TODO)

  • Environment requirements

    • cmake >= 3.12

    • xcode

9. iOS(TODO)

  • Environment requirements

    • cmake >= 3.12

    • xcode

10. Linux + 华为昇腾

  • Environment requirements

    • cmake >= 3.12

    • gcc >= 5.1

  • Third-party libraries

    • Install opencv

      • sudo apt install libopencv-dev reference link

    • Install AscendCL sdk ascend_env.md

  • Specific steps

    • Create a build directory in the root directory, copy cmake/config.cmake to this directory

      mkdir build
      cp cmake/config.cmake build
      cd build
      
    • cmake

      cmake ..
      
    • Compilation

      make -j
      
    • Install, place nndeploy’s libraries, executable files, third-party libraries into build/install/lib

      make install
      

11. 第三方库官方编译文档以及下载链接

第三方库 主版本 编译文档 官方库下载链接 备注
opencv 4.8.0 链接 链接
TensorRT 8.6.0.12 链接 链接 支持jetson-orin-nano
OpenVINO 2023.0.1 链接 链接
ONNXRuntime v1.15.1 链接 链接
MNN 2.6.2 链接 链接
TNN v0.3.0 链接 链接
ncnn v0.3.0 链接 链接

12. 补充说明

  • We use the above versions of third-party libraries, usually using other versions is also no problem

  • TensorRT

    • Windows link

    • Before installation, please ensure the graphics card driver, cuda, cudnn are all installed and versions are consistent

  • Under the windows platform, the system directory comes with onnxruntime, so you might link to the system directory’s onnxruntime when running, leading to runtime errors. Solution

    • Copy your own onnxruntime library to the build directory