I’m using a laptop to convert an onnx model to engine model, and then run the engine model on a gpu.
My laptop’s GPU is “NVIDIA GeForce RTX 3060 Laptop GPU“, which’s compute capability is 8.6.”
The engine model converted above can run on my laptop. But it can’t run on another PC,which‘s GPU is “NVIDIA GeForce GTX 1660 Ti” and compute capability is 7.5. The exception show “The engine plan file is generated on an incompatible device, expecting compute 7.5 gt compute 8.6.please rebuild.”
So I wonder on my laptop, how can I convert the onnx to engine model which support the PC (GPU 1660, compute capability 7.5). Hope anyone can give me some suggestions, thanks so much!
My loptop and PC has the same below configuration:
- Cuda 11.3
- Dudnn 6.14
- TensorRT 8.6.1
My python code convert onnx model to engine model is as below:
import torch
import onnx
import tensorrt as trt
onnx_model = 'model.onnx'
output_names=['output'], opset_version=11)
onnx_model = onnx.load(onnx_model)
logger = trt.Logger(trt.Logger.ERROR)
builder = trt.Builder(logger)
EXPLICIT_BATCH = 1 << (int)(
trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
network = builder.create_network(EXPLICIT_BATCH)
parser = trt.OnnxParser(network, logger)
if not parser.parse(onnx_model.SerializeToString()):
error_msgs = ''
for error in range(parser.num_errors):
error_msgs += f'{parser.get_error(error)}\n'
raise RuntimeError(f'Failed to parse onnx, {error_msgs}')
config = builder.create_builder_config()
config.max_workspace_size = 1<<20
profile = builder.create_optimization_profile()
profile.set_shape('input', [1, 1, 1440, 1440], [1, 1, 1440, 1440], [1, 1, 1440, 1440])
config.add_optimization_profile(profile)
engine = builder.build_engine(network, config)
with open('model.engine', mode='wb') as f:
f.write(bytearray(engine.serialize()))
print("generating file done!")