-
Notifications
You must be signed in to change notification settings - Fork 378
[diskann-wide] Optimize load_simd_first for 8-bit and 16-bit element types.
#747
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
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.
Pull request overview
Optimizes partial SIMD loads on x86_64::V3 for u8/i8 and u16 element types by replacing the previous cascaded load-chain logic with overlapping-load strategies that preserve the “no out-of-bounds access” safety contract while improving throughput in distance-function epilogues.
Changes:
- Added a new helper to efficiently load
(8, 16)bytes using two 8-byte loads +pshufb(_mm_shuffle_epi8). - Reworked
__load_first_of_16_bytesto use the new helper forfirst > 8and overlapping GP-register reads forfirst <= 8. - Reworked
__load_first_u16_of_16_bytesto use the new helper forbytes > 8and GP-register reads forbytes <= 8, removing prior masked-load/insert logic.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The particular benchmark results can be run locally by using the following input to JSON file{
"search_directories": [],
"jobs": [
{
"type": "simd-op",
"content": {
"query_type": "uint8",
"data_type": "uint8",
"arch": "x86-64-v3",
"runs": [
{
"distance": "squared_l2",
"dim": 100,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 101,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 102,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 103,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 104,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 105,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 128,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 160,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
}
]
}
},
{
"type": "simd-op",
"content": {
"query_type": "float16",
"data_type": "float16",
"arch": "x86-64-v3",
"runs": [
{
"distance": "squared_l2",
"dim": 100,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 101,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 102,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 103,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 104,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 105,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 128,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "squared_l2",
"dim": 160,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "inner_product",
"dim": 100,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "inner_product",
"dim": 101,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "inner_product",
"dim": 102,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "inner_product",
"dim": 103,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "inner_product",
"dim": 104,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "inner_product",
"dim": 105,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "inner_product",
"dim": 128,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
},
{
"distance": "inner_product",
"dim": 160,
"num_points": 50,
"loops_per_measurement": 5000,
"num_measurements": 100
}
]
}
}
]
} |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #747 +/- ##
==========================================
- Coverage 89.01% 89.00% -0.01%
==========================================
Files 428 428
Lines 78294 78295 +1
==========================================
- Hits 69691 69687 -4
- Misses 8603 8608 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
arkrishn94
left a comment
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.
LGTM, cool trick with the _load_8_to_16_bytes logic.
Optimize
SIMDVector::load_simd_firstforu8,i8andu16data type on thex86_64::V3architecture.These types use the
__load_first*algorithms since AVX2 does not have masked loads for 8/16-bit types. The current implementation uses a cascaded load-chain to ensure the safety contract is upheld. This results in a lot of fiddly conditional logic.This new implementation uses at most 2 data loads (plus sometimes one more load from a const variable for the shuffle-mask) to avoid the data dependent chain and avoids using the
u128type directly, which saves a bunch of LLVM register shenanigans.These functions are called in the epilogue handling of many distance function implementations.
Performance results are below. This is a pretty clear win for the 8-bit case. It appears to be kind of a wash for the 16-bit case though.