CMakeLists.txt 5.3 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 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
set(LITE_MODEL_DIR "${THIRD_PARTY_PATH}/install")

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}
            DOWNLOAD_COMMAND      wget --no-check-certificate -q -O ${INSTALL_DIR}/${FILENAME} ${URL}/${FILENAME} &&
            ${CMAKE_COMMAND} -E tar xzf ${INSTALL_DIR}/${FILENAME}
            DOWNLOAD_DIR          ${INSTALL_DIR}
            DOWNLOAD_NO_PROGRESS  1
            CONFIGURE_COMMAND     ""
            BUILD_COMMAND         ""
            UPDATE_COMMAND        ""
            INSTALL_COMMAND       ""
    )
endfunction()

34
function (lite_deps TARGET)
35 36
  set(options "")
  set(oneValueArgs "")
37
  set(multiValueArgs DEPS X86_DEPS CUDA_DEPS ARM_DEPS PROFILE_DEPS LIGHT_DEPS HVY_DEPS ARGS)
38 39
  cmake_parse_arguments(lite_deps "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

40
  set(deps ${lite_deps_DEPS})
41 42 43

  if(LITE_WITH_X86)
    foreach(var ${lite_deps_X86_DEPS})
44 45
      set(deps ${deps} ${var})
    endforeach(var)
46 47 48 49
  endif()

  if(LITE_WITH_CUDA)
    foreach(var ${lite_deps_CUDA_DEPS})
50 51
      set(deps ${deps} ${var})
    endforeach(var)
52 53 54 55
  endif()

  if(LITE_WITH_ARM)
    foreach(var ${lite_deps_ARM_DEPS})
56 57
      set(deps ${deps} ${var})
    endforeach(var)
58
  endif()
59

Y
Yan Chunwei 已提交
60 61 62 63 64 65
  if(LITE_WITH_PROFILE)
    foreach(var ${lite_deps_PROFILE_DEPS})
      set(deps ${deps} ${var})
    endforeach(var)
  endif()

66 67 68 69 70 71 72 73 74 75 76 77
  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()

78 79
  set(${TARGET} ${deps} PARENT_SCOPE)

80 81
endfunction()

82 83 84 85 86 87 88 89
# 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
90 91 92
function(lite_cc_library TARGET)
    set(options "")
    set(oneValueArgs "")
93 94
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS ARM_DEPS PROFILE_DEPS LIGHT_DEPS
      HVY_DEPS ARGS)
95 96 97 98 99 100 101
    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 已提交
102
            ARM_DEPS ${args_ARM_DEPS}
103 104 105 106
            PROFILE_DEPS ${args_PROFILE_DEPS}
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
            )
107

Y
Yan Chunwei 已提交
108
    cc_library(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS})
109 110
endfunction()

Y
Yan Chunwei 已提交
111 112 113
function(lite_cc_binary TARGET)
    set(options "")
    set(oneValueArgs "")
114 115
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS ARM_DEPS PROFILE_DEPS
      LIGHT_DEPS HVY_DEPS ARGS)
Y
Yan Chunwei 已提交
116 117 118 119 120 121 122
    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 已提交
123 124
            ARM_DEPS ${args_ARM_DEPS}
            PROFILE_DEPS ${args_PROFILE_DEPS}
125 126
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
Y
Yan Chunwei 已提交
127
            )
Y
Yan Chunwei 已提交
128 129 130 131 132 133 134 135 136 137 138
    cc_binary(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS})
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
function (register_test_offline TARGET)
  file(APPEND ${offline_test_registry_file} "${TARGET}\n")
endfunction()

# Test lite modules.
139 140 141
function(lite_cc_test TARGET)
    set(options "")
    set(oneValueArgs "")
142 143 144
    set(multiValueArgs SRCS DEPS X86_DEPS CUDA_DEPS ARM_DEPS PROFILE_DEPS
      LIGHT_DEPS HVY_DEPS
      ARGS)
145 146 147 148 149 150 151 152
    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 已提交
153
            PROFILE_DEPS ${args_PROFILE_DEPS}
154 155
            LIGHT_DEPS ${args_LIGHT_DEPS}
            HVY_DEPS ${args_HVY_DEPS}
156
            )
Y
Yan Chunwei 已提交
157 158
    _lite_cc_test(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ARGS ${args_ARGS})
    register_test_offline("${TARGET}")
159
endfunction()
S
superjomn 已提交
160

S
update  
superjomn 已提交
161
add_subdirectory(core)
S
superjomn 已提交
162
add_subdirectory(x86)
T
tensor-tang 已提交
163
add_subdirectory(arm)
164
add_subdirectory(host)
165
add_subdirectory(cuda)
S
superjomn 已提交
166 167 168
add_subdirectory(operators)
add_subdirectory(kernels)
add_subdirectory(model_parser)
S
superjomn 已提交
169
add_subdirectory(utils)
S
superjomn 已提交
170
add_subdirectory(api)
171
add_subdirectory(gen_code)