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

function(inference_download INSTALL_DIR URL FILENAME)
  message(STATUS "Download inference test stuff from ${URL}/${FILENAME}")
  string(REGEX REPLACE "[-%.]" "_" FILENAME_EX ${FILENAME})
  ExternalProject_Add(
      extern_inference_download_${FILENAME_EX}
      ${EXTERNAL_PROJECT_LOG_ARGS}
      PREFIX                ${INSTALL_DIR}
      URL                   ${URL}/${FILENAME}
T
Tao Luo 已提交
16
      DOWNLOAD_COMMAND      wget --no-check-certificate -q -O ${INSTALL_DIR}/${FILENAME} ${URL}/${FILENAME}
17 18 19 20 21 22 23
      DOWNLOAD_DIR          ${INSTALL_DIR}
      DOWNLOAD_NO_PROGRESS  1
      CONFIGURE_COMMAND     ""
      BUILD_COMMAND         ""
      UPDATE_COMMAND        ""
      INSTALL_COMMAND       ""
  )
24 25
endfunction()

26 27
function(inference_download_and_uncompress INSTALL_DIR URL FILENAME)
  message(STATUS "Download inference test stuff from ${URL}/${FILENAME}")
28 29
  string(REGEX REPLACE "[-%./\\]" "_" FILENAME_EX ${FILENAME})
  string(REGEX MATCH "[^/\\]+$" DOWNLOAD_NAME ${FILENAME})
30 31 32 33 34 35
  set(EXTERNAL_PROJECT_NAME "extern_inference_download_${FILENAME_EX}")
  set(UNPACK_DIR "${INSTALL_DIR}/src/${EXTERNAL_PROJECT_NAME}")
  ExternalProject_Add(
      ${EXTERNAL_PROJECT_NAME}
      ${EXTERNAL_PROJECT_LOG_ARGS}
      PREFIX                ${INSTALL_DIR}
36
      URL                   ${URL}/${FILENAME}
37
      DOWNLOAD_DIR          ${INSTALL_DIR}
38
      DOWNLOAD_NO_EXTRACT   1
39 40
      DOWNLOAD_NO_PROGRESS  1
      CONFIGURE_COMMAND     ""
41
      BUILD_COMMAND         ${CMAKE_COMMAND} -E chdir ${INSTALL_DIR}
42
                            ${CMAKE_COMMAND} -E tar xzf ${DOWNLOAD_NAME}
43
      UPDATE_COMMAND        ""
44
      INSTALL_COMMAND       ""
45
  )
46 47 48
endfunction()

set(WORD2VEC_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/word2vec")
Z
Zhou Wei 已提交
49
if(NOT EXISTS ${WORD2VEC_INSTALL_DIR}/word2vec.inference.model.tar.gz)
50
  inference_download_and_uncompress(${WORD2VEC_INSTALL_DIR} ${INFERENCE_URL} "word2vec.inference.model.tar.gz")
51 52 53
endif()
set(WORD2VEC_MODEL_DIR "${WORD2VEC_INSTALL_DIR}/word2vec.inference.model")

54
function (inference_base_test_build TARGET)
55 56
   set(options "")
   set(oneValueArgs "")
57 58 59 60 61 62 63 64 65
   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})
endfunction()

function (inference_base_test_run TARGET)
   set(options "")
   set(oneValueArgs "")
   set(multiValueArgs COMMAND ARGS)
66 67 68 69
   cmake_parse_arguments(base_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
   if(WITH_GPU)
       set(mem_opt "--fraction_of_gpu_memory_to_use=0.5")
   endif()
70
   cc_test_run(${TARGET} COMMAND ${base_test_COMMAND} ARGS ${mem_opt} ${base_test_ARGS})
71
endfunction()
72 73 74 75 76 77 78 79 80 81 82 83 84 85

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})
endfunction()