Refactor native SIMD mappers to return pointers directly#144634
Merged
ChrisHegarty merged 9 commits intoelastic:mainfrom Mar 20, 2026
Merged
Refactor native SIMD mappers to return pointers directly#144634ChrisHegarty merged 9 commits intoelastic:mainfrom
ChrisHegarty merged 9 commits intoelastic:mainfrom
Conversation
Collaborator
|
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
ldematte
approved these changes
Mar 20, 2026
Contributor
ldematte
left a comment
There was a problem hiding this comment.
Looks very good, thanks for doing this! Some very optional stuff on naming but that's it.
michalborek
pushed a commit
to michalborek/elasticsearch
that referenced
this pull request
Mar 23, 2026
…4634) This commit refactors the native vector scoring templates so that mapper functions return a direct `const T*` pointer to the target vector, instead of an `int64_t` byte offset that callers then multiply and add to a base pointer. This simplifies every bulk scoring template (`call_i8_bulk`, `call_f32_bulk`, `cosi8_inner_bulk`, `dot7u_inner_bulk`, `sqr7u_inner_bulk`, `doti4_bulk_impl`, `dotdXq4_inner_bulk`) by collapsing the three-step resolve-offset-then-compute-pointer pattern into a single mapper call. Specifically: - **`vec_common.h`**: `identity_mapper` and `array_mapper` are now templates returning `const T*`. Removed `safe_mapper_offset` and `init_offsets`; replaced with `init_pointers` which combines pointer resolution and bounds checking in one step. - **aarch64 and amd64 `.cpp` files**: Updated all template signatures, mapper call sites, and `init_offsets` / `safe_mapper_offset` usages to use the new pointer-returning mappers and `init_pointers`. Motivation The previous design required each call site to perform `base + mapper(i, offsets) * pitch` to obtain a vector pointer. With mappers returning pointers directly, call sites are simpler and the mapper signature becomes extensible; new mappers (e.g. for non-contiguous memory layouts) can use completely different addressing strategies while conforming to the same function pointer type. We have such things in the works!
ldematte
added a commit
to ldematte/elasticsearch
that referenced
this pull request
Mar 23, 2026
PR elastic#144634 refactored mappers to return pointers directly instead of indices. Update vec_i4_2.cpp to use the new init_pointers, sequential_mapper, and offsets_mapper. Made-with: Cursor
ChrisHegarty
added a commit
that referenced
this pull request
Apr 3, 2026
Follow-up to #144634. Extends the TData mapper template generalization to the BBQ (dotd1q4, dotd2q4, dotd4q4) and INT4 (doti4) bulk scoring templates on both amd64 and aarch64 tier-1, which were not covered by the original refactoring. This is a pure refactor with no functional change. The existing sequential_mapper and offsets_mapper instantiations now explicitly pass int8_t as TData rather than hardcoding const int8_t* in the template signature.
mromaios
pushed a commit
to mromaios/elasticsearch
that referenced
this pull request
Apr 9, 2026
…145459) Follow-up to elastic#144634. Extends the TData mapper template generalization to the BBQ (dotd1q4, dotd2q4, dotd4q4) and INT4 (doti4) bulk scoring templates on both amd64 and aarch64 tier-1, which were not covered by the original refactoring. This is a pure refactor with no functional change. The existing sequential_mapper and offsets_mapper instantiations now explicitly pass int8_t as TData rather than hardcoding const int8_t* in the template signature.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This commit refactors the native vector scoring templates so that mapper functions return a direct
const T*pointer to the target vector, instead of anint64_tbyte offset that callers then multiply and add to a base pointer. This simplifies every bulk scoring template (call_i8_bulk,call_f32_bulk,cosi8_inner_bulk,dot7u_inner_bulk,sqr7u_inner_bulk,doti4_bulk_impl,dotdXq4_inner_bulk) by collapsing the three-step resolve-offset-then-compute-pointer pattern into a single mapper call.Specifically:
vec_common.h:identity_mapperandarray_mapperare now templates returningconst T*. Removedsafe_mapper_offsetandinit_offsets; replaced withinit_pointerswhich combines pointer resolution and bounds checking in one step..cppfiles: Updated all template signatures, mapper call sites, andinit_offsets/safe_mapper_offsetusages to use the new pointer-returning mappers andinit_pointers.Motivation
The previous design required each call site to perform
base + mapper(i, offsets) * pitchto obtain a vector pointer. With mappers returning pointers directly, call sites are simpler and the mapper signature becomes extensible; new mappers (e.g. for non-contiguous memory layouts) can use completely different addressing strategies while conforming to the same function pointer type. We have such things in the works!