Skip to content

feat(search): Metal residual bound kernel + GPU cascade routing (chain 3/3) - #30

Open
christopherkarani wants to merge 1 commit into
chain/2-residual-corefrom
chain/3-gpu-bounds
Open

feat(search): Metal residual bound kernel + GPU cascade routing (chain 3/3)#30
christopherkarani wants to merge 1 commit into
chain/2-residual-corefrom
chain/3-gpu-bounds

Conversation

@christopherkarani

Copy link
Copy Markdown
Owner

Chain Info

Chain: 3 of 3
Strategy: feature-branch-chain
Base: chain/2-residual-core (merge 1, then 2 first)

Summary

  • Adds residual_bound_parameters / residual_compute_bounds to FlatSearch.metal: one bandwidth-bound GPU pass computes safe per-row lower bounds for the cascade.
  • ResidualCascadeGPU.swift implements searchGPU(context:) with lazy per-device plane caching and exact host verification; any failure falls back to the flat GPU tier (never approximate).
  • FlatGPUSearch.search routes eligible very-large-corpora queries through Tier 2.5 before the flat GPU tier.

Exactness

  • Only mathematically safe lower bounds prune; survivors are rescored exactly on host.
  • METALANNS_VERIFY_BOUNDS=1: zero bound violations across cosine/L2/inner-product diagnostics.
  • recall@10 = recall@100 = 1.000 vs scalar reference at n=300k and n=1M.

Performance (fixed protocol: 1M×384 cosine k=24, M3 Max, seed 42)

baseline this chain
warm p50 6.07 ms 2.42 ms (~2.5×)
p95 6.36 ms 4.43 ms
QPS 163.9 365.3
recall@10 1.000 1.000

The ≥10× aspiration is not met; limiting factors are the full-corpus projected-bound scan and host seed selection. Best observed run: p50 2.35 ms.

Changes

File Change
Sources/MetalANNSCore/Shaders/FlatSearch.metal +74 lines: bound kernel + parameter structs
Sources/MetalANNSCore/ResidualCascadeGPU.swift New: GPU cascade dispatch + plane cache
Sources/MetalANNSCore/FlatGPUSearch.swift Tier 2.5 routing + lint suppressions

Test Plan

  • Release build clean
  • Full suite: 325 tests / 71 suites pass on this branch alone
  • Zero bound violations (METALANNS_VERIFY_BOUNDS=1)

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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