From df028ce2a08a9135a4831032f5a43acc25e76120 Mon Sep 17 00:00:00 2001 From: Houjiang Chen Date: Tue, 23 Apr 2019 10:17:01 +0800 Subject: [PATCH] Fix compilation on Raspberry PI3, and fix some code style (#1566) --- .../kernel/arm/beam_search_decode_kernel.cpp | 1 + .../kernel/arm/beam_search_kernel.cpp | 1 + src/operators/math/pooling.h | 29 +++++------- test/net/test_benchmark.cpp | 2 +- test/net/test_googlenet.cpp | 44 +++++++++++++------ tools/build.sh | 3 +- tools/ci_build.sh | 8 ---- tools/toolchains/arm-linux-gnueabihf.cmake | 3 +- 8 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/operators/kernel/arm/beam_search_decode_kernel.cpp b/src/operators/kernel/arm/beam_search_decode_kernel.cpp index f22c032347..97aaffe7c2 100644 --- a/src/operators/kernel/arm/beam_search_decode_kernel.cpp +++ b/src/operators/kernel/arm/beam_search_decode_kernel.cpp @@ -15,6 +15,7 @@ limitations under the License. */ #ifdef BEAM_SEARCH_DECODE_OP #include "operators/kernel/beam_search_decode_kernel.h" +#include #include "framework/data_type.h" namespace paddle_mobile { diff --git a/src/operators/kernel/arm/beam_search_kernel.cpp b/src/operators/kernel/arm/beam_search_kernel.cpp index 5e88e2f18e..9128c57c64 100644 --- a/src/operators/kernel/arm/beam_search_kernel.cpp +++ b/src/operators/kernel/arm/beam_search_kernel.cpp @@ -15,6 +15,7 @@ limitations under the License. */ #ifdef BEAM_SEARCH_OP #include "operators/kernel/beam_search_kernel.h" +#include #include namespace paddle_mobile { diff --git a/src/operators/math/pooling.h b/src/operators/math/pooling.h index 0f0b4e2630..909d289767 100644 --- a/src/operators/math/pooling.h +++ b/src/operators/math/pooling.h @@ -157,39 +157,34 @@ inline float PoolPost(const float &x, const float &post) { template struct Pooling { - inline void operator()(const framework::Tensor &input, - const std::vector &kernel_size, - const std::vector &strides, - const std::vector &paddings, - framework::Tensor *output); + void operator()(const framework::Tensor &input, + const std::vector &kernel_size, + const std::vector &strides, + const std::vector &paddings, framework::Tensor *output); }; template struct Pooling2x2 { - inline void operator()(const framework::Tensor &input, - const std::vector &paddings, - framework::Tensor *output); + void operator()(const framework::Tensor &input, + const std::vector &paddings, framework::Tensor *output); }; template struct Pooling3x3 { - inline void operator()(const framework::Tensor &input, - const std::vector &paddings, - framework::Tensor *output); + void operator()(const framework::Tensor &input, + const std::vector &paddings, framework::Tensor *output); }; template struct Pooling5x5 { - inline void operator()(const framework::Tensor &input, - const std::vector &paddings, - framework::Tensor *output); + void operator()(const framework::Tensor &input, + const std::vector &paddings, framework::Tensor *output); }; template struct Pooling7x7 { - inline void operator()(const framework::Tensor &input, - const std::vector &paddings, - framework::Tensor *output); + void operator()(const framework::Tensor &input, + const std::vector &paddings, framework::Tensor *output); }; } // namespace math diff --git a/test/net/test_benchmark.cpp b/test/net/test_benchmark.cpp index 4c9a36dc26..0b576561b7 100644 --- a/test/net/test_benchmark.cpp +++ b/test/net/test_benchmark.cpp @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) { std::shared_ptr output; std::vector dims{1, 3, 224, 224}; if (feed_shape) { - sscanf(feed_shape, "%ld,%ld,%ld,%ld", &dims[0], &dims[1], &dims[2], + sscanf(feed_shape, "%lld,%lld,%lld,%lld", &dims[0], &dims[1], &dims[2], &dims[3]); } std::cout << "feed shape: [" << dims[0] << ", " << dims[1] << ", " diff --git a/test/net/test_googlenet.cpp b/test/net/test_googlenet.cpp index 24e74ffeac..ea6c6ce155 100644 --- a/test/net/test_googlenet.cpp +++ b/test/net/test_googlenet.cpp @@ -13,25 +13,31 @@ See the License for the specific language governing permissions and limitations under the License. */ #include +#include #include "../test_helper.h" #include "../test_include.h" -int main(int argc, char* argv[]) { - if (argc < 2) { - std::cout << "Usage: ./test_benchmark feed_shape [thread_num] [use_fuse]\n" - << "feed_shape: input tensor shape, such as 3,224,224.\n" - << "thread_num: optional int, threads count, default is 1.\n" - << "use_fuse: optional bool, default is 0.\n"; +int main(int argc, char *argv[]) { + if (argc < 4) { + std::cout << "Usage: ./test_googlenet fluid-model input-image image-shape " + "[thread-num] [fusion]\n" + << " fluid-model: fluid model path. \n" + << " input-image: input raw image path. \n" + << " image-shape: input tensor shape, such as 1,3,224,224.\n" + << " thread-num: optional int, threads count, default is 1.\n" + << " fusion: optional bool, default is 0.\n"; return 1; } int thread_num = 1; bool optimize = false; - char* feed_shape = argv[1]; - if (argc >= 3) { - thread_num = atoi(argv[2]); + char *fluid_model = argv[1]; + char *input_img = argv[2]; + char *feed_shape = argv[3]; + if (argc >= 5) { + thread_num = atoi(argv[4]); } - if (argc >= 4) { - optimize = atoi(argv[3]); + if (argc >= 6) { + optimize = atoi(argv[5]); } #ifdef PADDLE_MOBILE_FPGA paddle_mobile::PaddleMobile paddle_mobile; @@ -42,18 +48,21 @@ int main(int argc, char* argv[]) { paddle_mobile.SetThreadNum(thread_num); auto time1 = time(); std::vector output; - if (paddle_mobile.Load(g_googlenet, optimize, false, 1, true)) { + if (paddle_mobile.Load(fluid_model, optimize, false, 1, true)) { auto time2 = paddle_mobile::time(); std::cout << "load cost :" << paddle_mobile::time_diff(time1, time2) << "ms" << std::endl; std::vector input; std::vector dims{1, 3, 224, 224}; if (feed_shape) { - sscanf(feed_shape, "%d,%d,%d", &dims[1], &dims[2], &dims[3]); + sscanf(feed_shape, "%lld,%lld,%lld,%lld", &dims[0], &dims[1], &dims[2], + &dims[3]); } std::cout << "feed shape: [" << dims[0] << ", " << dims[1] << ", " << dims[2] << ", " << dims[3] << "]" << std::endl; - GetInput(g_test_image_1x3x224x224, &input, dims); + + GetInput(input_img, &input, dims); + // warmup for (int i = 0; i < 10; ++i) { output = paddle_mobile.Predict(input, dims); @@ -64,6 +73,13 @@ int main(int argc, char* argv[]) { } auto time4 = time(); std::cout << "predict cost: " << time_diff(time3, time4) / 10 << "ms\n"; + + std::ostringstream os; + os << output[0]; + for (int i = 1; i < output.size(); ++i) { + os << ", " << output[i]; + } + DLOG << os.str(); } return 0; } diff --git a/tools/build.sh b/tools/build.sh index cac18c79d7..2134abdd9e 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -118,7 +118,8 @@ build_for_arm_linux() { fi cd "../build/release/arm-linux" - make -j 8 + make -j 2 + cd "../../../test/" DIRECTORY="models" if [ "`ls -A $DIRECTORY`" = "" ]; then diff --git a/tools/ci_build.sh b/tools/ci_build.sh index 424dc1890f..8bd892c22d 100755 --- a/tools/ci_build.sh +++ b/tools/ci_build.sh @@ -75,7 +75,6 @@ function build_android_armv7_cpu_only() { -DANDROID=true \ -DWITH_LOGGING=OFF \ -DCPU=ON \ - -DGPU_MALI=OFF \ -DGPU_CL=OFF \ -DFPGA=OFF @@ -95,7 +94,6 @@ function build_android_armv7_gpu() { -DANDROID=true \ -DWITH_LOGGING=OFF \ -DCPU=ON \ - -DGPU_MALI=ON \ -DGPU_CL=ON \ -DFPGA=OFF @@ -115,7 +113,6 @@ function build_android_armv8_cpu_only() { -DANDROID=true \ -DWITH_LOGGING=OFF \ -DCPU=ON \ - -DGPU_MALI=OFF \ -DGPU_CL=OFF \ -DFPGA=OFF @@ -135,7 +132,6 @@ function build_android_armv8_gpu() { -DANDROID=true \ -DWITH_LOGGING=OFF \ -DCPU=ON \ - -DGPU_MALI=ON \ -DGPU_CL=ON \ -DFPGA=OFF @@ -154,7 +150,6 @@ function build_ios_armv8_cpu_only() { -DIS_IOS=true \ -DUSE_OPENMP=OFF \ -DCPU=ON \ - -DGPU_MALI=OFF \ -DGPU_CL=OFF \ -DFPGA=OFF @@ -173,7 +168,6 @@ function build_ios_armv8_gpu() { -DIS_IOS=true \ -DUSE_OPENMP=OFF \ -DCPU=ON \ - -DGPU_MALI=OFF \ -DGPU_CL=ON \ -DFPGA=OFF @@ -188,7 +182,6 @@ function build_linux_armv7_cpu_only() { -DCMAKE_BUILD_TYPE="MinSizeRel" \ -DCMAKE_TOOLCHAIN_FILE="./tools/toolchains/arm-linux-gnueabihf.cmake" \ -DCPU=ON \ - -DGPU_MALI=OFF \ -DGPU_CL=OFF \ -DFPGA=OFF @@ -203,7 +196,6 @@ function build_linux_armv7_gpu() { -DCMAKE_BUILD_TYPE="MinSizeRel" \ -DCMAKE_TOOLCHAIN_FILE="./tools/toolchains/arm-linux-gnueabihf.cmake" \ -DCPU=ON \ - -DGPU_MALI=ON \ -DGPU_CL=ON \ -DFPGA=OFF diff --git a/tools/toolchains/arm-linux-gnueabihf.cmake b/tools/toolchains/arm-linux-gnueabihf.cmake index 7db42c7e73..2b8729cd9d 100644 --- a/tools/toolchains/arm-linux-gnueabihf.cmake +++ b/tools/toolchains/arm-linux-gnueabihf.cmake @@ -4,8 +4,7 @@ set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_SYSTEM_VERSION 1) -message("if U build on platform . this is right.") set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) \ No newline at end of file +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) -- GitLab