OpenVINO Integration with Ubuntu Snap#

A snap is a way to containerize applications and embed them on Linux devices. Currently, OpenVINO supports this form of deployment for Ubuntu. Building a snap package involves several steps, including setting up your development environment, creating the necessary configuration files, and using the snapcraft tool to build the Snap. This article will show you how to integrate OpenVINO toolkit with your application snap:

Method 1: User Application Snap based on OpenVINO Sources#

OpenVINO libraries can be built using the CMake plugin (https://snapcraft.io/docs/cmake-plugin). To build and install it to the application snap image, you need to configure the new part in the application snapcraft.yaml:

openvino-build:
  plugin: cmake
  source-type: git
  source: https://github.com/openvino.git
  source-branch: master
  cmake-generator: Ninja
  cmake-parameters:
    - -DENABLE_SAMPLES:BOOL=OFF
    - -DENABLE_TESTS:BOOL=OFF
  build-environment:
    - CMAKE_BUILD_PARALLEL_LEVEL: ${SNAPCRAFT_PARALLEL_BUILD_COUNT}
    - CMAKE_BUILD_TYPE: Release
  build-packages:
    - build-essential
    - ninja-build
    - pkg-config
    - gzip

Method 2: Separate OpenVINO and User Application Snaps#

This approach means that OpenVINO libraries and user applications will be distributed as separate snaps. It involves three steps:

  1. Configure the OpenVINO snapcraft.yaml.

    Add the part to build and install OpenVINO as described in the 1st Method:

    openvino-build:
      plugin: cmake
      source-type: git
      source: https://github.com/openvino.git
      source-branch: master
      cmake-generator: Ninja
      cmake-parameters:
        - -DENABLE_SAMPLES:BOOL=OFF
        - -DENABLE_TESTS:BOOL=OFF
      build-environment:
        - CMAKE_BUILD_PARALLEL_LEVEL: ${SNAPCRAFT_PARALLEL_BUILD_COUNT}
        - CMAKE_BUILD_TYPE: Release
      build-packages:
        - build-essential
        - ninja-build
        - pkg-config
        - gzip
    

    Define the slots provided by the OpenVINO Snap. Slots are the interfaces your Snap exposes for other Snaps to connect to:

    slots:
      openvino-libs:
        interface: content
        content: openvino-libs
        read:
          - $SNAP/usr/local/li
      openvino-3rdparty-libs:
        interface: content
        content: openvino-extra-libs
        read:
          - $SNAP/usr/local/runtime/3rdparty/tbb/lib
    
  2. Configure the application’s snapcraft.yaml:

    Edit your snapcraft.yaml file to include OpenVINO plugs.

    plugs:
      openvino-libs:
        interface: content
        content: openvino-libs
        target: $SNAP/openvino-libs
        default-provider: openvino-libs-test
    
      openvino-3rdparty-libs:
        interface: content
        content: openvino-extra-libs
        target: $SNAP/openvino-extra-libs
        default-provider: openvino-libs-test
    

    Add OpenVINO snap to build-snaps:

    parts:
      app-build:
        build-snaps:
          - openvino-libs-test
    

    Set the OpenVINO environment in the build part:

    parts:
     app-build:
       build-environment:
         - OpenVINO_DIR: /snap/openvino-libs/current/usr/local/runtime/cmake
         - LD_LIBRARY_PATH: $LD_LIBRARY_PATH:/snap/openvino-libs/current/usr/local/runtime/3rdparty/tbb/lib
    

    Set the OpenVINO environment in the apps section:

    apps:
      app:
        command: usr/local/app
        environment:
          LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/openvino-libs:$SNAP/openvino-extra-libs
    
  3. Install snaps and Connect plugs. Snaps can be connected automatically only if they are published by the same user, otherwise you need to manually connect Application plugs with OpenVINO slots after installation:

    snap connect app:openvino-libs openvino-libs:openvino-libs
    snap connect app:openvino-3rdparty-libs openvino-libs:openvino-3rdparty-libs