Skip to content

Commit 0549cb0

Browse files
tannevaledclaude
andauthored
kernels: import go-simd/floats for sum, elementwise, extrema, clip, exp, log (K1) (#97)
* kernels: import go-simd/floats for sum, elementwise, extrema, clip, exp, log (K1) K1 of the go-scikit performance campaign (go-scikit/roadmap#27): ndarray now imports go-simd/floats v0.9.0 and deletes its copies. - exp, log, and the correctly rounded float32 exp/log (with the AVX2 kernels of #94/#96 and the NEON kernel of #95, now go-simd/floats#29): deleted here (Go sources, tests, generator kernels, assembly); Exp, Log, Exp32, Log32 and their P forms call floats. - amd64 and arm64: the sum/sqrt/max/min/add/sub/mul/div kernels are floats'; Clip is floats.ClampScalar. Max/Min resolve a zero result with the serial oracle (floats leaves the sign of zero unspecified). - Sum is floats.SumPairwise on every architecture: NumPy's order, bit-identical to np.sum; serial at every size. A changed last bit is the fix; the golden values of TestSumMatchesNumPy are NumPy 2.5.4's. - Not moved: the float32 elementwise/sqrt/extremum/AddBlocks8F32 kernels, the dot inside GEMM/Dot1D, and the ppc64le, loong64, riscv64 and s390x kernels (floats has none for them yet). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * kernels: test the parallel exp/log forms and Log10 (100% coverage gate) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 14d590b commit 0549cb0

45 files changed

Lines changed: 300 additions & 3499 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ arch is therefore a durable foundation. The numeric loops live in
175175
on every 64-bit target Go supports (amd64, arm64, ppc64le, loong64, riscv64,
176176
s390x), behind the same API and held to the same tests.
177177

178+
The one-dimensional float64 kernels that other libraries need too live once, in
179+
[go-simd/floats](https://github.com/go-simd/floats) (K1 of the go-scikit
180+
[performance campaign](https://github.com/go-scikit/roadmap/blob/main/docs/performance-campaign.md)),
181+
which this module imports: on amd64 (AVX2) and arm64 (NEON) the elementwise
182+
`Add`/`Sub`/`Mul`/`Div`, `Sqrt`, `Max`/`Min` and `Clip` kernels, and everywhere
183+
`Exp`, `Log` and the correctly rounded float32 `Exp`/`Log` (the AVX2 and NEON
184+
kernels were written here and moved down). **`Sum` is NumPy's pairwise sum**
185+
(`floats.SumPairwise`): bit-identical to `np.sum` of a contiguous 1-D float64
186+
array, on every architecture, at every size. It replaces lane-parallel sums whose
187+
last bits differed from NumPy's and from one architecture to the next, and it is
188+
serial (a multicore split would regroup NumPy's order). The other architectures
189+
keep their own elementwise kernels here until floats has them.
190+
178191
## Goroutines
179192

180193
Operations on large arrays are spread over `GOMAXPROCS` goroutines. After the

‎go.mod‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ module github.com/go-ndarray/ndarray
22

33
go 1.27.2
44

5-
require github.com/go-fft/fft v0.28.11
5+
require (
6+
github.com/go-fft/fft v0.28.11
7+
github.com/go-simd/floats v0.9.0
8+
)
9+
10+
require golang.org/x/sys v0.49.0 // indirect

‎go.sum‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
github.com/go-fft/fft v0.28.11 h1:ZfT78fSmPjZU2E9PgkSI/0f0E3sesYpl13GHmIFzRGc=
22
github.com/go-fft/fft v0.28.11/go.mod h1:GN5V4TWCjV05ECqH1ONfjFM6Z1m2shqCdssxKGqQ41s=
3+
github.com/go-simd/floats v0.9.0 h1:P/sMlwYWwaqCah/cMcBRfffK1JcUxXZVj76f4AwQRN0=
4+
github.com/go-simd/floats v0.9.0/go.mod h1:Aq5a6oY5pUqm9Hpi+iV2nrNmaaUb0rwHvUHIerXWSvA=
5+
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
6+
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=

‎internal/kernels/asmgen/amd64/gen.go‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,11 @@ import (
3737

3838
func main() {
3939
f := emit.NewFile("amd64")
40-
f.Add(sumKernel())
41-
f.Add(sqrtKernel())
42-
f.Add(extremeKernel("maxSSE2", "MAXPD", "MAXSD"))
43-
f.Add(extremeKernel("minSSE2", "MINPD", "MINSD"))
44-
f.Add(binKernel("addSSE2", "ADDPD", "ADDSD"))
45-
f.Add(binKernel("subSSE2", "SUBPD", "SUBSD"))
46-
f.Add(binKernel("mulSSE2", "MULPD", "MULSD"))
47-
f.Add(binKernel("divSSE2", "DIVPD", "DIVSD"))
40+
// The float64 sum, sqrt, max/min and add/sub/mul/div kernels, and the float32
41+
// exp/log and float64 log kernels, moved to go-simd/floats (K1 of the
42+
// go-scikit performance campaign): sumKernel, sqrtKernel, extremeKernel,
43+
// binKernel, exp32CRKernel, log32CRKernel and logKernel below are no longer
44+
// emitted.
4845
f.Add(gemmFMAKernel())
4946
f.Add(gemm32FMAKernel())
5047
for mr := 1; mr <= gemmMR; mr++ {
@@ -54,10 +51,6 @@ func main() {
5451
f.Add(dotFMAKernel())
5552
f.Add(gemmSSE2HalfKernel())
5653
f.Add(amd64.FeatureProbe("hasFMA", amd64.FMA))
57-
f.Add(amd64.FeatureProbe("hasAVX2", amd64.AVX2))
58-
f.Add(exp32CRKernel())
59-
f.Add(log32CRKernel())
60-
f.Add(logKernel())
6154
f.Add(blocks8Kernel())
6255
f.Add(bin32Kernel("add32SSE2", "ADDPS", "ADDSS"))
6356
f.Add(bin32Kernel("sub32SSE2", "SUBPS", "SUBSS"))

‎internal/kernels/asmgen/arm64/gen.go‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,15 @@ func reduceSig() arm64.Signature {
4141

4242
func main() {
4343
f := emit.NewFile("arm64")
44-
f.Add(sumKernel())
44+
// The float64 sum, sqrt, add/sub/mul/div and max/min kernels moved to
45+
// go-simd/floats (K1 of the go-scikit performance campaign): sumKernel,
46+
// sqrtKernel, binKernel and extremumKernel below are no longer emitted.
4547
f.Add(dotKernel())
46-
f.Add(sqrtKernel())
47-
f.Add(binKernel("addNEON", "VFADD", "FADDD"))
48-
f.Add(binKernel("subNEON", "VFSUB", "FSUBD"))
49-
f.Add(binKernel("mulNEON", "VFMUL", "FMULD"))
50-
f.Add(binKernel("divNEON", "VFDIV", "FDIVD"))
5148
f.Add(bin32Kernel("add32NEON", "VFADD", "FADDS"))
5249
f.Add(bin32Kernel("sub32NEON", "VFSUB", "FSUBS"))
5350
f.Add(bin32Kernel("mul32NEON", "VFMUL", "FMULS"))
5451
f.Add(bin32Kernel("div32NEON", "VFDIV", "FDIVS"))
5552
f.Add(sqrt32Kernel())
56-
f.Add(extremumKernel("maxNEON", "VFMAX", "FMAXD"))
57-
f.Add(extremumKernel("minNEON", "VFMIN", "FMIND"))
5853
f.Add(extremum32Kernel("max32NEON", "VFMAX", "FMAXS"))
5954
f.Add(extremum32Kernel("min32NEON", "VFMIN", "FMINS"))
6055
f.Add(gemmKernel())

‎internal/kernels/exp.go‎

Lines changed: 0 additions & 270 deletions
This file was deleted.

0 commit comments

Comments
 (0)