【问题标题】:TensorRT (C++ API) undefined reference to `createNvOnnxParser_INTERNAL'TensorRT (C++ API) 未定义对“createNvOnnxParser_INTERNAL”的引用
【发布时间】:2020-10-15 19:00:16
【问题描述】:

我正在尝试使用 TensorRT C++ API 从 ONNX 模型创建一个 tensorrt 引擎。我已经按照documentation 编写了代码来读取、序列化和写入 tensorrt 引擎到磁盘。我已经使用debian installation instructions 在 colab 上安装了 tensorrt7。

这是我使用 g++ rnxt.cpp -o rnxt 编译的 c++ 代码

#include <cuda_runtime_api.h>
#include <NvOnnxParser.h>
#include <NvInfer.h>

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>

class Logger : public nvinfer1::ILogger           
 {
     void log(Severity severity, const char* msg) override
     {
         // suppress info-level messages
         if (severity != Severity::kINFO)
             std::cout << msg << std::endl;
     }
 } gLogger;


int main(){

    int maxBatchSize = 32;

    nvinfer1::IBuilder* builder = nvinfer1::createInferBuilder(gLogger);
    const auto explicitBatch = 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);  
    nvinfer1::INetworkDefinition* network = builder->createNetworkV2(explicitBatch);

    nvonnxparser::IParser* parser = nvonnxparser::createParser(*network, gLogger);
    
    
    parser->parseFromFile("saved_resnext.onnx", 1);
    for (int i = 0; i < parser->getNbErrors(); ++i)
    {
        std::cout << parser->getError(i)->desc() << std::endl;
    }

    builder->setMaxBatchSize(maxBatchSize);
    nvinfer1::IBuilderConfig* config = builder->createBuilderConfig();
    config->setMaxWorkspaceSize(1 << 20);
    nvinfer1::ICudaEngine* engine = builder->buildEngineWithConfig(*network, *config);

    parser->destroy();
    network->destroy();
    config->destroy();
    builder->destroy();

    nvinfer1::IHostMemory *serializedModel = engine->serialize();

    std::ofstream engine_file("saved_resnext.engine");

    engine_file.write((const char*)serializedModel->data(),serializedModel->size());

    serializedModel->destroy();
    return 0;
 }

编译时出现以下错误:

/tmp/ccJaGxCX.o: In function `nvinfer1::(anonymous namespace)::createInferBuilder(nvinfer1::ILogger&)':
rnxt.cpp:(.text+0x19): undefined reference to `createInferBuilder_INTERNAL'
/tmp/ccJaGxCX.o: In function `nvonnxparser::(anonymous namespace)::createParser(nvinfer1::INetworkDefinition&, nvinfer1::ILogger&)':
rnxt.cpp:(.text+0x43): undefined reference to `createNvOnnxParser_INTERNAL'
collect2: error: ld returned 1 exit status

我也收到与&lt;cuda_runtime_api.h&gt; 相关的错误,因此我已将 cuda 包含目录 (/usr/local/cuda-11.0/targets/x86_64-linux/include) 中的这些文件添加(粘贴)到/usr/include directory,之后我收到了上述错误。我对 C++ 没有太多经验,如果有任何帮助,我将不胜感激。

编辑:我也安装了 libnvinfer 使用

!apt-get install -y libnvinfer7=7.1.3-1+cuda11.0
!apt-get install -y libnvinfer-dev=7.1.3-1+cuda11.0

【问题讨论】:

标签: c++ pytorch google-colaboratory tensorrt


【解决方案1】:

这个问题是由于 nvonnxparser.so 没有在 Makefile 中链接。只需添加

target_link_libraries(${TARGET_NAME} nvonnxparser)

在您的 CMake 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    相关资源
    最近更新 更多