forked from pingcap/tiflash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: Enable simsimd for usearch (pingcap#224)
Signed-off-by: Wish <breezewish@outlook.com> Co-authored-by: JaySon <tshent@qq.com>
- Loading branch information
1 parent
c192e9b
commit 628f40f
Showing
10 changed files
with
219 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
33 changes: 33 additions & 0 deletions
33
dbms/src/Storages/DeltaMerge/Index/VectorIndexHNSW/SIMDFeatures.cpp
This file contains 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,33 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// 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. | ||
|
||
#include <Common/Logger.h> | ||
#include <Storages/DeltaMerge/Index/VectorIndexHNSW/SIMDFeatures.h> | ||
#include <Storages/DeltaMerge/Index/VectorIndexHNSW/USearch.h> | ||
#include <common/logger_useful.h> | ||
|
||
namespace DB::DM | ||
{ | ||
|
||
std::vector<std::string> VectorIndexHNSWSIMDFeatures::get() | ||
{ | ||
auto m_l2 = unum::usearch::metric_punned_t(3, unum::usearch::metric_kind_t::l2sq_k); | ||
auto m_cos = unum::usearch::metric_punned_t(3, unum::usearch::metric_kind_t::cos_k); | ||
return { | ||
fmt::format("hnsw.l2={}", m_l2.isa_name()), | ||
fmt::format("hnsw.cosine={}", m_cos.isa_name()), | ||
}; | ||
} | ||
|
||
} // namespace DB::DM |
28 changes: 28 additions & 0 deletions
28
dbms/src/Storages/DeltaMerge/Index/VectorIndexHNSW/SIMDFeatures.h
This file contains 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,28 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// 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 <string> | ||
|
||
namespace DB::DM | ||
{ | ||
|
||
class VectorIndexHNSWSIMDFeatures | ||
{ | ||
public: | ||
static std::vector<std::string> get(); | ||
}; | ||
|
||
} // namespace DB::DM |
35 changes: 35 additions & 0 deletions
35
dbms/src/Storages/DeltaMerge/Index/VectorIndexHNSW/USearch.h
This file contains 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,35 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// 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 | ||
|
||
// USearch is header only. We don't use cmake to make these defines to avoid | ||
// polluting all compile units. | ||
|
||
#define USEARCH_USE_SIMSIMD 1 | ||
#define SIMSIMD_NATIVE_F16 0 | ||
#define SIMSIMD_NATIVE_BF16 0 | ||
|
||
// Force enable all target features. | ||
#define SIMSIMD_TARGET_NEON 1 | ||
#define SIMSIMD_TARGET_SVE 0 // Clang13's header does not support enableing SVE for region | ||
#define SIMSIMD_TARGET_HASWELL 1 | ||
#define SIMSIMD_TARGET_SKYLAKE 0 // Clang13 does not support AVX512 | ||
#define SIMSIMD_TARGET_ICE 0 | ||
#define SIMSIMD_TARGET_GENOA 0 | ||
#define SIMSIMD_TARGET_SAPPHIRE 0 | ||
|
||
#include <usearch/index.hpp> | ||
#include <usearch/index_dense.hpp> | ||
#include <usearch/index_plugins.hpp> |
This file contains 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 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 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