test.cmake 5.1 KB
Newer Older
1
include(ExternalProject)
2 3 4 5 6 7 8 9 10 11 12 13
set(INFERENCE_URL
    "http://paddle-inference-dist.bj.bcebos.com"
    CACHE STRING "inference download url")
set(INFERENCE_DEMO_INSTALL_DIR
    "${THIRD_PARTY_PATH}/inference_demo"
    CACHE STRING "A path setting inference demo download directories.")
set(CPU_NUM_THREADS_ON_CI
    4
    CACHE STRING "Run multi-threads on CI to reduce CI time.")
set(WARMUP_BATCH_SIZE
    100
    CACHE STRING "Default warmup_batch_size.")
14 15 16 17 18

function(inference_download INSTALL_DIR URL FILENAME)
  message(STATUS "Download inference test stuff from ${URL}/${FILENAME}")
  string(REGEX REPLACE "[-%.]" "_" FILENAME_EX ${FILENAME})
  ExternalProject_Add(
19 20 21 22 23 24 25 26 27 28 29 30
    extern_inference_download_${FILENAME_EX}
    ${EXTERNAL_PROJECT_LOG_ARGS}
    PREFIX ${INSTALL_DIR}
    URL ${URL}/${FILENAME}
    DOWNLOAD_COMMAND wget --no-check-certificate -q -O
                     ${INSTALL_DIR}/${FILENAME} ${URL}/${FILENAME}
    DOWNLOAD_DIR ${INSTALL_DIR}
    DOWNLOAD_NO_PROGRESS 1
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    UPDATE_COMMAND ""
    INSTALL_COMMAND "")
31 32
endfunction()

W
Wangzheee 已提交
33 34 35 36 37 38 39
function(inference_download_and_uncompress INSTALL_DIR URL FILENAME CHECK_SUM)
  message(STATUS "Download inference test stuff from ${URL}/${FILENAME}")
  string(REGEX REPLACE "[-%./\\]" "_" FILENAME_EX ${FILENAME})
  string(REGEX MATCH "[^/\\]+$" DOWNLOAD_NAME ${FILENAME})
  set(EXTERNAL_PROJECT_NAME "extern_download_${FILENAME_EX}")
  set(UNPACK_DIR "${INSTALL_DIR}/src/${EXTERNAL_PROJECT_NAME}")
  ExternalProject_Add(
40 41 42 43 44 45 46 47 48 49 50 51 52
    ${EXTERNAL_PROJECT_NAME}
    ${EXTERNAL_PROJECT_LOG_ARGS}
    PREFIX ${INSTALL_DIR}
    URL ${URL}/${FILENAME}
    URL_HASH MD5=${CHECK_SUM}
    DOWNLOAD_DIR ${INSTALL_DIR}
    DOWNLOAD_NO_EXTRACT 1
    DOWNLOAD_NO_PROGRESS 1
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ${CMAKE_COMMAND} -E chdir ${INSTALL_DIR} ${CMAKE_COMMAND} -E
                  tar xzf ${DOWNLOAD_NAME}
    UPDATE_COMMAND ""
    INSTALL_COMMAND "")
W
Wangzheee 已提交
53 54
endfunction()

55 56
function(inference_download_and_uncompress_without_verify INSTALL_DIR URL
         FILENAME)
57
  message(STATUS "Download inference test stuff from ${URL}/${FILENAME}")
58 59
  string(REGEX REPLACE "[-%./\\]" "_" FILENAME_EX ${FILENAME})
  string(REGEX MATCH "[^/\\]+$" DOWNLOAD_NAME ${FILENAME})
60
  set(EXTERNAL_PROJECT_NAME "extern_download_${FILENAME_EX}")
61 62
  set(UNPACK_DIR "${INSTALL_DIR}/src/${EXTERNAL_PROJECT_NAME}")
  ExternalProject_Add(
63 64 65 66 67 68 69 70 71 72 73 74
    ${EXTERNAL_PROJECT_NAME}
    ${EXTERNAL_PROJECT_LOG_ARGS}
    PREFIX ${INSTALL_DIR}
    URL ${URL}/${FILENAME}
    DOWNLOAD_DIR ${INSTALL_DIR}
    DOWNLOAD_NO_EXTRACT 1
    DOWNLOAD_NO_PROGRESS 1
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ${CMAKE_COMMAND} -E chdir ${INSTALL_DIR} ${CMAKE_COMMAND} -E
                  tar xzf ${DOWNLOAD_NAME}
    UPDATE_COMMAND ""
    INSTALL_COMMAND "")
75 76 77
endfunction()

set(WORD2VEC_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/word2vec")
Z
Zhou Wei 已提交
78
if(NOT EXISTS ${WORD2VEC_INSTALL_DIR}/word2vec.inference.model.tar.gz)
79 80
  inference_download_and_uncompress_without_verify(
    ${WORD2VEC_INSTALL_DIR} ${INFERENCE_URL} "word2vec.inference.model.tar.gz")
81 82 83
endif()
set(WORD2VEC_MODEL_DIR "${WORD2VEC_INSTALL_DIR}/word2vec.inference.model")

84 85 86 87 88 89 90 91
set(IMG_CLS_RESNET_INSTALL_DIR
    "${INFERENCE_DEMO_INSTALL_DIR}/image_classification_resnet")
if(NOT EXISTS
   ${IMG_CLS_RESNET_INSTALL_DIR}/image_classification_resnet.inference.model.tgz
)
  inference_download_and_uncompress_without_verify(
    ${IMG_CLS_RESNET_INSTALL_DIR} ${INFERENCE_URL}
    "image_classification_resnet.inference.model.tgz")
W
Wilber 已提交
92
endif()
93 94
set(IMG_CLS_RESNET_MODEL_DIR
    "${IMG_CLS_RESNET_INSTALL_DIR}/image_classification_resnet.inference.model")
W
Wilber 已提交
95

96 97 98
if(WITH_ONNXRUNTIME)
  set(MOBILENETV2_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/MobileNetV2")
  if(NOT EXISTS ${MOBILENETV2_INSTALL_DIR}/MobileNetV2.inference.model.tar.gz)
99 100 101
    inference_download_and_uncompress_without_verify(
      ${MOBILENETV2_INSTALL_DIR} ${INFERENCE_URL}
      "MobileNetV2.inference.model.tar.gz")
102 103 104 105
  endif()
  set(MOBILENETV2_MODEL_DIR "${MOBILENETV2_INSTALL_DIR}/MobileNetV2")
endif()

106 107 108 109 110 111 112
function(inference_base_test_build TARGET)
  set(options "")
  set(oneValueArgs "")
  set(multiValueArgs SRCS DEPS)
  cmake_parse_arguments(base_test "${options}" "${oneValueArgs}"
                        "${multiValueArgs}" ${ARGN})
  cc_test_build(${TARGET} SRCS ${base_test_SRCS} DEPS ${base_test_DEPS})
113 114
endfunction()

115 116 117 118 119 120 121 122 123 124 125
function(inference_base_test_run TARGET)
  set(options "")
  set(oneValueArgs "")
  set(multiValueArgs COMMAND ARGS)
  cmake_parse_arguments(base_test "${options}" "${oneValueArgs}"
                        "${multiValueArgs}" ${ARGN})
  if(WITH_GPU)
    set(mem_opt "--fraction_of_gpu_memory_to_use=0.5")
  endif()
  cc_test_run(${TARGET} COMMAND ${base_test_COMMAND} ARGS ${mem_opt}
              ${base_test_ARGS})
126
endfunction()
127

128 129 130 131 132 133 134 135 136
function(inference_base_test TARGET)
  set(options "")
  set(oneValueArgs "")
  set(multiValueArgs SRCS ARGS DEPS)
  cmake_parse_arguments(base_test "${options}" "${oneValueArgs}"
                        "${multiValueArgs}" ${ARGN})
  inference_base_test_build(${TARGET} SRCS ${base_test_SRCS} DEPS
                            ${base_test_DEPS})
  inference_base_test_run(${TARGET} COMMAND ${TARGET} ARGS ${base_test_ARGS})
137
endfunction()