MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / createPlugin

Method createPlugin

plugin/normalizePlugin/normalizePlugin.cpp:313–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311}
312
313IPluginV2Ext* NormalizePluginCreator::createPlugin(char const* name, PluginFieldCollection const* fc) noexcept
314{
315 try
316 {
317 std::vector<float> weightValues;
318 PluginField const* fields = fc->fields;
319 for (int32_t i = 0; i < fc->nbFields; ++i)
320 {
321 char const* attrName = fields[i].name;
322 if (!strcmp(attrName, "nbWeights"))
323 {
324 PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
325 mNbWeights = *(static_cast<int32_t const*>(fields[i].data));
326 }
327 else if (!strcmp(attrName, "acrossSpatial"))
328 {
329 PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
330 mAcrossSpatial = *(static_cast<bool const*>(fields[i].data));
331 }
332 else if (!strcmp(attrName, "channelShared"))
333 {
334 PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kINT32);
335 mChannelShared = *(static_cast<bool const*>(fields[i].data));
336 }
337 else if (!strcmp(attrName, "eps"))
338 {
339 PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kFLOAT32);
340 mEps = *(static_cast<float const*>(fields[i].data));
341 }
342 else if (!strcmp(attrName, "weights"))
343 {
344 PLUGIN_VALIDATE(fields[i].type == PluginFieldType::kFLOAT32);
345 int32_t size = fields[i].length;
346 weightValues.reserve(size);
347 auto const* w = static_cast<float const*>(fields[i].data);
348 for (int32_t j = 0; j < size; j++)
349 {
350 weightValues.push_back(*w);
351 w++;
352 }
353 }
354 }
355 Weights weights{DataType::kFLOAT, weightValues.data(), (int64_t) weightValues.size()};
356
357 Normalize* obj = new Normalize(&weights, mNbWeights, mAcrossSpatial, mChannelShared, mEps);
358 obj->setPluginNamespace(mNamespace.c_str());
359 return obj;
360 }
361 catch (std::exception const& e)
362 {
363 caughtError(e);
364 }
365 return nullptr;
366}
367
368IPluginV2Ext* NormalizePluginCreator::deserializePlugin(
369 char const* name, void const* serialData, size_t serialLength) noexcept

Callers

nothing calls this directly

Calls 5

caughtErrorFunction · 0.85
c_strMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
setPluginNamespaceMethod · 0.45

Tested by

no test coverage detected