How to test for/catch `The engine plan file is not compatible with this version of TensorRT, expecting library version X got Y. please rebuild`

If the system TRT version has been updated by the package manager and my code then loads an older serialized TRT engine from a file, I get an error like below:

    trtRuntime = nvinfer1::createInferRuntime(gLogger.getTRTLogger());             
    engine = trtRuntime->deserializeCudaEngine(cached_engine.data(),               
                                               cached_engine.size(), nullptr);
[E] [TRT] 6: The engine plan file is not compatible with this version of TensorRT, expecting library vers
ion 8.2.2 got 8.2.1, please rebuild.
[E] [TRT] 4: [runtime.cpp::deserializeCudaEngine::50] Error Code 4: Internal Error (Engine deserializatio
n failed.)

Of course the simple solution is to delete and rebuild the TRT engine. But my users don’t necessarily understand this, so I would like to be able to test for this condition, or catch this error so it can be dealt with automatically. How can I do this?

Hi,

The generated plan files are not portable across platforms or TensorRT versions. Plans are specific to the exact GPU model they were built on (in addition to the platforms and the TensorRT version) and must be re-targeted to the specific GPU in case you want to run them on a different GPU.
Please refer to the below link for same

Thanks!

hey, thanks for reply. I understand that they aren’t portable across tensorrt versions - what I want is to be able to catch this error, when it comes up (eg. after apt-get upgrade) - so that the incompatible engine can be rebuilt.

Hi,

I believe currently we do not have such feature. Maybe you can try with shell scripting.

Thank you.