mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 17:48:29 +08:00
Remove ConcurrentBitsetPtr in segcore
Signed-off-by: FluorineDog <guilin.gou@zilliz.com>
This commit is contained in:
parent
455cc59dbb
commit
af1900b42a
@ -18,4 +18,4 @@ set(MILVUS_QUERY_SRCS
|
|||||||
SubQueryResult.cpp
|
SubQueryResult.cpp
|
||||||
)
|
)
|
||||||
add_library(milvus_query ${MILVUS_QUERY_SRCS})
|
add_library(milvus_query ${MILVUS_QUERY_SRCS})
|
||||||
target_link_libraries(milvus_query milvus_proto milvus_utils knowhere)
|
target_link_libraries(milvus_query milvus_proto milvus_utils knowhere boost_bitset_ext)
|
||||||
|
|||||||
@ -20,20 +20,6 @@
|
|||||||
#include "query/SearchOnIndex.h"
|
#include "query/SearchOnIndex.h"
|
||||||
|
|
||||||
namespace milvus::query {
|
namespace milvus::query {
|
||||||
|
|
||||||
static faiss::ConcurrentBitsetPtr
|
|
||||||
create_bitmap_view(std::optional<const BitmapSimple*> bitmaps_opt, int64_t chunk_id) {
|
|
||||||
if (!bitmaps_opt.has_value()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
auto& bitmaps = *bitmaps_opt.value();
|
|
||||||
auto src_vec = ~bitmaps.at(chunk_id);
|
|
||||||
auto dst = std::make_shared<faiss::ConcurrentBitset>(src_vec.size());
|
|
||||||
auto iter = reinterpret_cast<BitmapChunk::block_type*>(dst->mutable_data());
|
|
||||||
boost::to_block_range(src_vec, iter);
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status
|
Status
|
||||||
FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
||||||
const query::QueryInfo& info,
|
const query::QueryInfo& info,
|
||||||
|
|||||||
@ -17,8 +17,8 @@
|
|||||||
#include "query/SubQueryResult.h"
|
#include "query/SubQueryResult.h"
|
||||||
|
|
||||||
namespace milvus::query {
|
namespace milvus::query {
|
||||||
using BitmapChunk = boost::dynamic_bitset<>;
|
using BitsetChunk = boost::dynamic_bitset<>;
|
||||||
using BitmapSimple = std::deque<BitmapChunk>;
|
using BitsetSimple = std::deque<BitsetChunk>;
|
||||||
|
|
||||||
void
|
void
|
||||||
SearchOnGrowing(const segcore::SegmentGrowingImpl& segment,
|
SearchOnGrowing(const segcore::SegmentGrowingImpl& segment,
|
||||||
|
|||||||
@ -17,32 +17,34 @@
|
|||||||
#include <knowhere/index/vector_index/VecIndex.h>
|
#include <knowhere/index/vector_index/VecIndex.h>
|
||||||
#include "knowhere/index/vector_index/helpers/IndexParameter.h"
|
#include "knowhere/index/vector_index/helpers/IndexParameter.h"
|
||||||
#include "knowhere/index/vector_index/adapter/VectorAdapter.h"
|
#include "knowhere/index/vector_index/adapter/VectorAdapter.h"
|
||||||
|
#include <boost_ext/dynamic_bitset_ext.hpp>
|
||||||
|
|
||||||
namespace milvus::query {
|
namespace milvus::query {
|
||||||
|
|
||||||
// negate bitset, and merge them into one
|
// negate bitset, and merge them into one
|
||||||
aligned_vector<uint8_t>
|
aligned_vector<uint8_t>
|
||||||
AssembleNegBitmap(const BitmapSimple& bitmap_simple) {
|
AssembleNegBitset(const BitsetSimple& bitset_simple) {
|
||||||
int64_t N = 0;
|
int64_t N = 0;
|
||||||
|
|
||||||
for (auto& bitmap : bitmap_simple) {
|
for (auto& bitset : bitset_simple) {
|
||||||
N += bitmap.size();
|
N += bitset.size();
|
||||||
}
|
}
|
||||||
aligned_vector<uint8_t> result(upper_align(upper_div(N, 8), sizeof(BitmapChunk::block_type)));
|
aligned_vector<uint8_t> result(upper_align(upper_div(N, 8), 64));
|
||||||
|
|
||||||
auto acc_byte_count = 0;
|
auto acc_byte_count = 0;
|
||||||
for (auto& bitmap_raw : bitmap_simple) {
|
for (auto& bitset : bitset_simple) {
|
||||||
auto bitmap = ~bitmap_raw;
|
auto size = bitset.size();
|
||||||
auto size = bitmap.size();
|
|
||||||
Assert(size % 8 == 0);
|
Assert(size % 8 == 0);
|
||||||
auto byte_count = size / 8;
|
auto byte_count = size / 8;
|
||||||
|
auto src_ptr = boost_ext::get_data(bitset);
|
||||||
auto iter = reinterpret_cast<BitmapChunk::block_type*>(result.data() + acc_byte_count);
|
memcpy(result.data() + acc_byte_count, src_ptr, byte_count);
|
||||||
boost::to_block_range(bitmap, iter);
|
|
||||||
|
|
||||||
acc_byte_count += byte_count;
|
acc_byte_count += byte_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// revert the bitset
|
||||||
|
for (int64_t i = 0; i < result.size(); ++i) {
|
||||||
|
result[i] = ~result[i];
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
namespace milvus::query {
|
namespace milvus::query {
|
||||||
|
|
||||||
aligned_vector<uint8_t>
|
aligned_vector<uint8_t>
|
||||||
AssembleNegBitmap(const BitmapSimple& bitmap_simple);
|
AssembleNegBitset(const BitsetSimple& bitmap_simple);
|
||||||
|
|
||||||
void
|
void
|
||||||
SearchOnSealed(const Schema& schema,
|
SearchOnSealed(const Schema& schema,
|
||||||
|
|||||||
@ -80,7 +80,7 @@ ExecPlanNodeVisitor::VectorVisitorImpl(VectorPlanNode& node) {
|
|||||||
|
|
||||||
if (node.predicate_.has_value()) {
|
if (node.predicate_.has_value()) {
|
||||||
ExecExprVisitor::RetType expr_ret = ExecExprVisitor(*segment, row_count).call_child(*node.predicate_.value());
|
ExecExprVisitor::RetType expr_ret = ExecExprVisitor(*segment, row_count).call_child(*node.predicate_.value());
|
||||||
bitset_holder = AssembleNegBitmap(expr_ret);
|
bitset_holder = AssembleNegBitset(expr_ret);
|
||||||
view = BitsetView(bitset_holder.data(), bitset_holder.size() * 8);
|
view = BitsetView(bitset_holder.data(), bitset_holder.size() * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
internal/core/thirdparty/CMakeLists.txt
vendored
1
internal/core/thirdparty/CMakeLists.txt
vendored
@ -55,3 +55,4 @@ endif()
|
|||||||
|
|
||||||
add_subdirectory( protobuf )
|
add_subdirectory( protobuf )
|
||||||
add_subdirectory( fiu )
|
add_subdirectory( fiu )
|
||||||
|
add_subdirectory( boost_ext )
|
||||||
|
|||||||
2
internal/core/thirdparty/boost_ext/CMakeLists.txt
vendored
Normal file
2
internal/core/thirdparty/boost_ext/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
find_package(Boost REQUIRED)
|
||||||
|
add_library(boost_bitset_ext dynamic_bitset_ext.cpp)
|
||||||
21
internal/core/thirdparty/boost_ext/LICENSE
vendored
Normal file
21
internal/core/thirdparty/boost_ext/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 FluorineDog
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
63
internal/core/thirdparty/boost_ext/dynamic_bitset_ext.cpp
vendored
Normal file
63
internal/core/thirdparty/boost_ext/dynamic_bitset_ext.cpp
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include "dynamic_bitset_ext.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct PtrWrapper {
|
||||||
|
explicit PtrWrapper(char*& ptr) : ptr_(ptr) {}
|
||||||
|
char*& ptr_;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ConstPtrWrapper {
|
||||||
|
explicit ConstPtrWrapper(const char*& ptr) : ptr_(ptr) {}
|
||||||
|
const char*& ptr_;
|
||||||
|
};
|
||||||
|
|
||||||
|
using Block = unsigned long;
|
||||||
|
using Allocator = std::allocator<Block>;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
// a language lawyer's way to steal original pointer from boost::dynamic_bitset
|
||||||
|
// salute to http://www.gotw.ca/gotw/076.htm
|
||||||
|
template<>
|
||||||
|
void
|
||||||
|
from_block_range<PtrWrapper, Block, Allocator>(PtrWrapper result,
|
||||||
|
PtrWrapper resultB,
|
||||||
|
dynamic_bitset<>& bitset) {
|
||||||
|
(void)resultB;
|
||||||
|
result.ptr_ = reinterpret_cast<char*>(bitset.m_bits.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
void
|
||||||
|
to_block_range<Block, Allocator, ConstPtrWrapper>(const dynamic_bitset<>& bitset,
|
||||||
|
ConstPtrWrapper result) {
|
||||||
|
result.ptr_ = reinterpret_cast<const char*>(bitset.m_bits.data());
|
||||||
|
}
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost_ext {
|
||||||
|
|
||||||
|
char*
|
||||||
|
get_data(boost::dynamic_bitset<>& bitset) {
|
||||||
|
char* ptr = nullptr;
|
||||||
|
PtrWrapper wrapper{ptr};
|
||||||
|
boost::from_block_range(wrapper, wrapper, bitset);
|
||||||
|
assert(ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
get_data(const boost::dynamic_bitset<>& bitset) {
|
||||||
|
const char* ptr = nullptr;
|
||||||
|
ConstPtrWrapper wrapper{ptr};
|
||||||
|
boost::to_block_range(bitset, wrapper);
|
||||||
|
assert(ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace boost_ext
|
||||||
6
internal/core/thirdparty/boost_ext/dynamic_bitset_ext.hpp
vendored
Normal file
6
internal/core/thirdparty/boost_ext/dynamic_bitset_ext.hpp
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <boost/dynamic_bitset.hpp>
|
||||||
|
|
||||||
|
namespace boost_ext {
|
||||||
|
const char* get_data(const boost::dynamic_bitset<>& bitset);
|
||||||
|
char* get_data(boost::dynamic_bitset<>& bitset);
|
||||||
|
} // namespace boost_ext
|
||||||
Loading…
x
Reference in New Issue
Block a user