Files
evm/core/parallel/backend_auto.go
zeekay 1775ee8ff1 LP-108 Phase 4: stop pretending parallel/auto-select is GPU-accelerated
backend_auto.go used to auto-select CppEVM when a GPU was detected
("parallel backend: GPU detected, backend=cevm, gpu=Metal"). But
cevmExecutor.ExecuteTransaction returned (nil, nil) — every tx fell
through to Go EVM regardless. The "GPU acceleration" log line was
misleading; the real path was always Go EVM.

Per LP-108 "one and one only": collapsed auto-select to GoEVM. The
GPU presence is still detected and logged honestly:

  parallel backend: Go EVM (Block-STM across all cores)
  cores=10  gpu_status="Metal (detected; cevm dispatch wiring
  pending — runs Go EVM)"

To re-enable CppEVM auto-selection, the per-tx → batched-block
adapter in backend_cevm.go::ExecuteTransaction must be completed
AND a parity test against Go EVM Block-STM must pass.

Documented the gap in backend_cevm.go and backend_revm.go executor
comments. The (nil, nil) return is the documented "this backend
declines; use Go EVM" contract that the parallel framework's
DefaultTransactionExecutor expects (parallel.go:107).

Build verified: CGO_ENABLED=0 go build ./core/parallel/... clean.

Reference cevm bridge that needs wiring:
  github.com/luxfi/chains/evm/cevm/cevm_cgo.go::ExecuteBlock
  takes []Transaction (block-batch), TransactionExecutor is per-tx;
  adapter must accumulate per-tx work and submit at block close.

This is the production-wiring counterpart to LP-108 Phase 4 vapor
deletion. The "GPU EVM is plumbed" claim is now contingent on the
adapter, not on ambient registration.
2026-05-04 17:01:33 -07:00

77 lines
2.3 KiB
Go

// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package parallel
import (
"runtime"
"sync"
log "github.com/luxfi/log"
)
// selectedBackend records the auto-detected backend at startup.
// Set once during init and never modified.
var (
selectedOnce sync.Once
selectedResult EVMBackend
selectedGPUName string
)
func init() {
selectedOnce.Do(detectBackend)
}
// detectBackend selects the parallel-EVM backend.
//
// LP-108 (2026-05-04): collapsed to GoEVM only. The previous code
// auto-selected CppEVM when a GPU was detected, but the
// cevmExecutor.ExecuteTransaction body returned `nil, nil` (always
// fell through to Go EVM regardless of selection). That was a
// pretense, not an acceleration path.
//
// CppEVM and RustEVM are kept behind their respective build tags
// (`//go:build cevm` / `//go:build revm`) so the registrations are
// only present when those backends are wired through the cgo
// bridge and the parity gate against Go EVM is met. Until then,
// auto-detect returns Go EVM honestly.
//
// To re-enable CppEVM auto-selection: complete the cevm bridge in
// backend_cevm.go::ExecuteTransaction and add a parity test against
// the Go EVM Block-STM path.
func detectBackend() {
selectedResult = GoEVM
if gpu := DefaultGPU(); gpu.Available() {
switch runtime.GOOS {
case "darwin":
selectedGPUName = "Metal (detected; cevm dispatch wiring pending — runs Go EVM)"
case "linux":
selectedGPUName = "CUDA (detected; cevm dispatch wiring pending — runs Go EVM)"
default:
selectedGPUName = "GPU (detected; cevm dispatch wiring pending — runs Go EVM)"
}
} else {
selectedGPUName = "none"
}
log.Info("parallel backend: Go EVM (Block-STM across all cores)",
"backend", selectedResult,
"cores", runtime.NumCPU(),
"gpu_status", selectedGPUName,
)
}
// SelectedBackend returns the auto-detected backend for metrics/observability.
func SelectedBackend() EVMBackend {
return selectedResult
}
// SelectedGPU returns the detected GPU name ("Metal", "CUDA", "none").
func SelectedGPU() string {
return selectedGPUName
}
// IsGPUAvailable returns true if a GPU backend was detected at startup.
func IsGPUAvailable() bool {
return selectedGPUName != "none" && selectedGPUName != ""
}