Skip to content

Commit 82f9a18

Browse files
authored
Add warning in docs and Cpp code for nvjpeg leak on CUDA < 11.6 (#5482)
1 parent 7251769 commit 82f9a18

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ torch::Tensor decode_jpeg_cuda(
4747

4848
TORCH_CHECK(device.is_cuda(), "Expected a cuda device")
4949

50+
int major_version;
51+
int minor_version;
52+
nvjpegStatus_t get_major_property_status =
53+
nvjpegGetProperty(MAJOR_VERSION, &major_version);
54+
nvjpegStatus_t get_minor_property_status =
55+
nvjpegGetProperty(MINOR_VERSION, &minor_version);
56+
57+
TORCH_CHECK(
58+
get_major_property_status == NVJPEG_STATUS_SUCCESS,
59+
"nvjpegGetProperty failed: ",
60+
get_major_property_status);
61+
TORCH_CHECK(
62+
get_minor_property_status == NVJPEG_STATUS_SUCCESS,
63+
"nvjpegGetProperty failed: ",
64+
get_minor_property_status);
65+
if ((major_version < 11) || ((major_version == 11) && (minor_version < 6))) {
66+
TORCH_WARN_ONCE(
67+
"There is a memory leak issue in the nvjpeg library for CUDA versions < 11.6. "
68+
"Make sure to rely on CUDA 11.6 or above before using decode_jpeg(..., device='cuda').");
69+
}
70+
5071
at::cuda::CUDAGuard device_guard(device);
5172

5273
// Create global nvJPEG handle

torchvision/io/image.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ def decode_jpeg(
145145
with `nvjpeg <https://developer.nvidia.com/nvjpeg>`_. This is only
146146
supported for CUDA version >= 10.1
147147
148+
.. warning::
149+
There is a memory leak in the nvjpeg library for CUDA versions < 11.6.
150+
Make sure to rely on CUDA 11.6 or above before using ``device="cuda"``.
151+
148152
Returns:
149153
output (Tensor[image_channels, image_height, image_width])
150154
"""

0 commit comments

Comments
 (0)