TensorRT升级错误:error: invalid new-expression of abstract class type ‘nvinfer1::UpsampleLayerPlugin’

将TensorRT由7升级到8的过程中遇到如下错误

plugins/upsample.cpp: In member function ‘virtual nvinfer1::IPluginV2Ext* nvinfer1::UpsampleLayerPlugin::clone() const’:
plugins/upsample.cpp:176:53: error: invalid new-expression of abstract class type ‘nvinfer1::UpsampleLayerPlugin’
         auto* plugin = new UpsampleLayerPlugin(*this);
                                                     ^
In file included from plugins/upsample.cpp:6:0:
plugins/upsample.h:22:11: note:   because the following virtual functions are pure within ‘nvinfer1::UpsampleLayerPlugin’:
     class UpsampleLayerPlugin : public IPluginV2IOExt
           ^
In file included from ../include/tensorrt/NvInferLegacyDims.h:53:0,
                 from ../include/tensorrt/NvInfer.h:53,
                 from plugins/upsample.cpp:2:
../include/tensorrt/NvInferRuntimeCommon.h:541:21: note: 	virtual int32_t nvinfer1::IPluginV2::enqueue(int32_t, const void* const*, void* const*, void*, cudaStream_t)
     virtual int32_t enqueue(int32_t batchSize, void const* const* inputs, void* const* outputs, void* workspace,
                     ^
plugins/upsample.cpp: In member function ‘virtual nvinfer1::IPluginV2* nvinfer1::UpsampleLayerCreator::deserializePlugin(const char*, const void*, size_t)’:
plugins/upsample.cpp:220:64: error: invalid new-expression of abstract class type ‘nvinfer1::UpsampleLayerPlugin’
         return new UpsampleLayerPlugin(serialData, serialLength);

google搜索得到如下答案:

TensorRT升级错误:error: invalid new-expression of abstract class type ‘nvinfer1::UpsampleLayerPlugin’以及如下答案:

TensorRT升级错误:error: invalid new-expression of abstract class type ‘nvinfer1::UpsampleLayerPlugin’

原因就是基类的某个纯虚函数没有被派生类实例化,从报错看是因为基类的enqueue纯虚函数没有被派生类实例化导致报错.然后发现派生类中有enqueue这个函数,只是函数参数有一个小差别.

上一篇:抽象类


下一篇:Java面向对象:接口