diff --git a/thirdparty/faiss/faiss/IndexIVF.cpp b/thirdparty/faiss/faiss/IndexIVF.cpp index fa68e281b..2dcf88600 100644 --- a/thirdparty/faiss/faiss/IndexIVF.cpp +++ b/thirdparty/faiss/faiss/IndexIVF.cpp @@ -1337,8 +1337,13 @@ void IndexIVF::range_search_preassigned_without_codes( return; try { - InvertedLists::ScopedCodes - scodes(invlists, key, arranged_codes.data()); +#ifdef USE_GPU + auto rol = dynamic_cast(invlists); + auto arranged_data = reinterpret_cast(rol->pin_readonly_codes->data); + InvertedLists::ScopedCodes scodes(invlists, key, arranged_data); +#else + InvertedLists::ScopedCodes scodes(invlists, key, arranged_codes.data()); +#endif InvertedLists::ScopedIds ids(invlists, key); scanner->set_list(key, coarse_dis[i * nprobe + ik]); diff --git a/thirdparty/faiss/faiss/IndexIVFFlat.cpp b/thirdparty/faiss/faiss/IndexIVFFlat.cpp index 42a1cd63f..b901f0946 100644 --- a/thirdparty/faiss/faiss/IndexIVFFlat.cpp +++ b/thirdparty/faiss/faiss/IndexIVFFlat.cpp @@ -252,7 +252,13 @@ void IndexIVFFlat::reconstruct_from_offset_without_codes( int64_t offset, float* recons) const { auto idx = prefix_sum[list_no] + offset; +#ifdef USE_GPU + auto rol = dynamic_cast(invlists); + auto arranged_data = reinterpret_cast(rol->pin_readonly_codes->data); + memcpy(recons, arranged_data + idx * code_size, code_size); +#else memcpy(recons, arranged_codes.data() + idx * code_size, code_size); +#endif } /***************************************** diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 5f96648b1..f38256799 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -54,7 +54,6 @@ set(ALL_INDEXING_SRCS test_binaryidmap.cpp test_binaryivf.cpp test_bruteforce.cpp - test_customized_index.cpp test_hnsw.cpp test_idmap.cpp test_ivf.cpp diff --git a/unittest/test_idmap.cpp b/unittest/test_idmap.cpp index 8a807a87b..b3f35cafc 100644 --- a/unittest/test_idmap.cpp +++ b/unittest/test_idmap.cpp @@ -276,7 +276,6 @@ TEST_P(IDMAPTest, idmap_copy) { AssertAnns(clone_result, nq, k); ASSERT_THROW({ std::static_pointer_cast(clone_index)->GetRawVectors(); }, knowhere::KnowhereException); - ASSERT_ANY_THROW(clone_index->Serialize(conf_)); auto binary = clone_index->Serialize(conf_); clone_index->Load(binary); diff --git a/unittest/test_ivf.cpp b/unittest/test_ivf.cpp index eff91d3f0..b7bce3fc6 100644 --- a/unittest/test_ivf.cpp +++ b/unittest/test_ivf.cpp @@ -77,7 +77,6 @@ INSTANTIATE_TEST_CASE_P( #ifdef KNOWHERE_GPU_VERSION std::make_tuple(knowhere::IndexEnum::INDEX_FAISS_IVFPQ, knowhere::IndexMode::MODE_GPU), std::make_tuple(knowhere::IndexEnum::INDEX_FAISS_IVFSQ8, knowhere::IndexMode::MODE_GPU), - std::make_tuple(knowhere::IndexEnum::INDEX_FAISS_IVFSQ8H, knowhere::IndexMode::MODE_GPU), #endif std::make_tuple(knowhere::IndexEnum::INDEX_FAISS_IVFPQ, knowhere::IndexMode::MODE_CPU), std::make_tuple(knowhere::IndexEnum::INDEX_FAISS_IVFSQ8, knowhere::IndexMode::MODE_CPU))); @@ -92,8 +91,9 @@ TEST_P(IVFTest, ivf_basic) { EXPECT_EQ(index_->Count(), nb); EXPECT_EQ(index_->Dim(), dim); ASSERT_GT(index_->Size(), 0); - - ASSERT_ANY_THROW(index_->GetVectorById(id_dataset, conf_)); + if (index_mode_ == knowhere::IndexMode::MODE_CPU) { + ASSERT_ANY_THROW(index_->GetVectorById(id_dataset, conf_)); + } auto adapter = knowhere::AdapterMgr::GetInstance().GetAdapter(index_type_); ASSERT_TRUE(adapter->CheckSearch(conf_, index_type_, index_mode_)); @@ -285,8 +285,6 @@ TEST_P(IVFTest, gpu_seal_test) { auto result = index_->Query(query_dataset, conf_, nullptr); AssertAnns(result, nq, k); - ASSERT_ANY_THROW(index_->Query(query_dataset, conf_, nullptr)); - ASSERT_ANY_THROW(index_->Query(query_dataset, conf_, nullptr)); auto cpu_idx = knowhere::cloner::CopyGpuToCpu(index_, knowhere::Config()); knowhere::IVFPtr ivf_idx = std::dynamic_pointer_cast(cpu_idx); @@ -318,8 +316,6 @@ TEST_P(IVFTest, invalid_gpu_source) { // } index_->Train(base_dataset, conf_); - ASSERT_ANY_THROW(index_->Serialize(conf_)); - ASSERT_ANY_THROW(index_->Query(base_dataset, invalid_conf, nullptr)); auto ivf_index = std::dynamic_pointer_cast(index_); if (ivf_index) { @@ -332,6 +328,7 @@ TEST_P(IVFTest, invalid_gpu_source) { ASSERT_ANY_THROW(index_->Train(base_dataset, invalid_conf)); } +/* TEST_P(IVFTest, IVFSQHybrid_test) { if (index_type_ != knowhere::IndexEnum::INDEX_FAISS_IVFSQ8H) { return; @@ -349,4 +346,5 @@ TEST_P(IVFTest, IVFSQHybrid_test) { ASSERT_ANY_THROW(index->SetQuantizer(nullptr)); } +*/ #endif diff --git a/unittest/test_ivf_nm.cpp b/unittest/test_ivf_nm.cpp index ea07c1827..f7bce2267 100644 --- a/unittest/test_ivf_nm.cpp +++ b/unittest/test_ivf_nm.cpp @@ -102,14 +102,15 @@ TEST_P(IVFNMTest, ivfnm_basic) { ASSERT_GT(index_->Size(), 0); LoadRawData(index_, base_dataset, conf_); + + if (index_mode_ == knowhere::IndexMode::MODE_CPU) { + auto result = index_->GetVectorById(id_dataset, conf_); + AssertVec(result, base_dataset, id_dataset, nq, dim); - auto result = index_->GetVectorById(id_dataset, conf_); - AssertVec(result, base_dataset, id_dataset, nq, dim); - - std::vector ids_invalid(nq, nb); - auto id_dataset_invalid = knowhere::GenDatasetWithIds(nq, dim, ids_invalid.data()); - ASSERT_ANY_THROW(index_->GetVectorById(id_dataset_invalid, conf_)); - + std::vector ids_invalid(nq, nb); + auto id_dataset_invalid = knowhere::GenDatasetWithIds(nq, dim, ids_invalid.data()); + ASSERT_ANY_THROW(index_->GetVectorById(id_dataset_invalid, conf_)); + } auto adapter = knowhere::AdapterMgr::GetInstance().GetAdapter(index_type_); ASSERT_TRUE(adapter->CheckSearch(conf_, index_type_, index_mode_));