Skip to content
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

[Fix] Add isolated option for TorchScript SDK backend #1002

Merged
merged 3 commits into from
Sep 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions csrc/mmdeploy/net/torchscript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

project(mmdeploy_torch_net)

find_package(Torch REQUIRED)
find_package(TorchVision)
option(MMDEPLOY_TORCHSCRIPT_SDK_BACKEND "Build TorchScript SDK backend" OFF)
lzhangzz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can MMDEPLOY_BUILD_SDK=ON and MMDEPLOY_TARGET_BACKENDS="torchscript" be enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just want the converter to work with torchscript (for optimization passes), this would introduce the chaos of different C++ ABIs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only converter is concerned, we can disable MMDEPLOY_BUILD_SDK

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I need to use converter with optimizer to convert TensorRT models and use SDK with TensorRT backend?


mmdeploy_add_module(${PROJECT_NAME} torch_net.cpp)
if (MMDEPLOY_TORCHSCRIPT_SDK_BACKEND)
find_package(Torch REQUIRED)
find_package(TorchVision QUIET)

target_link_libraries(${PROJECT_NAME} PRIVATE
${TORCH_LIBRARIES})
mmdeploy_add_module(${PROJECT_NAME} torch_net.cpp)

target_link_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${Torch_DIR}/../../../lib>)
target_link_libraries(${PROJECT_NAME} PRIVATE
${TORCH_LIBRARIES})

target_link_libraries(${PROJECT_NAME} PRIVATE
mmdeploy_torchscript_ops_obj)
target_link_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${Torch_DIR}/../../../lib>)

if (TorchVision_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE TorchVision::TorchVision)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DMMDEPLOY_USE_TORCHVISION=1)
endif ()
target_link_libraries(${PROJECT_NAME} PRIVATE
mmdeploy_torchscript_ops_obj)

if (TorchVision_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE TorchVision::TorchVision)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DMMDEPLOY_USE_TORCHVISION=1)
endif ()

add_library(mmdeploy::torch_net ALIAS ${PROJECT_NAME})
add_library(mmdeploy::torch_net ALIAS ${PROJECT_NAME})
endif ()