分享到微信

打开微信,使用扫一扫进入页面后,点击右上角菜单,

点击“发送给朋友”或“分享到朋友圈”完成分享

ARM HiLinux交叉编译CNStream zhupengdong2020-06-09 20:09:26 回复 1 查看 经验交流 视频流SDK CNStream
ARM HiLinux交叉编译CNStream
分享到:

0.   新建 hilinux文件夹,后续脚本中出现相关目录路径需要结合自己实际情况修改,依赖库的安装路径要求必须是CNStream仓库根目录,如-DCMAKE_INSTALL_PREFIX=/home/cambricon/hilinux/CNStream,否则需要修改CNStream/CMakeLists.txt。

1.   下载CNStream源码至hilinux

        https://github.com/Cambricon/CNStream

2.    安装ToolChain

        2.1 解压缩工具链压缩包:aarch64-himix100-linux.tgz

        2.2 安装工具链cd aarch64-himix100-linux ;   sudo ./aarch64-himix100-linux.install

        2.3 确认工具链安装成功:/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gdb -v; 默认安装路径为/opt/hisi-linux/

3.    交叉编译安装第三方库:

       3.1 下载依赖库源码:

         GFlags:https://github.com/gflags/gflags/releases

         Glogs:   https://github.com/google/glog/releases

         FFMpeg:http://ffmpeg.org/download.html V3.4.7

         OpenCVhttps://opencv.org/releases/   V2.4.9

       3.2  编辑交叉编译工具链配置文件toolchain-hilinux.cmake,放在hilinux文件夹下

SET(CMAKE_SYSTEM_NAME Linux)
 
SET(CROSS_PREFIX /opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-)
SET(CMAKE_C_COMPILER  /opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gcc)
SET(CMAKE_CXX_COMPILER /opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-g++)
SET(CMAKE_SYSTEM_PROCESSOR aarch64) 
SET(CMAKE_FIND_ROOT_PATH  /opt/hisi-linux/x86-arm/aarch64-himix100-linux/)
 
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

3.3 交叉编译gflags

提供build_gflags_hilinux.sh 脚本参考

#!/bin/bash
# 静态编译 gflags 源码脚本
 
# $gflags_source gflags源码位置
mkdir -p /home/cambricon/hilinux/gflags-2.2.2/build
pushd /home/cambricon/hilinux/gflags-2.2.2/build
#install_path 定义安装路径
# CMAKE_TOOLCHAIN_FILE 指定上面定义的toolchain文件的位置
# REGISTER_INSTALL_PREFIX=off 不写注册表
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/cambricon/hilinux/toolchain-hilinux.cmake \
    -DCMAKE_INSTALL_PREFIX=/home/cambricon/hilinux/CNStream \
    -DBUILD_SHARED_LIBS=on \
    -DBUILD_STATIC_LIBS=off \
    -DBUILD_gflags_LIB=on \
    -DINSTALL_STATIC_LIBS=off \
    -DINSTALL_SHARED_LIBS=on \
    -DREGISTER_INSTALL_PREFIX=off
make clean
make -j 8 install
popd

3.3 交叉编译glog

提供build_glog_hilinux.sh 脚本参考

#!/bin/bash
mkdir -p /home/cambricon/hilinux/glog-0.4.0/build
pushd /home/cambricon/hilinux/glog-0.4.0/build
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/cambricon/hilinux/toolchain-hilinux.cmake \
    -DCMAKE_INSTALL_PREFIX=/home/cambricon/hilinux/CNStream  -DBUILD_SHARED_LIBS=on
make clean
make -j 8 install
popd

         3.4 交叉编译FFMpeg

         提供build_ffmpeg_hilinux.sh脚本供参考,放置在FFMpeg源码目录下

#!/bin/bash
 
./configure --prefix=/home/cambricon/hilinux/CNStream --cross-prefix=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux- --enable-cross-compile --arch=arm64 --target-os=linux  --enable-shared --disable-static --enable-gpl --enable-nonfree  --disable-debug --disable-doc --enable-gpl  --enable-pic
make clean
make -j8 install

         3.5 交叉编译OpenCV

         提供build_opencv_hilinux.sh脚本供参考,放置在OpenCV源码目录下

#!/bin/bash
mkdir -p /home/cambricon/hilinux/opencv-2.4.9/build
pushd /home/cambricon/hilinux/opencv-2.4.9/build
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/cambricon/hilinux/toolchain-hilinux.cmake \
         -DCMAKE_INSTALL_PREFIX=/home/cambricon/hilinux/CNStream  \
         -DWITH_CUDA=OFF -DWITH_OPENCL=OFF \
         -DBUILD_DOCS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF \
         -DBUILD_WITH_DEBUG_INFO=OFF -DBUILD_opencv_apps=off -DWITH_V4L=OFF -DWITH_GTK=OFF \
         -DCMAKE_VERBOSE=on -DWITH_LIBV4L=OFF -DWITH_1394=OFF -DWITH_TIFF=OFF -DWITH_OPENEXR=OFF \
         -DBUILD_OPENEXR=OFF -DBUILD_opencv_ocl=off -DWITH_GSTREAMER=OFF -DWITH_FFMPEG=OFF \
         -DWITH_EIGEN=OFF -DWITH_GIGEAPI=OFF -DWITH_JASPER=OFF -DWITH_CUFFT=OFF \
         -DBUILD_opencv_contrib=off -DBUILD_opencv_ml=OFF -DBUILD_opencv_objdetect=OFF \
         -DBUILD_opencv_nonfree=off -DBUILD_opencv_gpu=OFF
 
make clean
make -j8 install
popd

4.   交叉编译CNStream

      4.1 配置Neuware包路径环境变量: export NEUWARE_HOME=~/hilinux/newuare_1.4/debian_workspace/usr/local/neuware; 默认路径为/usr/local/neuware

      4.2 重新编译bangc算子二进制文件(仓库中自带的是x86_64架构)

      因为ResizeKernel.mlu文件在最新的cncc编译器中编译不过,故在easydk/CMakeLists.txt将相关文件注释掉:

      # file(GLOB_RECURSE bang_srcs ${bang_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/src/easybang/resize/ResizeKernel.o ${CMAKE_CURRENT_SOURCE_DIR}/src/easybang/resize/*.cpp)

export PATH=$PATH:/usr/local/neuware/bin   #cncc所在的路径
cncc  pluginops_PluginResizeYuvToRgbaOp_plugin_resize_yuv_to_rgba_kernel_v2.mlu  -O3 -o kernel_c20.o  --bang-mlu-arch=MLU270 --bang-device-only --target=armv8
cncc  pluginops_PluginResizeYuvToRgbaOp_plugin_resize_yuv_to_rgba_kernel_v2.mlu  -O3 -o kernel_c20e.o  --bang-mlu-arch=MLU220 --bang-device-only --target=armv8

       将原仓库中kernel_c20.o,kernel_c20e.o分别替换新生成的文件

    4.3 生成MakeFile并编译

cd CNStream;
mkdir build;
cd build;
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/cambricon/hilinux/toolchain-hilinux.cmake -Dbuild_tests=OFF -Dbuild_track=OFF -DWITH_TRACKER=OFF -DENABLE_KCF=OFF
make

  4.4 运行demo

因为是交叉编译,运行环境和编译环境往往不在同一台机子上,所以先export LD_LIBRARY_PATH环境变量(具体的路径请自己仔细核对,如下只是示例)

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/CNStream/lib/:~/CNStream/build/3rdparty/lib/:~/CNStream/build/easydk/:/root/mlu220_software/newuare_1.4/debian_workspace/usr/local/neuware/lib64


版权所有 © 2019 寒武纪 Cambricon 备案/许可证号:京ICP备17003415
关闭