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:
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
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
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
Method 3 (Recommended): User Application Snap based on OpenVINO Debian Packages#
OpenVINO toolkit is also distributed via the APT repository, which can be used in the snaps. Third-party apt repositories can be added to the snap’s snapcraft.yaml (see the snapcraft guide).
Download the GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB:
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
To determine a key-id from a given key file with gpg, type the following:
gpg --show-keys ./GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB pub rsa2048 2019-07-26 [SC] [expired: 2023-07-26] E1BA4ECEFB0656C61BF9794936B9569B3F1A1BC7 uid KEY-PIDT-PGP-20190726 pub rsa2048 2020-05-18 [SC] [expires: 2024-05-18] 6113D31362A0D280FC025AAB640736427872A220 uid CN=Intel(R) Software Development Products (PREPROD USE ONLY) pub rsa2048 2023-08-21 [SC] [expires: 2027-08-21] E9BF0AFC46D6E8B7DA5882F1BAC6F0C353D04109 uid CN=Intel(R) Software Development Products
Export GPG key to asc file:
gpg --armor --export E9BF0AFC46D6E8B7DA5882F1BAC6F0C353D04109./GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB > 53D04109.acs
where the name of the .asc file is the last 8 symbols
Save this key in
<project>/snap/keys/folder
. Snapcraft will install the corresponding key.Then, the OpenVINO apt repositoriy can be added to the snap’s snapcraft.yaml by using the top-level package repositories keyword with a deb-type repository:
package-repositories: - type: apt components: [main] suites: [ubuntu20] key-id: E9BF0AFC46D6E8B7DA5882F1BAC6F0C353D04109 url: https://apt.repos.intel.com/openvino/2024
Add OpenVINO dep packages to build-packages and stage-packages dependencies:
parts: app-build: build-packages: - openvino-libraries-dev stage-packages: - openvino-libraries-2024.1.0
Build User Application