| 737 | } |
| 738 | |
| 739 | IPluginV2* FCPluginDynamicCreator::createPlugin(char const* name, PluginFieldCollection const* fc) noexcept |
| 740 | { |
| 741 | try |
| 742 | { |
| 743 | gLogVerbose << "Creating FCPluginDynamicCreator...\n"; |
| 744 | PLUGIN_VALIDATE(name != nullptr); |
| 745 | PLUGIN_VALIDATE(fc != nullptr); |
| 746 | |
| 747 | int32_t outDims = 0; |
| 748 | int32_t typeId = -1; |
| 749 | Weights W{DataType::kFLOAT, nullptr, 0LL}; |
| 750 | plugin::validateRequiredAttributesExist({"out_dims", "type_id", "W"}, fc); |
| 751 | |
| 752 | for (int32_t i = 0; i < fc->nbFields; i++) |
| 753 | { |
| 754 | std::string fieldName(fc->fields[i].name); |
| 755 | if (fieldName.compare("out_dims") == 0) |
| 756 | { |
| 757 | outDims = static_cast<int32_t const*>(fc->fields[i].data)[0]; |
| 758 | gLogVerbose << "Building outDims: " << outDims << std::endl; |
| 759 | } |
| 760 | |
| 761 | if (fieldName.compare("type_id") == 0) |
| 762 | { |
| 763 | typeId = static_cast<int32_t const*>(fc->fields[i].data)[0]; |
| 764 | gLogVerbose << "Building typeId: " << outDims << std::endl; |
| 765 | } |
| 766 | |
| 767 | if (fieldName.compare("W") == 0) |
| 768 | { |
| 769 | gLogVerbose << "Building W...\n"; |
| 770 | W.values = fc->fields[i].data; |
| 771 | W.count = fc->fields[i].length; |
| 772 | W.type = fieldTypeToDataType(fc->fields[i].type); |
| 773 | gLogVerbose << "Is W float32: " << (W.type == DataType::kFLOAT) << std::endl; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | if (outDims <= 0) |
| 778 | { |
| 779 | gLogError << "Invalid output dimension" << std::endl; |
| 780 | } |
| 781 | if (typeId < 0 || typeId > 1) |
| 782 | { |
| 783 | gLogError << "Invalid type id" << typeId << std::endl; |
| 784 | } |
| 785 | if (W.count == 0 || W.values == nullptr || W.count < outDims) |
| 786 | { |
| 787 | gLogError << "Invalid weights" << std::endl; |
| 788 | } |
| 789 | |
| 790 | DataType type = static_cast<DataType>(typeId); |
| 791 | return new FCPluginDynamic(name, type, outDims, W); |
| 792 | } |
| 793 | catch (std::exception const& e) |
| 794 | { |
| 795 | caughtError(e); |
| 796 | } |
no test coverage detected