How to compile and run Intel OpenVINO natively on Apple M1!

Raymond Lo, PhD
Mac O’Clock
Published in
3 min readDec 18, 2020

--

It’s not easy but it’s possible thanks to open source!

Ok! This is a rather controversial topic… And open source somehow bridged the ultimate gaps that I never saw would happen.

I’m going to go directly into the core of this. If you would like to get deeper into the OpenVINO source code, go here.

Now first, this is a native build and thus any x86–64 instructions should not be supported. Second, this build is focusing on getting it functional rather than doing a comparison on performance.

Prepare your build environment

You would need to first install Home Brew. It’s recommended that you install it on /opt directory.

cd /opt
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

After the installation, you need to add the HomeBrew path variable to /etc/paths.

Then, with HomeBrew, you can now install cmake, automaker, wget and a few core libraries to compile the code. Here is a list of tools I have to install before the next step.

#installation order matters. Do NOT change these.
brew install cmake
brew install automake
brew install --build-from-source libtool
brew install --build-from-source libunistring
brew install --build-from-source libidn2
brew install --build-from-source wget
brew install --build-from-source libusb

Build the Intel OpenVINO Toolkit from source

Now we get the source from OpenVINO’s Official GitHub Repository.

git clone https://github.com/openvinotoolkit/openvino.git
cd openvino
git submodule update --init --recursive

After everything checkout, we run the build script.

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DENABLE_SSE42=OFF \
-DTHREADING=SEQ \
-DENABLE_GNA=OFF .. && make -j 9

And 10 minutes later…

It’s completed! OpenVINO is fully compiled in the arm64 — Apple M1!

I got a complete code running OpenVINO on Apple M1!

And it recognized the Intel Neural Compute Stick 2!

Run an Object Detection Sample

Lastly, let’s test and make sure the system is working properly. First I go to the sample directory. Then, I use wget to download the pre-trained models.

cd openvino/bin/arm64/Releasewget https://download.01.org/opencv/2020/openvinotoolkit/2020.3/open_model_zoo/models_bin/1/person-vehicle-bike-detection-crossroad-0078/FP16/person-vehicle-bike-detection-crossroad-0078.binwget https://download.01.org/opencv/2020/openvinotoolkit/2020.3/open_model_zoo/models_bin/1/person-vehicle-bike-detection-crossroad-0078/FP16/person-vehicle-bike-detection-crossroad-0078.xml

Lastly, find your favorite BMP file (must be 24-bit color). Make sure you resize it to 1024x1024 — 24 bits color. And then run this command.

./object_detection_sample_ssd -i walk.bmp -m person-vehicle-bike-detection-crossroad-0078.xml async -d MYRIAD
Then magic!
The output from the algorithm which detects human from the scene. Images are resized to 1024x1024 and converted to 24bits.

Everything is working as expected! Omg. Open Source is the ultimate winner this time.

What’s next?

My next step is to compile the OpenVINO source again with Rosetta 2 under x86–64. Indeed, I have tried “copy and paste” the x86–64 pre-compiled code over and I was able to run the inference engine properly with Rosetta 2 (see the video attached below). This is exciting as the open-sourced OpenVINO can really run on everywhere!

I encountered lots of issues with compiling the code with Rosetta 2 due to the conflicts between arm64 vs x86–64 libraries. But the binary definitely works.

References:

Please check out the latest OpenVINO Toolkit here!

And here are the related steps I used to compile on arm64.

#iamintel

--

--

Raymond Lo, PhD
Mac O’Clock

@Intel - OpenVINO AI Software Evangelist. ex-Google, ex-Samsung, and ex-Meta (Augmented Reality) executive. Ph.D. in Computer Engineer — U of T.