Skip to content

Vectorise the dense Gaussian kernel - #465

Open
mtantaoui wants to merge 1 commit into
rust-ml:masterfrom
mtantaoui:perf/kernel-gaussian-across-points
Open

mtantaoui wants to merge 1 commit into
rust-ml:masterfrom
mtantaoui:perf/kernel-gaussian-across-points

Conversation

@mtantaoui

Copy link
Copy Markdown

Vectorise the dense Gaussian kernel

Build the dense Gaussian kernel one feature at a time across all points
instead of one pair at a time, so the distance loop vectorises. Results
are bit-identical to KernelMethod::distance; a new test checks this.

Add a criterion bench. On n = 2000 it is 2.4-6.2× faster for f32 and
1.7-3.3× for f64.

Benchmark

New criterion bench, cargo bench -p linfa-kernel --bench gaussian, which builds
a dense Gaussian kernel through the public API for n ∈ {500, 2000} and
d ∈ {2, 16, 64, 120}.

Intel Core Ultra 7 155H, one core pinned, criterion means, n = 2000:

case master this PR speedup
f32 d=2 22.8 ms 9.65 ms 2.4×
f32 d=16 54.8 ms 14.6 ms 3.8×
f32 d=64 194.2 ms 32.1 ms 6.0×
f32 d=120 322.4 ms 52.3 ms 6.2×
f64 d=2 28.6 ms 17.0 ms 1.7×
f64 d=16 59.5 ms 26.5 ms 2.2×
f64 d=64 199.5 ms 60.0 ms 3.3×
f64 d=120 331.7 ms 103.0 ms 3.2×

n = 500 shows the same pattern (f32 2.5–5.9×, f64 1.8–3.3×).

Everything that builds a dense Gaussian kernel benefits, linfa-svm included
(its tests pass unchanged).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant