Files
Hanzo AI ddff44bbee backend: add GPU substrate selector with fallback policy + ABI guards
Adds the canonical runtime substrate selector for luxfi/crypto and decomplects
all per-algorithm GPU dispatchers behind it.

New `backend` API:
- Default()/SetDefault/Resolved()/IsGPU/IsCGo/IsVanilla — runtime selection
- CGoAvailable()/GPUAvailable() — real probes (was stubbed)
- Probe() returning Snapshot{Default, Resolved, CGo, GPU, Disabled,
  GPUBackend, GPUDeviceCount, AccelVersion, Fallbacks}
- GPUDisabled() reads LUX_GPU_DISABLE operator kill switch
- RecordFallback(reason, where) atomic counter + one-shot log per reason,
  low-cardinality FallbackReason enum (disabled / unsupported / probe_failed
  / backend_unavailable / abi_mismatch)

Dispatcher cleanup (one-and-one-way):
- All Resolve(gpuhost.Available(), false) call sites replaced with IsGPU()
- hqc switched to IsVanilla() (its accel batch wins for any non-vanilla pick)
- gpu/gpu.go now delegates entirely to backend (no separate session)
- internal/gpuhost dropped Snapshot()/Provenance — backend.Probe() canonical

Build tag policy: CGo is the only gate. There is no `gpu` build tag.
LLM.md documents the canonical surface.
2026-05-24 14:16:55 -07:00

38 lines
1.3 KiB
Go

// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Package gpu is the public probe surface for the GPU acceleration layer
// used by luxfi/crypto.
//
// It delegates every call to github.com/luxfi/crypto/backend — the canonical
// runtime substrate selector. Callers writing new code should prefer
// backend.Probe() / backend.GPUAvailable(); this package stays for back-compat
// with consumers that already import "github.com/luxfi/crypto/gpu".
package gpu
import (
"github.com/luxfi/accel"
"github.com/luxfi/crypto/backend"
)
// Available reports whether the GPU substrate is reachable. Equivalent to
// backend.GPUAvailable().
func Available() bool { return backend.GPUAvailable() }
// Backend names the active accel backend ("metal" | "cuda" | "webgpu") or
// "" when no GPU is available. Equivalent to backend.Probe().GPUBackend.
func Backend() string { return backend.Probe().GPUBackend }
// Devices returns the list of devices visible to the accel layer, or nil
// when no GPU is available.
func Devices() []accel.DeviceInfo {
if !Available() {
return nil
}
return accel.Devices()
}
// Version returns the underlying accel library version string. Equivalent
// to backend.Probe().AccelVersion.
func Version() string { return accel.GetVersion() }