Skip to content

Feature: automatic GPU variant selection (CUDA + Vulkan) in loadBinary #33

Description

@lloyal-research

Summary

loadBinary() selects a GPU variant only from LLOYAL_GPU / the gpuVariant arg; no consumer (reasoning.run, rig) sets it, so an installed GPU silently runs on the CPU prebuilt. We want loadBinary() to auto-select the best available prebuilt when the caller hasn't asked for one.

A CUDA-only first cut was prototyped in PR #32 and pulled out (it was incomplete and out of scope for the #20 crash fix). This issue tracks doing it properly. (Note: once the #20 AVX-512 fix lands, LLOYAL_GPU=cuda already works again — auto-detect is a convenience feature, not part of the regression fix.)

Scope — all supported variants

From the release matrix:

  • Metalno work needed: there is no -metal package; darwin-arm64 IS the Metal build (llama.cpp auto-enables it). The base package already accelerates.
  • CUDA — NVIDIA. Detect the driver: libcuda.so.1 (Linux, incl. WSL2 /usr/lib/wsl/lib/), nvcuda.dll (Windows), with an absolute-path nvidia-smi fallback. No PATH lookup (hijack-safe).
  • Vulkan — AMD/Intel/Qualcomm (and NVIDIA). Detecting the loader (libvulkan.so.1 / vulkan-1.dll) is not enough — a software/llvmpipe device would false-positive. Must enumerate a real hardware physical device (e.g. a tiny probe or parsing vulkaninfo).
  • CPU — fallback.

Design requirements

  1. Preference order: a box can have both CUDA and Vulkan. Prefer CUDA on NVIDIA; else Vulkan if a hardware device exists; else CPU. Document and make overridable.
  2. LLOYAL_NO_FALLBACK contract (important): it must apply only to an explicitly requested variant (LLOYAL_GPU / gpuVariant). An auto-detected variant must always fall back to CPU if its package fails — otherwise auto-detect turns a working CPU load into a throw for users who set NO_FALLBACK for unrelated reasons. (This was the high-severity bug in the PR fix: pin AVX2 ISA floor for x64 prebuilts (hdk#20) #32 prototype.)
  3. stdout stays clean — diagnostics to stderr (console.warn), cached probe, never throws.
  4. CI invariant: every CI job that loads the binary sets LLOYAL_GPU (or LLOYAL_LOCAL), so auto-detect is end-user-only and never depends on CI-provisioned paths. Keep it that way; add a test asserting auto-detect is skipped when a variant is explicit.
  5. Reliability: containers, WSL2, no-GPU servers, non-FHS installs. Best-effort with the LLOYAL_GPU escape hatch — a miss must be non-fatal (CPU).

Reference

Prototype commits (reverted from PR #32): the CUDA driver/nvidia-smi probe and the loadBinary integration — reuse as a starting point for the CUDA half, then add Vulkan + preference + the NO_FALLBACK fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions