Lossless data compression library with GPU acceleration, written in Rust.
| Pipeline | Stages | Similar to |
|---|---|---|
| Deflate | LZ77 + Huffman | gzip |
| BW | BWT + MTF + RLE + Range Coder | bzip2 |
| LZA | LZ77 + Range Coder | lzma-like |
Optional OpenCL support for GPU-accelerated LZ77 match finding and BWT suffix array construction.
pz file.txt # compress to file.txt.pz
pz -d file.txt.pz # decompress
pz -c file.txt # compress to stdout
pz -k file.txt # keep original after compress
pz -l file.txt.pz # list info about compressed file
pz -p bw file.txt # use BW pipeline (best ratio)
pz -g -p bw file.txt # use GPU for BWT (requires --features opencl)
cat file | pz -c # compress stdin to stdout
cat file | pz -dc # decompress stdin to stdout
Gzip (.gz) files are auto-detected during decompression.
cargo build --release
cargo build --release --features opencl
Requires an OpenCL SDK. See platform-specific notes below.
Set one of the following environment variables to point to your OpenCL SDK:
OPENCL_PATHorOPENCL_ROOT— SDK root withlib/orlib/x64/containingOpenCL.libCUDA_PATH— NVIDIA CUDA Toolkit (shipsOpenCL.lib)INTELOCLSDKROOT— Intel OpenCL SDKAMDAPPSDKROOT— AMD APP SDK
Build from a Visual Studio Developer shell, or use the helper script:
.\scripts\cargo-msvc.ps1 build --release --features openclsudo apt-get install ocl-icd-opencl-dev opencl-headers
cargo build --release --features opencl
Rust’s default Windows target is x86_64-pc-windows-msvc, which needs the Visual Studio build tools and Windows SDK (for kernel32.lib etc.).
-
If you get “link.exe not found” or “cannot open input file 'kernel32.lib'”
- Install or modify Build Tools for Visual Studio and ensure both are selected:
- Workload: Desktop development with C++
- Or in Individual components: MSVC v143+ and Windows 10/11 SDK.
- Open Developer PowerShell for VS (or x64 Native Tools Command Prompt) from the Start menu and run
cargo buildfrom there,
or from a normal shell run the helper script so the VS environment is set first:
# From repo root (D:\code\libpz): .\scripts\cargo-msvc.ps1 build # From libpz-rs (D:\code\libpz\libpz-rs): ..\scripts\cargo-msvc.ps1 build
- Install or modify Build Tools for Visual Studio and ensure both are selected:
-
Stay on the MSVC target; do not switch to the GNU toolchain unless you intentionally want a different target/ABI.
The opencl3 crate (via opencl-sys) links to OpenCL.lib — the MSVC import library. That is independent of the Rust GNU vs MSVC target: you stay on the MSVC target and need an OpenCL SDK that provides OpenCL.lib (not only OpenCL.dll or MinGW-style libOpenCL.a).
-
Provide a path that contains
OpenCL.lib
Set one of these (to the SDK root or the folder that contains thelibdirectory withOpenCL.lib):OPENCL_PATH— path to a folder that has alibsubfolder withOpenCL.lib(e.g.OPENCL_PATH=C:\OpenCL\sdkifOpenCL.libis inC:\OpenCL\sdk\libor...\lib\x64).OPENCL_ROOT— same idea; opencl-sys will look in%OPENCL_ROOT%\lib\x64(64-bit).CUDA_PATH— if you use the NVIDIA CUDA Toolkit, it shipsOpenCL.lib(e.g.C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.x); opencl-sys will use%CUDA_PATH%\lib\x64.INTELOCLSDKROOTorAMDAPPSDKROOT— for Intel or AMD OpenCL SDKs.
-
Where to get OpenCL.lib
- NVIDIA: Install CUDA Toolkit; set
CUDA_PATHto the toolkit root (e.g.C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3). - Intel: Intel SDK for OpenCL or CPU runtime; set
INTELOCLSDKROOTorOPENCL_PATHto the SDK root that haslib\x64\OpenCL.lib. - AMD: AMD APP SDK; set
AMDAPPSDKROOTaccordingly.
- NVIDIA: Install CUDA Toolkit; set
-
MinGW / “GNU” OpenCL
If your OpenCL install only has MinGW/GNU libraries (e.g.libOpenCL.a), that does not work with the MSVC target. Use an SDK that includes OpenCL.lib (e.g. CUDA or Intel SDK) and the env var above, and keep using the MSVC target.
Then build with the VS environment (Developer PowerShell or the script) and:
# From repo root:
.\scripts\cargo-msvc.ps1 build --features opencl
# From libpz-rs:
..\scripts\cargo-msvc.ps1 build --features openclcargo test # CPU-only tests
cargo test --features opencl # includes GPU tests (skip gracefully if no device)
Uses criterion for statistical benchmarks.
cargo bench # CPU benchmarks
cargo bench --features opencl # includes GPU benchmarks
Two benchmark suites:
benches/throughput.rs— end-to-end pipeline throughput (MB/s) with external tool comparison (gzip, pigz, zstd)benches/stages.rs— per-algorithm scaling at 1KB / 10KB / 64KB
cargo clippy -- -D warnings
cargo fmt -- --check
opencl— Enable GPU acceleration via OpenCL (LZ77 match finding + BWT suffix array construction)
GitHub Actions workflow runs on every push/PR to master:
- CPU tests on ubuntu, windows, macos
- Lint (clippy + rustfmt)
- OpenCL compile check (ubuntu)
- Benchmark compilation and execution