build: require 'gpu' build tag for CGO GPU code

Changes:
- gpu_cgo.go: //go:build cgo -> //go:build cgo && gpu
- gpu.go: //go:build \!cgo -> //go:build \!cgo || \!gpu

This allows CGO_ENABLED=1 builds to work without requiring liblattice
to be installed. To enable GPU acceleration, build with -tags gpu.

Fixes CI builds that failed with linker errors:
- cannot find -lstdc++
- cannot find -llattice
- cannot find -lcudart
This commit is contained in:
2026-01-03 09:32:31 -08:00
parent 7ed03318b4
commit 5e0604b8f3
2 changed files with 6 additions and 9 deletions
+5 -8
View File
@@ -1,6 +1,6 @@
//go:build !cgo
//go:build !cgo || !gpu
// Package gpu provides pure Go implementations when CGO is disabled.
// Package gpu provides pure Go implementations when CGO is disabled or the gpu build tag is not set.
// These implementations use the lattice/ring package for NTT and polynomial operations.
package gpu
@@ -52,10 +52,7 @@ func NewNTTContext(N uint32, Q uint64) (*NTTContext, error) {
return nil, fmt.Errorf("failed to create SubRing: %w", err)
}
// Generate NTT constants
if err := subRing.GenNTTConstants(); err != nil {
return nil, fmt.Errorf("failed to generate NTT constants: %w", err)
}
// NTT constants are generated internally by NewSubRing via NewSubRingWithCustomNTT
return &NTTContext{
subRing: subRing,
@@ -260,7 +257,7 @@ func SampleGaussian(N uint32, Q uint64, sigma float64, seed []byte) ([]uint64, e
if len(seed) >= 32 {
prng, _ = sampling.NewKeyedPRNG(seed[:32])
} else {
prng = sampling.NewPRNG()
prng, _ = sampling.NewPRNG()
}
// Use Box-Muller transform for Gaussian sampling
@@ -308,7 +305,7 @@ func SampleUniform(N uint32, Q uint64, seed []byte) ([]uint64, error) {
if len(seed) >= 32 {
prng, _ = sampling.NewKeyedPRNG(seed[:32])
} else {
prng = sampling.NewPRNG()
prng, _ = sampling.NewPRNG()
}
qBig := new(big.Int).SetUint64(Q)
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build cgo
//go:build cgo && gpu
// Package gpu provides GPU-accelerated lattice operations via libLattice.
//