From 1558e5b17243493126f1a62e42cbb9473f1883cf Mon Sep 17 00:00:00 2001 From: zhangli Date: Mon, 5 Sep 2022 11:49:37 +0800 Subject: [PATCH 1/3] add option for TorchScript SDK backend --- csrc/mmdeploy/net/torchscript/CMakeLists.txt | 32 +++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/csrc/mmdeploy/net/torchscript/CMakeLists.txt b/csrc/mmdeploy/net/torchscript/CMakeLists.txt index 3d424ed474..f65c65c890 100644 --- a/csrc/mmdeploy/net/torchscript/CMakeLists.txt +++ b/csrc/mmdeploy/net/torchscript/CMakeLists.txt @@ -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 - $) + target_link_libraries(${PROJECT_NAME} PRIVATE + ${TORCH_LIBRARIES}) -target_link_libraries(${PROJECT_NAME} PRIVATE - mmdeploy_torchscript_ops_obj) + target_link_directories(${PROJECT_NAME} INTERFACE + $) -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 () From df866d34d32ddb3b03faf92eb3f1f1ec325e86d3 Mon Sep 17 00:00:00 2001 From: zhangli Date: Mon, 5 Sep 2022 12:56:18 +0800 Subject: [PATCH 2/3] add doc --- docs/en/05-supported-backends/torchscript.md | 9 +++++++++ docs/zh_cn/05-supported-backends/torchscript.md | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/docs/en/05-supported-backends/torchscript.md b/docs/en/05-supported-backends/torchscript.md index 9289c57523..181f5c788d 100644 --- a/docs/en/05-supported-backends/torchscript.md +++ b/docs/en/05-supported-backends/torchscript.md @@ -47,6 +47,15 @@ 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.` diff --git a/docs/zh_cn/05-supported-backends/torchscript.md b/docs/zh_cn/05-supported-backends/torchscript.md index a86f048d9b..4e98c9b592 100644 --- a/docs/zh_cn/05-supported-backends/torchscript.md +++ b/docs/zh_cn/05-supported-backends/torchscript.md @@ -47,6 +47,15 @@ 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.` From 05d21081846ebcd915e10d41068cc889090a7e4d Mon Sep 17 00:00:00 2001 From: zhangli Date: Mon, 5 Sep 2022 15:52:05 +0800 Subject: [PATCH 3/3] format --- docs/en/05-supported-backends/torchscript.md | 5 ++--- docs/zh_cn/05-supported-backends/torchscript.md | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/en/05-supported-backends/torchscript.md b/docs/en/05-supported-backends/torchscript.md index 181f5c788d..8b556cf2cb 100644 --- a/docs/en/05-supported-backends/torchscript.md +++ b/docs/en/05-supported-backends/torchscript.md @@ -51,9 +51,8 @@ make -j$(nproc) 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 +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 diff --git a/docs/zh_cn/05-supported-backends/torchscript.md b/docs/zh_cn/05-supported-backends/torchscript.md index 4e98c9b592..9ecd7761a9 100644 --- a/docs/zh_cn/05-supported-backends/torchscript.md +++ b/docs/zh_cn/05-supported-backends/torchscript.md @@ -51,9 +51,8 @@ make -j$(nproc) 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 +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