REGISTER_TENSORRT_PLUGIN and the static initialization order fiasco

REGISTER_TENSORRT_PLUGIN, defined near https://github.com/NVIDIA/TensorRT/blob/master/include/NvInferRuntimeCommon.h#L1272, defines a static instance of PluginRegistrar. The ctor of PluginRegistrar calls getPluginRegistry(), which retrieves the global plugin registry. If the global plugin registry is a usual global, then we have a dependency between statics defined in different translation units, and hence are potentially susceptible to the static initialization order fiasco (https://isocpp.org/wiki/faq/ctors#static-init-order), no? Note if the global registry is implemented as a function-local static, we don’t have this issue (because they are initialized on first use). We also wouldn’t have this issue if, as I’ve argued before (in 1, 2), TensorRT clients could own their own IPluginRegistry. The absence of bug reports on this issue is reassuring, but UB can strike at any time.

  1. https://devtalk.nvidia.com/default/topic/1064980/tensorrt/opposite-of-registercreator-/post/5417916/#5417916
  2. https://devtalk.nvidia.com/default/topic/1069573/tensorrt/thread-safety-of-ipluginregistry/post/5418069/#5418069

Hi Tom,

Thanks for the feedback, we will look into it and update you.

Thanks

The implementation uses a function local static.

1 Like

Thanks for the clarification, Dilip.

Cheers,
Tom