z-stackr

Optional · the gpu feature

On the graphics card

Alignment, the Apex, Relief and Strata fusions and the Relief multigrid solver can run on the GPU through wgpu (Vulkan, Direct3D 12 or Metal). The CPU stays the reference and the fallback.

01What runs where

StageOn the GPU
Alignment: the objectiveyes. Each candidate transform is evaluated on the device; the optimiser itself stays on the CPU. Pyramid levels under 64k pixels are evaluated on the CPU, where they are faster.
Alignment: the final warpyes, with the coverage mask from the same pass
Apex fusionyes, the whole fusion: pyramids, selection, averaged base, reconstruction
Relief fusionyes: focus maps, selection against the threshold, guided filter (focus radius up to 100)
Relief multigrid solveryes: the pinned depth is uploaded once and the whole cycle (restrict, prolong, Jacobi sweeps) runs on the device; the focus maps and the final smoothing stay on the CPU
Strata fusionyes for its two heavy steps: the saliency of each frame and the guided-filter pair that refines the layer weights. The base/detail split, the accumulation and the final blend stay on the CPU
Decoding, auto-cull, exportno

Frames are folded in one at a time on the device, so its memory does not grow with the number of frames, and only the result comes back. During alignment each pyramid level goes up once; the hundreds of evaluations the optimiser makes on it move only a few numbers. Lucas-Kanade, the first step of the auto optimizer, is a CPU path in every build: only the Nelder-Mead objective runs on the device, so a GPU run with optimizer = "neldermead" uses the alignment kernels fully. In the command-line tool Strata runs on the CPU.

In the browser version only the alignment runs on the GPU, through WebGPU; the fusions, Strata and the multigrid solver run on the CPU in a Web Worker.

02Switching it on

Build with the gpu feature and set the compute device to GPU, in the desktop app's settings (Compute device) or in the settings file:

terminal
cargo build --release -p z-stackr-gui --features gpu
cargo build --release -p z-stackr-cli --features gpu
settings.toml
compute_device = "gpu"

Without the feature, no GPU code is linked, the settings offer the CPU only, and a settings file that asks for the GPU still loads: the run uses the CPU and says so. The best adapter is chosen automatically: a discrete card before an integrated one, Vulkan before Direct3D 12.

03When the GPU cannot help

A run never fails because of the GPU.

What happensWhat z-stackr does
no usable adapter, or a build without GPU supportthe CPU from the start, with one message saying why
a call needs more device memory than the budget (3 GiB), or a setting the kernels do not coverthe CPU for that call only; the GPU stays on for the others
the device reports an error, a call fails or returns non-finite valuesthe CPU for that call and the rest of the run, with one message giving the reason

04How close it is to the CPU

The GPU kernels follow the CPU code operation for operation and are tested against it, but they are not bit for bit the same: drivers may fuse a multiply and an add, and the GPU's division is not always correctly rounded.

Because the objective differs in the last digits, an alignment on the GPU can take a slightly different path through the search. Where the frames have a clear best fit, both land within about a thousandth of a pixel of each other. Where the fit is flat (two frames far apart in focus share little detail), both land on points of equal quality that can be a few tenths of a pixel apart, about as far as the CPU's own alignment modes differ from each other there.

05Speed

TO BE MEASURED

Timings will be published here once they have been measured on a quiet machine; this includes whether the multigrid solver on the device beats the CPU solve, and the Strata kernels. The first, informal runs on an integrated GPU showed the largest gain in alignment, where the optimiser's many evaluations stay on the device, and a smaller one for the fusions, which are limited by uploading the frames.