diff --git a/isaac_ros_tensor_rt/include/isaac_ros_tensor_rt/tensor_rt_node.hpp b/isaac_ros_tensor_rt/include/isaac_ros_tensor_rt/tensor_rt_node.hpp index e05b197..51902b5 100644 --- a/isaac_ros_tensor_rt/include/isaac_ros_tensor_rt/tensor_rt_node.hpp +++ b/isaac_ros_tensor_rt/include/isaac_ros_tensor_rt/tensor_rt_node.hpp @@ -71,6 +71,9 @@ class TensorRTNode : public nitros::NitrosNode const int32_t max_batch_size_; const bool enable_fp16_; const bool relaxed_dimension_check_; + + // Plugin library paths + const StringList plugin_library_paths_; }; } // namespace dnn_inference diff --git a/isaac_ros_tensor_rt/launch/isaac_ros_tensor_rt.launch.py b/isaac_ros_tensor_rt/launch/isaac_ros_tensor_rt.launch.py index 4933b20..ea56757 100644 --- a/isaac_ros_tensor_rt/launch/isaac_ros_tensor_rt.launch.py +++ b/isaac_ros_tensor_rt/launch/isaac_ros_tensor_rt.launch.py @@ -58,6 +58,10 @@ def generate_launch_description(): 'force_engine_update', default_value='False', description='Whether TensorRT should update the TensorRT engine file or not'), + DeclareLaunchArgument( + 'plugin_library_paths', + default_value='[]', + description='A list of plugin library names to load'), ] # TensorRT parameters @@ -69,6 +73,7 @@ def generate_launch_description(): output_binding_names = LaunchConfiguration('output_binding_names') verbose = LaunchConfiguration('verbose') force_engine_update = LaunchConfiguration('force_engine_update') + plugin_library_paths = LaunchConfiguration('plugin_library_paths') tensor_rt_node = ComposableNode( name='tensor_rt', @@ -84,7 +89,8 @@ def generate_launch_description(): 'input_tensor_names': input_tensor_names, 'input_binding_names': input_binding_names, 'verbose': verbose, - 'force_engine_update': force_engine_update + 'force_engine_update': force_engine_update, + 'plugin_library_paths': plugin_library_paths, }] ) diff --git a/isaac_ros_tensor_rt/src/tensor_rt_node.cpp b/isaac_ros_tensor_rt/src/tensor_rt_node.cpp index cc12b29..d4e30ea 100644 --- a/isaac_ros_tensor_rt/src/tensor_rt_node.cpp +++ b/isaac_ros_tensor_rt/src/tensor_rt_node.cpp @@ -26,6 +26,49 @@ #include "rclcpp/rclcpp.hpp" #include "rclcpp_components/register_node_macro.hpp" +// For loadLibrary +#ifdef _MSC_VER +// Needed so that the max/min definitions in windows.h do not conflict with std::max/min. +#define NOMINMAX +#include +#undef NOMINMAX +#else +#include +#endif + +namespace +{ +inline void loadLibrary(const std::string & path, const rclcpp::Logger & logger) +{ +#ifdef _MSC_VER + void* handle = LoadLibrary(path.c_str()); +#else + int32_t flags{RTLD_LAZY}; +#if ENABLE_ASAN + // https://github.com/google/sanitizers/issues/89 + // asan doesn't handle module unloading correctly and there are no plans on doing + // so. In order to get proper stack traces, don't delete the shared library on + // close so that asan can resolve the symbols correctly. + flags |= RTLD_NODELETE; +#endif // ENABLE_ASAN + + void* handle = dlopen(path.c_str(), flags); +#endif + if (handle == nullptr) + { +#ifdef _MSC_VER + RCLCPP_INFO_STREAM( + logger, "Could not load plugin library: " << path << std::endl + ); +#else + RCLCPP_INFO_STREAM( + logger, "Could not load plugin library: " << path << ", due to: " << dlerror() << std::endl + ); +#endif + } +} +} // namespace + namespace nvidia { namespace isaac_ros @@ -114,7 +157,8 @@ TensorRTNode::TensorRTNode(const rclcpp::NodeOptions & options) dla_core_(declare_parameter("dla_core", default_dla_core)), max_batch_size_(declare_parameter("max_batch_size", 1)), enable_fp16_(declare_parameter("enable_fp16", true)), - relaxed_dimension_check_(declare_parameter("relaxed_dimension_check", true)) + relaxed_dimension_check_(declare_parameter("relaxed_dimension_check", true)), + plugin_library_paths_(declare_parameter("plugin_library_paths", StringList())) { RCLCPP_DEBUG(get_logger(), "[TensorRTNode] In TensorRTNode's constructor"); @@ -164,6 +208,10 @@ TensorRTNode::TensorRTNode(const rclcpp::NodeOptions & options) output_tensor_formats_[0].c_str()); } + for (const auto & path : plugin_library_paths_) { + loadLibrary(path, get_logger()); + } + registerSupportedType(); startNitrosNode();