Ne10编译安装
介紹
NEON,即“ARM Advanced SIMD”,是ARM從ARMv7開始提供的高級單指令多數(shù)據(jù)(SIMD)擴(kuò)展。它是一種64/128位混合SIMD體系結(jié)構(gòu)。NEON在網(wǎng)上的資料比較少,對于新手來說不太友好。一番折騰之后,終于在GIT上找到一個(gè)封裝好的NEON庫,Ne10,內(nèi)部用匯編實(shí)現(xiàn)了若干基本運(yùn)算。
Git地址
安裝指南
預(yù)備
先安裝arm-linux交叉編譯器:
sudo apt-get install gcc-arm-linux-gnueabihf
sudo apt-get install g++-arm-linux-gnueabihf
否則,會出現(xiàn)編譯錯(cuò)誤
cc: error: unrecognized command line option ‘-mthumb-interwork’ cc: error: unrecognized command line option ‘-mthumb’ cc: error: unrecognized command line option ‘-mfpu=vfp3’作為小白的我不知所以,抓狂很久,直到看到根目錄下的GNUlinux_config.cmake才恍然大誤大悟。
關(guān)于abi的介紹,可參考這篇博客
交叉編譯器。
編譯
Native compilation on *nix platforms
編譯命令
cd $NE10_PATH # Change directory to the location of the Ne10 source mkdir build && cd build # Create the `build` directory and navigate into it export NE10_LINUX_TARGET_ARCH=armv7 # Set the target architecture (can also be "aarch64") cmake -DGNULINUX_PLATFORM=ON .. # Run CMake to generate the build files make # Build the project這步總是有問題,找到的編譯器是gcc和g++,而不是gcc-arm-linux-gnueabihf和g++-arm-linux-gnueabihf。
-- Found assembler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works...Cross compilation on *nix platforms...
編譯命令
cd $NE10_PATH mkdir build && cd build export NE10_LINUX_TARGET_ARCH=armv7 # Can also be "aarch64" cmake -DCMAKE_TOOLCHAIN_FILE=../GNUlinux_config.cmake .. make這步是ok的。找到了合適的編譯器
-- Found assembler: /usr/bin/arm-linux-gnueabihf-as -- Check for working C compiler: /usr/bin/arm-linux-gnueabihf-gcc -- Check for working C compiler: /usr/bin/arm-linux-gnueabihf-gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++ -- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++ -- works成功編譯。
Linking C static library libNE10.a [ 94%] Built target NE10 Scanning dependencies of target NE10_test_static [ 95%] Building C object samples/CMakeFiles/NE10_test_static.dir/NE10_sample_intro.c.o [ 96%] Building C object samples/CMakeFiles/NE10_test_static.dir/NE10_sample_matrix_multiply.c.o [ 97%] Building C object samples/CMakeFiles/NE10_test_static.dir/NE10_sample_complex_fft.c.o [ 98%] Building C object samples/CMakeFiles/NE10_test_static.dir/NE10_sample_fir.c.o [100%] Building C object samples/CMakeFiles/NE10_test_static.dir/NE10_samples.c.o Linking CXX executable NE10_test_static [100%] Built target NE10_test_static作者還提到
Additionally, for systems without hardware floating point support, the appropriate compilation options should be added to the CMAKE_C_FLAGS and CMAKE_ASM_FLAGS variables in the root CMakeLists.txt file. For example, -mfloat-abi=softfp -mfpu=neon.
運(yùn)行/build/samples/NE10_test_static出現(xiàn)錯(cuò)誤
bash: ./NE10_test_static: cannot execute binary file: Exec format error應(yīng)該是32位程序不能運(yùn)行在64位系統(tǒng)上。
64位編譯
編譯64位程序時(shí)(armv7改為aarch64)出現(xiàn)問題
In file included from /home/XXX/Ne10-master/modules/imgproc/NE10_resize.neon.c:28:0: /home/XXX/Ne10-master/modules/imgproc/NE10_resize.neon.c: In function ‘ne10_img_vresize_linear_neon’: /home/XXX/Ne10-master/modules/imgproc/NE10_resize.neon.c:174:19: error: incompatible types when initializing type ‘int32x4_t’ using type ‘int32x2_t’qT_0123 = vmlaq_lane_s32 (qT_0123, qS1_0123, dBeta, 1);還沒有找到問題所在。
...for Android
編譯命令
cd $NE10_PATH mkdir build && cd build export ANDROID_NDK=/absolute/path/of/android-ndk # Change to your local ndk path export NE10_ANDROID_TARGET_ARCH=armv7 # Can also be "aarch64" cmake -DCMAKE_TOOLCHAIN_FILE=../android/android_config.cmake .. make找到編譯器
-- Found assembler: /home/XXX/android-ndk-r13b//toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as -- Detecting C compiler ABI info -- Detecting C compiler ABI info - failed -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - failed -- Target architecture: armv7 -- Building type: RELEASE -- Loaded toolchain:/home/XXX/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc/home/XXX/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++/home/XXX/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as成功編譯
Linking C static library libNE10.a Scanning dependencies of target NE10_test_static Linking CXX executable NE10_test_static Scanning dependencies of target NE10_test_demo Linking CXX shared library libNE10_test_demo.so [100%] Built target NE10_test_demoAndroid運(yùn)行結(jié)果
將運(yùn)算重復(fù)運(yùn)行十萬次。具體還需要深入理解后再分析。
# Introduction ne10_addc_float: 0.610000 ne10_addc_float_c: 1.863000 ne10_addc_float_neon: 0.652000# Matrix Multiply ne10_mulmat_3x3f: 4.211000 ne10_mulmat_3x3f_c: 7.352000 ne10_mulmat_3x3f_neon: 4.246000轉(zhuǎn)載于:https://www.cnblogs.com/luyb/p/6492283.html
總結(jié)
- 上一篇: SpringMVC:学习笔记(5)——数
- 下一篇: 锋利的jQuery--关于$(docum