-
Notifications
You must be signed in to change notification settings - Fork 154
Port Panama SIMD kernels to C++ using Google Highway #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
r-devulap
wants to merge
22
commits into
main
Choose a base branch
from
hwy-native-funcs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3c7b38f
Port native SIMD to Google Highway: C++ infrastructure
r-devulap f108a4c
Port native SIMD to Google Highway: FP32 kernels
r-devulap 6238715
Port native SIMD to Google Highway: PQ kernels
r-devulap d4ed0f9
Port native SIMD to Google Highway: NVQ kernels
r-devulap 397f712
Always prefer native dp, l2 and cosine
r-devulap ced7519
Add new calculatePartialSelfSum
r-devulap 6510a11
Add Meson and Ninja installation to GitHub Actions workflows
r-devulap 4190499
Add git submodule initialization to GitHub Actions workflows
r-devulap e381500
Exclude .gitmodules from RAT checks
r-devulap 18a90ce
Remove recursive submodule init from unit tests workflow
r-devulap 887c4b3
Use DataStax license headers and exclude native build artifacts from RAT
r-devulap 82d9d17
Remove unnecessary file and duplicate gcc version check
r-devulap e0106f5
Fix Shuffle2301/Shuffle1032 comments: diagrams and semantics were swa…
r-devulap c2e5068
Fix RAT excludes: add module-relative paths for build/ and third_party/
r-devulap 00b5eef
Use snake case consistently
r-devulap 18b1b5d
Use --auto-install-deps instead of --auto-install-gcc
r-devulap 1edff51
Configure maven-clean-plugin to remove meson build artifacts
r-devulap 80f3229
Mode meson build directory to jvector-native/target
r-devulap 32a0565
Revert "Configure maven-clean-plugin to remove meson build artifacts"
r-devulap d940c55
Rename jvector-native/src/main/c -> jvector-native/src/main/native
r-devulap 398caeb
ci: add meson/ninja install and submodule init to run-compaction work…
r-devulap 2053dcb
Adding release notes for PR #668
r-devulap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "jvector-native/src/main/native/third_party/highway"] | ||
| path = jvector-native/src/main/native/third_party/highway | ||
| url = https://github.com/google/highway.git | ||
|
r-devulap marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| ### Native SIMD Acceleration via Google Highway | ||
|
|
||
| **Description** | ||
|
|
||
| This PR introduces a comprehensive native SIMD backend to JVector, porting | ||
| **all** Panama Vector API kernels to native code backed by [Google | ||
| Highway](https://github.com/google/highway), a portable, header-only C++ | ||
| library for SIMD operations. Previously, only two kernels in `jvector-native` | ||
| were implemented natively; all other SIMD operations relied on the Panama | ||
| Vector API as a fallback. Google Highway is currently enabled on all x86-64 | ||
| platforms. The native shared library (`libjvector.so`) is built as a single | ||
| binary containing three ISA-specific variants: AVX-512 (Skylake), AVX2 | ||
| (Haswell), and SSE4.2. At JVM startup, the most suitable ISA is automatically | ||
| selected via CPUID detection. SSE4.2 serves as the minimum supported baseline; | ||
| CPUs lacking this capability will trigger a `SIGILL` at runtime. | ||
|
|
||
| The ported kernels cover all hot paths: | ||
|
|
||
| - **FP32 similarity** — `dot_product`, `cosine`, `euclidean` | ||
| - **Product Quantization (PQ)** — `assemble_and_sum`, `calculate_partial_sums`, | ||
| `pq_decoded_cosine_similarity` | ||
| - **Non-uniform Vector Quantization (NVQ)** — `nvq_quantize_8bit`, `nvq_loss`, | ||
| `nvq_square_l2_distance_8bit`, and related helpers | ||
| - **Element-wise arithmetic** — `add_in_place`, `sub_in_place`, `max`, | ||
| `min_in_place`, and others | ||
|
|
||
| A new `calculatePartialSelfSum` kernel was also added. On x86-64, when native | ||
| vectorization is enabled, the Google Highway backend is used **exclusively** | ||
| for all similarity and quantization operations — the Panama Vector API path is | ||
| bypassed almost entirely. On other architectures (ARM, RISC-V, etc.), the | ||
| Panama Vector API continues to provide SIMD acceleration as before; native | ||
| Highway support for these platforms is planned for a future release if required. | ||
|
|
||
| **Purpose / Impact** | ||
|
|
||
| - Consistent, portable SIMD coverage across AVX-512, AVX2, and SSE4.2 | ||
| without per-target intrinsic duplication | ||
| - Automatic ISA selection at startup based on CPUID — no manual configuration | ||
| needed | ||
| - Eliminates reliance on Panama Vector API for similarity kernels, removing | ||
| JDK-version sensitivity for the fast path | ||
| - Runtime ISA can be capped for testing via the `JVECTOR_MAX_ISA` environment | ||
| variable (`avx3`, `avx2`, or `sse42`) | ||
| - **Minimum requirement:** SSE4.2-capable x86-64 CPU; older CPUs will crash | ||
| with `SIGILL` | ||
|
|
||
| **How to Enable** | ||
|
|
||
| Native vectorization is opt-in. Add the following JVM flags to enable it: | ||
|
|
||
| ```bash | ||
| java --enable-native-access=ALL-UNNAMED \ | ||
| -Djvector.experimental.enable_native_vectorization=true \ | ||
| -jar your-app.jar | ||
| ``` | ||
|
|
||
| Once enabled, `NativeVectorizationProvider` loads `libjvector.so` and the | ||
| Highway-backed kernels are used automatically for all similarity and | ||
| quantization operations. | ||
|
|
||
| To additionally cap the ISA for debugging or benchmarking: | ||
|
|
||
| ```bash | ||
| JVECTOR_MAX_ISA=avx2 java --enable-native-access=ALL-UNNAMED \ | ||
| -Djvector.experimental.enable_native_vectorization=true \ | ||
| -jar your-app.jar | ||
| ``` | ||
|
|
||
| **Notes** | ||
|
|
||
| - The build now uses [Meson](https://mesonbuild.com/) + Ninja to compile the | ||
| three ISA variants; see | ||
| `jvector-native/src/main/native/jextract_vector_simd.sh` for build and | ||
| `jextract` binding-regeneration instructions. | ||
| - Google Highway is vendored as a Git submodule under | ||
| `jvector-native/src/main/native/third_party/highway` at commit | ||
| [`16f5f5c7`](https://github.com/google/highway/commit/16f5f5c768064d0bb52952888a14236bec75c104) | ||
| (v1.4.0+15). | ||
| - CI workflows (unit tests and compaction) were updated to install Meson/Ninja | ||
| and initialise the Highway submodule before building. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.