Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ dkms.conf
/build
/ipch
/packages
/out/build/x64-Debug
/out/build/x64-Debug
/sgKey.snk
9 changes: 0 additions & 9 deletions AnnService/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,6 @@ endif()

file(GLOB_RECURSE SSD_SERVING_HDR_FILES ${AnnService}/inc/SSDServing/*.h)
file(GLOB_RECURSE SSD_SERVING_FILES ${AnnService}/src/SSDServing/*.cpp)
#if(NOT WIN32)
# list(REMOVE_ITEM SSD_SERVING_HDR_FILES
# ${VECTORSEARCH_INC_DIR}/AsyncFileReader.h
# )
#elseif(WIN32)
# list(REMOVE_ITEM SSD_SERVING_HDR_FILES
# ${VECTORSEARCH_INC_DIR}/AsyncFileReaderLinux.h
# )
#endif()

add_executable(ssdserving ${SSD_SERVING_HDR_FILES} ${SSD_SERVING_FILES})
target_link_libraries(ssdserving SPTAGLibStatic ${Boost_LIBRARIES})
Expand Down
8 changes: 6 additions & 2 deletions AnnService/inc/Core/Common/BKTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ namespace SPTAG
_RD = m_pQuantizer->ReconstructDim();
fComputeDistance = m_pQuantizer->DistanceCalcSelector<T>(distMethod);
}
else
else if (distMethod == DistCalcMethod::L2 || distMethod == DistCalcMethod::Cosine)
{
fComputeDistance = COMMON::DistanceCalcSelector<T>(DistCalcMethod::L2);
}
else {
fComputeDistance = COMMON::DistanceCalcSelector<T>(distMethod);
}

Expand Down Expand Up @@ -179,10 +182,11 @@ namespace SPTAG
for (DimensionType j = 0; j < args._RD; j++) {
currCenters[j] /= args.counts[k];
}
/*
if (args._M == DistCalcMethod::Cosine) {
COMMON::Utils::Normalize(currCenters, args._RD, COMMON::Utils::GetBase<T>());
}

*/
if (args.m_pQuantizer) {
for (DimensionType j = 0; j < args._RD; j++) reconstructVector[j] = (R)(currCenters[j]);
args.m_pQuantizer->QuantizeVector(reconstructVector.data(), (uint8_t*)TCenter);
Expand Down
37 changes: 6 additions & 31 deletions AnnService/inc/Core/Common/KDTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,53 +210,28 @@ break;
return LoadTrees(ptr);
}

template <typename T>
template <typename T, typename Q>
void InitSearchTrees(const Dataset<T>& p_data, std::function<float(const T*, const T*, DimensionType)> fComputeDistance, COMMON::QueryResultSet<T> &p_query, COMMON::WorkSpace &p_space) const
{
for (int i = 0; i < m_iTreeNumber; i++) {
KDTSearch(p_data, fComputeDistance, p_query, p_space, m_pTreeStart[i], 0);
KDTSearch<T, Q>(p_data, fComputeDistance, p_query, p_space, m_pTreeStart[i], 0);
}
}

template <typename T>
template <typename T, typename Q>
void SearchTrees(const Dataset<T>& p_data, std::function<float(const T*, const T*, DimensionType)> fComputeDistance, COMMON::QueryResultSet<T> &p_query, COMMON::WorkSpace &p_space, const int p_limits) const
{
while (!p_space.m_SPTQueue.empty() && p_space.m_iNumberOfCheckedLeaves < p_limits)
{
auto& tcell = p_space.m_SPTQueue.pop();
KDTSearch(p_data, fComputeDistance, p_query, p_space, tcell.node, tcell.distance);
KDTSearch<T, Q>(p_data, fComputeDistance, p_query, p_space, tcell.node, tcell.distance);
}
}

private:

template <typename T>
void KDTSearch(const Dataset<T>& p_data, std::function<float(const T*, const T*, DimensionType)> fComputeDistance, COMMON::QueryResultSet<T>& p_query,
COMMON::WorkSpace& p_space, const SizeType node, const float distBound) const
{
if (m_pQuantizer)
{
switch (m_pQuantizer->GetReconstructType())
{
#define DefineVectorValueType(Name, Type) \
case VectorValueType::Name: \
return KDTSearchCore<T, Type>(p_data, fComputeDistance, p_query, p_space, node, distBound);

#include "inc/Core/DefinitionList.h"
#undef DefineVectorValueType

default: break;
}
}
else
{
return KDTSearchCore<T, T>(p_data, fComputeDistance, p_query, p_space, node, distBound);
}

}

template <typename T, typename Q>
void KDTSearchCore(const Dataset<T>& p_data, std::function<float(const T*, const T*, DimensionType)> fComputeDistance, COMMON::QueryResultSet<T> &p_query,
void KDTSearch(const Dataset<T>& p_data, std::function<float(const T*, const T*, DimensionType)> fComputeDistance, COMMON::QueryResultSet<T> &p_query,
COMMON::WorkSpace& p_space, const SizeType node, const float distBound) const {
if (node < 0)
{
Expand Down Expand Up @@ -292,7 +267,7 @@ return KDTSearchCore<T, Type>(p_data, fComputeDistance, p_query, p_space, node,
}

p_space.m_SPTQueue.insert(NodeDistPair(otherChild, distanceBound));
KDTSearchCore<T,Q>(p_data, fComputeDistance, p_query, p_space, bestChild, distBound);
KDTSearch<T,Q>(p_data, fComputeDistance, p_query, p_space, bestChild, distBound);
}


Expand Down
17 changes: 2 additions & 15 deletions AnnService/inc/Core/Common/NeighborhoodGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,8 @@ namespace SPTAG
SizeType initSize;
SPTAG::Helper::Convert::ConvertStringTo(index->GetParameter("NumberOfInitialDynamicPivots").c_str(), initSize);

if (index->m_pQuantizer) {
buildGraph<T>(index, m_iGraphSize, m_iNeighborhoodSize, m_iTPTNumber, (int*)m_pNeighborhoodGraph[0], m_iGPURefineSteps, m_iGPURefineDepth, m_iGPUGraphType, m_iGPULeafSize, initSize, m_iheadNumGPUs, m_iTPTBalanceFactor);
}
else {
// Build the entire RNG graph, both builds the KNN and refines it to RNG
buildGraph<T>(index, m_iGraphSize, m_iNeighborhoodSize, m_iTPTNumber, (int*)m_pNeighborhoodGraph[0], m_iGPURefineSteps, m_iGPURefineDepth, m_iGPUGraphType, m_iGPULeafSize, initSize, m_iheadNumGPUs, m_iTPTBalanceFactor);
}
// Build the entire RNG graph, both builds the KNN and refines it to RNG
buildGraph<T>(index, m_iGraphSize, m_iNeighborhoodSize, m_iTPTNumber, (int*)m_pNeighborhoodGraph[0], m_iGPURefineSteps, m_iGPURefineDepth, m_iGPUGraphType, m_iGPULeafSize, initSize, m_iheadNumGPUs, m_iTPTBalanceFactor);

if (idmap != nullptr) {
std::unordered_map<SizeType, SizeType>::const_iterator iter;
Expand Down Expand Up @@ -149,7 +144,6 @@ break;
}
else
{
printf("No quantizer!\n");
PartitionByTptreeCore<T, T>(index, indices, first, last, leaves);
}
}
Expand Down Expand Up @@ -331,13 +325,6 @@ break;
auto t2 = std::chrono::high_resolution_clock::now();
LOG(Helper::LogLevel::LL_Info, "Build TPTree time (s): %lld\n", std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count());

for(int i=0; i<10; i++) {
for(int j=0; j<20; j++) {
std::cout << static_cast<int16_t>(((uint8_t*)index->GetSample(i))[j]) << ", ";
}
std::cout << std::endl;
}

for (int i = 0; i < m_iTPTNumber; i++)
{
#pragma omp parallel for schedule(dynamic)
Expand Down
51 changes: 8 additions & 43 deletions AnnService/inc/Core/Common/QueryResultSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,19 @@ class QueryResultSet : public QueryResult
{
}

inline void SetTarget(const T *p_target)
{
m_target = p_target;
if (m_quantizedTarget)
{
ALIGN_FREE(m_quantizedTarget);
}
m_quantizedTarget = nullptr;
m_quantizedSize = 0;
}

inline void SetTarget(const T* p_target, const std::shared_ptr<IQuantizer>& quantizer)
{
m_target = p_target;
if (quantizer)
{
if (m_quantizedTarget && (m_quantizedSize == quantizer->QuantizeSize()))
{
quantizer->QuantizeVector((void*)p_target, (uint8_t*)m_quantizedTarget);
}
else
{
if (m_quantizedTarget) ALIGN_FREE(m_quantizedTarget);
m_quantizedSize = quantizer->QuantizeSize();
m_quantizedTarget = ALIGN_ALLOC(m_quantizedSize);
quantizer->QuantizeVector((void*)p_target, (uint8_t*)m_quantizedTarget);
}
}
if (quantizer == nullptr) QueryResult::SetTarget((const void*)p_target);
else
{
if (m_quantizedTarget)
if (m_target == m_quantizedTarget || (m_quantizedSize != quantizer->QuantizeSize()))
{
ALIGN_FREE(m_quantizedTarget);
if (m_target != m_quantizedTarget) ALIGN_FREE(m_quantizedTarget);
m_quantizedTarget = ALIGN_ALLOC(quantizer->QuantizeSize());
m_quantizedSize = quantizer->QuantizeSize();
}
m_quantizedTarget = nullptr;
m_quantizedSize = 0;
m_target = p_target;
quantizer->QuantizeVector((void*)p_target, (uint8_t*)m_quantizedTarget);
}
}

Expand All @@ -89,19 +66,7 @@ class QueryResultSet : public QueryResult

T* GetQuantizedTarget()
{
if (m_quantizedTarget)
{
return reinterpret_cast<T*>(m_quantizedTarget);
}
else
{
return (T*)reinterpret_cast<const T*>(m_target);
}
}

bool HasQuantizedTarget()
{
return m_quantizedTarget;
return reinterpret_cast<T*>(m_quantizedTarget);
}

inline float worstDist() const
Expand Down
4 changes: 2 additions & 2 deletions AnnService/inc/Core/KDT/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ namespace SPTAG
ErrorCode RefineIndex(std::shared_ptr<VectorIndex>& p_newIndex);

private:
void SearchIndexWithDeleted(COMMON::QueryResultSet<T> &p_query, COMMON::WorkSpace &p_space) const;
void SearchIndexWithoutDeleted(COMMON::QueryResultSet<T> &p_query, COMMON::WorkSpace &p_space) const;
template <typename Q>
void SearchIndex(COMMON::QueryResultSet<T> &p_query, COMMON::WorkSpace &p_space, bool p_searchDeleted) const;
};
} // namespace KDT
} // namespace SPTAG
Expand Down
Loading