-
Debian Grok
.debpackages can be found here -
Archlinux Grok Archlinux packages can be found here
-
Homebrew Grok can be installed using the
grokj2kbrew formula
Grok releases can be found here
git clone --recursive https://github.com/GrokImageCompression/grok.git
Grok uses cmake to configure builds across multiple platforms. It requires version 3.20 or higher.
Supported compilers:
- g++ : version 12 or higher (C++23 required)
- clang : version 16 or higher (C++23 required)
- MSVC : 2022 or higher
- Binaryen for WebAssembly
To ensure that g++ 12 is the default compiler after installation, execute:
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 --slave /usr/bin/g++ g++ /usr/bin/g++-12
To ensure that clang-16 is the default compiler after installation, execute:
$ sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-16 60
$ sudo update-alternatives --config c++
The second line brings up a menu allowing a user to configure the default c++ compiler, which is what is used by cmake to configure the project compiler.
The Emscripten SDK can installed by following these instructions
The SDK includes a helper script, emcmake, to configure cmake.
emcmake command:
$ emcmake cmake -DBUILD_SHARED_LIBS=OFF -DGRK_BUILD_CODEC=OFF -DGRK_BUILD_LIBPNG=OFF -DBUILD_TESTING=OFF -DGRK_BUILD_CORE_EXAMPLES=ON PATH/TO/SOURCE
Now the core example that decompresses from a buffer can be runs as follows:
$ node --experimental-wasm-threads bin/core_decompress_from_buf.js
Note: WebAssembly by default is sand-boxed and not allowed to access the file system, so
only the core_decompress_from_buf example will run.
To configure a build using the defaults:
$ mkdir /PATH/TO/BUILD
$ cd /PATH/TO/BUILD
$ cmake /PATH/TO/SOURCE
The cmake GUI is recommended, in order to view all cmake options.
On Linux distributions, cmake-gui will launch the cmake GUI.
On headless systems, ccmake (an ncurses application)
may be used to configure the build.
The BUILD_SHARED_LIBS cmake flag determines if the grk_compress
and grk_decompress binaries are linked dynamically or statically.
A static build on most systems will still link dynamically
to glibc. For a purely static build, the library can be built
on Alpine Linux. Alpine uses
musl libc, which can be linked to statically.
Note: cmake must also be configured with -DCMAKE_EXE_LINKER_FLAGS="-static".
- if the Grok library has been installed and you would still like to run the binaries
from the build folder, then
export LD_LIBRARY_PATH=/PATH/TO/BUILD/bin:/usr/local/lib64must be added to the.bashrcfile. Note that the build binary folder is entered before the system binary folder, so that build shared libraries are given priority when loading at run time. - for a static build, the following library must be installed:
sudo dnf install libstdc++-static
Default build type is Release. For a Debug build, configure
cmake with -DCMAKE_BUILD_TYPE=Debug
$ make -j$(nproc)
for a machine with multiple logical cores.
Binaries are located in the bin directory.
Root users may run:
$ make install
those with sudo powers can run:
$ sudo make install
and everyone else can run:
$ DESTDIR=$HOME/local make install
Note: On Linux, after a shared library build, run
$ sudo ldconfig
to update the shared library cache.
To build the Doxygen documentation (Doxygen needs to be found on the system):
$ make doc
A HTML directory is generated in the doc directory
Important cmake flags:
- To specify the install path: use
-DCMAKE_INSTALL_PREFIX=/path, or useDESTDIRenv variable (see above) - To build the shared libraries and link the executables against it:
-DBUILD_SHARED_LIBS:bool=on (default: ON)
Note: when using this option, static libraries are not built and executables are dynamically linked.
- To build the core codec :
-DGRK_BUILD_CODEC:bool=ON(default:ON) - To build the documentation:
-DGRK_BUILD_DOC=ON(default:OFF) - To enable testing : see TESTING.md
macOS builds are configured similar to *NIX builds. The Xcode project files can be generated using:
$ cmake -G Xcode ....
The BUILD_SHARED_LIBS cmake flag determines if the grk_compress and grk_decompress
binaries are linked to dynamic or static builds of the codec library libgrokj2k,
and also if a static or dynamic version of libgrokj2k is built on the system.
cmake can generate project files for various IDEs: Visual Studio, Eclipse CDT, NMake, etc.
Type cmake --help for available generators on your platform.
Third party libraries such as libtiff are built by default. To disable
libtiff library build and use the version installed on your system, set :
-DGRK_BUILD_LIBTIFF:BOOL=OFF
- set
CMAKE_INSTALL_PREFIXto/PATH/TO/INSTALL/DIR - build and install
- on other project, set
CMAKE_PREFIX_PATHto/PATH/TO/INSTALL/DIR
Grok provides bindings for Python, C#, Java, and Rust.
- Python/C#/Java (SWIG): see bindings/swig/README.md for build instructions, API reference, and test information.
- Rust (bindgen): see bindings/rust/README.md for build and usage instructions.
Grok supports GPU-accelerated Tier-1 encode and decode via the
closed source grok-gpu-plugin project.
The plugin offloads DWT, bit-plane coding, and MQ arithmetic coding to
NVIDIA CUDA GPUs while Grok handles file I/O, header parsing, and Tier-2
packet assembly.
| Dependency | Version | Notes |
|---|---|---|
| CUDA Toolkit | ≥ 11.0 | CUDA 12.x recommended |
| NVIDIA GPU | CC ≥ 6.0 | Tested on Ampere (CC 8.6) |
| C++23 compiler | GCC 13+ | Also tested with Clang 17+ |
| CMake | ≥ 3.21 |
The plugin is built independently from Grok as a shared library:
# Clone with submodules
git clone --recurse-submodules <plugin-repo-url>
cd grok-gpu-plugin
# Configure (shared library, CUDA enabled)
cmake -B build -S . \
-DCMAKE_BUILD_TYPE=Debug \
-DGRK_GPU_BUILD_SHARED=ON \
-DGRK_GPU_USE_CUDA=ON \
-DGRK_GPU_CUDA_ARCH=86 \
-DGRK_GPU_BUILD_TESTS=ON \
-DGRK_GPU_BUILD_TOOLS=OFF
# Build
cmake --build build -j$(nproc)
# Verify (optional)
ctest --test-dir build --output-on-failureReplace 86 with your GPU's compute capability (e.g., 75 for Turing,
90 for Hopper).
Grok discovers the plugin by searching for libgrokj2k_plugin.so in the
same directory as the Grok executables. The plugin builds as
libgrok_gpu_plugin.so, so a symlink is required:
ln -sf /PATH/TO/grok-gpu-plugin/build/libgrok_gpu_plugin.so \
/PATH/TO/grok/build/bin/libgrokj2k_plugin.soThe symlink must be recreated if the plugin or Grok build directory changes.
Pass -k 1 to grk_compress or grk_decompress to enable GPU acceleration.
grk_compress -i input.tiff -o output.jp2 -k 1grk_decompress -i input.jp2 -o output.tif -k 1grk_compress --batch-src /path/to/tiffs \
--out-dir /path/to/output \
--out-fmt jp2 \
-k 1 -e 10grk_decompress --batch-src /path/to/jp2s \
--out-dir /path/to/output \
--out-fmt tif \
-k 1 -e 10The -e flag sets the number of executor threads for batch file I/O.
| Variable | Value | Purpose |
|---|---|---|
CUDA_MODULE_LOADING |
EAGER |
Required. Ensures CUDA modules load at init time |
GRK_DEBUG |
1–5 |
Optional. Verbosity: 1=error 2=warn 3=info 4=debug 5=trace. Level ≥ 3 enables plugin verbose output |
- Single tile per image (no multi-tile images)
- Precision: 8, 10, 12, or 16 bits per component
- No subsampling (
dx = dy = 1) - Maximum 4 components
- No code block style extensions (
cblk_sty = 0) - Unsigned samples only
-
Python bindings: When
libgrokj2k_plugin.sois present inbuild/bin/, the plugin's auto-discovery intercepts Python SWIG binding calls togrk_codec_compress(). Remove or rename the symlink before running Python tests viactest. -
CUDA cleanup at exit: The executables call
grk_deinitialize()before returning frommain()to ensure CUDA resources are released before the CUDA runtime unloads. This is handled automatically bygrk_compressandgrk_decompress; library consumers should callgrk_deinitialize()at process exit if using the GPU plugin.
The repository includes GPU launch configurations in .vscode/launch.json:
| Configuration | Description |
|---|---|
single compress GPU |
Single-file GPU compress |
single decompress GPU |
Single-file GPU decompress |
compress GPU |
Batch GPU compress (directory of TIFFs) |
decompress GPU |
Batch GPU decompress (directory of JP2s) |
These configs set CUDA_MODULE_LOADING=EAGER and GRK_DEBUG=3 automatically.