In recent years, the on-device deep learning applications are getting more and
more popular on mobile phones or IoT devices. It's a challenging task for the developers to deploy their
deep learning models in their mobile applications or IoT devices.
They need to optionally choose a cost-effective hardware solution (i.e. chips and boards),
then a proper inference framework, optionally utilizing quantization or compression
techniques regarding the precision-performance trade-off, and finally
run the model on one or more of heterogeneous computing devices. How to make an
appropriate decision among these choices is a tedious and time-consuming task.
Mobile AI Benchmark (i.e. MobileAIBench) is an end-to-end benchmark tool
which covers different chips and inference frameworks, with results
include both speed and model accuracy, which will give insights for developers.
Daily Benchmark Results
Please check benchmark step in daily CI pipeline page, due to the lack of test devices, the CI result may not cover all hardwares and frameworks.
FAQ
Q: Why are benchmark results not stable on my device?
A: Due to power save considerations, some SoCs have aggressive and advanced
power control scheduling to reduce power consumption which make performance
quite unstable (especially CPU). Benchmark results highly depend on
states of devices, e.g., running processes, temperature, power control policy.
It is recommended to disable power control policy (as shown in tools/power.sh) if possible (e.g., rooted phone).
Otherwise, keep your device at idle state with low temperature, and benchmark one model on one framework each time.
Q: Why do some devices run faster (or slower) than expected in the CI benchmark result?
A: Some devices is rooted and has some specialized performance tuning while some
others is not rooted and failed to make such tuning (see the code for more details).
Q: Why is ncnn initialization time much less than others?
A: ncnn benchmark uses fake model parameters and skips loading weights from filesystem.
Q: Does benchmark use all available cores of devices?
A: Most modern Android phones use ARM big.LITTLE architecture which can lead to significant variance between different runs of the benchmark, we use only available big cores to reduce this variance by taskset command for MACE/NCNN/TFLITE benchmark.
Moreover, there are no well-defined APIs for SNPE to bind to big cores and set thread count.
Thread count can be set by adding --num_threads to tools/benchmark.sh command.
Environment requirement
MobileAIBench supports several deep learning frameworks (called executor in this project, i.e., MACE, SNPE, ncnn, TensorFlow Lite and HIAI) currently, which may require the following dependencies:
Note 1:SNPE
has strict license that disallows redistribution, so the default link in the
Bazel WORKSPACE file is only accessible by the CI server. To benchmark SNPE
in your local system (i.e. set --executors with all or SNPE explicitly),
you need to download the SDK here,
uncompress it, copy libgnustl_shared.so
and modify WORKSPACE as the following:
Note 2:HIAI
has strict license that disallows redistribution, so the default link in the
Bazel WORKSPACE file is only accessible by the CI server. To benchmark HIAI
in your local system (i.e. set --executors with all or HIAI explicitly),
you need to login and download the SDK here,
uncompress it and get the HiAI_DDK_100.200.010.011.zip file, uncompress it
and modify WORKSPACE as the following:
The whole benchmark may take a few time, and continuous benchmarking may heat
the device very quickly, so you may set the following arguments according to your
interests. Only MACE supports precision benchmark right now.
option
type
default
explanation
--benchmark_option
str
Performance
Benchmark options, Performance/Precision.
--output_dir
str
output
Benchmark output directory.
--executors
str
all
Executors(MACE/SNPE/NCNN/TFLITE/HIAI), comma separated list or all.
--device_types
str
all
DeviceTypes(CPU/GPU/DSP/NPU), comma separated list or all.
Model names(InceptionV3,MobileNetV1...), comma separated list or all.
--run_interval
int
10
Run interval between benchmarks, seconds.
--num_threads
int
4
The number of threads.
--input_dir
str
""
Input data directory for precision benchmark.
Configure ssh devices
For embedded ARM-Linux devices whose abi is aarch64 or armhf, ssh connection is supported.
Configure ssh devices in generic-mobile-devices/devices_for_ai_bench.yml, for example:
devices:
nanopi:
target_abis: [aarch64, armhf]target_socs: RK3333models: Nanopi M4address: 10.231.46.118username: pi
Adding a model to run on existing executor
Add the new model name in aibench/proto/base.proto if not in there.
Configure the model info in aibench/proto/model.meta.
Configure the benchmark info in aibench/proto/benchmark.meta.
Open the corresponding link in a browser to see the report.
Adding a new AI executor
Define executor and implement the interfaces:
classYourExecutor : publicBaseExecutor {
public:YourExecutor() :
BaseExecutor(executor_type, device_type, model_file, weight_file) {}
// Init method should invoke the initializing process for your executor // (e.g. Mace needs to compile OpenCL kernel once per target). It will be// called only once when creating executor engine.virtual Status Init(int num_threads);
// Load model and prepare to run. It will be called only once before // benchmarking the model.virtual Status Prepare();
// Run the model. It will be called more than once.virtual Status Run(const std::map<std::string, BaseTensor> &inputs,
std::map<std::string, BaseTensor> *outputs);
// Unload model and free the memory after benchmarking. It will be called// only once.virtualvoidFinish();
};
Include your executor header in aibench/benchmark/benchmark_main.cc:
Add dependencies to third_party/your_executor, aibench/benchmark/BUILD and WORKSPACE.
Put macro AIBENCH_ENABLE_YOUR_EXECUTOR into aibench/benchmark/BUILD at model_benchmark target.
Benchmark a model on existing executor
Refer to [Adding a model to run on existing executor](#Adding a model to run on existing executor).
请发表评论