From 6c7bce36d536c5f7bbeda2b18b38a868893cef45 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Mon, 23 Jul 2018 14:30:54 +0800 Subject: [PATCH] Add simd tag (#1160) * Add simd tag * Clean up Makefile * Request CI again --- Makefile | 14 ++++++++------ mining/tensority/Makefile | 3 --- mining/tensority/cgo_algorithm/algorithm_simd.go | 2 +- .../tensority/cgo_algorithm/algorithm_unsupported.go | 2 +- mining/tensority/{ => go_algorithm}/algorithm_test.go | 18 +++++++----------- 5 files changed, 17 insertions(+), 22 deletions(-) delete mode 100644 mining/tensority/Makefile rename mining/tensority/{ => go_algorithm}/algorithm_test.go (96%) diff --git a/Makefile b/Makefile index 23a8b32c..b1223543 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ endif endif PACKAGES := $(shell go list ./... | grep -v '/vendor/' | grep -v '/crypto/ed25519/chainkd' | grep -v '/mining/tensority') +PACKAGES += 'github.com/bytom/mining/tensority/go_algorithm' + BUILD_FLAGS := -ldflags "-X github.com/bytom/version.GitCommit=`git rev-parse HEAD`" MINER_BINARY32 := miner-$(GOOS)_386 @@ -39,12 +41,12 @@ all: test target release-all bytomd: @echo "Building bytomd to cmd/bytomd/bytomd" - @CGO_ENABLED=0 go build $(BUILD_FLAGS) -o cmd/bytomd/bytomd cmd/bytomd/main.go + @go build $(BUILD_FLAGS) -o cmd/bytomd/bytomd cmd/bytomd/main.go bytomd-simd: @echo "Building SIMD version bytomd to cmd/bytomd/bytomd" @cd mining/tensority/cgo_algorithm/lib/ && make - @CGO_ENABLED=1 go build $(BUILD_FLAGS) -o cmd/bytomd/bytomd cmd/bytomd/main.go + @go build -tags="simd" $(BUILD_FLAGS) -o cmd/bytomd/bytomd cmd/bytomd/main.go bytomcli: @echo "Building bytomcli to cmd/bytomcli/bytomcli" @@ -111,14 +113,14 @@ target/$(MINER_BINARY64): test: @echo "====> Running go test" - @CGO_ENABLED=0 go test -tags "network" $(PACKAGES) + @go test -tags "network" $(PACKAGES) benchmark: - @CGO_ENABLED=0 go test -bench $(PACKAGES) + @go test -bench $(PACKAGES) functional-tests: - @CGO_ENABLED=0 go test -v -timeout=5m -tags=functional ./test + @go test -v -timeout=5m -tags="functional" ./test ci: test functional-tests -.PHONY: all target release-all clean test benchmark +.PHONY: all target release-all clean test benchmark \ No newline at end of file diff --git a/mining/tensority/Makefile b/mining/tensority/Makefile deleted file mode 100644 index d68875c0..00000000 --- a/mining/tensority/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -test: - cd cgo_algorithm/lib/ && make - go test -v && go test -bench=. diff --git a/mining/tensority/cgo_algorithm/algorithm_simd.go b/mining/tensority/cgo_algorithm/algorithm_simd.go index 469dfebd..2371f80f 100644 --- a/mining/tensority/cgo_algorithm/algorithm_simd.go +++ b/mining/tensority/cgo_algorithm/algorithm_simd.go @@ -1,4 +1,4 @@ -// +build cgo +// +build simd package cgo_algorithm diff --git a/mining/tensority/cgo_algorithm/algorithm_unsupported.go b/mining/tensority/cgo_algorithm/algorithm_unsupported.go index b1e8c99b..375ad6c4 100644 --- a/mining/tensority/cgo_algorithm/algorithm_unsupported.go +++ b/mining/tensority/cgo_algorithm/algorithm_unsupported.go @@ -1,4 +1,4 @@ -// +build !cgo +// +build !simd package cgo_algorithm diff --git a/mining/tensority/algorithm_test.go b/mining/tensority/go_algorithm/algorithm_test.go similarity index 96% rename from mining/tensority/algorithm_test.go rename to mining/tensority/go_algorithm/algorithm_test.go index 797e8bbe..c1213d41 100644 --- a/mining/tensority/algorithm_test.go +++ b/mining/tensority/go_algorithm/algorithm_test.go @@ -1,4 +1,4 @@ -package tensority +package go_algorithm import ( "reflect" @@ -237,13 +237,13 @@ var tests = []struct { } // Tests that tensority hash result is correct. -func TestAlgorithm(t *testing.T) { +func TestLegacyAlgorithm(t *testing.T) { startT := time.Now() for i, tt := range tests { sT := time.Now() bhhash := bc.NewHash(tt.blockHeader) sdhash := bc.NewHash(tt.seed) - result := algorithm(&bhhash, &sdhash).Bytes() + result := LegacyAlgorithm(&bhhash, &sdhash).Bytes() var resArr [32]byte copy(resArr[:], result) eT := time.Now() @@ -263,26 +263,22 @@ func TestAlgorithm(t *testing.T) { t.Log("Avg time:", time.Duration(int(endT.Sub(startT))/len(tests))) } -func BenchmarkAlgorithm(b *testing.B) { +func BenchmarkLegacyAlgorithm(b *testing.B) { bhhash := bc.NewHash(tests[0].blockHeader) sdhash := bc.NewHash(tests[0].seed) b.ResetTimer() for i := 0; i < b.N; i++ { - algorithm(&bhhash, &sdhash) + LegacyAlgorithm(&bhhash, &sdhash) } } -func BenchmarkAlgorithmParallel(b *testing.B) { +func BenchmarkLegacyAlgorithmParallel(b *testing.B) { bhhash := bc.NewHash(tests[0].blockHeader) sdhash := bc.NewHash(tests[0].seed) b.SetParallelism(runtime.NumCPU()) b.RunParallel(func(pb *testing.PB) { for pb.Next() { - algorithm(&bhhash, &sdhash) + LegacyAlgorithm(&bhhash, &sdhash) } }) } - -func init() { - UseSIMD = true -} -- 2.11.0