From a1ce0c6ccc4181a881405cc301d7befa963dcd32 Mon Sep 17 00:00:00 2001 From: laugh12321 Date: Mon, 16 Dec 2024 22:20:44 +0800 Subject: [PATCH 1/3] fix(custom plugin): Resolved trtexec Fails to Build TensorRT Engine with Custom Plugins on Windows (#50) --- plugin/common/vfcCommon.cpp | 6 +++--- plugin/common/vfcCommon.h | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/plugin/common/vfcCommon.cpp b/plugin/common/vfcCommon.cpp index 36d9a53..a7f20cd 100644 --- a/plugin/common/vfcCommon.cpp +++ b/plugin/common/vfcCommon.cpp @@ -73,13 +73,13 @@ ILogger* getPluginLogger() } // namespace plugin } // namespace -extern "C" TENSORRTAPI void setLoggerFinder(nvinfer1::ILoggerFinder* finder) +extern "C" DEPLOYAPI void setLoggerFinder(nvinfer1::ILoggerFinder* finder) { nvinfer1::plugin::gLoggerFinder.setLoggerFinder(finder); } #if (TENSORRT_VERSION >= 100000) -extern "C" TENSORRTAPI IPluginCreatorInterface* const* getCreators(int32_t& nbCreators) +extern "C" DEPLOYAPI IPluginCreatorInterface* const* getCreators(int32_t& nbCreators) { nbCreators = 2; static EfficientRotatedNMSPluginCreator efficientRotatedNMSPluginCreator; @@ -91,7 +91,7 @@ extern "C" TENSORRTAPI IPluginCreatorInterface* const* getCreators(int32_t& nbCr #endif #if (TENSORRT_VERSION < 100100) -extern "C" TENSORRTAPI IPluginCreator* const* getPluginCreators(int32_t& nbCreators) +extern "C" DEPLOYAPI IPluginCreator* const* getPluginCreators(int32_t& nbCreators) { nbCreators = 2; static EfficientRotatedNMSPluginCreator efficientRotatedNMSPluginCreator; diff --git a/plugin/common/vfcCommon.h b/plugin/common/vfcCommon.h index 8ac02a2..9284003 100644 --- a/plugin/common/vfcCommon.h +++ b/plugin/common/vfcCommon.h @@ -22,6 +22,12 @@ #include "NvInferRuntimeCommon.h" #include "NvInferVersion.h" +#ifdef _MSC_VER +#define DEPLOYAPI __declspec(dllexport) +#else +#define DEPLOYAPI __attribute__((visibility("default"))) +#endif + #define TENSORRT_VERSION (NV_TENSORRT_MAJOR * 10000L + NV_TENSORRT_MINOR * 100L + NV_TENSORRT_PATCH * 1L) using namespace nvinfer1; @@ -36,14 +42,14 @@ ILogger* getPluginLogger(); } // namespace plugin } // namespace nvinfer1 -extern "C" TENSORRTAPI void setLoggerFinder(nvinfer1::ILoggerFinder* finder); +extern "C" DEPLOYAPI void setLoggerFinder(nvinfer1::ILoggerFinder* finder); #if (TENSORRT_VERSION >= 100000) -extern "C" TENSORRTAPI IPluginCreatorInterface* const* getCreators(int32_t& nbCreators); +extern "C" DEPLOYAPI IPluginCreatorInterface* const* getCreators(int32_t& nbCreators); #endif #if (TENSORRT_VERSION < 100100) -extern "C" TENSORRTAPI IPluginCreator* const* getPluginCreators(int32_t& nbCreators); +extern "C" DEPLOYAPI IPluginCreator* const* getPluginCreators(int32_t& nbCreators); #endif #endif // TRT_PLUGIN_VFC_COMMON_H \ No newline at end of file From 72306a1e9403c4415c985050ccc7d5cd6d6feddd Mon Sep 17 00:00:00 2001 From: laugh12321 Date: Mon, 16 Dec 2024 22:27:24 +0800 Subject: [PATCH 2/3] docs: Made corresponding changes to the documentation --- docs/cn/model_export.md | 7 ++----- docs/en/model_export.md | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/cn/model_export.md b/docs/cn/model_export.md index 9a87e91..fc5249c 100644 --- a/docs/cn/model_export.md +++ b/docs/cn/model_export.md @@ -49,11 +49,8 @@ trtexec --onnx=model.onnx --saveEngine=model.engine --minShapes=images:1x3x640x6 trtexec --onnx=yolov8n-obb.onnx --saveEngine=yolov8n-obb.engine --fp16 --staticPlugins=./lib/plugin/libcustom_plugins.so --setPluginsToSerialize=./lib/plugin/libcustom_plugins.so # YOLO11-OBB 动态 batch -trtexec --onnx=yolov11n-obb.onnx --saveEngine=yolov11n-obb.engine --fp16 --minShapes=images:1x3x640x640 --optShapes=images:4x3x640x640 --maxShapes=images:8x3x640x640 --dynamicPlugins=./lib/plugin/custom_plugins.dll --setPluginsToSerialize=./lib/plugin/custom_plugins.dll +trtexec --onnx=yolov11n-obb.onnx --saveEngine=yolov11n-obb.engine --fp16 --minShapes=images:1x3x640x640 --optShapes=images:4x3x640x640 --maxShapes=images:8x3x640x640 --staticPlugins=./lib/plugin/custom_plugins.dll --setPluginsToSerialize=./lib/plugin/custom_plugins.dll ``` > [!NOTE] -> 在使用 `--dynamicPlugins` 和 `--setPluginsToSerialize` 参数构建包含自定义插件的动态模型时,如果遇到错误 `[E] Error[4]: IRuntime::deserializeCudaEngine: Error Code 4: API Usage Error (Cannot register the library as plugin creator of EfficientRotatedNMS_TRT exists already.)`,这通常意味着引擎构建已成功,但加载并反序列化引擎时检测到插件重复注册。这种情况下,可以忽略该错误。 - -> [!IMPORTANT] -> 强烈推荐您使用Linux操作系统。经过测试,在Windows和Linux系统中使用NVIDIA 20、30、40系列显卡时发现,对于经过显存修改的2080Ti 22G显卡,在Windows环境下构建包含自定义插件的动态模型时,可能会遇到“`IPluginRegistry::loadLibrary: Error Code 3: API Usage Error (SymbolAddress for getCreators could not be loaded, check function name against library symbol)`”的错误。然而,在Linux系统中,该问题并未出现。目前尚不清楚这一问题是由于Windows系统本身的缺陷,还是由于显卡显存的修改所导致。因此,为了避免潜在的兼容性问题,强烈建议您在Linux系统下进行相关操作。 \ No newline at end of file +> 在使用 `--staticPlugins` 和 `--setPluginsToSerialize` 参数构建包含自定义插件的动态模型时,如果遇到错误 `[E] Error[4]: IRuntime::deserializeCudaEngine: Error Code 4: API Usage Error (Cannot register the library as plugin creator of EfficientRotatedNMS_TRT exists already.)`,这通常意味着引擎构建已成功,但加载并反序列化引擎时检测到插件重复注册。这种情况下,可以忽略该错误。 diff --git a/docs/en/model_export.md b/docs/en/model_export.md index 1557735..b9f26c5 100644 --- a/docs/en/model_export.md +++ b/docs/en/model_export.md @@ -48,11 +48,8 @@ trtexec --onnx=model.onnx --saveEngine=model.engine --minShapes=images:1x3x640x6 trtexec --onnx=yolov8n-obb.onnx --saveEngine=yolov8n-obb.engine --fp16 --staticPlugins=./lib/plugin/libcustom_plugins.so --setPluginsToSerialize=./lib/plugin/libcustom_plugins.so # YOLO11-OBB dynamic batch -trtexec --onnx=yolov11n-obb.onnx --saveEngine=yolov11n-obb.engine --fp16 --minShapes=images:1x3x640x640 --optShapes=images:4x3x640x640 --maxShapes=images:8x3x640x640 --dynamicPlugins=./lib/plugin/custom_plugins.dll --setPluginsToSerialize=./lib/plugin/custom_plugins.dll +trtexec --onnx=yolov11n-obb.onnx --saveEngine=yolov11n-obb.engine --fp16 --minShapes=images:1x3x640x640 --optShapes=images:4x3x640x640 --maxShapes=images:8x3x640x640 --staticPlugins=./lib/plugin/custom_plugins.dll --setPluginsToSerialize=./lib/plugin/custom_plugins.dll ``` > [!NOTE] -> When using the `--dynamicPlugins` and `--setPluginsToSerialize` parameters to build a dynamic model with custom plugins, encountering the error `[E] Error[4]: IRuntime::deserializeCudaEngine: Error Code 4: API Usage Error (Cannot register the library as plugin creator of EfficientRotatedNMS_TRT exists already.)` typically indicates that the engine has been successfully built, but an attempt to load and deserialize the engine detected a duplicate plugin registration. This error can be safely ignored. - -> [!IMPORTANT] -> We strongly recommend using the Linux operating system. After testing, it has been found that when using NVIDIA 20, 30, and 40 series graphics cards in both Windows and Linux systems, a modified 2080Ti 22G graphics card may encounter the error `IPluginRegistry::loadLibrary: Error Code 3: API Usage Error (SymbolAddress for getCreators could not be loaded, check function name against library symbol)` when building dynamic models with custom plugins in the Windows environment. However, this issue does not occur in the Linux system. It is currently unclear whether this problem is due to defects in the Windows system itself or due to the modification of the graphics card's memory. Therefore, to avoid potential compatibility issues, it is strongly advised that you perform related operations in the Linux system. +> When using the `--staticPlugins` and `--setPluginsToSerialize` parameters to build a dynamic model with custom plugins, encountering the error `[E] Error[4]: IRuntime::deserializeCudaEngine: Error Code 4: API Usage Error (Cannot register the library as plugin creator of EfficientRotatedNMS_TRT exists already.)` typically indicates that the engine has been successfully built, but an attempt to load and deserialize the engine detected a duplicate plugin registration. This error can be safely ignored. From bd3cbdaf89e65fd55a89640c3a21addd5e698898 Mon Sep 17 00:00:00 2001 From: laugh12321 Date: Mon, 16 Dec 2024 22:31:04 +0800 Subject: [PATCH 3/3] chore: Bump version number to 5.0.2 --- CMakeLists.txt | 2 +- pyproject.toml | 2 +- xmake.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95659b2..8009820 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15.0) # 设置CMake的最低版本要求 cmake_policy(SET CMP0091 NEW) # 允许在CMake 3.10+中自动设置项目名作为二进制目录名 cmake_policy(SET CMP0146 OLD) # 忽略对find_package的过时警告 -project(TensorRT-YOLO VERSION 5.0.0 LANGUAGES CXX CUDA) # 定义项目名称、版本和使用的编程语言(C++和CUDA) +project(TensorRT-YOLO VERSION 5.0.2 LANGUAGES CXX CUDA) # 定义项目名称、版本和使用的编程语言(C++和CUDA) # 设置 C++ 标准 set(CMAKE_CXX_STANDARD 17) # 设置C++标准为17 diff --git a/pyproject.toml b/pyproject.toml index fa3a999..bb9b640 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" # Project settings ----------------------------------------------------------------------------------------------------- [project] -version = "5.0.0" +version = "5.0.2" readme = "README.md" name = "tensorrt_yolo" requires-python = ">=3.8" diff --git a/xmake.lua b/xmake.lua index 8da9b77..1e51ea7 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,6 +1,6 @@ -- 设置项目信息 set_project("TensorRT-YOLO") -set_version("5.0.0") +set_version("5.0.2") set_languages("cxx17") set_allowedplats("windows", "linux")