Skip to content

Commit 1fd0ca8

Browse files
authored
merge from develop: add tensorrt support for win test=develop (#19172)
* merge from develop: add tensorrt support for win test=develop
1 parent 5a86891 commit 1fd0ca8

File tree

12 files changed

+61
-19
lines changed

12 files changed

+61
-19
lines changed

cmake/configure.cmake

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,20 @@ if(WITH_GPU)
8888
include_directories(${CUDA_TOOLKIT_INCLUDE})
8989

9090
if(TENSORRT_FOUND)
91-
if(${CUDA_VERSION_MAJOR} VERSION_LESS 8)
92-
message(FATAL_ERROR "TensorRT needs CUDA >= 8.0 to compile")
93-
endif()
94-
if(${CUDNN_MAJOR_VERSION} VERSION_LESS 7)
95-
message(FATAL_ERROR "TensorRT needs CUDNN >= 7.0 to compile")
96-
endif()
97-
if(${TENSORRT_MAJOR_VERSION} VERSION_LESS 4)
98-
message(FATAL_ERROR "Paddle needs TensorRT >= 4.0 to compile")
91+
if(WIN32)
92+
if(${CUDA_VERSION_MAJOR} VERSION_LESS 9)
93+
message(FATAL_ERROR "TensorRT needs CUDA >= 9.0 to compile on Windows")
94+
endif()
95+
else()
96+
if(${CUDA_VERSION_MAJOR} VERSION_LESS 8)
97+
message(FATAL_ERROR "TensorRT needs CUDA >= 8.0 to compile")
98+
endif()
99+
if(${CUDNN_MAJOR_VERSION} VERSION_LESS 7)
100+
message(FATAL_ERROR "TensorRT needs CUDNN >= 7.0 to compile")
101+
endif()
102+
if(${TENSORRT_MAJOR_VERSION} VERSION_LESS 4)
103+
message(FATAL_ERROR "Paddle needs TensorRT >= 4.0 to compile")
104+
endif()
99105
endif()
100106
include_directories(${TENSORRT_INCLUDE_DIR})
101107
endif()

cmake/inference_lib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ endif ()
218218

219219
if (TENSORRT_FOUND)
220220
copy(tensorrt_lib DEPS ${inference_deps}
221-
SRCS ${TENSORRT_ROOT}/include/Nv*.h ${TENSORRT_ROOT}/lib/libnvinfer*
221+
SRCS ${TENSORRT_ROOT}/include/Nv*.h ${TENSORRT_ROOT}/lib/*nvinfer*
222222
DSTS ${FLUID_INSTALL_DIR}/third_party/install/tensorrt/include ${FLUID_INSTALL_DIR}/third_party/install/tensorrt/lib)
223223
endif ()
224224

cmake/tensorrt.cmake

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@ if(NOT WITH_GPU)
22
return()
33
endif()
44

5-
set(TENSORRT_ROOT "/usr" CACHE PATH "TENSORRT ROOT")
5+
if(WIN32)
6+
if("${TENSORRT_ROOT}" STREQUAL "")
7+
message(WARNING "Please specify the TensorRT root path: TENSORRT_ROOT.")
8+
endif()
9+
string(REPLACE "\\" "/" TENSORRT_ROOT "${TENSORRT_ROOT}")
10+
set(TR_INFER_LIB nvinfer.lib)
11+
set(TR_INFER_RT nvinfer.dll)
12+
set(TR_INFER_PLUGIN_RT nvinfer_plugin.dll)
13+
else()
14+
set(TENSORRT_ROOT "/usr" CACHE PATH "TENSORRT ROOT")
15+
set(TR_INFER_LIB libnvinfer.a)
16+
set(TR_INFER_RT libnvinfer.so)
17+
set(TR_INFER_PLUGIN_RT libnvinfer_plugin.so)
18+
endif()
19+
620
find_path(TENSORRT_INCLUDE_DIR NvInfer.h
721
PATHS ${TENSORRT_ROOT} ${TENSORRT_ROOT}/include
822
$ENV{TENSORRT_ROOT} $ENV{TENSORRT_ROOT}/include
923
NO_DEFAULT_PATH
1024
)
1125

12-
find_library(TENSORRT_LIBRARY NAMES libnvinfer.so libnvinfer.a
26+
find_library(TENSORRT_LIBRARY NAMES ${TR_INFER_LIB} ${TR_INFER_RT}
1327
PATHS ${TENSORRT_ROOT} ${TENSORRT_ROOT}/lib
1428
$ENV{TENSORRT_ROOT} $ENV{TENSORRT_ROOT}/lib
1529
NO_DEFAULT_PATH

paddle/fluid/inference/anakin/convert/op_converter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ template class AnakinOpConverter<::anakin::saber::X86,
219219
#define USE_ANAKIN_CONVERTER_BASE(op_type__, place_type__, precision_type__) \
220220
extern int Touch_anakin_##op_type__##_##place_type__##_##precision_type__(); \
221221
int use_converter_anakin_##op_type__##_##place_type__##_##precision_type__ \
222-
__attribute__((unused)) = \
222+
UNUSED = \
223223
Touch_anakin_##op_type__##_##place_type__##_##precision_type__();
224224

225225
#if defined(PADDLE_WITH_CUDA) && defined(ANAKIN_X86_PLACE)

paddle/fluid/inference/api/demo_ci/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ if(WITH_GPU)
141141
endif()
142142
set(DEPS ${DEPS} ${CUDA_LIB}/libcudart${CMAKE_SHARED_LIBRARY_SUFFIX})
143143
else()
144+
if (USE_TENSORRT)
145+
set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/nvinfer${CMAKE_STATIC_LIBRARY_SUFFIX})
146+
set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/nvinfer_plugin${CMAKE_STATIC_LIBRARY_SUFFIX})
147+
endif()
144148
set(DEPS ${DEPS} ${CUDA_LIB}/cudart${CMAKE_STATIC_LIBRARY_SUFFIX} )
145149
set(DEPS ${DEPS} ${CUDA_LIB}/cublas${CMAKE_STATIC_LIBRARY_SUFFIX} )
146150
set(DEPS ${DEPS} ${CUDA_LIB}/cudnn${CMAKE_STATIC_LIBRARY_SUFFIX} )
@@ -150,6 +154,14 @@ endif()
150154
add_executable(${DEMO_NAME} ${DEMO_NAME}.cc)
151155
target_link_libraries(${DEMO_NAME} ${DEPS})
152156
if(WIN32)
157+
if(USE_TENSORRT)
158+
add_custom_command(TARGET ${DEMO_NAME} POST_BUILD
159+
COMMAND ${CMAKE_COMMAND} -E copy ${TENSORRT_LIB_DIR}/nvinfer${CMAKE_SHARED_LIBRARY_SUFFIX}
160+
${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}
161+
COMMAND ${CMAKE_COMMAND} -E copy ${TENSORRT_LIB_DIR}/nvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX}
162+
${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}
163+
)
164+
endif()
153165
if(WITH_MKL)
154166
add_custom_command(TARGET ${DEMO_NAME} POST_BUILD
155167
COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_PATH}/lib/mkldnn.dll ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}

paddle/fluid/inference/tensorrt/convert/op_converter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class OpConverter {
225225
return 0; \
226226
}
227227

228-
#define USE_TRT_CONVERTER(op_type__) \
229-
extern int TouchConverterRegister_##op_type__(); \
230-
static int use_op_converter_trt_##op_type__ __attribute__((unused)) = \
228+
#define USE_TRT_CONVERTER(op_type__) \
229+
extern int TouchConverterRegister_##op_type__(); \
230+
static int use_op_converter_trt_##op_type__ UNUSED = \
231231
TouchConverterRegister_##op_type__();

paddle/fluid/inference/tensorrt/engine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ class TensorRTEngine {
216216
// TensorRT has too many layers, so that is not wise to add member functions for
217217
// them, and an macro like this is more extensible when underlying TensorRT
218218
// library add new layer supports.
219-
#define TRT_ENGINE_ADD_LAYER(engine__, layer__, ARGS...) \
220-
engine__->network()->add##layer__(ARGS);
219+
#define TRT_ENGINE_ADD_LAYER(engine__, layer__, ...) \
220+
engine__->network()->add##layer__(__VA_ARGS__);
221221

222222
class TRTEngineManager {
223223
public:

paddle/fluid/inference/tensorrt/plugin/prelu_op_plugin.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ int PReluPlugin::initialize() {
3434
cudaMalloc(&p_gpu_weight_, sizeof(float) * weight_.size());
3535
cudaMemcpy(p_gpu_weight_, weight_.data(), weight_.size() * sizeof(float),
3636
cudaMemcpyHostToDevice);
37+
return 0;
3738
}
3839

3940
nvinfer1::Dims PReluPlugin::getOutputDimensions(int index,

paddle/fluid/inference/tensorrt/plugin/trt_plugin_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TrtPluginRegistrar {
6868

6969
#define REGISTER_TRT_PLUGIN_UNIQ(ctr, name, deserialize_func) \
7070
static paddle::inference::tensorrt::plugin::TrtPluginRegistrar \
71-
trt_plugin_registrar##ctr __attribute__((unused)) = \
71+
trt_plugin_registrar##ctr UNUSED = \
7272
paddle::inference::tensorrt::plugin::TrtPluginRegistrar( \
7373
name, deserialize_func)
7474

paddle/fluid/platform/dynload/dynamic_loader.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ void* GetNCCLDsoHandle() {
247247
void* GetTensorRtDsoHandle() {
248248
#if defined(__APPLE__) || defined(__OSX__)
249249
return GetDsoHandleFromSearchPath(FLAGS_tensorrt_dir, "libnvinfer.dylib");
250+
#elif defined(_WIN32)
251+
return GetDsoHandleFromSearchPath(FLAGS_mklml_dir, "nvinfer.dll");
250252
#else
251253
return GetDsoHandleFromSearchPath(FLAGS_tensorrt_dir, "libnvinfer.so");
252254
#endif

0 commit comments

Comments
 (0)