-
Notifications
You must be signed in to change notification settings - Fork 675
[Enhancement] fix-cmake-relocatable #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
9c47c14
a54dd2c
2897ac2
d2b225b
46bf20d
9ba5c50
f3a794d
14ad701
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,17 @@ if (NOT MMDEPLOY_BUILD_SHARED) | |
endif () | ||
endif () | ||
|
||
set(MMDEPLOY_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules") | ||
list(APPEND CMAKE_MODULE_PATH ${MMDEPLOY_MODULE_PATH}) | ||
if ("trt" IN_LIST MMDEPLOY_TARGET_BACKENDS) | ||
find_package(CUDNN) | ||
find_package(TENSORRT) | ||
endif() | ||
if ("ort" IN_LIST MMDEPLOY_TARGET_BACKENDS) | ||
find_package(ONNXRUNTIME) | ||
endif() | ||
list(POP_BACK CMAKE_MODULE_PATH) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just make CMAKE_MODULE_PATH clean |
||
|
||
find_package(spdlog REQUIRED) | ||
find_package(OpenCV REQUIRED) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
|
||
if (NOT DEFINED CUDNN_DIR) | ||
set(CUDNN_DIR $ENV{CUDNN_DIR}) | ||
endif () | ||
|
||
find_path( | ||
CUDNN_INCLUDE_DIR cudnn.h | ||
HINTS ${CUDNN_DIR} ${CUDA_TOOLKIT_ROOT_DIR} | ||
PATH_SUFFIXES include) | ||
|
||
find_library( | ||
CUDNN_LIBRARY_CUDNN_PATH cudnn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. find_library return lib path instead of directory path like find_path. Since there are may libs in {CUDNN_DIR}/lib64, I use {CUDNN_LIBRARY_XX_PATH} to indicate a specific xx lib path. |
||
HINTS ${CUDNN_DIR} ${CUDA_TOOLKIT_ROOT_DIR} | ||
PATH_SUFFIXES lib lib64 lib/x64) | ||
|
||
if (NOT (CUDNN_INCLUDE_DIR AND CUDNN_LIBRARY_CUDNN_PATH)) | ||
message(FATAL_ERROR "Couldn't find cuDNN in CUDNN_DIR: ${CUDNN_DIR}, " | ||
"or in CUDA_TOOLKIT_ROOT_DIR: ${CUDA_TOOLKIT_ROOT_DIR}, " | ||
"please check if the path is correct.") | ||
endif() | ||
|
||
add_library(cudnn SHARED IMPORTED) | ||
set_property(TARGET cudnn APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) | ||
if (MSVC) | ||
set_target_properties(cudnn PROPERTIES | ||
IMPORTED_IMPLIB_RELEASE ${CUDNN_LIBRARY_CUDNN_PATH} | ||
INTERFACE_INCLUDE_DIRECTORIES ${CUDNN_INCLUDE_DIR} | ||
) | ||
|
||
else() | ||
set_target_properties(cudnn PROPERTIES | ||
IMPORTED_LOCATION_RELEASE ${CUDNN_LIBRARY_CUDNN_PATH} | ||
INTERFACE_INCLUDE_DIRECTORIES ${CUDNN_INCLUDE_DIR} | ||
) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
|
||
if (NOT DEFINED ONNXRUNTIME_DIR) | ||
set(ONNXRUNTIME_DIR $ENV{ONNXRUNTIME_DIR}) | ||
endif () | ||
if (NOT ONNXRUNTIME_DIR) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we support |
||
message(FATAL_ERROR "Please set ONNXRUNTIME_DIR with cmake -D option.") | ||
endif() | ||
|
||
find_path( | ||
ONNXRUNTIME_INCLUDE_DIR onnxruntime_cxx_api.h | ||
HINTS ${ONNXRUNTIME_DIR} | ||
PATH_SUFFIXES include) | ||
find_library( | ||
ONNXRUNTIME_LIBRARY_ONNXRUNTIME_PATH onnxruntime | ||
irexyc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
HINTS ${ONNXRUNTIME_DIR} | ||
PATH_SUFFIXES lib lib64 lib/x64) | ||
if (NOT (ONNXRUNTIME_INCLUDE_DIR AND ONNXRUNTIME_LIBRARY_ONNXRUNTIME_PATH)) | ||
message(FATAL_ERROR "Couldn't find onnxruntime in ONNXRUNTIME_DIR: " | ||
"${ONNXRUNTIME_DIR}, please check if the path is correct.") | ||
endif() | ||
|
||
add_library(onnxruntime SHARED IMPORTED) | ||
set_property(TARGET onnxruntime APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) | ||
if (MSVC) | ||
set_target_properties(onnxruntime PROPERTIES | ||
IMPORTED_IMPLIB_RELEASE ${ONNXRUNTIME_LIBRARY_ONNXRUNTIME_PATH} | ||
INTERFACE_INCLUDE_DIRECTORIES ${ONNXRUNTIME_INCLUDE_DIR} | ||
) | ||
|
||
else() | ||
set_target_properties(onnxruntime PROPERTIES | ||
IMPORTED_LOCATION_RELEASE ${ONNXRUNTIME_LIBRARY_ONNXRUNTIME_PATH} | ||
INTERFACE_INCLUDE_DIRECTORIES ${ONNXRUNTIME_INCLUDE_DIR} | ||
) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
|
||
if (NOT DEFINED TENSORRT_DIR) | ||
set(TENSORRT_DIR $ENV{TENSORRT_DIR}) | ||
endif () | ||
if (NOT TENSORRT_DIR) | ||
message(FATAL_ERROR "Please set TENSORRT_DIR with cmake -D option.") | ||
endif() | ||
|
||
find_path( | ||
TENSORRT_INCLUDE_DIR NvInfer.h | ||
HINTS ${TENSORRT_DIR} | ||
PATH_SUFFIXES include) | ||
|
||
if (NOT TENSORRT_INCLUDE_DIR) | ||
message(FATAL_ERROR "Cannot find TensorRT header NvInfer.h, " | ||
"please check if the path is correct") | ||
endif () | ||
|
||
set(__TENSORRT_LIB_COMPONENTS nvinfer;nvinfer_plugin) | ||
foreach(__component ${__TENSORRT_LIB_COMPONENTS}) | ||
find_library( | ||
__component_path ${__component} | ||
HINTS ${TENSORRT_DIR} | ||
PATH_SUFFIXES lib lib64 lib/x64) | ||
if (NOT __component_path) | ||
message(FATAL_ERROR "Cannot find TensorRT lib ${__component}, " | ||
"please check if the path is correct") | ||
endif() | ||
|
||
add_library(${__component} SHARED IMPORTED) | ||
set_property(TARGET ${__component} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) | ||
if (MSVC) | ||
set_target_properties( | ||
${__component} PROPERTIES | ||
IMPORTED_IMPLIB_RELEASE ${__component_path} | ||
INTERFACE_INCLUDE_DIRECTORIES ${TENSORRT_INCLUDE_DIR} | ||
) | ||
else() | ||
set_target_properties( | ||
${__component} PROPERTIES | ||
IMPORTED_LOCATION_RELEASE ${__component_path} | ||
INTERFACE_INCLUDE_DIRECTORIES ${TENSORRT_INCLUDE_DIR} | ||
) | ||
endif() | ||
unset(__component_path CACHE) | ||
endforeach() | ||
|
||
set(TENSORRT_LIBS ${__TENSORRT_LIB_COMPONENTS}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.14) | |
project(mmdeploy_onnxruntime_ops) | ||
|
||
include(${CMAKE_SOURCE_DIR}/cmake/MMDeploy.cmake) | ||
include(${CMAKE_SOURCE_DIR}/cmake/modules/FindONNXRUNTIME.cmake) | ||
|
||
# add plugin source | ||
file(GLOB_RECURSE ORT_OPS_SRCS *.cpp) | ||
|
@@ -16,8 +17,8 @@ target_include_directories(${PROJECT_NAME}_obj PUBLIC | |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../common> | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/csrc>) | ||
target_link_directories(${PROJECT_NAME}_obj PUBLIC | ||
${ONNXRUNTIME_DIR}/lib) | ||
# target_link_directories(${PROJECT_NAME}_obj PUBLIC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented code |
||
# ${ONNXRUNTIME_DIR}/lib) | ||
target_link_libraries(${PROJECT_NAME}_obj PUBLIC onnxruntime) | ||
|
||
mmdeploy_add_library(${PROJECT_NAME} SHARED EXCLUDE "") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,9 @@ target_include_directories(${PROJECT_NAME}_obj | |
target_include_directories(${PROJECT_NAME}_obj PRIVATE ${TENSORRT_INCLUDE_DIR}) | ||
target_include_directories(${PROJECT_NAME}_obj PRIVATE ${CUDNN_DIR}/include) | ||
target_include_directories(${PROJECT_NAME}_obj PRIVATE ${CUB_ROOT_DIR}) | ||
target_link_directories(${PROJECT_NAME}_obj PUBLIC ${CUDNN_DIR}/lib64 ${CUDNN_DIR}/lib/x64) | ||
# target_link_directories(${PROJECT_NAME}_obj PUBLIC ${CUDNN_DIR}/lib64 ${CUDNN_DIR}/lib/x64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented code |
||
target_link_libraries(${PROJECT_NAME}_obj | ||
PUBLIC ${TENSORRT_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} cudnn) | ||
PUBLIC ${TENSORRT_LIBS} cublas cudnn) | ||
mmdeploy_export(${PROJECT_NAME}_obj) | ||
|
||
# Build module library. It is used to convert onnx model to tensorrt engine | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ set(SRCS | |
cuda_device.cpp | ||
cuda_builtin_kernels.cu) | ||
mmdeploy_add_module(${PROJECT_NAME} "${SRCS}") | ||
target_include_directories(${PROJECT_NAME} PUBLIC ${CUDA_INCLUDE_DIRS}) | ||
target_link_directories(${PROJECT_NAME} PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/lib64) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDA_INCLUDE_DIRS}) | ||
# target_link_directories(${PROJECT_NAME} PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/lib64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented code |
||
target_link_libraries(${PROJECT_NAME} PRIVATE cudart cuda) | ||
add_library(mmdeploy::device::cuda ALIAS ${PROJECT_NAME}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,15 @@ | |
cmake_minimum_required(VERSION 3.14) | ||
project(mmdeploy_ort_net) | ||
|
||
include(${CMAKE_SOURCE_DIR}/cmake/modules/FindONNXRUNTIME.cmake) | ||
|
||
if ("cpu" IN_LIST MMDEPLOY_TARGET_DEVICES) | ||
include(${CMAKE_SOURCE_DIR}/cmake/MMDeploy.cmake) | ||
mmdeploy_add_module(${PROJECT_NAME} ort_net.cpp) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${ONNXRUNTIME_DIR}/include) | ||
target_link_directories(${PROJECT_NAME} PUBLIC ${ONNXRUNTIME_DIR}/lib) | ||
# target_link_directories(${PROJECT_NAME} PUBLIC ${ONNXRUNTIME_DIR}/lib) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented code |
||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy_onnxruntime_ops_obj) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC onnxruntime) | ||
add_library(mmdeploy::ort_net ALIAS ${PROJECT_NAME}) | ||
else () | ||
message(ERROR "'ort_net' is NOT supported in target devices: ${MMDEPLOY_TARGET_DEVICES}") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ target_include_directories(${PROJECT_NAME} PRIVATE | |
${TENSORRT_INCLUDE_DIR}) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDNN_DIR}/include) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDA_TOOLKIT_ROOT_DIR}/include) | ||
target_link_directories(${PROJECT_NAME} PUBLIC ${CUDNN_DIR}/lib64 ${CUDNN_DIR}/lib/x64) | ||
# target_link_directories(${PROJECT_NAME} PUBLIC ${CUDNN_DIR}/lib64 ${CUDNN_DIR}/lib/x64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented code |
||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy_tensorrt_ops_obj) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC ${TENSORRT_LIBRARY} cudnn) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC ${TENSORRT_LIBS} cudnn) | ||
|
||
add_library(mmdeploy::trt_net ALIAS ${PROJECT_NAME}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any special purpose to use
CMAKE_CURRENT_LIST_DIR
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path added to CMAKE_MODULE_PATH should be absolute path.