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.
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package backend
|
|
|
|
import "testing"
|
|
|
|
func TestParseTruthy(t *testing.T) {
|
|
cases := map[string]bool{
|
|
"": false,
|
|
"0": false,
|
|
"false": false,
|
|
"FALSE": false,
|
|
"no": false,
|
|
"NO": false,
|
|
"off": false,
|
|
" 0 ": false,
|
|
"1": true,
|
|
"true": true,
|
|
"yes": true,
|
|
"on": true,
|
|
"YES": true,
|
|
"foo": true, // any non-falsy spelling counts as truthy
|
|
}
|
|
for in, want := range cases {
|
|
if got := parseTruthy(in); got != want {
|
|
t.Errorf("parseTruthy(%q) = %v; want %v", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGPUDisabledStable(t *testing.T) {
|
|
// gpuDisabled is parsed once at init; repeated calls must agree.
|
|
v1 := GPUDisabled()
|
|
v2 := GPUDisabled()
|
|
if v1 != v2 {
|
|
t.Fatalf("GPUDisabled() not stable: %v then %v", v1, v2)
|
|
}
|
|
}
|
|
|
|
func TestGPUAvailableHonorsDisabled(t *testing.T) {
|
|
// When disabled, GPUAvailable must return false regardless of probe.
|
|
if GPUDisabled() && GPUAvailable() {
|
|
t.Fatal("GPUAvailable=true while GPUDisabled=true — kill switch ignored")
|
|
}
|
|
}
|