Get/Set - AlgorithmSelector fails with access violation error

Hi,
I can not define the IAlgorithmSelector via the IBuilderConfig, since setAlgorithmSelector and getAlgorithmSelector always end in an Access violation reading location 0xFFFFFFFFFFFFFFFF error.

The sampleAgorithmSelector example also ends with the same error for me.

Environment

TensorRT Version : 7.1.3.4
Nvidia Driver Version : 451.82
CUDA Version : 11.0.3
CUDNN Version : 8.0.1.13
Operating System + Version : Windows 10

Hi @gkru,
Request you to check the steps from below link

Thanks!

Hi,
I have read the steps from the Developer Guide but could not find the error.

I tried to use the AlgorithmCacheWriter from the sample and add it to a config.
But config->setAlgorithmSelector(&algoWriter); always ends with the following error:

Exception thrown: read access violation.
nvinfer1::IBuilderConfig::setAlgorithmSelector[virtual] was 0xFFFFFFFFFFFFFFFF.

The following sourcecode can be used to reproduce the error:

#include <iostream>
#include <cassert>
#include <fstream>
#include <sstream>
#include <numeric>

#include "NvInfer.h"

class DummyLogger : public nvinfer1::ILogger {
public:
    void log(Severity severity, const char* msg) override {
        std::cout << "[TRT] " << msg << std::endl;
    }
};

class AlgorithmCacheWriter : public nvinfer1::IAlgorithmSelector {
public:
    int32_t selectAlgorithms(const nvinfer1::IAlgorithmContext& context, const nvinfer1::IAlgorithm* const* choices,
        int32_t nbChoices, int32_t* selection) override {
        // TensorRT always provides more than zero number of algorithms in selectAlgorithms.
        assert(nbChoices > 0);

        std::iota(selection, selection + nbChoices, 0);
        return nbChoices;
    }

    void reportAlgorithms(const nvinfer1::IAlgorithmContext* const* algoContexts,
        const nvinfer1::IAlgorithm* const* algoChoices, int32_t nbAlgorithms) noexcept override {
        std::ofstream algorithmFile(mCacheFileName);
        if (!algorithmFile.good()) {
            std::cout << "Cannot open algorithm cache file: " << mCacheFileName << " to write." << std::endl;
            abort();
        }

        for (int32_t i = 0; i < nbAlgorithms; i++) {
            algorithmFile << algoContexts[i]->getName() << "\n";
            algorithmFile << algoChoices[i]->getAlgorithmVariant().getImplementation() << "\n";
            algorithmFile << algoChoices[i]->getAlgorithmVariant().getTactic() << "\n";

            // Write number of inputs and outputs.
            const int32_t nbInputs = algoContexts[i]->getNbInputs();
            algorithmFile << nbInputs << "\n";
            const int32_t nbOutputs = algoContexts[i]->getNbOutputs();
            algorithmFile << nbOutputs << "\n";

            // Write input and output formats.
            for (int32_t j = 0; j < nbInputs + nbOutputs; j++) {
                algorithmFile << static_cast<int32_t>(algoChoices[i]->getAlgorithmIOInfo(j).getTensorFormat()) << "\n";
                algorithmFile << static_cast<int32_t>(algoChoices[i]->getAlgorithmIOInfo(j).getDataType()) << "\n";
            }
        }
        algorithmFile.close();
    }

    AlgorithmCacheWriter(const std::string& cacheFileName)
        : mCacheFileName(cacheFileName) {
    }
private:
    std::string mCacheFileName;
};


int main(int, char**) {
    DummyLogger dummyLogger;

    auto builder = nvinfer1::createInferBuilder(dummyLogger);
    if (!builder) {
        return -1;
    }

    auto network = builder->createNetwork();
    if (!network) {
        return -2;
    }

    auto config = builder->createBuilderConfig();
    if (!config) {
        return -3;
    }
    
    std::string cacheFile = "CacheFile.txt";
    AlgorithmCacheWriter algoWriter(cacheFile);
    config->setAlgorithmSelector(&algoWriter);
    //auto currentAlgoSelector = config->getAlgorithmSelector(); // also ends with error

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

Hi @AakankshaS,
do you have any news on that issue?

Thanks.