diff --git a/thirdparty/MNN/HPKBUILD b/thirdparty/MNN/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..e0ad34c0e1219f36cbf2fddcc61ea6ff6b60afc5 --- /dev/null +++ b/thirdparty/MNN/HPKBUILD @@ -0,0 +1,74 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Contributor: Ding Qian <1052888395@qq.com> luozhu <1393302983@qq.com> +# Maintainer: Ding Qian <1052888395@qq.com> + +pkgname=MNN +pkgver=2.6.3 +pkgrel=0 +pkgdesc="MNN is a highly efficient and lightweight deep learning framework. It supports inference and training of deep learning models." +url="https://github.com/alibaba/MNN" +archs=("armeabi-v7a" "arm64-v8a") +license=("Apache 2.0") +depends=() +makedepends=() +source="https://github.com/alibaba/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +autounpack=true +downloadpackage=true +builddir=$pkgname-${pkgver} +packagename=$builddir.tar.gz +buildtools="cmake" + +prepare() { + mkdir -p $builddir/$ARCH-build +} + +build() { + cd $builddir + ${OHOS_SDK}/native/build-tools/cmake/bin/cmake "$@" -B$ARCH-build -DMNN_BUILD_TEST=ON -B$ARCH-build -S./ > $buildlog 2>&1 + $MAKE VERBOSE=1 -C $ARCH-build >> $buildlog 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir + $MAKE -C $ARCH-build install VERBOSE=1 >> $buildlog 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +check() { + if [ $ARCH == "armeabi-v7a" ] + then + cp ${OHOS_SDK}/native/llvm/lib/arm-linux-ohos/libc++_shared.so $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ + elif [ $ARCH == "arm64-v8a" ] + then + cp ${OHOS_SDK}/native/llvm/lib/aarch64-linux-ohos/libc++_shared.so $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ + else + echo "${ARCH} not support" + return -1. + fi + echo "The test must be on an OpenHarmony device!" + # ./run_test.out +} + +# 清理环境 +cleanbuild(){ + rm -rf ${PWD}/$builddir +} + diff --git a/thirdparty/MNN/HPKCHECK b/thirdparty/MNN/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..bf85699a0a0e396c5400b9343f15afe8572ab0e7 --- /dev/null +++ b/thirdparty/MNN/HPKCHECK @@ -0,0 +1,27 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Contributor: luozhu <1393302983@qq.com> +# Maintainer: luozhu <1393302983@qq.com> + +source HPKBUILD > /dev/null 2>&1 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +openharmonycheck() { + res=0 + cd $builddir/${ARCH}-build + ./run_test.out > ${logfile} 2>&1 + res=$? + cd $OLDPWD + return $res +} diff --git a/thirdparty/MNN/OAT.xml b/thirdparty/MNN/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..c2cd820f7f651fb29f55ae2db126d2fd44be3cc6 --- /dev/null +++ b/thirdparty/MNN/OAT.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/thirdparty/MNN/README.OpenSource b/thirdparty/MNN/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..fd1ec843d38d1aa4cd2450847284b312177c9125 --- /dev/null +++ b/thirdparty/MNN/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "MNN", + "License": "Apache 2.0", + "License File": "https://www.apache.org/licenses/LICENSE-2.0.txt", + "Version Number": "2.6.3", + "Owner": "1393302983@qq.com", + "Upstream URL": "https://github.com/alibaba/MNN/archive/refs/tags/2.6.3.tar.gz", + "Description": "MNN is a highly efficient and lightweight deep learning framework.It supports inference and training of deep learning models." + } +] diff --git a/thirdparty/MNN/README_zh.md b/thirdparty/MNN/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..534632146fd0635e2b97f4407b09053a9326bbc4 --- /dev/null +++ b/thirdparty/MNN/README_zh.md @@ -0,0 +1,11 @@ +# MNN三方库说明 +## 功能简介 +MNN是一个高效、轻量级的深度学习框架,支持深度学习模型的推理和训练 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 4.0.8.1 (API Version 10 Release) +- 三方库版本:2.6.3 +- 当前适配的功能:支持Tensorflow、Caffe和ONNX等不同的训练框架;通过算子融合、算子替代、模型压缩、布局调整等方式对图进行基本的优化操作 + +## 集成方式 ++ [应用hap包集成](docs/hap_ingtegrate.md) \ No newline at end of file diff --git a/thirdparty/MNN/SHA512SUM b/thirdparty/MNN/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..fd8f9c1fca1fdaaee282d844ffc53b1e6dbeacb0 --- /dev/null +++ b/thirdparty/MNN/SHA512SUM @@ -0,0 +1 @@ +16ccd1d018f9eb026db2845a6f06e7b16d4992f2684bd36327b0ce5889f68fbec26b92c4b249d3c0e786f19c005a647430dd9e181423c29abe0cf4004b146acb MNN-2.6.3.tar.gz diff --git a/thirdparty/MNN/docs/hap_ingtegrate.md b/thirdparty/MNN/docs/hap_ingtegrate.md new file mode 100644 index 0000000000000000000000000000000000000000..2858a134402af4a016fc403e70b1eef824caa5c4 --- /dev/null +++ b/thirdparty/MNN/docs/hap_ingtegrate.md @@ -0,0 +1,71 @@ +# MNN集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- [开发环境准备](../../../docs/hap_integrate_environment.md) + +## 编译三方库 + +- 下载本仓库 + ``` + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/thirdparty/MNN # 三方库MNN的目录结构如下 + ├── docs # 三方库相关文档的文件夹 + ├── HPKBUILD # 编译脚本 + ├── HPKCHECK # 测试脚本 + ├── OAT.xml # OAT开源审查文本 + ├── README.OpenSource # 说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md # 三方库说明文档 + ├── SHA512SUM # 三方库校验文件 + ``` + +- 在lycium目录下编译三方库 + MNN库不需要依赖其它库,所以在build时只需要编译MNN库即可 + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + ``` + cd lycium + ./build.sh MNN + ``` +- 三方库头文件及生成的库 + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + ``` + MNN/arm64-v8a MNN/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库和依赖库拷贝到该目录下,如下图所示 +   +![thirdparty_install_dir](pic/MNN_install_dir.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + ```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libMNN.so) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/MNN/${OHOS_ARCH}/include) + + ``` + +![MNN_usage](pic/MNN_usage.png) + +## 测试三方库 +三方库的测试使用自己编写的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +- 将编译生成的可执行文件及生成的动态库准备好 + +- 将准备好的文件推送到开发板,进入到构建的目录添加执行文件权限和lib库环境执行./run_test.out + ![MNN_test](pic/MNN_test.png) + +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) diff --git a/thirdparty/MNN/docs/pic/MNN_install_dir.png b/thirdparty/MNN/docs/pic/MNN_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..756b8729dc64847a886f4430c30913afca095e6b Binary files /dev/null and b/thirdparty/MNN/docs/pic/MNN_install_dir.png differ diff --git a/thirdparty/MNN/docs/pic/MNN_test.png b/thirdparty/MNN/docs/pic/MNN_test.png new file mode 100644 index 0000000000000000000000000000000000000000..608f4dc3aa8ea8f8c66c6cf139ab4390a95282e4 Binary files /dev/null and b/thirdparty/MNN/docs/pic/MNN_test.png differ diff --git a/thirdparty/MNN/docs/pic/MNN_usage.png b/thirdparty/MNN/docs/pic/MNN_usage.png new file mode 100644 index 0000000000000000000000000000000000000000..fce97800ddaed7dac37470c0a5786eea0972ed1d Binary files /dev/null and b/thirdparty/MNN/docs/pic/MNN_usage.png differ