[ARM] Accelerate computing on Android
一系列学习笔记总结,对当前发展趋势做一次调研。
一、优化策略
From: 代码Android端加速
1. OpenCL优化(GPU)
编译成功后,在android端优化却不是非常明显,这个问题我们还在找。
- 判断手机是否支持OpenCL
- Google可能不太喜欢OpenCL,需要自己配置。
More details: Android OpenCL测试程序,使用dlopen动态加载libOpenCL.so库
2. NEON指令集优化(并行)
NEON指令集加速,是目前android端推荐最多的方式,基本的介绍可以百度,有很多文章。
这个优化有两种:
(1)直接使用NEON指令集封装好的C指令,网上有很多介绍,操作方法也是类C风格,比较容易上手。
(2)对寄存器写汇编进行优化。
第一种方法上手快,效果也比较明显;
第二种写起来会比较费劲,但加速效果会非常恐怖(前提是要对汇编指令足够熟悉)。 而这两种方法对于使用opencv的函数却没法优化。
二、NDK引入NEON
Ref: ARM和NEON指令
Ref: Optimizing C Code with Neon Intrinsics
Ref: A Software Library for Computer Vision and Machine Learning
-
配置为NEON模式编译
Build for Android: https://arm-software.github.io/ComputeLibrary/v19.11.1/index.xhtml#S3_3_android
-
集成进工程
相关问题:how to build for android #300
Did you manage to use ACL in your project?
There shouldn't be anything different from other libraries (Except that you might need to link against OpenCL if you're using it, in which case it will not work on Android O and after).
It means that because of some added security now applications can only link against system libraries that have been explicitly whitelisted by the manufacturer.
Therefore, even if OpenCL is available on your platform, you're unlikely to be able to use it in an App
相关问题:How to use the Binaries release (android version) ? #434
直接下载Binary版本。
.
├── android-arm64-v8a-cl
├── android-arm64-v8a-cl-asserts
├── android-arm64-v8a-cl-debug
├── android-arm64-v8a-neon
│ ├── libarm_compute_core.so
│ ├── libarm_compute_core-static.a
│ ├── libarm_compute_graph.so
│ ├── libarm_compute_graph-static.a
│ ├── libarm_compute.so
│ └── libarm_compute-static.a
├── android-arm64-v8a-neon-asserts
├── android-arm64-v8a-neon-cl
├── android-arm64-v8a-neon-cl-asserts
├── android-arm64-v8a-neon-cl-debug
├── android-arm64-v8a-neon-debug
├── android-armv7a-cl
├── android-armv7a-cl-asserts
├── android-armv7a-cl-debug
├── android-armv7a-neon
├── android-armv7a-neon-asserts
├── android-armv7a-neon-cl
├── android-armv7a-neon-cl-asserts
├── android-armv7a-neon-cl-debug
└── android-armv7a-neon-debug
Ref: Arm NN 软件开发套件
libarm_compute.so, libarm_compute_core.so, libarm_compute_graph.so
集成到 Android 项目中。
In order to use the compute library on Android there are few steps to follow to make everything working. Before starting to present the necessary steps, I would suggest to use the static libs of arm compute library (i.e. libarm_compute-static.a) rather than the dynamic ones and to use the arm compute library only with NEON acceleration as there are extra steps to follow for OpenCL. Following I reported few necessary steps for using the arm compute library on Android. Hope this can help you.
Step1: Add pre-built library for arm compute library in CMakeLists.txt along with the include directory You could have something like this: // Add includes for arm_compute include_directories(${PATH_ARM_COMPUTE}/include) // Add prebuilt library for arm_compute add_library( lib_arm_compute STATIC IMPORTED ) set_target_properties(lib_arm_compute PROPERTIES IMPORTED_LOCATION ${PATH_ARM_COMPUTE}/libs/${ANDROID_ABI}/libarm_compute-static.a) ... target_link_libraries( native-lib lib_arm_compute ${log-lib} ) where PATH_ARM_COMPUTE is the path to your arm_compute folder
Step2: Add necessary includes in your .cpp file located in the JNI folder #include "arm_compute/runtime/NEON/NEFunctions.h" #include "arm_compute/runtime/CPP/CPPScheduler.h"
Step3: Write your example in Java_com_chenleiblogs_mlopencl_ml_1opencl_MainActivity_stringFromJNI( function In the arm compute library we have few examples which could be used (examples/ folder). Have a look at for instance to neon_convolution example. This should be a good example to integrate in your app.
/* implement */
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律