Files
tensor/signal/conv_bench_test.go
T
petrbalvin af4ee19703
Release / gates (push) Successful in 4m38s
Test / test (push) Successful in 5m16s
Release / release (push) Successful in 35s
feat: initial release
Assisted-by: GLM 5.3 Flash
2026-09-03 10:00:00 +02:00

49 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: MIT
package signal
import (
"fmt"
"testing"
)
// Channel-blocked kernel benchmarks at inference-like sizes. The
// channel count is the axis the kernels divide work along, so each
// size climbs a cache level: 4 channels stay in L1, 32 cross L2 and
// 128 make the whole-volume walk pay for memory bandwidth.
// BenchmarkConv3D measures a (1, C, 64, 64, 64) input through C×C
// kernels of 3×3×3, stride 1, padding 1.
func BenchmarkConv3D(b *testing.B) {
for _, ch := range []int{4, 32, 128} {
b.Run(fmt.Sprintf("%d channels", ch), func(b *testing.B) {
input := benchSig(b, 1, ch*64*64*64, 1, ch, 64, 64, 64)
kernel := benchSig(b, 2, ch*ch*27, ch, ch, 3, 3, 3)
b.ReportAllocs()
for b.Loop() {
if _, err := Conv3D(input, kernel, nil, 1, [3]int{1, 1, 1}, [3]int{1, 1, 1}); err != nil {
b.Fatal(err)
}
}
})
}
}
// BenchmarkConvTranspose2D measures a (1, C, 128, 128) input through
// C×C kernels of 3×3 at the upsampling stride of 2, padding 1.
func BenchmarkConvTranspose2D(b *testing.B) {
for _, ch := range []int{4, 32, 128} {
b.Run(fmt.Sprintf("%d channels", ch), func(b *testing.B) {
input := benchSig(b, 3, ch*128*128, 1, ch, 128, 128)
kernel := benchSig(b, 4, ch*ch*9, ch, ch, 3, 3)
b.ReportAllocs()
for b.Loop() {
if _, err := ConvTranspose2D(input, kernel, nil, 2, 1); err != nil {
b.Fatal(err)
}
}
})
}
}