Skip to content

Commit

Permalink
[Fix] Add isolated option for TorchScript SDK backend (#1002)
Browse files Browse the repository at this point in the history
* add option for TorchScript SDK backend

* add doc

* format
  • Loading branch information
lzhangzz authored Sep 6, 2022
1 parent 124635e commit b602356
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
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)

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 ()
8 changes: 8 additions & 0 deletions docs/en/05-supported-backends/torchscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ make -j$(nproc)

- You could follow the instructions of tutorial [How to convert model](../02-how-to-run/convert_model.md)

## SDK backend

TorchScript SDK backend may be built by passing `-DMMDEPLOY_TORCHSCRIPT_SDK_BACKEND=ON` to `cmake`.

Notice that `libtorch` is sensitive to C++ ABI versions. On platforms defaulted to C++11 ABI (e.g. Ubuntu 16+) one may
pass `-DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"` to `cmake` to use pre-C++11 ABI for building. In this case all
dependencies with ABI sensitive interfaces (e.g. OpenCV) must be built with pre-C++11 ABI.

## FAQs

- Error: `projects/thirdparty/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:96 (message):Your installed Caffe2 version uses cuDNN but I cannot find the cuDNN libraries. Please set the proper cuDNN prefixes and / or install cuDNN.`
Expand Down
8 changes: 8 additions & 0 deletions docs/zh_cn/05-supported-backends/torchscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ make -j$(nproc)

- You could follow the instructions of tutorial [How to convert model](../02-how-to-run/convert_model.md)

## SDK backend

TorchScript SDK backend may be built by passing `-DMMDEPLOY_TORCHSCRIPT_SDK_BACKEND=ON` to `cmake`.

Notice that `libtorch` is sensitive to C++ ABI versions. On platforms defaulted to C++11 ABI (e.g. Ubuntu 16+) one may
pass `-DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"` to `cmake` to use pre-C++11 ABI for building. In this case all
dependencies with ABI sensitive interfaces (e.g. OpenCV) must be built with pre-C++11 ABI.

## FAQs

- Error: `projects/thirdparty/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:96 (message):Your installed Caffe2 version uses cuDNN but I cannot find the cuDNN libraries. Please set the proper cuDNN prefixes and / or install cuDNN.`
Expand Down

0 comments on commit b602356

Please sign in to comment.