CMakeLists.txt 3.6 KB
Newer Older
1
option(INFRT_WITH_PTEN  "Compile PaddlePaddle InfRT with Paddle Tensor Library." ON)
2

Y
Yan Chunwei 已提交
3 4 5
if (NOT WITH_INFRT)
    return()
endif()
6 7 8 9 10 11 12 13

# 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()

14 15
set(INFRT_SOURCE_DIR "${PADDLE_SOURCE_DIR}/paddle/infrt" )
set(INFRT_BINARY_DIR "${PADDLE_BINARY_DIR}/paddle/infrt" )
16
set(INFRT_TEST_TARGETS CACHE INTERNAL "")
17 18
include(infrt_lib)

Y
Yan Chunwei 已提交
19 20
set(infrt_src CACHE INTERNAL "" FORCE)

21 22 23 24 25 26 27 28 29
if (INFRT_WITH_PTEN)
  add_definitions("-DINFRT_WITH_PTEN")
endif()

if (INFRT_WITH_PTEN)
  #TO DO:remove fluid
  include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform)
endif()

Y
Yan Chunwei 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
# Gather headers for library publish.
function(core_gather_headers)
    file(GLOB includes LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} *.h)

    foreach(header ${includes})
        set(core_includes "${core_includes};${header}" CACHE INTERNAL "")
    endforeach()
endfunction()

function(gather_srcs SRC_GROUP)
    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()
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)
    cmake_parse_arguments(cc_test_tiny "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
    add_executable(${TARGET_NAME} ${cc_test_tiny_SRCS})
    get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
    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)

    add_test(NAME ${TARGET_NAME}
      COMMAND ${TARGET_NAME} "${cc_test_tiny_ARGS}"
            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
    if (${cc_test_tiny_SERIAL})
      set_property(TEST ${TARGET_NAME} PROPERTY RUN_SERIAL 1)
    endif()
68
    set(INFRT_TEST_TARGETS ${INFRT_TEST_TARGETS} ${TARGET_NAME} CACHE INTERNAL "")
Y
Yan Chunwei 已提交
69 70 71 72 73 74 75 76 77 78
  endif()

endfunction()

if (WITH_TESTING)
    cc_library(infrt_gtest_main SRCS gtest_main.cc DEPS gtest glog gflags)
endif()


add_subdirectory(api)
79
add_subdirectory(backends)
Y
Yan Chunwei 已提交
80 81 82 83 84 85 86 87
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)
88
add_subdirectory(tests)
Y
Yan Chunwei 已提交
89 90 91 92 93 94 95 96 97 98


# MLIR td file generations
set(infrt_mlir_incs
        basic_kernels_inc
        test_kernels_inc
        infrt_base_inc
        tensor_shape_inc
        dense_tensor_inc
        pd_ops_inc
99
        pd_extra_ops_inc
Y
Yan Chunwei 已提交
100
        rewrite_inc
101
        trt_ops_inc
Y
Yan Chunwei 已提交
102 103 104
        )
message(STATUS "infrt srcs:\n${infrt_src}")

105 106 107 108 109
if (INFRT_WITH_PTEN)
cc_library(infrt SHARED SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto pten dense_tensor)
cc_library(infrt_static SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto pten dense_tensor)
add_dependencies(infrt ${infrt_mlir_incs})
else()
110 111
cc_library(infrt SHARED SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto)
cc_library(infrt_static SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto)
Y
Yan Chunwei 已提交
112
add_dependencies(infrt ${infrt_mlir_incs})
113
endif()
114 115

add_custom_target(test_infrt_exec DEPENDS ${INFRT_TEST_TARGETS})