cujpegxl - GPU CUDA-accelerated JPEG XL encoder
This project is a GPU-accelerated CUDA implementation of a JPEG XL encoder, covering a GPU- and real-time-friendly subset of the JPEG XL algorithm.
Goals
- Conformance. The encoded image must be readable by any standard-conforming decoder.
- Real-time performance with 4K resolution inputs on a constrained device.
Speed
| Platform | fps |
|---|---|
| GTX 1080Ti | 325 |
| Tegra T234 | 64 |
On a T234 SoC (15 W mode) encoding a 4K frame uses 16 ms of GPU time and 36 ms of CPU core time.
Maximum throughput can be achieved by pipelining multiple frames. Optimal pipeline depth depends on the target hardware, the results above use a depth of 3 frames on the 1080Ti and 2 frames on the T234.
Quality
Quality is close to libjxl. Some algorithmic approximations trade off a small amount of quality and compression rate in exchange for speed.
The results above can be reproduced with the 100-image subset of //eval_dataset at 2160p resolution (bazelisk run //eval_dataset:prepare_dataset -- --resolution 2160p --limit 100 ...). See Evaluation tools below for details.
Input formats
The encoder supports 8-bit sRGB input in these formats:
- YUV420 (
NV12orNV21) - Packed YUV422 (
UYVYorYUYV) - Packed
RGB8/BGR8(orRGBA8/BGRA8)
YUV can be BT.709 or BT.601, either in full or limited range.
Usage
C and C++
The project exposes a versioned C API/ABI in cujpegxl/cujpegxl.h. See also examples/api_usage for an API usage example in C++.
#include "cujpegxl/cujpegxl.h"
cujpegxl_config config = {.width = 3840, .height = 2160, .distance = 1.0f};
size_t capacity;
cujpegxl_max_output_size(&config, &capacity);
cujpegxl_output outputs[2] = {
{.data = malloc(capacity), .capacity = capacity},
{.data = malloc(capacity), .capacity = capacity},
};
/* Up to 2 frames in flight on device 0. */
cujpegxl_encoder* encoder;
cujpegxl_encoder_create(&config, 0, 2, &encoder);
cujpegxl_output* encoded;
for (int frame = 0; frame < frame_count; ++frame) {
if (frame >= 2) {
/* Waits for the oldest frame and frees its output for reuse. */
cujpegxl_encoder_receive(encoder, &encoded);
fwrite(encoded->data, 1, encoded->size, file);
}
/* Device pointers to the frame's NV12 planes, e.g. from a decoder or camera. */
cujpegxl_input input = {
.format = CUJPEGXL_FORMAT_NV12,
.planes = {d_luma[frame], d_chroma[frame]},
.pitches = {luma_pitch, chroma_pitch},
.stream = stream, /* the stream the planes were written on */
};
cujpegxl_encoder_submit(encoder, &input, &outputs[frame % 2]);
}
while (cujpegxl_encoder_receive(encoder, &encoded) == CUJPEGXL_OK) {
fwrite(encoded->data, 1, encoded->size, file);
}
cujpegxl_encoder_destroy(encoder);
Python
Python bindings are provided in //python:cujpegxl, and published on PyPI for Linux x86_64 and CPython 3.12 or newer:
pip install cujpegxl
The wheel needs an NVIDIA driver that supports the GPU, at least 525.60.13 on Linux (528.33 on Windows if using WSL) for the supported architectures. Other GPU families run the PTX through the driver's JIT compiler, which needs at least 575.57.08 on Linux (576.57 on Windows).
A cujpegxl.Encoder is a pipelined encoder, and takes input buffers either from device memory through DLPack or __cuda_array_interface__ (e.g. PyTorch, CuPy, JAX or Numba arrays) or from host memory through DLPack or the buffer protocol (e.g. NumPy arrays or CPU PyTorch tensors).
import cujpegxl
with cujpegxl.Encoder(3840, 2160, distance=1.0, pipeline_depth=2) as encoder:
for rgb in frames:
if encoder.in_flight == encoder.pipeline_depth:
file.write(encoder.receive())
encoder.submit(rgb, format=cujpegxl.Format.RGB8, stream=stream) # the stream the buffer was written on
while encoder.in_flight:
file.write(encoder.receive())
The pipelined asynchronous approach above is suited for applications where performance matters. As a convenience for a single image, if performance is not crucial, cujpegxl.encode creates an encoder of the image's size and returns the output synchronously.
import cujpegxl
jxl = cujpegxl.encode(rgb, distance=1.0, format=cujpegxl.Format.RGB8)
Supported architectures
cujpegxl can be built for a broad range of GPUs, targeting both x86_64 and aarch64. However, performance is currently not fine-tuned for all individual architectures, with focus being primarily on Tegra, and architecture-specific optimizations for different GPU families will be progressively expanded.
The Python wheels include SASS for the following GPU architectures, and PTX that can be used by other GPU families not in the list.
| Architecture | Compute capability | Example GPUs |
|---|---|---|
| Pascal | 6.1 | GTX 10xx |
| Turing | 7.5 | RTX 20xx, GTX 16xx, T4 |
| Ampere | 8.0, 8.6, 8.7 | A100, RTX 30xx, A10, Jetson Orin |
| Ada | 8.9 | RTX 40xx, L4, L40 |
| Hopper | 9.0 | H100, H200 |
| Blackwell | 10.0, 10.3, 12.0, 12.1 | B200, B300, RTX 50xx, GB10 |
Build system integration
See examples for integration in Bazel (examples/bazel_consumer) and CMake (examples/cmake_consumer) projects.
Source builds must set the target CUDA architecture(s) with the --@rules_cuda//cuda:archs flag; any build of CUDA code fails without it.
Example:
bazelisk build //... '--@rules_cuda//cuda:archs=sm_86;sm_89'
The flag can also be set locally for a project in a .bazelrc.user file at the repository root:
build --@rules_cuda//cuda:archs=sm_86;sm_89
Example toolchain integrations for hermetic cross-compilation targeting Tegra T234 on JetPack 6.2 (CUDA 12.6) and 7.2 (CUDA 13.2) are provided for illustrative purpose:
bazelisk build --config=jetson_jp62 //packaging:install_tree
bazelisk build --config=jetson_jp72 //packaging:install_tree
Features
Quality and compression rate are lower compared to the reference libjxl implementation. This is expected, as cujpegxl only implements a subset of the JPEG XL algorithm, excluding some parts of it (in particular, some GPU-unfriendly steps are intentionally omitted for performance reasons).
Notable exclusions include:
- rANS+Huffman coding used only for AC coefficients; DC and AcMetadata use Huffman coding only.
- LZ77 pre-pass is omitted.
- No non-square, <8 and >32 transforms.
- No iterative Butteraugli rate control.
Some numerical approximations are made for performance reasons, trading a bit of quality for speed:
- Huffman codes limited to 15 bit.
- Quantization global scale computed from histogram only rather than exact median.
- Transform selection uses a simpler heuristic.
- Fuzzy erosion is local (clamped to a 32px tile) as opposed to global.
- Context clustering uses <=32 clusters (as opposed to libjxl's 128) and a simplified cost model.
- DCT coefficients stored as FP16.
- Uniform field quant calibration.
- Fixed-strength inverse Gaborish pre-sharpening.
- Simplified CfL estimation.
Some features are not implemented:
- Modular mode and lossless compression.
- Single-group frames (or, in general, inputs 256x256 or smaller).
- Multi-pass encoding.
- Reference frames.
- ICC colour profiles.
Evaluation tools
A small development set of freely licensed images is bundled in //data:frames. See data/LICENSE.txt for credits and respective licenses.
The //eval_dataset package implements tooling to generate a reproducible evaluation dataset using high-quality and free-license images, while //tools/quality_benchmark implements comparative compression quality benchmarking, see eval_dataset/README.md for information.
Code checks
To run tests and various code checks:
# Including GPU tests
bazelisk test //...
# Excluding GPU tests
bazelisk test //... --test_tag_filters=-gpu
# Sanitizers
bazelisk test --config=asan //... --test_tag_filters=-gpu,-no-sanitizers
bazelisk test --config=ubsan //... --test_tag_filters=-gpu,-no-sanitizers
bazelisk test --config=tsan //... --test_tag_filters=-gpu,-no-sanitizers
# Code style
bazelisk build --config=clang-tidy //...
bazelisk run //tools/format:format.check
# Fix formatting
bazelisk run //tools/format
Credits
The implementation is a derivative work of libjxl, see the License section below for details.
The source code of this project is almost entirely LLM-generated, using a mix of GLM-5.3, GLM-5.2, Qwen 3.8, GPT-5.6 Sol, and Claude Opus 4.8.
Disclaimer
JPEG and JPEG XL are trademarks of their respective owners. cujpegxl is an independent project and is not affiliated with or endorsed by the JPEG committee.
License
The cujpegxl software is made available under a BSD-3-Clause license.
This software is a derivative work of libjxl, the reference JPEG XL implementation, which is made available by its authors under the same license type.
For additional patent rights, see the PATENTS file in the libjxl source codebase.
Metadata
Release files for cujpegxl 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cujpegxl-0.0.1-cp312-abi3-manylinux_2_28_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ x86-64 | Details for cujpegxl-0.0.1-cp312-abi3-manylinux_2_28_x86_64.whl |
Release files / cujpegxl-0.0.1-cp312-abi3-manylinux_2_28_x86_64.whl
| Download URL | cujpegxl-0.0.1-cp312-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1e972bd2e037e37e8a56bc3c64478f6342531c0e4c9f079dd1f38ed5aa104714
|
|
BLAKE2b-256 checksum How to use checksums |
48008b518fd7a529eb9ec66107c41ff42fb7cb7a3a9c69e85f22fbe6a0c8b955
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for cujpegxl 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.