Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/bee/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const (
optionAutoTLSDomain = "autotls-domain"
optionAutoTLSRegistrationEndpoint = "autotls-registration-endpoint"
optionAutoTLSCAEndpoint = "autotls-ca-endpoint"
optionUseSIMD = "use-simd-hashing"

// blockchain-rpc
optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint"
Expand Down Expand Up @@ -337,6 +338,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().String(optionAutoTLSDomain, p2pforge.DefaultForgeDomain, "autotls domain")
cmd.Flags().String(optionAutoTLSRegistrationEndpoint, p2pforge.DefaultForgeEndpoint, "autotls registration endpoint")
cmd.Flags().String(optionAutoTLSCAEndpoint, p2pforge.DefaultCAEndpoint, "autotls certificate authority endpoint")
cmd.Flags().Bool(optionUseSIMD, false, "use SIMD BMT hasher (available only on linux amd64 platforms)")
}

// preRun must be called from every command's PreRunE, after which c.logger is
Expand Down
19 changes: 19 additions & 0 deletions cmd/bee/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime"
"strings"
"sync/atomic"
"syscall"
"time"

"github.com/ethersphere/bee/v2"
"github.com/ethersphere/bee/v2/pkg/accesscontrol"
"github.com/ethersphere/bee/v2/pkg/bmt"
"github.com/ethersphere/bee/v2/pkg/bmtpool"
chaincfg "github.com/ethersphere/bee/v2/pkg/config"
"github.com/ethersphere/bee/v2/pkg/crypto"
"github.com/ethersphere/bee/v2/pkg/keccak"
"github.com/ethersphere/bee/v2/pkg/keystore"
filekeystore "github.com/ethersphere/bee/v2/pkg/keystore/file"
memkeystore "github.com/ethersphere/bee/v2/pkg/keystore/mem"
Expand Down Expand Up @@ -266,6 +270,21 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo
neighborhoodSuggester = c.config.GetString(optionNameNeighborhoodSuggester)
}

useSIMD := c.config.GetBool(optionUseSIMD)
if useSIMD {
if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
return nil, fmt.Errorf("SIMD hashing requires linux/amd64 (this build is %s/%s)", runtime.GOOS, runtime.GOARCH)
}
if !keccak.HasSIMD() {
return nil, errors.New("SIMD hashing requires a CPU with AVX2 or AVX-512; this CPU has neither")
}
bmt.SetSIMDOptIn(true)
// Rebuild the global bmtpool instance so the new SIMDOptIn value
// is reflected in the pool created for hot-path BMT hashing.
bmtpool.Rebuild()
logger.Info("SIMD hashing enabled", "batch_width", keccak.BatchWidth(), "avx512", keccak.HasAVX512())
}

b, err := node.NewBee(ctx, c.config.GetString(optionNameP2PAddr), signerConfig.publicKey, signerConfig.signer, networkID, logger, signerConfig.libp2pPrivateKey, signerConfig.pssPrivateKey, signerConfig.session, &node.Options{
Addr: c.config.GetString(optionNameP2PAddr),
AllowPrivateCIDRs: c.config.GetBool(optionNameAllowPrivateCIDRs),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ require (
github.com/ipfs/go-log/v2 v2.6.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/klauspost/cpuid/v2 v2.3.0
github.com/koron/go-ssdp v0.0.6 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/libdns/libdns v0.2.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYW
github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.6/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg=
github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/klauspost/reedsolomon v1.11.8 h1:s8RpUW5TK4hjr+djiOpbZJB4ksx+TdYbRH7vHQpwPOY=
Expand Down
19 changes: 15 additions & 4 deletions pkg/bmt/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ func BenchmarkBMT(b *testing.B) {
b.Run(fmt.Sprintf("%v_size_%v", "REF", size), func(b *testing.B) {
benchmarkRefHasher(b, size)
})
b.Run(fmt.Sprintf("%v_size_%v", "BMT", size), func(b *testing.B) {
b.Run(fmt.Sprintf("%v_size_%v", "BMT_Goroutine", size), func(b *testing.B) {
prev := bmt.SIMDOptIn()
bmt.SetSIMDOptIn(false)
defer bmt.SetSIMDOptIn(prev)
benchmarkBMT(b, size)
})
b.Run(fmt.Sprintf("%v_size_%v", "BMT_SIMD", size), func(b *testing.B) {
prev := bmt.SIMDOptIn()
bmt.SetSIMDOptIn(true)
defer bmt.SetSIMDOptIn(prev)
benchmarkBMT(b, size)
})
}
Expand Down Expand Up @@ -81,13 +90,15 @@ func benchmarkBMTBaseline(b *testing.B, _ int) {
}
}

// benchmarks BMT Hasher
// benchmarks BMT Hasher with whichever pool the current SIMDOptIn selects.
// Tree is constructed inside the benchmark so the SIMDOptIn value at call time
// determines which implementation gets exercised.
func benchmarkBMT(b *testing.B, n int) {
b.Helper()

testData := testutil.RandBytesWithSeed(b, 4096, seed)

pool := bmt.NewPool(bmt.NewConf(swarm.NewHasher, testSegmentCount, testPoolSize))
pool := bmt.NewPool(bmt.NewConf(testSegmentCount, testPoolSize))
h := pool.Get()
defer pool.Put(h)

Expand All @@ -106,7 +117,7 @@ func benchmarkPool(b *testing.B, poolsize int) {

testData := testutil.RandBytesWithSeed(b, 4096, seed)

pool := bmt.NewPool(bmt.NewConf(swarm.NewHasher, testSegmentCount, poolsize))
pool := bmt.NewPool(bmt.NewConf(testSegmentCount, poolsize))
cycles := 100

b.ReportAllocs()
Expand Down
Loading
Loading