提交 af1900b4 编写于 作者: F FluorineDog 提交者: yefu.chen

Remove ConcurrentBitsetPtr in segcore

Signed-off-by: NFluorineDog <guilin.gou@zilliz.com>
上级 455cc59d
......@@ -18,4 +18,4 @@ set(MILVUS_QUERY_SRCS
SubQueryResult.cpp
)
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"
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
FloatSearch(const segcore::SegmentGrowingImpl& segment,
const query::QueryInfo& info,
......
......@@ -17,8 +17,8 @@
#include "query/SubQueryResult.h"
namespace milvus::query {
using BitmapChunk = boost::dynamic_bitset<>;
using BitmapSimple = std::deque<BitmapChunk>;
using BitsetChunk = boost::dynamic_bitset<>;
using BitsetSimple = std::deque<BitsetChunk>;
void
SearchOnGrowing(const segcore::SegmentGrowingImpl& segment,
......
......@@ -17,32 +17,34 @@
#include <knowhere/index/vector_index/VecIndex.h>
#include "knowhere/index/vector_index/helpers/IndexParameter.h"
#include "knowhere/index/vector_index/adapter/VectorAdapter.h"
#include <boost_ext/dynamic_bitset_ext.hpp>
namespace milvus::query {
// negate bitset, and merge them into one
aligned_vector<uint8_t>
AssembleNegBitmap(const BitmapSimple& bitmap_simple) {
AssembleNegBitset(const BitsetSimple& bitset_simple) {
int64_t N = 0;
for (auto& bitmap : bitmap_simple) {
N += bitmap.size();
for (auto& bitset : bitset_simple) {
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;
for (auto& bitmap_raw : bitmap_simple) {
auto bitmap = ~bitmap_raw;
auto size = bitmap.size();
for (auto& bitset : bitset_simple) {
auto size = bitset.size();
Assert(size % 8 == 0);
auto byte_count = size / 8;
auto iter = reinterpret_cast<BitmapChunk::block_type*>(result.data() + acc_byte_count);
boost::to_block_range(bitmap, iter);
auto src_ptr = boost_ext::get_data(bitset);
memcpy(result.data() + acc_byte_count, src_ptr, 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;
}
......
......@@ -18,7 +18,7 @@
namespace milvus::query {
aligned_vector<uint8_t>
AssembleNegBitmap(const BitmapSimple& bitmap_simple);
AssembleNegBitset(const BitsetSimple& bitmap_simple);
void
SearchOnSealed(const Schema& schema,
......
......@@ -80,7 +80,7 @@ ExecPlanNodeVisitor::VectorVisitorImpl(VectorPlanNode& node) {
if (node.predicate_.has_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);
}
......
......@@ -55,3 +55,4 @@ endif()
add_subdirectory( protobuf )
add_subdirectory( fiu )
add_subdirectory( boost_ext )
find_package(Boost REQUIRED)
add_library(boost_bitset_ext dynamic_bitset_ext.cpp)
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.
#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
#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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册