Description
Apologies if this is the wrong forum for a newbie question. My problem is more about how to use go assembler than python. I have gotten stuck trying to compile and run the output of PeachPy in the go-generate example:
jon@brainsIntel:~/Documents/PeachPy/examples/go-generate$ go generate dot_product.go
jon@brainsIntel:~/Documents/PeachPy/examples/go-generate$ ls
dot_product_amd64.s dot_product.go dot_product.py dot_product_test.go main.go
I tried many different go build and go run commands with no success yet. To get the main.go to run I had to change "package blas" to "package main" in all files and rename the folder from "go-generate" to "main". Finally I could run the main function with "go build -x .". Sadly the results seem to be incorrect, so I guess I am doing something wrong still:
jon@brainsIntel:~/Documents/PeachPy/examples/main$ git diff main.go
diff --git a/examples/main/main.go b/examples/main/main.go
index 18f6e32..80af7e1 100644
--- a/examples/main/main.go
+++ b/examples/main/main.go
@@ -1,17 +1,21 @@
-package blas
+package main
+
import "fmt"
func main() {
+
+ var d float32
x := make([]float32, 2048)
y := make([]float32, len(x))
+ d = 0
for i := 0; i < len(x); i++ {
x[i] = 2.0
y[i] = 3.0
+ d += x[i] * y[i]
}
z := DotProduct(&x[0], &y[0], uint(len(x)))
fmt.Println("hello world")
- fmt.Println("z =", z)
+ fmt.Println("z =", z, "d =", d)
}
jon@brainsIntel:~/Documents/PeachPy/examples/main$ go build -x .
WORK=/tmp/go-build474848716
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg.link << 'EOF' # internal
packagefile _/home/jon/Documents/PeachPy/examples/main=/home/jon/.cache/go-build/ff/ff2e6ec9f76a30991be7715da37e3f2bb5e4bada2dfb76a5c6f6c282c58359c5-d
packagefile fmt=/usr/lib/go-1.10/pkg/linux_amd64/fmt.a
packagefile runtime=/usr/lib/go-1.10/pkg/linux_amd64/runtime.a
packagefile errors=/usr/lib/go-1.10/pkg/linux_amd64/errors.a
packagefile io=/usr/lib/go-1.10/pkg/linux_amd64/io.a
packagefile math=/usr/lib/go-1.10/pkg/linux_amd64/math.a
packagefile os=/usr/lib/go-1.10/pkg/linux_amd64/os.a
packagefile reflect=/usr/lib/go-1.10/pkg/linux_amd64/reflect.a
packagefile strconv=/usr/lib/go-1.10/pkg/linux_amd64/strconv.a
packagefile sync=/usr/lib/go-1.10/pkg/linux_amd64/sync.a
packagefile unicode/utf8=/usr/lib/go-1.10/pkg/linux_amd64/unicode/utf8.a
packagefile runtime/internal/atomic=/usr/lib/go-1.10/pkg/linux_amd64/runtime/internal/atomic.a
packagefile runtime/internal/sys=/usr/lib/go-1.10/pkg/linux_amd64/runtime/internal/sys.a
packagefile sync/atomic=/usr/lib/go-1.10/pkg/linux_amd64/sync/atomic.a
packagefile internal/cpu=/usr/lib/go-1.10/pkg/linux_amd64/internal/cpu.a
packagefile internal/poll=/usr/lib/go-1.10/pkg/linux_amd64/internal/poll.a
packagefile internal/testlog=/usr/lib/go-1.10/pkg/linux_amd64/internal/testlog.a
packagefile syscall=/usr/lib/go-1.10/pkg/linux_amd64/syscall.a
packagefile time=/usr/lib/go-1.10/pkg/linux_amd64/time.a
packagefile unicode=/usr/lib/go-1.10/pkg/linux_amd64/unicode.a
packagefile internal/race=/usr/lib/go-1.10/pkg/linux_amd64/internal/race.a
EOF
mkdir -p $WORK/b001/exe/
cd .
BUILD_PATH_PREFIX_MAP='/tmp/go-build=$WORK:' /usr/lib/go-1.10/pkg/tool/linux_amd64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -buildmode=exe -buildid=QZKile1wdIBBkCwbsWwa/66eWng91NslShieKxUh9/4qjNxkXklLxRsN2b-BAg/QZKile1wdIBBkCwbsWwa -extld=gcc /home/jon/.cache/go-build/ff/ff2e6ec9f76a30991be7715da37e3f2bb5e4bada2dfb76a5c6f6c282c58359c5-d
/usr/lib/go-1.10/pkg/tool/linux_amd64/buildid -w $WORK/b001/exe/a.out # internal
mv $WORK/b001/exe/a.out main
rm -r $WORK/b001/
jon@brainsIntel:~/Documents/PeachPy/examples/main$ ./main
hello world
z = 5.252114e+21 d = 12288
jon@brainsIntel:~/Documents/PeachPy/examples/main$ go test -bench .
goos: linux
goarch: amd64
BenchmarkDotProduct_L1_PeachPy-4 10000000 170 ns/op
BenchmarkDotProduct_L2_PeachPy-4 500000 3043 ns/op
BenchmarkDotProduct_L3_PeachPy-4 50000 35891 ns/op
BenchmarkDotProduct_L1_Go-4 1000000 1647 ns/op
BenchmarkDotProduct_L2_Go-4 100000 13089 ns/op
BenchmarkDotProduct_L3_Go-4 10000 104663 ns/op
Could you help me? I am missing the exact series of "go" commands (or other) that need to be used in a shell order to run the code, run the tests and verify the output is correct.
Adding the main function code into the test code and running "go test" lets me use the original folder, but the answer is still incorrect ?
jon@brainsIntel:~/Documents/PeachPy/examples/go-generate$ go test .
--- FAIL: TestDotProduct (0.00s)
dot_product_test.go:20: Dot incorrect, got: 5252114210988121653248.000000 want: 12288.000000
FAIL
FAIL _/home/jon/Documents/PeachPy/examples/go-generate 0.001s
jon@brainsIntel:~/Documents/PeachPy/examples/go-generate$ git diff dot_product_test.go
diff --git a/examples/go-generate/dot_product_test.go b/examples/go-generate/dot_product_test.go
index d7f24b4..e86a9e2 100644
--- a/examples/go-generate/dot_product_test.go
+++ b/examples/go-generate/dot_product_test.go
@@ -4,6 +4,22 @@ import (
"testing"
"math/rand"
)
+
+func TestDotProduct(t *testing.T ){
+ var N int
+ N = 2048
+ x := make([]float32, N)
+ y := make([]float32, N)
+ for i:=0 ; i < N; i++ {
+ x[i] = 2.
+ y[i] = 3.
+ }
+ dasm := DotProduct( &x[0], &y[0], uint(N) )
+ dtrue := float32( N ) * 6
+ if dasm != dtrue {
+ t.Errorf("Dot incorrect, got: %f want: %f",dasm,dtrue)
+ }
+}
It could also be an error in the generated asm code perhaps, but I was sort of assuming this should be OK...
Many thanks in advance for your help!