Cuda Driver (TensorRT internal error)

Description

Hi Folks. I am new to tensorrt and cpp. I am trying to optimise a simple resnet50 onnx model. but I keep getting this error Unexpected Internal Error: [virtualMemoryBuffer.cpp::~StdVirtualMemoryBufferImpl::123] Error Code 1: Cuda Driver (TensorRT internal error)

Below is my code. Please note its incomplete I was trying to check whether it compiles

#include <NvInfer.h>
#include <NvOnnxParser.h>
#include <cuda_runtime_api.h>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

class Logger: public nvinfer1::ILogger{
public:
    void log(Severity severity, const char* msg) noexcept override {
        if (severity != Severity::kINFO) {
            std::cout<< msg << std::endl;
        }
    }
} glogger;

std::vector<char> readFile(const std::string& filename) {
    std::ifstream file(filename, std::ios::binary | std::ios::ate);
    std::streamsize size = file.tellg();
    file.seekg(0, std::ios::beg);

    std::vector<char> buffer(size);
    if (!file.read(buffer.data(), size)) {
        throw std::runtime_error("Failed to read engine file");
    }
    return buffer;
}

int main() {
    std::vector<char> onnxModelStream = readFile("resnet.onnx");
    if (onnxModelStream.empty()) {
        std::cerr << "Unable to read onnx file" << std::endl;
        return 1;
    }

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

    auto parser = nvonnxparser::createParser(*network, glogger);
    if (!parser->parse(onnxModelStream.data(), onnxModelStream.size())) {
        std::cerr << "Failed to parse ONNX file" <<std::endl;
        for (int i = 0; i < parser->getNbErrors(); ++i) {
            std::cerr<< parser->getError(i)->desc()<<std::endl;
        }
        return 1;
    }

    nvinfer1::IBuilderConfig* config = builder->createBuilderConfig();

    auto profile = builder->createOptimizationProfile();
    auto input = network->getInput(0);

    profile->setDimensions(input->getName(), nvinfer1::OptProfileSelector::kMIN, nvinfer1::Dims4{1, 3, 224, 224});
    profile->setDimensions(input->getName(), nvinfer1::OptProfileSelector::kOPT, nvinfer1::Dims4{1, 3, 224, 224});
    profile->setDimensions(input->getName(), nvinfer1::OptProfileSelector::kMAX, nvinfer1::Dims4{1, 3, 224, 224});

    config->addOptimizationProfile(profile);

    nvinfer1::ICudaEngine* engine = builder->buildEngineWithConfig(*network, *config);
    if (!engine) {
        std::cerr << "Failed to build engine"<< std::endl;
        return 1;
    }

    nvinfer1::IExecutionContext* context = engine->createExecutionContext();
    if (!context) {
        std::cerr << "Failed to create execution context" << std::endl;
        return 1;
    }

    return 0;
}

//clang++ tensor-inference.cpp -I/usr/include/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lnvinfer -lnvonnxparser -lcudart -o tensor-inference

Environment

TensorRT Version: 10.7.0
GPU Type: Tesla t4
Nvidia Driver Version : 535.161.07
CUDA Version: 12.6
Container Image: nvcr.io/nvidia/tensorrt:24.12-py3

Steps To Reproduce

  1. Run clang++ tensor-inference.cpp -I/usr/include/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lnvinfer -lnvonnxparser -lcudart -o tensor-inference
  2. Run the binary ./tensor-inference

Any help will be appreciated

Hi @chayakudas.das56 ,
I believe Quick Start Guide :: NVIDIA Deep Learning TensorRT Documentation link can help you getting started.

Hi @AakankshaS.

Is there any issue with the existing code that is provided?

Hi @chayakudas.das56 , I also met the same issue when I’m trying to use tensorRT to quantize alexnet in python. I’m wondering if you fix this issue or have any updates about the problem.