-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTaskfile.yml
More file actions
296 lines (247 loc) · 7.55 KB
/
Copy pathTaskfile.yml
File metadata and controls
296 lines (247 loc) · 7.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# https://taskfile.dev
version: '3'
vars:
BENCH_TIME: 2s
BENCH_COUNT: 1
tasks:
default:
desc: Show available tasks
cmds:
- task --list
# Testing
test:
desc: Run all tests
cmds:
- go test -v ./...
test:short:
desc: Run tests without verbose output
cmds:
- go test ./...
test:f32:
desc: Run float32 tests
cmds:
- go test -v ./pkg/simd/f32/
test:f64:
desc: Run float64 tests
cmds:
- go test -v ./pkg/simd/f64/
test:race:
desc: Run tests with race detector
cmds:
- go test -race ./...
# Benchmarks
bench:
desc: Run all benchmarks
cmds:
- go test -bench=. -benchmem -benchtime={{.BENCH_TIME}} ./pkg/simd/f32/
- go test -bench=. -benchmem -benchtime={{.BENCH_TIME}} ./pkg/simd/f64/
bench:f32:
desc: Run float32 benchmarks
cmds:
- go test -bench=. -benchmem -benchtime={{.BENCH_TIME}} ./pkg/simd/f32/
bench:f64:
desc: Run float64 benchmarks
cmds:
- go test -bench=. -benchmem -benchtime={{.BENCH_TIME}} ./pkg/simd/f64/
bench:dot:
desc: Run DotProduct benchmarks only
cmds:
- go test -bench=BenchmarkDotProduct -benchmem -benchtime={{.BENCH_TIME}} ./pkg/simd/f32/
- go test -bench=BenchmarkDotProduct -benchmem -benchtime={{.BENCH_TIME}} ./pkg/simd/f64/
bench:compare:
desc: Run SIMD vs Pure Go comparison benchmark
cmds:
- |
cat > /tmp/bench_compare.go << 'EOF'
package main
import (
"fmt"
"math"
"runtime"
"time"
"github.com/tphakala/simd/cpu"
"github.com/tphakala/simd/f32"
"github.com/tphakala/simd/f64"
)
func main() {
fmt.Printf("Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf("CPU: %s\n", cpu.Info())
fmt.Println()
sizes := []int{100, 1000, 10000}
fmt.Println("=== Float32 DotProduct ===")
for _, n := range sizes {
a := make([]float32, n)
b := make([]float32, n)
for i := range a {
a[i] = float32(i+1)
b[i] = float32(i+1)
}
_ = f32.DotProduct(a, b)
iterations := 100000
if n >= 10000 { iterations = 10000 }
start := time.Now()
var goResult float32
for i := 0; i < iterations; i++ {
goResult = dotProductGo32(a, b)
}
goTime := time.Since(start)
start = time.Now()
var simdResult float32
for i := 0; i < iterations; i++ {
simdResult = f32.DotProduct(a, b)
}
simdTime := time.Since(start)
speedup := float64(goTime) / float64(simdTime)
fmt.Printf("n=%5d: Go=%7.2f ns, SIMD=%7.2f ns, Speedup=%.2fx (match: %v)\n",
n, float64(goTime.Nanoseconds())/float64(iterations),
float64(simdTime.Nanoseconds())/float64(iterations), speedup,
math.Abs(float64(goResult-simdResult)) < 1)
}
fmt.Println("\n=== Float64 DotProduct ===")
for _, n := range sizes {
a := make([]float64, n)
b := make([]float64, n)
for i := range a {
a[i] = float64(i+1)
b[i] = float64(i+1)
}
_ = f64.DotProduct(a, b)
iterations := 100000
if n >= 10000 { iterations = 10000 }
start := time.Now()
var goResult float64
for i := 0; i < iterations; i++ {
goResult = dotProductGo64(a, b)
}
goTime := time.Since(start)
start = time.Now()
var simdResult float64
for i := 0; i < iterations; i++ {
simdResult = f64.DotProduct(a, b)
}
simdTime := time.Since(start)
speedup := float64(goTime) / float64(simdTime)
fmt.Printf("n=%5d: Go=%7.2f ns, SIMD=%7.2f ns, Speedup=%.2fx (match: %v)\n",
n, float64(goTime.Nanoseconds())/float64(iterations),
float64(simdTime.Nanoseconds())/float64(iterations), speedup,
math.Abs(goResult-simdResult) < 0.001)
}
fmt.Println("\n=== Float32 Add ===")
for _, n := range sizes {
a := make([]float32, n)
b := make([]float32, n)
dst := make([]float32, n)
for i := range a {
a[i] = float32(i+1)
b[i] = float32(i+1)
}
iterations := 100000
if n >= 10000 { iterations = 10000 }
start := time.Now()
for i := 0; i < iterations; i++ {
for j := range dst { dst[j] = a[j] + b[j] }
}
goTime := time.Since(start)
start = time.Now()
for i := 0; i < iterations; i++ {
f32.Add(dst, a, b)
}
simdTime := time.Since(start)
speedup := float64(goTime) / float64(simdTime)
fmt.Printf("n=%5d: Go=%7.2f ns, SIMD=%7.2f ns, Speedup=%.2fx\n",
n, float64(goTime.Nanoseconds())/float64(iterations),
float64(simdTime.Nanoseconds())/float64(iterations), speedup)
}
}
func dotProductGo32(a, b []float32) float32 {
var sum float32
for i := range a { sum += a[i] * b[i] }
return sum
}
func dotProductGo64(a, b []float64) float64 {
var sum float64
for i := range a { sum += a[i] * b[i] }
return sum
}
EOF
go run /tmp/bench_compare.go
# Build & Lint
build:
desc: Build the project
cmds:
- go build ./...
lint:
desc: Run golangci-lint
cmds:
- golangci-lint run ./...
lint:fix:
desc: Run golangci-lint with auto-fix
cmds:
- golangci-lint run --fix ./...
vet:
desc: Run go vet
cmds:
- go vet ./...
fmt:
desc: Format code
cmds:
- go fmt ./...
# Development
cpu:
desc: Show CPU SIMD capabilities
cmds:
- |
cat > /tmp/cpu_info.go << 'EOF'
package main
import (
"fmt"
"runtime"
"github.com/tphakala/simd/cpu"
)
func main() {
fmt.Printf("Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf("SIMD: %s\n", cpu.Info())
fmt.Printf("\nx86/AMD64 Features:\n")
fmt.Printf(" AVX-512F: %v\n", cpu.X86.AVX512F)
fmt.Printf(" AVX-512VL: %v\n", cpu.X86.AVX512VL)
fmt.Printf(" AVX2: %v\n", cpu.X86.AVX2)
fmt.Printf(" AVX: %v\n", cpu.X86.AVX)
fmt.Printf(" FMA: %v\n", cpu.X86.FMA)
fmt.Printf(" SSE2: %v\n", cpu.X86.SSE2)
fmt.Printf("\nARM64 Features:\n")
fmt.Printf(" NEON: %v\n", cpu.ARM64.NEON)
fmt.Printf(" SVE: %v\n", cpu.ARM64.SVE)
fmt.Printf(" SVE2: %v\n", cpu.ARM64.SVE2)
}
EOF
go run /tmp/cpu_info.go
# CI/CD
ci:
desc: Run CI checks (test, lint, vet)
cmds:
- task: fmt
- task: vet
- task: lint
- task: test:short
# Git Hooks
hooks:install:
desc: Install git pre-commit hook
cmds:
- git config core.hooksPath .githooks
- echo "Pre-commit hook installed (using .githooks directory)"
hooks:uninstall:
desc: Remove git pre-commit hook
cmds:
- git config --unset core.hooksPath || true
- echo "Pre-commit hook uninstalled"
hooks:run:
desc: Run pre-commit checks manually
cmds:
- ./.githooks/pre-commit
# Cleanup
clean:
desc: Clean build artifacts
cmds:
- go clean ./...
- rm -f /tmp/bench_compare.go /tmp/cpu_info.go
- rm -f testdata/generate_expectations