CMakeLists.txt 13.0 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6
if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
  lite_cc_library(place SRCS paddle_place.cc DEPS logging)
else()
  lite_cc_library(place SRCS paddle_place.cc DEPS glog)
endif(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)

7 8 9 10
if (LITE_ON_TINY_PUBLISH)
    set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
    set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
endif()
11
set(light_lib_DEPS light_api paddle_api paddle_api_light optimizer)
H
huzhiqiang 已提交
12
if ((NOT LITE_ON_TINY_PUBLISH) AND (LITE_WITH_X86 OR ARM_TARGET_OS STREQUAL "android"))
13 14 15 16 17
    #full api dynamic library
    add_library(paddle_full_api_shared SHARED "")
    target_sources(paddle_full_api_shared PUBLIC ${__lite_cc_files} paddle_api.cc light_api.cc cxx_api.cc cxx_api_impl.cc light_api_impl.cc)
    add_dependencies(paddle_full_api_shared op_list_h kernel_list_h framework_proto)
    target_link_libraries(paddle_full_api_shared framework_proto)
H
huzhiqiang 已提交
18 19 20 21 22
    add_dependencies(lite_compile_deps paddle_full_api_shared)
    if(LITE_WITH_X86)
       add_dependencies(paddle_full_api_shared xxhash)
       target_link_libraries(paddle_full_api_shared xxhash)
    endif()
23 24 25 26 27
    
    #light api dynamic library
    lite_cc_library(paddle_light_api_shared MODULE
    SRCS light_api_shared.cc
    DEPS ${light_lib_DEPS}
28
    ARM_DEPS ${arm_kernels} NPU_DEPS ${npu_kernels})
29
    target_link_libraries(paddle_light_api_shared ${light_lib_DEPS} ${arm_kernels} ${npu_kernels})
30 31 32 33 34 35
    if (LITE_WITH_NPU)
        # Strips the symbols of our protobuf functions to fix the conflicts during
        # loading HIAI builder libs (libhiai_ir.so and libhiai_ir_build.so)
        set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
        set_target_properties(paddle_light_api_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
    endif()
36
else()
37
    if ((ARM_TARGET_OS STREQUAL "android") OR (ARM_TARGET_OS STREQUAL "armlinux"))
38 39 40
        add_library(paddle_light_api_shared SHARED "")
        target_sources(paddle_light_api_shared PUBLIC ${__lite_cc_files} paddle_api.cc light_api.cc light_api_impl.cc)
        add_dependencies(paddle_light_api_shared op_list_h kernel_list_h)
41 42 43 44
        if (LITE_WITH_NPU)
            # Need to add HIAI runtime libs (libhiai.so) dependency
            target_link_libraries(paddle_light_api_shared ${npu_runtime_libs})
        endif()
45 46 47
    endif()
endif()

Y
Yan Chunwei 已提交
48 49 50 51
if (WITH_TESTING)
    lite_cc_library(lite_api_test_helper SRCS lite_api_test_helper.cc
      DEPS scope optimizer target_wrapper_host model_parser program
           ${ops} ${host_kernels}
52
      CUDA_DEPS ${cuda_kernels}
53 54
      X86_DEPS ${x86_kernels}
      XPU_DEPS ${xpu_kernels})
Y
Yan Chunwei 已提交
55 56 57 58 59 60 61
endif()
if(LITE_WITH_FPGA)
    set(light_api_deps ${light_api_deps} ${fpga_deps})
    set(cxx_api_deps ${cxx_api_deps} ${fpga_deps})
endif()

message(STATUS "get ops ${ops}")
62
message(STATUS "get X86 kernels ${x86_kernels}")
Y
Yan Chunwei 已提交
63 64 65
message(STATUS "get Host kernels ${host_kernels}")
message(STATUS "get ARM kernels ${arm_kernels}")
message(STATUS "get NPU kernels ${npu_kernels}")
66
message(STATUS "get XPU kernels ${xpu_kernels}")
Y
Yan Chunwei 已提交
67 68 69 70 71 72 73 74 75 76 77 78
message(STATUS "get FPGA kernels ${fpga_kernels}")

# for full api
if (NOT LITE_ON_TINY_PUBLISH)
    set(cxx_api_deps
      scope optimizer target_wrapper_host model_parser program)
    lite_cc_library(cxx_api
                    SRCS cxx_api.cc
                    DEPS ${cxx_api_deps} ${ops} ${host_kernels} program
                    X86_DEPS ${x86_kernels}
                    ARM_DEPS ${arm_kernels}
                    NPU_DEPS ${npu_kernels} ${npu_bridges} npu_pass
79
                    XPU_DEPS ${xpu_kernels} ${xpu_bridges} xpu_pass
Y
Yan Chunwei 已提交
80 81 82 83 84 85 86 87 88
                    CL_DEPS ${opencl_kenrels}
                    FPGA_DEPS ${fpga_kenrels})
endif()

# for light api
set(light_api_deps
    scope target_wrapper_host model_parser program)
if(LITE_WITH_CUDA)
    set(light_api_deps ${light_api_deps} target_wrapper_cuda)
89 90
    set(cuda_static_deps cudart_static cublas_static curand_static
        cudnn_static culibos_static)
Y
Yan Chunwei 已提交
91 92 93 94
endif()
lite_cc_library(light_api SRCS light_api.cc
        DEPS scope target_wrapper_host model_parser
            ${light_api_deps} ${ops} ${host_kernels} program
95
        CUDA_DEPS ${cuda_kernels}
Y
Yan Chunwei 已提交
96 97
        X86_DEPS ${x86_kernels}
        ARM_DEPS ${arm_kernels}
98
        NPU_DEPS ${npu_kernels}
99
        XPU_DEPS ${xpu_kernels}
Y
Yan Chunwei 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113
        CL_DEPS ${opencl_kenrels}
        FPGA_DEPS ${fpga_kenrels})

include(ExternalProject)
set(LITE_DEMO_INSTALL_DIR "${THIRD_PARTY_PATH}/inference_demo" CACHE STRING
        "A path setting inference demo download directories.")

if(WITH_TESTING)
    lite_cc_test(test_cxx_api SRCS cxx_api_test.cc
       DEPS cxx_api mir_passes lite_api_test_helper
       ${ops} ${host_kernels}
       X86_DEPS ${x86_kernels}
       ARM_DEPS ${arm_kernels}
       NPU_DEPS ${npu_kernels}
114
       XPU_DEPS ${xpu_kernels}
Y
Yan Chunwei 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
       CL_DEPS ${opencl_kernels}
       FPGA_DEPS ${fpga_kernels}
       EXCLUDE_COMPILE_DEPS "ON"
       ARGS --model_dir=${LITE_MODEL_DIR}/lite_naive_model
            --optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL)
    add_dependencies(test_cxx_api extern_lite_download_lite_naive_model_tar_gz)
    if(NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
        lite_cc_test(test_googlenet SRCS test_googlenet_lite.cc
           DEPS cxx_api mir_passes lite_api_test_helper
           ${ops} ${host_kernels} ${x86_kernels}
           ARGS --model_dir=${LITE_MODEL_DIR}/googlenet)
        add_dependencies(test_googlenet extern_lite_download_GoogleNet_inference_tar_gz)
        lite_cc_test(test_mobilenetv1_lite_x86 SRCS test_mobilenetv1_lite_x86.cc
           DEPS cxx_api mir_passes lite_api_test_helper
           ${ops} ${host_kernels} ${x86_kernels}
           ARGS --model_dir=${LITE_MODEL_DIR}/mobilenet_v1)
        add_dependencies(test_mobilenetv1_lite_x86 extern_lite_download_mobilenet_v1_tar_gz)
        lite_cc_test(test_mobilenetv2_lite_x86 SRCS test_mobilenetv2_lite_x86.cc
           DEPS cxx_api mir_passes lite_api_test_helper
           ${ops} ${host_kernels} ${x86_kernels}
           ARGS --model_dir=${LITE_MODEL_DIR}/mobilenet_v2_relu)
        add_dependencies(test_mobilenetv2_lite_x86 extern_lite_download_mobilenet_v2_relu_tar_gz)
        lite_cc_test(test_inceptionv4_lite_x86 SRCS test_inceptionv4_lite_x86.cc
           DEPS cxx_api mir_passes lite_api_test_helper
           ${ops} ${host_kernels} ${x86_kernels}
           ARGS --model_dir=${LITE_MODEL_DIR}/inception_v4_simple)
        add_dependencies(test_inceptionv4_lite_x86 extern_lite_download_inception_v4_simple_tar_gz)
142 143 144 145 146
        lite_cc_test(test_resnet50_lite_x86 SRCS test_resnet50_lite_x86.cc
           DEPS cxx_api mir_passes lite_api_test_helper
           ${ops} ${host_kernels} ${x86_kernels}
           ARGS --model_dir=${LITE_MODEL_DIR}/resnet50)
        add_dependencies(test_resnet50_lite_x86 extern_lite_download_resnet50_tar_gz)
Y
Yan Chunwei 已提交
147 148 149 150 151 152 153 154 155
    endif()
endif()

if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING)
    set(lite_model_test_DEPS cxx_api mir_passes ${ops} ${host_kernels} ${arm_kernels} ${npu_kernels} ${fpga_kernels})

    lite_cc_test(test_mobilenetv1_int8 SRCS mobilenetv1_int8_test.cc
       DEPS ${lite_model_test_DEPS}
       CL_DEPS ${opencl_kernels}
156
       ARGS --cl_path=${CMAKE_SOURCE_DIR}/lite/backends/opencl
Y
Yan Chunwei 已提交
157 158 159 160 161 162 163
        --model_dir=${LITE_MODEL_DIR}/MobilenetV1_quant SERIAL)
    add_dependencies(test_mobilenetv1_int8 extern_lite_download_MobileNetV1_quant_tar_gz)

    lite_cc_test(test_mobilenetv1 SRCS mobilenetv1_test.cc
       DEPS ${lite_model_test_DEPS}
       CL_DEPS ${opencl_kernels}
       NPU_DEPS ${npu_kernels} ${npu_bridges}
164
       ARGS --cl_path=${CMAKE_SOURCE_DIR}/lite/backends/opencl
Y
Yan Chunwei 已提交
165 166 167 168
            --model_dir=${LITE_MODEL_DIR}/mobilenet_v1 SERIAL)
    add_dependencies(test_mobilenetv1 extern_lite_download_mobilenet_v1_tar_gz)
    set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
    set_target_properties(test_mobilenetv1 PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
169

Y
Yan Chunwei 已提交
170 171 172
    lite_cc_test(test_mobilenetv2 SRCS mobilenetv2_test.cc
       DEPS ${lite_model_test_DEPS}
       CL_DEPS ${opencl_kernels}
173
       ARGS --cl_path=${CMAKE_SOURCE_DIR}/lite/backends/opencl
Y
Yan Chunwei 已提交
174 175 176
            --model_dir=${LITE_MODEL_DIR}/mobilenet_v2_relu SERIAL)
    add_dependencies(test_mobilenetv2 extern_lite_download_mobilenet_v2_relu_tar_gz)
    set_target_properties(test_mobilenetv2 PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
177

Y
Yan Chunwei 已提交
178
    lite_cc_test(test_resnet50 SRCS resnet50_test.cc
179
       DEPS ${lite_model_test_DEPS} paddle_api_light
Y
Yan Chunwei 已提交
180 181
       CL_DEPS ${opencl_kernels}
       FPGA_DEPS ${fpga_kernels}
182
       ARGS --cl_path=${CMAKE_SOURCE_DIR}/lite/backends/opencl
Y
Yan Chunwei 已提交
183 184 185 186 187 188 189 190 191 192 193
            --model_dir=${LITE_MODEL_DIR}/resnet50 SERIAL)
    add_dependencies(test_resnet50 extern_lite_download_resnet50_tar_gz)

    lite_cc_test(test_resnet50_fpga SRCS resnet50_test_fpga.cc
       DEPS ${lite_model_test_DEPS}
       CL_DEPS ${opencl_kernels}
       FPGA_DEPS ${fpga_kernels})

    lite_cc_test(test_inceptionv4 SRCS inceptionv4_test.cc
       DEPS ${lite_model_test_DEPS}
       CL_DEPS ${opencl_kernels}
194
       ARGS --cl_path=${CMAKE_SOURCE_DIR}/lite/backends/opencl
Y
Yan Chunwei 已提交
195
            --model_dir=${LITE_MODEL_DIR}/inception_v4 SERIAL)
196
    add_dependencies(test_inceptionv4 extern_lite_download_inception_v4_simple_tar_gz)
T
TianXiaogang 已提交
197 198 199 200 201 202 203
   # lite_cc_test(test_ocr_attention SRCS ocr_attention_test.cc
   #    DEPS ${lite_model_test_DEPS})

   # lite_cc_test(model_run_test_image SRCS model_run_test_image.cc
   #    DEPS ${lite_model_test_DEPS}
   #    CL_DEPS ${opencl_kernels}
   #    FPGA_DEPS ${fpga_kernels})
Y
Yan Chunwei 已提交
204 205
endif()

206
lite_cc_library(paddle_api SRCS paddle_api.cc DEPS op_params tensor device_info)
Y
Yan Chunwei 已提交
207 208 209

#-----------------------------------------------------------------------------------------------------
# The final inference library for both CxxConfig and MobileConfig.
210 211 212 213 214
if (LITE_ON_TINY_PUBLISH)
    lite_cc_library(paddle_api_light SRCS light_api_impl.cc DEPS light_api paddle_api stream)
else()
    lite_cc_library(paddle_api_light SRCS light_api_impl.cc DEPS light_api paddle_api)
endif()
Y
Yan Chunwei 已提交
215
if (NOT LITE_ON_TINY_PUBLISH)
216
    lite_cc_library(paddle_api_full SRCS cxx_api_impl.cc DEPS cxx_api paddle_api_light
Y
Yan Chunwei 已提交
217 218 219 220 221 222 223
      ${ops}
      ARM_DEPS ${arm_kernels}
      NPU_DEPS ${npu_kernels}
      CL_DEPS ${opencl_kernels}
      FPGA_DEPS ${fpga_kernels})
    # The final inference library for just MobileConfig.
    bundle_static_library(paddle_api_full paddle_api_full_bundled bundle_full_api)
224
    get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
225
    cc_library(api_full_static SRCS DEPS paddle_api_full cxx_api paddle_api light_api  ${cxx_api_deps} ${ops} ${host_kernels} ${cuda_kernels} program tensor memory naive_buffer types ${fluid_modules} protobuf ${cuda_static_deps})
Y
Yan Chunwei 已提交
226 227 228 229
endif()
bundle_static_library(paddle_api_light paddle_api_light_bundled bundle_light_api)
#-----------------------------------------------------------------------------------------------------

230 231 232 233 234 235 236 237 238 239 240 241
# These tests needs CLI arguments, and is not supported in ARM CI.
# TODO(Superjomn) support latter.
lite_cc_test(test_light_api SRCS light_api_test.cc
        DEPS light_api program mir_passes paddle_api_light
        CL_DEPS ${opencl_kernels}
        FPGA_DEPS ${fpga_kernels}
        ARGS --optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL)

lite_cc_test(test_apis SRCS apis_test.cc
        DEPS cxx_api light_api ${ops} paddle_api_light
        CL_DEPS ${opencl_kernels}
        X86_DEPS ${x86_kernels}
242
        XPU_DEPS ${xpu_kernels}
243 244 245 246
        FPGA_DEPS ${fpga_kernels}
        ARGS --model_dir=${LITE_MODEL_DIR}/lite_naive_model
        --optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL)

Y
Yan Chunwei 已提交
247 248 249 250
if (LITE_WITH_JAVA AND LITE_WITH_ARM)
    add_subdirectory(android)
endif()

S
sangoly 已提交
251 252 253 254
if (LITE_WITH_PYTHON) 
    add_subdirectory(python)
endif()

Y
Yan Chunwei 已提交
255 256 257
if (LITE_ON_TINY_PUBLISH)
    return()
endif()
258 259 260 261 262 263 264 265

if (LITE_ON_MODEL_OPTIMIZE_TOOL)
    message(STATUS "Compiling model_optimize_tool")
    lite_cc_binary(model_optimize_tool SRCS model_optimize_tool.cc cxx_api_impl.cc paddle_api.cc cxx_api.cc
        DEPS gflags kernel op optimizer mir_passes utils)
    add_dependencies(model_optimize_tool op_list_h kernel_list_h all_kernel_faked_cc)
endif(LITE_ON_MODEL_OPTIMIZE_TOOL)

Y
Yan Chunwei 已提交
266 267 268 269
lite_cc_test(test_paddle_api SRCS paddle_api_test.cc DEPS paddle_api_full paddle_api_light
  ${ops}
  ARM_DEPS ${arm_kernels}
  NPU_DEPS ${npu_kernels}
270
  XPU_DEPS ${xpu_kernels}
Y
Yan Chunwei 已提交
271 272 273 274 275 276 277 278 279 280
  CL_DEPS ${opencl_kernels}
  X86_DEPS ${x86_kernels}
  FPGA_DEPS ${fpga_kernels}
  ARGS --model_dir=${LITE_MODEL_DIR}/lite_naive_model SERIAL)
if (WITH_TESTING)
    add_dependencies(test_paddle_api extern_lite_download_lite_naive_model_tar_gz)
endif()

# Some bins
if(NOT IOS)
281
  lite_cc_binary(test_model_bin SRCS model_test.cc DEPS paddle_api_full paddle_api_light gflags utils
J
juncaipeng 已提交
282
    ${ops} ${host_kernels}
Y
Yan Chunwei 已提交
283 284
    ARM_DEPS ${arm_kernels}
    NPU_DEPS ${npu_kernels}
285
    XPU_DEPS ${xpu_kernels}
Y
Yan Chunwei 已提交
286 287 288
    CL_DEPS ${opencl_kernels}
    FPGA_DEPS ${fpga_kernels}
    X86_DEPS ${x86_kernels})
289
  lite_cc_binary(benchmark_bin SRCS benchmark.cc DEPS paddle_api_full paddle_api_light gflags utils
J
juncaipeng 已提交
290
    ${ops} ${host_kernels}
Y
Yan Chunwei 已提交
291 292
    ARM_DEPS ${arm_kernels}
    NPU_DEPS ${npu_kernels}
293
    XPU_DEPS ${xpu_kernels}
Y
Yan Chunwei 已提交
294 295 296
    CL_DEPS ${opencl_kernels}
    FPGA_DEPS ${fpga_kernels}
    X86_DEPS ${x86_kernels})
Y
Yan Chunwei 已提交
297 298 299 300 301 302
endif()

#lite_cc_binary(cxx_api_bin SRCS cxx_api_bin.cc
    #X86_DEPS operator
    #DEPS light_api model_parser target_wrapper_host mir_passes
    #ARM_DEPS ${arm_kernels}) NPU_DEPS ${npu_kernels})