CMakeLists.txt 13.7 KB
Newer Older
1 2 3 4
if (NOT WITH_LITE)
    return()
endif()

S
superjomn 已提交
5 6
include(lite)

S
superjomn 已提交
7
message(WARNING "Lite enabled!")
8 9 10 11
message(STATUS "LIGHT_FRAMEWORK:\t${LITE_WITH_LIGHT_WEIGHT_FRAMEWORK}")
message(STATUS "LITE_WITH_CUDA:\t${LITE_WITH_CUDA}")
message(STATUS "LITE_WITH_X86:\t${LITE_WITH_X86}")
message(STATUS "LITE_WITH_ARM:\t${LITE_WITH_ARM}")
Y
Yan Chunwei 已提交
12
message(STATUS "LITE_WITH_PROFILE:\t${LITE_WITH_PROFILE}")
S
Superjomn 已提交
13

S
superjomn 已提交
14
set(LITE_MODEL_DIR "${THIRD_PARTY_PATH}/install")
C
Chunwei 已提交
15

S
sangoly 已提交
16
set(LITE_ON_MOBILE ${LITE_WITH_LIGHT_WEIGHT_FRAMEWORK})
C
Chunwei 已提交
17

Z
Zhen Wang 已提交
18
set(LITE_URL "http://paddle-inference-dist.bj.bcebos.com" CACHE STRING "inference download url")
S
superjomn 已提交
19 20 21 22 23 24 25 26 27 28

function(lite_download_and_uncompress INSTALL_DIR URL FILENAME)
    message(STATUS "Download inference test stuff from ${URL}/${FILENAME}")
    string(REGEX REPLACE "[-%.]" "_" FILENAME_EX ${FILENAME})
    set(EXTERNAL_PROJECT_NAME "extern_lite_download_${FILENAME_EX}")
    set(UNPACK_DIR "${INSTALL_DIR}/src/${EXTERNAL_PROJECT_NAME}")
    ExternalProject_Add(
            ${EXTERNAL_PROJECT_NAME}
            ${EXTERNAL_PROJECT_LOG_ARGS}
            PREFIX                ${INSTALL_DIR}
C
Chunwei 已提交
29
            DOWNLOAD_COMMAND      wget --no-check-certificate -q -O ${INSTALL_DIR}/${FILENAME} ${URL}/${FILENAME} && ${CMAKE_COMMAND} -E tar xzf ${INSTALL_DIR}/${FILENAME}
S
superjomn 已提交
30 31 32 33 34 35 36 37 38
            DOWNLOAD_DIR          ${INSTALL_DIR}
            DOWNLOAD_NO_PROGRESS  1
            CONFIGURE_COMMAND     ""
            BUILD_COMMAND         ""
            UPDATE_COMMAND        ""
            INSTALL_COMMAND       ""
    )
endfunction()

39
function (lite_deps TARGET)
40 41
  set(options "")
  set(oneValueArgs "")
C
Chunwei 已提交
42
  set(multiValueArgs DEPS X86_DEPS CUDA_DEPS ARM_DEPS PROFILE_DEPS LIGHT_DEPS HVY_DEPS CL_DEPS ARGS)
43 44
  cmake_parse_arguments(lite_deps "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

45
  set(deps ${lite_deps_DEPS})
46 47 48

  if(LITE_WITH_X86)
    foreach(var ${lite_deps_X86_DEPS})
49 50
      set(deps ${deps} ${var})
    endforeach(var)
51 52 53 54
  endif()

  if(LITE_WITH_CUDA)
    foreach(var ${lite_deps_CUDA_DEPS})
55 56
      set(deps ${deps} ${var})
    endforeach(var)
57 58 59 60
  endif()

  if(LITE_WITH_ARM)
    foreach(var ${lite_deps_ARM_DEPS})
61 62
      set(deps ${deps} ${var})
    endforeach(var)
63
  endif()
64

Y
Yan Chunwei 已提交
65 66 67 68 69 70
  if(LITE_WITH_PROFILE)
    foreach(var ${lite_deps_PROFILE_DEPS})
      set(deps ${deps} ${var})
    endforeach(var)
  endif()

71 72 73 74 75 76 77 78 79 80 81 82
  if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
    foreach(var ${lite_deps_LIGHT_DEPS})
      set(deps ${deps} ${var})
    endforeach(var)
  endif()

  if (NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
    foreach(var ${lite_deps_HVY_DEPS})
      set(deps ${deps} ${var})
    endforeach(var)
  endif()

C
Chunwei 已提交
83 84 85 86 87 88
  if (LITE_WITH_OPENCL)
    foreach(var ${lite_deps_CL_DEPS})
      set(deps ${deps} ${var})
    endforeach(var)
  endif()

89
  set(${TARGET} ${deps} PARENT_SCOPE)
90 91
endfunction()

S
superjomn 已提交
92

C
Chunwei 已提交
93 94 95
# A fake target to include all the libraries and tests the lite module depends.
add_custom_target(lite_compile_deps COMMAND echo 1)

Y
Yan Chunwei 已提交
96 97 98 99
# Add names for lite libraries for latter compile. We use this name list to avoid compiling
# the whole fluid project to accelerate the compile speed.
set(offline_lib_registry_file "${CMAKE_BINARY_DIR}/lite_libs.txt")
file(WRITE ${offline_lib_registry_file} "") # clean
S
superjomn 已提交
100

H
Huihuang Zheng 已提交
101
set(__lite_cc_files "" ; "")
S
superjomn 已提交
102 103
set(__lite_cc_files "${CMAKE_BINARY_DIR}/lite_cc_files.txt")
file(WRITE ${__lite_cc_files} "") # clean
104 105 106 107 108 109 110 111
# cc_library with branch support.
# The branches:
#  X86_DEPS: works only when LITE_WITH_X86 is ON.
#  CUDA_DEPS:     LITE_WITH_CUDA
#  ARM_DEPS:      LITE_WITH_ARM
#  PROFILE_DEPS:  LITE_WITH_PROFILE
#  LIGHT_DEPS:    LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
#  HVY_DEPS:      NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
112
function(lite_cc_library TARGET)
H
Huihuang Zheng 已提交
113
    set(options SHARED shared STATIC static MODULE module)
114
    set(oneValueArgs "")
Z
Zhen Wang 已提交
115
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS CL_DEPS ARM_DEPS PROFILE_DEPS LIGHT_DEPS
116
      HVY_DEPS ARGS)
117 118 119 120 121 122 123
    cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    set(deps "")
    lite_deps(deps
            DEPS ${args_DEPS}
            X86_DEPS ${args_X86_DEPS}
            CUDA_DEPS ${args_CUDA_DEPS}
Z
Zhen Wang 已提交
124
            CL_DEPS ${args_CL_DEPS}
Y
Yan Chunwei 已提交
125
            ARM_DEPS ${args_ARM_DEPS}
126 127 128 129
            PROFILE_DEPS ${args_PROFILE_DEPS}
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
            )
H
Huihuang Zheng 已提交
130 131

    if (args_SHARED OR ARGS_shared)
C
Chunwei 已提交
132
        cc_library(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS} SHARED)
H
Huihuang Zheng 已提交
133 134 135
    elseif (args_MODULE OR ARGS_module)
        add_library(${TARGET} MODULE ${args_SRCS})
        add_dependencies(${TARGET} ${deps} ${args_DEPS})
C
Chunwei 已提交
136 137 138
    else()
        cc_library(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS})
    endif()
Z
Zhen Wang 已提交
139
    target_compile_options(${TARGET} BEFORE PRIVATE -Wno-ignored-qualifiers)
Y
Yan Chunwei 已提交
140

S
superjomn 已提交
141 142 143 144
    foreach(cc_file ${args_SRCS})
        file(APPEND ${__lite_cc_files} "${cc_file}\n")
    endforeach()

C
Chunwei 已提交
145
    # collect targets need to compile for lite
S
superjomn 已提交
146 147 148
    if (args_SRCS)
        add_dependencies(lite_compile_deps ${TARGET})
    endif()
C
Chunwei 已提交
149

Y
Yan Chunwei 已提交
150 151
    # register a library name.
    file(APPEND ${offline_lib_registry_file} "${TARGET}\n")
152 153
endfunction()

Y
Yan Chunwei 已提交
154 155 156
function(lite_cc_binary TARGET)
    set(options "")
    set(oneValueArgs "")
Z
Zhen Wang 已提交
157
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS CL_DEPS ARM_DEPS PROFILE_DEPS
158
      LIGHT_DEPS HVY_DEPS ARGS)
Y
Yan Chunwei 已提交
159 160 161 162 163 164 165
    cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    set(deps "")
    lite_deps(deps
            DEPS ${args_DEPS}
            X86_DEPS ${args_X86_DEPS}
            CUDA_DEPS ${args_CUDA_DEPS}
Z
Zhen Wang 已提交
166
            CL_DEPS ${args_CL_DEPS}
Y
Yan Chunwei 已提交
167 168
            ARM_DEPS ${args_ARM_DEPS}
            PROFILE_DEPS ${args_PROFILE_DEPS}
169 170
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
Y
Yan Chunwei 已提交
171
            )
Y
Yan Chunwei 已提交
172
    cc_binary(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS})
Z
Zhen Wang 已提交
173
    target_compile_options(${TARGET} BEFORE PRIVATE -Wno-ignored-qualifiers)
C
Chunwei 已提交
174 175
    # collect targets need to compile for lite
    add_dependencies(lite_compile_deps ${TARGET})
Y
Yan Chunwei 已提交
176 177 178 179 180 181
endfunction()

# Add a unit-test name to file for latter offline manual test.
set(offline_test_registry_file "${CMAKE_BINARY_DIR}/lite_tests.txt")
file(WRITE ${offline_test_registry_file} "") # clean
# Test lite modules.
182 183 184
function(lite_cc_test TARGET)
    set(options "")
    set(oneValueArgs "")
Z
Zhen Wang 已提交
185
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS CL_DEPS ARM_DEPS PROFILE_DEPS
186 187
      LIGHT_DEPS HVY_DEPS
      ARGS)
188 189 190 191 192 193 194
    cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    set(deps "")
    lite_deps(deps
            DEPS ${args_DEPS}
            X86_DEPS ${args_X86_DEPS}
            CUDA_DEPS ${args_CUDA_DEPS}
Z
Zhen Wang 已提交
195
            CL_DEPS ${args_CL_DEPS}
196
            ARM_DEPS ${args_ARM_DEPS}
Y
Yan Chunwei 已提交
197
            PROFILE_DEPS ${args_PROFILE_DEPS}
198 199
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
200
            )
Y
Yan Chunwei 已提交
201
    _lite_cc_test(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ARGS ${args_ARGS})
Z
Zhen Wang 已提交
202
    target_compile_options(${TARGET} BEFORE PRIVATE -Wno-ignored-qualifiers)
Y
Yan Chunwei 已提交
203
    file(APPEND ${offline_test_registry_file} "${TARGET}\n")
C
Chunwei 已提交
204 205 206

    # collect targets need to compile for lite
    add_dependencies(lite_compile_deps ${TARGET})
207
endfunction()
S
superjomn 已提交
208

Z
Zhen Wang 已提交
209 210
add_subdirectory(operators)
add_subdirectory(kernels)
S
update  
superjomn 已提交
211
add_subdirectory(core)
S
superjomn 已提交
212
add_subdirectory(x86)
T
tensor-tang 已提交
213
add_subdirectory(arm)
214
add_subdirectory(host)
215
add_subdirectory(cuda)
Z
Zhen Wang 已提交
216
add_subdirectory(opencl)
S
superjomn 已提交
217
add_subdirectory(model_parser)
S
superjomn 已提交
218
add_subdirectory(utils)
S
superjomn 已提交
219
add_subdirectory(api)
220
add_subdirectory(gen_code)
221
add_subdirectory(tools)
C
Chunwei 已提交
222 223


S
sangoly 已提交
224 225 226
# Deployment required
lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v1.tar.gz")

C
Chunwei 已提交
227 228
if (WITH_TESTING)
    lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "lite_naive_model.tar.gz")
S
sangoly 已提交
229
    if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
S
sangoly 已提交
230
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v2_relu.tar.gz")
231
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "resnet50.tar.gz")
S
sangoly 已提交
232
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "inception_v4_simple.tar.gz")
S
sangoly 已提交
233
    endif()
234 235 236
    if(NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "GoogleNet_inference.tar.gz")
    endif()
C
Chunwei 已提交
237
endif()
C
Chunwei 已提交
238 239

# for publish
C
Chunwei 已提交
240
set(INFER_LITE_PUBLISH_ROOT "${CMAKE_BINARY_DIR}/inference_lite_lib.${ARM_TARGET_OS}.${ARM_TARGET_ARCH_ABI}")
C
Chunwei 已提交
241 242 243 244 245 246 247 248
message(STATUS "publish inference lib to ${INFER_LITE_PUBLISH_ROOT}")

# The final target for publish lite lib
add_custom_target(publish_inference_lite)

#cc_library(inference_cxx_lib DEPS cxx_api_lite)
add_custom_target(publish_inference_cxx_lib ${TARGET}
        COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
C
Chunwei 已提交
249
        COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/bin"
C
Chunwei 已提交
250
        COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
S
sangoly 已提交
251 252 253
        COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/third_party"
        COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/demo/cxx"
        COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/demo/models"
C
Chunwei 已提交
254
        COMMAND cp "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/api/paddle_*.h" "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
S
superjomn 已提交
255
        COMMAND cp "${CMAKE_BINARY_DIR}/libpaddle_api_full_bundled.a" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
C
Chunwei 已提交
256 257
        COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/model_optimize_tool" "${INFER_LITE_PUBLISH_ROOT}/bin"
        COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/gen_code/paddle_code_generator" "${INFER_LITE_PUBLISH_ROOT}/bin"
S
sangoly 已提交
258 259 260 261 262
        COMMAND cp -r "${CMAKE_BINARY_DIR}/third_party/install/glog" "${INFER_LITE_PUBLISH_ROOT}/third_party"
        COMMAND cp -r "${CMAKE_BINARY_DIR}/third_party/install/gflags" "${INFER_LITE_PUBLISH_ROOT}/third_party"
        COMMAND cp -r "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/demo/cxx/mobile_full" "${INFER_LITE_PUBLISH_ROOT}/demo/cxx"
        COMMAND cp "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/demo/cxx/Makefile.def" "${INFER_LITE_PUBLISH_ROOT}/demo/cxx"
        COMMAND cp -r "${CMAKE_BINARY_DIR}/third_party/install/mobilenet_v1" "${INFER_LITE_PUBLISH_ROOT}/demo/models"
C
Chunwei 已提交
263
        )
C
Chunwei 已提交
264 265
add_dependencies(publish_inference_cxx_lib model_optimize_tool)
add_dependencies(publish_inference_cxx_lib paddle_code_generator)
S
superjomn 已提交
266
add_dependencies(publish_inference_cxx_lib bundle_full_api)
S
sangoly 已提交
267
add_dependencies(publish_inference_cxx_lib extern_lite_download_mobilenet_v1_tar_gz)
C
Chunwei 已提交
268 269
add_dependencies(publish_inference_lite publish_inference_cxx_lib)

C
Chunwei 已提交
270

C
Chunwei 已提交
271 272
if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
    #cc_library(inference_mobile_lib DEPS light_api_lite)
S
sangoly 已提交
273
    # copy cpp mobile_light demo/lib
C
Chunwei 已提交
274
    add_custom_target(publish_inference_mobile_lib ${TARGET}
H
Huihuang Zheng 已提交
275 276
            COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
            COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/demo/cxx"
S
sangoly 已提交
277 278
            COMMAND cp "${CMAKE_BINARY_DIR}/libpaddle_api_light_bundled.a" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
            COMMAND cp -r "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/demo/cxx/mobile_light" "${INFER_LITE_PUBLISH_ROOT}/demo/cxx"
C
Chunwei 已提交
279
            )
S
superjomn 已提交
280
    add_dependencies(publish_inference_mobile_lib paddle_api_light bundle_light_api)
C
Chunwei 已提交
281
    add_dependencies(publish_inference_lite publish_inference_mobile_lib)
S
sangoly 已提交
282 283 284 285 286

    if (LITE_WITH_JAVA AND LITE_WITH_ARM)
        # copy java mobile_light demo/lib
        add_custom_target(publish_java_inference_mobile_lib ${TARGET}
                COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/java/so"
H
Huihuang Zheng 已提交
287
                COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/demo/java"
S
sangoly 已提交
288 289
                COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/android/jni/libpaddle_lite_jni.so" "${INFER_LITE_PUBLISH_ROOT}/java/so"
                COMMAND cp -r "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/api/android/jni/src" "${INFER_LITE_PUBLISH_ROOT}/java"
H
Huihuang Zheng 已提交
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
                COMMAND cp -r "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/demo/java/android" "${INFER_LITE_PUBLISH_ROOT}/demo/java"
                COMMAND cp -r "${CMAKE_BINARY_DIR}/third_party/install/inception_v4_simple"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/assets"
                COMMAND cp -r "${CMAKE_BINARY_DIR}/third_party/install/lite_naive_model"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/assets"
                COMMAND cp -r "${CMAKE_BINARY_DIR}/third_party/install/mobilenet_v1"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/assets"
                COMMAND cp -r "${CMAKE_BINARY_DIR}/third_party/install/mobilenet_v2_relu"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/assets"
                COMMAND cp -r "${CMAKE_BINARY_DIR}/third_party/install/resnet50"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/assets"
                COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/android/jni/libpaddle_lite_jni.so"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/jniLibs/arm7"
                COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/android/jni/libpaddle_lite_jni.so"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/jniLibs/arm8"
                COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/android/jni/libpaddle_lite_jni.so"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/jniLibs/arm64-v8a"
                COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/android/jni/libpaddle_lite_jni.so"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/jniLibs/armeabi-v7a"
                COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/android/jni/libpaddle_lite_jni.so"
                    "${INFER_LITE_PUBLISH_ROOT}/demo/java/android/PaddlePredictor/app/src/main/jniLibs/x86"
S
sangoly 已提交
311 312 313 314
                )
        add_dependencies(publish_java_inference_mobile_lib paddle_lite_jni)
        add_dependencies(publish_inference_lite publish_java_inference_mobile_lib)
    endif()
C
Chunwei 已提交
315
endif()