Skip to content

Refactor native SIMD mappers to return pointers directly#144634

Merged
ChrisHegarty merged 9 commits intoelastic:mainfrom
ChrisHegarty:simdvec_template_refactor
Mar 20, 2026
Merged

Refactor native SIMD mappers to return pointers directly#144634
ChrisHegarty merged 9 commits intoelastic:mainfrom
ChrisHegarty:simdvec_template_refactor

Conversation

@ChrisHegarty
Copy link
Copy Markdown
Contributor

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!

@ChrisHegarty ChrisHegarty requested a review from ldematte March 20, 2026 09:23
@ChrisHegarty ChrisHegarty added >refactoring :Search Relevance/Vectors Vector search Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch labels Mar 20, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@ChrisHegarty ChrisHegarty requested a review from a team as a code owner March 20, 2026 09:30
@ChrisHegarty ChrisHegarty added the test-arm Pull Requests that should be tested against arm agents label Mar 20, 2026
Copy link
Copy Markdown
Contributor

@ldematte ldematte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good, thanks for doing this! Some very optional stuff on naming but that's it.

@ChrisHegarty ChrisHegarty merged commit 7b5d10a into elastic:main Mar 20, 2026
41 checks passed
@ChrisHegarty ChrisHegarty deleted the simdvec_template_refactor branch March 20, 2026 12:51
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>refactoring :Search Relevance/Vectors Vector search Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch test-arm Pull Requests that should be tested against arm agents v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants