BitPacking.jl is a Julia package that implements bitpacking and unpacking arrays with element bit-widths from 1 to 8, imposing mild size limitations on the first dimension. Bitpacking methods are designed to be device-agnostic, meaning they run fast on GPUs.
using BitPacking
x = rand(UInt8, 32) .& 0b1111 # 4-bit unpacked values
y = bitpacked(x, 4) # half the memory size
x == y == bitunpacked(y) # true
# broadcasting assignment works
y .= rand(UInt8, 32) .& 0b1111 # assign new values
- The first dimension of the input array must currently be divisible by the least common multiple of 8 and the bitwidth.
- Broadcasting assignment first materializes the unpacked result.
using Pkg
Pkg.add("BitPacking")
BitPacking.jl is partially inspired by IntArrays.jl