描述
Why?
Building anything on mobile is challenging, because of the many tricks that one will need to do to make optimized builds. This task aims to be a master tracking point if you encounter mobile build and performance issues.
As you might have expected, at Facebook we use buck to build our code. We know that such build system is not ideal for the open source world. As a result, we worked hard to standardize on CMake as the blessed open source build tool for all platforms (thanks @slayton58 for the suffering!). We tried really hard to make sure that all platforms build correctly, but we are asking you to help us verifying the correctness. Here are a few build and execution check points.
Always Check if you have built things with NEON
You should have -mfpu=neon -mfloat-abi=[softfp|hardfp] in your build tools all the time. If things are slow, definitely double check this.
Check if you have built and used NNPACK
Check if your cmake has USE_NNPACK on in the summary print. If not, you might want to figure out the NNPACK build. The nnpack build cmake script is located here: https://github.com/caffe2/caffe2/blob/master/cmake/External/nnpack.cmake .
For operators such as convolution, you should then set engine to "NNPACK" in your protobuf - we use this on mobile to achieve good performance on CNNs.
For binary size controls, use a whitelist of source files
Due to the modular nature of the library, if you are just running specific models (such as CNNs), you don't need the full set of the source files, especially those under operators. In facebook we explicitly whitelist the files that we build for mobile. On OSS, we added a cmake option CAFFE2_WHITELIST to mirror such mechanism. We haven't tested it extensively on the OSS side, so if you'd like to give it a try and write down your steps for others, that would be really great!
android-cmake and ios-cmake
We use these two cmake plugins to build android and ios librarys. For android, the binaries can be directly used by adb shell. To build your libraries, you should make sure to include all the .a files, and also use whole static library linking.
An example android app build
Check out https://github.com/bwasti/AICamera