Skip to content

Commit

Permalink
OpenVino docker file changes to bypass privileged mode
Browse files Browse the repository at this point in the history
Description: Builds and installs libusb without UDEV support, which is used for communicating with the VPU device.

Motivation and Context

This enables the resulting docker container to be run without '--privileged' and '--network host' options which may not be suitable in deployment environments.
  • Loading branch information
smkarlap authored Jan 22, 2021
1 parent bba185a commit 4442d94
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 17 deletions.
33 changes: 28 additions & 5 deletions dockerfiles/Dockerfile.openvino
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,27 @@ ENV LD_LIBRARY_PATH=${INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/exte
ENV LANG en_US.UTF-8
ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && \
apt -y install apt-transport-https ca-certificates python3 python3-pip zip x11-apps lsb-core wget cpio sudo libboost-python-dev libpng-dev zlib1g-dev git libnuma1 ocl-icd-libopencl1 clinfo libboost-filesystem1.65-dev libboost-thread1.65-dev protobuf-compiler libprotoc-dev autoconf automake libtool libjson-c-dev unattended-upgrades && \


RUN apt update && apt -y install --no-install-recommends apt-transport-https ca-certificates gnupg python3 python3-pip udev unzip zip x11-apps lsb-core wget curl cpio sudo libboost-python-dev libpng-dev zlib1g-dev git libnuma1 ocl-icd-libopencl1 clinfo libboost-filesystem1.65-dev libboost-thread1.65-dev protobuf-compiler libprotoc-dev autoconf automake libtool libjson-c-dev unattended-upgrades && \
unattended-upgrade && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/lib/apt/lists/* && \
cd /opt && \
# libusb1.0.22
curl -L https://github.com/libusb/libusb/archive/v1.0.22.zip --output v1.0.22.zip && \
unzip v1.0.22.zip && \
cd /opt/libusb-1.0.22 && \
# bootstrap steps
./bootstrap.sh && \
./configure --disable-udev --enable-shared && \
make -j4 && \
cd /opt/libusb-1.0.22/libusb && \
# configure libusb1.0.22
/bin/mkdir -p '/usr/local/lib' && \
/bin/bash ../libtool --mode=install /usr/bin/install -c libusb-1.0.la '/usr/local/lib' && \
/bin/mkdir -p '/usr/local/include/libusb-1.0' && \
/usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0' && \
/bin/mkdir -p '/usr/local/lib/pkgconfig' && \
# Install OpenVINO
cd ${MY_ROOT} && \
wget https://apt.repos.intel.com/openvino/2021/GPG-PUB-KEY-INTEL-OPENVINO-2021 && \
Expand All @@ -39,7 +56,11 @@ RUN apt update && \
apt update && \
apt -y install intel-openvino-dev-ubuntu18-2021.2.200 && \
cd ${INTEL_OPENVINO_DIR}/install_dependencies && ./install_openvino_dependencies.sh && \
cd ${INTEL_OPENVINO_DIR} && rm -rf documentation data_processing && cd deployment_tools/ && rm -rf model_optimizer tools open_model_zoo demo && cd inference_engine && rm -rf samples && \
cd ${INTEL_OPENVINO_DIR} && rm -rf documentation data_processing && cd deployment_tools/ && rm -rf model_optimizer tools open_model_zoo demo && cd inference_engine && rm -rf samples && \
cd /opt/libusb-1.0.22/ && \
/usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig' && \
cp /opt/intel/openvino_2021/deployment_tools/inference_engine/external/97-myriad-usbboot.rules /etc/udev/rules.d/ && \
ldconfig && \
# Install GPU runtime and drivers
cd ${MY_ROOT} && \
mkdir /tmp/opencl && \
Expand All @@ -65,4 +86,6 @@ RUN apt update && \
cd onnxruntime/cmake/external/onnx && python3 setup.py install && \
cd ${MY_ROOT}/onnxruntime && ./build.sh --config Release --update --build --parallel --use_openvino ${DEVICE} --build_wheel && \
pip install build/Linux/Release/dist/*-linux_x86_64.whl && \
cd ${MY_ROOT}/ && rm -rf onnxruntime
cd ${MY_ROOT}/ && rm -rf onnxruntime && cd /opt && rm -rf v1.0.22.zip && cd ${MY_ROOT} &&\
apt remove -y cmake && cd /usr/share/python-wheels/ && rm -rf *.whl &&\
cd /usr/lib/ && rm -rf python2.7 python3.6 python3.8 && cd && rm -rf .cache
36 changes: 30 additions & 6 deletions dockerfiles/Dockerfile.openvino-csharp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,25 @@ ENV LANG en_US.UTF-8
ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && \
apt -y install apt-transport-https ca-certificates python3 python3-pip curl zip x11-apps lsb-core wget cpio sudo libboost-python-dev libpng-dev zlib1g-dev git libnuma1 ocl-icd-libopencl1 clinfo libboost-filesystem1.65-dev libboost-thread1.65-dev protobuf-compiler libprotoc-dev autoconf automake libtool libjson-c-dev unattended-upgrades && \
apt -y install --no-install-recommends apt-transport-https ca-certificates python3 python3-pip gnupg udev zip unzip x11-apps lsb-core wget curl cpio sudo libboost-python-dev libpng-dev zlib1g-dev git libnuma1 ocl-icd-libopencl1 clinfo libboost-filesystem1.65-dev libboost-thread1.65-dev protobuf-compiler libprotoc-dev autoconf automake libtool libjson-c-dev unattended-upgrades && \
unattended-upgrade && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/lib/apt/lists/* && \
# libusb from source
cd /opt && \
curl -L https://github.com/libusb/libusb/archive/v1.0.22.zip --output v1.0.22.zip && \
unzip v1.0.22.zip && \
cd /opt/libusb-1.0.22 && \
# bootstrap steps
./bootstrap.sh && \
./configure --disable-udev --enable-shared && \
make -j4 && \
cd /opt/libusb-1.0.22/libusb && \
# configure libusb1.0.22
/bin/mkdir -p '/usr/local/lib' && \
/bin/bash ../libtool --mode=install /usr/bin/install -c libusb-1.0.la '/usr/local/lib' && \
/bin/mkdir -p '/usr/local/include/libusb-1.0' && \
/usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0' && \
/bin/mkdir -p '/usr/local/lib/pkgconfig' && \
# Install OpenVINO
cd ${MY_ROOT} && \
wget https://apt.repos.intel.com/openvino/2021/GPG-PUB-KEY-INTEL-OPENVINO-2021 && \
Expand All @@ -39,7 +55,13 @@ RUN apt update && \
apt update && \
apt -y install intel-openvino-dev-ubuntu18-2021.2.200 && \
cd ${INTEL_OPENVINO_DIR}/install_dependencies && ./install_openvino_dependencies.sh && \
cd ${INTEL_OPENVINO_DIR} && rm -rf documentation data_processing && cd deployment_tools/ && rm -rf model_optimizer tools open_model_zoo demo && cd inference_engine && rm -rf samples && \
cd ${INTEL_OPENVINO_DIR} && rm -rf documentation data_processing && \
cd deployment_tools/ && rm -rf model_optimizer open_model_zoo demo tools && \
cd inference_engine && rm -rf samples && \
cd /opt/libusb-1.0.22/ && \
/usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig' && \
cp /opt/intel/openvino_2021/deployment_tools/inference_engine/external/97-myriad-usbboot.rules /etc/udev/rules.d/ && \
ldconfig && \
# Install GPU runtime and drivers
cd ${MY_ROOT} && \
mkdir /tmp/opencl && \
Expand Down Expand Up @@ -85,6 +107,8 @@ RUN apt update && \
# Clean-up unnecessary files
rm -rf ${MY_ROOT}/cmake* /opt/cmake ${MY_ROOT}/onnxruntime && \
rm -rf /opt/miniconda && \
rm -rf /opt/intel/openvino/data_processing && \
rm -rf /opt/intel/openvino/deployment_tools/tools && \
apt remove -y git && apt autoremove -y
rm -rf /opt/v1.0.22.zip && \
apt remove -y git && apt autoremove -y && apt remove -y cmake && \
cd /usr/lib/ && rm -rf python2.7 python3.6 python3.8 && cd && rm -rf .cache && \
cd /usr/share/python-wheels/ && rm -rf *.whl

12 changes: 6 additions & 6 deletions dockerfiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,34 +133,34 @@ If the *device_type* runtime config option is not explicitly specified, CPU will
1. Build the docker image from the DockerFile in this repository.
```
docker build --rm -t onnxruntime-cpu --build-arg DEVICE=CPU_FP32 --network host -f <Dockerfile> .
docker build --rm -t onnxruntime-cpu --build-arg DEVICE=CPU_FP32 -f <Dockerfile> .
```
2. Run the docker image
```
docker run -it onnxruntime-cpu
docker run -it --rm --device-cgroup-rule='c 189:* rmw' -v /dev/bus/usb:/dev/bus/usb onnxruntime-cpu:latest
```
### OpenVINO on GPU
1. Build the docker image from the DockerFile in this repository.
```
docker build --rm -t onnxruntime-gpu --build-arg DEVICE=GPU_FP32 --network host -f <Dockerfile> .
docker build --rm -t onnxruntime-gpu --build-arg DEVICE=GPU_FP32 -f <Dockerfile> .
```
2. Run the docker image
```
docker run -it --device /dev/dri:/dev/dri onnxruntime-gpu:latest
docker run -it --rm --device-cgroup-rule='c 189:* rmw' -v /dev/bus/usb:/dev/bus/usb onnxruntime-gpu:latest
```
### OpenVINO on Myriad VPU Accelerator
1. Build the docker image from the DockerFile in this repository.
```
docker build --rm -t onnxruntime-myriad --build-arg DEVICE=MYRIAD_FP16 --network host -f <Dockerfile> .
docker build --rm -t onnxruntime-myriad --build-arg DEVICE=MYRIAD_FP16 -f <Dockerfile> .
```
2. Install the Myriad rules drivers on the host machine according to the reference in [here](https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_linux.html#additional-NCS-steps)
3. Run the docker image by mounting the device drivers
```
docker run -it --network host --privileged -v /dev:/dev onnxruntime-myriad:latest
docker run -it --rm --device-cgroup-rule='c 189:* rmw' -v /dev/bus/usb:/dev/bus/usb onnxruntime-myriad:latest
```
Expand Down

0 comments on commit 4442d94

Please sign in to comment.