r/CUDA • u/Sure_Resource4753 • 4d ago
exact-gpu-jpeg: CUDA JPEG decode/encode that’s byte-identical to libjpeg-turbo and Pillow
GPU JPEG decoders are fast, but their pixels differ from the CPU libraries'. On 102 public test images, nvJPEG matched libjpeg-turbo on none of them, by up to 110 levels at 4:2:0. That quietly breaks reproducible ML pipelines, test baselines and caches whenever decoding moves between CPU and GPU.
exact-gpu-jpeg decodes on the GPU and returns libjpeg-turbo's pixels byte for byte (accurate IDCT, fancy upsampling), and its encoder writes the same bytes as Pillow. Anything it can't reproduce exactly, progressive files for example, goes to libjpeg-turbo itself, so the output is always the reference.
On a 2016 GTX 1070: a 30 MP camera photo decodes in 11.3 ms, against 185 ms for libjpeg-turbo on one core and 164 ms for nvJPEG on the same card. Batches of small images: 7,310 images/s. Encoding: 5.5x faster than Pillow with identical files.
Where it loses is listed near the top of the README: one small image at a time, small encodes against 8 CPU threads, progressive files. Everything so far is from one machine, so results from other GPUs are very welcome: `python bench/reproduce.py --quick`, and there's a pinned issue for them.
The parallel Huffman stage (Weißenberger & Schmidt's self-synchronising method) is drawn in docs/huffman-sync.md, and there's a white paper in docs/ covering the method, the evidence and the limits.
2
u/mherf 4d ago
Very nice!
fwiw, nvJPEG is not really accelerated on the GTX/RTX GPUs, they only accelerated Huffman on the A100 and similar datacenter GPUs, see https://developer.nvidia.com/blog/leveraging-hardware-jpeg-decoder-and-nvjpeg-on-a100/
I ran your benchmark on RTX 5070ti - here is bench/reproduce.py - GPU utilization overall is low. ~1ms for 24MP operations is amazing.
## Decode, one image at a time (ms per image, lower is better)| size | file | libjpeg-turbo (simplejpeg), CPU | exact-gpu-jpeg | speed-up | decoded on | pixels equal to libjpeg-turbo's ||---|---|---|---|---|---|---|| 0.25 MP (616x408) | 35.7 kB | 0.39 | 0.52 | 0.8x | GPU | yes || 1 MP (1224x816) | 136.3 kB | 1.52 | 0.59 | 2.6x | GPU | yes || 2 MP (1736x1160) | 279.2 kB | 3.04 | 0.69 | 4.4x | GPU | yes || 6 MP (3000x2000) | 840 kB | 9.16 | 0.83 | 11.1x | GPU | yes || 12 MP (4240x2824) | 1655 kB | 18.02 | 0.94 | 19.1x | GPU | yes || 24 MP (6000x4000) | 3359.7 kB | 39.57 | 1.40 | 28.3x | GPU | yes |## Decode, 64 different images per call (images per second, higher is better)## Encode, quality 90, 4:2:0 (ms per image, lower is better)1
u/Sure_Resource4753 4d ago
Summary Image
1
u/Sure_Resource4753 4d ago edited 4d ago
UnHuff: faster Huffman stage decoding’s parallel huffman diagram
1
u/TQ_GPU 3d ago
"30 MP camera photo decodes in 11.3 ms" --> is this 12 GB/s decode speed?