mirror of
https://github.com/luxfi/crypto.git
synced 2026-07-27 01:54:50 +00:00
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.
17 lines
675 B
Go
17 lines
675 B
Go
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package backend
|
|
|
|
import "github.com/luxfi/crypto/internal/gpuhost"
|
|
|
|
// gpuLinked reports whether the GPU substrate is reachable right now.
|
|
// The first call triggers a one-time accel.Init() inside gpuhost; the
|
|
// answer is then cached for the lifetime of the process.
|
|
//
|
|
// Returns false when:
|
|
// - the binary was built without cgo (accel.Init returns ErrNoBackends)
|
|
// - accel initialised but found no Metal / CUDA / WebGPU device
|
|
// - the accel.Session allocation failed (driver / permission / OOM)
|
|
func gpuLinked() bool { return gpuhost.Available() }
|