Capture time with NVIDIA GPU on Windows is unstable

Problem

The capture time is unstable or variable when capturing using an NVIDIA GPU on Windows. More specifically, captures with longer pauses between them are slower than captures with shorter pauses.

Cause

The GPU driver has a power saving feature which lowers the GPU clock and memory frequencies when it is not actively used.

Solution

Lock the GPU clock and memory frequencies to constant values or ranges with nvidia-smi to maintain consistent processing times. Read out the available clock frequencies by

nvidia-smi --query-supported-clocks=graphics --format=csv
nvidia-smi --query-supported-clocks=mem --format=csv

This will list multiple supported frequencies, where higher frequencies give better performance. Then lock the clock frequency by

nvidia-smi --lock-gpu-clocks="<minGpuClock>, <maxGpuClock>"
nvidia-smi --lock-memory-clocks="<minMemClock>, <maxMemClock>"

where <minGpuClock> and <maxGpuClock> are the desired min and max GPU clock frequencies, while <minMemClock> and <maxMemClock> are the desired min and max memory clock frequencies. Use the same value for both min and max if you want to lock the frequency to a constant value.

Note

Not all NVIDIA GPUs support the --lock-gpu-clocks and/or --lock-memory-clocks options. Try updating the GPU driver to the latest version if the options are not available.

To reset the clock frequencies back to default, use

nvidia-smi --reset-gpu-clocks
nvidia-smi --reset-memory-clocks