Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Add CMakeLists.txt for the inference demo. #13

Merged
merged 7 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
*.pyc
build/
build_*/
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Here mainly describes how to deploy PaddlePaddle to the mobile end, as well as s
- [Build PaddlePaddle for Raspberry Pi3](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/howto/cross_compiling/cross_compiling_for_raspberry_cn.md)
- Build PaddlePaddle for PX2
- How to build PaddlePaddle mobile inference library with minimum size.
- How to build PaddlePaddle with NNPACK.

## Deployment optimization methods
- [Merge batch normalization before deploying the model to the mobile.](./tool/merge_batch_normalization/README.md)
Expand Down
48 changes: 48 additions & 0 deletions benchmark/tool/C/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/")


if(ANDROID_ABI)
set(ANDROID_COMPILER_FLAGS -ffunction-sections -fdata-sections)
set(ANDROID_LINKER_FLAGS -Wl,--gc-sections)

if(ANDROID_ABI STREQUAL "armeabi-v7a")
set(CMAKE_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot")
set(ANDROID_TOOLCHAIN_PREFIX
"${ANDROID_STANDALONE_TOOLCHAIN}/bin/arm-linux-androideabi")
list(APPEND ANDROID_COMPILER_FLAGS -mfpu=neon)
list(APPEND ANDROID_LINKER_FLAGS -Wl,--fix-cortex-a8)
elseif(ANDROID_ABI STREQUAL "arm64-v8a")
set(CMAKE_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot")
set(ANDROID_TOOLCHAIN_PREFIX
"${ANDROID_STANDALONE_TOOLCHAIN}/bin/aarch64-linux-android")
list(APPEND ANDROID_COMPILER_FLAGS -march=armv8-a)
endif()
string(REPLACE ";" " " ANDROID_COMPILER_FLAGS "${ANDROID_COMPILER_FLAGS}")
string(REPLACE ";" " " ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}")

set(CMAKE_C_FLAGS "${ANDROID_COMPILER_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING "C flags")
set(CMAKE_CXX_FLAGS "${ANDROID_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING "CXX flags")
set(CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" CACHE STRING "shared linker flags")
set(CMAKE_EXE_LINKER_FLAGS "-pie -fPIE ${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "executable linker flags")

set(CMAKE_C_COMPILER ${ANDROID_TOOLCHAIN_PREFIX}-gcc CACHE PATH "C compiler" FORCE)
set(CMAKE_CXX_COMPILER ${ANDROID_TOOLCHAIN_PREFIX}-g++ CACHE PATH "CXX compiler" FORCE)
endif()
project(inference CXX C)
include(FindPaddle)

aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})

if(ANDROID_ABI)
target_link_libraries(${PROJECT_NAME}
-Wl,--start-group -Wl,--whole-archive -lpaddle_capi_layers
-Wl,--no-whole-archive -lpaddle_capi_engine -Wl,--end-group
${THIRD_PARTY_LIBRARYS})
else()
target_link_libraries(${PROJECT_NAME}
-Wl,--start-group -Wl,--whole-archive -lpaddle_capi_whole
-Wl,--no-whole-archive -Wl,--end-group
${THIRD_PARTY_LIBRARYS} -lrt -ldl -lpthread)
endif()
18 changes: 18 additions & 0 deletions benchmark/tool/C/FindPaddle.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(PADDLE_ROOT $ENV{PADDLE_ROOT} CACHE PATH "Paddle Path")
find_path(PADDLE_INC NAMES capi.h PATHS ${PADDLE_ROOT}/include/paddle)
find_library(PADDLE_LIB NAMES paddle_capi_shared PATHS ${PADDLE_ROOT}/lib/${ANDROID_ABI})
if(PADDLE_INC AND PADDLE_LIB)
message("Found")
else()
message(${PADDLE_ROOT})
message("Not Found")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to use message(STATUS ...), and the message should be more detail, such as

message(STATUS "Found PaddlePaddle (include: ${PADDLE_INC}; library: ${PADDLE_LIB})")
message(FATAL_ERROR "Cannot find PaddlePaddle on ${PADDLE_ROOT}")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

endif()
include_directories(${PADDLE_ROOT}/include)
set(THIRD_PARTY_LIBRARYS)
list(APPEND THIRD_PARTY_LIBRARYS -lglog -lgflags -lprotobuf -lopenblas -lz)
link_directories(${PADDLE_ROOT}/lib/${ANDROID_ABI})
link_directories(${PADDLE_ROOT}/third_party/gflags/lib/${ANDROID_ABI})
link_directories(${PADDLE_ROOT}/third_party/glog/lib/${ANDROID_ABI})
link_directories(${PADDLE_ROOT}/third_party/protobuf/lib/${ANDROID_ABI})
link_directories(${PADDLE_ROOT}/third_party/openblas/lib/${ANDROID_ABI})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes, there is no openblas.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

link_directories(${PADDLE_ROOT}/third_party/zip/lib/${ANDROID_ABI})
2 changes: 1 addition & 1 deletion benchmark/tool/C/inference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) {

{
Timer time("init paddle");
char* argv[] = {"--use_gpu=False"};
char* argv[] = {(char*)"--use_gpu=False"};
if (paddle_init(1, (char**)argv) != kPD_NO_ERROR) {
std::cout << "paddle init error!" << std::endl;
}
Expand Down