tensorrt.cmake 1.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 22 23 24 25
find_path(TENSORRT_INCLUDE_DIR NvInfer.h
    PATHS ${TENSORRT_ROOT} ${TENSORRT_ROOT}/include
    $ENV{TENSORRT_ROOT} $ENV{TENSORRT_ROOT}/include
    NO_DEFAULT_PATH
)

26
find_library(TENSORRT_LIBRARY NAMES ${TR_INFER_LIB} ${TR_INFER_RT}
L
Luo Tao 已提交
27 28 29 30 31 32
    PATHS ${TENSORRT_ROOT} ${TENSORRT_ROOT}/lib
    $ENV{TENSORRT_ROOT} $ENV{TENSORRT_ROOT}/lib
    NO_DEFAULT_PATH
    DOC "Path to TensorRT library.")

if(TENSORRT_INCLUDE_DIR AND TENSORRT_LIBRARY)
D
dzhwinter 已提交
33
  if(WITH_DSO)
L
Luo Tao 已提交
34
    set(TENSORRT_FOUND ON)
X
xzl 已提交
35
  endif(WITH_DSO)
L
Luo Tao 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48
else()
    set(TENSORRT_FOUND OFF)
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}")
    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 已提交
49
    include_directories(${TENSORRT_INCLUDE_DIR})
N
nhzlx 已提交
50
    link_directories(${TENSORRT_LIBRARY})
51
    add_definitions(-DPADDLE_WITH_TENSORRT)
L
Luo Tao 已提交
52
endif()