Skip to content

Commit 1565fe7

Browse files
authored
Merge pull request #653 from rajeevsrao/dev/release/7.0
Merge branch 'master' into release/7.0
2 parents dd074cc + 8f430a6 commit 1565fe7

File tree

6 files changed

+107
-26
lines changed

6 files changed

+107
-26
lines changed

Diff for: plugin/InferPlugin.cpp

+69-20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include <array>
2020
#include <iostream>
2121
#include <memory>
22+
#include <mutex>
23+
#include <stack>
24+
#include <unordered_set>
2225
using namespace nvinfer1;
2326
using namespace nvinfer1::plugin;
2427

@@ -54,47 +57,93 @@ namespace plugin
5457
{
5558
ILogger* gLogger{};
5659

57-
// Instances of this class are statically constructed in initializePlugin.
58-
// This ensures that each plugin is only registered a single time, as further calls to
59-
// initializePlugin will be no-ops.
60-
template <typename CreatorType>
61-
class InitializePlugin
60+
// This singleton ensures that each plugin is only registered once for a given
61+
// namespace and type, and attempts of duplicate registration are ignored.
62+
class PluginCreatorRegistry
6263
{
6364
public:
64-
InitializePlugin(void* logger, const char* libNamespace)
65-
: mCreator{new CreatorType{}}
65+
static PluginCreatorRegistry& getInstance()
66+
{
67+
static PluginCreatorRegistry instance;
68+
return instance;
69+
}
70+
71+
template <typename CreatorType>
72+
void addPluginCreator(void* logger, const char* libNamespace)
6673
{
67-
mCreator->setPluginNamespace(libNamespace);
68-
bool status = getPluginRegistry()->registerCreator(*mCreator, libNamespace);
74+
// Make accesses to the plugin creator registry thread safe
75+
std::lock_guard<std::mutex> lock(mRegistryLock);
76+
77+
std::string errorMsg;
78+
std::string verboseMsg;
79+
80+
std::unique_ptr<CreatorType> pluginCreator{new CreatorType{}};
81+
pluginCreator->setPluginNamespace(libNamespace);
82+
83+
nvinfer1::plugin::gLogger = static_cast<nvinfer1::ILogger*>(logger);
84+
std::string pluginType
85+
= std::string(pluginCreator->getPluginNamespace()) + "::" + std::string(pluginCreator->getPluginName());
86+
87+
if (mRegistryList.find(pluginType) == mRegistryList.end())
88+
{
89+
bool status = getPluginRegistry()->registerCreator(*pluginCreator, libNamespace);
90+
if (status)
91+
{
92+
mRegistry.push(std::move(pluginCreator));
93+
mRegistryList.insert(pluginType);
94+
verboseMsg = "Plugin creator registration succeeded - " + pluginType;
95+
}
96+
else
97+
{
98+
errorMsg = "Could not register plugin creator: " + pluginType;
99+
}
100+
}
101+
else
102+
{
103+
verboseMsg = "Plugin creator already registered - " + pluginType;
104+
}
105+
69106
if (logger)
70107
{
71-
nvinfer1::plugin::gLogger = static_cast<nvinfer1::ILogger*>(logger);
72-
if (!status)
108+
if (!errorMsg.empty())
73109
{
74-
std::string errorMsg{"Could not register plugin creator: " + std::string(mCreator->getPluginName())
75-
+ " in namespace: " + std::string{mCreator->getPluginNamespace()}};
76110
nvinfer1::plugin::gLogger->log(ILogger::Severity::kERROR, errorMsg.c_str());
77111
}
78-
else
112+
if (!verboseMsg.empty())
79113
{
80-
std::string verboseMsg{
81-
"Plugin Creator registration succeeded - " + std::string{mCreator->getPluginName()}};
82114
nvinfer1::plugin::gLogger->log(ILogger::Severity::kVERBOSE, verboseMsg.c_str());
83115
}
84116
}
85117
}
86118

87-
InitializePlugin(const InitializePlugin&) = delete;
88-
InitializePlugin(InitializePlugin&&) = delete;
119+
~PluginCreatorRegistry()
120+
{
121+
std::lock_guard<std::mutex> lock(mRegistryLock);
122+
123+
// Release pluginCreators in LIFO order of registration.
124+
while (!mRegistry.empty())
125+
{
126+
mRegistry.pop();
127+
}
128+
mRegistryList.clear();
129+
}
89130

90131
private:
91-
std::unique_ptr<CreatorType> mCreator;
132+
PluginCreatorRegistry() {}
133+
134+
std::mutex mRegistryLock;
135+
std::stack<std::unique_ptr<IPluginCreator>> mRegistry;
136+
std::unordered_set<std::string> mRegistryList;
137+
138+
public:
139+
PluginCreatorRegistry(PluginCreatorRegistry const&) = delete;
140+
void operator=(PluginCreatorRegistry const&) = delete;
92141
};
93142

94143
template <typename CreatorType>
95144
void initializePlugin(void* logger, const char* libNamespace)
96145
{
97-
static InitializePlugin<CreatorType> plugin{logger, libNamespace};
146+
PluginCreatorRegistry::getInstance().addPluginCreator<CreatorType>(logger, libNamespace);
98147
}
99148

100149
} // namespace plugin

Diff for: plugin/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# TensorRT Plugins
2+
3+
## Plugins shipped in this release
4+
5+
| Plugin | Name | Version |
6+
|---|---|---|
7+
| [batchTilePlugin](batchTilePlugin) | BatchTilePlugin_TRT | 1 |
8+
| [batchedNMSPlugin](batchedNMSPlugin) | BatchedNMS_TRT | 1 |
9+
| [bertQKVToContextPlugin](bertQKVToContextPlugin) | CustomQKVToContextPluginDynamic | 1 |
10+
| [cropAndResizePlugin](cropAndResizePlugin) | CropAndResize | 1 |
11+
| [detectionLayerPlugin](detectionLayerPlugin) | DetectionLayer_TRT | 1 |
12+
| [embLayerNormPlugin](embLayerNormPlugin) | CustomEmbLayerNormPluginDynamic | 1 |
13+
| [fcPlugin](fcPlugin) | CustomFCPluginDynamic | 1 |
14+
| [flattenConcat](flattenConcat) | FlattenConcat_TRT | 1 |
15+
| [geluPlugin](geluPlugin) | CustomGeluPluginDynamic | 1 |
16+
| [gridAnchorPlugin](gridAnchorPlugin) | GridAnchor_TRT | 1 |
17+
| [instanceNormalizationPlugin](instanceNormalizationPlugin) | InstanceNormalization_TRT | 1 |
18+
| [nmsPlugin](nmsPlugin) | NMS_TRT | 1 |
19+
| [normalizePlugin](normalizePlugin) | Normalize_TRT | 1 |
20+
| [nvFasterRCNN](nvFasterRCNN) | RPROI_TRT | 1 |
21+
| [priorBoxPlugin](priorBoxPlugin) | PriorBox_TRT | 1 |
22+
| [proposalLayerPlugin](proposalLayerPlugin) | ProposalLayer_TRT | 1 |
23+
| [proposalPlugin](proposalPlugin) | Proposal | 1 |
24+
| [pyramidROIAlignPlugin](pyramidROIAlignPlugin) | PyramidROIAlign_TRT | 1 |
25+
| [regionPlugin](regionPlugin) | Region_TRT | 1 |
26+
| [reorgPlugin](reorgPlugin) | Reorg_TRT | 1 |
27+
| [resizeNearestPlugin](resizeNearestPlugin) | ResizeNearest_TRT | 1 |
28+
| [skipLayerNormPlugin](skipLayerNormPlugin) | CustomSkipLayerNormPluginDynamic | 1 |
29+
| [specialSlicePlugin](specialSlicePlugin) | SpecialSlice_TRT | 1 |

Diff for: plugin/instanceNormalizationPlugin/instanceNormalizationPlugin.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ void InstanceNormalizationPlugin::destroy()
279279

280280
IPluginV2DynamicExt* InstanceNormalizationPlugin::clone() const
281281
{
282-
return new InstanceNormalizationPlugin{_epsilon, _h_scale, _h_bias};
282+
auto plugin = new InstanceNormalizationPlugin{_epsilon, _h_scale, _h_bias};
283+
plugin->setPluginNamespace(mPluginNamespace);
284+
return plugin;
283285
}
284286

285287
// Set plugin namespace

Diff for: plugin/normalizePlugin/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This plugin consists of the plugin creator class `NormalizePluginCreator` and th
2929
|`bool` |`acrossSpatial` |When `acrossSpatial = true`, the normalization is conducted for each sample from the batch independently, meaning across spatial locations only. This is somewhat similar to instance normalization. When `acrossSpatial = false`, the normalization is conducted across all samples in the batch and spatial locations. This is somewhat similar to batch normalization.
3030
|`bool` |`channelShared` |When `channelShared = true`, a single scale factor is used for all channels. When `channelShared = false`, several scale factors are provided and are used for each channel independently.
3131
|`float` |`eps` |A small number to prevent being divided by zero during normalization.
32-
|`Weights *` |`weights` |A pointer to weights which contains information about scale factors for normalization. The definition of `Weights` can be found in the [NvInfer.h](https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/c_api/_nv_infer_8h_source.html) header. The number of values in weights is `1` if `channelShared = false`, otherwise the number of values in weights is the number of channels in the input tensor.
32+
|`Weights *` |`weights` |A pointer to weights which contains information about scale factors for normalization. The definition of `Weights` can be found in the [NvInfer.h](https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/c_api/_nv_infer_8h_source.html) header. The number of values in weights is `1` if `channelShared = true`, otherwise the number of values in weights is the number of channels in the input tensor.
3333
|`int` |`nbWeights` |The number of weights sent to the plugin. This value has to be `1`.
3434

3535

@@ -55,4 +55,4 @@ This is the first release of this `README.md` file.
5555

5656
## Known issues
5757

58-
There are no known issues in this plugin.
58+
There are no known issues in this plugin.

Diff for: plugin/normalizePlugin/normalizePlugin.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ Normalize::Normalize(const void* buffer, size_t length)
7171
channelShared = read<bool>(d);
7272
eps = read<float>(d);
7373

74-
int nbWeights = read<int>(d);
75-
mWeights = deserializeToDevice(d, nbWeights);
74+
mNbWeights = read<int>(d);
75+
mWeights = deserializeToDevice(d, mNbWeights);
76+
cublasCreate(&mCublas);
7677
ASSERT(d == a + length);
7778
}
7879

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
keras == 2.1.3
2-
tensorflow-gpu >= 1.9.0, < 2.0
2+
tensorflow-gpu == 1.15.2
33
scikit-image

0 commit comments

Comments
 (0)