Ncnn: 请问ncnn for raspberry pi 3b , 怎么编译?

Created on 3 Apr 2018  ·  9Comments  ·  Source: Tencent/ncnn

如题

Most helpful comment

我自己来回答一下吧,首先要修改一下源码:

respeaker@v2:~/ncnn$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3cd319..a25c1ce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,10 +43,15 @@ else()
     add_definitions(-Ofast)

     add_definitions(-ffast-math)
-    # add_definitions(-march=native)
+    add_definitions(-march=native)

     # add_definitions(-flto)
-
+    #add_definitions(-mfloat-abi=hard -mhard-float -D_NDK_MATH_NO_SOFTFP=1)
+    add_definitions(-mfpu=neon)
+    #add_definitions(-mfpu=vfpv3)
+    add_definitions(-mfloat-abi=hard)
+    add_definitions(-D__ARM_NEON)
+    add_definitions(-D__ANDROID__)
     add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
 endif()

@@ -62,8 +67,8 @@ endif()

 ##############################################

-# add_subdirectory(examples)
-# add_subdirectory(benchmark)
+add_subdirectory(examples)
+add_subdirectory(benchmark)
 add_subdirectory(src)
 if(NOT ANDROID AND NOT IOS)
 add_subdirectory(tools)
diff --git a/src/cpu.cpp b/src/cpu.cpp
index 7814ec0..53878c9 100644
--- a/src/cpu.cpp
+++ b/src/cpu.cpp
@@ -287,7 +287,7 @@ typedef struct
   memset((cpusetp), 0, sizeof(cpu_set_t))

     // set affinity for thread
-    pid_t pid = gettid();
+    pid_t pid = getpid();

     cpu_set_t mask;
     CPU_ZERO(&mask);
respeaker@v2:~/ncnn$ cat arm.toolchan.cmake
SET(CMAKE_SYSTEM_NANE Android)
SET(CMAKE_SYSTEM_PROCESSOR "armv7l")
SET(ANDROID_ARCH_NAME "arm")
SET(UNIX true)
SET(CMAKE_C_COMPILER "gcc")
SET(CMAKE_CXX_COMPILER "g++")

respeaker@v2:~/ncnn$ 

经测试,性能如下:
image

All 9 comments

我自己来回答一下吧,首先要修改一下源码:

respeaker@v2:~/ncnn$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3cd319..a25c1ce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,10 +43,15 @@ else()
     add_definitions(-Ofast)

     add_definitions(-ffast-math)
-    # add_definitions(-march=native)
+    add_definitions(-march=native)

     # add_definitions(-flto)
-
+    #add_definitions(-mfloat-abi=hard -mhard-float -D_NDK_MATH_NO_SOFTFP=1)
+    add_definitions(-mfpu=neon)
+    #add_definitions(-mfpu=vfpv3)
+    add_definitions(-mfloat-abi=hard)
+    add_definitions(-D__ARM_NEON)
+    add_definitions(-D__ANDROID__)
     add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
 endif()

@@ -62,8 +67,8 @@ endif()

 ##############################################

-# add_subdirectory(examples)
-# add_subdirectory(benchmark)
+add_subdirectory(examples)
+add_subdirectory(benchmark)
 add_subdirectory(src)
 if(NOT ANDROID AND NOT IOS)
 add_subdirectory(tools)
diff --git a/src/cpu.cpp b/src/cpu.cpp
index 7814ec0..53878c9 100644
--- a/src/cpu.cpp
+++ b/src/cpu.cpp
@@ -287,7 +287,7 @@ typedef struct
   memset((cpusetp), 0, sizeof(cpu_set_t))

     // set affinity for thread
-    pid_t pid = gettid();
+    pid_t pid = getpid();

     cpu_set_t mask;
     CPU_ZERO(&mask);
respeaker@v2:~/ncnn$ cat arm.toolchan.cmake
SET(CMAKE_SYSTEM_NANE Android)
SET(CMAKE_SYSTEM_PROCESSOR "armv7l")
SET(ANDROID_ARCH_NAME "arm")
SET(UNIX true)
SET(CMAKE_C_COMPILER "gcc")
SET(CMAKE_CXX_COMPILER "g++")

respeaker@v2:~/ncnn$ 

经测试,性能如下:
image

28

使用 89ef9d779dcc3fa0eee195ecc76552806b5be0d6 测试了一下。

respeaker@v2:~/ncnn/build/benchmark$  ./benchncnn 8 4 0
loop_count = 8
num_threads = 4
powersave = 0
      squeezenet  min =  300.97  max =  302.80  avg =  301.89
       mobilenet  min =  489.53  max =  627.75  avg =  515.26
    mobilenet_v2  min =  430.57  max =  474.48  avg =  438.63
      shufflenet  min =  172.46  max =  184.58  avg =  174.88
       googlenet  min =  900.90  max =  917.64  avg =  909.99
        resnet18  min = 1033.58  max = 1055.32  avg = 1045.79
         alexnet  min =  665.61  max =  732.15  avg =  696.10
           vgg16  min = 7845.35  max = 8337.21  avg = 8047.88
  squeezenet-ssd  min =  468.08  max =  476.50  avg =  470.12
   mobilenet-ssd  min =  505.71  max =  521.30  avg =  511.93

同樣都是ARM A53 1.2 GHz quad-core 為什麼Snapdragon 410上速度可以這麼快

世界上的为什么就是这么多

为什么,我树莓派上的性能,看起来,花费的时间是你这个结果的4倍?天哪,我这个哪里出问题了?

min max avg单位是毫秒吗?

使用 89ef9d7 测试了一下。

respeaker@v2:~/ncnn/build/benchmark$  ./benchncnn 8 4 0
loop_count = 8
num_threads = 4
powersave = 0
      squeezenet  min =  300.97  max =  302.80  avg =  301.89
       mobilenet  min =  489.53  max =  627.75  avg =  515.26
    mobilenet_v2  min =  430.57  max =  474.48  avg =  438.63
      shufflenet  min =  172.46  max =  184.58  avg =  174.88
       googlenet  min =  900.90  max =  917.64  avg =  909.99
        resnet18  min = 1033.58  max = 1055.32  avg = 1045.79
         alexnet  min =  665.61  max =  732.15  avg =  696.10
           vgg16  min = 7845.35  max = 8337.21  avg = 8047.88
  squeezenet-ssd  min =  468.08  max =  476.50  avg =  470.12
   mobilenet-ssd  min =  505.71  max =  521.30  avg =  511.93

试了一下3B+

root@raspberrypi:/home/pi/ncnn/build/benchmark# ./benchncnn 8 4 0
loop_count = 8
num_threads = 4
powersave = 0
squeezenet min = 103.89 max = 104.15 avg = 104.02
mobilenet min = 189.70 max = 191.48 avg = 190.49
mobilenet_v2 min = 200.17 max = 201.02 avg = 200.49
shufflenet min = 72.47 max = 72.65 avg = 72.52
googlenet min = 337.07 max = 338.15 avg = 337.52
resnet18 min = 510.73 max = 518.89 avg = 514.81
alexnet min = 422.94 max = 423.15 avg = 423.03
vgg16 min = 2459.17 max = 2487.06 avg = 2474.63
squeezenet-ssd min = 341.95 max = 353.17 avg = 349.39
mobilenet-ssd min = 335.72 max = 349.97 avg = 346.59
mobilenet-yolo min = 866.91 max = 870.52 avg = 868.21

wiki how to build updated for Raspberry Pi 3 compilation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Abel119 picture Abel119  ·  4Comments

xhappy picture xhappy  ·  5Comments

kame-lqm picture kame-lqm  ·  4Comments

ghost picture ghost  ·  3Comments

mychina75 picture mychina75  ·  4Comments