-
Notifications
You must be signed in to change notification settings - Fork 516
feat: introduce turbo. #224
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
Open
luoxiaojian
wants to merge
13
commits into
alibaba:main
Choose a base branch
from
luoxiaojian:turbo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+565
−3
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a19b148
introduce turbo
luoxiaojian 8974bcf
format
luoxiaojian f332f2f
fix
luoxiaojian cffaa75
comment
luoxiaojian a1001ef
add guard
luoxiaojian d08d17c
fix
luoxiaojian 7a8e2a4
fix
luoxiaojian cb842fb
fix
luoxiaojian 8ec213f
fix
luoxiaojian 2ef289f
revert some modifications
luoxiaojian 642deff
refine
luoxiaojian ee3af4e
fix bound check
luoxiaojian 5fd4a0f
fix prefetch
luoxiaojian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ set(zvec_ailego_deps | |
| ) | ||
|
|
||
| set(zvec_core_deps | ||
| # empty | ||
| zvec_turbo | ||
| ) | ||
|
|
||
| set(zvec_db_deps | ||
|
|
||
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright 2025-present the zvec project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #pragma once | ||
|
|
||
| #include <functional> | ||
| #include <zvec/ailego/math_batch/utils.h> | ||
|
|
||
| namespace zvec::turbo { | ||
|
|
||
| using DistanceFunc = | ||
| std::function<void(const void *m, const void *q, size_t dim, float *out)>; | ||
| using BatchDistanceFunc = std::function<void( | ||
| const void **m, const void *q, size_t num, size_t dim, float *out)>; | ||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using QueryPreprocessFunc = | ||
| zvec::ailego::DistanceBatch::DistanceBatchQueryPreprocessFunc; | ||
|
|
||
| enum class MetricType { | ||
| kSquaredEuclidean, | ||
| kUnknown, | ||
| }; | ||
|
|
||
| enum class DataType { | ||
| kInt8, | ||
| kUnknown, | ||
| }; | ||
|
|
||
| enum class QuantizeType { | ||
| kDefault, | ||
| }; | ||
|
|
||
| DistanceFunc get_distance_func(MetricType metric_type, DataType data_type, | ||
| QuantizeType quantize_type); | ||
|
|
||
| BatchDistanceFunc get_batch_distance_func(MetricType metric_type, | ||
| DataType data_type, | ||
| QuantizeType quantize_type); | ||
|
|
||
| QueryPreprocessFunc get_query_preprocess_func(MetricType metric_type, | ||
| DataType data_type, | ||
| QuantizeType quantize_type); | ||
|
|
||
| } // namespace zvec::turbo | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) | ||
| include(${PROJECT_ROOT_DIR}/cmake/option.cmake) | ||
|
|
||
| if(NOT ANDROID AND AUTO_DETECT_ARCH) | ||
| if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|i686|i386|x64") | ||
| setup_compiler_march_for_x86(TURBO_MARCH_FLAG_SSE TURBO_MARCH_FLAG_AVX2 TURBO_MARCH_FLAG_AVX512) | ||
| set_source_files_properties( | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/euclidean/avx512_impl.cc | ||
| PROPERTIES | ||
| COMPILE_FLAGS "${TURBO_MARCH_FLAG_AVX512}" | ||
| ) | ||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") | ||
| # ARM64 architecture - no special march flags needed for now | ||
| # NEON implementations can be added here if needed | ||
| message(STATUS "turbo: ARM64 detected, skipping x86-specific optimizations") | ||
| endif() | ||
| endif() | ||
|
|
||
| file(GLOB_RECURSE ALL_SRCS *.cc *.c *.h) | ||
|
|
||
| cc_library( | ||
| NAME zvec_turbo STATIC STRICT PACKED | ||
| SRCS ${ALL_SRCS} | ||
| INCS ${PROJECT_ROOT_DIR}/src/include/zvec | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
m × nmatrix casesturbo::DistanceFunchas the same ABI asMatrixDistance— both arestd::function<void(const void*, const void*, size_t, float*)>— but their calling conventions differ. Form = 1, n = 1the pointers are treated as single vectors. Form = M, n = N > 1, callers interpret the first pointer asMtightly-packed vectors and the output as anM × Nfloat matrix. The turbo function only ever computes a single inner product, so calling it in place of an8 × 4matrix kernel writes one float instead of 32, leaving the rest uninitialised and corrupting the caller's output array.The turbo path should be limited to the 1×1 case: