tensorrt.cmake 2.7 KB
Newer Older
L
Luo Tao 已提交
1 2 3 4
if(NOT WITH_GPU)
    return()
endif()

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
if(WIN32)
    if("${TENSORRT_ROOT}" STREQUAL "")
        message(WARNING "Please specify the TensorRT root path: TENSORRT_ROOT.")
    endif()
    string(REPLACE "\\" "/" TENSORRT_ROOT "${TENSORRT_ROOT}")
    set(TR_INFER_LIB nvinfer.lib)
    set(TR_INFER_RT nvinfer.dll)
    set(TR_INFER_PLUGIN_RT nvinfer_plugin.dll)
else()
    set(TENSORRT_ROOT "/usr" CACHE PATH "TENSORRT ROOT")
    set(TR_INFER_LIB libnvinfer.a)
    set(TR_INFER_RT libnvinfer.so)
    set(TR_INFER_PLUGIN_RT libnvinfer_plugin.so)
endif()

L
Luo Tao 已提交
20 21
find_path(TENSORRT_INCLUDE_DIR NvInfer.h
    PATHS ${TENSORRT_ROOT} ${TENSORRT_ROOT}/include
J
Jeng Bai-Cheng 已提交
22
    ${TENSORRT_ROOT}/include/${CMAKE_LIBRARY_ARCHITECTURE}
L
Luo Tao 已提交
23
    $ENV{TENSORRT_ROOT} $ENV{TENSORRT_ROOT}/include
J
Jeng Bai-Cheng 已提交
24
    $ENV{TENSORRT_ROOT}/include/${CMAKE_LIBRARY_ARCHITECTURE}
L
Luo Tao 已提交
25 26 27
    NO_DEFAULT_PATH
)

J
Jeng Bai-Cheng 已提交
28
find_path(TENSORRT_LIBRARY_DIR NAMES ${TR_INFER_LIB} ${TR_INFER_RT}
L
Luo Tao 已提交
29
    PATHS ${TENSORRT_ROOT} ${TENSORRT_ROOT}/lib
J
Jeng Bai-Cheng 已提交
30
    ${TENSORRT_ROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE}
L
Luo Tao 已提交
31
    $ENV{TENSORRT_ROOT} $ENV{TENSORRT_ROOT}/lib
J
Jeng Bai-Cheng 已提交
32 33 34 35 36 37 38
    $ENV{TENSORRT_ROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE}
    NO_DEFAULT_PATH
    DOC "Path to TensorRT library."
)

find_library(TENSORRT_LIBRARY NAMES ${TR_INFER_LIB} ${TR_INFER_RT}
    PATHS ${TENSORRT_LIBRARY_DIR}
L
Luo Tao 已提交
39 40 41 42
    NO_DEFAULT_PATH
    DOC "Path to TensorRT library.")

if(TENSORRT_INCLUDE_DIR AND TENSORRT_LIBRARY)
D
dzhwinter 已提交
43
  if(WITH_DSO)
L
Luo Tao 已提交
44
    set(TENSORRT_FOUND ON)
X
xzl 已提交
45
  endif(WITH_DSO)
L
Luo Tao 已提交
46 47
else()
    set(TENSORRT_FOUND OFF)
J
Jeng Bai-Cheng 已提交
48 49 50 51 52
    if(WITH_DSO)
        message(WARNING "TensorRT is NOT found.")
    else(WITH_DSO)
        message(WARNING "TensorRT is disabled because WITH_DSO is OFF.")
    endif(WITH_DSO)
L
Luo Tao 已提交
53 54 55 56 57 58
endif()

if(TENSORRT_FOUND)
    file(READ ${TENSORRT_INCLUDE_DIR}/NvInfer.h TENSORRT_VERSION_FILE_CONTENTS)
    string(REGEX MATCH "define NV_TENSORRT_MAJOR +([0-9]+)" TENSORRT_MAJOR_VERSION
        "${TENSORRT_VERSION_FILE_CONTENTS}")
J
Jeng Bai-Cheng 已提交
59 60 61 62 63 64 65 66 67 68 69

    if("${TENSORRT_MAJOR_VERSION}" STREQUAL "")
        file(READ ${TENSORRT_INCLUDE_DIR}/NvInferVersion.h TENSORRT_VERSION_FILE_CONTENTS)
        string(REGEX MATCH "define NV_TENSORRT_MAJOR +([0-9]+)" TENSORRT_MAJOR_VERSION
        "${TENSORRT_VERSION_FILE_CONTENTS}")
    endif()

    if("${TENSORRT_MAJOR_VERSION}" STREQUAL "")
        message(SEND_ERROR "Failed to detect TensorRT version.")
    endif()

L
Luo Tao 已提交
70 71 72 73 74
    string(REGEX REPLACE "define NV_TENSORRT_MAJOR +([0-9]+)" "\\1"
        TENSORRT_MAJOR_VERSION "${TENSORRT_MAJOR_VERSION}")

    message(STATUS "Current TensorRT header is ${TENSORRT_INCLUDE_DIR}/NvInfer.h. "
        "Current TensorRT version is v${TENSORRT_MAJOR_VERSION}. ")
L
Luo Tao 已提交
75
    include_directories(${TENSORRT_INCLUDE_DIR})
N
nhzlx 已提交
76
    link_directories(${TENSORRT_LIBRARY})
77
    add_definitions(-DPADDLE_WITH_TENSORRT)
L
Luo Tao 已提交
78
endif()