# Engines and GPU backends

Mirli ships and vendors no native binaries. It uses three engines, each
fetched from its upstream GitHub releases on request and cached under the
data folder. Nothing is installed system-wide.

## Engines

| Binary | Upstream | Role | Installed by |
|---|---|---|---|
| `audiocpp_cli` | [`0xShug0/audio.cpp`](https://github.com/0xShug0/audio.cpp) | Audio inference runtime | With the first model download, **Install runtime** on the Models page, or `soundbox model install audiocpp` |
| `llama-server` | [`ggml-org/llama.cpp`](https://github.com/ggml-org/llama.cpp) | Optional prompt assistant | `soundbox model install llm`, or the app when the prompt assistant is set to managed |
| `sd-server` | [`leejet/stable-diffusion.cpp`](https://github.com/leejet/stable-diffusion.cpp) | Optional artwork generator | The app, when artwork is turned on in the setup wizard or in **Settings > Prompt assistant & artwork** (`POST /api/image/engine/install`) |

The install and status commands and their flags are in the
[command-line reference](https://mirli.app/docs/install-cli/index.md#soundbox-model).

## Install location

Each engine version gets its own folder:

```text
<DATA_DIR>/bin/audiocpp/<VERSION>/    audiocpp_cli and its runtime libraries
<DATA_DIR>/bin/llama/<VERSION>/       llama-server, same layout
<DATA_DIR>/bin/sd/<VERSION>/          sd-server, same layout
```

`<DATA_DIR>` is the data folder and `<VERSION>` the release tag.

- The engines live beside `models/`, not inside it. Deleting models keeps the
  engines, and reinstalling an engine keeps the weights.
- The most recently installed version is used. An upgrade never overwrites
  the copy that is running.
- Uninstalling an engine means deleting its folder.

## Checksums

Every download is checked before anything is unpacked:

- against GitHub's SHA-256 digest for the release asset, and
- against the release's checksum manifest, when the release publishes one.

An asset covered by neither is refused unless
`MIRLI_ALLOW_UNVERIFIED_BINARIES=1` is set for that run. A checksum mismatch
is always refused.

## Resolution order

When Mirli needs an engine, it uses the first of these that exists:

1. The environment override: an absolute path in `MIRLI_AUDIOCPP_BIN`,
   `MIRLI_LLAMA_SERVER_BIN` or `MIRLI_SD_SERVER_BIN`.
2. The managed install under `<DATA_DIR>/bin/`.
3. `PATH`.
4. On macOS, `/opt/homebrew/bin` and `/usr/local/bin`. A server started from a
   desktop launcher often inherits a `PATH` without Homebrew.

The managed install comes before `PATH`, so a binary installed through Mirli
wins over a system-wide copy. `soundbox model status` reports which one was
used: a managed install shows its version, an override shows
`external (env)`, and a binary found on `PATH` shows `external (PATH)`.

## Backend detection

The backend is detected once per machine and decides which release asset is
downloaded:

| Machine | audio.cpp | `llama-server`, `sd-server` |
|---|---|---|
| macOS | Metal | Metal |
| `nvidia-smi` answers | CUDA | CUDA |
| Anything else | CPU | Vulkan |

`--backend` on `install` downloads another build. Separately, these variables
change what is reported or requested at run time without changing the
download:

| Variable | Effect |
|---|---|
| `MIRLI_AUDIOCPP_BACKEND` | The backend audio.cpp is asked to run with. `GET /api/health` reports it as `device`. |
| `MIRLI_LLAMA_SERVER_BACKEND` | The backend reported for `llama-server`. |
| `MIRLI_SD_SERVER_BACKEND` | The backend reported for `sd-server`. |

For audio.cpp's CUDA builds and ROCm, see [About audio.cpp](https://mirli.app/docs/audiocpp/index.md).
To use a binary of your own, see
[Use your own audio.cpp build](https://mirli.app/docs/audiocpp-binary/index.md).
