Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f4fc92e
add rocjpeg support
xytpai Jan 8, 2026
a371c3e
update rocjpeg utils
xytpai Jan 8, 2026
e4c4fd0
rm cout
xytpai Jan 8, 2026
3d9041c
refine code
xytpai Jan 16, 2026
1d29986
rm unused file
xytpai Jan 16, 2026
15d8f11
refine code 2
xytpai Jan 16, 2026
fb2f9fc
Merge branch 'main' into xyt/rocjpeg_upstream
xytpai Jan 27, 2026
bc8c702
Merge branch 'main' into xyt/rocjpeg_upstream
zy1git Jan 28, 2026
173c23d
Merge branch 'main' into xyt/rocjpeg_upstream
zy1git Jan 28, 2026
09c589d
Merge branch 'main' into xyt/rocjpeg_upstream
xytpai Feb 9, 2026
8d4f6ff
Merge branch 'main' into xyt/rocjpeg_upstream
xytpai Jun 12, 2026
b68f0ef
full format support
xytpai Jun 13, 2026
e113fcc
remove stream dependency
xytpai Jun 13, 2026
85b55f1
make batch-size dynamic
xytpai Jun 13, 2026
dd23f0e
resolve remaining comments
xytpai Jun 13, 2026
722a4af
[ROCm] Clean up rocJPEG decode and share GPU JPEG scaffolding (#2)
jeffdaily Jun 18, 2026
a319739
refine IMAGE_READ_MODE_UNCHANGED
xytpai Jun 18, 2026
4b71908
rm dead code & refine comment
xytpai Jun 18, 2026
7ce968f
recover nv path
xytpai Jun 18, 2026
248894c
resolve comments
xytpai Jun 18, 2026
802cac2
apply clang-format
xytpai Jun 18, 2026
d942228
Separate rocJPEG and nvJPEG setup blocks
xytpai Jun 19, 2026
7581393
add _ suffix for private class members
xytpai Jun 19, 2026
a4073b0
just return padded tensor in its original layout
xytpai Jun 19, 2026
a2572c8
rm unnecessary sync
xytpai Jun 22, 2026
b413e54
refine code
xytpai Jun 22, 2026
0fe060a
add rocjpeg doc link
xytpai Jun 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
USE_JPEG = os.getenv("TORCHVISION_USE_JPEG", "1") == "1"
USE_WEBP = os.getenv("TORCHVISION_USE_WEBP", "1") == "1"
USE_NVJPEG = os.getenv("TORCHVISION_USE_NVJPEG", "1") == "1"
USE_ROCJPEG = os.getenv("TORCHVISION_USE_ROCJPEG", "1") == "1"
NVCC_FLAGS = os.getenv("NVCC_FLAGS", None)

TORCHVISION_INCLUDE = os.environ.get("TORCHVISION_INCLUDE", "")
Expand All @@ -45,6 +46,7 @@
print(f"{USE_JPEG = }")
print(f"{USE_WEBP = }")
print(f"{USE_NVJPEG = }")
print(f"{USE_ROCJPEG = }")
print(f"{NVCC_FLAGS = }")
print(f"{TORCHVISION_INCLUDE = }")
print(f"{TORCHVISION_LIBRARY = }")
Expand Down Expand Up @@ -344,18 +346,31 @@ def make_image_extension():
else:
warnings.warn("Building torchvision without WEBP support")

if USE_NVJPEG and (torch.cuda.is_available() or FORCE_CUDA):
nvjpeg_found = CUDA_HOME is not None and (Path(CUDA_HOME) / "include/nvjpeg.h").exists()

if nvjpeg_found:
print("Building torchvision with NVJPEG image support")
libraries.append("nvjpeg")
define_macros += [("NVJPEG_FOUND", 1)]
Extension = CUDAExtension
if IS_ROCM:
if USE_ROCJPEG and (torch.cuda.is_available() or FORCE_CUDA):
rocjpeg_found = ROCM_HOME is not None and (Path(ROCM_HOME) / "include/rocjpeg/rocjpeg.h").exists()
if rocjpeg_found:
print("Building torchvision with ROCJPEG image support")
libraries.append("rocjpeg")
define_macros += [("ROCJPEG_FOUND", 1)]
Extension = CUDAExtension
else:
warnings.warn("Building torchvision without ROCJPEG support")
else:
warnings.warn("Building torchvision without ROCJPEG support")
else:
if USE_NVJPEG and (torch.cuda.is_available() or FORCE_CUDA):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just leave the previous if USE_NVJPEG and (torch.cuda.is_available() or FORCE_CUDA): block exactly like it was, and just have a separate (indepentent) ROCm-specific block below it? They should be mutually exclusive?

nvjpeg_found = CUDA_HOME is not None and (Path(CUDA_HOME) / "include/nvjpeg.h").exists()

if nvjpeg_found:
print("Building torchvision with NVJPEG image support")
libraries.append("nvjpeg")
define_macros += [("NVJPEG_FOUND", 1)]
Extension = CUDAExtension
else:
warnings.warn("Building torchvision without NVJPEG support")
elif USE_NVJPEG:
warnings.warn("Building torchvision without NVJPEG support")
elif USE_NVJPEG:
warnings.warn("Building torchvision without NVJPEG support")

return Extension(
name="torchvision.image",
Expand Down
5 changes: 4 additions & 1 deletion test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,15 @@ def test_decode_jpegs_cuda(mode, scripted):
futures = [executor.submit(decode_fn, encoded_images, mode, "cuda") for _ in range(num_workers)]
decoded_images_threaded = [future.result() for future in futures]
assert len(decoded_images_threaded) == num_workers
# rocJPEG's color conversion differs slightly from nvJPEG, so it needs a
# looser tolerance against the CPU reference.
tol = 2.5 if torch.version.hip is not None else 2
for decoded_images in decoded_images_threaded:
assert len(decoded_images) == len(encoded_images)
for decoded_image_cuda, decoded_image_cpu in zip(decoded_images, decoded_images_cpu):
assert decoded_image_cuda.shape == decoded_image_cpu.shape
assert decoded_image_cuda.dtype == decoded_image_cpu.dtype == torch.uint8
assert (decoded_image_cuda.cpu().float() - decoded_image_cpu.cpu().float()).abs().mean() < 2
assert (decoded_image_cuda.cpu().float() - decoded_image_cpu.cpu().float()).abs().mean() < tol


@needs_cuda
Expand Down
Loading