How to compile Intel OpenVINO in x86–64 on Apple M1
|Rosetta 2 = x86–64!?
Last post I tried compiling OpenVINO on Apple M1 natively. However, running it natively had also taken away the ability to run the inference on the CPU. Now, this time I will compile it on x86–64 architecture using Rosetta 2.
If you have installed HomeBrew in arm64 previously, let’s remove it from the system.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
After that, we quit the arm64 Terminal. We will then create a new Terminal and enable “Open using Rosetta” in the option.
Then, we will start the “Intel Terminal”, and start executing everything from thereon.
In the “Intel Terminal”, we execute this command to install HomeBrew in x86–64.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then, you should be ready to start setting up your build environment.
Prepare the Build Environment
As usual, we will use the brew command to install the dependencies for the build.
brew install cmake
brew install wget
brew install opencv
brew install automake
brew install libusb
Then, we check out the source from the OpenVINO repository.
git clone https://github.com/openvinotoolkit/openvino.git
cd openvino
git submodule update --init --recursive
Now, we make the build directory in the openvino directory.
mkdir build_x86 && cd build_x86
cmake ../
make -j 9
Wait for the compiler to complete the job…And magic… It works! Yes, it works!
Then, I immediately download the pre-trained model in the last post.
cd ../bin/intel64/Release
wget 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.bin
wget 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
Also, converted my BMP file into 1024x1024@24 bits and run the command. Note: You can skip conversion because we now support OpenCV in this build. However, I kept it just for consistency.
./object_detection_sample_ssd -i walk.bmp -m person-vehicle-bike-detection-crossroad-0078.xml
Unbelievable. It just worked… and I got the results. Well done Intel OpenVINO!
Lastly, here is a quick video demo of running the Intel OpenVINO’s Inference Engine on Apple M1.
Limitations and Validations
Of course, this post did not perform a full and extensive testing of OpenVINO on Apple M1. I’m sure that there will be problems if the code specifically required various Intel instructions with deeper pipeline (see reference below). But with the open source approach, you can go into the code and see if you have utilized various instructions that were not supported and fix it on the way.
Conclusion
I will say the support from OpenVINO is pretty amazing. By taking the direction in open source and open community, I can see how we can have OpenVINO in all devices and architectures and supporting the AI community holistically.
#iamintel