← Back to Pull requests

Score native bulk similarity two targets per downcall #866

Open
unknown opened this pull request with 419 lines diff across 5 files
View on GitHub
unknown unknown commented on Dec 02, 2026 03:41 UTC
Author

Score native bulk similarity two targets per downcall

Since #819, the Panama provider scores four targets per pass in bulk, but the native provider still loops over single-pair calls. This PR adds native bulk kernels.

What

  • New kernels dot_product_f32_x2, cosine_f32_x2 and euclidean_f32_x2 score one query against two targets. They share the query loads and return results bit-identical to the single-pair kernels.

  • NativeVectorUtilSupport's bulk dotProduct, cosine and squareDistance use them. An odd last target goes through the single-pair kernel.

  • The kernels take 3 pointers and return both scores packed in a uint64_t. That keeps the JDK downcall stub at 319 bytes, under C2's 325-byte inlining limit, so the heap segment wrappers are scalar-replaced and the bulk path allocates nothing.

  • The fused loops need 8 accumulators, which fits AVX2's 16 vector registers, so AVX2 benefits too.
  • Why two targets, not four: a 4-target kernel gets a 600-byte stub, which doesn't inline. It allocated 432 B per call and made sift-128 search 14–16% slower.

    Results

    Search QPS. Recall is identical in every arm.

    | Dataset | Vectors (base / queries) | ISA | Search threads | Overquery | Panama | main native | This PR, native | PR vs main native |
    |---|---|---|---|---|---:|---:|---:|---:|
    | sift-128 | 1M / 10k | AVX-512 | 16 | ×1 | 101,937 | 102,619 | 100,789 | −1.8% |
    | sift-128 | 1M / 10k | AVX-512 | 16 | ×5 | 36,322 | 35,994 | 35,517 | −1.3% |
    | sift-128 | 1M / 10k | AVX-512 | 16 | ×20 | 11,638 | 11,514 | 11,526 | +0.1% |
    | sift-128 | 1M / 10k | AVX2 | 16 | ×1 | 114,286 | 102,056 | 108,813 | +6.6% |
    | sift-128 | 1M / 10k | AVX2 | 16 | ×5 | 39,791 | 36,159 | 38,177 | +5.6% |
    | sift-128 | 1M / 10k | AVX2 | 16 | ×20 | 12,820 | 11,558 | 12,386 | +7.2% |
    | Cohere 1024-d | 100k / 10k | AVX-512 | 1 (pinned) | n/a | 1,620 | 1,350 | 1,494 | +10.6% |
    | Cohere 1024-d | 100k / 10k | AVX2 | 1 (pinned) | n/a | 1,662 | 1,361 | 1,542 | +13.3% |

    Build time (s)

    | Dataset | Vectors | ISA | Build threads | Panama | main native | This PR, native |
    |---|---|---|---|---:|---:|---:|
    | sift-128 | 1M | AVX-512 | 8 | 97.6 | 91.5 | 85.7 (noisy: native runs ranged 82–95) |
    | sift-128 | 1M | AVX2 | 8 | 89.3 | 89.4 | 87.7 |
    | Cohere 1024-d | 100k | AVX-512 | 7 | 17.97 | 20.00 | 19.69 |
    | Cohere 1024-d | 100k | AVX2 | 7 | 18.96 | 20.93 | 19.31 |

    Machine: m6idn.4xlarge. Xeon Platinum 8375C, 8 cores / 16 vCPUs. sift search uses the JVM's shared thread pool, which comes to 16 threads on this machine. Cohere search runs on a single thread pinned to one CPU.

    Setup

  • Xeon Platinum 8375C, with main, its native provider and Panama interleaved; medians of 3 rounds.

  • AVX2 means -XX:UseAVX=2 for Panama and JVECTOR_MAX_ISA=avx2 for native.

  • sift-128: BenchYAML on JDK 22, M 32, efConstruction 100, top-10, overquery 1 to 20.

  • Cohere 1024-d: 100k vectors, exact single-thread search, JDK 25.
  • Tests: NativeBulkScoringTest checks that bulk results match single-pair results bit for bit across lengths 1–3072, group sizes 0–32 and edge values. It passes with no ISA cap and capped at AVX2 and SSE4.2. BulkScoringBenchmark (JMH) shows 0 B/op allocation, and bulk is faster than single-pair at 128-d and 1024-d.

    Related: #771, #821

    Diff: 419 lines (+314 / -105) across 5 files Reviewer: MarkWolters Review duration: 1729m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.45) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 419 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.361
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #866"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.0% (MEDIUM) · Higher = larger blast radius
    45.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.7% · Safe to merge
    25.7%