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

S
superjomn 已提交
5
message(WARNING "Lite enabled!")
6 7 8 9
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 已提交
10
message(STATUS "LITE_WITH_PROFILE:\t${LITE_WITH_PROFILE}")
S
Superjomn 已提交
11

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

S
sangoly 已提交
14
set(LITE_ON_MOBILE ${LITE_WITH_LIGHT_WEIGHT_FRAMEWORK})
C
Chunwei 已提交
15

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

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 已提交
27
            DOWNLOAD_COMMAND      wget --no-check-certificate -q -O ${INSTALL_DIR}/${FILENAME} ${URL}/${FILENAME} && ${CMAKE_COMMAND} -E tar xzf ${INSTALL_DIR}/${FILENAME}
S
superjomn 已提交
28 29 30 31 32 33 34 35 36
            DOWNLOAD_DIR          ${INSTALL_DIR}
            DOWNLOAD_NO_PROGRESS  1
            CONFIGURE_COMMAND     ""
            BUILD_COMMAND         ""
            UPDATE_COMMAND        ""
            INSTALL_COMMAND       ""
    )
endfunction()

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

43
  set(deps ${lite_deps_DEPS})
44 45 46

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

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

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

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

69 70 71 72 73 74 75 76 77 78 79 80
  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 已提交
81 82 83 84 85 86
  if (LITE_WITH_OPENCL)
    foreach(var ${lite_deps_CL_DEPS})
      set(deps ${deps} ${var})
    endforeach(var)
  endif()

87 88
  set(${TARGET} ${deps} PARENT_SCOPE)

89 90
endfunction()

C
Chunwei 已提交
91 92 93
# 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 已提交
94 95 96 97
# 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
98 99 100 101 102 103 104 105
# 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
106
function(lite_cc_library TARGET)
C
Chunwei 已提交
107
    set(options STATIC static SHARED shared)
108
    set(oneValueArgs "")
109 110
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS ARM_DEPS PROFILE_DEPS LIGHT_DEPS
      HVY_DEPS ARGS)
111 112 113 114 115 116 117
    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}
Y
Yan Chunwei 已提交
118
            ARM_DEPS ${args_ARM_DEPS}
119 120 121 122
            PROFILE_DEPS ${args_PROFILE_DEPS}
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
            )
C
Chunwei 已提交
123 124 125 126 127
    if (${args_SHARED} OR ${args_shared})
        cc_library(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS} SHARED)
    else()
        cc_library(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS})
    endif()
Y
Yan Chunwei 已提交
128

C
Chunwei 已提交
129 130 131
    # collect targets need to compile for lite
    add_dependencies(lite_compile_deps ${TARGET})

Y
Yan Chunwei 已提交
132 133
    # register a library name.
    file(APPEND ${offline_lib_registry_file} "${TARGET}\n")
134 135
endfunction()

Y
Yan Chunwei 已提交
136 137 138
function(lite_cc_binary TARGET)
    set(options "")
    set(oneValueArgs "")
139 140
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS ARM_DEPS PROFILE_DEPS
      LIGHT_DEPS HVY_DEPS ARGS)
Y
Yan Chunwei 已提交
141 142 143 144 145 146 147
    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}
Y
Yan Chunwei 已提交
148 149
            ARM_DEPS ${args_ARM_DEPS}
            PROFILE_DEPS ${args_PROFILE_DEPS}
150 151
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
Y
Yan Chunwei 已提交
152
            )
Y
Yan Chunwei 已提交
153
    cc_binary(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS})
C
Chunwei 已提交
154 155
    # collect targets need to compile for lite
    add_dependencies(lite_compile_deps ${TARGET})
Y
Yan Chunwei 已提交
156 157 158 159 160 161
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.
162 163 164
function(lite_cc_test TARGET)
    set(options "")
    set(oneValueArgs "")
165 166 167
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS ARM_DEPS PROFILE_DEPS
      LIGHT_DEPS HVY_DEPS
      ARGS)
168 169 170 171 172 173 174 175
    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}
            ARM_DEPS ${args_ARM_DEPS}
Y
Yan Chunwei 已提交
176
            PROFILE_DEPS ${args_PROFILE_DEPS}
177 178
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
179
            )
Y
Yan Chunwei 已提交
180
    _lite_cc_test(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ARGS ${args_ARGS})
Y
Yan Chunwei 已提交
181
    file(APPEND ${offline_test_registry_file} "${TARGET}\n")
C
Chunwei 已提交
182 183 184

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

Z
Zhen Wang 已提交
187 188
add_subdirectory(operators)
add_subdirectory(kernels)
S
update  
superjomn 已提交
189
add_subdirectory(core)
S
superjomn 已提交
190
add_subdirectory(x86)
T
tensor-tang 已提交
191
add_subdirectory(arm)
192
add_subdirectory(host)
193
add_subdirectory(cuda)
Z
Zhen Wang 已提交
194
add_subdirectory(opencl)
S
superjomn 已提交
195
add_subdirectory(model_parser)
S
superjomn 已提交
196
add_subdirectory(utils)
S
superjomn 已提交
197
add_subdirectory(api)
198
add_subdirectory(gen_code)
199
add_subdirectory(tools)
C
Chunwei 已提交
200 201 202 203


if (WITH_TESTING)
    lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "lite_naive_model.tar.gz")
S
sangoly 已提交
204
    if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
205
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v1.tar.gz")
S
sangoly 已提交
206
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v2_relu.tar.gz")
207
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "resnet50.tar.gz")
S
sangoly 已提交
208
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "inception_v4_simple.tar.gz")
S
sangoly 已提交
209
    endif()
210 211 212
    if(NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
        lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "GoogleNet_inference.tar.gz")
    endif()
C
Chunwei 已提交
213
endif()
C
Chunwei 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

# for publish
set(INFER_LITE_PUBLISH_ROOT "${CMAKE_BINARY_DIR}/inference_lite_lib" CACHE STRING "inference publish path")
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"
        COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
        COMMAND cp "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/api/paddle_*.h" "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
        COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/libpaddle_api_full.a" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
        )
add_dependencies(publish_inference_cxx_lib paddle_api_full)
add_dependencies(publish_inference_lite publish_inference_cxx_lib)

if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
    #cc_library(inference_mobile_lib DEPS light_api_lite)

    add_custom_target(publish_inference_mobile_lib ${TARGET}
            COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/mobile/lib"
            COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/mobile/include"
            COMMAND cp "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/api/paddle_*.h" "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
            COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/libpaddle_api_light.a" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
            )
    add_dependencies(publish_inference_mobile_lib paddle_api_light)
    add_dependencies(publish_inference_lite publish_inference_mobile_lib)
endif()