CMakeLists.txt 3.9 KB
Newer Older
1 2
if(NOT WITH_INFRT)
  return()
Y
Yan Chunwei 已提交
3
endif()
4

5 6 7
option(INFRT_WITH_PHI "Compile INFRT with PHI" ON)
option(INFRT_WITH_GPU "Compile INFRT with GPU" OFF)
option(INFRT_WITH_TRT "Compile INFRT with TensorRT" OFF)
8 9 10 11

#TODO(xiaowei) remove fluid
include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform)

12 13 14 15
if(WITH_GPU)
  set(INFRT_WITH_GPU ON)
endif()

16
if(INFRT_WITH_PHI)
W
Wilber 已提交
17 18 19
  add_definitions("-DINFRT_WITH_PHI")

  # TODO(wilber): Now Infrt gpu/trt depends on phi's components, Modify compile dependency options later.
20
  if(INFRT_WITH_GPU)
W
Wilber 已提交
21
    add_definitions("-DINFRT_WITH_GPU")
22
    if(INFRT_WITH_TRT)
W
Wilber 已提交
23 24 25
      add_definitions("-DINFRT_WITH_TRT")
    endif()
  endif()
26 27
endif()

28 29 30 31 32 33 34
# compile flags
set(INFRT_FLAGS -Wno-comment)
foreach(flag ${INFRT_FLAGS})
  safe_set_cflag(CMAKE_C_FLAGS ${flag})
  safe_set_cxxflag(CMAKE_CXX_FLAGS ${flag})
endforeach()

35 36
set(INFRT_SOURCE_DIR "${PADDLE_SOURCE_DIR}/paddle/infrt")
set(INFRT_BINARY_DIR "${PADDLE_BINARY_DIR}/paddle/infrt")
37
set(INFRT_TEST_TARGETS CACHE INTERNAL "")
38 39
include(infrt_lib)

Y
Yan Chunwei 已提交
40 41 42 43
set(infrt_src CACHE INTERNAL "" FORCE)

# Gather headers for library publish.
function(core_gather_headers)
44 45 46 47 48 49 50 51 52 53 54
  file(
    GLOB includes
    LIST_DIRECTORIES false
    RELATIVE ${CMAKE_SOURCE_DIR}
    *.h)

  foreach(header ${includes})
    set(core_includes
        "${core_includes};${header}"
        CACHE INTERNAL "")
  endforeach()
Y
Yan Chunwei 已提交
55 56 57
endfunction()

function(gather_srcs SRC_GROUP)
58 59 60 61 62 63 64 65 66
  set(options)
  set(oneValueArgs)
  set(multiValueArgs "SRCS")
  cmake_parse_arguments(prefix "" "" "${multiValueArgs}" ${ARGN})
  foreach(cpp ${prefix_SRCS})
    set(${SRC_GROUP}
        "${${SRC_GROUP}};${CMAKE_CURRENT_SOURCE_DIR}/${cpp}"
        CACHE INTERNAL "")
  endforeach()
Y
Yan Chunwei 已提交
67 68 69 70 71 72 73 74 75
endfunction()

# This method is similar to the global cc_test, but discard the huge amount default dependencies those are
# not needed by INFRT.
function(cc_test_tiny TARGET_NAME)
  if(WITH_TESTING)
    set(options SERIAL)
    set(oneValueArgs "")
    set(multiValueArgs SRCS DEPS ARGS)
76 77
    cmake_parse_arguments(cc_test_tiny "${options}" "${oneValueArgs}"
                          "${multiValueArgs}" ${ARGN})
Y
Yan Chunwei 已提交
78 79
    add_executable(${TARGET_NAME} ${cc_test_tiny_SRCS})
    get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
80 81 82 83
    target_link_libraries(${TARGET_NAME} ${cc_test_tiny_DEPS}
                          ${os_dependency_modules} infrt_gtest_main gtest)
    add_dependencies(${TARGET_NAME} ${cc_test_tiny_DEPS} infrt_gtest_main gtest
                     extern_gtest)
Y
Yan Chunwei 已提交
84

85 86
    add_test(
      NAME ${TARGET_NAME}
Y
Yan Chunwei 已提交
87
      COMMAND ${TARGET_NAME} "${cc_test_tiny_ARGS}"
88 89
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
    if(${cc_test_tiny_SERIAL})
Y
Yan Chunwei 已提交
90 91
      set_property(TEST ${TARGET_NAME} PROPERTY RUN_SERIAL 1)
    endif()
92 93 94
    set(INFRT_TEST_TARGETS
        ${INFRT_TEST_TARGETS} ${TARGET_NAME}
        CACHE INTERNAL "")
Y
Yan Chunwei 已提交
95 96 97 98
  endif()

endfunction()

99 100 101 102 103
if(WITH_TESTING)
  cc_library(
    infrt_gtest_main
    SRCS gtest_main.cc
    DEPS gtest glog gflags)
Y
Yan Chunwei 已提交
104 105 106
endif()

add_subdirectory(api)
W
Wilber 已提交
107
add_subdirectory(backends)
Y
Yan Chunwei 已提交
108 109 110 111 112 113 114 115
add_subdirectory(common)
add_subdirectory(dialect)
add_subdirectory(host_context)
add_subdirectory(kernel)
add_subdirectory(tensor)
add_subdirectory(support)
add_subdirectory(external_kernels)
add_subdirectory(paddle)
116
add_subdirectory(tests)
Y
Yan Chunwei 已提交
117 118

# MLIR td file generations
119 120 121 122 123 124 125
set(infrt_mlir_incs basic_kernels_inc test_kernels_inc tensor_shape_inc
                    dense_tensor_inc pd_extra_ops_inc trt_ops_inc)

if(INFRT_WITH_PHI)
  set(phi_libs phi)
  set(infrt_mlir_incs ${infrt_mlir_incs} MLIRinfrt_phi_tensorIncGen
                      MLIRinfrt_phi_baseIncGen)
126
endif()
Y
Yan Chunwei 已提交
127

128 129 130 131 132 133 134 135
cc_library(
  infrt SHARED
  SRCS ${infrt_src}
  DEPS glog boost ${mlir_libs} ${phi_libs} paddle_framework_proto infrt_naive)
cc_library(
  infrt_static
  SRCS ${infrt_src}
  DEPS glog boost ${mlir_libs} ${phi_libs} paddle_framework_proto)
136
add_dependencies(infrt ${infrt_mlir_incs} mlir-headers)
137 138

add_custom_target(test_infrt_exec DEPENDS ${INFRT_TEST_TARGETS})