#pragma once #include #include class MatMulDynamic : public nvinfer1::IPluginV2DynamicExt { public: MatMulDynamic() = delete; MatMulDynamic(const std::string name); MatMulDynamic(const std::string name, const void* data, size_t length); // IPluginV2Dynamic Methods nvinfer1::IPluginV2DynamicExt* clone() const noexcept override; nvinfer1::DimsExprs getOutputDimensions(int outputIndex, const nvinfer1::DimsExprs* inputs, int nbInputs, nvinfer1::IExprBuilder& exprBuilder) noexcept override; bool supportsFormatCombination(int pos, const nvinfer1::PluginTensorDesc* inOut, int nbInputs, int nbOutputs) noexcept override; void configurePlugin(const nvinfer1::DynamicPluginTensorDesc* in, int nbInputs, const nvinfer1::DynamicPluginTensorDesc* out, int nbOutputs) noexcept override; size_t getWorkspaceSize(const nvinfer1::PluginTensorDesc* inputs, int nbInputs, const nvinfer1::PluginTensorDesc* outputs, int nbOutputs) const noexcept override; int enqueue(const nvinfer1::PluginTensorDesc* inputDesc, const nvinfer1::PluginTensorDesc* outputDesc, const void* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept override; // IPluginV2Ext Methods nvinfer1::DataType getOutputDataType(int32_t index, nvinfer1::DataType const* inputTypes, int32_t nbInputs) const noexcept override; // IPluginV2 Methods const char* getPluginType() const noexcept override; const char* getPluginVersion() const noexcept override; int32_t getNbOutputs() const noexcept override; int32_t initialize() noexcept override; void terminate() noexcept override; size_t getSerializationSize() const noexcept override; void serialize(void* buffer) const noexcept override; void destroy() noexcept override; void setPluginNamespace(const char* libNamespace) noexcept override; const char* getPluginNamespace() const noexcept override; private: int matMulForward(const void* in1, const void* in2, void* out, const int m, const int k, const int n, nvinfer1::DataType data_type, cudaStream_t stream); const std::string m_layername; std::string m_namespace; }; class MatMulDynamicCreator : public nvinfer1::IPluginCreator { public: MatMulDynamicCreator(); const char* getPluginName() const noexcept override; const char* getPluginVersion() const noexcept override; const nvinfer1::PluginFieldCollection* getFieldNames() noexcept override; nvinfer1::IPluginV2* createPlugin(const char* name, const nvinfer1::PluginFieldCollection* fc) noexcept override; nvinfer1::IPluginV2* deserializePlugin(const char* name, void const* serialData, size_t serialLength) noexcept override; void setPluginNamespace(const char* pluginNamespace) noexcept override; const char* getPluginNamespace() const noexcept override; private: static nvinfer1::PluginFieldCollection m_fc; static std::vector m_plugin_attributes; std::string m_namespace; };