Skip to main content

GPU acceleration

Lifer can use a graphics card (GPU) to match species faster. It's automatic: there's nothing to turn on, and no setting to choose. On a server you only need to give the container access to the GPU.

How it works​

Once species recognition is downloaded, Lifer runs a one-time hardware test when it starts:

  1. It looks for every GPU it can use.
  2. It checks that each one gives the same answers as the CPU. A GPU that doesn't is never used.
  3. It times them, and moves species recognition to the fastest GPU if it's at least 15% faster than the CPU. Otherwise it stays on the CPU.

Lifer remembers the result. It only tests again if the hardware, the graphics driver or the species recognition models change, or if you ask it to.

The speed-up can be large: even an older graphics card can match species several times faster than the CPU.

If anything goes wrong with a GPU, Lifer uses the CPU instead. Suggestions are the same either way, just slower.

What's supported​

Where Lifer runsGPUsWhat you need to do
Desktop app on a MacThe Mac's built-in GPUNothing.
Desktop app on WindowsAny GPU with a current driverNothing.
Docker or TrueNAS on LinuxNVIDIAPass the GPU into the container. See Docker or TrueNAS.
Docker or TrueNAS on LinuxIntel and AMDPass the GPU into the container. See Docker or TrueNAS.

Intel and AMD GPUs on Linux are detected and tested automatically, but they haven't been tried on many machines yet. If you have one, please report how it goes in an issue on GitHub.

The desktop app connected to a server​

When the desktop app is connected to a server, it can match photos on your computer or leave it to the server. It times both and uses whichever is faster, checking the other again every 20 photos or so. A server with a GPU often beats a laptop; a fast laptop beats a server without one. The import screen shows "Matching on this computer or the server, whichever is faster".

One-time downloads for NVIDIA​

The Lifer image doesn't include NVIDIA's software, so it stays small for everyone else. When Lifer finds an NVIDIA GPU, it downloads what it needs once, into its app data folder (/app-data in Docker):

  • NVIDIA's CUDA libraries, matched to your driver, about 1.5 GB.
  • A full-precision copy of the species identification model, about 1.2 GB.

That's about 2.7 GB in total. Until it finishes, species recognition runs on the CPU as usual. Mac, Windows, Intel and AMD don't need any extra downloads.

Give a Docker container the GPU​

GPU access lives in a second file, hwaccel.yml, so docker-compose.yml stays the same for everyone.

  1. Download hwaccel.yml into the folder with your docker-compose.yml.

  2. In docker-compose.yml, uncomment the extends lines under api: and set service to your GPU type:

    extends:
    file: hwaccel.yml
    service: nvidia # or intel-amd
  3. Do the setup for your GPU below, then run docker compose up -d.

NVIDIA​

On the server, install the NVIDIA driver (version 525 or newer) and the NVIDIA Container Toolkit. Check that the driver works by running nvidia-smi on the server. Use service: nvidia.

With plain docker run, add --gpus all instead.

Intel and AMD​

Lifer's user needs the server's render group to open the GPU. Find the group's number on the server:

stat -c %g /dev/dri/renderD128

Put it in .env as RENDER_GROUP_ID (for example RENDER_GROUP_ID=993), and use service: intel-amd.

Give a TrueNAS Custom App the GPU​

Lifer isn't in the TrueNAS app catalog yet, so on TrueNAS you run it as a Custom App from docker-compose.yml.

  1. NVIDIA only: open Apps > Configuration > Settings, tick Install NVIDIA Drivers, and save.

  2. A Custom App is a single YAML file, so hwaccel.yml can't be used. Add the lines for your GPU under api: directly, and save. TrueNAS restarts Lifer with the GPU.

    NVIDIA:

    deploy:
    resources:
    reservations:
    devices:
    - driver: nvidia
    count: all
    capabilities: [gpu]

    Intel or AMD, with your render group's number (see Intel and AMD) in place of 107:

    devices:
    - /dev/dri:/dev/dri
    group_add:
    - "107"

Check where species recognition runs​

Settings > Offline data > Species recognition shows whether species recognition runs on the CPU or a GPU, and which one.

Click Test again in Settings > Offline data > Recognition speed to run the test again, for example after you add a GPU, pass one into the container, or update the graphics driver.

Turn it off​

You shouldn't need to. For troubleshooting, set the LIFER_GPU environment variable to off and restart Lifer. Species recognition then always runs on the CPU. With Docker, set LIFER_GPU=off in .env and run docker compose up -d. On a TrueNAS Custom App, change the LIFER_GPU line in the app's YAML to LIFER_GPU: "off".

Troubleshooting​

Whatever happens with the GPU, Lifer keeps working on the CPU, so these only cost speed.

  • Species recognition stays on the CPU on a server with a GPU. The GPU probably isn't passed into the container. Follow Docker or TrueNAS, then click Test again. For NVIDIA, docker compose exec api nvidia-smi should list your card.
  • NVIDIA driver too old. Lifer needs NVIDIA driver 525 or newer. nvidia-smi on the server shows the version. Update the driver, restart Lifer, and click Test again.
  • Intel or AMD GPU isn't used. Check that /dev/dri is passed in and the render group number is right. Some older or very new GPUs may not work yet. Please let us know which GPU you have.
  • A GPU is found but not used. Either it gave slightly different answers than the CPU, or it wasn't at least 15% faster. That's on purpose: Lifer only uses a GPU when it's both correct and clearly faster.
  • The NVIDIA download failed. Lifer keeps species recognition on the CPU. Check the server can reach the internet and has about 3 GB free for app data, then click Test again.