Skip to content

[SPARK-59563][ML] Use BLAS routines for vector L1 and L2 norms - #58849

Open
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:ml-blas-vector-norms-dev-7
Open

zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:ml-blas-vector-norms-dev-7

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR adds BLAS.asum(Vector) and BLAS.nrm2(Vector) to both ML and MLlib and uses them for
L1 and L2 vector norms. Dense vectors pass their backing arrays to BLAS, while sparse vectors pass
only their stored values.

Why are the changes needed?

The existing Scala loops do not use the SIMD BLAS implementation available to Spark.

On an Intel Xeon Platinum 8375C with JDK 17 and VectorBLAS, a local benchmark measured these
speedups over the existing Scala loops:

Stored values L1 L2
16 1.6x 2.1x
256 8.4x 9.2x
4,096 7.7x 8.3x
65,536 6.1x 7.2x

Dense and sparse vectors had equivalent results for the same stored-value count.

Does this PR introduce any user-facing change?

No. This replaces the internal norm loops with equivalent BLAS routines.

How was this patch tested?

Ran the existing dense and sparse vector norm coverage:

build/sbt "mllib-local/testOnly org.apache.spark.ml.linalg.VectorsSuite"
build/sbt "mllib/testOnly org.apache.spark.mllib.linalg.VectorsSuite"

All 76 tests passed (36 in mllib-local, 40 in mllib). The performance results above were
measured with a temporary Spark Benchmark harness that compared the previous loops with
Vectors.norm; the harness is not included in this PR.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Codex (GPT-5)

@zhengruifeng
zhengruifeng marked this pull request as ready for review September 16, 2026 12:38
@zhengruifeng
zhengruifeng marked this pull request as draft September 16, 2026 12:39
@zhengruifeng
zhengruifeng marked this pull request as ready for review September 16, 2026 15:21
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