mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-30 23:45:28 +08:00
Merge branch 'merge_knowhere' into 'branch-0.4.0'
MS-442 merge knowhere See merge request megasearch/milvus!450 Former-commit-id: da835b7093f62e3ac9d3c65b92d13607acee2283
This commit is contained in:
commit
288dbd899c
@ -67,6 +67,7 @@ Please mark all change in change log and use the ticket from JIRA.
|
||||
- MS-422 - Support DeleteTask in Multi-GpuResource case
|
||||
- MS-428 - Add PushTaskByDataLocality in scheduler
|
||||
- MS-440 - Add DumpTaskTables in sdk
|
||||
- MS-442 - Merge Knowhere
|
||||
|
||||
## New Feature
|
||||
- MS-343 - Implement ResourceMgr
|
||||
|
||||
@ -10,7 +10,7 @@ DB_PATH="/opt/milvus"
|
||||
PROFILING="OFF"
|
||||
BUILD_FAISS_WITH_MKL="OFF"
|
||||
USE_JFROG_CACHE="OFF"
|
||||
KNOWHERE_BUILD_DIR="`pwd`/thirdparty/knowhere/cmake_build"
|
||||
KNOWHERE_BUILD_DIR="`pwd`/src/core/cmake_build"
|
||||
|
||||
while getopts "p:d:t:k:uhlrcgmj" arg
|
||||
do
|
||||
|
||||
1
cpp/src/core/.gitignore
vendored
Normal file
1
cpp/src/core/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
cmake_build
|
||||
75
cpp/src/core/CMakeLists.txt
Normal file
75
cpp/src/core/CMakeLists.txt
Normal file
@ -0,0 +1,75 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
# Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
# Proprietary and confidential.
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
message(STATUS "Building using CMake version: ${CMAKE_VERSION}")
|
||||
|
||||
set(KNOWHERE_VERSION "0.1.0")
|
||||
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" KNOWHERE_BASE_VERSION "${KNOWHERE_VERSION}")
|
||||
project(knowhere VERSION "${KNOWHERE_BASE_VERSION}" LANGUAGES CUDA C CXX)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
set(KNOWHERE_VERSION_MAJOR "${knowhere_VERSION_MAJOR}")
|
||||
set(KNOWHERE_VERSION_MINOR "${knowhere_VERSION_MINOR}")
|
||||
set(KNOWHERE_VERSION_PATCH "${knowhere_VERSION_PATCH}")
|
||||
if(KNOWHERE_VERSION_MAJOR STREQUAL ""
|
||||
OR KNOWHERE_VERSION_MINOR STREQUAL ""
|
||||
OR KNOWHERE_VERSION_PATCH STREQUAL "")
|
||||
message(FATAL_ERROR "Failed to determine Knowhere version from '${KNOWHERE_VERSION}'")
|
||||
endif()
|
||||
|
||||
message(STATUS "Knowhere version: "
|
||||
"${KNOWHERE_VERSION_MAJOR}.${KNOWHERE_VERSION_MINOR}.${KNOWHERE_VERSION_PATCH} "
|
||||
"(full: '${KNOWHERE_VERSION}')")
|
||||
|
||||
# if no build build type is specified, default to release builds
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif(NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -fopenmp")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fPIC -fopenmp")
|
||||
endif()
|
||||
MESSAGE(STATUS "CMAKE_CXX_FLAGS" ${CMAKE_CXX_FLAGS})
|
||||
|
||||
find_package(CUDA)
|
||||
#set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -fPIC -std=c++11 -D_FORCE_INLINES --expt-extended-lambda")
|
||||
#set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O0 -g")
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
|
||||
message("building milvus_engine on x86 architecture")
|
||||
set(KNOWHERE_BUILD_ARCH x86_64)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(ppc)")
|
||||
message("building milvus_engine on ppc architecture")
|
||||
set(KNOWHERE_BUILD_ARCH ppc64le)
|
||||
else()
|
||||
message("unknown processor type")
|
||||
message("CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
|
||||
set(KNOWHERE_BUILD_ARCH unknown)
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(BUILD_TYPE "release")
|
||||
else()
|
||||
set(BUILD_TYPE "debug")
|
||||
endif()
|
||||
message(STATUS "Build type = ${BUILD_TYPE}")
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
include(ExternalProject)
|
||||
include(DefineOptions)
|
||||
include(BuildUtils)
|
||||
include(ThirdPartyPackages)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
if(BUILD_UNIT_TEST STREQUAL "ON")
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
config_summary()
|
||||
88
cpp/src/core/build.sh
Executable file
88
cpp/src/core/build.sh
Executable file
@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
|
||||
BUILD_TYPE="Debug"
|
||||
BUILD_UNITTEST="OFF"
|
||||
INSTALL_PREFIX=$(pwd)/cmake_build
|
||||
MAKE_CLEAN="OFF"
|
||||
PROFILING="OFF"
|
||||
BUILD_FAISS_WITH_MKL="OFF"
|
||||
USE_JFROG_CACHE="OFF"
|
||||
|
||||
while getopts "p:d:t:uhrcgmj" arg
|
||||
do
|
||||
case $arg in
|
||||
t)
|
||||
BUILD_TYPE=$OPTARG # BUILD_TYPE
|
||||
;;
|
||||
u)
|
||||
echo "Build and run unittest cases" ;
|
||||
BUILD_UNITTEST="ON";
|
||||
;;
|
||||
p)
|
||||
INSTALL_PREFIX=$OPTARG
|
||||
;;
|
||||
r)
|
||||
if [[ -d cmake_build ]]; then
|
||||
rm ./cmake_build -r
|
||||
MAKE_CLEAN="ON"
|
||||
fi
|
||||
;;
|
||||
g)
|
||||
PROFILING="ON"
|
||||
;;
|
||||
m)
|
||||
BUILD_FAISS_WITH_MKL="ON"
|
||||
;;
|
||||
j)
|
||||
USE_JFROG_CACHE="ON"
|
||||
;;
|
||||
h) # help
|
||||
echo "
|
||||
|
||||
parameter:
|
||||
-t: build type(default: Debug)
|
||||
-u: building unit test options(default: OFF)
|
||||
-p: install prefix(default: $(pwd)/knowhere)
|
||||
-r: remove previous build directory(default: OFF)
|
||||
-g: profiling(default: OFF)
|
||||
-m: build faiss with MKL(default: OFF)
|
||||
|
||||
usage:
|
||||
./build.sh -t \${BUILD_TYPE} [-u] [-h] [-g] [-r] [-c] [-m]
|
||||
"
|
||||
exit 0
|
||||
;;
|
||||
?)
|
||||
echo "unknown argument"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ! -d cmake_build ]]; then
|
||||
mkdir cmake_build
|
||||
MAKE_CLEAN="ON"
|
||||
fi
|
||||
|
||||
cd cmake_build
|
||||
|
||||
CUDA_COMPILER=/usr/local/cuda/bin/nvcc
|
||||
|
||||
if [[ ${MAKE_CLEAN} == "ON" ]]; then
|
||||
CMAKE_CMD="cmake -DBUILD_UNIT_TEST=${BUILD_UNITTEST} \
|
||||
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}
|
||||
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
|
||||
-DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} \
|
||||
-DMILVUS_ENABLE_PROFILING=${PROFILING} \
|
||||
-DBUILD_FAISS_WITH_MKL=${BUILD_FAISS_WITH_MKL} \
|
||||
-DUSE_JFROG_CACHE=${USE_JFROG_CACHE} \
|
||||
../"
|
||||
echo ${CMAKE_CMD}
|
||||
|
||||
${CMAKE_CMD}
|
||||
make clean
|
||||
fi
|
||||
|
||||
make -j 8 || exit 1
|
||||
|
||||
make install || exit 1
|
||||
199
cpp/src/core/cmake/BuildUtils.cmake
Normal file
199
cpp/src/core/cmake/BuildUtils.cmake
Normal file
@ -0,0 +1,199 @@
|
||||
# Define a function that check last file modification
|
||||
function(Check_Last_Modify cache_check_lists_file_path working_dir last_modified_commit_id)
|
||||
if(EXISTS "${working_dir}")
|
||||
if(EXISTS "${cache_check_lists_file_path}")
|
||||
set(GIT_LOG_SKIP_NUM 0)
|
||||
set(_MATCH_ALL ON CACHE BOOL "Match all")
|
||||
set(_LOOP_STATUS ON CACHE BOOL "Whether out of loop")
|
||||
file(STRINGS ${cache_check_lists_file_path} CACHE_IGNORE_TXT)
|
||||
while(_LOOP_STATUS)
|
||||
foreach(_IGNORE_ENTRY ${CACHE_IGNORE_TXT})
|
||||
if(NOT _IGNORE_ENTRY MATCHES "^[^#]+")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
set(_MATCH_ALL OFF)
|
||||
execute_process(COMMAND git log --no-merges -1 --skip=${GIT_LOG_SKIP_NUM} --name-status --pretty= WORKING_DIRECTORY ${working_dir} OUTPUT_VARIABLE CHANGE_FILES)
|
||||
if(NOT CHANGE_FILES STREQUAL "")
|
||||
string(REPLACE "\n" ";" _CHANGE_FILES ${CHANGE_FILES})
|
||||
foreach(_FILE_ENTRY ${_CHANGE_FILES})
|
||||
string(REGEX MATCH "[^ \t]+$" _FILE_NAME ${_FILE_ENTRY})
|
||||
execute_process(COMMAND sh -c "echo ${_FILE_NAME} | grep ${_IGNORE_ENTRY}" RESULT_VARIABLE return_code)
|
||||
if (return_code EQUAL 0)
|
||||
execute_process(COMMAND git log --no-merges -1 --skip=${GIT_LOG_SKIP_NUM} --pretty=%H WORKING_DIRECTORY ${working_dir} OUTPUT_VARIABLE LAST_MODIFIED_COMMIT_ID)
|
||||
set (${last_modified_commit_id} ${LAST_MODIFIED_COMMIT_ID} PARENT_SCOPE)
|
||||
set(_LOOP_STATUS OFF)
|
||||
endif()
|
||||
endforeach()
|
||||
else()
|
||||
set(_LOOP_STATUS OFF)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(_MATCH_ALL)
|
||||
execute_process(COMMAND git log --no-merges -1 --skip=${GIT_LOG_SKIP_NUM} --pretty=%H WORKING_DIRECTORY ${working_dir} OUTPUT_VARIABLE LAST_MODIFIED_COMMIT_ID)
|
||||
set (${last_modified_commit_id} ${LAST_MODIFIED_COMMIT_ID} PARENT_SCOPE)
|
||||
set(_LOOP_STATUS OFF)
|
||||
endif()
|
||||
|
||||
math(EXPR GIT_LOG_SKIP_NUM "${GIT_LOG_SKIP_NUM} + 1")
|
||||
endwhile(_LOOP_STATUS)
|
||||
else()
|
||||
execute_process(COMMAND git log --no-merges -1 --skip=${GIT_LOG_SKIP_NUM} --pretty=%H WORKING_DIRECTORY ${working_dir} OUTPUT_VARIABLE LAST_MODIFIED_COMMIT_ID)
|
||||
set (${last_modified_commit_id} ${LAST_MODIFIED_COMMIT_ID} PARENT_SCOPE)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "The directory ${working_dir} does not exist")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Define a function that extracts a cached package
|
||||
function(ExternalProject_Use_Cache project_name package_file install_path)
|
||||
message(STATUS "Will use cached package file: ${package_file}")
|
||||
|
||||
ExternalProject_Add(${project_name}
|
||||
DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"No download step needed (using cached package)"
|
||||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"No configure step needed (using cached package)"
|
||||
BUILD_COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"No build step needed (using cached package)"
|
||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"No install step needed (using cached package)"
|
||||
)
|
||||
|
||||
# We want our tar files to contain the Install/<package> prefix (not for any
|
||||
# very special reason, only for consistency and so that we can identify them
|
||||
# in the extraction logs) which means that we must extract them in the
|
||||
# binary (top-level build) directory to have them installed in the right
|
||||
# place for subsequent ExternalProjects to pick them up. It seems that the
|
||||
# only way to control the working directory is with Add_Step!
|
||||
ExternalProject_Add_Step(${project_name} extract
|
||||
ALWAYS 1
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E echo
|
||||
"Extracting ${package_file} to ${install_path}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E tar xzvf ${package_file} ${install_path}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
ExternalProject_Add_StepTargets(${project_name} extract)
|
||||
endfunction()
|
||||
|
||||
# Define a function that to create a new cached package
|
||||
function(ExternalProject_Create_Cache project_name package_file install_path cache_username cache_password cache_path)
|
||||
if(EXISTS ${package_file})
|
||||
message(STATUS "Removing existing package file: ${package_file}")
|
||||
file(REMOVE ${package_file})
|
||||
endif()
|
||||
|
||||
message(STATUS "Will create cached package file: ${package_file}")
|
||||
|
||||
ExternalProject_Add_Step(${project_name} package
|
||||
DEPENDEES install
|
||||
BYPRODUCTS ${package_file}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Updating cached package file: ${package_file}"
|
||||
COMMAND ${CMAKE_COMMAND} -E tar czvf ${package_file} ${install_path}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Uploading package file ${package_file} to ${cache_path}"
|
||||
COMMAND curl -u${cache_username}:${cache_password} -T ${package_file} ${cache_path}
|
||||
)
|
||||
|
||||
ExternalProject_Add_StepTargets(${project_name} package)
|
||||
endfunction()
|
||||
|
||||
function(ADD_THIRDPARTY_LIB LIB_NAME)
|
||||
set(options)
|
||||
set(one_value_args SHARED_LIB STATIC_LIB)
|
||||
set(multi_value_args DEPS INCLUDE_DIRECTORIES)
|
||||
cmake_parse_arguments(ARG
|
||||
"${options}"
|
||||
"${one_value_args}"
|
||||
"${multi_value_args}"
|
||||
${ARGN})
|
||||
if(ARG_UNPARSED_ARGUMENTS)
|
||||
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
|
||||
if(ARG_STATIC_LIB AND ARG_SHARED_LIB)
|
||||
if(NOT ARG_STATIC_LIB)
|
||||
message(FATAL_ERROR "No static or shared library provided for ${LIB_NAME}")
|
||||
endif()
|
||||
|
||||
set(AUG_LIB_NAME "${LIB_NAME}_static")
|
||||
add_library(${AUG_LIB_NAME} STATIC IMPORTED)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES IMPORTED_LOCATION "${ARG_STATIC_LIB}")
|
||||
if(ARG_DEPS)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES INTERFACE_LINK_LIBRARIES "${ARG_DEPS}")
|
||||
endif()
|
||||
message(STATUS "Added static library dependency ${AUG_LIB_NAME}: ${ARG_STATIC_LIB}")
|
||||
if(ARG_INCLUDE_DIRECTORIES)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${ARG_INCLUDE_DIRECTORIES}")
|
||||
endif()
|
||||
|
||||
set(AUG_LIB_NAME "${LIB_NAME}_shared")
|
||||
add_library(${AUG_LIB_NAME} SHARED IMPORTED)
|
||||
|
||||
if(WIN32)
|
||||
# Mark the ".lib" location as part of a Windows DLL
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES IMPORTED_IMPLIB "${ARG_SHARED_LIB}")
|
||||
else()
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES IMPORTED_LOCATION "${ARG_SHARED_LIB}")
|
||||
endif()
|
||||
if(ARG_DEPS)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES INTERFACE_LINK_LIBRARIES "${ARG_DEPS}")
|
||||
endif()
|
||||
message(STATUS "Added shared library dependency ${AUG_LIB_NAME}: ${ARG_SHARED_LIB}")
|
||||
if(ARG_INCLUDE_DIRECTORIES)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${ARG_INCLUDE_DIRECTORIES}")
|
||||
endif()
|
||||
elseif(ARG_STATIC_LIB)
|
||||
set(AUG_LIB_NAME "${LIB_NAME}_static")
|
||||
add_library(${AUG_LIB_NAME} STATIC IMPORTED)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES IMPORTED_LOCATION "${ARG_STATIC_LIB}")
|
||||
if(ARG_DEPS)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES INTERFACE_LINK_LIBRARIES "${ARG_DEPS}")
|
||||
endif()
|
||||
message(STATUS "Added static library dependency ${AUG_LIB_NAME}: ${ARG_STATIC_LIB}")
|
||||
if(ARG_INCLUDE_DIRECTORIES)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${ARG_INCLUDE_DIRECTORIES}")
|
||||
endif()
|
||||
elseif(ARG_SHARED_LIB)
|
||||
set(AUG_LIB_NAME "${LIB_NAME}_shared")
|
||||
add_library(${AUG_LIB_NAME} SHARED IMPORTED)
|
||||
|
||||
if(WIN32)
|
||||
# Mark the ".lib" location as part of a Windows DLL
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES IMPORTED_IMPLIB "${ARG_SHARED_LIB}")
|
||||
else()
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES IMPORTED_LOCATION "${ARG_SHARED_LIB}")
|
||||
endif()
|
||||
message(STATUS "Added shared library dependency ${AUG_LIB_NAME}: ${ARG_SHARED_LIB}")
|
||||
if(ARG_DEPS)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES INTERFACE_LINK_LIBRARIES "${ARG_DEPS}")
|
||||
endif()
|
||||
if(ARG_INCLUDE_DIRECTORIES)
|
||||
set_target_properties(${AUG_LIB_NAME}
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${ARG_INCLUDE_DIRECTORIES}")
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "No static or shared library provided for ${LIB_NAME}")
|
||||
endif()
|
||||
endfunction()
|
||||
164
cpp/src/core/cmake/DefineOptions.cmake
Normal file
164
cpp/src/core/cmake/DefineOptions.cmake
Normal file
@ -0,0 +1,164 @@
|
||||
|
||||
macro(set_option_category name)
|
||||
set(KNOWHERE_OPTION_CATEGORY ${name})
|
||||
list(APPEND "KNOWHERE_OPTION_CATEGORIES" ${name})
|
||||
endmacro()
|
||||
|
||||
macro(define_option name description default)
|
||||
option(${name} ${description} ${default})
|
||||
list(APPEND "KNOWHERE_${KNOWHERE_OPTION_CATEGORY}_OPTION_NAMES" ${name})
|
||||
set("${name}_OPTION_DESCRIPTION" ${description})
|
||||
set("${name}_OPTION_DEFAULT" ${default})
|
||||
set("${name}_OPTION_TYPE" "bool")
|
||||
endmacro()
|
||||
|
||||
function(list_join lst glue out)
|
||||
if("${${lst}}" STREQUAL "")
|
||||
set(${out} "" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
list(GET ${lst} 0 joined)
|
||||
list(REMOVE_AT ${lst} 0)
|
||||
foreach(item ${${lst}})
|
||||
set(joined "${joined}${glue}${item}")
|
||||
endforeach()
|
||||
set(${out} ${joined} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
macro(define_option_string name description default)
|
||||
set(${name} ${default} CACHE STRING ${description})
|
||||
list(APPEND "KNOWHERE_${KNOWHERE_OPTION_CATEGORY}_OPTION_NAMES" ${name})
|
||||
set("${name}_OPTION_DESCRIPTION" ${description})
|
||||
set("${name}_OPTION_DEFAULT" "\"${default}\"")
|
||||
set("${name}_OPTION_TYPE" "string")
|
||||
|
||||
set("${name}_OPTION_ENUM" ${ARGN})
|
||||
list_join("${name}_OPTION_ENUM" "|" "${name}_OPTION_ENUM")
|
||||
if(NOT ("${${name}_OPTION_ENUM}" STREQUAL ""))
|
||||
set_property(CACHE ${name} PROPERTY STRINGS ${ARGN})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
set_option_category("Thirdparty")
|
||||
|
||||
set(KNOWHERE_DEPENDENCY_SOURCE_DEFAULT "AUTO")
|
||||
|
||||
define_option_string(KNOWHERE_DEPENDENCY_SOURCE
|
||||
"Method to use for acquiring KNOWHERE's build dependencies"
|
||||
"${KNOWHERE_DEPENDENCY_SOURCE_DEFAULT}"
|
||||
"AUTO"
|
||||
"BUNDLED"
|
||||
"SYSTEM")
|
||||
|
||||
define_option(KNOWHERE_VERBOSE_THIRDPARTY_BUILD
|
||||
"Show output from ExternalProjects rather than just logging to files" ON)
|
||||
|
||||
define_option(KNOWHERE_BOOST_USE_SHARED "Rely on boost shared libraries where relevant" OFF)
|
||||
|
||||
define_option(KNOWHERE_BOOST_VENDORED "Use vendored Boost instead of existing Boost. \
|
||||
Note that this requires linking Boost statically" OFF)
|
||||
|
||||
define_option(KNOWHERE_BOOST_HEADER_ONLY "Use only BOOST headers" OFF)
|
||||
|
||||
define_option(KNOWHERE_WITH_ARROW "Build with ARROW" ON)
|
||||
|
||||
define_option(KNOWHERE_WITH_LAPACK "Build with LAPACK library" ON)
|
||||
|
||||
define_option(KNOWHERE_WITH_FAISS "Build with FAISS library" ON)
|
||||
|
||||
define_option(KNOWHERE_WITH_FAISS_GPU_VERSION "Build with FAISS GPU version" ON)
|
||||
|
||||
define_option(KNOWHERE_WITH_OPENBLAS "Build with OpenBLAS library" ON)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
if(MSVC)
|
||||
set_option_category("MSVC")
|
||||
|
||||
define_option(MSVC_LINK_VERBOSE
|
||||
"Pass verbose linking options when linking libraries and executables"
|
||||
OFF)
|
||||
|
||||
define_option(KNOWHERE_USE_STATIC_CRT "Build KNOWHERE with statically linked CRT" OFF)
|
||||
endif()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
set_option_category("Test and benchmark")
|
||||
|
||||
if (BUILD_UNIT_TEST)
|
||||
define_option(KNOWHERE_BUILD_TESTS "Build the KNOWHERE googletest unit tests" ON)
|
||||
else()
|
||||
define_option(KNOWHERE_BUILD_TESTS "Build the KNOWHERE googletest unit tests" OFF)
|
||||
endif(BUILD_UNIT_TEST)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
macro(config_summary)
|
||||
message(STATUS "---------------------------------------------------------------------")
|
||||
message(STATUS "KNOWHERE version: ${KNOWHERE_VERSION}")
|
||||
message(STATUS)
|
||||
message(STATUS "Build configuration summary:")
|
||||
|
||||
message(STATUS " Generator: ${CMAKE_GENERATOR}")
|
||||
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
|
||||
message(STATUS " Source directory: ${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
if(${CMAKE_EXPORT_COMPILE_COMMANDS})
|
||||
message(
|
||||
STATUS " Compile commands: ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json")
|
||||
endif()
|
||||
|
||||
foreach(category ${KNOWHERE_OPTION_CATEGORIES})
|
||||
|
||||
message(STATUS)
|
||||
message(STATUS "${category} options:")
|
||||
|
||||
set(option_names ${KNOWHERE_${category}_OPTION_NAMES})
|
||||
|
||||
set(max_value_length 0)
|
||||
foreach(name ${option_names})
|
||||
string(LENGTH "\"${${name}}\"" value_length)
|
||||
if(${max_value_length} LESS ${value_length})
|
||||
set(max_value_length ${value_length})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(name ${option_names})
|
||||
if("${${name}_OPTION_TYPE}" STREQUAL "string")
|
||||
set(value "\"${${name}}\"")
|
||||
else()
|
||||
set(value "${${name}}")
|
||||
endif()
|
||||
|
||||
set(default ${${name}_OPTION_DEFAULT})
|
||||
set(description ${${name}_OPTION_DESCRIPTION})
|
||||
string(LENGTH ${description} description_length)
|
||||
if(${description_length} LESS 70)
|
||||
string(
|
||||
SUBSTRING
|
||||
" "
|
||||
${description_length} -1 description_padding)
|
||||
else()
|
||||
set(description_padding "
|
||||
")
|
||||
endif()
|
||||
|
||||
set(comment "[${name}]")
|
||||
|
||||
if("${value}" STREQUAL "${default}")
|
||||
set(comment "[default] ${comment}")
|
||||
endif()
|
||||
|
||||
if(NOT ("${${name}_OPTION_ENUM}" STREQUAL ""))
|
||||
set(comment "${comment} [${${name}_OPTION_ENUM}]")
|
||||
endif()
|
||||
|
||||
string(
|
||||
SUBSTRING "${value} "
|
||||
0 ${max_value_length} value)
|
||||
|
||||
message(STATUS " ${description} ${description_padding} ${value} ${comment}")
|
||||
endforeach()
|
||||
|
||||
endforeach()
|
||||
|
||||
endmacro()
|
||||
1017
cpp/src/core/cmake/ThirdPartyPackages.cmake
Normal file
1017
cpp/src/core/cmake/ThirdPartyPackages.cmake
Normal file
File diff suppressed because it is too large
Load Diff
18
cpp/src/core/include/knowhere/adapter/arrow.h
Normal file
18
cpp/src/core/include/knowhere/adapter/arrow.h
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <knowhere/common/array.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
ArrayPtr
|
||||
CopyArray(const ArrayPtr &origin);
|
||||
|
||||
SchemaPtr
|
||||
CopySchema(const SchemaPtr &origin);
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
20
cpp/src/core/include/knowhere/adapter/faiss_adopt.h
Normal file
20
cpp/src/core/include/knowhere/adapter/faiss_adopt.h
Normal file
@ -0,0 +1,20 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
#define GETTENSOR(dataset) \
|
||||
auto tensor = dataset->tensor()[0]; \
|
||||
auto p_data = tensor->raw_data(); \
|
||||
auto dim = tensor->shape()[1]; \
|
||||
auto rows = tensor->shape()[0]; \
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
24
cpp/src/core/include/knowhere/adapter/sptag.h
Normal file
24
cpp/src/core/include/knowhere/adapter/sptag.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <knowhere/common/dataset.h>
|
||||
#include <SPTAG/AnnService/inc/Core/VectorIndex.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
std::shared_ptr<SPTAG::VectorSet>
|
||||
ConvertToVectorSet(const DatasetPtr &dataset);
|
||||
|
||||
std::shared_ptr<SPTAG::MetadataSet>
|
||||
ConvertToMetadataSet(const DatasetPtr &dataset);
|
||||
|
||||
std::vector<SPTAG::QueryResult>
|
||||
ConvertToQueryResult(const DatasetPtr &dataset, const Config &config);
|
||||
|
||||
DatasetPtr
|
||||
ConvertToDataset(std::vector<SPTAG::QueryResult> query_results);
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
42
cpp/src/core/include/knowhere/adapter/structure.h
Normal file
42
cpp/src/core/include/knowhere/adapter/structure.h
Normal file
@ -0,0 +1,42 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <knowhere/common/dataset.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
extern ArrayPtr
|
||||
ConstructInt64ArraySmart(uint8_t *data, int64_t size);
|
||||
|
||||
extern ArrayPtr
|
||||
ConstructFloatArraySmart(uint8_t *data, int64_t size);
|
||||
|
||||
extern TensorPtr
|
||||
ConstructFloatTensorSmart(uint8_t *data, int64_t size, std::vector<int64_t> shape);
|
||||
|
||||
extern ArrayPtr
|
||||
ConstructInt64Array(uint8_t *data, int64_t size);
|
||||
|
||||
extern ArrayPtr
|
||||
ConstructFloatArray(uint8_t *data, int64_t size);
|
||||
|
||||
extern TensorPtr
|
||||
ConstructFloatTensor(uint8_t *data, int64_t size, std::vector<int64_t> shape);
|
||||
|
||||
extern FieldPtr
|
||||
ConstructInt64Field(const std::string &name);
|
||||
|
||||
extern FieldPtr
|
||||
ConstructFloatField(const std::string &name);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
35
cpp/src/core/include/knowhere/common/array.h
Normal file
35
cpp/src/core/include/knowhere/common/array.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "arrow/array.h"
|
||||
#include "knowhere/common/schema.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
using ArrayData = arrow::ArrayData;
|
||||
using ArrayDataPtr = std::shared_ptr<ArrayData>;
|
||||
|
||||
using Array = arrow::Array;
|
||||
using ArrayPtr = std::shared_ptr<Array>;
|
||||
|
||||
using BooleanArray = arrow::BooleanArray;
|
||||
using BooleanArrayPtr = std::shared_ptr<arrow::BooleanArray>;
|
||||
|
||||
template<typename DType>
|
||||
using NumericArray = arrow::NumericArray<DType>;
|
||||
template<typename DType>
|
||||
using NumericArrayPtr = std::shared_ptr<arrow::NumericArray<DType>>;
|
||||
|
||||
using BinaryArray = arrow::BinaryArray;
|
||||
using BinaryArrayPtr = std::shared_ptr<arrow::BinaryArray>;
|
||||
|
||||
using FixedSizeBinaryArray = arrow::FixedSizeBinaryArray;
|
||||
using FixedSizeBinaryArrayPtr = std::shared_ptr<arrow::FixedSizeBinaryArray>;
|
||||
|
||||
using Decimal128Array = arrow::Decimal128Array;
|
||||
using Decimal128ArrayPtr = std::shared_ptr<arrow::Decimal128Array>;
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
62
cpp/src/core/include/knowhere/common/binary_set.h
Normal file
62
cpp/src/core/include/knowhere/common/binary_set.h
Normal file
@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "knowhere/common/id.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
struct Binary {
|
||||
ID id;
|
||||
std::shared_ptr<uint8_t> data;
|
||||
int64_t size = 0;
|
||||
};
|
||||
using BinaryPtr = std::shared_ptr<Binary>;
|
||||
|
||||
|
||||
class BinarySet {
|
||||
public:
|
||||
BinaryPtr
|
||||
GetByName(const std::string &name) const {
|
||||
return binary_map_.at(name);
|
||||
}
|
||||
|
||||
void
|
||||
Append(const std::string &name, BinaryPtr binary) {
|
||||
binary_map_[name] = std::move(binary);
|
||||
}
|
||||
|
||||
void
|
||||
Append(const std::string &name, std::shared_ptr<uint8_t> data, int64_t size) {
|
||||
auto binary = std::make_shared<Binary>();
|
||||
binary->data = data;
|
||||
binary->size = size;
|
||||
binary_map_[name] = std::move(binary);
|
||||
}
|
||||
|
||||
//void
|
||||
//Append(const std::string &name, void *data, int64_t size, ID id) {
|
||||
// Binary binary;
|
||||
// binary.data = data;
|
||||
// binary.size = size;
|
||||
// binary.id = id;
|
||||
// binary_map_[name] = binary;
|
||||
//}
|
||||
|
||||
void clear() {
|
||||
binary_map_.clear();
|
||||
}
|
||||
|
||||
public:
|
||||
std::map<std::string, BinaryPtr> binary_map_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
45
cpp/src/core/include/knowhere/common/buffer.h
Normal file
45
cpp/src/core/include/knowhere/common/buffer.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "arrow/buffer.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
using Buffer = arrow::Buffer;
|
||||
using BufferPtr = std::shared_ptr<Buffer>;
|
||||
using MutableBuffer = arrow::MutableBuffer;
|
||||
using MutableBufferPtr = std::shared_ptr<MutableBuffer>;
|
||||
|
||||
namespace internal {
|
||||
|
||||
struct BufferDeleter {
|
||||
void operator()(Buffer *buffer) {
|
||||
free((void *) buffer->data());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
inline BufferPtr
|
||||
MakeBufferSmart(uint8_t *data, const int64_t size) {
|
||||
return BufferPtr(new Buffer(data, size), internal::BufferDeleter());
|
||||
}
|
||||
|
||||
inline MutableBufferPtr
|
||||
MakeMutableBufferSmart(uint8_t *data, const int64_t size) {
|
||||
return MutableBufferPtr(new MutableBuffer(data, size), internal::BufferDeleter());
|
||||
}
|
||||
|
||||
inline BufferPtr
|
||||
MakeBuffer(uint8_t *data, const int64_t size) {
|
||||
return std::make_shared<Buffer>(data, size);
|
||||
}
|
||||
|
||||
inline MutableBufferPtr
|
||||
MakeMutableBuffer(uint8_t *data, const int64_t size) {
|
||||
return std::make_shared<MutableBuffer>(data, size);
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
14
cpp/src/core/include/knowhere/common/config.h
Normal file
14
cpp/src/core/include/knowhere/common/config.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <jsoncons/json.hpp>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
using Config = jsoncons::json;
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
122
cpp/src/core/include/knowhere/common/dataset.h
Normal file
122
cpp/src/core/include/knowhere/common/dataset.h
Normal file
@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "knowhere/common/array.h"
|
||||
#include "knowhere/common/buffer.h"
|
||||
#include "knowhere/common/tensor.h"
|
||||
#include "knowhere/common/schema.h"
|
||||
#include "knowhere/common/config.h"
|
||||
#include "knowhere/adapter/arrow.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
class Dataset;
|
||||
|
||||
using DatasetPtr = std::shared_ptr<Dataset>;
|
||||
|
||||
class Dataset {
|
||||
public:
|
||||
Dataset() = default;
|
||||
|
||||
Dataset(std::vector<ArrayPtr> &&array, SchemaPtr array_schema,
|
||||
std::vector<TensorPtr> &&tensor, SchemaPtr tensor_schema)
|
||||
: array_(std::move(array)),
|
||||
array_schema_(std::move(array_schema)),
|
||||
tensor_(std::move(tensor)),
|
||||
tensor_schema_(std::move(tensor_schema)) {}
|
||||
|
||||
Dataset(std::vector<ArrayPtr> array, SchemaPtr array_schema)
|
||||
: array_(std::move(array)), array_schema_(std::move(array_schema)) {}
|
||||
|
||||
Dataset(std::vector<TensorPtr> tensor, SchemaPtr tensor_schema)
|
||||
: tensor_(std::move(tensor)), tensor_schema_(std::move(tensor_schema)) {}
|
||||
|
||||
Dataset(const Dataset &) = delete;
|
||||
Dataset &operator=(const Dataset &) = delete;
|
||||
|
||||
DatasetPtr
|
||||
Clone() {
|
||||
auto dataset = std::make_shared<Dataset>();
|
||||
|
||||
std::vector<ArrayPtr> clone_array;
|
||||
for (auto &array : array_) {
|
||||
clone_array.emplace_back(CopyArray(array));
|
||||
}
|
||||
dataset->set_array(clone_array);
|
||||
|
||||
std::vector<TensorPtr> clone_tensor;
|
||||
for (auto &tensor : tensor_) {
|
||||
auto buffer = tensor->data();
|
||||
std::shared_ptr<Buffer> copy_buffer;
|
||||
// TODO: checkout copy success;
|
||||
buffer->Copy(0, buffer->size(), ©_buffer);
|
||||
auto copy = std::make_shared<Tensor>(tensor->type(), copy_buffer, tensor->shape());
|
||||
clone_tensor.emplace_back(copy);
|
||||
}
|
||||
dataset->set_tensor(clone_tensor);
|
||||
|
||||
if (array_schema_)
|
||||
dataset->set_array_schema(CopySchema(array_schema_));
|
||||
if (tensor_schema_)
|
||||
dataset->set_tensor_schema(CopySchema(tensor_schema_));
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
public:
|
||||
const std::vector<ArrayPtr> &
|
||||
array() const { return array_; }
|
||||
|
||||
void
|
||||
set_array(std::vector<ArrayPtr> array) {
|
||||
array_ = std::move(array);
|
||||
}
|
||||
|
||||
const std::vector<TensorPtr> &
|
||||
tensor() const { return tensor_; }
|
||||
|
||||
void
|
||||
set_tensor(std::vector<TensorPtr> tensor) {
|
||||
tensor_ = std::move(tensor);
|
||||
}
|
||||
|
||||
SchemaConstPtr
|
||||
array_schema() const { return array_schema_; }
|
||||
|
||||
void
|
||||
set_array_schema(SchemaPtr array_schema) {
|
||||
array_schema_ = std::move(array_schema);
|
||||
}
|
||||
|
||||
SchemaConstPtr
|
||||
tensor_schema() const { return tensor_schema_; }
|
||||
|
||||
void
|
||||
set_tensor_schema(SchemaPtr tensor_schema) {
|
||||
tensor_schema_ = std::move(tensor_schema);
|
||||
}
|
||||
|
||||
//const Config &
|
||||
//meta() const { return meta_; }
|
||||
|
||||
//void
|
||||
//set_meta(Config meta) {
|
||||
// meta_ = std::move(meta);
|
||||
//}
|
||||
|
||||
private:
|
||||
SchemaPtr array_schema_;
|
||||
SchemaPtr tensor_schema_;
|
||||
std::vector<ArrayPtr> array_;
|
||||
std::vector<TensorPtr> tensor_;
|
||||
//Config meta_;
|
||||
};
|
||||
|
||||
using DatasetPtr = std::shared_ptr<Dataset>;
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
10
cpp/src/core/include/knowhere/common/device_type.h
Normal file
10
cpp/src/core/include/knowhere/common/device_type.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace sched {
|
||||
namespace master {
|
||||
|
||||
} // namespace master
|
||||
} // namespace sched
|
||||
} // namespace zilliz
|
||||
40
cpp/src/core/include/knowhere/common/error.h
Normal file
40
cpp/src/core/include/knowhere/common/error.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "zlibrary/error/error.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
using Error = zilliz::lib::ErrorCode;
|
||||
|
||||
constexpr Error STORE_SUCCESS = zilliz::lib::SUCCESS_CODE;
|
||||
|
||||
constexpr Error ERROR_CODE_BASE = 0x36000;
|
||||
constexpr Error ERROR_CODE_END = 0x37000;
|
||||
|
||||
constexpr Error
|
||||
ToGlobalErrorCode(const Error error_code) {
|
||||
return zilliz::lib::ToGlobalErrorCode(error_code, ERROR_CODE_BASE);
|
||||
}
|
||||
|
||||
class Exception : public zilliz::lib::Exception {
|
||||
public:
|
||||
Exception(const Error error_code,
|
||||
const std::string &message = nullptr)
|
||||
: zilliz::lib::Exception(error_code, "KNOWHERE", message) {}
|
||||
};
|
||||
|
||||
constexpr Error UNEXPECTED = ToGlobalErrorCode(0x001);
|
||||
constexpr Error UNSUPPORTED = ToGlobalErrorCode(0x002);
|
||||
constexpr Error NULL_POINTER = ToGlobalErrorCode(0x003);
|
||||
constexpr Error OVERFLOW = ToGlobalErrorCode(0x004);
|
||||
constexpr Error INVALID_ARGUMENT = ToGlobalErrorCode(0x005);
|
||||
constexpr Error UNSUPPORTED_TYPE = ToGlobalErrorCode(0x006);
|
||||
|
||||
|
||||
} // namespace store
|
||||
} // namespace zilliz
|
||||
|
||||
using Error = zilliz::store::Error;
|
||||
45
cpp/src/core/include/knowhere/common/exception.h
Normal file
45
cpp/src/core/include/knowhere/common/exception.h
Normal file
@ -0,0 +1,45 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
class KnowhereException : public std::exception {
|
||||
public:
|
||||
explicit KnowhereException(const std::string &msg);
|
||||
|
||||
KnowhereException(const std::string &msg, const char *funName,
|
||||
const char *file, int line);
|
||||
|
||||
const char *what() const noexcept override;
|
||||
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
|
||||
#define KNOWHERE_THROW_MSG(MSG)\
|
||||
do {\
|
||||
throw KnowhereException(MSG, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
|
||||
} while (false)
|
||||
|
||||
#define KNOHERE_THROW_FORMAT(FMT, ...)\
|
||||
do { \
|
||||
std::string __s;\
|
||||
int __size = snprintf(nullptr, 0, FMT, __VA_ARGS__);\
|
||||
__s.resize(__size + 1);\
|
||||
snprintf(&__s[0], __s.size(), FMT, __VA_ARGS__);\
|
||||
throw faiss::FaissException(__s, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
|
||||
} while (false)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
42
cpp/src/core/include/knowhere/common/id.h
Normal file
42
cpp/src/core/include/knowhere/common/id.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
//#include "zcommon/id/id.h"
|
||||
//using ID = zilliz::common::ID;
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
|
||||
class ID {
|
||||
public:
|
||||
constexpr static int64_t kIDSize = 20;
|
||||
|
||||
public:
|
||||
const int32_t *
|
||||
data() const { return content_; }
|
||||
|
||||
int32_t *
|
||||
mutable_data() { return content_; }
|
||||
|
||||
bool
|
||||
IsValid() const;
|
||||
|
||||
std::string
|
||||
ToString() const;
|
||||
|
||||
bool
|
||||
operator==(const ID &that) const;
|
||||
|
||||
bool
|
||||
operator<(const ID &that) const;
|
||||
|
||||
protected:
|
||||
int32_t content_[5] = {};
|
||||
};
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
21
cpp/src/core/include/knowhere/common/schema.h
Normal file
21
cpp/src/core/include/knowhere/common/schema.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "arrow/type.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
using DataType = arrow::DataType;
|
||||
using Field = arrow::Field;
|
||||
using FieldPtr = std::shared_ptr<arrow::Field>;
|
||||
using Schema = arrow::Schema;
|
||||
using SchemaPtr = std::shared_ptr<Schema>;
|
||||
using SchemaConstPtr = std::shared_ptr<const Schema>;
|
||||
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
16
cpp/src/core/include/knowhere/common/tensor.h
Normal file
16
cpp/src/core/include/knowhere/common/tensor.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "arrow/tensor.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
using Tensor = arrow::Tensor;
|
||||
using TensorPtr = std::shared_ptr<Tensor>;
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
41
cpp/src/core/include/knowhere/common/timer.h
Normal file
41
cpp/src/core/include/knowhere/common/timer.h
Normal file
@ -0,0 +1,41 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
class TimeRecorder {
|
||||
using stdclock = std::chrono::high_resolution_clock;
|
||||
|
||||
public:
|
||||
TimeRecorder(const std::string &header,
|
||||
int64_t log_level = 0);
|
||||
|
||||
~TimeRecorder();//trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5
|
||||
|
||||
double RecordSection(const std::string &msg);
|
||||
|
||||
double ElapseFromBegin(const std::string &msg);
|
||||
|
||||
static std::string GetTimeSpanStr(double span);
|
||||
|
||||
private:
|
||||
void PrintTimeRecord(const std::string &msg, double span);
|
||||
|
||||
private:
|
||||
std::string header_;
|
||||
stdclock::time_point start_;
|
||||
stdclock::time_point last_;
|
||||
int64_t log_level_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
49
cpp/src/core/include/knowhere/index/index.h
Normal file
49
cpp/src/core/include/knowhere/index/index.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "knowhere/common/binary_set.h"
|
||||
#include "knowhere/common/dataset.h"
|
||||
#include "knowhere/index/index_type.h"
|
||||
#include "knowhere/index/index_model.h"
|
||||
#include "knowhere/index/preprocessor/preprocessor.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
class Index {
|
||||
public:
|
||||
virtual BinarySet
|
||||
Serialize() = 0;
|
||||
|
||||
virtual void
|
||||
Load(const BinarySet &index_binary) = 0;
|
||||
|
||||
// @throw
|
||||
virtual DatasetPtr
|
||||
Search(const DatasetPtr &dataset, const Config &config) = 0;
|
||||
|
||||
public:
|
||||
IndexType
|
||||
idx_type() const { return idx_type_; }
|
||||
|
||||
void
|
||||
set_idx_type(IndexType idx_type) { idx_type_ = idx_type; }
|
||||
|
||||
virtual void
|
||||
set_preprocessor(PreprocessorPtr preprocessor) {}
|
||||
|
||||
virtual void
|
||||
set_index_model(IndexModelPtr model) {}
|
||||
|
||||
private:
|
||||
IndexType idx_type_;
|
||||
};
|
||||
|
||||
|
||||
using IndexPtr = std::shared_ptr<Index>;
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
24
cpp/src/core/include/knowhere/index/index_model.h
Normal file
24
cpp/src/core/include/knowhere/index/index_model.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "knowhere/common/binary_set.h"
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
class IndexModel {
|
||||
public:
|
||||
virtual BinarySet
|
||||
Serialize() = 0;
|
||||
|
||||
virtual void
|
||||
Load(const BinarySet &binary) = 0;
|
||||
};
|
||||
|
||||
using IndexModelPtr = std::shared_ptr<IndexModel>;
|
||||
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
17
cpp/src/core/include/knowhere/index/index_type.h
Normal file
17
cpp/src/core/include/knowhere/index/index_type.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
enum class IndexType {
|
||||
kUnknown = 0,
|
||||
kVecIdxBegin = 100,
|
||||
kVecIVFFlat = kVecIdxBegin,
|
||||
kVecIdxEnd,
|
||||
};
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
26
cpp/src/core/include/knowhere/index/preprocessor/normalize.h
Normal file
26
cpp/src/core/include/knowhere/index/preprocessor/normalize.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "preprocessor.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
class NormalizePreprocessor : public Preprocessor {
|
||||
public:
|
||||
DatasetPtr
|
||||
Preprocess(const DatasetPtr &input) override;
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
Normalize(float *arr, int64_t dimension);
|
||||
};
|
||||
|
||||
|
||||
using NormalizePreprocessorPtr = std::shared_ptr<NormalizePreprocessor>;
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "knowhere/common/dataset.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
class Preprocessor {
|
||||
public:
|
||||
virtual DatasetPtr
|
||||
Preprocess(const DatasetPtr &input) = 0;
|
||||
};
|
||||
|
||||
|
||||
using PreprocessorPtr = std::shared_ptr<Preprocessor>;
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
23
cpp/src/core/include/knowhere/index/vector_index/cloner.h
Normal file
23
cpp/src/core/include/knowhere/index/vector_index/cloner.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
* Proprietary and confidential.
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "vector_index.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
// TODO(linxj): rename CopyToGpu
|
||||
extern VectorIndexPtr
|
||||
CopyCpuToGpu(const VectorIndexPtr &index, const int64_t &device_id, const Config &config);
|
||||
|
||||
extern VectorIndexPtr
|
||||
CopyGpuToCpu(const VectorIndexPtr &index, const Config &config);
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include "knowhere/index/vector_index/vector_index.h"
|
||||
#include "knowhere/index/index_model.h"
|
||||
#include <SPTAG/AnnService/inc/Core/VectorIndex.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
class CPUKDTRNG : public VectorIndex {
|
||||
public:
|
||||
CPUKDTRNG() {
|
||||
index_ptr_ = SPTAG::VectorIndex::CreateInstance(SPTAG::IndexAlgoType::KDT,
|
||||
SPTAG::VectorValueType::Float);
|
||||
index_ptr_->SetParameter("DistCalcMethod", "L2");
|
||||
}
|
||||
|
||||
public:
|
||||
BinarySet
|
||||
Serialize() override;
|
||||
VectorIndexPtr Clone() override;
|
||||
void
|
||||
Load(const BinarySet &index_array) override;
|
||||
|
||||
public:
|
||||
PreprocessorPtr
|
||||
BuildPreprocessor(const DatasetPtr &dataset, const Config &config) override;
|
||||
int64_t Count() override;
|
||||
int64_t Dimension() override;
|
||||
|
||||
IndexModelPtr
|
||||
Train(const DatasetPtr &dataset, const Config &config) override;
|
||||
|
||||
void
|
||||
Add(const DatasetPtr &dataset, const Config &config) override;
|
||||
|
||||
DatasetPtr
|
||||
Search(const DatasetPtr &dataset, const Config &config) override;
|
||||
void Seal() override;
|
||||
private:
|
||||
void
|
||||
SetParameters(const Config &config);
|
||||
|
||||
private:
|
||||
PreprocessorPtr preprocessor_;
|
||||
std::shared_ptr<SPTAG::VectorIndex> index_ptr_;
|
||||
};
|
||||
|
||||
using CPUKDTRNGPtr = std::shared_ptr<CPUKDTRNG>;
|
||||
|
||||
class CPUKDTRNGIndexModel : public IndexModel {
|
||||
public:
|
||||
BinarySet
|
||||
Serialize() override;
|
||||
|
||||
void
|
||||
Load(const BinarySet &binary) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<SPTAG::VectorIndex> index_;
|
||||
};
|
||||
|
||||
using CPUKDTRNGIndexModelPtr = std::shared_ptr<CPUKDTRNGIndexModel>;
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
#define META_ROWS ("rows")
|
||||
#define META_DIM ("dimension")
|
||||
#define META_K ("k")
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
132
cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h
Normal file
132
cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h
Normal file
@ -0,0 +1,132 @@
|
||||
#pragma once
|
||||
|
||||
#include <faiss/gpu/StandardGpuResources.h>
|
||||
|
||||
#include "ivf.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
class FaissGpuResourceMgr {
|
||||
public:
|
||||
struct DeviceParams {
|
||||
int64_t temp_mem_size = 0;
|
||||
int64_t pinned_mem_size = 0;
|
||||
int64_t resource_num = 2;
|
||||
};
|
||||
|
||||
public:
|
||||
using ResPtr = std::shared_ptr<faiss::gpu::StandardGpuResources>;
|
||||
using ResWPtr = std::weak_ptr<faiss::gpu::StandardGpuResources>;
|
||||
|
||||
static FaissGpuResourceMgr &
|
||||
GetInstance();
|
||||
|
||||
void
|
||||
AllocateTempMem(ResPtr &res, const int64_t& device_id, const int64_t& size);
|
||||
|
||||
void
|
||||
InitDevice(int64_t device_id,
|
||||
int64_t pin_mem_size = 0,
|
||||
int64_t temp_mem_size = 0,
|
||||
int64_t res_num = 2);
|
||||
|
||||
void InitResource();
|
||||
|
||||
ResPtr GetRes(const int64_t &device_id, const int64_t& alloc_size = 0);
|
||||
|
||||
void MoveToInuse(const int64_t &device_id, const ResPtr& res);
|
||||
void MoveToIdle(const int64_t &device_id, const ResPtr& res);
|
||||
|
||||
protected:
|
||||
bool is_init = false;
|
||||
|
||||
std::mutex mutex_;
|
||||
std::map<int64_t, DeviceParams> devices_params_;
|
||||
std::map<int64_t, std::vector<ResPtr>> in_use_;
|
||||
std::map<int64_t, std::vector<ResPtr>> idle_;
|
||||
};
|
||||
|
||||
class ResScope {
|
||||
public:
|
||||
ResScope(const int64_t device_id,std::shared_ptr<faiss::gpu::StandardGpuResources> &res) : resource(res), device_id(device_id) {
|
||||
FaissGpuResourceMgr::GetInstance().MoveToInuse(device_id, resource);
|
||||
}
|
||||
|
||||
~ResScope() {
|
||||
resource->noTempMemory();
|
||||
FaissGpuResourceMgr::GetInstance().MoveToIdle(device_id, resource);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<faiss::gpu::StandardGpuResources> resource;
|
||||
int64_t device_id;
|
||||
};
|
||||
|
||||
class GPUIndex {
|
||||
public:
|
||||
explicit GPUIndex(const int &device_id) : gpu_id_(device_id) {};
|
||||
|
||||
virtual VectorIndexPtr CopyGpuToCpu(const Config &config) = 0;
|
||||
virtual VectorIndexPtr CopyGpuToGpu(const int64_t &device_id, const Config &config) = 0;
|
||||
|
||||
void SetGpuDevice(const int &gpu_id);
|
||||
const int64_t &GetGpuDevice();
|
||||
|
||||
protected:
|
||||
int64_t gpu_id_;
|
||||
};
|
||||
|
||||
class GPUIVF : public IVF, public GPUIndex {
|
||||
public:
|
||||
explicit GPUIVF(const int &device_id) : IVF(), GPUIndex(device_id) {}
|
||||
explicit GPUIVF(std::shared_ptr<faiss::Index> index, const int64_t &device_id)
|
||||
: IVF(std::move(index)), GPUIndex(device_id) {};
|
||||
IndexModelPtr Train(const DatasetPtr &dataset, const Config &config) override;
|
||||
void set_index_model(IndexModelPtr model) override;
|
||||
//DatasetPtr Search(const DatasetPtr &dataset, const Config &config) override;
|
||||
VectorIndexPtr CopyGpuToCpu(const Config &config) override;
|
||||
VectorIndexPtr CopyGpuToGpu(const int64_t &device_id, const Config &config) override;
|
||||
VectorIndexPtr Clone() final;
|
||||
|
||||
// TODO(linxj): Deprecated
|
||||
virtual IVFIndexPtr Copy_index_gpu_to_cpu();
|
||||
|
||||
protected:
|
||||
void search_impl(int64_t n,
|
||||
const float *data,
|
||||
int64_t k,
|
||||
float *distances,
|
||||
int64_t *labels,
|
||||
const Config &cfg) override;
|
||||
BinarySet SerializeImpl() override;
|
||||
void LoadImpl(const BinarySet &index_binary) override;
|
||||
};
|
||||
|
||||
class GPUIVFSQ : public GPUIVF {
|
||||
public:
|
||||
explicit GPUIVFSQ(const int &device_id) : GPUIVF(device_id) {}
|
||||
explicit GPUIVFSQ(std::shared_ptr<faiss::Index> index, const int64_t& device_id) : GPUIVF(std::move(index),device_id) {};
|
||||
IndexModelPtr Train(const DatasetPtr &dataset, const Config &config) override;
|
||||
|
||||
public:
|
||||
VectorIndexPtr CopyGpuToCpu(const Config &config) override;
|
||||
};
|
||||
|
||||
class GPUIVFPQ : public GPUIVF {
|
||||
public:
|
||||
explicit GPUIVFPQ(const int &device_id) : GPUIVF(device_id) {}
|
||||
IndexModelPtr Train(const DatasetPtr &dataset, const Config &config) override;
|
||||
|
||||
public:
|
||||
VectorIndexPtr CopyGpuToCpu(const Config &config) override;
|
||||
|
||||
protected:
|
||||
// TODO(linxj): remove GenParams.
|
||||
std::shared_ptr<faiss::IVFSearchParameters> GenParams(const Config &config) override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
59
cpp/src/core/include/knowhere/index/vector_index/idmap.h
Normal file
59
cpp/src/core/include/knowhere/index/vector_index/idmap.h
Normal file
@ -0,0 +1,59 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ivf.h"
|
||||
#include "gpu_ivf.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
class IDMAP : public VectorIndex, public BasicIndex {
|
||||
public:
|
||||
IDMAP() : BasicIndex(nullptr) {};
|
||||
explicit IDMAP(std::shared_ptr<faiss::Index> index) : BasicIndex(std::move(index)) {};
|
||||
BinarySet Serialize() override;
|
||||
void Load(const BinarySet &index_binary) override;
|
||||
void Train(const Config &config);
|
||||
DatasetPtr Search(const DatasetPtr &dataset, const Config &config) override;
|
||||
int64_t Count() override;
|
||||
VectorIndexPtr Clone() override;
|
||||
int64_t Dimension() override;
|
||||
void Add(const DatasetPtr &dataset, const Config &config) override;
|
||||
VectorIndexPtr CopyCpuToGpu(const int64_t &device_id, const Config &config);
|
||||
void Seal() override;
|
||||
|
||||
virtual float *GetRawVectors();
|
||||
virtual int64_t *GetRawIds();
|
||||
|
||||
protected:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
using IDMAPPtr = std::shared_ptr<IDMAP>;
|
||||
|
||||
class GPUIDMAP : public IDMAP, public GPUIndex {
|
||||
public:
|
||||
explicit GPUIDMAP(std::shared_ptr<faiss::Index> index, const int64_t &device_id)
|
||||
: IDMAP(std::move(index)), GPUIndex(device_id) {}
|
||||
|
||||
VectorIndexPtr CopyGpuToCpu(const Config &config) override;
|
||||
float *GetRawVectors() override;
|
||||
int64_t *GetRawIds() override;
|
||||
VectorIndexPtr Clone() override;
|
||||
VectorIndexPtr CopyGpuToGpu(const int64_t &device_id, const Config &config) override;
|
||||
|
||||
protected:
|
||||
BinarySet SerializeImpl() override;
|
||||
void LoadImpl(const BinarySet &index_binary) override;
|
||||
};
|
||||
|
||||
using GPUIDMAPPtr = std::shared_ptr<GPUIDMAP>;
|
||||
|
||||
}
|
||||
}
|
||||
145
cpp/src/core/include/knowhere/index/vector_index/ivf.h
Normal file
145
cpp/src/core/include/knowhere/index/vector_index/ivf.h
Normal file
@ -0,0 +1,145 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <faiss/IndexIVF.h>
|
||||
#include <faiss/AuxIndexStructures.h>
|
||||
#include <faiss/Index.h>
|
||||
|
||||
#include "knowhere/index/vector_index/vector_index.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
class BasicIndex {
|
||||
protected:
|
||||
explicit BasicIndex(std::shared_ptr<faiss::Index> index);
|
||||
virtual BinarySet SerializeImpl();
|
||||
virtual void LoadImpl(const BinarySet &index_binary);
|
||||
virtual void
|
||||
SealImpl();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<faiss::Index> index_ = nullptr;
|
||||
};
|
||||
|
||||
using Graph = std::vector<std::vector<int64_t>>;
|
||||
|
||||
class IVF : public VectorIndex, protected BasicIndex {
|
||||
public:
|
||||
IVF() : BasicIndex(nullptr) {};
|
||||
explicit IVF(std::shared_ptr<faiss::Index> index) : BasicIndex(std::move(index)) {}
|
||||
VectorIndexPtr Clone() override;;
|
||||
IndexModelPtr Train(const DatasetPtr &dataset, const Config &config) override;
|
||||
void set_index_model(IndexModelPtr model) override;
|
||||
void Add(const DatasetPtr &dataset, const Config &config) override;
|
||||
void AddWithoutIds(const DatasetPtr &dataset, const Config &config);
|
||||
DatasetPtr Search(const DatasetPtr &dataset, const Config &config) override;
|
||||
void GenGraph(const int64_t &k, Graph &graph, const DatasetPtr &dataset, const Config &config);
|
||||
BinarySet Serialize() override;
|
||||
void Load(const BinarySet &index_binary) override;
|
||||
int64_t Count() override;
|
||||
int64_t Dimension() override;
|
||||
|
||||
void
|
||||
Seal() override;
|
||||
|
||||
virtual VectorIndexPtr CopyCpuToGpu(const int64_t &device_id, const Config &config);
|
||||
|
||||
|
||||
protected:
|
||||
virtual std::shared_ptr<faiss::IVFSearchParameters> GenParams(const Config &config);
|
||||
|
||||
virtual VectorIndexPtr Clone_impl(const std::shared_ptr<faiss::Index> &index);
|
||||
|
||||
virtual void search_impl(int64_t n,
|
||||
const float *data,
|
||||
int64_t k,
|
||||
float *distances,
|
||||
int64_t *labels,
|
||||
const Config &cfg);
|
||||
|
||||
protected:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
using IVFIndexPtr = std::shared_ptr<IVF>;
|
||||
|
||||
class IVFSQ : public IVF {
|
||||
public:
|
||||
explicit IVFSQ(std::shared_ptr<faiss::Index> index) : IVF(std::move(index)) {}
|
||||
IVFSQ() = default;
|
||||
IndexModelPtr Train(const DatasetPtr &dataset, const Config &config) override;
|
||||
VectorIndexPtr CopyCpuToGpu(const int64_t &device_id, const Config &config) override;
|
||||
protected:
|
||||
VectorIndexPtr Clone_impl(const std::shared_ptr<faiss::Index> &index) override;
|
||||
};
|
||||
|
||||
class IVFPQ : public IVF {
|
||||
public:
|
||||
explicit IVFPQ(std::shared_ptr<faiss::Index> index) : IVF(std::move(index)) {}
|
||||
IVFPQ() = default;
|
||||
IndexModelPtr Train(const DatasetPtr &dataset, const Config &config) override;
|
||||
protected:
|
||||
std::shared_ptr<faiss::IVFSearchParameters> GenParams(const Config &config) override;
|
||||
VectorIndexPtr Clone_impl(const std::shared_ptr<faiss::Index> &index) override;
|
||||
};
|
||||
|
||||
|
||||
//class OPQIVFPQ : public IVFPQ {
|
||||
// public:
|
||||
// PreprocessorPtr BuildPreprocessor(const Dataset &dataset, const Config &config) override;
|
||||
//};
|
||||
|
||||
|
||||
class GPUIVF;
|
||||
|
||||
|
||||
struct MemoryIOWriter : public faiss::IOWriter {
|
||||
uint8_t *data_ = nullptr;
|
||||
size_t total = 0;
|
||||
size_t rp = 0;
|
||||
|
||||
size_t operator()(const void *ptr, size_t size, size_t nitems) override;
|
||||
};
|
||||
|
||||
|
||||
struct MemoryIOReader : public faiss::IOReader {
|
||||
uint8_t *data_;
|
||||
size_t rp = 0;
|
||||
size_t total = 0;
|
||||
|
||||
size_t operator()(void *ptr, size_t size, size_t nitems) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class IVFIndexModel : public IndexModel, public BasicIndex {
|
||||
friend IVF;
|
||||
friend GPUIVF;
|
||||
|
||||
public:
|
||||
explicit IVFIndexModel(std::shared_ptr<faiss::Index> index);
|
||||
IVFIndexModel() : BasicIndex(nullptr) {};
|
||||
BinarySet Serialize() override;
|
||||
protected:
|
||||
void SealImpl() override;
|
||||
public:
|
||||
void Load(const BinarySet &binary) override;
|
||||
|
||||
protected:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
using IVFIndexModelPtr = std::shared_ptr<IVFIndexModel>;
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
using KDTParameter = std::pair<std::string, std::string>;
|
||||
|
||||
class KDTParameterManagement {
|
||||
public:
|
||||
const std::vector<KDTParameter> &
|
||||
GetKDTParameters();
|
||||
|
||||
public:
|
||||
static KDTParameterManagement &
|
||||
GetInstance() {
|
||||
static KDTParameterManagement instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
KDTParameterManagement(const KDTParameterManagement &) = delete;
|
||||
KDTParameterManagement &operator=(const KDTParameterManagement &) = delete;
|
||||
private:
|
||||
KDTParameterManagement();
|
||||
|
||||
private:
|
||||
std::vector<KDTParameter> kdt_parameters_;
|
||||
};
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
@ -0,0 +1,51 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
namespace algo {
|
||||
|
||||
using node_t = int64_t;
|
||||
|
||||
// TODO: search use simple neighbor
|
||||
struct Neighbor {
|
||||
node_t id; // offset of node in origin data
|
||||
float distance;
|
||||
bool has_explored;
|
||||
|
||||
Neighbor() = default;
|
||||
explicit Neighbor(node_t id, float distance, bool f) : id{id}, distance{distance}, has_explored(f) {}
|
||||
|
||||
explicit Neighbor(node_t id, float distance) : id{id}, distance{distance}, has_explored(false) {}
|
||||
|
||||
inline bool operator<(const Neighbor &other) const {
|
||||
return distance < other.distance;
|
||||
}
|
||||
};
|
||||
|
||||
//struct SimpleNeighbor {
|
||||
// node_t id; // offset of node in origin data
|
||||
// float distance;
|
||||
//
|
||||
// SimpleNeighbor() = default;
|
||||
// explicit SimpleNeighbor(node_t id, float distance) : id{id}, distance{distance}{}
|
||||
//
|
||||
// inline bool operator<(const Neighbor &other) const {
|
||||
// return distance < other.distance;
|
||||
// }
|
||||
//};
|
||||
|
||||
typedef std::lock_guard<std::mutex> LockGuard;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
147
cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.h
Normal file
147
cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.h
Normal file
@ -0,0 +1,147 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include "neighbor.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
namespace algo {
|
||||
|
||||
|
||||
using node_t = int64_t;
|
||||
|
||||
enum class MetricType {
|
||||
METRIC_INNER_PRODUCT = 0,
|
||||
METRIC_L2 = 1,
|
||||
};
|
||||
|
||||
struct BuildParams {
|
||||
size_t search_length;
|
||||
size_t out_degree;
|
||||
size_t candidate_pool_size;
|
||||
};
|
||||
|
||||
struct SearchParams {
|
||||
size_t search_length;
|
||||
};
|
||||
|
||||
using Graph = std::vector<std::vector<node_t>>;
|
||||
|
||||
class NsgIndex {
|
||||
public:
|
||||
size_t dimension;
|
||||
size_t ntotal; // totabl nb of indexed vectors
|
||||
MetricType metric_type; // L2 | IP
|
||||
|
||||
float *ori_data_;
|
||||
long *ids_; // TODO: support different type
|
||||
Graph nsg; // final graph
|
||||
Graph knng; // reset after build
|
||||
|
||||
node_t navigation_point; // offset of node in origin data
|
||||
|
||||
bool is_trained = false;
|
||||
|
||||
/*
|
||||
* build and search parameter
|
||||
*/
|
||||
size_t search_length;
|
||||
size_t candidate_pool_size; // search deepth in fullset
|
||||
size_t out_degree;
|
||||
|
||||
public:
|
||||
explicit NsgIndex(const size_t &dimension,
|
||||
const size_t &n,
|
||||
MetricType metric = MetricType::METRIC_L2);
|
||||
|
||||
NsgIndex() = default;
|
||||
|
||||
virtual ~NsgIndex();
|
||||
|
||||
void SetKnnGraph(Graph &knng);
|
||||
|
||||
virtual void Build_with_ids(size_t nb,
|
||||
const float *data,
|
||||
const long *ids,
|
||||
const BuildParams ¶meters);
|
||||
|
||||
void Search(const float *query,
|
||||
const unsigned &nq,
|
||||
const unsigned &dim,
|
||||
const unsigned &k,
|
||||
float *dist,
|
||||
long *ids,
|
||||
SearchParams ¶ms);
|
||||
|
||||
// Not support yet.
|
||||
//virtual void Add() = 0;
|
||||
//virtual void Add_with_ids() = 0;
|
||||
//virtual void Delete() = 0;
|
||||
//virtual void Delete_with_ids() = 0;
|
||||
//virtual void Rebuild(size_t nb,
|
||||
// const float *data,
|
||||
// const long *ids,
|
||||
// const Parameters ¶meters) = 0;
|
||||
//virtual void Build(size_t nb,
|
||||
// const float *data,
|
||||
// const BuildParam ¶meters);
|
||||
|
||||
protected:
|
||||
virtual void InitNavigationPoint();
|
||||
|
||||
// link specify
|
||||
void GetNeighbors(const float *query,
|
||||
std::vector<Neighbor> &resset,
|
||||
std::vector<Neighbor> &fullset,
|
||||
boost::dynamic_bitset<> &has_calculated_dist);
|
||||
|
||||
// FindUnconnectedNode
|
||||
void GetNeighbors(const float *query,
|
||||
std::vector<Neighbor> &resset,
|
||||
std::vector<Neighbor> &fullset);
|
||||
|
||||
// search and navigation-point
|
||||
void GetNeighbors(const float *query,
|
||||
std::vector<Neighbor> &resset,
|
||||
Graph &graph,
|
||||
SearchParams *param = nullptr);
|
||||
|
||||
void Link();
|
||||
|
||||
void SyncPrune(size_t q,
|
||||
std::vector<Neighbor> &pool,
|
||||
boost::dynamic_bitset<> &has_calculated,
|
||||
float *cut_graph_dist
|
||||
);
|
||||
|
||||
void SelectEdge(unsigned &cursor,
|
||||
std::vector<Neighbor> &sort_pool,
|
||||
std::vector<Neighbor> &result,
|
||||
bool limit = false);
|
||||
|
||||
void InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float *dist);
|
||||
|
||||
void CheckConnectivity();
|
||||
|
||||
void DFS(size_t root, boost::dynamic_bitset<> &flags, int64_t &count);
|
||||
|
||||
void FindUnconnectedNode(boost::dynamic_bitset<> &flags, int64_t &root);
|
||||
|
||||
private:
|
||||
void GetKnnGraphFromFile();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
15
cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.i
Normal file
15
cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.i
Normal file
@ -0,0 +1,15 @@
|
||||
%module nsg
|
||||
%{
|
||||
#define SWIG_FILE_WITH_INIT
|
||||
#include <numpy/arrayobject.h>
|
||||
|
||||
/* Include the header in the wrapper code */
|
||||
#include "nsg.h"
|
||||
|
||||
|
||||
%}
|
||||
|
||||
|
||||
/* Parse the header file */
|
||||
%include "index.h"
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "nsg.h"
|
||||
#include "knowhere/index/vector_index/ivf.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
namespace algo {
|
||||
|
||||
extern void write_index(NsgIndex* index, MemoryIOWriter& writer);
|
||||
extern NsgIndex* read_index(MemoryIOReader& reader);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
41
cpp/src/core/include/knowhere/index/vector_index/nsg_index.h
Normal file
41
cpp/src/core/include/knowhere/index/vector_index/nsg_index.h
Normal file
@ -0,0 +1,41 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "knowhere/index/vector_index/vector_index.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
namespace algo {
|
||||
class NsgIndex;
|
||||
}
|
||||
|
||||
class NSG : public VectorIndex {
|
||||
public:
|
||||
explicit NSG(const int64_t& gpu_num):gpu_(gpu_num){}
|
||||
NSG() = default;
|
||||
|
||||
IndexModelPtr Train(const DatasetPtr &dataset, const Config &config) override;
|
||||
DatasetPtr Search(const DatasetPtr &dataset, const Config &config) override;
|
||||
void Add(const DatasetPtr &dataset, const Config &config) override;
|
||||
BinarySet Serialize() override;
|
||||
void Load(const BinarySet &index_binary) override;
|
||||
int64_t Count() override;
|
||||
int64_t Dimension() override;
|
||||
VectorIndexPtr Clone() override;
|
||||
void Seal() override;
|
||||
private:
|
||||
std::shared_ptr<algo::NsgIndex> index_;
|
||||
int64_t gpu_;
|
||||
};
|
||||
|
||||
using NSGIndexPtr = std::shared_ptr<NSG>();
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include "knowhere/common/config.h"
|
||||
#include "knowhere/common/dataset.h"
|
||||
#include "knowhere/index/index.h"
|
||||
#include "knowhere/index/preprocessor/preprocessor.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
class VectorIndex;
|
||||
using VectorIndexPtr = std::shared_ptr<VectorIndex>;
|
||||
|
||||
|
||||
class VectorIndex : public Index {
|
||||
public:
|
||||
virtual PreprocessorPtr
|
||||
BuildPreprocessor(const DatasetPtr &dataset, const Config &config) { return nullptr; }
|
||||
|
||||
virtual IndexModelPtr
|
||||
Train(const DatasetPtr &dataset, const Config &config) { return nullptr; }
|
||||
|
||||
virtual void
|
||||
Add(const DatasetPtr &dataset, const Config &config) = 0;
|
||||
|
||||
virtual void
|
||||
Seal() = 0;
|
||||
|
||||
virtual VectorIndexPtr
|
||||
Clone() = 0;
|
||||
|
||||
virtual int64_t
|
||||
Count() = 0;
|
||||
|
||||
virtual int64_t
|
||||
Dimension() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
139
cpp/src/core/src/CMakeLists.txt
Normal file
139
cpp/src/core/src/CMakeLists.txt
Normal file
@ -0,0 +1,139 @@
|
||||
set(TBB_DIR ${CMAKE_SOURCE_DIR}/thirdparty/tbb)
|
||||
set(TBB_LIBRARIES ${TBB_DIR}/libtbb.so)
|
||||
include_directories(${TBB_DIR}/include)
|
||||
|
||||
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
|
||||
link_directories(${CUDA_TOOLKIT_ROOT_DIR}/lib64)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/thirdparty)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/thirdparty/SPTAG/AnnService)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/thirdparty/jsoncons-0.126.0/include)
|
||||
|
||||
set(SPTAG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/SPTAG)
|
||||
file(GLOB HDR_FILES
|
||||
${SPTAG_SOURCE_DIR}/AnnService/inc/Core/*.h
|
||||
${SPTAG_SOURCE_DIR}/AnnService/inc/Core/Common/*.h
|
||||
${SPTAG_SOURCE_DIR}/AnnService/inc/Core/BKT/*.h
|
||||
${SPTAG_SOURCE_DIR}/AnnService/inc/Core/KDT/*.h
|
||||
${SPTAG_SOURCE_DIR}/AnnService/inc/Helper/*.h)
|
||||
file(GLOB SRC_FILES
|
||||
${SPTAG_SOURCE_DIR}/AnnService/src/Core/*.cpp
|
||||
${SPTAG_SOURCE_DIR}/AnnService/src/Core/Common/*.cpp
|
||||
${SPTAG_SOURCE_DIR}/AnnService/src/Core/BKT/*.cpp
|
||||
${SPTAG_SOURCE_DIR}/AnnService/src/Core/KDT/*.cpp
|
||||
${SPTAG_SOURCE_DIR}/AnnService/src/Helper/*.cpp)
|
||||
|
||||
#add_library(SPTAGLib SHARED ${SRC_FILES} ${HDR_FILES})
|
||||
#target_link_libraries(SPTAGLib ${TBB_LIBRARIES})
|
||||
add_library(SPTAGLibStatic STATIC ${SRC_FILES} ${HDR_FILES})
|
||||
|
||||
set(external_srcs
|
||||
knowhere/adapter/sptag.cpp
|
||||
knowhere/adapter/structure.cpp
|
||||
knowhere/adapter/arrow.cpp
|
||||
knowhere/common/exception.cpp
|
||||
knowhere/common/timer.cpp
|
||||
)
|
||||
|
||||
set(index_srcs
|
||||
knowhere/index/preprocessor/normalize.cpp
|
||||
knowhere/index/vector_index/cpu_kdt_rng.cpp
|
||||
knowhere/index/vector_index/idmap.cpp
|
||||
knowhere/index/vector_index/ivf.cpp
|
||||
knowhere/index/vector_index/gpu_ivf.cpp
|
||||
knowhere/index/vector_index/kdt_parameters.cpp
|
||||
knowhere/index/vector_index/nsg_index.cpp
|
||||
knowhere/index/vector_index/nsg/nsg.cpp
|
||||
knowhere/index/vector_index/nsg/nsg_io.cpp
|
||||
knowhere/index/vector_index/nsg/utils.cpp
|
||||
knowhere/index/vector_index/cloner.cpp
|
||||
)
|
||||
|
||||
set(depend_libs
|
||||
# libtcmalloc.a
|
||||
SPTAGLibStatic
|
||||
${TBB_LIBRARIES}
|
||||
faiss
|
||||
openblas
|
||||
lapack
|
||||
arrow
|
||||
jemalloc_pic
|
||||
cudart
|
||||
cublas
|
||||
gomp
|
||||
gfortran
|
||||
pthread
|
||||
)
|
||||
|
||||
add_library(
|
||||
knowhere STATIC
|
||||
${external_srcs}
|
||||
${index_srcs}
|
||||
)
|
||||
#target_compile_options(knowhere PUBLIC "-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
|
||||
|
||||
target_link_libraries(
|
||||
knowhere
|
||||
${depend_libs}
|
||||
)
|
||||
|
||||
#add_library(
|
||||
# knowhereS SHARED
|
||||
# ${external_srcs}
|
||||
# ${index_srcs}
|
||||
#)
|
||||
#
|
||||
#target_link_libraries(
|
||||
# knowhereS
|
||||
## ${TBB_LIBRARIES}
|
||||
# ${depend_libs}
|
||||
#)
|
||||
|
||||
INSTALL(TARGETS
|
||||
knowhere
|
||||
SPTAGLibStatic
|
||||
DESTINATION
|
||||
lib)
|
||||
|
||||
INSTALL(FILES
|
||||
${ARROW_STATIC_LIB}
|
||||
# ${PARQUET_STATIC_LIB}
|
||||
${ARROW_PREFIX}/lib/libjemalloc_pic.a
|
||||
${FAISS_STATIC_LIB}
|
||||
${LAPACK_STATIC_LIB}
|
||||
${BLAS_STATIC_LIB}
|
||||
DESTINATION
|
||||
lib
|
||||
)
|
||||
|
||||
INSTALL(FILES ${OPENBLAS_REAL_STATIC_LIB}
|
||||
RENAME "libopenblas.a"
|
||||
DESTINATION lib
|
||||
)
|
||||
|
||||
INSTALL(FILES ${CMAKE_SOURCE_DIR}/thirdparty/tbb/libtbb.so.2
|
||||
# RENAME "libtbb.so.2"
|
||||
DESTINATION lib
|
||||
)
|
||||
INSTALL(FILES ${CMAKE_SOURCE_DIR}/thirdparty/tbb/libtbb.so
|
||||
# RENAME "libtbb.so"
|
||||
DESTINATION lib
|
||||
)
|
||||
|
||||
INSTALL(DIRECTORY
|
||||
${CMAKE_SOURCE_DIR}/include/knowhere
|
||||
${CMAKE_SOURCE_DIR}/thirdparty/jsoncons-0.126.0/include/jsoncons
|
||||
${CMAKE_SOURCE_DIR}/thirdparty/jsoncons-0.126.0/include/jsoncons_ext
|
||||
${ARROW_INCLUDE_DIR}/arrow
|
||||
# ${ARROW_INCLUDE_DIR}/parquet
|
||||
${FAISS_PREFIX}/include/faiss
|
||||
${OPENBLAS_INCLUDE_DIR}/
|
||||
${CMAKE_SOURCE_DIR}/thirdparty/tbb/include/tbb
|
||||
DESTINATION
|
||||
include)
|
||||
|
||||
INSTALL(DIRECTORY
|
||||
${SPTAG_SOURCE_DIR}/AnnService/inc/
|
||||
DESTINATION
|
||||
include/SPTAG/AnnService/inc)
|
||||
39
cpp/src/core/src/knowhere/adapter/arrow.cpp
Normal file
39
cpp/src/core/src/knowhere/adapter/arrow.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
#include "knowhere/adapter/arrow.h"
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
ArrayPtr
|
||||
CopyArray(const ArrayPtr &origin) {
|
||||
ArrayPtr copy = nullptr;
|
||||
auto copy_data = origin->data()->Copy();
|
||||
switch (origin->type_id()) {
|
||||
#define DEFINE_TYPE(type, clazz) \
|
||||
case arrow::Type::type: { \
|
||||
copy = std::make_shared<arrow::clazz>(copy_data); \
|
||||
}
|
||||
DEFINE_TYPE(BOOL, BooleanArray)
|
||||
DEFINE_TYPE(BINARY, BinaryArray)
|
||||
DEFINE_TYPE(FIXED_SIZE_BINARY, FixedSizeBinaryArray)
|
||||
DEFINE_TYPE(DECIMAL, Decimal128Array)
|
||||
DEFINE_TYPE(FLOAT, NumericArray<arrow::FloatType>)
|
||||
DEFINE_TYPE(INT64, NumericArray<arrow::Int64Type>)
|
||||
default:break;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
SchemaPtr
|
||||
CopySchema(const SchemaPtr &origin) {
|
||||
std::vector<std::shared_ptr<Field>> fields;
|
||||
for (auto &field : origin->fields()) {
|
||||
auto copy = std::make_shared<Field>(field->name(), field->type(),field->nullable(), nullptr);
|
||||
fields.emplace_back(copy);
|
||||
}
|
||||
return std::make_shared<Schema>(std::move(fields));
|
||||
}
|
||||
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
116
cpp/src/core/src/knowhere/adapter/sptag.cpp
Normal file
116
cpp/src/core/src/knowhere/adapter/sptag.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
|
||||
#include "knowhere/index/vector_index/definitions.h"
|
||||
#include "knowhere/adapter/sptag.h"
|
||||
#include "knowhere/adapter/structure.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
std::shared_ptr<SPTAG::MetadataSet>
|
||||
ConvertToMetadataSet(const DatasetPtr &dataset) {
|
||||
auto array = dataset->array()[0];
|
||||
auto elems = array->length();
|
||||
|
||||
auto p_data = array->data()->GetValues<int64_t>(1, 0);
|
||||
auto p_offset = (int64_t *) malloc(sizeof(int64_t) * elems);
|
||||
for (auto i = 0; i <= elems; ++i)
|
||||
p_offset[i] = i * 8;
|
||||
|
||||
std::shared_ptr<SPTAG::MetadataSet> metaset(new SPTAG::MemMetadataSet(
|
||||
SPTAG::ByteArray((std::uint8_t *) p_data, elems * sizeof(int64_t), false),
|
||||
SPTAG::ByteArray((std::uint8_t *) p_offset, elems * sizeof(int64_t), true),
|
||||
elems));
|
||||
|
||||
|
||||
return metaset;
|
||||
}
|
||||
|
||||
std::shared_ptr<SPTAG::VectorSet>
|
||||
ConvertToVectorSet(const DatasetPtr &dataset) {
|
||||
auto tensor = dataset->tensor()[0];
|
||||
|
||||
auto p_data = tensor->raw_mutable_data();
|
||||
auto dimension = tensor->shape()[1];
|
||||
auto rows = tensor->shape()[0];
|
||||
auto num_bytes = tensor->size() * sizeof(float);
|
||||
|
||||
SPTAG::ByteArray byte_array(p_data, num_bytes, false);
|
||||
|
||||
auto vectorset = std::make_shared<SPTAG::BasicVectorSet>(byte_array,
|
||||
SPTAG::VectorValueType::Float,
|
||||
dimension,
|
||||
rows);
|
||||
return vectorset;
|
||||
}
|
||||
|
||||
std::vector<SPTAG::QueryResult>
|
||||
ConvertToQueryResult(const DatasetPtr &dataset, const Config &config) {
|
||||
auto tensor = dataset->tensor()[0];
|
||||
|
||||
auto p_data = (float *) tensor->raw_mutable_data();
|
||||
auto dimension = tensor->shape()[1];
|
||||
auto rows = tensor->shape()[0];
|
||||
|
||||
auto k = config[META_K].as<int64_t>();
|
||||
std::vector<SPTAG::QueryResult> query_results(rows, SPTAG::QueryResult(nullptr, k, true));
|
||||
for (auto i = 0; i < rows; ++i) {
|
||||
query_results[i].SetTarget(&p_data[i * dimension]);
|
||||
}
|
||||
|
||||
return query_results;
|
||||
}
|
||||
|
||||
DatasetPtr
|
||||
ConvertToDataset(std::vector<SPTAG::QueryResult> query_results) {
|
||||
auto k = query_results[0].GetResultNum();
|
||||
auto elems = query_results.size() * k;
|
||||
|
||||
auto p_id = (int64_t *) malloc(sizeof(int64_t) * elems);
|
||||
auto p_dist = (float *) malloc(sizeof(float) * elems);
|
||||
// TODO: throw if malloc failed.
|
||||
|
||||
#pragma omp parallel for
|
||||
for (auto i = 0; i < query_results.size(); ++i) {
|
||||
auto results = query_results[i].GetResults();
|
||||
auto num_result = query_results[i].GetResultNum();
|
||||
for (auto j = 0; j < num_result; ++j) {
|
||||
// p_id[i * k + j] = results[j].VID;
|
||||
p_id[i * k + j] = *(int64_t *) query_results[i].GetMetadata(j).Data();
|
||||
p_dist[i * k + j] = results[j].Dist;
|
||||
}
|
||||
}
|
||||
|
||||
auto id_buf = MakeMutableBufferSmart((uint8_t *) p_id, sizeof(int64_t) * elems);
|
||||
auto dist_buf = MakeMutableBufferSmart((uint8_t *) p_dist, sizeof(float) * elems);
|
||||
|
||||
// TODO: magic
|
||||
std::vector<BufferPtr> id_bufs{nullptr, id_buf};
|
||||
std::vector<BufferPtr> dist_bufs{nullptr, dist_buf};
|
||||
|
||||
auto int64_type = std::make_shared<arrow::Int64Type>();
|
||||
auto float_type = std::make_shared<arrow::FloatType>();
|
||||
|
||||
auto id_array_data = arrow::ArrayData::Make(int64_type, elems, id_bufs);
|
||||
auto dist_array_data = arrow::ArrayData::Make(float_type, elems, dist_bufs);
|
||||
// auto id_array_data = std::make_shared<ArrayData>(int64_type, sizeof(int64_t) * elems, id_bufs);
|
||||
// auto dist_array_data = std::make_shared<ArrayData>(float_type, sizeof(float) * elems, dist_bufs);
|
||||
|
||||
// auto ids = ConstructInt64Array((uint8_t*)p_id, sizeof(int64_t) * elems);
|
||||
// auto dists = ConstructFloatArray((uint8_t*)p_dist, sizeof(float) * elems);
|
||||
|
||||
auto ids = std::make_shared<NumericArray<arrow::Int64Type>>(id_array_data);
|
||||
auto dists = std::make_shared<NumericArray<arrow::FloatType>>(dist_array_data);
|
||||
std::vector<ArrayPtr> array{ids, dists};
|
||||
|
||||
auto field_id = std::make_shared<Field>("id", std::make_shared<arrow::Int64Type>());
|
||||
auto field_dist = std::make_shared<Field>("dist", std::make_shared<arrow::FloatType>());
|
||||
std::vector<FieldPtr> fields{field_id, field_dist};
|
||||
auto schema = std::make_shared<Schema>(fields);
|
||||
|
||||
return std::make_shared<Dataset>(array, schema);
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
76
cpp/src/core/src/knowhere/adapter/structure.cpp
Normal file
76
cpp/src/core/src/knowhere/adapter/structure.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "knowhere/adapter/structure.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
ArrayPtr
|
||||
ConstructInt64ArraySmart(uint8_t *data, int64_t size) {
|
||||
// TODO: magic
|
||||
std::vector<BufferPtr> id_buf{nullptr, MakeMutableBufferSmart(data, size)};
|
||||
auto type = std::make_shared<arrow::Int64Type>();
|
||||
auto id_array_data = arrow::ArrayData::Make(type, size / sizeof(int64_t), id_buf);
|
||||
return std::make_shared<NumericArray<arrow::Int64Type>>(id_array_data);
|
||||
}
|
||||
|
||||
ArrayPtr
|
||||
ConstructFloatArraySmart(uint8_t *data, int64_t size) {
|
||||
// TODO: magic
|
||||
std::vector<BufferPtr> id_buf{nullptr, MakeMutableBufferSmart(data, size)};
|
||||
auto type = std::make_shared<arrow::FloatType>();
|
||||
auto id_array_data = arrow::ArrayData::Make(type, size / sizeof(float), id_buf);
|
||||
return std::make_shared<NumericArray<arrow::FloatType>>(id_array_data);
|
||||
}
|
||||
|
||||
TensorPtr
|
||||
ConstructFloatTensorSmart(uint8_t *data, int64_t size, std::vector<int64_t> shape) {
|
||||
auto buffer = MakeMutableBufferSmart(data, size);
|
||||
auto float_type = std::make_shared<arrow::FloatType>();
|
||||
return std::make_shared<Tensor>(float_type, buffer, shape);
|
||||
}
|
||||
|
||||
ArrayPtr
|
||||
ConstructInt64Array(uint8_t *data, int64_t size) {
|
||||
// TODO: magic
|
||||
std::vector<BufferPtr> id_buf{nullptr, MakeMutableBuffer(data, size)};
|
||||
auto type = std::make_shared<arrow::Int64Type>();
|
||||
auto id_array_data = arrow::ArrayData::Make(type, size / sizeof(int64_t), id_buf);
|
||||
return std::make_shared<NumericArray<arrow::Int64Type>>(id_array_data);
|
||||
}
|
||||
|
||||
ArrayPtr
|
||||
ConstructFloatArray(uint8_t *data, int64_t size) {
|
||||
// TODO: magic
|
||||
std::vector<BufferPtr> id_buf{nullptr, MakeMutableBuffer(data, size)};
|
||||
auto type = std::make_shared<arrow::FloatType>();
|
||||
auto id_array_data = arrow::ArrayData::Make(type, size / sizeof(float), id_buf);
|
||||
return std::make_shared<NumericArray<arrow::FloatType>>(id_array_data);
|
||||
}
|
||||
|
||||
TensorPtr
|
||||
ConstructFloatTensor(uint8_t *data, int64_t size, std::vector<int64_t> shape) {
|
||||
auto buffer = MakeMutableBuffer(data, size);
|
||||
auto float_type = std::make_shared<arrow::FloatType>();
|
||||
return std::make_shared<Tensor>(float_type, buffer, shape);
|
||||
}
|
||||
|
||||
FieldPtr
|
||||
ConstructInt64Field(const std::string &name) {
|
||||
auto type = std::make_shared<arrow::Int64Type>();
|
||||
return std::make_shared<Field>(name, type);
|
||||
}
|
||||
|
||||
|
||||
FieldPtr
|
||||
ConstructFloatField(const std::string &name) {
|
||||
auto type = std::make_shared<arrow::FloatType>();
|
||||
return std::make_shared<Field>(name, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
cpp/src/core/src/knowhere/common/exception.cpp
Normal file
29
cpp/src/core/src/knowhere/common/exception.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "knowhere/common/exception.h"
|
||||
#include <cstdio>
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
KnowhereException::KnowhereException(const std::string &msg):msg(msg) {}
|
||||
|
||||
KnowhereException::KnowhereException(const std::string &m, const char *funcName, const char *file, int line) {
|
||||
int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s",
|
||||
funcName, file, line, m.c_str());
|
||||
msg.resize(size + 1);
|
||||
snprintf(&msg[0], msg.size(), "Error in %s at %s:%d: %s",
|
||||
funcName, file, line, m.c_str());
|
||||
}
|
||||
|
||||
const char *KnowhereException::what() const noexcept {
|
||||
return msg.c_str();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
93
cpp/src/core/src/knowhere/common/timer.cpp
Normal file
93
cpp/src/core/src/knowhere/common/timer.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream> // TODO(linxj): using Log instead
|
||||
|
||||
#include "knowhere/common/timer.h"
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
TimeRecorder::TimeRecorder(const std::string &header,
|
||||
int64_t log_level) :
|
||||
header_(header),
|
||||
log_level_(log_level) {
|
||||
start_ = last_ = stdclock::now();
|
||||
}
|
||||
|
||||
TimeRecorder::~TimeRecorder() {
|
||||
}
|
||||
|
||||
std::string
|
||||
TimeRecorder::GetTimeSpanStr(double span) {
|
||||
std::string str_sec = std::to_string(span * 0.000001) + ((span > 1000000) ? " seconds" : " second");
|
||||
std::string str_ms = std::to_string(span * 0.001) + " ms";
|
||||
|
||||
return str_sec + " [" + str_ms + "]";
|
||||
}
|
||||
|
||||
void
|
||||
TimeRecorder::PrintTimeRecord(const std::string &msg, double span) {
|
||||
std::string str_log;
|
||||
if (!header_.empty()) str_log += header_ + ": ";
|
||||
str_log += msg;
|
||||
str_log += " (";
|
||||
str_log += TimeRecorder::GetTimeSpanStr(span);
|
||||
str_log += ")";
|
||||
|
||||
switch (log_level_) {
|
||||
case 0: {
|
||||
std::cout << str_log << std::endl;
|
||||
break;
|
||||
}
|
||||
//case 1: {
|
||||
// SERVER_LOG_DEBUG << str_log;
|
||||
// break;
|
||||
//}
|
||||
//case 2: {
|
||||
// SERVER_LOG_INFO << str_log;
|
||||
// break;
|
||||
//}
|
||||
//case 3: {
|
||||
// SERVER_LOG_WARNING << str_log;
|
||||
// break;
|
||||
//}
|
||||
//case 4: {
|
||||
// SERVER_LOG_ERROR << str_log;
|
||||
// break;
|
||||
//}
|
||||
//case 5: {
|
||||
// SERVER_LOG_FATAL << str_log;
|
||||
// break;
|
||||
//}
|
||||
//default: {
|
||||
// SERVER_LOG_INFO << str_log;
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
TimeRecorder::RecordSection(const std::string &msg) {
|
||||
stdclock::time_point curr = stdclock::now();
|
||||
double span = (std::chrono::duration<double, std::micro>(curr - last_)).count();
|
||||
last_ = curr;
|
||||
|
||||
PrintTimeRecord(msg, span);
|
||||
return span;
|
||||
}
|
||||
|
||||
double
|
||||
TimeRecorder::ElapseFromBegin(const std::string &msg) {
|
||||
stdclock::time_point curr = stdclock::now();
|
||||
double span = (std::chrono::duration<double, std::micro>(curr - start_)).count();
|
||||
|
||||
PrintTimeRecord(msg, span);
|
||||
return span;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
42
cpp/src/core/src/knowhere/index/preprocessor/normalize.cpp
Normal file
42
cpp/src/core/src/knowhere/index/preprocessor/normalize.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
#include "knowhere/index/vector_index/definitions.h"
|
||||
#include "knowhere/common/config.h"
|
||||
#include "knowhere/index/preprocessor/normalize.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
DatasetPtr
|
||||
NormalizePreprocessor::Preprocess(const DatasetPtr &dataset) {
|
||||
// TODO: wrap dataset->tensor
|
||||
auto tensor = dataset->tensor()[0];
|
||||
auto p_data = (float *)tensor->raw_mutable_data();
|
||||
auto dimension = tensor->shape()[1];
|
||||
auto rows = tensor->shape()[0];
|
||||
|
||||
#pragma omp parallel for
|
||||
for (auto i = 0; i < rows; ++i) {
|
||||
Normalize(&(p_data[i * dimension]), dimension);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NormalizePreprocessor::Normalize(float *arr, int64_t dimension) {
|
||||
double vector_length = 0;
|
||||
for (auto j = 0; j < dimension; j++) {
|
||||
double val = arr[j];
|
||||
vector_length += val * val;
|
||||
}
|
||||
vector_length = std::sqrt(vector_length);
|
||||
if (vector_length < 1e-6) {
|
||||
auto val = (float) (1.0 / std::sqrt((double) dimension));
|
||||
for (int j = 0; j < dimension; j++) arr[j] = val;
|
||||
} else {
|
||||
for (int j = 0; j < dimension; j++) arr[j] = (float) (arr[j] / vector_length);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
|
||||
45
cpp/src/core/src/knowhere/index/vector_index/cloner.cpp
Normal file
45
cpp/src/core/src/knowhere/index/vector_index/cloner.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
* Proprietary and confidential.
|
||||
******************************************************************************/
|
||||
|
||||
#include "knowhere/common/exception.h"
|
||||
#include "knowhere/index/vector_index/cloner.h"
|
||||
#include "knowhere/index/vector_index/ivf.h"
|
||||
#include "knowhere/index/vector_index/gpu_ivf.h"
|
||||
#include "knowhere/index/vector_index/idmap.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
VectorIndexPtr CopyGpuToCpu(const VectorIndexPtr &index, const Config &config) {
|
||||
if (auto device_index = std::dynamic_pointer_cast<GPUIndex>(index)) {
|
||||
return device_index->CopyGpuToCpu(config);
|
||||
} else {
|
||||
KNOWHERE_THROW_MSG("index type is not gpuindex");
|
||||
}
|
||||
}
|
||||
|
||||
VectorIndexPtr CopyCpuToGpu(const VectorIndexPtr &index, const int64_t &device_id, const Config &config) {
|
||||
if (auto device_index = std::dynamic_pointer_cast<GPUIndex>(index)) {
|
||||
return device_index->CopyGpuToGpu(device_id, config);
|
||||
}
|
||||
|
||||
if (auto cpu_index = std::dynamic_pointer_cast<IVFSQ>(index)) {
|
||||
return cpu_index->CopyCpuToGpu(device_id, config);
|
||||
//KNOWHERE_THROW_MSG("IVFSQ not support tranfer to gpu");
|
||||
} else if (auto cpu_index = std::dynamic_pointer_cast<IVFPQ>(index)) {
|
||||
KNOWHERE_THROW_MSG("IVFPQ not support tranfer to gpu");
|
||||
} else if (auto cpu_index = std::dynamic_pointer_cast<IVF>(index)) {
|
||||
return cpu_index->CopyCpuToGpu(device_id, config);
|
||||
} else if (auto cpu_index = std::dynamic_pointer_cast<IDMAP>(index)) {
|
||||
return cpu_index->CopyCpuToGpu(device_id, config);
|
||||
} else {
|
||||
KNOWHERE_THROW_MSG("this index type not support tranfer to gpu");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
155
cpp/src/core/src/knowhere/index/vector_index/cpu_kdt_rng.cpp
Normal file
155
cpp/src/core/src/knowhere/index/vector_index/cpu_kdt_rng.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <SPTAG/AnnService/inc/Server/QueryParser.h>
|
||||
#include <SPTAG/AnnService/inc/Core/VectorSet.h>
|
||||
#include <SPTAG/AnnService/inc/Core/Common.h>
|
||||
|
||||
|
||||
#undef mkdir
|
||||
|
||||
#include "knowhere/index/vector_index/cpu_kdt_rng.h"
|
||||
#include "knowhere/index/vector_index/definitions.h"
|
||||
#include "knowhere/index/preprocessor/normalize.h"
|
||||
#include "knowhere/index/vector_index/kdt_parameters.h"
|
||||
#include "knowhere/adapter/sptag.h"
|
||||
#include "knowhere/common/exception.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
BinarySet
|
||||
CPUKDTRNG::Serialize() {
|
||||
std::vector<void *> index_blobs;
|
||||
std::vector<int64_t> index_len;
|
||||
index_ptr_->SaveIndexToMemory(index_blobs, index_len);
|
||||
BinarySet binary_set;
|
||||
|
||||
auto sample = std::make_shared<uint8_t>();
|
||||
sample.reset(static_cast<uint8_t *>(index_blobs[0]));
|
||||
auto tree = std::make_shared<uint8_t>();
|
||||
tree.reset(static_cast<uint8_t *>(index_blobs[1]));
|
||||
auto graph = std::make_shared<uint8_t>();
|
||||
graph.reset(static_cast<uint8_t *>(index_blobs[2]));
|
||||
auto metadata = std::make_shared<uint8_t>();
|
||||
metadata.reset(static_cast<uint8_t *>(index_blobs[3]));
|
||||
|
||||
binary_set.Append("samples", sample, index_len[0]);
|
||||
binary_set.Append("tree", tree, index_len[1]);
|
||||
binary_set.Append("graph", graph, index_len[2]);
|
||||
binary_set.Append("metadata", metadata, index_len[3]);
|
||||
return binary_set;
|
||||
}
|
||||
|
||||
void
|
||||
CPUKDTRNG::Load(const BinarySet &binary_set) {
|
||||
std::vector<void *> index_blobs;
|
||||
|
||||
auto samples = binary_set.GetByName("samples");
|
||||
index_blobs.push_back(samples->data.get());
|
||||
|
||||
auto tree = binary_set.GetByName("tree");
|
||||
index_blobs.push_back(tree->data.get());
|
||||
|
||||
auto graph = binary_set.GetByName("graph");
|
||||
index_blobs.push_back(graph->data.get());
|
||||
|
||||
auto metadata = binary_set.GetByName("metadata");
|
||||
index_blobs.push_back(metadata->data.get());
|
||||
|
||||
index_ptr_->LoadIndexFromMemory(index_blobs);
|
||||
}
|
||||
|
||||
PreprocessorPtr
|
||||
CPUKDTRNG::BuildPreprocessor(const DatasetPtr &dataset, const Config &config) {
|
||||
return std::make_shared<NormalizePreprocessor>();
|
||||
}
|
||||
|
||||
IndexModelPtr
|
||||
CPUKDTRNG::Train(const DatasetPtr &origin, const Config &train_config) {
|
||||
SetParameters(train_config);
|
||||
DatasetPtr dataset = origin->Clone();
|
||||
|
||||
if (index_ptr_->GetDistCalcMethod() == SPTAG::DistCalcMethod::Cosine
|
||||
&& preprocessor_) {
|
||||
preprocessor_->Preprocess(dataset);
|
||||
}
|
||||
|
||||
auto vectorset = ConvertToVectorSet(dataset);
|
||||
auto metaset = ConvertToMetadataSet(dataset);
|
||||
index_ptr_->BuildIndex(vectorset, metaset);
|
||||
|
||||
// TODO: return IndexModelPtr
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
CPUKDTRNG::Add(const DatasetPtr &origin, const Config &add_config) {
|
||||
SetParameters(add_config);
|
||||
DatasetPtr dataset = origin->Clone();
|
||||
|
||||
if (index_ptr_->GetDistCalcMethod() == SPTAG::DistCalcMethod::Cosine
|
||||
&& preprocessor_) {
|
||||
preprocessor_->Preprocess(dataset);
|
||||
}
|
||||
|
||||
auto vectorset = ConvertToVectorSet(dataset);
|
||||
auto metaset = ConvertToMetadataSet(dataset);
|
||||
index_ptr_->AddIndex(vectorset, metaset);
|
||||
}
|
||||
|
||||
void
|
||||
CPUKDTRNG::SetParameters(const Config &config) {
|
||||
for (auto ¶ : KDTParameterManagement::GetInstance().GetKDTParameters()) {
|
||||
auto value = config.get_with_default(para.first, para.second);
|
||||
index_ptr_->SetParameter(para.first, value);
|
||||
}
|
||||
}
|
||||
|
||||
DatasetPtr
|
||||
CPUKDTRNG::Search(const DatasetPtr &dataset, const Config &config) {
|
||||
SetParameters(config);
|
||||
auto tensor = dataset->tensor()[0];
|
||||
auto p = (float *) tensor->raw_mutable_data();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
for (auto j = 0; j < 10; ++j) {
|
||||
std::cout << p[i * 10 + j] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::vector<SPTAG::QueryResult> query_results = ConvertToQueryResult(dataset, config);
|
||||
|
||||
#pragma omp parallel for
|
||||
for (auto i = 0; i < query_results.size(); ++i) {
|
||||
auto target = (float *) query_results[i].GetTarget();
|
||||
std::cout << target[0] << ", " << target[1] << ", " << target[2] << std::endl;
|
||||
index_ptr_->SearchIndex(query_results[i]);
|
||||
}
|
||||
|
||||
return ConvertToDataset(query_results);
|
||||
}
|
||||
|
||||
int64_t CPUKDTRNG::Count() {
|
||||
index_ptr_->GetNumSamples();
|
||||
}
|
||||
int64_t CPUKDTRNG::Dimension() {
|
||||
index_ptr_->GetFeatureDim();
|
||||
}
|
||||
|
||||
VectorIndexPtr CPUKDTRNG::Clone() {
|
||||
KNOWHERE_THROW_MSG("not support");
|
||||
}
|
||||
|
||||
void CPUKDTRNG::Seal() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// TODO(linxj):
|
||||
BinarySet
|
||||
CPUKDTRNGIndexModel::Serialize() {}
|
||||
|
||||
void
|
||||
CPUKDTRNGIndexModel::Load(const BinarySet &binary) {}
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
309
cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp
Normal file
309
cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp
Normal file
@ -0,0 +1,309 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <faiss/gpu/GpuIndexFlat.h>
|
||||
#include <faiss/gpu/GpuIndexIVF.h>
|
||||
#include <faiss/gpu/GpuIndexIVFFlat.h>
|
||||
#include <faiss/gpu/GpuIndexIVFPQ.h>
|
||||
#include <faiss/gpu/GpuAutoTune.h>
|
||||
#include <faiss/IndexIVFPQ.h>
|
||||
#include <faiss/index_io.h>
|
||||
|
||||
|
||||
#include "knowhere/common/exception.h"
|
||||
#include "knowhere/index/vector_index/cloner.h"
|
||||
#include "knowhere/adapter/faiss_adopt.h"
|
||||
#include "knowhere/index/vector_index/gpu_ivf.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
IndexModelPtr GPUIVF::Train(const DatasetPtr &dataset, const Config &config) {
|
||||
auto nlist = config["nlist"].as<size_t>();
|
||||
auto gpu_device = config.get_with_default("gpu_id", gpu_id_);
|
||||
auto metric_type = config["metric_type"].as_string() == "L2" ?
|
||||
faiss::METRIC_L2 : faiss::METRIC_INNER_PRODUCT;
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
// TODO(linxj): use device_id
|
||||
auto res = FaissGpuResourceMgr::GetInstance().GetRes(gpu_device);
|
||||
ResScope rs(gpu_device, res);
|
||||
faiss::gpu::GpuIndexIVFFlat device_index(res.get(), dim, nlist, metric_type);
|
||||
device_index.train(rows, (float *) p_data);
|
||||
|
||||
std::shared_ptr<faiss::Index> host_index = nullptr;
|
||||
host_index.reset(faiss::gpu::index_gpu_to_cpu(&device_index));
|
||||
|
||||
return std::make_shared<IVFIndexModel>(host_index);
|
||||
}
|
||||
|
||||
void GPUIVF::set_index_model(IndexModelPtr model) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
auto host_index = std::static_pointer_cast<IVFIndexModel>(model);
|
||||
if (auto res = FaissGpuResourceMgr::GetInstance().GetRes(gpu_id_)) {
|
||||
ResScope rs(gpu_id_, res);
|
||||
auto device_index = faiss::gpu::index_cpu_to_gpu(res.get(), gpu_id_, host_index->index_.get());
|
||||
index_.reset(device_index);
|
||||
} else {
|
||||
KNOWHERE_THROW_MSG("load index model error, can't get gpu_resource");
|
||||
}
|
||||
}
|
||||
|
||||
BinarySet GPUIVF::SerializeImpl() {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("index not initialize or trained");
|
||||
}
|
||||
|
||||
try {
|
||||
MemoryIOWriter writer;
|
||||
{
|
||||
faiss::Index *index = index_.get();
|
||||
faiss::Index *host_index = faiss::gpu::index_gpu_to_cpu(index);
|
||||
|
||||
SealImpl();
|
||||
|
||||
faiss::write_index(host_index, &writer);
|
||||
delete host_index;
|
||||
}
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(writer.data_);
|
||||
|
||||
BinarySet res_set;
|
||||
res_set.Append("IVF", data, writer.rp);
|
||||
|
||||
return res_set;
|
||||
} catch (std::exception &e) {
|
||||
KNOWHERE_THROW_MSG(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void GPUIVF::LoadImpl(const BinarySet &index_binary) {
|
||||
auto binary = index_binary.GetByName("IVF");
|
||||
MemoryIOReader reader;
|
||||
{
|
||||
reader.total = binary->size;
|
||||
reader.data_ = binary->data.get();
|
||||
|
||||
faiss::Index *index = faiss::read_index(&reader);
|
||||
|
||||
if (auto res = FaissGpuResourceMgr::GetInstance().GetRes(gpu_id_)) {
|
||||
ResScope rs(gpu_id_, res);
|
||||
auto device_index = faiss::gpu::index_cpu_to_gpu(res.get(), gpu_id_, index);
|
||||
index_.reset(device_index);
|
||||
} else {
|
||||
KNOWHERE_THROW_MSG("Load error, can't get gpu resource");
|
||||
}
|
||||
|
||||
delete index;
|
||||
}
|
||||
}
|
||||
|
||||
IVFIndexPtr GPUIVF::Copy_index_gpu_to_cpu() {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
faiss::Index *device_index = index_.get();
|
||||
faiss::Index *host_index = faiss::gpu::index_gpu_to_cpu(device_index);
|
||||
|
||||
std::shared_ptr<faiss::Index> new_index;
|
||||
new_index.reset(host_index);
|
||||
return std::make_shared<IVF>(new_index);
|
||||
}
|
||||
|
||||
void GPUIVF::search_impl(int64_t n,
|
||||
const float *data,
|
||||
int64_t k,
|
||||
float *distances,
|
||||
int64_t *labels,
|
||||
const Config &cfg) {
|
||||
if (auto device_index = std::static_pointer_cast<faiss::gpu::GpuIndexIVF>(index_)) {
|
||||
auto nprobe = cfg.get_with_default("nprobe", size_t(1));
|
||||
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
device_index->setNumProbes(nprobe);
|
||||
device_index->search(n, (float *) data, k, distances, labels);
|
||||
}
|
||||
}
|
||||
|
||||
VectorIndexPtr GPUIVF::CopyGpuToCpu(const Config &config) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
faiss::Index *device_index = index_.get();
|
||||
faiss::Index *host_index = faiss::gpu::index_gpu_to_cpu(device_index);
|
||||
|
||||
std::shared_ptr<faiss::Index> new_index;
|
||||
new_index.reset(host_index);
|
||||
return std::make_shared<IVF>(new_index);
|
||||
}
|
||||
|
||||
VectorIndexPtr GPUIVF::Clone() {
|
||||
auto cpu_idx = CopyGpuToCpu(Config());
|
||||
return ::zilliz::knowhere::CopyCpuToGpu(cpu_idx, gpu_id_, Config());
|
||||
}
|
||||
|
||||
VectorIndexPtr GPUIVF::CopyGpuToGpu(const int64_t &device_id, const Config &config) {
|
||||
auto host_index = CopyGpuToCpu(config);
|
||||
return std::static_pointer_cast<IVF>(host_index)->CopyCpuToGpu(device_id, config);
|
||||
}
|
||||
|
||||
IndexModelPtr GPUIVFPQ::Train(const DatasetPtr &dataset, const Config &config) {
|
||||
auto nlist = config["nlist"].as<size_t>();
|
||||
auto M = config["M"].as<size_t>(); // number of subquantizers(subvectors)
|
||||
auto nbits = config["nbits"].as<size_t>();// number of bit per subvector index
|
||||
auto gpu_num = config.get_with_default("gpu_id", gpu_id_);
|
||||
auto metric_type = config["metric_type"].as_string() == "L2" ?
|
||||
faiss::METRIC_L2 : faiss::METRIC_L2; // IP not support.
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
// TODO(linxj): set device here.
|
||||
faiss::gpu::StandardGpuResources res;
|
||||
faiss::gpu::GpuIndexIVFPQ device_index(&res, dim, nlist, M, nbits, metric_type);
|
||||
device_index.train(rows, (float *) p_data);
|
||||
|
||||
std::shared_ptr<faiss::Index> host_index = nullptr;
|
||||
host_index.reset(faiss::gpu::index_gpu_to_cpu(&device_index));
|
||||
|
||||
return std::make_shared<IVFIndexModel>(host_index);
|
||||
}
|
||||
|
||||
std::shared_ptr<faiss::IVFSearchParameters> GPUIVFPQ::GenParams(const Config &config) {
|
||||
auto params = std::make_shared<faiss::IVFPQSearchParameters>();
|
||||
params->nprobe = config.get_with_default("nprobe", size_t(1));
|
||||
//params->scan_table_threshold = 0;
|
||||
//params->polysemous_ht = 0;
|
||||
//params->max_codes = 0;
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
VectorIndexPtr GPUIVFPQ::CopyGpuToCpu(const Config &config) {
|
||||
KNOWHERE_THROW_MSG("not support yet");
|
||||
}
|
||||
|
||||
IndexModelPtr GPUIVFSQ::Train(const DatasetPtr &dataset, const Config &config) {
|
||||
auto nlist = config["nlist"].as<size_t>();
|
||||
auto nbits = config["nbits"].as<size_t>(); // TODO(linxj): gpu only support SQ4 SQ8 SQ16
|
||||
auto gpu_num = config.get_with_default("gpu_id", gpu_id_);
|
||||
auto metric_type = config["metric_type"].as_string() == "L2" ?
|
||||
faiss::METRIC_L2 : faiss::METRIC_INNER_PRODUCT;
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
std::stringstream index_type;
|
||||
index_type << "IVF" << nlist << "," << "SQ" << nbits;
|
||||
auto build_index = faiss::index_factory(dim, index_type.str().c_str(), metric_type);
|
||||
|
||||
faiss::gpu::StandardGpuResources res;
|
||||
auto device_index = faiss::gpu::index_cpu_to_gpu(&res, gpu_num, build_index);
|
||||
device_index->train(rows, (float *) p_data);
|
||||
|
||||
std::shared_ptr<faiss::Index> host_index = nullptr;
|
||||
host_index.reset(faiss::gpu::index_gpu_to_cpu(device_index));
|
||||
|
||||
delete device_index;
|
||||
delete build_index;
|
||||
|
||||
return std::make_shared<IVFIndexModel>(host_index);
|
||||
}
|
||||
|
||||
VectorIndexPtr GPUIVFSQ::CopyGpuToCpu(const Config &config) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
faiss::Index *device_index = index_.get();
|
||||
faiss::Index *host_index = faiss::gpu::index_gpu_to_cpu(device_index);
|
||||
|
||||
std::shared_ptr<faiss::Index> new_index;
|
||||
new_index.reset(host_index);
|
||||
return std::make_shared<IVFSQ>(new_index);
|
||||
}
|
||||
|
||||
FaissGpuResourceMgr &FaissGpuResourceMgr::GetInstance() {
|
||||
static FaissGpuResourceMgr instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void FaissGpuResourceMgr::AllocateTempMem(std::shared_ptr<faiss::gpu::StandardGpuResources> &res,
|
||||
const int64_t &device_id,
|
||||
const int64_t &size) {
|
||||
if (size) {
|
||||
res->setTempMemory(size);
|
||||
}
|
||||
else {
|
||||
auto search = devices_params_.find(device_id);
|
||||
if (search != devices_params_.end()) {
|
||||
res->setTempMemory(search->second.temp_mem_size);
|
||||
}
|
||||
// else do nothing. allocate when use.
|
||||
}
|
||||
}
|
||||
|
||||
void FaissGpuResourceMgr::InitDevice(int64_t device_id,
|
||||
int64_t pin_mem_size,
|
||||
int64_t temp_mem_size,
|
||||
int64_t res_num) {
|
||||
DeviceParams params;
|
||||
params.pinned_mem_size = pin_mem_size;
|
||||
params.temp_mem_size = temp_mem_size;
|
||||
params.resource_num = res_num;
|
||||
|
||||
devices_params_.emplace(device_id, params);
|
||||
}
|
||||
|
||||
void FaissGpuResourceMgr::InitResource() {
|
||||
for(auto& device : devices_params_) {
|
||||
auto& resource_vec = idle_[device.first];
|
||||
|
||||
for (int i = 0; i < device.second.resource_num; ++i) {
|
||||
auto res = std::make_shared<faiss::gpu::StandardGpuResources>();
|
||||
res->noTempMemory();
|
||||
resource_vec.push_back(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<faiss::gpu::StandardGpuResources> FaissGpuResourceMgr::GetRes(const int64_t &device_id,
|
||||
const int64_t &alloc_size) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
if (!is_init) {
|
||||
InitResource();
|
||||
is_init = true;
|
||||
}
|
||||
|
||||
auto search = idle_.find(device_id);
|
||||
if (search != idle_.end()) {
|
||||
auto res = search->second.back();
|
||||
AllocateTempMem(res, device_id, alloc_size);
|
||||
|
||||
search->second.pop_back();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
void FaissGpuResourceMgr::MoveToInuse(const int64_t &device_id, const std::shared_ptr<faiss::gpu::StandardGpuResources> &res) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
in_use_[device_id].push_back(res);
|
||||
}
|
||||
|
||||
void FaissGpuResourceMgr::MoveToIdle(const int64_t &device_id, const std::shared_ptr<faiss::gpu::StandardGpuResources> &res) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
idle_[device_id].push_back(res);
|
||||
}
|
||||
|
||||
void GPUIndex::SetGpuDevice(const int &gpu_id) {
|
||||
gpu_id_ = gpu_id;
|
||||
}
|
||||
|
||||
const int64_t &GPUIndex::GetGpuDevice() {
|
||||
return gpu_id_;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
231
cpp/src/core/src/knowhere/index/vector_index/idmap.cpp
Normal file
231
cpp/src/core/src/knowhere/index/vector_index/idmap.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <faiss/IndexFlat.h>
|
||||
#include <faiss/AutoTune.h>
|
||||
#include <faiss/MetaIndexes.h>
|
||||
#include <faiss/index_io.h>
|
||||
#include <faiss/gpu/GpuAutoTune.h>
|
||||
|
||||
|
||||
#include "knowhere/common/exception.h"
|
||||
#include "knowhere/adapter/faiss_adopt.h"
|
||||
#include "knowhere/index/vector_index/idmap.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
BinarySet IDMAP::Serialize() {
|
||||
if (!index_) {
|
||||
KNOWHERE_THROW_MSG("index not initialize");
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
return SerializeImpl();
|
||||
}
|
||||
|
||||
void IDMAP::Load(const BinarySet &index_binary) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
LoadImpl(index_binary);
|
||||
}
|
||||
|
||||
DatasetPtr IDMAP::Search(const DatasetPtr &dataset, const Config &config) {
|
||||
if (!index_) {
|
||||
KNOWHERE_THROW_MSG("index not initialize");
|
||||
}
|
||||
|
||||
auto k = config["k"].as<size_t>();
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
// TODO(linxj): handle malloc exception
|
||||
auto elems = rows * k;
|
||||
auto res_ids = (int64_t *) malloc(sizeof(int64_t) * elems);
|
||||
auto res_dis = (float *) malloc(sizeof(float) * elems);
|
||||
|
||||
index_->search(rows, (float *) p_data, k, res_dis, res_ids);
|
||||
|
||||
auto id_buf = MakeMutableBufferSmart((uint8_t *) res_ids, sizeof(int64_t) * elems);
|
||||
auto dist_buf = MakeMutableBufferSmart((uint8_t *) res_dis, sizeof(float) * elems);
|
||||
|
||||
// TODO: magic
|
||||
std::vector<BufferPtr> id_bufs{nullptr, id_buf};
|
||||
std::vector<BufferPtr> dist_bufs{nullptr, dist_buf};
|
||||
|
||||
auto int64_type = std::make_shared<arrow::Int64Type>();
|
||||
auto float_type = std::make_shared<arrow::FloatType>();
|
||||
|
||||
auto id_array_data = arrow::ArrayData::Make(int64_type, elems, id_bufs);
|
||||
auto dist_array_data = arrow::ArrayData::Make(float_type, elems, dist_bufs);
|
||||
|
||||
auto ids = std::make_shared<NumericArray<arrow::Int64Type>>(id_array_data);
|
||||
auto dists = std::make_shared<NumericArray<arrow::FloatType>>(dist_array_data);
|
||||
std::vector<ArrayPtr> array{ids, dists};
|
||||
|
||||
return std::make_shared<Dataset>(array, nullptr);
|
||||
}
|
||||
|
||||
void IDMAP::Add(const DatasetPtr &dataset, const Config &config) {
|
||||
if (!index_) {
|
||||
KNOWHERE_THROW_MSG("index not initialize");
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
GETTENSOR(dataset)
|
||||
|
||||
// TODO: magic here.
|
||||
auto array = dataset->array()[0];
|
||||
auto p_ids = array->data()->GetValues<long>(1, 0);
|
||||
|
||||
index_->add_with_ids(rows, (float *) p_data, p_ids);
|
||||
}
|
||||
|
||||
int64_t IDMAP::Count() {
|
||||
return index_->ntotal;
|
||||
}
|
||||
|
||||
int64_t IDMAP::Dimension() {
|
||||
return index_->d;
|
||||
}
|
||||
|
||||
// TODO(linxj): return const pointer
|
||||
float *IDMAP::GetRawVectors() {
|
||||
try {
|
||||
auto file_index = dynamic_cast<faiss::IndexIDMap *>(index_.get());
|
||||
auto flat_index = dynamic_cast<faiss::IndexFlat*>(file_index->index);
|
||||
return flat_index->xb.data();
|
||||
} catch (std::exception &e) {
|
||||
KNOWHERE_THROW_MSG(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(linxj): return const pointer
|
||||
int64_t *IDMAP::GetRawIds() {
|
||||
try {
|
||||
auto file_index = dynamic_cast<faiss::IndexIDMap *>(index_.get());
|
||||
return file_index->id_map.data();
|
||||
} catch (std::exception &e) {
|
||||
KNOWHERE_THROW_MSG(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
const char* type = "IDMap,Flat";
|
||||
void IDMAP::Train(const Config &config) {
|
||||
auto metric_type = config["metric_type"].as_string() == "L2" ?
|
||||
faiss::METRIC_L2 : faiss::METRIC_INNER_PRODUCT;
|
||||
auto dim = config["dim"].as<size_t>();
|
||||
|
||||
auto index = faiss::index_factory(dim, type, metric_type);
|
||||
index_.reset(index);
|
||||
}
|
||||
|
||||
VectorIndexPtr IDMAP::Clone() {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
auto clone_index = faiss::clone_index(index_.get());
|
||||
std::shared_ptr<faiss::Index> new_index;
|
||||
new_index.reset(clone_index);
|
||||
return std::make_shared<IDMAP>(new_index);
|
||||
}
|
||||
|
||||
VectorIndexPtr IDMAP::CopyCpuToGpu(const int64_t &device_id, const Config &config) {
|
||||
if (auto res = FaissGpuResourceMgr::GetInstance().GetRes(device_id)){
|
||||
ResScope rs(device_id, res);
|
||||
auto gpu_index = faiss::gpu::index_cpu_to_gpu(res.get(), device_id, index_.get());
|
||||
|
||||
std::shared_ptr<faiss::Index> device_index;
|
||||
device_index.reset(gpu_index);
|
||||
return std::make_shared<GPUIDMAP>(device_index, device_id);
|
||||
} else {
|
||||
KNOWHERE_THROW_MSG("CopyCpuToGpu Error, can't get gpu_resource");
|
||||
}
|
||||
}
|
||||
|
||||
void IDMAP::Seal() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
VectorIndexPtr GPUIDMAP::CopyGpuToCpu(const Config &config) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
faiss::Index *device_index = index_.get();
|
||||
faiss::Index *host_index = faiss::gpu::index_gpu_to_cpu(device_index);
|
||||
|
||||
std::shared_ptr<faiss::Index> new_index;
|
||||
new_index.reset(host_index);
|
||||
return std::make_shared<IDMAP>(new_index);
|
||||
}
|
||||
|
||||
VectorIndexPtr GPUIDMAP::Clone() {
|
||||
auto cpu_idx = CopyGpuToCpu(Config());
|
||||
|
||||
if (auto idmap = std::dynamic_pointer_cast<IDMAP>(cpu_idx)){
|
||||
return idmap->CopyCpuToGpu(gpu_id_, Config());
|
||||
}
|
||||
else {
|
||||
KNOWHERE_THROW_MSG("IndexType not Support GpuClone");
|
||||
}
|
||||
}
|
||||
|
||||
BinarySet GPUIDMAP::SerializeImpl() {
|
||||
try {
|
||||
MemoryIOWriter writer;
|
||||
{
|
||||
faiss::Index *index = index_.get();
|
||||
faiss::Index *host_index = faiss::gpu::index_gpu_to_cpu(index);
|
||||
|
||||
faiss::write_index(host_index, &writer);
|
||||
delete host_index;
|
||||
}
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(writer.data_);
|
||||
|
||||
BinarySet res_set;
|
||||
res_set.Append("IVF", data, writer.rp);
|
||||
|
||||
return res_set;
|
||||
} catch (std::exception &e) {
|
||||
KNOWHERE_THROW_MSG(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void GPUIDMAP::LoadImpl(const BinarySet &index_binary) {
|
||||
auto binary = index_binary.GetByName("IVF");
|
||||
MemoryIOReader reader;
|
||||
{
|
||||
reader.total = binary->size;
|
||||
reader.data_ = binary->data.get();
|
||||
|
||||
faiss::Index *index = faiss::read_index(&reader);
|
||||
|
||||
if (auto res = FaissGpuResourceMgr::GetInstance().GetRes(gpu_id_) ){
|
||||
ResScope rs(gpu_id_, res);
|
||||
auto device_index = faiss::gpu::index_cpu_to_gpu(res.get(), gpu_id_, index);
|
||||
index_.reset(device_index);
|
||||
} else {
|
||||
KNOWHERE_THROW_MSG("Load error, can't get gpu resource");
|
||||
}
|
||||
|
||||
delete index;
|
||||
}
|
||||
}
|
||||
|
||||
VectorIndexPtr GPUIDMAP::CopyGpuToGpu(const int64_t &device_id, const Config &config) {
|
||||
auto cpu_index = CopyGpuToCpu(config);
|
||||
return std::static_pointer_cast<IDMAP>(cpu_index)->CopyCpuToGpu(device_id, config);
|
||||
}
|
||||
|
||||
float *GPUIDMAP::GetRawVectors() {
|
||||
KNOWHERE_THROW_MSG("Not support");
|
||||
}
|
||||
|
||||
int64_t *GPUIDMAP::GetRawIds() {
|
||||
KNOWHERE_THROW_MSG("Not support");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
402
cpp/src/core/src/knowhere/index/vector_index/ivf.cpp
Normal file
402
cpp/src/core/src/knowhere/index/vector_index/ivf.cpp
Normal file
@ -0,0 +1,402 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <faiss/IndexFlat.h>
|
||||
#include <faiss/IndexIVF.h>
|
||||
#include <faiss/IndexIVFFlat.h>
|
||||
#include <faiss/IndexIVFPQ.h>
|
||||
#include <faiss/AutoTune.h>
|
||||
#include <faiss/IVFlib.h>
|
||||
#include <faiss/AuxIndexStructures.h>
|
||||
#include <faiss/index_io.h>
|
||||
#include <faiss/gpu/StandardGpuResources.h>
|
||||
#include <faiss/gpu/GpuAutoTune.h>
|
||||
#include <knowhere/index/vector_index/ivf.h>
|
||||
|
||||
|
||||
#include "knowhere/common/exception.h"
|
||||
#include "knowhere/index/vector_index/ivf.h"
|
||||
#include "knowhere/adapter/faiss_adopt.h"
|
||||
#include "knowhere/index/vector_index/gpu_ivf.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
|
||||
IndexModelPtr IVF::Train(const DatasetPtr &dataset, const Config &config) {
|
||||
auto nlist = config["nlist"].as<size_t>();
|
||||
auto metric_type = config["metric_type"].as_string() == "L2" ?
|
||||
faiss::METRIC_L2 : faiss::METRIC_INNER_PRODUCT;
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
faiss::Index *coarse_quantizer = new faiss::IndexFlatL2(dim);
|
||||
auto index = std::make_shared<faiss::IndexIVFFlat>(coarse_quantizer, dim, nlist, metric_type);
|
||||
index->train(rows, (float *) p_data);
|
||||
|
||||
// TODO: override here. train return model or not.
|
||||
return std::make_shared<IVFIndexModel>(index);
|
||||
}
|
||||
|
||||
|
||||
void IVF::Add(const DatasetPtr &dataset, const Config &config) {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("index not initialize or trained");
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
GETTENSOR(dataset)
|
||||
|
||||
// TODO: magic here.
|
||||
auto array = dataset->array()[0];
|
||||
auto p_ids = array->data()->GetValues<long>(1, 0);
|
||||
index_->add_with_ids(rows, (float *) p_data, p_ids);
|
||||
}
|
||||
|
||||
void IVF::AddWithoutIds(const DatasetPtr &dataset, const Config &config) {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("index not initialize or trained");
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
GETTENSOR(dataset)
|
||||
|
||||
index_->add(rows, (float *) p_data);
|
||||
}
|
||||
|
||||
BinarySet IVF::Serialize() {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("index not initialize or trained");
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
Seal();
|
||||
return SerializeImpl();
|
||||
}
|
||||
|
||||
void IVF::Load(const BinarySet &index_binary) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
LoadImpl(index_binary);
|
||||
}
|
||||
|
||||
DatasetPtr IVF::Search(const DatasetPtr &dataset, const Config &config) {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("index not initialize or trained");
|
||||
}
|
||||
|
||||
auto k = config["k"].as<size_t>();
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
// TODO(linxj): handle malloc exception
|
||||
auto elems = rows * k;
|
||||
auto res_ids = (int64_t *) malloc(sizeof(int64_t) * elems);
|
||||
auto res_dis = (float *) malloc(sizeof(float) * elems);
|
||||
|
||||
search_impl(rows, (float*) p_data, k, res_dis, res_ids, config);
|
||||
//faiss::ivflib::search_with_parameters(index_.get(),
|
||||
// rows,
|
||||
// (float *) p_data,
|
||||
// k,
|
||||
// res_dis,
|
||||
// res_ids,
|
||||
// params.get());
|
||||
|
||||
auto id_buf = MakeMutableBufferSmart((uint8_t *) res_ids, sizeof(int64_t) * elems);
|
||||
auto dist_buf = MakeMutableBufferSmart((uint8_t *) res_dis, sizeof(float) * elems);
|
||||
|
||||
// TODO: magic
|
||||
std::vector<BufferPtr> id_bufs{nullptr, id_buf};
|
||||
std::vector<BufferPtr> dist_bufs{nullptr, dist_buf};
|
||||
|
||||
auto int64_type = std::make_shared<arrow::Int64Type>();
|
||||
auto float_type = std::make_shared<arrow::FloatType>();
|
||||
|
||||
auto id_array_data = arrow::ArrayData::Make(int64_type, elems, id_bufs);
|
||||
auto dist_array_data = arrow::ArrayData::Make(float_type, elems, dist_bufs);
|
||||
|
||||
auto ids = std::make_shared<NumericArray<arrow::Int64Type>>(id_array_data);
|
||||
auto dists = std::make_shared<NumericArray<arrow::FloatType>>(dist_array_data);
|
||||
std::vector<ArrayPtr> array{ids, dists};
|
||||
|
||||
return std::make_shared<Dataset>(array, nullptr);
|
||||
}
|
||||
|
||||
void IVF::set_index_model(IndexModelPtr model) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
auto rel_model = std::static_pointer_cast<IVFIndexModel>(model);
|
||||
|
||||
// Deep copy here.
|
||||
index_.reset(faiss::clone_index(rel_model->index_.get()));
|
||||
}
|
||||
|
||||
std::shared_ptr<faiss::IVFSearchParameters> IVF::GenParams(const Config &config) {
|
||||
auto params = std::make_shared<faiss::IVFPQSearchParameters>();
|
||||
params->nprobe = config.get_with_default("nprobe", size_t(1));
|
||||
//params->max_codes = config.get_with_default("max_codes", size_t(0));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
int64_t IVF::Count() {
|
||||
return index_->ntotal;
|
||||
}
|
||||
|
||||
int64_t IVF::Dimension() {
|
||||
return index_->d;
|
||||
}
|
||||
|
||||
void IVF::GenGraph(const int64_t &k, Graph &graph, const DatasetPtr &dataset, const Config &config) {
|
||||
GETTENSOR(dataset)
|
||||
|
||||
auto ntotal = Count();
|
||||
|
||||
auto batch_size = 100;
|
||||
auto tail_batch_size = ntotal % batch_size;
|
||||
auto batch_search_count = ntotal / batch_size;
|
||||
auto total_search_count = tail_batch_size == 0 ? batch_search_count : batch_search_count + 1;
|
||||
|
||||
std::vector<float> res_dis(k * batch_size);
|
||||
graph.resize(ntotal);
|
||||
Graph res_vec(total_search_count);
|
||||
for (int i = 0; i < total_search_count; ++i) {
|
||||
auto b_size = i == total_search_count - 1 && tail_batch_size != 0 ? tail_batch_size : batch_size;
|
||||
|
||||
auto &res = res_vec[i];
|
||||
res.resize(k * b_size);
|
||||
|
||||
auto xq = p_data + batch_size * dim * i;
|
||||
search_impl(b_size, (float*)xq, k, res_dis.data(), res.data(), config);
|
||||
|
||||
int tmp = 0;
|
||||
for (int j = 0; j < b_size; ++j) {
|
||||
auto &node = graph[batch_size * i + j];
|
||||
node.resize(k);
|
||||
for (int m = 0; m < k && tmp < k * b_size; ++m, ++tmp) {
|
||||
// TODO(linxj): avoid memcopy here.
|
||||
node[m] = res[tmp];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IVF::search_impl(int64_t n,
|
||||
const float *data,
|
||||
int64_t k,
|
||||
float *distances,
|
||||
int64_t *labels,
|
||||
const Config &cfg) {
|
||||
auto params = GenParams(cfg);
|
||||
faiss::ivflib::search_with_parameters(index_.get(), n, (float *) data, k, distances, labels, params.get());
|
||||
}
|
||||
|
||||
VectorIndexPtr IVF::CopyCpuToGpu(const int64_t& device_id, const Config &config) {
|
||||
if (auto res = FaissGpuResourceMgr::GetInstance().GetRes(device_id)){
|
||||
ResScope rs(device_id, res);
|
||||
auto gpu_index = faiss::gpu::index_cpu_to_gpu(res.get(), device_id, index_.get());
|
||||
|
||||
std::shared_ptr<faiss::Index> device_index;
|
||||
device_index.reset(gpu_index);
|
||||
return std::make_shared<GPUIVF>(device_index, device_id);
|
||||
} else {
|
||||
KNOWHERE_THROW_MSG("CopyCpuToGpu Error, can't get gpu_resource");
|
||||
}
|
||||
}
|
||||
|
||||
VectorIndexPtr IVF::Clone() {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
|
||||
auto clone_index = faiss::clone_index(index_.get());
|
||||
std::shared_ptr<faiss::Index> new_index;
|
||||
new_index.reset(clone_index);
|
||||
return Clone_impl(new_index);
|
||||
}
|
||||
|
||||
VectorIndexPtr IVF::Clone_impl(const std::shared_ptr<faiss::Index> &index) {
|
||||
return std::make_shared<IVF>(index);
|
||||
}
|
||||
|
||||
void IVF::Seal() {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("index not initialize or trained");
|
||||
}
|
||||
SealImpl();
|
||||
}
|
||||
|
||||
|
||||
IVFIndexModel::IVFIndexModel(std::shared_ptr<faiss::Index> index) : BasicIndex(std::move(index)) {}
|
||||
|
||||
BinarySet IVFIndexModel::Serialize() {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("indexmodel not initialize or trained");
|
||||
}
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
return SerializeImpl();
|
||||
}
|
||||
|
||||
void IVFIndexModel::Load(const BinarySet &binary_set) {
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
LoadImpl(binary_set);
|
||||
}
|
||||
|
||||
void IVFIndexModel::SealImpl() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
IndexModelPtr IVFSQ::Train(const DatasetPtr &dataset, const Config &config) {
|
||||
auto nlist = config["nlist"].as<size_t>();
|
||||
auto nbits = config["nbits"].as<size_t>(); // TODO(linxj): only support SQ4 SQ6 SQ8 SQ16
|
||||
auto metric_type = config["metric_type"].as_string() == "L2" ?
|
||||
faiss::METRIC_L2 : faiss::METRIC_INNER_PRODUCT;
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
std::stringstream index_type;
|
||||
index_type << "IVF" << nlist << "," << "SQ" << nbits;
|
||||
auto build_index = faiss::index_factory(dim, index_type.str().c_str(), metric_type);
|
||||
build_index->train(rows, (float *) p_data);
|
||||
|
||||
std::shared_ptr<faiss::Index> ret_index;
|
||||
ret_index.reset(build_index);
|
||||
return std::make_shared<IVFIndexModel>(ret_index);
|
||||
}
|
||||
|
||||
VectorIndexPtr IVFSQ::Clone_impl(const std::shared_ptr<faiss::Index> &index) {
|
||||
return std::make_shared<IVFSQ>(index);
|
||||
}
|
||||
|
||||
VectorIndexPtr IVFSQ::CopyCpuToGpu(const int64_t &device_id, const Config &config) {
|
||||
if (auto res = FaissGpuResourceMgr::GetInstance().GetRes(device_id)){
|
||||
ResScope rs(device_id, res);
|
||||
faiss::gpu::GpuClonerOptions option;
|
||||
option.allInGpu = true;
|
||||
|
||||
auto gpu_index = faiss::gpu::index_cpu_to_gpu(res.get(), device_id, index_.get(), &option);
|
||||
|
||||
std::shared_ptr<faiss::Index> device_index;
|
||||
device_index.reset(gpu_index);
|
||||
return std::make_shared<GPUIVFSQ>(device_index, device_id);
|
||||
} else {
|
||||
KNOWHERE_THROW_MSG("CopyCpuToGpu Error, can't get gpu_resource");
|
||||
}
|
||||
}
|
||||
|
||||
IndexModelPtr IVFPQ::Train(const DatasetPtr &dataset, const Config &config) {
|
||||
auto nlist = config["nlist"].as<size_t>();
|
||||
auto M = config["M"].as<size_t>(); // number of subquantizers(subvector)
|
||||
auto nbits = config["nbits"].as<size_t>();// number of bit per subvector index
|
||||
auto metric_type = config["metric_type"].as_string() == "L2" ?
|
||||
faiss::METRIC_L2 : faiss::METRIC_INNER_PRODUCT;
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
faiss::Index *coarse_quantizer = new faiss::IndexFlat(dim, metric_type);
|
||||
auto index = std::make_shared<faiss::IndexIVFPQ>(coarse_quantizer, dim, nlist, M, nbits);
|
||||
index->train(rows, (float *) p_data);
|
||||
|
||||
return std::make_shared<IVFIndexModel>(index);
|
||||
}
|
||||
|
||||
std::shared_ptr<faiss::IVFSearchParameters> IVFPQ::GenParams(const Config &config) {
|
||||
auto params = std::make_shared<faiss::IVFPQSearchParameters>();
|
||||
params->nprobe = config.get_with_default("nprobe", size_t(1));
|
||||
//params->scan_table_threshold = 0;
|
||||
//params->polysemous_ht = 0;
|
||||
//params->max_codes = 0;
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
VectorIndexPtr IVFPQ::Clone_impl(const std::shared_ptr<faiss::Index> &index) {
|
||||
return std::make_shared<IVFPQ>(index);
|
||||
}
|
||||
|
||||
BasicIndex::BasicIndex(std::shared_ptr<faiss::Index> index) : index_(std::move(index)) {}
|
||||
|
||||
BinarySet BasicIndex::SerializeImpl() {
|
||||
try {
|
||||
faiss::Index *index = index_.get();
|
||||
|
||||
SealImpl();
|
||||
|
||||
MemoryIOWriter writer;
|
||||
faiss::write_index(index, &writer);
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(writer.data_);
|
||||
|
||||
BinarySet res_set;
|
||||
// TODO(linxj): use virtual func Name() instead of raw string.
|
||||
res_set.Append("IVF", data, writer.rp);
|
||||
return res_set;
|
||||
} catch (std::exception &e) {
|
||||
KNOWHERE_THROW_MSG(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void BasicIndex::LoadImpl(const BinarySet &index_binary) {
|
||||
auto binary = index_binary.GetByName("IVF");
|
||||
|
||||
MemoryIOReader reader;
|
||||
reader.total = binary->size;
|
||||
reader.data_ = binary->data.get();
|
||||
|
||||
faiss::Index *index = faiss::read_index(&reader);
|
||||
|
||||
index_.reset(index);
|
||||
}
|
||||
|
||||
void BasicIndex::SealImpl() {
|
||||
//#ifdef ZILLIZ_FAISS
|
||||
faiss::Index *index = index_.get();
|
||||
auto idx = dynamic_cast<faiss::IndexIVF *>(index);
|
||||
if (idx != nullptr) {
|
||||
idx->to_readonly();
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
|
||||
// TODO(linxj): Get From Config File
|
||||
static size_t magic_num = 2;
|
||||
size_t MemoryIOWriter::operator()(const void *ptr, size_t size, size_t nitems) {
|
||||
auto total_need = size * nitems + rp;
|
||||
|
||||
if (!data_) { // data == nullptr
|
||||
total = total_need * magic_num;
|
||||
rp = size * nitems;
|
||||
data_ = new uint8_t[total];
|
||||
memcpy((void *) (data_), ptr, rp);
|
||||
}
|
||||
|
||||
if (total_need > total) {
|
||||
total = total_need * magic_num;
|
||||
auto new_data = new uint8_t[total];
|
||||
memcpy((void *) new_data, (void *) data_, rp);
|
||||
delete data_;
|
||||
data_ = new_data;
|
||||
|
||||
memcpy((void *) (data_ + rp), ptr, size * nitems);
|
||||
rp = total_need;
|
||||
} else {
|
||||
memcpy((void *) (data_ + rp), ptr, size * nitems);
|
||||
rp = total_need;
|
||||
}
|
||||
|
||||
return nitems;
|
||||
}
|
||||
|
||||
size_t MemoryIOReader::operator()(void *ptr, size_t size, size_t nitems) {
|
||||
if (rp >= total) return 0;
|
||||
size_t nremain = (total - rp) / size;
|
||||
if (nremain < nitems) nitems = nremain;
|
||||
memcpy(ptr, (void *) (data_ + rp), size * nitems);
|
||||
rp += size * nitems;
|
||||
return nitems;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
|
||||
#include <mutex>
|
||||
#include "knowhere/index/vector_index/kdt_parameters.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
const std::vector<KDTParameter> &
|
||||
KDTParameterManagement::GetKDTParameters() {
|
||||
return kdt_parameters_;
|
||||
}
|
||||
|
||||
KDTParameterManagement::KDTParameterManagement() {
|
||||
kdt_parameters_ = std::vector<KDTParameter>{
|
||||
{"KDTNumber", "1"},
|
||||
{"NumTopDimensionKDTSplit", "5"},
|
||||
{"NumSamplesKDTSplitConsideration", "100"},
|
||||
|
||||
{"TPTNumber", "32"},
|
||||
{"TPTLeafSize", "2000"},
|
||||
{"NumTopDimensionTPTSplit", "5"},
|
||||
|
||||
{"NeighborhoodSize", "32"},
|
||||
{"GraphNeighborhoodScale", "2"},
|
||||
{"GraphCEFScale", "2"},
|
||||
{"RefineIterations", "0"},
|
||||
{"CEF", "1000"},
|
||||
{"MaxCheckForRefineGraph", "10000"},
|
||||
|
||||
{"NumberOfThreads", "1"},
|
||||
|
||||
{"MaxCheck", "8192"},
|
||||
{"ThresholdOfNumberOfContinuousNoBetterPropagation", "3"},
|
||||
{"NumberOfInitialDynamicPivots", "50"},
|
||||
{"NumberOfOtherDynamicPivots", "4"},
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
} // namespace zilliz
|
||||
20
cpp/src/core/src/knowhere/index/vector_index/nsg/index_io.h
Normal file
20
cpp/src/core/src/knowhere/index/vector_index/nsg/index_io.h
Normal file
@ -0,0 +1,20 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "knowhere/index/vector_index/nsg/nsg.h"
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
namespace algo {
|
||||
|
||||
void read_from_file(NsgIndex* index, const char *filename);
|
||||
void write_to_file(NsgIndex* index, const char *filename);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
752
cpp/src/core/src/knowhere/index/vector_index/nsg/nsg.cpp
Normal file
752
cpp/src/core/src/knowhere/index/vector_index/nsg/nsg.cpp
Normal file
@ -0,0 +1,752 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stack>
|
||||
#include <omp.h>
|
||||
|
||||
#include "knowhere/index/vector_index/nsg/nsg.h"
|
||||
#include "knowhere/common/exception.h"
|
||||
#include "knowhere/common/timer.h"
|
||||
#include "utils.h"
|
||||
|
||||
// TODO: enable macro
|
||||
//#include <gperftools/profiler.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
namespace algo {
|
||||
|
||||
|
||||
NsgIndex::NsgIndex(const size_t &dimension, const size_t &n, MetricType metric)
|
||||
: dimension(dimension), ntotal(n), metric_type(metric) {
|
||||
}
|
||||
|
||||
NsgIndex::~NsgIndex() {
|
||||
delete[] ori_data_;
|
||||
delete[] ids_;
|
||||
}
|
||||
|
||||
//void NsgIndex::Build(size_t nb, const float *data, const BuildParam ¶meters) {
|
||||
//}
|
||||
void NsgIndex::Build_with_ids(size_t nb, const float *data, const long *ids, const BuildParams ¶meters) {
|
||||
TimeRecorder rc("NSG");
|
||||
|
||||
ntotal = nb;
|
||||
ori_data_ = new float[ntotal * dimension];
|
||||
ids_ = new long[ntotal];
|
||||
memcpy((void *) ori_data_, (void *) data, sizeof(float) * ntotal * dimension);
|
||||
memcpy((void *) ids_, (void *) ids, sizeof(long) * ntotal);
|
||||
|
||||
search_length = parameters.search_length;
|
||||
out_degree = parameters.out_degree;
|
||||
candidate_pool_size = parameters.candidate_pool_size;
|
||||
|
||||
InitNavigationPoint();
|
||||
rc.RecordSection("init");
|
||||
|
||||
Link();
|
||||
rc.RecordSection("Link");
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//int count = 0;
|
||||
//for (int i = 0; i < ntotal; ++i) {
|
||||
// count += nsg[i].size();
|
||||
//}
|
||||
/////
|
||||
|
||||
CheckConnectivity();
|
||||
rc.RecordSection("Connect");
|
||||
|
||||
//>> Debug code
|
||||
///
|
||||
int total_degree = 0;
|
||||
for (int i = 0; i < ntotal; ++i) {
|
||||
total_degree += nsg[i].size();
|
||||
}
|
||||
std::cout << "graph physical size: " << total_degree * sizeof(node_t) / 1024 / 1024;
|
||||
std::cout << "average degree: " << total_degree / ntotal;
|
||||
/////
|
||||
|
||||
is_trained = true;
|
||||
}
|
||||
|
||||
void NsgIndex::InitNavigationPoint() {
|
||||
// calculate the center of vectors
|
||||
auto center = new float[dimension];
|
||||
memset(center, 0, sizeof(float) * dimension);
|
||||
|
||||
for (size_t i = 0; i < ntotal; i++) {
|
||||
for (size_t j = 0; j < dimension; j++) {
|
||||
center[j] += ori_data_[i * dimension + j];
|
||||
}
|
||||
}
|
||||
for (size_t j = 0; j < dimension; j++) {
|
||||
center[j] /= ntotal;
|
||||
}
|
||||
|
||||
// select navigation point
|
||||
std::vector<Neighbor> resset, fullset;
|
||||
navigation_point = rand() % ntotal; // random initialize navigating point
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//navigation_point = drand48();
|
||||
/////
|
||||
|
||||
GetNeighbors(center, resset, knng);
|
||||
navigation_point = resset[0].id;
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//std::cout << "ep: " << navigation_point << std::endl;
|
||||
/////
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//float r1 = calculate(center, ori_data_ + navigation_point * dimension, dimension);
|
||||
//assert(r1 == resset[0].distance);
|
||||
/////
|
||||
}
|
||||
|
||||
// Specify Link
|
||||
void NsgIndex::GetNeighbors(const float *query,
|
||||
std::vector<Neighbor> &resset,
|
||||
std::vector<Neighbor> &fullset,
|
||||
boost::dynamic_bitset<> &has_calculated_dist) {
|
||||
auto &graph = knng;
|
||||
size_t buffer_size = search_length;
|
||||
|
||||
if (buffer_size > ntotal) {
|
||||
// TODO: throw exception here.
|
||||
}
|
||||
|
||||
std::vector<node_t> init_ids;
|
||||
|
||||
{
|
||||
/*
|
||||
* copy navigation-point neighbor, pick random node if less than buffer size
|
||||
*/
|
||||
size_t count = 0;
|
||||
|
||||
// Get all neighbors
|
||||
for (size_t i = 0; i < graph[navigation_point].size(); ++i) {
|
||||
init_ids.push_back(graph[navigation_point][i]);
|
||||
has_calculated_dist[init_ids[i]] = true;
|
||||
++count;
|
||||
}
|
||||
while (count < buffer_size) {
|
||||
node_t id = rand() % ntotal;
|
||||
if (has_calculated_dist[id]) continue; // duplicate id
|
||||
init_ids.push_back(id);
|
||||
++count;
|
||||
has_calculated_dist[id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
resset.resize(init_ids.size());
|
||||
|
||||
// init resset and sort by distance
|
||||
for (size_t i = 0; i < init_ids.size(); ++i) {
|
||||
node_t id = init_ids[i];
|
||||
|
||||
if (id >= ntotal) {
|
||||
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
|
||||
continue;
|
||||
}
|
||||
|
||||
float dist = calculate(ori_data_ + dimension * id, query, dimension);
|
||||
resset[i] = Neighbor(id, dist, false);
|
||||
|
||||
///////////// difference from other GetNeighbors ///////////////
|
||||
fullset.push_back(resset[i]);
|
||||
///////////////////////////////////////
|
||||
}
|
||||
std::sort(resset.begin(), resset.end()); // sort by distance
|
||||
|
||||
//search nearest neighbor
|
||||
size_t cursor = 0;
|
||||
while (cursor < buffer_size) {
|
||||
size_t nearest_updated_pos = buffer_size;
|
||||
|
||||
if (!resset[cursor].has_explored) {
|
||||
resset[cursor].has_explored = true;
|
||||
|
||||
node_t start_pos = resset[cursor].id;
|
||||
auto &wait_for_search_node_vec = graph[start_pos];
|
||||
for (size_t i = 0; i < wait_for_search_node_vec.size(); ++i) {
|
||||
node_t id = wait_for_search_node_vec[i];
|
||||
if (has_calculated_dist[id]) continue;
|
||||
has_calculated_dist[id] = true;
|
||||
|
||||
float
|
||||
dist = calculate(query, ori_data_ + dimension * id, dimension);
|
||||
Neighbor nn(id, dist, false);
|
||||
fullset.push_back(nn);
|
||||
|
||||
if (dist >= resset[buffer_size - 1].distance) continue;
|
||||
|
||||
size_t pos = InsertIntoPool(resset.data(), buffer_size, nn); // replace with a closer node
|
||||
if (pos < nearest_updated_pos) nearest_updated_pos = pos;
|
||||
|
||||
//assert(buffer_size + 1 >= resset.size());
|
||||
if (buffer_size + 1 < resset.size()) ++buffer_size;
|
||||
}
|
||||
}
|
||||
if (cursor >= nearest_updated_pos) {
|
||||
cursor = nearest_updated_pos; // re-search from new pos
|
||||
} else ++cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FindUnconnectedNode
|
||||
void NsgIndex::GetNeighbors(const float *query, std::vector<Neighbor> &resset, std::vector<Neighbor> &fullset) {
|
||||
auto &graph = nsg;
|
||||
size_t buffer_size = search_length;
|
||||
|
||||
if (buffer_size > ntotal) {
|
||||
// TODO: throw exception here.
|
||||
}
|
||||
|
||||
std::vector<node_t> init_ids;
|
||||
boost::dynamic_bitset<> has_calculated_dist{ntotal, 0}; // TODO: ?
|
||||
|
||||
{
|
||||
/*
|
||||
* copy navigation-point neighbor, pick random node if less than buffer size
|
||||
*/
|
||||
size_t count = 0;
|
||||
|
||||
// Get all neighbors
|
||||
for (size_t i = 0; i < graph[navigation_point].size(); ++i) {
|
||||
init_ids.push_back(graph[navigation_point][i]);
|
||||
has_calculated_dist[init_ids[i]] = true;
|
||||
++count;
|
||||
}
|
||||
while (count < buffer_size) {
|
||||
node_t id = rand() % ntotal;
|
||||
if (has_calculated_dist[id]) continue; // duplicate id
|
||||
init_ids.push_back(id);
|
||||
++count;
|
||||
has_calculated_dist[id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
resset.resize(init_ids.size());
|
||||
|
||||
// init resset and sort by distance
|
||||
for (size_t i = 0; i < init_ids.size(); ++i) {
|
||||
node_t id = init_ids[i];
|
||||
|
||||
if (id >= ntotal) {
|
||||
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
|
||||
continue;
|
||||
}
|
||||
|
||||
float dist = calculate(ori_data_ + id * dimension, query, dimension);
|
||||
resset[i] = Neighbor(id, dist, false);
|
||||
}
|
||||
std::sort(resset.begin(), resset.end()); // sort by distance
|
||||
|
||||
// search nearest neighbor
|
||||
size_t cursor = 0;
|
||||
while (cursor < buffer_size) {
|
||||
size_t nearest_updated_pos = buffer_size;
|
||||
|
||||
if (!resset[cursor].has_explored) {
|
||||
resset[cursor].has_explored = true;
|
||||
|
||||
node_t start_pos = resset[cursor].id;
|
||||
auto &wait_for_search_node_vec = graph[start_pos];
|
||||
for (size_t i = 0; i < wait_for_search_node_vec.size(); ++i) {
|
||||
node_t id = wait_for_search_node_vec[i];
|
||||
if (has_calculated_dist[id]) continue;
|
||||
has_calculated_dist[id] = true;
|
||||
|
||||
float
|
||||
dist = calculate(ori_data_ + dimension * id, query, dimension);
|
||||
Neighbor nn(id, dist, false);
|
||||
fullset.push_back(nn);
|
||||
|
||||
if (dist >= resset[buffer_size - 1].distance) continue;
|
||||
|
||||
size_t pos = InsertIntoPool(resset.data(), buffer_size, nn); // replace with a closer node
|
||||
if (pos < nearest_updated_pos) nearest_updated_pos = pos;
|
||||
|
||||
//assert(buffer_size + 1 >= resset.size());
|
||||
if (buffer_size + 1 < resset.size()) ++buffer_size; // trick
|
||||
}
|
||||
}
|
||||
if (cursor >= nearest_updated_pos) {
|
||||
cursor = nearest_updated_pos; // re-search from new pos
|
||||
} else ++cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NsgIndex::GetNeighbors(const float *query,
|
||||
std::vector<Neighbor> &resset,
|
||||
Graph &graph,
|
||||
SearchParams *params) {
|
||||
size_t &buffer_size = params ? params->search_length : search_length;
|
||||
|
||||
if (buffer_size > ntotal) {
|
||||
// TODO: throw exception here.
|
||||
}
|
||||
|
||||
std::vector<node_t> init_ids;
|
||||
boost::dynamic_bitset<> has_calculated_dist{ntotal, 0};
|
||||
|
||||
{
|
||||
/*
|
||||
* copy navigation-point neighbor, pick random node if less than buffer size
|
||||
*/
|
||||
size_t count = 0;
|
||||
|
||||
// Get all neighbors
|
||||
for (size_t i = 0; i < graph[navigation_point].size(); ++i) {
|
||||
init_ids.push_back(graph[navigation_point][i]);
|
||||
has_calculated_dist[init_ids[i]] = true;
|
||||
++count;
|
||||
}
|
||||
while (count < buffer_size) {
|
||||
node_t id = rand() % ntotal;
|
||||
if (has_calculated_dist[id]) continue; // duplicate id
|
||||
init_ids.push_back(id);
|
||||
++count;
|
||||
has_calculated_dist[id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
resset.resize(init_ids.size());
|
||||
|
||||
// init resset and sort by distance
|
||||
for (size_t i = 0; i < init_ids.size(); ++i) {
|
||||
node_t id = init_ids[i];
|
||||
|
||||
//assert(id < ntotal);
|
||||
if (id >= ntotal) {
|
||||
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
|
||||
continue;
|
||||
}
|
||||
|
||||
float dist = calculate(ori_data_ + id * dimension, query, dimension);
|
||||
resset[i] = Neighbor(id, dist, false);
|
||||
}
|
||||
std::sort(resset.begin(), resset.end()); // sort by distance
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//for (int j = 0; j < buffer_size; ++j) {
|
||||
// std::cout << "resset_id: " << resset[j].id << ", resset_dist: " << resset[j].distance << std::endl;
|
||||
//}
|
||||
/////
|
||||
|
||||
// search nearest neighbor
|
||||
size_t cursor = 0;
|
||||
while (cursor < buffer_size) {
|
||||
size_t nearest_updated_pos = buffer_size;
|
||||
|
||||
if (!resset[cursor].has_explored) {
|
||||
resset[cursor].has_explored = true;
|
||||
|
||||
node_t start_pos = resset[cursor].id;
|
||||
auto &wait_for_search_node_vec = graph[start_pos];
|
||||
for (size_t i = 0; i < wait_for_search_node_vec.size(); ++i) {
|
||||
node_t id = wait_for_search_node_vec[i];
|
||||
if (has_calculated_dist[id]) continue;
|
||||
has_calculated_dist[id] = true;
|
||||
|
||||
float
|
||||
dist = calculate(query, ori_data_ + dimension * id, dimension);
|
||||
|
||||
if (dist >= resset[buffer_size - 1].distance) continue;
|
||||
///////////// difference from other GetNeighbors ///////////////
|
||||
Neighbor nn(id, dist, false);
|
||||
///////////////////////////////////////
|
||||
|
||||
size_t pos = InsertIntoPool(resset.data(), buffer_size, nn); // replace with a closer node
|
||||
if (pos < nearest_updated_pos) nearest_updated_pos = pos;
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//std::cout << "pos: " << pos << ", nn: " << nn.id << ":" << nn.distance << ", nup: " << nearest_updated_pos << std::endl;
|
||||
/////
|
||||
|
||||
|
||||
// trick: avoid search query search_length < init_ids.size() ...
|
||||
if (buffer_size + 1 < resset.size()) ++buffer_size;
|
||||
}
|
||||
}
|
||||
if (cursor >= nearest_updated_pos) {
|
||||
cursor = nearest_updated_pos; // re-search from new pos
|
||||
} else ++cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NsgIndex::Link() {
|
||||
auto cut_graph_dist = new float[ntotal * out_degree];
|
||||
nsg.resize(ntotal);
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
std::vector<Neighbor> fullset;
|
||||
std::vector<Neighbor> temp;
|
||||
boost::dynamic_bitset<> flags{ntotal, 0}; // TODO: ?
|
||||
#pragma omp for schedule(dynamic, 100)
|
||||
for (size_t n = 0; n < ntotal; ++n) {
|
||||
fullset.clear();
|
||||
flags.reset();
|
||||
GetNeighbors(ori_data_ + dimension * n, temp, fullset, flags);
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//float r1 = calculate(ori_data_ + n * dimension, ori_data_ + temp[0].id * dimension, dimension);
|
||||
//assert(r1 == temp[0].distance);
|
||||
/////
|
||||
SyncPrune(n, fullset, flags, cut_graph_dist);
|
||||
}
|
||||
}
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//auto bak_nsg = nsg;
|
||||
/////
|
||||
|
||||
knng.clear();
|
||||
knng.shrink_to_fit();
|
||||
|
||||
std::vector<std::mutex> mutex_vec(ntotal);
|
||||
|
||||
#pragma omp for schedule(dynamic, 100)
|
||||
for (unsigned n = 0; n < ntotal; ++n) {
|
||||
InterInsert(n, mutex_vec, cut_graph_dist);
|
||||
}
|
||||
delete[] cut_graph_dist;
|
||||
|
||||
//>> Debug code
|
||||
/////
|
||||
//int count = 0;
|
||||
//for (int i = 0; i < ntotal; ++i) {
|
||||
// if (bak_nsg[i].size() != nsg[i].size()) {
|
||||
// //count += nsg[i].size() - bak_nsg[i].size();
|
||||
// count += nsg[i].size();
|
||||
// }
|
||||
//}
|
||||
/////
|
||||
|
||||
for (int i = 0; i < ntotal; ++i) {
|
||||
nsg[i].shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
void NsgIndex::SyncPrune(size_t n,
|
||||
std::vector<Neighbor> &pool,
|
||||
boost::dynamic_bitset<> &has_calculated,
|
||||
float *cut_graph_dist) {
|
||||
// avoid lose nearest neighbor in knng
|
||||
for (size_t i = 0; i < knng[n].size(); ++i) {
|
||||
auto id = knng[n][i];
|
||||
if (has_calculated[id]) continue;
|
||||
float dist = calculate(ori_data_ + dimension * n,
|
||||
ori_data_ + dimension * id, dimension);
|
||||
pool.emplace_back(Neighbor(id, dist, true));
|
||||
}
|
||||
|
||||
// sort and find closest node
|
||||
unsigned cursor = 0;
|
||||
std::sort(pool.begin(), pool.end());
|
||||
std::vector<Neighbor> result;
|
||||
if (pool[cursor].id == n) cursor++;
|
||||
result.push_back(pool[cursor]); // init result with nearest neighbor
|
||||
|
||||
SelectEdge(cursor, pool, result, true);
|
||||
|
||||
// filling the cut_graph
|
||||
auto &des_id_pool = nsg[n];
|
||||
float *des_dist_pool = cut_graph_dist + n * out_degree;
|
||||
for (size_t i = 0; i < result.size(); ++i) {
|
||||
des_id_pool.push_back(result[i].id);
|
||||
des_dist_pool[i] = result[i].distance;
|
||||
}
|
||||
if (result.size() < out_degree) {
|
||||
des_dist_pool[result.size()] = -1;
|
||||
}
|
||||
//>> Optimize: reserve id_pool capacity
|
||||
}
|
||||
|
||||
//>> Optimize: remove read-lock
|
||||
void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float *cut_graph_dist) {
|
||||
auto ¤t = n;
|
||||
|
||||
auto &neighbor_id_pool = nsg[current];
|
||||
float *neighbor_dist_pool = cut_graph_dist + current * out_degree;
|
||||
for (size_t i = 0; i < out_degree; ++i) {
|
||||
if (neighbor_dist_pool[i] == -1) break;
|
||||
|
||||
size_t current_neighbor = neighbor_id_pool[i]; // center's neighbor id
|
||||
auto &nsn_id_pool = nsg[current_neighbor]; // nsn => neighbor's neighbor
|
||||
float *nsn_dist_pool = cut_graph_dist + current_neighbor * out_degree;
|
||||
|
||||
std::vector<Neighbor> wait_for_link_pool; // maintain candidate neighbor of the current neighbor.
|
||||
int duplicate = false;
|
||||
{
|
||||
LockGuard lk(mutex_vec[current_neighbor]);
|
||||
for (int j = 0; j < out_degree; ++j) {
|
||||
if (nsn_dist_pool[j] == -1) break;
|
||||
|
||||
// 保证至少有一条边能连回来
|
||||
if (n == nsn_id_pool[j]) {
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Neighbor nsn(nsn_id_pool[j], nsn_dist_pool[j]);
|
||||
wait_for_link_pool.push_back(nsn);
|
||||
}
|
||||
}
|
||||
if (duplicate) continue;
|
||||
|
||||
// original: (neighbor) <------- (current)
|
||||
// after: (neighbor) -------> (current)
|
||||
// current node as a neighbor of its neighbor
|
||||
Neighbor current_as_neighbor(n, neighbor_dist_pool[i]);
|
||||
wait_for_link_pool.push_back(current_as_neighbor);
|
||||
|
||||
// re-selectEdge if candidate neighbor num > out_degree
|
||||
if (wait_for_link_pool.size() > out_degree) {
|
||||
std::vector<Neighbor> result;
|
||||
|
||||
unsigned start = 0;
|
||||
std::sort(wait_for_link_pool.begin(), wait_for_link_pool.end());
|
||||
result.push_back(wait_for_link_pool[start]);
|
||||
|
||||
SelectEdge(start, wait_for_link_pool, result);
|
||||
|
||||
{
|
||||
LockGuard lk(mutex_vec[current_neighbor]);
|
||||
for (int j = 0; j < result.size(); ++j) {
|
||||
nsn_id_pool[j] = result[j].id;
|
||||
nsn_dist_pool[j] = result[j].distance;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LockGuard lk(mutex_vec[current_neighbor]);
|
||||
for (int j = 0; j < out_degree; ++j) {
|
||||
if (nsn_dist_pool[j] == -1) {
|
||||
nsn_id_pool.push_back(current_as_neighbor.id);
|
||||
nsn_dist_pool[j] = current_as_neighbor.distance;
|
||||
if (j + 1 < out_degree) nsn_dist_pool[j + 1] = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void NsgIndex::SelectEdge(unsigned &cursor,
|
||||
std::vector<Neighbor> &sort_pool,
|
||||
std::vector<Neighbor> &result,
|
||||
bool limit) {
|
||||
auto &pool = sort_pool;
|
||||
|
||||
/*
|
||||
* edge selection
|
||||
*
|
||||
* search in pool and search deepth is under candidate_pool_size
|
||||
* max result size equal to out_degress
|
||||
*/
|
||||
size_t search_deepth = limit ? candidate_pool_size : pool.size();
|
||||
while (result.size() < out_degree && cursor < search_deepth && (++cursor) < pool.size()) {
|
||||
auto &p = pool[cursor];
|
||||
bool should_link = true;
|
||||
for (size_t t = 0; t < result.size(); ++t) {
|
||||
float dist = calculate(ori_data_ + dimension * result[t].id,
|
||||
ori_data_ + dimension * p.id, dimension);
|
||||
|
||||
if (dist < p.distance) {
|
||||
should_link = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (should_link) result.push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
void NsgIndex::CheckConnectivity() {
|
||||
auto root = navigation_point;
|
||||
boost::dynamic_bitset<> has_linked{ntotal, 0};
|
||||
int64_t linked_count = 0;
|
||||
|
||||
while (linked_count < ntotal) {
|
||||
DFS(root, has_linked, linked_count);
|
||||
if (linked_count >= ntotal) break;
|
||||
FindUnconnectedNode(has_linked, root);
|
||||
}
|
||||
}
|
||||
|
||||
void NsgIndex::DFS(size_t root, boost::dynamic_bitset<> &has_linked, int64_t &linked_count) {
|
||||
size_t start = root;
|
||||
std::stack<size_t> s;
|
||||
s.push(root);
|
||||
if (!has_linked[root]) {
|
||||
linked_count++; // not link
|
||||
has_linked[root] = true; // link start...
|
||||
}
|
||||
|
||||
while (!s.empty()) {
|
||||
size_t next = ntotal + 1;
|
||||
|
||||
for (unsigned i = 0; i < nsg[start].size(); i++) {
|
||||
if (has_linked[nsg[start][i]] == false) // if not link
|
||||
{
|
||||
next = nsg[start][i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (next == (ntotal + 1)) {
|
||||
s.pop();
|
||||
if (s.empty()) break;
|
||||
start = s.top();
|
||||
continue;
|
||||
}
|
||||
start = next;
|
||||
has_linked[start] = true;
|
||||
s.push(start);
|
||||
++linked_count;
|
||||
}
|
||||
}
|
||||
|
||||
void NsgIndex::FindUnconnectedNode(boost::dynamic_bitset<> &has_linked, int64_t &root) {
|
||||
// find any of unlinked-node
|
||||
size_t id = ntotal;
|
||||
for (size_t i = 0; i < ntotal; i++) { // find not link
|
||||
if (has_linked[i] == false) {
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (id == ntotal) return; // No Unlinked Node
|
||||
|
||||
// search unlinked-node's neighbor
|
||||
std::vector<Neighbor> tmp, pool;
|
||||
GetNeighbors(ori_data_ + dimension * id, tmp, pool);
|
||||
std::sort(pool.begin(), pool.end());
|
||||
|
||||
size_t found = 0;
|
||||
for (size_t i = 0; i < pool.size(); i++) { // find nearest neighbor and add unlinked-node as its neighbor
|
||||
if (has_linked[pool[i].id]) {
|
||||
root = pool[i].id;
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == 0) {
|
||||
while (true) { // random a linked-node and add unlinked-node as its neighbor
|
||||
size_t rid = rand() % ntotal;
|
||||
if (has_linked[rid]) {
|
||||
root = rid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
nsg[root].push_back(id);
|
||||
}
|
||||
|
||||
|
||||
void NsgIndex::Search(const float *query,
|
||||
const unsigned &nq,
|
||||
const unsigned &dim,
|
||||
const unsigned &k,
|
||||
float *dist,
|
||||
long *ids,
|
||||
SearchParams ¶ms) {
|
||||
std::vector<std::vector<Neighbor>> resset(nq);
|
||||
|
||||
TimeRecorder rc("search");
|
||||
if (nq == 1) {
|
||||
GetNeighbors(query, resset[0], nsg, ¶ms);
|
||||
} else{
|
||||
//#pragma omp parallel for schedule(dynamic, 50)
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < nq; ++i) {
|
||||
// TODO(linxj): when to use openmp
|
||||
auto single_query = query + i * dim;
|
||||
GetNeighbors(single_query, resset[i], nsg, ¶ms);
|
||||
}
|
||||
}
|
||||
rc.ElapseFromBegin("cost");
|
||||
|
||||
for (int i = 0; i < nq; ++i) {
|
||||
for (int j = 0; j < k; ++j) {
|
||||
//ids[i * k + j] = resset[i][j].id;
|
||||
|
||||
// Fix(linxj): bug, reset[i][j] out of range
|
||||
ids[i * k + j] = ids_[resset[i][j].id];
|
||||
dist[i * k + j] = resset[i][j].distance;
|
||||
}
|
||||
}
|
||||
|
||||
//>> Debug: test single insert
|
||||
//int x_0 = resset[0].size();
|
||||
//for (int l = 0; l < resset[0].size(); ++l) {
|
||||
// resset[0].pop_back();
|
||||
//}
|
||||
//resset.clear();
|
||||
|
||||
//ProfilerStart("xx.prof");
|
||||
//std::vector<Neighbor> resset;
|
||||
//GetNeighbors(query, resset, nsg, ¶ms);
|
||||
//for (int i = 0; i < k; ++i) {
|
||||
// ids[i] = resset[i].id;
|
||||
//dist[i] = resset[i].distance;
|
||||
//}
|
||||
//ProfilerStop();
|
||||
}
|
||||
|
||||
void NsgIndex::SetKnnGraph(Graph &g) {
|
||||
knng = std::move(g);
|
||||
}
|
||||
|
||||
void NsgIndex::GetKnnGraphFromFile() {
|
||||
//std::string filename = "/home/zilliz/opt/workspace/wook/efanna_graph/tests/sift.1M.50NN.graph";
|
||||
std::string filename = "/home/zilliz/opt/workspace/wook/efanna_graph/tests/sift.50NN.graph";
|
||||
|
||||
std::ifstream in(filename, std::ios::binary);
|
||||
unsigned k;
|
||||
in.read((char *) &k, sizeof(unsigned));
|
||||
in.seekg(0, std::ios::end);
|
||||
std::ios::pos_type ss = in.tellg();
|
||||
size_t fsize = (size_t) ss;
|
||||
size_t num = (unsigned) (fsize / (k + 1) / 4);
|
||||
in.seekg(0, std::ios::beg);
|
||||
|
||||
knng.resize(num);
|
||||
knng.reserve(num);
|
||||
unsigned kk = (k + 3) / 4 * 4;
|
||||
for (size_t i = 0; i < num; i++) {
|
||||
in.seekg(4, std::ios::cur);
|
||||
knng[i].resize(k);
|
||||
knng[i].reserve(kk);
|
||||
in.read((char *) knng[i].data(), k * sizeof(unsigned));
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
59
cpp/src/core/src/knowhere/index/vector_index/nsg/nsg_io.cpp
Normal file
59
cpp/src/core/src/knowhere/index/vector_index/nsg/nsg_io.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "knowhere/index/vector_index/nsg/nsg_io.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
namespace algo {
|
||||
|
||||
void write_index(NsgIndex *index, MemoryIOWriter &writer) {
|
||||
writer(&index->ntotal, sizeof(index->ntotal), 1);
|
||||
writer(&index->dimension, sizeof(index->dimension), 1);
|
||||
writer(&index->navigation_point, sizeof(index->navigation_point), 1);
|
||||
writer(index->ori_data_, sizeof(float) * index->ntotal * index->dimension, 1);
|
||||
writer(index->ids_, sizeof(long) * index->ntotal, 1);
|
||||
|
||||
for (unsigned i = 0; i < index->ntotal; ++i) {
|
||||
auto neighbor_num = (node_t) index->nsg[i].size();
|
||||
writer(&neighbor_num, sizeof(node_t), 1);
|
||||
writer(index->nsg[i].data(), neighbor_num * sizeof(node_t), 1);
|
||||
}
|
||||
}
|
||||
|
||||
NsgIndex *read_index(MemoryIOReader &reader) {
|
||||
size_t ntotal;
|
||||
size_t dimension;
|
||||
reader(&ntotal, sizeof(size_t), 1);
|
||||
reader(&dimension, sizeof(size_t), 1);
|
||||
auto index = new NsgIndex(dimension, ntotal);
|
||||
reader(&index->navigation_point, sizeof(index->navigation_point), 1);
|
||||
|
||||
index->ori_data_ = new float[index->ntotal * index->dimension];
|
||||
index->ids_ = new long[index->ntotal];
|
||||
reader(index->ori_data_, sizeof(float) * index->ntotal * index->dimension, 1);
|
||||
reader(index->ids_, sizeof(long) * index->ntotal, 1);
|
||||
|
||||
index->nsg.reserve(index->ntotal);
|
||||
index->nsg.resize(index->ntotal);
|
||||
node_t neighbor_num;
|
||||
for (unsigned i = 0; i < index->ntotal; ++i) {
|
||||
reader(&neighbor_num, sizeof(node_t), 1);
|
||||
index->nsg[i].reserve(neighbor_num);
|
||||
index->nsg[i].resize(neighbor_num);
|
||||
reader(index->nsg[i].data(), neighbor_num * sizeof(node_t), 1);
|
||||
}
|
||||
|
||||
index->is_trained = true;
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
166
cpp/src/core/src/knowhere/index/vector_index/nsg/utils.cpp
Normal file
166
cpp/src/core/src/knowhere/index/vector_index/nsg/utils.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
namespace algo {
|
||||
|
||||
// TODO: impl search && insert && return insert pos. why not just find and swap?
|
||||
int InsertIntoPool(Neighbor *addr, unsigned K, Neighbor nn) {
|
||||
//>> Fix: Add assert
|
||||
for (int i = 0; i < K; ++i) {
|
||||
assert(addr[i].id != nn.id);
|
||||
}
|
||||
|
||||
// find the location to insert
|
||||
int left = 0, right = K - 1;
|
||||
if (addr[left].distance > nn.distance) {
|
||||
//>> Fix: memmove overflow, dump when vector<Neighbor> deconstruct
|
||||
memmove((char *) &addr[left + 1], &addr[left], (K - 1) * sizeof(Neighbor));
|
||||
addr[left] = nn;
|
||||
return left;
|
||||
}
|
||||
if (addr[right].distance < nn.distance) {
|
||||
addr[K] = nn;
|
||||
return K;
|
||||
}
|
||||
while (left < right - 1) {
|
||||
int mid = (left + right) / 2;
|
||||
if (addr[mid].distance > nn.distance)
|
||||
right = mid;
|
||||
else
|
||||
left = mid;
|
||||
}
|
||||
//check equal ID
|
||||
|
||||
while (left > 0) {
|
||||
if (addr[left].distance < nn.distance) // pos is right
|
||||
break;
|
||||
if (addr[left].id == nn.id)
|
||||
return K + 1;
|
||||
left--;
|
||||
}
|
||||
if (addr[left].id == nn.id || addr[right].id == nn.id)
|
||||
return K + 1;
|
||||
|
||||
//>> Fix: memmove overflow, dump when vector<Neighbor> deconstruct
|
||||
memmove((char *) &addr[right + 1], &addr[right], (K - 1 - right) * sizeof(Neighbor));
|
||||
addr[right] = nn;
|
||||
return right;
|
||||
}
|
||||
|
||||
// TODO: support L2 / IP
|
||||
float calculate(const float *a, const float *b, unsigned size) {
|
||||
float result = 0;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#ifdef __AVX__
|
||||
|
||||
#define AVX_L2SQR(addr1, addr2, dest, tmp1, tmp2) \
|
||||
tmp1 = _mm256_loadu_ps(addr1);\
|
||||
tmp2 = _mm256_loadu_ps(addr2);\
|
||||
tmp1 = _mm256_sub_ps(tmp1, tmp2); \
|
||||
tmp1 = _mm256_mul_ps(tmp1, tmp1); \
|
||||
dest = _mm256_add_ps(dest, tmp1);
|
||||
|
||||
__m256 sum;
|
||||
__m256 l0, l1;
|
||||
__m256 r0, r1;
|
||||
unsigned D = (size + 7) & ~7U;
|
||||
unsigned DR = D % 16;
|
||||
unsigned DD = D - DR;
|
||||
const float *l = a;
|
||||
const float *r = b;
|
||||
const float *e_l = l + DD;
|
||||
const float *e_r = r + DD;
|
||||
float unpack[8] __attribute__ ((aligned (32))) = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
sum = _mm256_loadu_ps(unpack);
|
||||
if (DR) { AVX_L2SQR(e_l, e_r, sum, l0, r0); }
|
||||
|
||||
for (unsigned i = 0; i < DD; i += 16, l += 16, r += 16) {
|
||||
AVX_L2SQR(l, r, sum, l0, r0);
|
||||
AVX_L2SQR(l + 8, r + 8, sum, l1, r1);
|
||||
}
|
||||
_mm256_storeu_ps(unpack, sum);
|
||||
result = unpack[0] + unpack[1] + unpack[2] + unpack[3] + unpack[4] + unpack[5] + unpack[6] + unpack[7];
|
||||
|
||||
#else
|
||||
#ifdef __SSE2__
|
||||
#define SSE_L2SQR(addr1, addr2, dest, tmp1, tmp2) \
|
||||
tmp1 = _mm_load_ps(addr1);\
|
||||
tmp2 = _mm_load_ps(addr2);\
|
||||
tmp1 = _mm_sub_ps(tmp1, tmp2); \
|
||||
tmp1 = _mm_mul_ps(tmp1, tmp1); \
|
||||
dest = _mm_add_ps(dest, tmp1);
|
||||
|
||||
__m128 sum;
|
||||
__m128 l0, l1, l2, l3;
|
||||
__m128 r0, r1, r2, r3;
|
||||
unsigned D = (size + 3) & ~3U;
|
||||
unsigned DR = D % 16;
|
||||
unsigned DD = D - DR;
|
||||
const float *l = a;
|
||||
const float *r = b;
|
||||
const float *e_l = l + DD;
|
||||
const float *e_r = r + DD;
|
||||
float unpack[4] __attribute__ ((aligned (16))) = {0, 0, 0, 0};
|
||||
|
||||
sum = _mm_load_ps(unpack);
|
||||
switch (DR) {
|
||||
case 12:SSE_L2SQR(e_l + 8, e_r + 8, sum, l2, r2);
|
||||
case 8:SSE_L2SQR(e_l + 4, e_r + 4, sum, l1, r1);
|
||||
case 4:SSE_L2SQR(e_l, e_r, sum, l0, r0);
|
||||
default:break;
|
||||
}
|
||||
for (unsigned i = 0; i < DD; i += 16, l += 16, r += 16) {
|
||||
SSE_L2SQR(l, r, sum, l0, r0);
|
||||
SSE_L2SQR(l + 4, r + 4, sum, l1, r1);
|
||||
SSE_L2SQR(l + 8, r + 8, sum, l2, r2);
|
||||
SSE_L2SQR(l + 12, r + 12, sum, l3, r3);
|
||||
}
|
||||
_mm_storeu_ps(unpack, sum);
|
||||
result += unpack[0] + unpack[1] + unpack[2] + unpack[3];
|
||||
|
||||
//nomal distance
|
||||
#else
|
||||
|
||||
float diff0, diff1, diff2, diff3;
|
||||
const float* last = a + size;
|
||||
const float* unroll_group = last - 3;
|
||||
|
||||
/* Process 4 items with each loop for efficiency. */
|
||||
while (a < unroll_group) {
|
||||
diff0 = a[0] - b[0];
|
||||
diff1 = a[1] - b[1];
|
||||
diff2 = a[2] - b[2];
|
||||
diff3 = a[3] - b[3];
|
||||
result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3;
|
||||
a += 4;
|
||||
b += 4;
|
||||
}
|
||||
/* Process last 0-3 pixels. Not needed for standard vector lengths. */
|
||||
while (a < last) {
|
||||
diff0 = *a++ - *b++;
|
||||
result += diff0 * diff0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
27
cpp/src/core/src/knowhere/index/vector_index/nsg/utils.h
Normal file
27
cpp/src/core/src/knowhere/index/vector_index/nsg/utils.h
Normal file
@ -0,0 +1,27 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <x86intrin.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <faiss/AutoTune.h>
|
||||
|
||||
#include "knowhere/index/vector_index/nsg/nsg.h"
|
||||
#include "knowhere/common/config.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
namespace algo {
|
||||
|
||||
extern int InsertIntoPool(Neighbor *addr, unsigned K, Neighbor nn);
|
||||
extern float calculate(const float *a, const float *b, unsigned size);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
157
cpp/src/core/src/knowhere/index/vector_index/nsg_index.cpp
Normal file
157
cpp/src/core/src/knowhere/index/vector_index/nsg_index.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "knowhere/index/vector_index/nsg_index.h"
|
||||
#include "knowhere/index/vector_index/nsg/nsg.h"
|
||||
#include "knowhere/index/vector_index/nsg/nsg_io.h"
|
||||
#include "knowhere/index/vector_index/idmap.h"
|
||||
#include "knowhere/index/vector_index/ivf.h"
|
||||
#include "knowhere/index/vector_index/gpu_ivf.h"
|
||||
#include "knowhere/adapter/faiss_adopt.h"
|
||||
#include "knowhere/common/exception.h"
|
||||
#include "knowhere/common/timer.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace knowhere {
|
||||
|
||||
BinarySet NSG::Serialize() {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("index not initialize or trained");
|
||||
}
|
||||
|
||||
try {
|
||||
algo::NsgIndex *index = index_.get();
|
||||
|
||||
MemoryIOWriter writer;
|
||||
algo::write_index(index, writer);
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(writer.data_);
|
||||
|
||||
BinarySet res_set;
|
||||
res_set.Append("NSG", data, writer.total);
|
||||
return res_set;
|
||||
} catch (std::exception &e) {
|
||||
KNOWHERE_THROW_MSG(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void NSG::Load(const BinarySet &index_binary) {
|
||||
try {
|
||||
auto binary = index_binary.GetByName("NSG");
|
||||
|
||||
MemoryIOReader reader;
|
||||
reader.total = binary->size;
|
||||
reader.data_ = binary->data.get();
|
||||
|
||||
auto index = algo::read_index(reader);
|
||||
index_.reset(index);
|
||||
} catch (std::exception &e) {
|
||||
KNOWHERE_THROW_MSG(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
DatasetPtr NSG::Search(const DatasetPtr &dataset, const Config &config) {
|
||||
if (!index_ || !index_->is_trained) {
|
||||
KNOWHERE_THROW_MSG("index not initialize or trained");
|
||||
}
|
||||
|
||||
// Required
|
||||
// if not found throw exception here.
|
||||
auto k = config["k"].as<size_t>();
|
||||
auto search_length = config.get_with_default("search_length", 30);
|
||||
|
||||
GETTENSOR(dataset)
|
||||
|
||||
auto elems = rows * k;
|
||||
auto res_ids = (int64_t *) malloc(sizeof(int64_t) * elems);
|
||||
auto res_dis = (float *) malloc(sizeof(float) * elems);
|
||||
|
||||
// TODO(linxj): get from config
|
||||
algo::SearchParams s_params;
|
||||
s_params.search_length = search_length;
|
||||
index_->Search((float *) p_data, rows, dim, k, res_dis, res_ids, s_params);
|
||||
|
||||
auto id_buf = MakeMutableBufferSmart((uint8_t *) res_ids, sizeof(int64_t) * elems);
|
||||
auto dist_buf = MakeMutableBufferSmart((uint8_t *) res_dis, sizeof(float) * elems);
|
||||
|
||||
// TODO: magic
|
||||
std::vector<BufferPtr> id_bufs{nullptr, id_buf};
|
||||
std::vector<BufferPtr> dist_bufs{nullptr, dist_buf};
|
||||
|
||||
auto int64_type = std::make_shared<arrow::Int64Type>();
|
||||
auto float_type = std::make_shared<arrow::FloatType>();
|
||||
|
||||
auto id_array_data = arrow::ArrayData::Make(int64_type, elems, id_bufs);
|
||||
auto dist_array_data = arrow::ArrayData::Make(float_type, elems, dist_bufs);
|
||||
|
||||
auto ids = std::make_shared<NumericArray<arrow::Int64Type>>(id_array_data);
|
||||
auto dists = std::make_shared<NumericArray<arrow::FloatType>>(dist_array_data);
|
||||
std::vector<ArrayPtr> array{ids, dists};
|
||||
|
||||
return std::make_shared<Dataset>(array, nullptr);
|
||||
}
|
||||
|
||||
IndexModelPtr NSG::Train(const DatasetPtr &dataset, const Config &config) {
|
||||
TimeRecorder rc("Interface");
|
||||
|
||||
auto metric_type = config["metric_type"].as_string();
|
||||
if (metric_type != "L2") { KNOWHERE_THROW_MSG("NSG not support this kind of metric type");}
|
||||
|
||||
// TODO(linxj): dev IndexFactory, support more IndexType
|
||||
auto preprocess_index = std::make_shared<GPUIVF>(0);
|
||||
//auto preprocess_index = std::make_shared<IVF>();
|
||||
auto model = preprocess_index->Train(dataset, config);
|
||||
preprocess_index->set_index_model(model);
|
||||
preprocess_index->AddWithoutIds(dataset, config);
|
||||
rc.RecordSection("build ivf");
|
||||
|
||||
auto k = config["knng"].as<int64_t>();
|
||||
Graph knng;
|
||||
preprocess_index->GenGraph(k, knng, dataset, config);
|
||||
rc.RecordSection("build knng");
|
||||
|
||||
GETTENSOR(dataset)
|
||||
auto array = dataset->array()[0];
|
||||
auto p_ids = array->data()->GetValues<long>(1, 0);
|
||||
|
||||
algo::BuildParams b_params;
|
||||
b_params.candidate_pool_size = config["candidate_pool_size"].as<size_t>();
|
||||
b_params.out_degree = config["out_degree"].as<size_t>();
|
||||
b_params.search_length = config["search_length"].as<size_t>();
|
||||
|
||||
index_ = std::make_shared<algo::NsgIndex>(dim, rows);
|
||||
index_->SetKnnGraph(knng);
|
||||
index_->Build_with_ids(rows, (float *) p_data, (long *) p_ids, b_params);
|
||||
rc.RecordSection("build nsg");
|
||||
rc.ElapseFromBegin("total cost");
|
||||
return nullptr; // TODO(linxj): support serialize
|
||||
}
|
||||
|
||||
void NSG::Add(const DatasetPtr &dataset, const Config &config) {
|
||||
// TODO(linxj): support incremental index.
|
||||
|
||||
//KNOWHERE_THROW_MSG("Not support yet");
|
||||
}
|
||||
|
||||
int64_t NSG::Count() {
|
||||
return index_->ntotal;
|
||||
}
|
||||
|
||||
int64_t NSG::Dimension() {
|
||||
return index_->dimension;
|
||||
}
|
||||
VectorIndexPtr NSG::Clone() {
|
||||
KNOWHERE_THROW_MSG("not support");
|
||||
}
|
||||
|
||||
void NSG::Seal() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
79
cpp/src/core/test/CMakeLists.txt
Normal file
79
cpp/src/core/test/CMakeLists.txt
Normal file
@ -0,0 +1,79 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR}/thirdparty)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/thirdparty/SPTAG/AnnService)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/thirdparty/jsoncons-0.126.0/include)
|
||||
include_directories(/usr/local/cuda/include)
|
||||
link_directories(/usr/local/cuda/lib64)
|
||||
link_directories(${CMAKE_SOURCE_DIR}/thirdparty/tbb)
|
||||
|
||||
set(unittest_libs
|
||||
gtest gmock gtest_main gmock_main)
|
||||
|
||||
set(depend_libs
|
||||
faiss openblas lapack
|
||||
arrow jemalloc_pic
|
||||
tbb
|
||||
)
|
||||
|
||||
set(basic_libs
|
||||
cudart cublas
|
||||
gomp gfortran pthread
|
||||
)
|
||||
|
||||
|
||||
#<IVF-TEST>
|
||||
#<<<<<<<<<<
|
||||
set(ivf_srcs
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/ivf.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/gpu_ivf.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/cloner.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/idmap.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/adapter/structure.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/common/exception.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/common/timer.cpp
|
||||
utils.cpp
|
||||
)
|
||||
add_executable(test_ivf test_ivf.cpp ${ivf_srcs})
|
||||
target_link_libraries(test_ivf ${depend_libs} ${unittest_libs} ${basic_libs})
|
||||
#<<<<<<<<<<
|
||||
|
||||
#<IDMAP-TEST>
|
||||
#<<<<<<<<<<
|
||||
set(idmap_srcs
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/idmap.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/ivf.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/cloner.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/gpu_ivf.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/adapter/structure.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/common/exception.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/common/timer.cpp
|
||||
utils.cpp
|
||||
)
|
||||
add_executable(test_idmap test_idmap.cpp ${idmap_srcs})
|
||||
target_link_libraries(test_idmap ${depend_libs} ${unittest_libs} ${basic_libs})
|
||||
#<<<<<<<<<<
|
||||
|
||||
|
||||
#<KDT-TEST>
|
||||
#<<<<<<<<<<
|
||||
set(kdt_srcs
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/preprocessor/normalize.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/kdt_parameters.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/cpu_kdt_rng.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/adapter/structure.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/adapter/sptag.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/common/exception.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/adapter/arrow.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/common/timer.cpp
|
||||
utils.cpp
|
||||
)
|
||||
add_executable(test_kdt test_kdt.cpp ${kdt_srcs})
|
||||
target_link_libraries(test_kdt
|
||||
SPTAGLibStatic
|
||||
${depend_libs} ${unittest_libs} ${basic_libs})
|
||||
#<<<<<<<<<<
|
||||
|
||||
|
||||
add_subdirectory(faiss_ori)
|
||||
add_subdirectory(test_nsg)
|
||||
|
||||
36
cpp/src/core/test/SPTAG.cpp
Normal file
36
cpp/src/core/test/SPTAG.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
#include <random>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include "SPTAG/AnnService/inc/Core/Common.h"
|
||||
#include "SPTAG/AnnService/inc/Core/VectorIndex.h"
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
using namespace SPTAG;
|
||||
const int d = 128;
|
||||
const int n = 100;
|
||||
|
||||
auto p_data = new float[n * d];
|
||||
|
||||
auto index = VectorIndex::CreateInstance(IndexAlgoType::KDT, VectorValueType::Float);
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 mt(rd());
|
||||
std::uniform_real_distribution<double> dist(1.0, 2.0);
|
||||
|
||||
for (auto i = 0; i < n; i++) {
|
||||
for (auto j = 0; j < d; j++) {
|
||||
p_data[i * d + j] = dist(mt) - 1;
|
||||
}
|
||||
}
|
||||
std::cout << "generate random n * d finished.";
|
||||
ByteArray data((uint8_t *) p_data, n * d * sizeof(float), true);
|
||||
|
||||
auto vectorset = std::make_shared<BasicVectorSet>(data, VectorValueType::Float, d, n);
|
||||
index->BuildIndex(vectorset, nullptr);
|
||||
|
||||
std::cout << index->GetFeatureDim();
|
||||
}
|
||||
|
||||
26
cpp/src/core/test/faiss_ori/CMakeLists.txt
Normal file
26
cpp/src/core/test/faiss_ori/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR}/thirdparty)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
include_directories(/usr/local/cuda/include)
|
||||
link_directories(/usr/local/cuda/lib64)
|
||||
link_directories(${CMAKE_SOURCE_DIR}/thirdparty/tbb)
|
||||
|
||||
set(unittest_libs
|
||||
gtest gmock gtest_main gmock_main)
|
||||
|
||||
set(depend_libs
|
||||
faiss openblas lapack
|
||||
arrow jemalloc_pic
|
||||
tbb
|
||||
)
|
||||
|
||||
set(basic_libs
|
||||
cudart cublas
|
||||
gomp gfortran pthread
|
||||
)
|
||||
|
||||
|
||||
#<GPU-TEST>
|
||||
#<<<<<<<<<<
|
||||
add_executable(test_gpu gpuresource_test.cpp)
|
||||
target_link_libraries(test_gpu ${depend_libs} ${unittest_libs} ${basic_libs})
|
||||
#<<<<<<<<<<
|
||||
166
cpp/src/core/test/faiss_ori/gpuresource_test.cpp
Normal file
166
cpp/src/core/test/faiss_ori/gpuresource_test.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <faiss/gpu/StandardGpuResources.h>
|
||||
#include <faiss/gpu/GpuIndexIVFFlat.h>
|
||||
#include <faiss/Index.h>
|
||||
#include <faiss/AutoTune.h>
|
||||
#include <faiss/gpu/GpuAutoTune.h>
|
||||
#include <faiss/index_io.h>
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class TestGpuRes {
|
||||
public:
|
||||
TestGpuRes() {
|
||||
res_ = new faiss::gpu::StandardGpuResources;
|
||||
}
|
||||
~TestGpuRes() {
|
||||
delete res_;
|
||||
delete index_;
|
||||
}
|
||||
std::shared_ptr<faiss::Index> Do() {
|
||||
int d = 128; // dimension
|
||||
int nb = 100000; // database size
|
||||
int nq = 100; // nb of queries
|
||||
int nlist = 1638;
|
||||
|
||||
float *xb = new float[d * nb];
|
||||
float *xq = new float[d * nq];
|
||||
|
||||
for (int i = 0; i < nb; i++) {
|
||||
for (int j = 0; j < d; j++)
|
||||
xb[d * i + j] = drand48();
|
||||
xb[d * i] += i / 1000.;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nq; i++) {
|
||||
for (int j = 0; j < d; j++)
|
||||
xq[d * i + j] = drand48();
|
||||
xq[d * i] += i / 1000.;
|
||||
}
|
||||
|
||||
index_ = new faiss::gpu::GpuIndexIVFFlat(res_, d, nlist, faiss::METRIC_L2);
|
||||
index_->train(nb, xb);
|
||||
index_->add(nb, xb);
|
||||
|
||||
std::shared_ptr<faiss::Index> host_index = nullptr;
|
||||
host_index.reset(faiss::gpu::index_gpu_to_cpu(index_));
|
||||
return host_index;
|
||||
}
|
||||
private:
|
||||
faiss::gpu::GpuResources *res_ = nullptr;
|
||||
faiss::Index *index_ = nullptr;
|
||||
};
|
||||
|
||||
TEST(gpuresource, resource) {
|
||||
TestGpuRes t;
|
||||
t.Do();
|
||||
}
|
||||
|
||||
TEST(test, resource_re) {
|
||||
int d = 128; // dimension
|
||||
int nb = 1000000; // database size
|
||||
int nq = 100; // nb of queries
|
||||
int nlist = 16384;
|
||||
int k = 100;
|
||||
|
||||
float *xb = new float[d * nb];
|
||||
float *xq = new float[d * nq];
|
||||
|
||||
for (int i = 0; i < nb; i++) {
|
||||
for (int j = 0; j < d; j++)
|
||||
xb[d * i + j] = drand48();
|
||||
xb[d * i] += i / 1000.;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nq; i++) {
|
||||
for (int j = 0; j < d; j++)
|
||||
xq[d * i + j] = drand48();
|
||||
xq[d * i] += i / 1000.;
|
||||
}
|
||||
|
||||
auto elems = nq * k;
|
||||
auto res_ids = (int64_t *) malloc(sizeof(int64_t) * elems);
|
||||
auto res_dis = (float *) malloc(sizeof(float) * elems);
|
||||
|
||||
faiss::gpu::StandardGpuResources res;
|
||||
auto cpu_index = faiss::index_factory(d, "IVF16384, Flat");
|
||||
auto device_index = faiss::gpu::index_cpu_to_gpu(&res, 0, cpu_index);
|
||||
device_index->train(nb, xb);
|
||||
device_index->add(nb, xb);
|
||||
auto new_index = faiss::gpu::index_gpu_to_cpu(device_index);
|
||||
|
||||
delete device_index;
|
||||
|
||||
std::cout << "start clone" << std::endl;
|
||||
auto load = [&] {
|
||||
std::cout << "start" << std::endl;
|
||||
faiss::gpu::StandardGpuResources res;
|
||||
//res.noTempMemory();
|
||||
for (int l = 0; l < 100; ++l) {
|
||||
auto x = faiss::gpu::index_cpu_to_gpu(&res, 1, new_index);
|
||||
delete x;
|
||||
}
|
||||
std::cout << "load finish" << std::endl;
|
||||
};
|
||||
|
||||
auto search = [&] {
|
||||
faiss::gpu::StandardGpuResources res;
|
||||
auto device_index = faiss::gpu::index_cpu_to_gpu(&res, 1, new_index);
|
||||
std::cout << "search start" << std::endl;
|
||||
for (int l = 0; l < 10000; ++l) {
|
||||
device_index->search(nq,xq,10, res_dis, res_ids);
|
||||
}
|
||||
std::cout << "search finish" << std::endl;
|
||||
delete device_index;
|
||||
delete cpu_index;
|
||||
};
|
||||
|
||||
load();
|
||||
search();
|
||||
std::thread t1(search);
|
||||
std::this_thread::sleep_for(1s);
|
||||
std::thread t2(load);
|
||||
t1.join();
|
||||
t2.join();
|
||||
std::cout << "finish clone" << std::endl;
|
||||
|
||||
//std::this_thread::sleep_for(5s);
|
||||
//
|
||||
//auto device_index_2 = faiss::gpu::index_cpu_to_gpu(&res, 1, cpu_index);
|
||||
//device_index->train(nb, xb);
|
||||
//device_index->add(nb, xb);
|
||||
|
||||
//std::cout << "finish clone" << std::endl;
|
||||
//std::this_thread::sleep_for(5s);
|
||||
|
||||
//std::this_thread::sleep_for(2s);
|
||||
//std::cout << "start clone" << std::endl;
|
||||
//auto new_index = faiss::clone_index(device_index);
|
||||
//std::cout << "start search" << std::endl;
|
||||
//new_index->search(nq, xq, k, res_dis, res_ids);
|
||||
|
||||
//std::cout << "start clone" << std::endl;
|
||||
//{
|
||||
// faiss::gpu::StandardGpuResources res;
|
||||
// auto cpu_index = faiss::index_factory(d, "IVF1638, Flat");
|
||||
// auto device_index = faiss::gpu::index_cpu_to_gpu(&res, 1, cpu_index);
|
||||
// device_index->train(nb, xb);
|
||||
// device_index->add(nb, xb);
|
||||
// std::cout << "finish clone" << std::endl;
|
||||
// delete device_index;
|
||||
// delete cpu_index;
|
||||
// std::cout << "finish clone" << std::endl;
|
||||
//}
|
||||
//
|
||||
//std::cout << "finish clone" << std::endl;
|
||||
}
|
||||
134
cpp/src/core/test/kdtree.cpp
Normal file
134
cpp/src/core/test/kdtree.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "knowhere/index/vector_index/cpu_kdt_rng.h"
|
||||
#include "knowhere/index/vector_index/definitions.h"
|
||||
#include "knowhere/adapter/sptag.h"
|
||||
#include "knowhere/adapter/structure.h"
|
||||
|
||||
|
||||
using namespace zilliz::knowhere;
|
||||
|
||||
DatasetPtr
|
||||
generate_dataset(int64_t n, int64_t d, int64_t base) {
|
||||
auto elems = n * d;
|
||||
auto p_data = (float *) malloc(elems * sizeof(float));
|
||||
auto p_id = (int64_t *) malloc(elems * sizeof(int64_t));
|
||||
assert(p_data != nullptr && p_id != nullptr);
|
||||
|
||||
for (auto i = 0; i < n; ++i) {
|
||||
for (auto j = 0; j < d; ++j) {
|
||||
p_data[i * d + j] = float(base + i);
|
||||
}
|
||||
p_id[i] = i;
|
||||
}
|
||||
|
||||
std::vector<int64_t> shape{n, d};
|
||||
auto tensor = ConstructFloatTensorSmart((uint8_t *) p_data, elems * sizeof(float), shape);
|
||||
std::vector<TensorPtr> tensors{tensor};
|
||||
std::vector<FieldPtr> tensor_fields{ConstructFloatField("data")};
|
||||
auto tensor_schema = std::make_shared<Schema>(tensor_fields);
|
||||
|
||||
auto id_array = ConstructInt64ArraySmart((uint8_t *) p_id, n * sizeof(int64_t));
|
||||
std::vector<ArrayPtr> arrays{id_array};
|
||||
std::vector<FieldPtr> array_fields{ConstructInt64Field("id")};
|
||||
auto array_schema = std::make_shared<Schema>(tensor_fields);
|
||||
|
||||
auto dataset = std::make_shared<Dataset>(std::move(arrays), array_schema,
|
||||
std::move(tensors), tensor_schema);
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
DatasetPtr
|
||||
generate_queries(int64_t n, int64_t d, int64_t k, int64_t base) {
|
||||
size_t size = sizeof(float) * n * d;
|
||||
auto v = (float *) malloc(size);
|
||||
// TODO: check malloc
|
||||
for (auto i = 0; i < n; ++i) {
|
||||
for (auto j = 0; j < d; ++j) {
|
||||
v[i * d + j] = float(base + i);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<TensorPtr> data;
|
||||
auto buffer = MakeMutableBufferSmart((uint8_t *) v, size);
|
||||
std::vector<int64_t> shape{n, d};
|
||||
auto float_type = std::make_shared<arrow::FloatType>();
|
||||
auto tensor = std::make_shared<Tensor>(float_type, buffer, shape);
|
||||
data.push_back(tensor);
|
||||
|
||||
Config meta;
|
||||
meta[META_ROWS] = int64_t (n);
|
||||
meta[META_DIM] = int64_t (d);
|
||||
meta[META_K] = int64_t (k);
|
||||
|
||||
auto type = std::make_shared<arrow::FloatType>();
|
||||
auto field = std::make_shared<Field>("data", type);
|
||||
std::vector<FieldPtr> fields{field};
|
||||
auto schema = std::make_shared<Schema>(fields);
|
||||
|
||||
return std::make_shared<Dataset>(data, schema);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
auto kdt_index = std::make_shared<CPUKDTRNG>();
|
||||
|
||||
const auto d = 10;
|
||||
const auto k = 3;
|
||||
const auto nquery = 10;
|
||||
|
||||
// ID [0, 99]
|
||||
auto train = generate_dataset(100, d, 0);
|
||||
// ID [100]
|
||||
auto base = generate_dataset(1, d, 0);
|
||||
auto queries = generate_queries(nquery, d, k, 0);
|
||||
|
||||
// Build Preprocessor
|
||||
auto preprocessor = kdt_index->BuildPreprocessor(train, Config());
|
||||
|
||||
// Set Preprocessor
|
||||
kdt_index->set_preprocessor(preprocessor);
|
||||
|
||||
Config train_config;
|
||||
train_config["TPTNumber"] = "64";
|
||||
// Train
|
||||
kdt_index->Train(train, train_config);
|
||||
|
||||
// Add
|
||||
kdt_index->Add(base, Config());
|
||||
|
||||
auto binary = kdt_index->Serialize();
|
||||
auto new_index = std::make_shared<CPUKDTRNG>();
|
||||
new_index->Load(binary);
|
||||
// auto new_index = kdt_index;
|
||||
|
||||
Config search_config;
|
||||
search_config[META_K] = int64_t (k);
|
||||
|
||||
// Search
|
||||
auto result = new_index->Search(queries, search_config);
|
||||
|
||||
// Print Result
|
||||
{
|
||||
auto ids = result->array()[0];
|
||||
auto dists = result->array()[1];
|
||||
|
||||
std::stringstream ss_id;
|
||||
std::stringstream ss_dist;
|
||||
for (auto i = 0; i < nquery; i++) {
|
||||
for (auto j = 0; j < k; ++j) {
|
||||
ss_id << *ids->data()->GetValues<int64_t>(1, i * k + j) << " ";
|
||||
ss_dist << *dists->data()->GetValues<float>(1, i * k + j) << " ";
|
||||
}
|
||||
ss_id << std::endl;
|
||||
ss_dist << std::endl;
|
||||
}
|
||||
std::cout << "id\n" << ss_id.str() << std::endl;
|
||||
std::cout << "dist\n" << ss_dist.str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
cpp/src/core/test/sift.50NN.graph
Normal file
BIN
cpp/src/core/test/sift.50NN.graph
Normal file
Binary file not shown.
BIN
cpp/src/core/test/siftsmall_base.fvecs
Normal file
BIN
cpp/src/core/test/siftsmall_base.fvecs
Normal file
Binary file not shown.
171
cpp/src/core/test/test_idmap.cpp
Normal file
171
cpp/src/core/test/test_idmap.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "knowhere/index/vector_index/idmap.h"
|
||||
#include "knowhere/adapter/structure.h"
|
||||
#include "knowhere/index/vector_index/cloner.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
using namespace zilliz::knowhere;
|
||||
|
||||
class IDMAPTest : public DataGen, public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
Init_with_default();
|
||||
index_ = std::make_shared<IDMAP>();
|
||||
}
|
||||
protected:
|
||||
IDMAPPtr index_ = nullptr;
|
||||
};
|
||||
|
||||
void AssertAnns(const DatasetPtr &result,
|
||||
const int &nq,
|
||||
const int &k) {
|
||||
auto ids = result->array()[0];
|
||||
for (auto i = 0; i < nq; i++) {
|
||||
EXPECT_EQ(i, *(ids->data()->GetValues<int64_t>(1, i * k)));
|
||||
}
|
||||
}
|
||||
|
||||
void PrintResult(const DatasetPtr &result,
|
||||
const int &nq,
|
||||
const int &k) {
|
||||
auto ids = result->array()[0];
|
||||
auto dists = result->array()[1];
|
||||
|
||||
std::stringstream ss_id;
|
||||
std::stringstream ss_dist;
|
||||
for (auto i = 0; i < 10; i++) {
|
||||
for (auto j = 0; j < k; ++j) {
|
||||
ss_id << *(ids->data()->GetValues<int64_t>(1, i * k + j)) << " ";
|
||||
ss_dist << *(dists->data()->GetValues<float>(1, i * k + j)) << " ";
|
||||
}
|
||||
ss_id << std::endl;
|
||||
ss_dist << std::endl;
|
||||
}
|
||||
std::cout << "id\n" << ss_id.str() << std::endl;
|
||||
std::cout << "dist\n" << ss_dist.str() << std::endl;
|
||||
}
|
||||
|
||||
TEST_F(IDMAPTest, idmap_basic) {
|
||||
assert(!xb.empty());
|
||||
Config Default_cfg;
|
||||
|
||||
index_->Train(Config::object{{"dim", dim}, {"metric_type", "L2"}});
|
||||
index_->Add(base_dataset, Default_cfg);
|
||||
EXPECT_EQ(index_->Count(), nb);
|
||||
EXPECT_EQ(index_->Dimension(), dim);
|
||||
assert(index_->GetRawVectors() != nullptr);
|
||||
assert(index_->GetRawIds() != nullptr);
|
||||
auto result = index_->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(result, nq, k);
|
||||
PrintResult(result, nq, k);
|
||||
|
||||
auto binaryset = index_->Serialize();
|
||||
auto new_index = std::make_shared<IDMAP>();
|
||||
new_index->Load(binaryset);
|
||||
auto re_result = index_->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(re_result, nq, k);
|
||||
PrintResult(re_result, nq, k);
|
||||
}
|
||||
|
||||
TEST_F(IDMAPTest, idmap_serialize) {
|
||||
auto serialize = [](const std::string &filename, BinaryPtr &bin, uint8_t *ret) {
|
||||
FileIOWriter writer(filename);
|
||||
writer(static_cast<void *>(bin->data.get()), bin->size);
|
||||
|
||||
FileIOReader reader(filename);
|
||||
reader(ret, bin->size);
|
||||
};
|
||||
|
||||
{
|
||||
// serialize index
|
||||
index_->Train(Config::object{{"dim", dim}, {"metric_type", "L2"}});
|
||||
index_->Add(base_dataset, Config());
|
||||
auto re_result = index_->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(re_result, nq, k);
|
||||
PrintResult(re_result, nq, k);
|
||||
EXPECT_EQ(index_->Count(), nb);
|
||||
EXPECT_EQ(index_->Dimension(), dim);
|
||||
auto binaryset = index_->Serialize();
|
||||
auto bin = binaryset.GetByName("IVF");
|
||||
|
||||
std::string filename = "/tmp/idmap_test_serialize.bin";
|
||||
auto load_data = new uint8_t[bin->size];
|
||||
serialize(filename, bin, load_data);
|
||||
|
||||
binaryset.clear();
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(load_data);
|
||||
binaryset.Append("IVF", data, bin->size);
|
||||
|
||||
index_->Load(binaryset);
|
||||
EXPECT_EQ(index_->Count(), nb);
|
||||
EXPECT_EQ(index_->Dimension(), dim);
|
||||
auto result = index_->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(result, nq, k);
|
||||
PrintResult(result, nq, k);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(IDMAPTest, copy_test) {
|
||||
assert(!xb.empty());
|
||||
Config Default_cfg;
|
||||
|
||||
index_->Train(Config::object{{"dim", dim}, {"metric_type", "L2"}});
|
||||
index_->Add(base_dataset, Default_cfg);
|
||||
EXPECT_EQ(index_->Count(), nb);
|
||||
EXPECT_EQ(index_->Dimension(), dim);
|
||||
assert(index_->GetRawVectors() != nullptr);
|
||||
assert(index_->GetRawIds() != nullptr);
|
||||
auto result = index_->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(result, nq, k);
|
||||
//PrintResult(result, nq, k);
|
||||
|
||||
{
|
||||
// clone
|
||||
auto clone_index = index_->Clone();
|
||||
auto clone_result = clone_index->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(clone_result, nq, k);
|
||||
}
|
||||
|
||||
{
|
||||
// cpu to gpu
|
||||
static int64_t device_id = 0;
|
||||
FaissGpuResourceMgr::GetInstance().InitDevice(0);
|
||||
FaissGpuResourceMgr::GetInstance().InitDevice(1);
|
||||
|
||||
auto clone_index = CopyCpuToGpu(index_, device_id, Config());
|
||||
auto clone_result = clone_index->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(clone_result, nq, k);
|
||||
//assert(std::static_pointer_cast<GPUIDMAP>(clone_index)->GetRawVectors() != nullptr);
|
||||
//assert(std::static_pointer_cast<GPUIDMAP>(clone_index)->GetRawIds() != nullptr);
|
||||
auto clone_gpu_idx = clone_index->Clone();
|
||||
auto clone_gpu_res = clone_gpu_idx->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(clone_gpu_res, nq, k);
|
||||
|
||||
// gpu to cpu
|
||||
auto host_index = CopyGpuToCpu(clone_index, Config());
|
||||
auto host_result = host_index->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(host_result, nq, k);
|
||||
assert(std::static_pointer_cast<IDMAP>(host_index)->GetRawVectors() != nullptr);
|
||||
assert(std::static_pointer_cast<IDMAP>(host_index)->GetRawIds() != nullptr);
|
||||
|
||||
// gpu to gpu
|
||||
auto device_index = CopyCpuToGpu(index_, 1, Config());
|
||||
auto device_result = device_index->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(device_result, nq, k);
|
||||
//assert(std::static_pointer_cast<GPUIDMAP>(device_index)->GetRawVectors() != nullptr);
|
||||
//assert(std::static_pointer_cast<GPUIDMAP>(device_index)->GetRawIds() != nullptr);
|
||||
}
|
||||
}
|
||||
346
cpp/src/core/test/test_ivf.cpp
Normal file
346
cpp/src/core/test/test_ivf.cpp
Normal file
@ -0,0 +1,346 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "knowhere/index/vector_index/gpu_ivf.h"
|
||||
#include "knowhere/index/vector_index/ivf.h"
|
||||
#include "knowhere/adapter/structure.h"
|
||||
#include "knowhere/index/vector_index/cloner.h"
|
||||
#include "knowhere/common/exception.h"
|
||||
#include "knowhere/common/timer.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
using namespace zilliz::knowhere;
|
||||
|
||||
using ::testing::TestWithParam;
|
||||
using ::testing::Values;
|
||||
using ::testing::Combine;
|
||||
|
||||
static int device_id = 1;
|
||||
IVFIndexPtr IndexFactory(const std::string &type) {
|
||||
if (type == "IVF") {
|
||||
return std::make_shared<IVF>();
|
||||
} else if (type == "IVFPQ") {
|
||||
return std::make_shared<IVFPQ>();
|
||||
} else if (type == "GPUIVF") {
|
||||
return std::make_shared<GPUIVF>(device_id);
|
||||
} else if (type == "GPUIVFPQ") {
|
||||
return std::make_shared<GPUIVFPQ>(device_id);
|
||||
} else if (type == "IVFSQ") {
|
||||
return std::make_shared<IVFSQ>();
|
||||
} else if (type == "GPUIVFSQ") {
|
||||
return std::make_shared<GPUIVFSQ>(device_id);
|
||||
}
|
||||
}
|
||||
|
||||
class IVFTest
|
||||
: public DataGen, public TestWithParam<::std::tuple<std::string, Config, Config, Config, Config>> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
std::tie(index_type, preprocess_cfg, train_cfg, add_cfg, search_cfg) = GetParam();
|
||||
//Init_with_default();
|
||||
Generate(128, 1000000/5, 10);
|
||||
index_ = IndexFactory(index_type);
|
||||
FaissGpuResourceMgr::GetInstance().InitDevice(device_id);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string index_type;
|
||||
Config preprocess_cfg;
|
||||
Config train_cfg;
|
||||
Config add_cfg;
|
||||
Config search_cfg;
|
||||
IVFIndexPtr index_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(IVFParameters, IVFTest,
|
||||
Values(
|
||||
std::make_tuple("IVF",
|
||||
Config(),
|
||||
Config::object{{"nlist", 100}, {"metric_type", "L2"}},
|
||||
Config(),
|
||||
Config::object{{"k", 10}}),
|
||||
//std::make_tuple("IVFPQ",
|
||||
// Config(),
|
||||
// Config::object{{"nlist", 100}, {"M", 8}, {"nbits", 8}, {"metric_type", "L2"}},
|
||||
// Config(),
|
||||
// Config::object{{"k", 10}}),
|
||||
std::make_tuple("GPUIVF",
|
||||
Config(),
|
||||
Config::object{{"nlist", 1638}, {"gpu_id", device_id}, {"metric_type", "L2"}},
|
||||
Config(),
|
||||
Config::object{{"k", 10}}),
|
||||
//std::make_tuple("GPUIVFPQ",
|
||||
// Config(),
|
||||
// Config::object{{"gpu_id", device_id}, {"nlist", 100}, {"M", 8}, {"nbits", 8}, {"metric_type", "L2"}},
|
||||
// Config(),
|
||||
// Config::object{{"k", 10}}),
|
||||
std::make_tuple("IVFSQ",
|
||||
Config(),
|
||||
Config::object{{"nlist", 100}, {"nbits", 8}, {"metric_type", "L2"}},
|
||||
Config(),
|
||||
Config::object{{"k", 10}}),
|
||||
std::make_tuple("GPUIVFSQ",
|
||||
Config(),
|
||||
Config::object{{"gpu_id", device_id}, {"nlist", 1638}, {"nbits", 8}, {"metric_type", "L2"}},
|
||||
Config(),
|
||||
Config::object{{"k", 10}})
|
||||
)
|
||||
);
|
||||
|
||||
void AssertAnns(const DatasetPtr &result,
|
||||
const int &nq,
|
||||
const int &k) {
|
||||
auto ids = result->array()[0];
|
||||
for (auto i = 0; i < nq; i++) {
|
||||
EXPECT_EQ(i, *(ids->data()->GetValues<int64_t>(1, i * k)));
|
||||
}
|
||||
}
|
||||
|
||||
void PrintResult(const DatasetPtr &result,
|
||||
const int &nq,
|
||||
const int &k) {
|
||||
auto ids = result->array()[0];
|
||||
auto dists = result->array()[1];
|
||||
|
||||
std::stringstream ss_id;
|
||||
std::stringstream ss_dist;
|
||||
for (auto i = 0; i < 10; i++) {
|
||||
for (auto j = 0; j < k; ++j) {
|
||||
ss_id << *(ids->data()->GetValues<int64_t>(1, i * k + j)) << " ";
|
||||
ss_dist << *(dists->data()->GetValues<float>(1, i * k + j)) << " ";
|
||||
}
|
||||
ss_id << std::endl;
|
||||
ss_dist << std::endl;
|
||||
}
|
||||
std::cout << "id\n" << ss_id.str() << std::endl;
|
||||
std::cout << "dist\n" << ss_dist.str() << std::endl;
|
||||
}
|
||||
|
||||
TEST_P(IVFTest, ivf_basic) {
|
||||
assert(!xb.empty());
|
||||
|
||||
auto preprocessor = index_->BuildPreprocessor(base_dataset, preprocess_cfg);
|
||||
index_->set_preprocessor(preprocessor);
|
||||
|
||||
auto model = index_->Train(base_dataset, train_cfg);
|
||||
index_->set_index_model(model);
|
||||
index_->Add(base_dataset, add_cfg);
|
||||
EXPECT_EQ(index_->Count(), nb);
|
||||
EXPECT_EQ(index_->Dimension(), dim);
|
||||
auto result = index_->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
//PrintResult(result, nq, k);
|
||||
}
|
||||
|
||||
//TEST_P(IVFTest, gpu_to_cpu) {
|
||||
// if (index_type.find("GPU") == std::string::npos) { return; }
|
||||
//
|
||||
// // else
|
||||
// assert(!xb.empty());
|
||||
//
|
||||
// auto preprocessor = index_->BuildPreprocessor(base_dataset, preprocess_cfg);
|
||||
// index_->set_preprocessor(preprocessor);
|
||||
//
|
||||
// auto model = index_->Train(base_dataset, train_cfg);
|
||||
// index_->set_index_model(model);
|
||||
// index_->Add(base_dataset, add_cfg);
|
||||
// EXPECT_EQ(index_->Count(), nb);
|
||||
// EXPECT_EQ(index_->Dimension(), dim);
|
||||
// auto result = index_->Search(query_dataset, search_cfg);
|
||||
// AssertAnns(result, nq, k);
|
||||
//
|
||||
// if (auto device_index = std::dynamic_pointer_cast<GPUIVF>(index_)) {
|
||||
// auto host_index = device_index->Copy_index_gpu_to_cpu();
|
||||
// auto result = host_index->Search(query_dataset, search_cfg);
|
||||
// AssertAnns(result, nq, k);
|
||||
// }
|
||||
//}
|
||||
|
||||
TEST_P(IVFTest, ivf_serialize) {
|
||||
auto serialize = [](const std::string &filename, BinaryPtr &bin, uint8_t *ret) {
|
||||
FileIOWriter writer(filename);
|
||||
writer(static_cast<void *>(bin->data.get()), bin->size);
|
||||
|
||||
FileIOReader reader(filename);
|
||||
reader(ret, bin->size);
|
||||
};
|
||||
|
||||
{
|
||||
// serialize index-model
|
||||
auto model = index_->Train(base_dataset, train_cfg);
|
||||
auto binaryset = model->Serialize();
|
||||
auto bin = binaryset.GetByName("IVF");
|
||||
|
||||
std::string filename = "/tmp/ivf_test_model_serialize.bin";
|
||||
auto load_data = new uint8_t[bin->size];
|
||||
serialize(filename, bin, load_data);
|
||||
|
||||
binaryset.clear();
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(load_data);
|
||||
binaryset.Append("IVF", data, bin->size);
|
||||
|
||||
model->Load(binaryset);
|
||||
|
||||
index_->set_index_model(model);
|
||||
index_->Add(base_dataset, add_cfg);
|
||||
auto result = index_->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
}
|
||||
|
||||
{
|
||||
// serialize index
|
||||
auto model = index_->Train(base_dataset, train_cfg);
|
||||
index_->set_index_model(model);
|
||||
index_->Add(base_dataset, add_cfg);
|
||||
auto binaryset = index_->Serialize();
|
||||
auto bin = binaryset.GetByName("IVF");
|
||||
|
||||
std::string filename = "/tmp/ivf_test_serialize.bin";
|
||||
auto load_data = new uint8_t[bin->size];
|
||||
serialize(filename, bin, load_data);
|
||||
|
||||
binaryset.clear();
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(load_data);
|
||||
binaryset.Append("IVF", data, bin->size);
|
||||
|
||||
index_->Load(binaryset);
|
||||
EXPECT_EQ(index_->Count(), nb);
|
||||
EXPECT_EQ(index_->Dimension(), dim);
|
||||
auto result = index_->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(IVFTest, clone_test) {
|
||||
assert(!xb.empty());
|
||||
|
||||
auto preprocessor = index_->BuildPreprocessor(base_dataset, preprocess_cfg);
|
||||
index_->set_preprocessor(preprocessor);
|
||||
|
||||
auto model = index_->Train(base_dataset, train_cfg);
|
||||
index_->set_index_model(model);
|
||||
index_->Add(base_dataset, add_cfg);
|
||||
EXPECT_EQ(index_->Count(), nb);
|
||||
EXPECT_EQ(index_->Dimension(), dim);
|
||||
auto result = index_->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
//PrintResult(result, nq, k);
|
||||
|
||||
auto AssertEqual = [&] (DatasetPtr p1, DatasetPtr p2) {
|
||||
auto ids_p1 = p1->array()[0];
|
||||
auto ids_p2 = p2->array()[0];
|
||||
|
||||
for (int i = 0; i < nq * k; ++i) {
|
||||
EXPECT_EQ(*(ids_p2->data()->GetValues<int64_t>(1, i)),
|
||||
*(ids_p1->data()->GetValues<int64_t>(1, i)));
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
// clone in place
|
||||
std::vector<std::string> support_idx_vec{"IVF", "GPUIVF", "IVFPQ", "IVFSQ", "GPUIVFSQ"};
|
||||
auto finder = std::find(support_idx_vec.cbegin(), support_idx_vec.cend(), index_type);
|
||||
if (finder != support_idx_vec.cend()) {
|
||||
EXPECT_NO_THROW({
|
||||
auto clone_index = index_->Clone();
|
||||
auto clone_result = clone_index->Search(query_dataset, search_cfg);
|
||||
//AssertAnns(result, nq, k);
|
||||
AssertEqual(result, clone_result);
|
||||
std::cout << "inplace clone [" << index_type << "] success" << std::endl;
|
||||
});
|
||||
} else {
|
||||
EXPECT_THROW({
|
||||
std::cout << "inplace clone [" << index_type << "] failed" << std::endl;
|
||||
auto clone_index = index_->Clone();
|
||||
}, KnowhereException);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// copy from gpu to cpu
|
||||
std::vector<std::string> support_idx_vec{"GPUIVF", "GPUIVFSQ"};
|
||||
auto finder = std::find(support_idx_vec.cbegin(), support_idx_vec.cend(), index_type);
|
||||
if (finder != support_idx_vec.cend()) {
|
||||
EXPECT_NO_THROW({
|
||||
auto clone_index = CopyGpuToCpu(index_, Config());
|
||||
auto clone_result = clone_index->Search(query_dataset, search_cfg);
|
||||
AssertEqual(result, clone_result);
|
||||
std::cout << "clone G <=> C [" << index_type << "] success" << std::endl;
|
||||
});
|
||||
} else {
|
||||
EXPECT_THROW({
|
||||
std::cout << "clone G <=> C [" << index_type << "] failed" << std::endl;
|
||||
auto clone_index = CopyGpuToCpu(index_, Config());
|
||||
}, KnowhereException);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// copy to gpu
|
||||
std::vector<std::string> support_idx_vec{"IVF", "GPUIVF", "IVFSQ", "GPUIVFSQ"};
|
||||
auto finder = std::find(support_idx_vec.cbegin(), support_idx_vec.cend(), index_type);
|
||||
if (finder != support_idx_vec.cend()) {
|
||||
EXPECT_NO_THROW({
|
||||
auto clone_index = CopyCpuToGpu(index_, device_id, Config());
|
||||
auto clone_result = clone_index->Search(query_dataset, search_cfg);
|
||||
AssertEqual(result, clone_result);
|
||||
std::cout << "clone C <=> G [" << index_type << "] success" << std::endl;
|
||||
});
|
||||
} else {
|
||||
EXPECT_THROW({
|
||||
std::cout << "clone C <=> G [" << index_type << "] failed" << std::endl;
|
||||
auto clone_index = CopyCpuToGpu(index_, device_id, Config());
|
||||
}, KnowhereException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(IVFTest, seal_test) {
|
||||
//FaissGpuResourceMgr::GetInstance().InitDevice(device_id);
|
||||
|
||||
std::vector<std::string> support_idx_vec{"GPUIVF", "GPUIVFSQ"};
|
||||
auto finder = std::find(support_idx_vec.cbegin(), support_idx_vec.cend(), index_type);
|
||||
if (finder == support_idx_vec.cend()) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(!xb.empty());
|
||||
|
||||
//index_ = std::make_shared<GPUIVF>(0);
|
||||
auto preprocessor = index_->BuildPreprocessor(base_dataset, preprocess_cfg);
|
||||
index_->set_preprocessor(preprocessor);
|
||||
|
||||
auto model = index_->Train(base_dataset, train_cfg);
|
||||
index_->set_index_model(model);
|
||||
index_->Add(base_dataset, add_cfg);
|
||||
EXPECT_EQ(index_->Count(), nb);
|
||||
EXPECT_EQ(index_->Dimension(), dim);
|
||||
auto result = index_->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
|
||||
auto cpu_idx = CopyGpuToCpu(index_, Config());
|
||||
|
||||
TimeRecorder tc("CopyToGpu");
|
||||
CopyCpuToGpu(cpu_idx, device_id, Config());
|
||||
auto without_seal = tc.RecordSection("Without seal");
|
||||
cpu_idx->Seal();
|
||||
tc.RecordSection("seal cost");
|
||||
CopyCpuToGpu(cpu_idx, device_id, Config());
|
||||
auto with_seal = tc.RecordSection("With seal");
|
||||
ASSERT_GE(without_seal, with_seal);
|
||||
}
|
||||
|
||||
// TODO(linxj): Add exception test
|
||||
18
cpp/src/core/test/test_json.cpp
Normal file
18
cpp/src/core/test/test_json.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "knowhere/common/config.h"
|
||||
|
||||
using namespace zilliz::knowhere;
|
||||
|
||||
int main(){
|
||||
Config cfg;
|
||||
|
||||
cfg["size"] = size_t(199);
|
||||
auto size = cfg.get_with_default("size", 123);
|
||||
auto size_2 = cfg["size"].as<int>();
|
||||
printf("%d", size_2);
|
||||
}
|
||||
162
cpp/src/core/test/test_kdt.cpp
Normal file
162
cpp/src/core/test/test_kdt.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "knowhere/index/vector_index/cpu_kdt_rng.h"
|
||||
#include "knowhere/index/vector_index/definitions.h"
|
||||
#include "knowhere/adapter/sptag.h"
|
||||
#include "knowhere/adapter/structure.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
using namespace zilliz::knowhere;
|
||||
|
||||
using ::testing::TestWithParam;
|
||||
using ::testing::Values;
|
||||
using ::testing::Combine;
|
||||
|
||||
|
||||
class KDTTest
|
||||
: public DataGen, public TestWithParam<::std::tuple<Config, Config, Config, Config>> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
std::tie(preprocess_cfg, train_cfg, add_cfg, search_cfg) = GetParam();
|
||||
index_ = std::make_shared<CPUKDTRNG>();
|
||||
Init_with_default();
|
||||
}
|
||||
|
||||
protected:
|
||||
Config preprocess_cfg;
|
||||
Config train_cfg;
|
||||
Config add_cfg;
|
||||
Config search_cfg;
|
||||
std::shared_ptr<CPUKDTRNG> index_ = nullptr;
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(KDTParameters, KDTTest,
|
||||
Values(
|
||||
std::make_tuple(Config(),
|
||||
Config::object{{"TPTNumber", 1}},
|
||||
Config(),
|
||||
Config::object{{"k", 10}})
|
||||
)
|
||||
);
|
||||
|
||||
void AssertAnns(const DatasetPtr &result,
|
||||
const int &nq,
|
||||
const int &k) {
|
||||
auto ids = result->array()[0];
|
||||
for (auto i = 0; i < nq; i++) {
|
||||
EXPECT_EQ(i, *(ids->data()->GetValues<int64_t>(1, i * k)));
|
||||
}
|
||||
}
|
||||
|
||||
void PrintResult(const DatasetPtr &result,
|
||||
const int &nq,
|
||||
const int &k) {
|
||||
auto ids = result->array()[0];
|
||||
auto dists = result->array()[1];
|
||||
|
||||
std::stringstream ss_id;
|
||||
std::stringstream ss_dist;
|
||||
for (auto i = 0; i < 10; i++) {
|
||||
for (auto j = 0; j < k; ++j) {
|
||||
ss_id << *(ids->data()->GetValues<int64_t>(1, i * k + j)) << " ";
|
||||
ss_dist << *(dists->data()->GetValues<float>(1, i * k + j)) << " ";
|
||||
}
|
||||
ss_id << std::endl;
|
||||
ss_dist << std::endl;
|
||||
}
|
||||
std::cout << "id\n" << ss_id.str() << std::endl;
|
||||
std::cout << "dist\n" << ss_dist.str() << std::endl;
|
||||
}
|
||||
|
||||
// TODO(linxj): add test about count() and dimension()
|
||||
TEST_P(KDTTest, kdt_basic) {
|
||||
assert(!xb.empty());
|
||||
|
||||
auto preprocessor = index_->BuildPreprocessor(base_dataset, preprocess_cfg);
|
||||
index_->set_preprocessor(preprocessor);
|
||||
|
||||
auto model = index_->Train(base_dataset, train_cfg);
|
||||
index_->set_index_model(model);
|
||||
index_->Add(base_dataset, add_cfg);
|
||||
auto result = index_->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
|
||||
{
|
||||
auto ids = result->array()[0];
|
||||
auto dists = result->array()[1];
|
||||
|
||||
std::stringstream ss_id;
|
||||
std::stringstream ss_dist;
|
||||
for (auto i = 0; i < nq; i++) {
|
||||
for (auto j = 0; j < k; ++j) {
|
||||
ss_id << *ids->data()->GetValues<int64_t>(1, i * k + j) << " ";
|
||||
ss_dist << *dists->data()->GetValues<float>(1, i * k + j) << " ";
|
||||
}
|
||||
ss_id << std::endl;
|
||||
ss_dist << std::endl;
|
||||
}
|
||||
std::cout << "id\n" << ss_id.str() << std::endl;
|
||||
std::cout << "dist\n" << ss_dist.str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(KDTTest, kdt_serialize) {
|
||||
assert(!xb.empty());
|
||||
|
||||
auto preprocessor = index_->BuildPreprocessor(base_dataset, preprocess_cfg);
|
||||
index_->set_preprocessor(preprocessor);
|
||||
|
||||
auto model = index_->Train(base_dataset, train_cfg);
|
||||
//index_->Add(base_dataset, add_cfg);
|
||||
auto binaryset = index_->Serialize();
|
||||
auto new_index = std::make_shared<CPUKDTRNG>();
|
||||
new_index->Load(binaryset);
|
||||
auto result = new_index->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
PrintResult(result, nq, k);
|
||||
|
||||
{
|
||||
int fileno = 0;
|
||||
const std::string &base_name = "/tmp/kdt_serialize_test_bin_";
|
||||
std::vector<std::string> filename_list;
|
||||
std::vector<std::pair<std::string, size_t >> meta_list;
|
||||
for (auto &iter: binaryset.binary_map_) {
|
||||
const std::string &filename = base_name + std::to_string(fileno);
|
||||
FileIOWriter writer(filename);
|
||||
writer(iter.second->data.get(), iter.second->size);
|
||||
|
||||
meta_list.emplace_back(std::make_pair(iter.first, iter.second->size));
|
||||
filename_list.push_back(filename);
|
||||
++fileno;
|
||||
}
|
||||
|
||||
BinarySet load_data_list;
|
||||
for (int i = 0; i < filename_list.size() && i < meta_list.size(); ++i) {
|
||||
auto bin_size = meta_list[i].second;
|
||||
FileIOReader reader(filename_list[i]);
|
||||
|
||||
auto load_data = new uint8_t[bin_size];
|
||||
reader(load_data, bin_size);
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(load_data);
|
||||
load_data_list.Append(meta_list[i].first, data, bin_size);
|
||||
}
|
||||
|
||||
auto new_index = std::make_shared<CPUKDTRNG>();
|
||||
new_index->Load(load_data_list);
|
||||
auto result = new_index->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
PrintResult(result, nq, k);
|
||||
}
|
||||
}
|
||||
98
cpp/src/core/test/test_nsg.cpp
Normal file
98
cpp/src/core/test/test_nsg.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <utils.h>
|
||||
#include "index.h"
|
||||
|
||||
//#include <gperftools/profiler.h>
|
||||
|
||||
using namespace zilliz::knowhere;
|
||||
|
||||
void load_data(std::string &filename, float *&data, unsigned &num,
|
||||
unsigned &dim) { // load data with sift10K pattern
|
||||
std::ifstream in(filename, std::ios::binary);
|
||||
if (!in.is_open()) {
|
||||
std::cout << "open file error" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
in.read((char *) &dim, 4);
|
||||
in.seekg(0, std::ios::end);
|
||||
std::ios::pos_type ss = in.tellg();
|
||||
size_t fsize = (size_t) ss;
|
||||
num = (unsigned) (fsize / (dim + 1) / 4);
|
||||
data = new float[(size_t) num * (size_t) dim];
|
||||
|
||||
in.seekg(0, std::ios::beg);
|
||||
for (size_t i = 0; i < num; i++) {
|
||||
in.seekg(4, std::ios::cur);
|
||||
in.read((char *) (data + i * dim), dim * 4);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
|
||||
void test_distance() {
|
||||
std::vector<float> xb{1, 2, 3, 4};
|
||||
std::vector<float> xq{2, 2, 3, 4};
|
||||
float r = calculate(xb.data(), xq.data(), 4);
|
||||
std::cout << r << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_distance();
|
||||
|
||||
BuildParams params;
|
||||
params.search_length = 100;
|
||||
params.candidate_pool_size = 100;
|
||||
params.out_degree = 50;
|
||||
|
||||
float *data = nullptr;
|
||||
long *ids = nullptr;
|
||||
unsigned ntotal, dim;
|
||||
std::string filename = "/home/zilliz/opt/workspace/wook/efanna_graph/tests/siftsmall/siftsmall_base.fvecs";
|
||||
//std::string filename = "/home/zilliz/opt/workspace/wook/efanna_graph/tests/sift/sift_base.fvecs";
|
||||
|
||||
load_data(filename, data, ntotal, dim);
|
||||
assert(data);
|
||||
//float x = calculate(data + dim * 0, data + dim * 62, dim);
|
||||
//std::cout << x << std::endl;
|
||||
|
||||
NsgIndex index(dim, ntotal);
|
||||
|
||||
auto s = std::chrono::high_resolution_clock::now();
|
||||
index.Build_with_ids(ntotal, data, ids, params);
|
||||
auto e = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> diff = e - s;
|
||||
std::cout << "indexing time: " << diff.count() << "\n";
|
||||
|
||||
|
||||
int k = 10;
|
||||
int nq = 1000;
|
||||
SearchParams s_params;
|
||||
s_params.search_length = 50;
|
||||
auto dist = new float[nq*k];
|
||||
auto ids_b = new long[nq*k];
|
||||
s = std::chrono::high_resolution_clock::now();
|
||||
//ProfilerStart("xx.prof");
|
||||
index.Search(data, nq, dim, k, dist, ids_b, s_params);
|
||||
//ProfilerStop();
|
||||
e = std::chrono::high_resolution_clock::now();
|
||||
diff = e - s;
|
||||
std::cout << "search time: " << diff.count() << "\n";
|
||||
|
||||
for (int i = 0; i < k; ++i) {
|
||||
std::cout << "id " << ids_b[i] << std::endl;
|
||||
//std::cout << "dist " << dist[i] << std::endl;
|
||||
}
|
||||
|
||||
delete[] dist;
|
||||
delete[] ids_b;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
48
cpp/src/core/test/test_nsg/CMakeLists.txt
Normal file
48
cpp/src/core/test/test_nsg/CMakeLists.txt
Normal file
@ -0,0 +1,48 @@
|
||||
##############################
|
||||
include_directories(/usr/local/include/gperftools)
|
||||
link_directories(/usr/local/lib)
|
||||
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
|
||||
add_definitions(-std=c++11 -O3 -lboost -march=native -Wall -DINFO)
|
||||
|
||||
find_package(OpenMP)
|
||||
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 ()
|
||||
message(${OpenMP_CXX_FLAGS})
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/nsg)
|
||||
#include_directories(/home/zilliz/opt/app/pyenv/versions/3.6.8/include/python3.6m)
|
||||
#include_directories(/home/zilliz/opt/app/pyenv/versions/3.6.8/envs/megasearch_testframework_dev/lib/python3.6/site-packages/numpy/core/include)
|
||||
|
||||
aux_source_directory(${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/nsg nsg_src)
|
||||
|
||||
#add_library(nsg_raw SHARED ${nsg_src})
|
||||
#target_link_libraries(nsg_raw
|
||||
# gomp)
|
||||
|
||||
set(interface_src
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/ivf.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/gpu_ivf.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/index/vector_index/nsg_index.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/adapter/structure.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/common/exception.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/knowhere/common/timer.cpp
|
||||
../utils.cpp
|
||||
)
|
||||
|
||||
add_executable(test_nsg
|
||||
test_nsg.cpp
|
||||
${interface_src}
|
||||
${nsg_src}
|
||||
)
|
||||
#target_link_libraries(test_nsg
|
||||
# # libprofiler.so
|
||||
## -ltcmalloc
|
||||
## gomp
|
||||
# )
|
||||
target_link_libraries(test_nsg ${depend_libs} ${unittest_libs} ${basic_libs})
|
||||
##############################
|
||||
82
cpp/src/core/test/test_nsg/test_nsg.cpp
Normal file
82
cpp/src/core/test/test_nsg/test_nsg.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
|
||||
#include "knowhere/index/vector_index/nsg_index.h"
|
||||
#include "knowhere/index/vector_index/nsg/nsg_io.h"
|
||||
|
||||
#include "../utils.h"
|
||||
|
||||
|
||||
using namespace zilliz::knowhere;
|
||||
using ::testing::TestWithParam;
|
||||
using ::testing::Values;
|
||||
using ::testing::Combine;
|
||||
|
||||
class NSGInterfaceTest : public DataGen, public TestWithParam<::std::tuple<Config, Config>> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
//Init_with_default();
|
||||
Generate(256, 1000000, 1);
|
||||
index_ = std::make_shared<NSG>();
|
||||
std::tie(train_cfg, search_cfg) = GetParam();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<NSG> index_;
|
||||
Config train_cfg;
|
||||
Config search_cfg;
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(NSGparameters, NSGInterfaceTest,
|
||||
Values(std::make_tuple(
|
||||
// search length > out_degree
|
||||
Config::object{{"nlist", 16384}, {"nprobe", 50}, {"knng", 100}, {"metric_type", "L2"},
|
||||
{"search_length", 60}, {"out_degree", 70}, {"candidate_pool_size", 500}},
|
||||
Config::object{{"k", 20}, {"search_length", 30}}))
|
||||
);
|
||||
|
||||
void AssertAnns(const DatasetPtr &result,
|
||||
const int &nq,
|
||||
const int &k) {
|
||||
auto ids = result->array()[0];
|
||||
for (auto i = 0; i < nq; i++) {
|
||||
EXPECT_EQ(i, *(ids->data()->GetValues<int64_t>(1, i * k)));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(NSGInterfaceTest, basic_test) {
|
||||
assert(!xb.empty());
|
||||
|
||||
auto model = index_->Train(base_dataset, train_cfg);
|
||||
auto result = index_->Search(query_dataset, search_cfg);
|
||||
AssertAnns(result, nq, k);
|
||||
|
||||
auto binaryset = index_->Serialize();
|
||||
auto new_index = std::make_shared<NSG>();
|
||||
new_index->Load(binaryset);
|
||||
auto new_result = new_index->Search(query_dataset, Config::object{{"k", k}});
|
||||
AssertAnns(result, nq, k);
|
||||
|
||||
{
|
||||
//std::cout << "k = 1" << std::endl;
|
||||
//new_index->Search(GenQuery(1), Config::object{{"k", 1}});
|
||||
//new_index->Search(GenQuery(10), Config::object{{"k", 1}});
|
||||
//new_index->Search(GenQuery(100), Config::object{{"k", 1}});
|
||||
//new_index->Search(GenQuery(1000), Config::object{{"k", 1}});
|
||||
//new_index->Search(GenQuery(10000), Config::object{{"k", 1}});
|
||||
|
||||
//std::cout << "k = 5" << std::endl;
|
||||
//new_index->Search(GenQuery(1), Config::object{{"k", 5}});
|
||||
//new_index->Search(GenQuery(20), Config::object{{"k", 5}});
|
||||
//new_index->Search(GenQuery(100), Config::object{{"k", 5}});
|
||||
//new_index->Search(GenQuery(300), Config::object{{"k", 5}});
|
||||
//new_index->Search(GenQuery(500), Config::object{{"k", 5}});
|
||||
}
|
||||
}
|
||||
|
||||
131
cpp/src/core/test/utils.cpp
Normal file
131
cpp/src/core/test/utils.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
void DataGen::Init_with_default() {
|
||||
Generate(dim, nb, nq);
|
||||
}
|
||||
|
||||
void DataGen::Generate(const int &dim, const int &nb, const int &nq) {
|
||||
this->nb = nb;
|
||||
this->nq = nq;
|
||||
this->dim = dim;
|
||||
|
||||
GenAll(dim, nb, xb, ids, nq, xq);
|
||||
assert(xb.size() == dim * nb);
|
||||
assert(xq.size() == dim * nq);
|
||||
|
||||
base_dataset = generate_dataset(nb, dim, xb.data(), ids.data());
|
||||
query_dataset = generate_query_dataset(nq, dim, xq.data());
|
||||
|
||||
}
|
||||
zilliz::knowhere::DatasetPtr DataGen::GenQuery(const int &nq) {
|
||||
xq.resize(nq * dim);
|
||||
for (size_t i = 0; i < nq * dim; ++i) {
|
||||
xq[i] = xb[i];
|
||||
}
|
||||
return generate_query_dataset(nq, dim, xq.data());
|
||||
}
|
||||
|
||||
void GenAll(const int64_t dim,
|
||||
const int64_t &nb,
|
||||
std::vector<float> &xb,
|
||||
std::vector<int64_t> &ids,
|
||||
const int64_t &nq,
|
||||
std::vector<float> &xq) {
|
||||
xb.resize(nb * dim);
|
||||
xq.resize(nq * dim);
|
||||
ids.resize(nb);
|
||||
GenAll(dim, nb, xb.data(), ids.data(), nq, xq.data());
|
||||
}
|
||||
|
||||
void GenAll(const int64_t &dim,
|
||||
const int64_t &nb,
|
||||
float *xb,
|
||||
int64_t *ids,
|
||||
const int64_t &nq,
|
||||
float *xq) {
|
||||
GenBase(dim, nb, xb, ids);
|
||||
for (size_t i = 0; i < nq * dim; ++i) {
|
||||
xq[i] = xb[i];
|
||||
}
|
||||
}
|
||||
|
||||
void GenBase(const int64_t &dim,
|
||||
const int64_t &nb,
|
||||
float *xb,
|
||||
int64_t *ids) {
|
||||
for (auto i = 0; i < nb; ++i) {
|
||||
for (auto j = 0; j < dim; ++j) {
|
||||
//p_data[i * d + j] = float(base + i);
|
||||
xb[i * dim + j] = drand48();
|
||||
}
|
||||
xb[dim * i] += i / 1000.;
|
||||
ids[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
FileIOReader::FileIOReader(const std::string &fname) {
|
||||
name = fname;
|
||||
fs = std::fstream(name, std::ios::in | std::ios::binary);
|
||||
}
|
||||
|
||||
FileIOReader::~FileIOReader() {
|
||||
fs.close();
|
||||
}
|
||||
|
||||
size_t FileIOReader::operator()(void *ptr, size_t size) {
|
||||
fs.read(reinterpret_cast<char *>(ptr), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
FileIOWriter::FileIOWriter(const std::string &fname) {
|
||||
name = fname;
|
||||
fs = std::fstream(name, std::ios::out | std::ios::binary);
|
||||
}
|
||||
|
||||
FileIOWriter::~FileIOWriter() {
|
||||
fs.close();
|
||||
}
|
||||
|
||||
size_t FileIOWriter::operator()(void *ptr, size_t size) {
|
||||
fs.write(reinterpret_cast<char *>(ptr), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
using namespace zilliz::knowhere;
|
||||
|
||||
DatasetPtr
|
||||
generate_dataset(int64_t nb, int64_t dim, float *xb, long *ids) {
|
||||
std::vector<int64_t> shape{nb, dim};
|
||||
auto tensor = ConstructFloatTensor((uint8_t *) xb, nb * dim * sizeof(float), shape);
|
||||
std::vector<TensorPtr> tensors{tensor};
|
||||
std::vector<FieldPtr> tensor_fields{ConstructFloatField("data")};
|
||||
auto tensor_schema = std::make_shared<Schema>(tensor_fields);
|
||||
|
||||
auto id_array = ConstructInt64Array((uint8_t *) ids, nb * sizeof(int64_t));
|
||||
std::vector<ArrayPtr> arrays{id_array};
|
||||
std::vector<FieldPtr> array_fields{ConstructInt64Field("id")};
|
||||
auto array_schema = std::make_shared<Schema>(tensor_fields);
|
||||
|
||||
auto dataset = std::make_shared<Dataset>(std::move(arrays), array_schema,
|
||||
std::move(tensors), tensor_schema);
|
||||
return dataset;
|
||||
}
|
||||
|
||||
DatasetPtr
|
||||
generate_query_dataset(int64_t nb, int64_t dim, float *xb) {
|
||||
std::vector<int64_t> shape{nb, dim};
|
||||
auto tensor = ConstructFloatTensor((uint8_t *) xb, nb * dim * sizeof(float), shape);
|
||||
std::vector<TensorPtr> tensors{tensor};
|
||||
std::vector<FieldPtr> tensor_fields{ConstructFloatField("data")};
|
||||
auto tensor_schema = std::make_shared<Schema>(tensor_fields);
|
||||
|
||||
auto dataset = std::make_shared<Dataset>(std::move(tensors), tensor_schema);
|
||||
return dataset;
|
||||
}
|
||||
79
cpp/src/core/test/utils.h
Normal file
79
cpp/src/core/test/utils.h
Normal file
@ -0,0 +1,79 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
|
||||
#include "knowhere/adapter/structure.h"
|
||||
|
||||
class DataGen {
|
||||
protected:
|
||||
void Init_with_default();
|
||||
|
||||
void Generate(const int &dim, const int &nb, const int &nq);
|
||||
|
||||
zilliz::knowhere::DatasetPtr GenQuery(const int&nq);
|
||||
|
||||
protected:
|
||||
int nb = 10000;
|
||||
int nq = 10;
|
||||
int dim = 64;
|
||||
int k = 10;
|
||||
std::vector<float> xb;
|
||||
std::vector<float> xq;
|
||||
std::vector<int64_t> ids;
|
||||
zilliz::knowhere::DatasetPtr base_dataset = nullptr;
|
||||
zilliz::knowhere::DatasetPtr query_dataset = nullptr;
|
||||
};
|
||||
|
||||
|
||||
extern void GenAll(const int64_t dim,
|
||||
const int64_t &nb,
|
||||
std::vector<float> &xb,
|
||||
std::vector<int64_t> &ids,
|
||||
const int64_t &nq,
|
||||
std::vector<float> &xq);
|
||||
|
||||
extern void GenAll(const int64_t &dim,
|
||||
const int64_t &nb,
|
||||
float *xb,
|
||||
int64_t *ids,
|
||||
const int64_t &nq,
|
||||
float *xq);
|
||||
|
||||
extern void GenBase(const int64_t &dim,
|
||||
const int64_t &nb,
|
||||
float *xb,
|
||||
int64_t *ids);
|
||||
|
||||
zilliz::knowhere::DatasetPtr
|
||||
generate_dataset(int64_t nb, int64_t dim, float *xb, long *ids);
|
||||
|
||||
zilliz::knowhere::DatasetPtr
|
||||
generate_query_dataset(int64_t nb, int64_t dim, float *xb);
|
||||
|
||||
struct FileIOWriter {
|
||||
std::fstream fs;
|
||||
std::string name;
|
||||
|
||||
FileIOWriter(const std::string &fname);
|
||||
~FileIOWriter();
|
||||
size_t operator()(void *ptr, size_t size);
|
||||
};
|
||||
|
||||
struct FileIOReader {
|
||||
std::fstream fs;
|
||||
std::string name;
|
||||
|
||||
FileIOReader(const std::string &fname);
|
||||
~FileIOReader();
|
||||
size_t operator()(void *ptr, size_t size);
|
||||
};
|
||||
|
||||
35
cpp/src/core/thirdparty/SPTAG/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
35
cpp/src/core/thirdparty/SPTAG/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
17
cpp/src/core/thirdparty/SPTAG/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
17
cpp/src/core/thirdparty/SPTAG/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
93
cpp/src/core/thirdparty/SPTAG/.gitignore
vendored
Normal file
93
cpp/src/core/thirdparty/SPTAG/.gitignore
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
/.vs/SPTAG/v14
|
||||
/AnnService/x64
|
||||
/obj/x64_Release
|
||||
/PythonWrapper/x64/Release
|
||||
/x64/Release
|
||||
/SPTAG.VC.db
|
||||
/SPTAG.VC.VC.opendb
|
||||
/AnnService/CoreLibrary.vcxproj.user
|
||||
/AnnService/IndexBuilder.vcxproj.user
|
||||
/AnnService/Server.vcxproj.user
|
||||
/AnnService/SocketLib.vcxproj.user
|
||||
/PythonWrapper/PythonCore.vcxproj.user
|
||||
/build
|
||||
/PythonWrapper/inc/ClientInterface_wrap.cxx
|
||||
/PythonWrapper/inc/CoreInterface_wrap.cxx
|
||||
/PythonWrapper/inc/SPTAG.py
|
||||
/PythonWrapper/inc/SPTAGClient.py
|
||||
/ipch/TEST-4fb66b42
|
||||
/obj/x64_Debug
|
||||
/x64/Debug
|
||||
/packages
|
||||
/Search/Search.vcxproj.user
|
||||
/AnnService/IndexSearcher.vcxproj.user
|
||||
/Wrappers/inc/SWIGTYPE_p_RemoteSearchResult.java
|
||||
/Wrappers/inc/SWIGTYPE_p_QueryResult.java
|
||||
/Wrappers/inc/SPTAGJNI.java
|
||||
/Wrappers/inc/SPTAGClientJNI.java
|
||||
/Wrappers/inc/SPTAGClient.py
|
||||
/Wrappers/inc/SPTAGClient.java
|
||||
/Wrappers/inc/SPTAG.py
|
||||
/Wrappers/inc/SPTAG.java
|
||||
/Wrappers/inc/CoreInterface_pwrap.cpp
|
||||
/Wrappers/inc/CoreInterface_jwrap.cpp
|
||||
/Wrappers/inc/ClientInterface_pwrap.cpp
|
||||
/Wrappers/inc/ClientInterface_jwrap.cpp
|
||||
/Wrappers/inc/AnnIndex.java
|
||||
/Wrappers/inc/AnnClient.java
|
||||
/AnnService.users - Copy.props
|
||||
/.vs
|
||||
Release/
|
||||
Debug/
|
||||
18
cpp/src/core/thirdparty/SPTAG/AnnService.users.props
vendored
Normal file
18
cpp/src/core/thirdparty/SPTAG/AnnService.users.props
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(SolutionDir)AnnService.users.props.user" Condition="Exists('$(SolutionDir)AnnService.users.props.user')" />
|
||||
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalOptions>$(SystemVersionDef) %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<PropertyGroup Label="UserMacros">
|
||||
<OutAppDir>$(SolutionDir)\$(Platform)\$(Configuration)\</OutAppDir>
|
||||
<OutLibDir>$(SolutionDir)\$(Platform)\$(Configuration)\</OutLibDir>
|
||||
<JavaIncDir></JavaIncDir>
|
||||
<JavaLib></JavaLib>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
178
cpp/src/core/thirdparty/SPTAG/AnnService/Aggregator.vcxproj
vendored
Normal file
178
cpp/src/core/thirdparty/SPTAG/AnnService/Aggregator.vcxproj
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{D7F09A63-BDCA-4F6C-A864-8551D1FE447A}</ProjectGuid>
|
||||
<RootNamespace>Aggregator</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(SolutionDir)\AnnService.users.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(SolutionDir)obj\$(Platform)_$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
<OutDir>$(OutAppDir)</OutDir>
|
||||
<LibraryPath>$(OutLibDir);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/guard:cf
|
||||
%(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Aggregator\AggregatorContext.h" />
|
||||
<ClInclude Include="inc\Aggregator\AggregatorExecutionContext.h" />
|
||||
<ClInclude Include="inc\Aggregator\AggregatorService.h" />
|
||||
<ClInclude Include="inc\Aggregator\AggregatorSettings.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Aggregator\AggregatorContext.cpp" />
|
||||
<ClCompile Include="src\Aggregator\AggregatorExecutionContext.cpp" />
|
||||
<ClCompile Include="src\Aggregator\AggregatorService.cpp" />
|
||||
<ClCompile Include="src\Aggregator\AggregatorSettings.cpp" />
|
||||
<ClCompile Include="src\Aggregator\main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\boost.1.67.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.67.0.0\build\boost.targets')" />
|
||||
<Import Project="..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets" Condition="Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets" Condition="Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets" Condition="Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets" Condition="Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets" Condition="Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets" Condition="Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\boost.1.67.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.67.0.0\build\boost.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
44
cpp/src/core/thirdparty/SPTAG/AnnService/Aggregator.vcxproj.filters
vendored
Normal file
44
cpp/src/core/thirdparty/SPTAG/AnnService/Aggregator.vcxproj.filters
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Aggregator\AggregatorService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Aggregator\AggregatorContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Aggregator\AggregatorSettings.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Aggregator\AggregatorExecutionContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Aggregator\AggregatorService.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Aggregator\AggregatorContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Aggregator\AggregatorExecutionContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Aggregator\AggregatorSettings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Aggregator\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
44
cpp/src/core/thirdparty/SPTAG/AnnService/CMakeLists.txt
vendored
Normal file
44
cpp/src/core/thirdparty/SPTAG/AnnService/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
file(GLOB HDR_FILES ${PROJECT_SOURCE_DIR}/AnnService/inc/Core/*.h ${PROJECT_SOURCE_DIR}/AnnService/inc/Core/Common/*.h ${PROJECT_SOURCE_DIR}/AnnService/inc/Core/BKT/*.h ${PROJECT_SOURCE_DIR}/AnnService/inc/Core/KDT/*.h ${PROJECT_SOURCE_DIR}/AnnService/inc/Helper/*.h)
|
||||
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/AnnService/src/Core/*.cpp ${PROJECT_SOURCE_DIR}/AnnService/src/Core/Common/*.cpp ${PROJECT_SOURCE_DIR}/AnnService/src/Core/BKT/*.cpp ${PROJECT_SOURCE_DIR}/AnnService/src/Core/KDT/*.cpp ${PROJECT_SOURCE_DIR}/AnnService/src/Helper/*.cpp)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/AnnService)
|
||||
|
||||
add_library (SPTAGLib SHARED ${SRC_FILES} ${HDR_FILES})
|
||||
target_link_libraries (SPTAGLib ${TBB_LIBRARIES})
|
||||
add_library (SPTAGLibStatic STATIC ${SRC_FILES} ${HDR_FILES})
|
||||
set_target_properties(SPTAGLibStatic PROPERTIES OUTPUT_NAME SPTAGLib)
|
||||
|
||||
file(GLOB SERVER_HDR_FILES ${HDR_FILES} ${PROJECT_SOURCE_DIR}/AnnService/inc/Server/*.h ${PROJECT_SOURCE_DIR}/AnnService/inc/Socket/*.h)
|
||||
file(GLOB SERVER_FILES ${SRC_FILES} ${PROJECT_SOURCE_DIR}/AnnService/src/Server/*.cpp ${PROJECT_SOURCE_DIR}/AnnService/src/Socket/*.cpp)
|
||||
add_executable (server ${SERVER_FILES} ${SERVER_HDR_FILES})
|
||||
target_link_libraries(server ${Boost_LIBRARIES} ${TBB_LIBRARIES})
|
||||
|
||||
file(GLOB CLIENT_HDR_FILES ${HDR_FILES} ${PROJECT_SOURCE_DIR}/AnnService/inc/Client/*.h ${PROJECT_SOURCE_DIR}/AnnService/inc/Socket/*.h)
|
||||
file(GLOB CLIENT_FILES ${SRC_FILES} ${PROJECT_SOURCE_DIR}/AnnService/src/Client/*.cpp ${PROJECT_SOURCE_DIR}/AnnService/src/Socket/*.cpp)
|
||||
add_executable (client ${CLIENT_FILES} ${CLIENT_HDR_FILES})
|
||||
target_link_libraries(client ${Boost_LIBRARIES} ${TBB_LIBRARIES})
|
||||
|
||||
file(GLOB AGG_HDR_FILES ${HDR_FILES} ${PROJECT_SOURCE_DIR}/AnnService/inc/Aggregator/*.h ${PROJECT_SOURCE_DIR}/AnnService/inc/Socket/*.h)
|
||||
file(GLOB AGG_FILES ${SRC_FILES} ${PROJECT_SOURCE_DIR}/AnnService/src/Aggregator/*.cpp ${PROJECT_SOURCE_DIR}/AnnService/src/Socket/*.cpp)
|
||||
add_executable (aggregator ${AGG_FILES} ${AGG_HDR_FILES})
|
||||
target_link_libraries(aggregator ${Boost_LIBRARIES} ${TBB_LIBRARIES})
|
||||
|
||||
file(GLOB BUILDER_HDR_FILES ${HDR_FILES} ${PROJECT_SOURCE_DIR}/AnnService/inc/IndexBuilder/*.h ${PROJECT_SOURCE_DIR}/AnnService/inc/IndexBuilder/VectorSetReaders/*.h)
|
||||
file(GLOB BUILDER_FILES ${SRC_FILES} ${PROJECT_SOURCE_DIR}/AnnService/src/IndexBuilder/*.cpp ${PROJECT_SOURCE_DIR}/AnnService/src/IndexBuilder/VectorSetReaders/*.cpp)
|
||||
add_executable (indexbuilder ${BUILDER_FILES} ${BUILDER_HDR_FILES})
|
||||
target_link_libraries(indexbuilder ${Boost_LIBRARIES} ${TBB_LIBRARIES})
|
||||
|
||||
file(GLOB SEARCHER_FILES ${SRC_FILES} ${PROJECT_SOURCE_DIR}/AnnService/src/IndexSearcher/*.cpp)
|
||||
add_executable (indexsearcher ${SEARCHER_FILES} ${HDR_FILES})
|
||||
target_link_libraries(indexsearcher ${Boost_LIBRARIES} ${TBB_LIBRARIES})
|
||||
|
||||
install(TARGETS SPTAGLib SPTAGLibStatic server client aggregator indexbuilder indexsearcher
|
||||
RUNTIME DESTINATION bin
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib)
|
||||
|
||||
install(DIRECTORY inc DESTINATION include/sptag
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
145
cpp/src/core/thirdparty/SPTAG/AnnService/Client.vcxproj
vendored
Normal file
145
cpp/src/core/thirdparty/SPTAG/AnnService/Client.vcxproj
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{A89D70C3-C53B-42DE-A5CE-9A472540F5CB}</ProjectGuid>
|
||||
<RootNamespace>Client</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(SolutionDir)\AnnService.users.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(SolutionDir)obj\$(Platform)_$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
<OutDir>$(OutAppDir)</OutDir>
|
||||
<LibraryPath>$(OutLibDir);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/guard:cf %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Client\ClientWrapper.cpp" />
|
||||
<ClCompile Include="src\Client\main.cpp" />
|
||||
<ClCompile Include="src\Client\Options.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Client\ClientWrapper.h" />
|
||||
<ClInclude Include="inc\Client\Options.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\boost.1.67.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.67.0.0\build\boost.targets')" />
|
||||
<Import Project="..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets" Condition="Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets" Condition="Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets" Condition="Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets" Condition="Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets" Condition="Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets" Condition="Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\boost.1.67.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.67.0.0\build\boost.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
32
cpp/src/core/thirdparty/SPTAG/AnnService/Client.vcxproj.filters
vendored
Normal file
32
cpp/src/core/thirdparty/SPTAG/AnnService/Client.vcxproj.filters
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Client\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Client\ClientWrapper.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Client\Options.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Client\Options.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Client\ClientWrapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
193
cpp/src/core/thirdparty/SPTAG/AnnService/CoreLibrary.vcxproj
vendored
Normal file
193
cpp/src/core/thirdparty/SPTAG/AnnService/CoreLibrary.vcxproj
vendored
Normal file
@ -0,0 +1,193 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{C2BC5FDE-C853-4F3D-B7E4-2C9B5524DDF9}</ProjectGuid>
|
||||
<RootNamespace>CoreLibrary</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
<ProjectName>CoreLibrary</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(SolutionDir)\AnnService.users.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IncludePath>$(IncludePath);$(ProjectDir)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<IntDir>$(SolutionDir)obj\$(Platform)_$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<OutDir>$(OutLibDir)</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalOptions>/Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalOptions>/Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Core\Common\FineGrainedLock.h" />
|
||||
<ClInclude Include="inc\Core\Common\WorkSpace.h" />
|
||||
<ClInclude Include="inc\Core\Common\CommonUtils.h" />
|
||||
<ClInclude Include="inc\Core\Common\Dataset.h" />
|
||||
<ClInclude Include="inc\Core\Common\DataUtils.h" />
|
||||
<ClInclude Include="inc\Core\Common\DistanceUtils.h" />
|
||||
<ClInclude Include="inc\Core\Common\Heap.h" />
|
||||
<ClInclude Include="inc\Core\Common\QueryResultSet.h" />
|
||||
<ClInclude Include="inc\Core\Common\WorkSpacePool.h" />
|
||||
<ClInclude Include="inc\Core\BKT\Index.h" />
|
||||
<ClInclude Include="inc\Core\BKT\ParameterDefinitionList.h" />
|
||||
<ClInclude Include="inc\Core\KDT\Index.h" />
|
||||
<ClInclude Include="inc\Core\KDT\ParameterDefinitionList.h" />
|
||||
<ClInclude Include="inc\Core\Common.h" />
|
||||
<ClInclude Include="inc\Core\CommonDataStructure.h" />
|
||||
<ClInclude Include="inc\Core\DefinitionList.h" />
|
||||
<ClInclude Include="inc\Core\MetadataSet.h" />
|
||||
<ClInclude Include="inc\Core\SearchQuery.h" />
|
||||
<ClInclude Include="inc\Core\VectorIndex.h" />
|
||||
<ClInclude Include="inc\Core\VectorSet.h" />
|
||||
<ClInclude Include="inc\Helper\ArgumentsParser.h" />
|
||||
<ClInclude Include="inc\Helper\Base64Encode.h" />
|
||||
<ClInclude Include="inc\Helper\CommonHelper.h" />
|
||||
<ClInclude Include="inc\Helper\Concurrent.h" />
|
||||
<ClInclude Include="inc\Helper\SimpleIniReader.h" />
|
||||
<ClInclude Include="inc\Helper\StringConvert.h" />
|
||||
<ClInclude Include="inc\Core\Common\NeighborhoodGraph.h" />
|
||||
<ClInclude Include="inc\Core\Common\RelativeNeighborhoodGraph.h" />
|
||||
<ClInclude Include="inc\Core\Common\BKTree.h" />
|
||||
<ClInclude Include="inc\Core\Common\KDTree.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Core\BKT\BKTIndex.cpp" />
|
||||
<ClCompile Include="src\Core\Common\NeighborhoodGraph.cpp" />
|
||||
<ClCompile Include="src\Core\KDT\KDTIndex.cpp" />
|
||||
<ClCompile Include="src\Core\Common\WorkSpacePool.cpp" />
|
||||
<ClCompile Include="src\Core\CommonDataStructure.cpp" />
|
||||
<ClCompile Include="src\Core\MetadataSet.cpp" />
|
||||
<ClCompile Include="src\Core\VectorIndex.cpp" />
|
||||
<ClCompile Include="src\Core\VectorSet.cpp" />
|
||||
<ClCompile Include="src\Helper\ArgumentsParser.cpp" />
|
||||
<ClCompile Include="src\Helper\Base64Encode.cpp" />
|
||||
<ClCompile Include="src\Helper\CommonHelper.cpp" />
|
||||
<ClCompile Include="src\Helper\Concurrent.cpp" />
|
||||
<ClCompile Include="src\Helper\SimpleIniReader.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets" Condition="Exists('..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
178
cpp/src/core/thirdparty/SPTAG/AnnService/CoreLibrary.vcxproj.filters
vendored
Normal file
178
cpp/src/core/thirdparty/SPTAG/AnnService/CoreLibrary.vcxproj.filters
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{c260e4c4-ec44-4d50-941f-078454da2a89}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Core">
|
||||
<UniqueIdentifier>{c7b9ab49-a99f-4eb4-b8ab-61f0730b9a89}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Core\BKT">
|
||||
<UniqueIdentifier>{a306a099-8e3f-433d-b065-9d99433f422e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Helper">
|
||||
<UniqueIdentifier>{33f272c5-907e-4848-bbd7-4340fe44f511}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Core">
|
||||
<UniqueIdentifier>{47ec2958-e880-4c1a-b663-04fc48c799af}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Core\BKT">
|
||||
<UniqueIdentifier>{10d17e5e-9ad2-4000-96d4-83b616480b97}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Helper">
|
||||
<UniqueIdentifier>{23fdeb31-9052-47d1-8edb-9b47c4b02707}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Core\KDT">
|
||||
<UniqueIdentifier>{6dff7b24-66ea-40b4-b408-d8fe264a6caa}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Core\Common">
|
||||
<UniqueIdentifier>{b0f1e81d-ca05-426e-bffa-75513a52ca6b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Core\Common">
|
||||
<UniqueIdentifier>{774592a9-40aa-4342-a4af-b711a1cc4d52}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Core\KDT">
|
||||
<UniqueIdentifier>{8fb36afb-73ed-4c3d-8c9b-c3581d80c5d1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Core\Common.h">
|
||||
<Filter>Header Files\Core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\CommonDataStructure.h">
|
||||
<Filter>Header Files\Core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\DefinitionList.h">
|
||||
<Filter>Header Files\Core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\SearchQuery.h">
|
||||
<Filter>Header Files\Core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\VectorIndex.h">
|
||||
<Filter>Header Files\Core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\BKT\Index.h">
|
||||
<Filter>Header Files\Core\BKT</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Helper\CommonHelper.h">
|
||||
<Filter>Header Files\Helper</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Helper\SimpleIniReader.h">
|
||||
<Filter>Header Files\Helper</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Helper\StringConvert.h">
|
||||
<Filter>Header Files\Helper</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\MetadataSet.h">
|
||||
<Filter>Header Files\Core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\VectorSet.h">
|
||||
<Filter>Header Files\Core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Helper\Base64Encode.h">
|
||||
<Filter>Header Files\Helper</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Helper\Concurrent.h">
|
||||
<Filter>Header Files\Helper</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Helper\ArgumentsParser.h">
|
||||
<Filter>Header Files\Helper</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\BKT\ParameterDefinitionList.h">
|
||||
<Filter>Header Files\Core\BKT</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\WorkSpace.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\CommonUtils.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\Dataset.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\DataUtils.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\DistanceUtils.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\Heap.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\QueryResultSet.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\WorkSpacePool.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\KDT\Index.h">
|
||||
<Filter>Header Files\Core\KDT</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\KDT\ParameterDefinitionList.h">
|
||||
<Filter>Header Files\Core\KDT</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\FineGrainedLock.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\NeighborhoodGraph.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\RelativeNeighborhoodGraph.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\KDTree.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Core\Common\BKTree.h">
|
||||
<Filter>Header Files\Core\Common</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Core\CommonDataStructure.cpp">
|
||||
<Filter>Source Files\Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Core\VectorIndex.cpp">
|
||||
<Filter>Source Files\Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Core\Common\WorkSpacePool.cpp">
|
||||
<Filter>Source Files\Core\Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Helper\CommonHelper.cpp">
|
||||
<Filter>Source Files\Helper</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Helper\SimpleIniReader.cpp">
|
||||
<Filter>Source Files\Helper</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Core\VectorSet.cpp">
|
||||
<Filter>Source Files\Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Core\MetadataSet.cpp">
|
||||
<Filter>Source Files\Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Helper\Base64Encode.cpp">
|
||||
<Filter>Source Files\Helper</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Helper\Concurrent.cpp">
|
||||
<Filter>Source Files\Helper</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Helper\ArgumentsParser.cpp">
|
||||
<Filter>Source Files\Helper</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Core\BKT\BKTIndex.cpp">
|
||||
<Filter>Source Files\Core\BKT</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Core\KDT\KDTIndex.cpp">
|
||||
<Filter>Source Files\Core\KDT</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Core\Common\NeighborhoodGraph.cpp">
|
||||
<Filter>Source Files\Core\Common</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
179
cpp/src/core/thirdparty/SPTAG/AnnService/IndexBuilder.vcxproj
vendored
Normal file
179
cpp/src/core/thirdparty/SPTAG/AnnService/IndexBuilder.vcxproj
vendored
Normal file
@ -0,0 +1,179 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{F492F794-E78B-4B1F-A556-5E045B9163D5}</ProjectGuid>
|
||||
<RootNamespace>IndexBuilder</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(SolutionDir)\AnnService.users.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup>
|
||||
<IntDir>$(SolutionDir)obj\$(Platform)_$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
<OutDir>$(OutAppDir)</OutDir>
|
||||
<LibraryPath>$(OutLibDir);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalOptions>/guard:cf %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\IndexBuilder\Options.h" />
|
||||
<ClInclude Include="inc\IndexBuilder\ThreadPool.h" />
|
||||
<ClInclude Include="inc\IndexBuilder\VectorSetReader.h" />
|
||||
<ClInclude Include="inc\IndexBuilder\VectorSetReaders\DefaultReader.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\IndexBuilder\main.cpp" />
|
||||
<ClCompile Include="src\IndexBuilder\Options.cpp" />
|
||||
<ClCompile Include="src\IndexBuilder\ThreadPool.cpp" />
|
||||
<ClCompile Include="src\IndexBuilder\VectorSetReader.cpp" />
|
||||
<ClCompile Include="src\IndexBuilder\VectorSetReaders\DefaultReader.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\boost.1.67.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.67.0.0\build\boost.targets')" />
|
||||
<Import Project="..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets" Condition="Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets" Condition="Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets" Condition="Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets" Condition="Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets" Condition="Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets" Condition="Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" />
|
||||
<Import Project="..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets" Condition="Exists('..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\boost.1.67.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.67.0.0\build\boost.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
50
cpp/src/core/thirdparty/SPTAG/AnnService/IndexBuilder.vcxproj.filters
vendored
Normal file
50
cpp/src/core/thirdparty/SPTAG/AnnService/IndexBuilder.vcxproj.filters
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\VectorSetReaders">
|
||||
<UniqueIdentifier>{cf68b421-6a65-44f2-bf43-438b13940d7d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\VectorSetReaders">
|
||||
<UniqueIdentifier>{41ac91f9-6b6d-4341-8791-12f672d6ad5c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\IndexBuilder\Options.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\IndexBuilder\ThreadPool.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\IndexBuilder\VectorSetReader.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\IndexBuilder\VectorSetReaders\DefaultReader.h">
|
||||
<Filter>Header Files\VectorSetReaders</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\IndexBuilder\Options.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\IndexBuilder\ThreadPool.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\IndexBuilder\VectorSetReader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\IndexBuilder\VectorSetReaders\DefaultReader.cpp">
|
||||
<Filter>Source Files\VectorSetReaders</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\IndexBuilder\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
172
cpp/src/core/thirdparty/SPTAG/AnnService/IndexSearcher.vcxproj
vendored
Normal file
172
cpp/src/core/thirdparty/SPTAG/AnnService/IndexSearcher.vcxproj
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{97615D3B-9FA0-469E-B229-95A91A5087E0}</ProjectGuid>
|
||||
<RootNamespace>IndexSearcher</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
<ProjectName>IndexSearcher</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(SolutionDir)\AnnService.users.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup>
|
||||
<IntDir>$(SolutionDir)obj\$(Platform)_$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<IncludePath>$(ProjectDir);$(SolutionDir)AnnService\;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(OutLibDir);$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(OutAppDir)</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalOptions>/guard:cf %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\IndexSearcher\main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\boost.1.67.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.67.0.0\build\boost.targets')" />
|
||||
<Import Project="..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets" Condition="Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets" Condition="Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets" Condition="Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets" Condition="Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets" Condition="Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets" Condition="Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" />
|
||||
<Import Project="..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets" Condition="Exists('..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\boost.1.67.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.67.0.0\build\boost.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
25
cpp/src/core/thirdparty/SPTAG/AnnService/IndexSearcher.vcxproj.filters
vendored
Normal file
25
cpp/src/core/thirdparty/SPTAG/AnnService/IndexSearcher.vcxproj.filters
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\IndexSearcher\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
155
cpp/src/core/thirdparty/SPTAG/AnnService/Server.vcxproj
vendored
Normal file
155
cpp/src/core/thirdparty/SPTAG/AnnService/Server.vcxproj
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{E28B1222-8BEA-4A92-8FE0-088EBDAA7FE0}</ProjectGuid>
|
||||
<RootNamespace>Server</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(SolutionDir)\AnnService.users.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(SolutionDir)obj\$(Platform)_$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
<OutDir>$(OutAppDir)</OutDir>
|
||||
<LibraryPath>$(OutLibDir);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/guard:cf %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Link>
|
||||
<AdditionalDependencies>CoreLibrary.lib;SocketLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Server\QueryParser.h" />
|
||||
<ClInclude Include="inc\Server\SearchExecutor.h" />
|
||||
<ClInclude Include="inc\Server\SearchExecutionContext.h" />
|
||||
<ClInclude Include="inc\Server\SearchService.h" />
|
||||
<ClInclude Include="inc\Server\ServiceContext.h" />
|
||||
<ClInclude Include="inc\Server\ServiceSettings.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Server\main.cpp" />
|
||||
<ClCompile Include="src\Server\QueryParser.cpp" />
|
||||
<ClCompile Include="src\Server\SearchExecutionContext.cpp" />
|
||||
<ClCompile Include="src\Server\SearchExecutor.cpp" />
|
||||
<ClCompile Include="src\Server\SearchService.cpp" />
|
||||
<ClCompile Include="src\Server\ServiceContext.cpp" />
|
||||
<ClCompile Include="src\Server\ServiceSettings.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\boost.1.67.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.67.0.0\build\boost.targets')" />
|
||||
<Import Project="..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets" Condition="Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets" Condition="Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets" Condition="Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets" Condition="Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets" Condition="Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" />
|
||||
<Import Project="..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets" Condition="Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" />
|
||||
<Import Project="..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets" Condition="Exists('..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\boost.1.67.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.67.0.0\build\boost.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_date_time-vc140.1.67.0.0\build\boost_date_time-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_regex-vc140.1.67.0.0\build\boost_regex-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_serialization-vc140.1.67.0.0\build\boost_serialization-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_system-vc140.1.67.0.0\build\boost_system-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_thread-vc140.1.67.0.0\build\boost_thread-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_wserialization-vc140.1.67.0.0\build\boost_wserialization-vc140.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\tbb_oss.9.107.0.0\build\native\tbb_oss.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
56
cpp/src/core/thirdparty/SPTAG/AnnService/Server.vcxproj.filters
vendored
Normal file
56
cpp/src/core/thirdparty/SPTAG/AnnService/Server.vcxproj.filters
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Server\ServiceSettings.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Server\ServiceContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Server\SearchExecutor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Server\SearchExecutionContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Server\QueryParser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Server\SearchService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Server\SearchExecutionContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Server\SearchExecutor.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Server\ServiceContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Server\ServiceSettings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Server\QueryParser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Server\SearchService.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Server\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
123
cpp/src/core/thirdparty/SPTAG/AnnService/SocketLib.vcxproj
vendored
Normal file
123
cpp/src/core/thirdparty/SPTAG/AnnService/SocketLib.vcxproj
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{F9A72303-6381-4C80-86FF-606A2F6F7B96}</ProjectGuid>
|
||||
<RootNamespace>SocketLib</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<Import Project="$(SolutionDir)\AnnService.users.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
<IntDir>$(SolutionDir)obj\$(Platform)_$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<OutDir>$(OutLibDir)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_MBCS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Socket\Common.h" />
|
||||
<ClInclude Include="inc\Socket\Connection.h" />
|
||||
<ClInclude Include="inc\Socket\ConnectionManager.h" />
|
||||
<ClInclude Include="inc\Socket\Packet.h" />
|
||||
<ClInclude Include="inc\Socket\Client.h" />
|
||||
<ClInclude Include="inc\Socket\ResourceManager.h" />
|
||||
<ClInclude Include="inc\Socket\Server.h" />
|
||||
<ClInclude Include="inc\Socket\RemoteSearchQuery.h" />
|
||||
<ClInclude Include="inc\Socket\SimpleSerialization.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Socket\Client.cpp" />
|
||||
<ClCompile Include="src\Socket\Common.cpp" />
|
||||
<ClCompile Include="src\Socket\Connection.cpp" />
|
||||
<ClCompile Include="src\Socket\ConnectionManager.cpp" />
|
||||
<ClCompile Include="src\Socket\Packet.cpp" />
|
||||
<ClCompile Include="src\Socket\RemoteSearchQuery.cpp" />
|
||||
<ClCompile Include="src\Socket\Server.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\boost.1.67.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.67.0.0\build\boost.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\boost.1.67.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.67.0.0\build\boost.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
65
cpp/src/core/thirdparty/SPTAG/AnnService/SocketLib.vcxproj.filters
vendored
Normal file
65
cpp/src/core/thirdparty/SPTAG/AnnService/SocketLib.vcxproj.filters
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\Socket\Packet.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Socket\Connection.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Socket\ConnectionManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Socket\Server.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Socket\Client.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Socket\ResourceManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Socket\Common.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Socket\RemoteSearchQuery.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\Socket\SimpleSerialization.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Socket\Connection.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Socket\ConnectionManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Socket\Packet.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Socket\Server.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Socket\Client.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Socket\Common.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Socket\RemoteSearchQuery.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
67
cpp/src/core/thirdparty/SPTAG/AnnService/inc/Aggregator/AggregatorContext.h
vendored
Normal file
67
cpp/src/core/thirdparty/SPTAG/AnnService/inc/Aggregator/AggregatorContext.h
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifndef _SPTAG_AGGREGATOR_AGGREGATORCONTEXT_H_
|
||||
#define _SPTAG_AGGREGATOR_AGGREGATORCONTEXT_H_
|
||||
|
||||
#include "inc/Socket/Common.h"
|
||||
#include "AggregatorSettings.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
namespace SPTAG
|
||||
{
|
||||
namespace Aggregator
|
||||
{
|
||||
|
||||
enum RemoteMachineStatus : uint8_t
|
||||
{
|
||||
Disconnected = 0,
|
||||
|
||||
Connecting,
|
||||
|
||||
Connected
|
||||
};
|
||||
|
||||
|
||||
struct RemoteMachine
|
||||
{
|
||||
RemoteMachine();
|
||||
|
||||
std::string m_address;
|
||||
|
||||
std::string m_port;
|
||||
|
||||
Socket::ConnectionID m_connectionID;
|
||||
|
||||
std::atomic<RemoteMachineStatus> m_status;
|
||||
};
|
||||
|
||||
class AggregatorContext
|
||||
{
|
||||
public:
|
||||
AggregatorContext(const std::string& p_filePath);
|
||||
|
||||
~AggregatorContext();
|
||||
|
||||
bool IsInitialized() const;
|
||||
|
||||
const std::vector<std::shared_ptr<RemoteMachine>>& GetRemoteServers() const;
|
||||
|
||||
const std::shared_ptr<AggregatorSettings>& GetSettings() const;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<RemoteMachine>> m_remoteServers;
|
||||
|
||||
std::shared_ptr<AggregatorSettings> m_settings;
|
||||
|
||||
bool m_initialized;
|
||||
};
|
||||
|
||||
} // namespace Aggregator
|
||||
} // namespace AnnService
|
||||
|
||||
|
||||
#endif // _SPTAG_AGGREGATOR_AGGREGATORCONTEXT_H_
|
||||
53
cpp/src/core/thirdparty/SPTAG/AnnService/inc/Aggregator/AggregatorExecutionContext.h
vendored
Normal file
53
cpp/src/core/thirdparty/SPTAG/AnnService/inc/Aggregator/AggregatorExecutionContext.h
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifndef _SPTAG_AGGREGATOR_AGGREGATOREXECUTIONCONTEXT_H_
|
||||
#define _SPTAG_AGGREGATOR_AGGREGATOREXECUTIONCONTEXT_H_
|
||||
|
||||
#include "inc/Socket/RemoteSearchQuery.h"
|
||||
#include "inc/Socket/Packet.h"
|
||||
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
|
||||
namespace SPTAG
|
||||
{
|
||||
namespace Aggregator
|
||||
{
|
||||
|
||||
typedef std::shared_ptr<Socket::RemoteSearchResult> AggregatorResult;
|
||||
|
||||
class AggregatorExecutionContext
|
||||
{
|
||||
public:
|
||||
AggregatorExecutionContext(std::size_t p_totalServerNumber,
|
||||
Socket::PacketHeader p_requestHeader);
|
||||
|
||||
~AggregatorExecutionContext();
|
||||
|
||||
std::size_t GetServerNumber() const;
|
||||
|
||||
AggregatorResult& GetResult(std::size_t p_num);
|
||||
|
||||
const Socket::PacketHeader& GetRequestHeader() const;
|
||||
|
||||
bool IsCompletedAfterFinsh(std::uint32_t p_finishedCount);
|
||||
|
||||
private:
|
||||
std::atomic<std::uint32_t> m_unfinishedCount;
|
||||
|
||||
std::vector<AggregatorResult> m_results;
|
||||
|
||||
Socket::PacketHeader m_requestHeader;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Aggregator
|
||||
} // namespace AnnService
|
||||
|
||||
|
||||
#endif // _SPTAG_AGGREGATOR_AGGREGATOREXECUTIONCONTEXT_H_
|
||||
|
||||
88
cpp/src/core/thirdparty/SPTAG/AnnService/inc/Aggregator/AggregatorService.h
vendored
Normal file
88
cpp/src/core/thirdparty/SPTAG/AnnService/inc/Aggregator/AggregatorService.h
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifndef _SPTAG_AGGREGATOR_AGGREGATORSERVICE_H_
|
||||
#define _SPTAG_AGGREGATOR_AGGREGATORSERVICE_H_
|
||||
|
||||
#include "AggregatorContext.h"
|
||||
#include "AggregatorExecutionContext.h"
|
||||
#include "inc/Socket/Server.h"
|
||||
#include "inc/Socket/Client.h"
|
||||
#include "inc/Socket/ResourceManager.h"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace SPTAG
|
||||
{
|
||||
namespace Aggregator
|
||||
{
|
||||
|
||||
class AggregatorService
|
||||
{
|
||||
public:
|
||||
AggregatorService();
|
||||
|
||||
~AggregatorService();
|
||||
|
||||
bool Initialize();
|
||||
|
||||
void Run();
|
||||
|
||||
private:
|
||||
|
||||
void StartClient();
|
||||
|
||||
void StartListen();
|
||||
|
||||
void WaitForShutdown();
|
||||
|
||||
void ConnectToPendingServers();
|
||||
|
||||
void AddToPendingServers(std::shared_ptr<RemoteMachine> p_remoteServer);
|
||||
|
||||
void SearchRequestHanlder(Socket::ConnectionID p_localConnectionID, Socket::Packet p_packet);
|
||||
|
||||
void SearchResponseHanlder(Socket::ConnectionID p_localConnectionID, Socket::Packet p_packet);
|
||||
|
||||
void AggregateResults(std::shared_ptr<AggregatorExecutionContext> p_exectionContext);
|
||||
|
||||
std::shared_ptr<AggregatorContext> GetContext();
|
||||
|
||||
private:
|
||||
typedef std::function<void(Socket::RemoteSearchResult)> AggregatorCallback;
|
||||
|
||||
std::shared_ptr<AggregatorContext> m_aggregatorContext;
|
||||
|
||||
std::shared_ptr<Socket::Server> m_socketServer;
|
||||
|
||||
std::shared_ptr<Socket::Client> m_socketClient;
|
||||
|
||||
bool m_initalized;
|
||||
|
||||
std::unique_ptr<boost::asio::thread_pool> m_threadPool;
|
||||
|
||||
boost::asio::io_context m_ioContext;
|
||||
|
||||
boost::asio::signal_set m_shutdownSignals;
|
||||
|
||||
std::vector<std::shared_ptr<RemoteMachine>> m_pendingConnectServers;
|
||||
|
||||
std::mutex m_pendingConnectServersMutex;
|
||||
|
||||
boost::asio::deadline_timer m_pendingConnectServersTimer;
|
||||
|
||||
Socket::ResourceManager<AggregatorCallback> m_aggregatorCallbackManager;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Aggregator
|
||||
} // namespace AnnService
|
||||
|
||||
|
||||
#endif // _SPTAG_AGGREGATOR_AGGREGATORSERVICE_H_
|
||||
39
cpp/src/core/thirdparty/SPTAG/AnnService/inc/Aggregator/AggregatorSettings.h
vendored
Normal file
39
cpp/src/core/thirdparty/SPTAG/AnnService/inc/Aggregator/AggregatorSettings.h
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifndef _SPTAG_AGGREGATOR_AGGREGATORSETTINGS_H_
|
||||
#define _SPTAG_AGGREGATOR_AGGREGATORSETTINGS_H_
|
||||
|
||||
#include "../Core/Common.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace SPTAG
|
||||
{
|
||||
namespace Aggregator
|
||||
{
|
||||
|
||||
struct AggregatorSettings
|
||||
{
|
||||
AggregatorSettings();
|
||||
|
||||
std::string m_listenAddr;
|
||||
|
||||
std::string m_listenPort;
|
||||
|
||||
std::uint32_t m_searchTimeout;
|
||||
|
||||
SizeType m_threadNum;
|
||||
|
||||
SizeType m_socketThreadNum;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Aggregator
|
||||
} // namespace AnnService
|
||||
|
||||
|
||||
#endif // _SPTAG_AGGREGATOR_AGGREGATORSETTINGS_H_
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user