OSDN Git Service

Add simd tag (#1160)
authorHAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Mon, 23 Jul 2018 06:30:54 +0000 (14:30 +0800)
committerPaladz <yzhu101@uottawa.ca>
Mon, 23 Jul 2018 06:30:54 +0000 (14:30 +0800)
* Add simd tag

* Clean up Makefile

* Request CI again

Makefile
mining/tensority/Makefile [deleted file]
mining/tensority/cgo_algorithm/algorithm_simd.go
mining/tensority/cgo_algorithm/algorithm_unsupported.go
mining/tensority/go_algorithm/algorithm_test.go [moved from mining/tensority/algorithm_test.go with 96% similarity]

index 23a8b32..b122354 100644 (file)
--- 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 (file)
index d68875c..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-test:
-       cd cgo_algorithm/lib/ && make
-       go test -v && go test -bench=.
similarity index 96%
rename from mining/tensority/algorithm_test.go
rename to mining/tensority/go_algorithm/algorithm_test.go
index 797e8bb..c1213d4 100644 (file)
@@ -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
-}