2026-06-05 15:00:35 -07:00
|
|
|
// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
|
|
|
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
|
|
|
|
|
|
//go:build cgo
|
|
|
|
|
|
2026-07-03 01:23:03 -07:00
|
|
|
// Package mpcvm re-exports the GPU bridge from
|
|
|
|
|
// github.com/luxfi/chains/mpcvm so callers that import the legacy
|
2026-06-05 15:00:35 -07:00
|
|
|
// node path keep working without source changes.
|
|
|
|
|
//
|
|
|
|
|
// One and only one way to dlopen: the canonical bridge lives in
|
2026-07-03 01:23:03 -07:00
|
|
|
// chains/mpcvm. This package is a typed alias layer — both the
|
2026-06-05 15:00:35 -07:00
|
|
|
// types and the GPUBackend singleton come straight from the upstream.
|
|
|
|
|
// There is exactly one dlopen handle, one symbol table, one init()
|
|
|
|
|
// probe across the entire luxd process. Consumers of either import path
|
|
|
|
|
// share the same plugin instance.
|
|
|
|
|
|
2026-07-03 01:23:03 -07:00
|
|
|
package mpcvm
|
2026-06-05 15:00:35 -07:00
|
|
|
|
2026-07-03 01:23:03 -07:00
|
|
|
import "github.com/luxfi/chains/mpcvm"
|
2026-06-05 15:00:35 -07:00
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
// Type re-exports — Go aliases preserve the public API so external callers
|
|
|
|
|
// (e.g. node/chains, node/main) can drop the import path without source
|
|
|
|
|
// changes. The GPU- prefix avoids collisions with the domain types
|
|
|
|
|
// already aliased above (Block, Client, Operation).
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
|
|
type (
|
2026-07-03 01:23:03 -07:00
|
|
|
GPUBackend = mpcvm.GPUBackend
|
|
|
|
|
GPUBackendKind = mpcvm.GPUBackendKind
|
2026-06-05 15:00:35 -07:00
|
|
|
|
2026-07-03 01:23:03 -07:00
|
|
|
GPUCeremony = mpcvm.GPUCeremony
|
|
|
|
|
GPUKeyShare = mpcvm.GPUKeyShare
|
|
|
|
|
GPUContribution = mpcvm.GPUContribution
|
|
|
|
|
GPUMPCVMState = mpcvm.GPUMPCVMState
|
|
|
|
|
GPUMPCVMRoundDescriptor = mpcvm.GPUMPCVMRoundDescriptor
|
|
|
|
|
GPUCeremonyOp = mpcvm.GPUCeremonyOp
|
|
|
|
|
GPUContributionOp = mpcvm.GPUContributionOp
|
|
|
|
|
GPUMPCVMTransitionResult = mpcvm.GPUMPCVMTransitionResult
|
2026-06-05 15:00:35 -07:00
|
|
|
)
|
|
|
|
|
|
2026-07-03 01:23:03 -07:00
|
|
|
// Backend constants re-exported. Matches the chains/mpcvm dlopen
|
2026-06-05 15:00:35 -07:00
|
|
|
// probe order: cuda → hip → metal → vulkan → webgpu.
|
|
|
|
|
const (
|
2026-07-03 01:23:03 -07:00
|
|
|
GPUBackendNone = mpcvm.GPUBackendNone
|
|
|
|
|
GPUBackendCUDA = mpcvm.GPUBackendCUDA
|
|
|
|
|
GPUBackendHIP = mpcvm.GPUBackendHIP
|
|
|
|
|
GPUBackendMetal = mpcvm.GPUBackendMetal
|
|
|
|
|
GPUBackendVulkan = mpcvm.GPUBackendVulkan
|
|
|
|
|
GPUBackendWebGPU = mpcvm.GPUBackendWebGPU
|
2026-06-05 15:00:35 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ErrGPUNotAvailable is the canonical "no plugin loaded" error. Callers
|
2026-07-03 01:23:03 -07:00
|
|
|
// `errors.Is(err, mpcvm.ErrGPUNotAvailable)` to distinguish a
|
2026-06-05 15:00:35 -07:00
|
|
|
// fallback-to-CPU condition from a hard launcher failure.
|
2026-07-03 01:23:03 -07:00
|
|
|
var ErrGPUNotAvailable = mpcvm.ErrGPUNotAvailable
|
2026-06-05 15:00:35 -07:00
|
|
|
|
|
|
|
|
// GPUBackendInstance returns the dlopen'd GPU plugin handle resolved at
|
2026-07-03 01:23:03 -07:00
|
|
|
// chains/mpcvm package init. nil means no plugin was loaded
|
2026-06-05 15:00:35 -07:00
|
|
|
// (CPU-only mode). The handle is shared across the whole process — both
|
|
|
|
|
// the node and chains paths see the same instance.
|
|
|
|
|
//
|
|
|
|
|
// The name is GPUBackendInstance (not GPUBackend / Backend) because Go
|
|
|
|
|
// disallows a function named the same as a type alias in the same
|
|
|
|
|
// package, and `Backend` is already a domain term in the threshold
|
|
|
|
|
// state machine. Callers write:
|
|
|
|
|
//
|
2026-07-03 01:23:03 -07:00
|
|
|
// if g := mpcvm.GPUBackendInstance(); g != nil && g.IsAvailable() {
|
2026-06-05 15:00:35 -07:00
|
|
|
// _, err := g.CeremonyApply(desc, ops, ceremonies)
|
|
|
|
|
// ...
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// This mirrors the cevm pattern `cevm.AvailableBackends()` /
|
|
|
|
|
// `cevm.LibraryABIVersion()` — discovery via package-scope function,
|
|
|
|
|
// not via a global variable.
|
|
|
|
|
func GPUBackendInstance() *GPUBackend {
|
2026-07-03 01:23:03 -07:00
|
|
|
return mpcvm.Backend()
|
2026-06-05 15:00:35 -07:00
|
|
|
}
|