Skip to content

Cuda illegal memory access when running inference on *.engine #6311

@Lick

Description

@Lick

Search before asking

Question

When performing inference with *.engine I receive this error

Loading model.engine for TensorRT inference...
[01/16/2022-04:18:26] [TRT] [I] [MemUsageChange] Init CUDA: CPU +426, GPU +0, now: CPU 520, GPU 3258 (MiB)
[01/16/2022-04:18:26] [TRT] [I] Loaded engine size: 28 MiB
[01/16/2022-04:18:26] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.3 but loaded cuBLAS/cuBLAS LT 11.3.0
[01/16/2022-04:18:26] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +634, GPU +266, now: CPU 1193, GPU 3552 (MiB)
[01/16/2022-04:18:27] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +126, GPU +58, now: CPU 1319, GPU 3610 (MiB)
[01/16/2022-04:18:27] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in engine deserialization: CPU +0, GPU +26, now: CPU 0, GPU 26 (MiB)
[01/16/2022-04:18:31] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.3 but loaded cuBLAS/cuBLAS LT 11.3.0
[01/16/2022-04:18:31] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +1, GPU +10, now: CPU 5022, GPU 5368 (MiB)
[01/16/2022-04:18:31] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 5022, GPU 5376 (MiB)
[01/16/2022-04:18:31] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in IExecutionContext creation: CPU +0, GPU +36, now: CPU 0, GPU 62 (MiB)
Adding AutoShape...
[01/16/2022-04:18:32] [TRT] [E] 1: [convolutionRunner.cpp::executeConv::511] Error Code 1: Cudnn (CUDNN_STATUS_EXECUTION_FAILED)
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "/root/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 539, in forward
t.append(time_sync())
File "/root/.cache/torch/hub/ultralytics_yolov5_master/utils/torch_utils.py", line 91, in time_sync
torch.cuda.synchronize()
File "/usr/local/lib/python3.8/dist-packages/torch/cuda/init.py", line 493, in synchronize
return torch._C._cuda_synchronize()
RuntimeError: CUDA error: an illegal memory access was encountered
[01/16/2022-04:18:32] [TRT] [E] 1: [defaultAllocator.cpp::deallocate::35] Error Code 1: Cuda Runtime (an illegal memory access was encountered)

Code:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

torch.backends.cudnn.benchmark = True
torch.backends.cudnn.enabled= False
model = torch.hub.load('ultralytics/yolov5', 'custom', 'model.engine', force_reload=True)
model.to(device)
model.half()

image = open("find.png", 'rb').read()
original_image = cv2.imdecode(np.frombuffer(image, np.uint8), cv2.IMREAD_COLOR)
resized_image = cv2.resize(original_image, (320, 320))
with torch.inference_mode():
    results = model(resized_image, size=320)

Additional

Name: torch
Version: 1.10.1+cu113

Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleStale and schedule for closing soonduplicateThis issue or pull request already existsquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions