-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[ENH] Use AVX in distance calculations #5258
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
Conversation
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
Prioritize AVX Over SSE in Distance Calculations for Rust Distance Crate This pull request reorders the SIMD feature detection and function selection logic in the Rust distance calculation module to give higher priority to AVX/FMA over SSE for x86/x86_64 architectures. The changes ensure that, when available, AVX and FMA instructions are used for distance computations (euclidean, cosine, and inner product), which can offer higher performance for platforms that support these instruction sets. Additionally, the author notes that builds will be forced to use AVX if ENABLE_AVX512 is set in the Dockerfile, though Dockerfile changes are not present in this diff. Key Changes• Reordered feature detection to select Affected Areas• rust/distance/src/types.rs (distance calculation logic for all supported This summary was automatically generated by @propel-code-bot |
274fb50
to
02928a9
Compare
#[cfg(all( | ||
any(target_arch = "x86_64", target_arch = "x86"), | ||
target_feature = "sse" | ||
))] | ||
{ | ||
if std::arch::is_x86_feature_detected!("sse") { | ||
return unsafe { crate::distance_sse::euclidean_distance(a, b) }; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Documentation]
The reordering of instruction set priority from SSE-first to AVX-first looks correct, but consider documenting this prioritization decision. When both SSE and AVX are available at runtime, AVX will now be chosen, which should provide better performance. However, this means the fallback path (SSE → scalar) is now longer when AVX is not available.
Consider adding a comment explaining the prioritization rationale:
// Check instruction sets in order of performance: AVX (best) → SSE → scalar (fallback)
Also verify that the runtime feature detection order aligns with the compile-time feature requirements - all AVX-capable processors should also support SSE, so this ordering should be safe.
Description of changes
This PR updates the distance crate to prioritize AVX over SSE, and forces builds with AVX flags when ENABLE_AVX512 is set in the Dockerfile
Test plan
How are these changes tested?
pytest
for python,yarn test
for js,cargo test
for rustMigration plan
Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?
Observability plan
What is the plan to instrument and monitor this change?
Documentation Changes
Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?