Unverified Commit a05ec6a9 authored by 蔡宇东's avatar 蔡宇东 Committed by GitHub
Browse files

Caiyd 1885 optimize knowhere ut (#1889)



* optimize knowhere unittest

Signed-off-by: default avataryudong.cai <yudong.cai@zilliz.com>

* code clean

Signed-off-by: default avataryudong.cai <yudong.cai@zilliz.com>

* optimize knowhere util

Signed-off-by: default avataryudong.cai <yudong.cai@zilliz.com>

* fix clang-format

Signed-off-by: default avataryudong.cai <yudong.cai@zilliz.com>

* update changelog

Signed-off-by: default avataryudong.cai <yudong.cai@zilliz.com>

* fix unittest build error

Signed-off-by: default avataryudong.cai <yudong.cai@zilliz.com>

* retry CI

Signed-off-by: default avataryudong.cai <yudong.cai@zilliz.com>

Co-authored-by: default avatarJin Hai <hai.jin@zilliz.com>
parent 354f29a0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -24,10 +24,12 @@ Please mark all change in change log and use the issue from GitHub
-   \#1784 Add Substructure and Superstructure in http module
-   \#1858 Disable S3 build
-   \#1882 Add index annoy into http module
-   \#1885 Optimize knowhere unittest
-   \#1886 Refactor log on search and insert request

## Task


# Milvus 0.7.1 (2020-03-29)

## Bug
+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ struct MemoryIOWriter : public faiss::IOWriter {
    template <typename T>
    size_t
    write(T* ptr, size_t size, size_t nitems = 1) {
        operator()((const void*)ptr, size, nitems);
        return operator()((const void*)ptr, size, nitems);
    }
};

@@ -42,7 +42,7 @@ struct MemoryIOReader : public faiss::IOReader {
    template <typename T>
    size_t
    read(T* ptr, size_t size, size_t nitems = 1) {
        operator()((void*)ptr, size, nitems);
        return operator()((void*)ptr, size, nitems);
    }
};

+95 −60
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ set(basic_libs

set(util_srcs
        ${MILVUS_THIRDPARTY_SRC}/easyloggingpp/easylogging++.cc
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/adapter/VectorAdapter.cpp
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/helpers/FaissIO.cpp
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/helpers/IndexParameter.cpp
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexType.cpp
@@ -51,8 +52,7 @@ if (KNOWHERE_GPU_VERSION)
            )
endif ()

#<IVF-TEST>
set(ivf_srcs
set(faiss_srcs
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/FaissBaseIndex.cpp
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/FaissBaseBinaryIndex.cpp
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexBinaryIDMAP.cpp
@@ -63,7 +63,7 @@ set(ivf_srcs
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexIVFPQ.cpp
        )
if (KNOWHERE_GPU_VERSION)
    set(ivf_srcs ${ivf_srcs}
set(faiss_srcs ${faiss_srcs}
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/helpers/Cloner.cpp
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/gpu/IndexGPUIDMAP.cpp
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp
@@ -72,49 +72,104 @@ if (KNOWHERE_GPU_VERSION)
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp
        )
endif ()

################################################################################
#<INSTRUCTIONSET-TEST>
if (NOT TARGET test_instructionset)
    add_executable(test_instructionset test_instructionset.cpp)
endif ()
target_link_libraries(test_instructionset ${depend_libs} ${unittest_libs})

################################################################################
#<KNOWHERE-COMMON-TEST>
if (NOT TARGET test_knowhere_common)
    add_executable(test_knowhere_common test_common.cpp ${util_srcs})
endif ()
target_link_libraries(test_knowhere_common ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_knowhere_common DESTINATION unittest)

if (KNOWHERE_GPU_VERSION)
################################################################################
#<GPU-RESOURCE-TEST>
add_executable(test_gpuresource test_gpuresource.cpp ${util_srcs} ${faiss_srcs})
target_link_libraries(test_gpuresource ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_gpuresource DESTINATION unittest)

################################################################################
#<CUSTOMIZED-INDEX-TEST>
add_executable(test_customized_index test_customized_index.cpp ${util_srcs} ${faiss_srcs})
target_link_libraries(test_customized_index ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_customized_index DESTINATION unittest)
endif ()

################################################################################
#<IDMAP-TEST>
if (NOT TARGET test_idmap)
    add_executable(test_idmap test_idmap.cpp ${faiss_srcs} ${util_srcs})
endif ()
target_link_libraries(test_idmap ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_idmap DESTINATION unittest)

################################################################################
#<IVF-TEST>
if (NOT TARGET test_ivf)
    add_executable(test_ivf test_ivf.cpp ${ivf_srcs} ${util_srcs})
    add_executable(test_ivf test_ivf.cpp ${faiss_srcs} ${util_srcs})
endif ()
target_link_libraries(test_ivf ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_ivf DESTINATION unittest)

################################################################################
#<BinaryIDMAP-TEST>
if (NOT TARGET test_binaryidmap)
    add_executable(test_binaryidmap test_binaryidmap.cpp ${faiss_srcs} ${util_srcs})
endif ()
target_link_libraries(test_binaryidmap ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_binaryidmap DESTINATION unittest)

################################################################################
#<BinaryIVF-TEST>
if (NOT TARGET test_binaryivf)
    add_executable(test_binaryivf test_binaryivf.cpp ${ivf_srcs} ${util_srcs})
    add_executable(test_binaryivf test_binaryivf.cpp ${faiss_srcs} ${util_srcs})
endif ()
target_link_libraries(test_binaryivf ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_binaryivf DESTINATION unittest)


#<IDMAP-TEST>
if (NOT TARGET test_idmap)
    add_executable(test_idmap test_idmap.cpp ${ivf_srcs} ${util_srcs})
################################################################################
#<NSG-TEST>
add_definitions(-std=c++11 -O3 -lboost -march=native -Wall -DINFO)

find_package(OpenMP REQUIRED)
if (OpenMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else ()
    message(FATAL_ERROR "no OpenMP supprot")
endif ()
target_link_libraries(test_idmap ${depend_libs} ${unittest_libs} ${basic_libs})

#<ANNOY-TEST>
set(annoy_srcs
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexAnnoy.cpp
include_directories(${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/impl/nsg)
aux_source_directory(${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/impl/nsg nsg_src)
set(interface_src
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexNSG.cpp
        )

if (NOT TARGET test_annoy)
    add_executable(test_annoy test_annoy.cpp ${annoy_srcs} ${util_srcs})
if (NOT TARGET test_nsg)
    add_executable(test_nsg test_nsg.cpp ${interface_src} ${nsg_src} ${util_srcs} ${faiss_srcs})
endif ()
target_link_libraries(test_annoy ${depend_libs} ${unittest_libs} ${basic_libs})
target_link_libraries(test_nsg ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_nsg DESTINATION unittest)

################################################################################
#<HNSW-TEST>
set(hnsw_srcs
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexHNSW.cpp
        )

if (NOT TARGET test_hnsw)
    add_executable(test_hnsw test_hnsw.cpp ${hnsw_srcs} ${util_srcs})
endif ()
target_link_libraries(test_hnsw ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_hnsw DESTINATION unittest)

#<BinaryIDMAP-TEST>
if (NOT TARGET test_binaryidmap)
    add_executable(test_binaryidmap test_binaryidmap.cpp ${ivf_srcs} ${util_srcs})
endif ()
target_link_libraries(test_binaryidmap ${depend_libs} ${unittest_libs} ${basic_libs})

################################################################################
#<SPTAG-TEST>
set(sptag_srcs
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/adapter/SptagAdapter.cpp
@@ -127,40 +182,20 @@ endif ()
target_link_libraries(test_sptag
        SPTAGLibStatic
        ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_sptag DESTINATION unittest)

if (KNOWHERE_GPU_VERSION)
    add_executable(test_gpuresource test_gpuresource.cpp ${util_srcs} ${ivf_srcs})
    target_link_libraries(test_gpuresource ${depend_libs} ${unittest_libs} ${basic_libs})

    add_executable(test_customized_index test_customized_index.cpp ${util_srcs} ${ivf_srcs})
    target_link_libraries(test_customized_index ${depend_libs} ${unittest_libs} ${basic_libs})
endif ()

#<INSTRUCTIONSET-TEST>
if (NOT TARGET test_instructionset)
    add_executable(test_instructionset test_instructionset.cpp)
endif ()
target_link_libraries(test_instructionset ${depend_libs} ${unittest_libs})

if (NOT TARGET test_knowhere_common)
    add_executable(test_knowhere_common test_common.cpp ${util_srcs})
################################################################################
#<ANNOY-TEST>
set(annoy_srcs
        ${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexAnnoy.cpp
        )
if (NOT TARGET test_annoy)
    add_executable(test_annoy test_annoy.cpp ${annoy_srcs} ${util_srcs})
endif ()
target_link_libraries(test_knowhere_common ${depend_libs} ${unittest_libs} ${basic_libs})

install(TARGETS test_ivf DESTINATION unittest)
install(TARGETS test_hnsw DESTINATION unittest)
install(TARGETS test_binaryivf DESTINATION unittest)
install(TARGETS test_idmap DESTINATION unittest)
install(TARGETS test_binaryidmap DESTINATION unittest)
install(TARGETS test_sptag DESTINATION unittest)
install(TARGETS test_knowhere_common DESTINATION unittest)
target_link_libraries(test_annoy ${depend_libs} ${unittest_libs} ${basic_libs})
install(TARGETS test_annoy DESTINATION unittest)

if (KNOWHERE_GPU_VERSION)
    install(TARGETS test_gpuresource DESTINATION unittest)
    install(TARGETS test_customized_index DESTINATION unittest)
endif ()

#add_subdirectory(faiss_ori)
#add_subdirectory(faiss_benchmark)
add_subdirectory(test_nsg)
+2 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ IndexFactory(const milvus::knowhere::IndexType& type, const milvus::knowhere::In
        }
#endif
    }
    return nullptr;
}

class ParamGenerator {
@@ -109,6 +110,7 @@ class ParamGenerator {
        } else {
            std::cout << "Invalid index type " << type << std::endl;
        }
        return milvus::knowhere::Config();
    }
};

+3 −3
Original line number Diff line number Diff line
@@ -21,11 +21,11 @@ using ::testing::Combine;
using ::testing::TestWithParam;
using ::testing::Values;

class BinaryIDMAPTest : public BinaryDataGen, public TestWithParam<std::string> {
class BinaryIDMAPTest : public DataGen, public TestWithParam<std::string> {
 protected:
    void
    SetUp() override {
        Init_with_binary_default();
        Init_with_default(true);
        index_ = std::make_shared<milvus::knowhere::BinaryIDMAP>();
    }

@@ -40,7 +40,7 @@ INSTANTIATE_TEST_CASE_P(METRICParameters, BinaryIDMAPTest,
                        Values(std::string("JACCARD"), std::string("TANIMOTO"), std::string("HAMMING")));

TEST_P(BinaryIDMAPTest, binaryidmap_basic) {
    ASSERT_TRUE(!xb.empty());
    ASSERT_TRUE(!xb_bin.empty());

    std::string MetricType = GetParam();
    milvus::knowhere::Config conf{
Loading