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
35 changes: 35 additions & 0 deletions include/logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "windows_customizations.h"

namespace diskann
{
namespace logging
{
enum LogLevel
{
Debug,
Info,
Warning,
Error,
Assert
};

// Interface for a logger that can be used to log messages at various levels.
class ILogger
{
public:
virtual ~ILogger() = default;

// Log a message associated with a specific level, title, file name, function, and line number.
virtual void Write(char const *filename,
char const *function,
unsigned lineNumber,
LogLevel level,
char const *title,
char const *message) = 0;
};

DISKANN_DLLEXPORT void RegisterLogger(ILogger *logger);
}
}
31 changes: 31 additions & 0 deletions nuget/DiskANN-preview.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>DiskANN-preview.win-x64</id>
<version>0.13.717.3</version>
<authors>DiskANN team</authors>
<owners>DiskANN team</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">LICENSE</license>
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
<projectUrl>https://github.com/microsoft/DiskANN</projectUrl>
<description>The package includes Windows x64 libraries

The goal of the project is to build scalable, performant and cost-effective approximate nearest neighbor search algorithms. This release has the code from the DiskANN paper published in NeurIPS 2019, and improvements. This code reuses and builds upon some of the code for NSG algorithm.</description>
<copyright>Copyright (c) Microsoft Corporation</copyright>
<tags>DiskANN ANNS ANN nearest neighbor vector search</tags>
<dependencies>
<dependency id="intelopenmp.redist.win" version="[2022.0.3.3747]" />
</dependencies>
</metadata>
<files>
<file src="x64\Release\diskann.lib" target="lib\native\win-x64\retail" />
<file src="x64\Release\diskann.dll" target="lib\native\win-x64\retail" />
<file src="x64\Release\diskann.pdb" target="lib\native\win-x64\retail" />
<file src="x64\Debug\diskann.lib" target="lib\native\win-x64\debug" />
<file src="x64\Debug\diskann.dll" target="lib\native\win-x64\debug" />
<file src="x64\Debug\diskann.pdb" target="lib\native\win-x64\debug" />
<file src="include\**" target="lib\native\include\diskann" />
<file src="LICENSE" target="LICENSE" />
</files>
</package>
50 changes: 20 additions & 30 deletions src/distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "distance.h"
#include "utils.h"
#include "logger.h"
#include "logging_internal.h"
#include "ann_exception.h"

namespace diskann
Expand Down Expand Up @@ -529,37 +529,33 @@ template <> diskann::Distance<float> *get_distance_function(diskann::Metric m)
{
if (Avx2SupportedCPU)
{
diskann::cout << "L2: Using AVX2 distance computation DistanceL2Float" << std::endl;
Log(logging::Info, "Index", "L2: Using AVX2 distance computation DistanceL2Float");
return new diskann::DistanceL2Float();
}
else if (AvxSupportedCPU)
{
diskann::cout << "L2: AVX2 not supported. Using AVX distance computation" << std::endl;
Log(logging::Info, "Index", "L2: AVX2 not supported. Using AVX distance computation");
return new diskann::AVXDistanceL2Float();
}
else
{
diskann::cout << "L2: Older CPU. Using slow distance computation" << std::endl;
Log(logging::Info, "Index", "L2: Older CPU. Using slow distance computation");
return new diskann::SlowDistanceL2Float();
}
}
else if (m == diskann::Metric::COSINE)
{
diskann::cout << "Cosine: Using either AVX or AVX2 implementation" << std::endl;
Log(logging::Info, "Index", "Cosine: Using either AVX or AVX2 implementation");
return new diskann::DistanceCosineFloat();
}
else if (m == diskann::Metric::INNER_PRODUCT)
{
diskann::cout << "Inner product: Using AVX2 implementation "
"AVXDistanceInnerProductFloat"
<< std::endl;
Log(logging::Info, "Index", "Inner product: Using AVX2 implementation AVXDistanceInnerProductFloat");
return new diskann::AVXDistanceInnerProductFloat();
}
else if (m == diskann::Metric::FAST_L2)
{
diskann::cout << "Fast_L2: Using AVX2 implementation with norm "
"memoization DistanceFastL2<float>"
<< std::endl;
Log(logging::Info, "Index", "Fast_L2: Using AVX2 implementation with norm memoization DistanceFastL2<float>");
return new diskann::DistanceFastL2<float>();
}
else
Expand All @@ -568,7 +564,7 @@ template <> diskann::Distance<float> *get_distance_function(diskann::Metric m)
stream << "Only L2, cosine, and inner product supported for floating "
"point vectors as of now."
<< std::endl;
diskann::cerr << stream.str() << std::endl;
Log(logging::Error, "Index", stream.str().c_str());
throw diskann::ANNException(stream.str(), -1, __FUNCSIG__, __FILE__, __LINE__);
}
}
Expand All @@ -579,34 +575,30 @@ template <> diskann::Distance<int8_t> *get_distance_function(diskann::Metric m)
{
if (Avx2SupportedCPU)
{
diskann::cout << "Using AVX2 distance computation DistanceL2Int8." << std::endl;
Log(logging::Info, "Index", "Using AVX2 distance computation DistanceL2Int8.");
return new diskann::DistanceL2Int8();
}
else if (AvxSupportedCPU)
{
diskann::cout << "AVX2 not supported. Using AVX distance computation" << std::endl;
Log(logging::Info, "Index", "AVX2 not supported. Using AVX distance computation");
return new diskann::AVXDistanceL2Int8();
}
else
{
diskann::cout << "Older CPU. Using slow distance computation "
"SlowDistanceL2Int<int8_t>."
<< std::endl;
Log(logging::Info, "Index", "Older CPU. Using slow distance computation SlowDistanceL2Int<int8_t>.");
return new diskann::SlowDistanceL2Int<int8_t>();
}
}
else if (m == diskann::Metric::COSINE)
{
diskann::cout << "Using either AVX or AVX2 for Cosine similarity "
"DistanceCosineInt8."
<< std::endl;
Log(logging::Info, "Index", "Using either AVX or AVX2 for Cosine similarity DistanceCosineInt8.");
return new diskann::DistanceCosineInt8();
}
else
{
std::stringstream stream;
stream << "Only L2 and cosine supported for signed byte vectors." << std::endl;
diskann::cerr << stream.str() << std::endl;
Log(logging::Error, "Index", stream.str().c_str());
throw diskann::ANNException(stream.str(), -1, __FUNCSIG__, __FILE__, __LINE__);
}
}
Expand All @@ -616,26 +608,24 @@ template <> diskann::Distance<uint8_t> *get_distance_function(diskann::Metric m)
if (m == diskann::Metric::L2)
{
#ifdef _WINDOWS
diskann::cout << "WARNING: AVX/AVX2 distance function not defined for Uint8. Using "
"slow version. "
"Contact gopalsr@microsoft.com if you need AVX/AVX2 support."
<< std::endl;
Log(logging::Warning,
"Index",
"WARNING: AVX/AVX2 distance function not defined for Uint8. Using slow version. Contact gopalsr@microsoft.com if you need AVX/AVX2 support.");
#endif
return new diskann::DistanceL2UInt8();
}
else if (m == diskann::Metric::COSINE)
{
diskann::cout << "AVX/AVX2 distance function not defined for Uint8. Using "
"slow version SlowDistanceCosineUint8() "
"Contact gopalsr@microsoft.com if you need AVX/AVX2 support."
<< std::endl;
Log(logging::Warning,
"Index",
"AVX/AVX2 distance function not defined for Uint8. Using slow version SlowDistanceCosineUint8(). Contact gopalsr@microsoft.com if you need AVX/AVX2 support.");
return new diskann::SlowDistanceCosineUInt8();
}
else
{
std::stringstream stream;
stream << "Only L2 and cosine supported for unsigned byte vectors." << std::endl;
diskann::cerr << stream.str() << std::endl;
Log(logging::Error, "Index", stream.str().c_str());
throw diskann::ANNException(stream.str(), -1, __FUNCSIG__, __FILE__, __LINE__);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Copyright(c) Microsoft Corporation.All rights reserved.
#Licensed under the MIT license.

add_library(${PROJECT_NAME} SHARED dllmain.cpp ../partition.cpp ../pq.cpp ../pq_flash_index.cpp ../logger.cpp ../utils.cpp
add_library(${PROJECT_NAME} SHARED dllmain.cpp ../partition.cpp ../pq.cpp ../pq_flash_index.cpp ../logger.cpp ../logging_internal.cpp ../utils.cpp
../windows_aligned_file_reader.cpp ../distance.cpp ../memory_mapper.cpp ../index.cpp ../math_utils.cpp ../disk_utils.cpp
../ann_exception.cpp ../natural_number_set.cpp ../natural_number_map.cpp ../scratch.cpp)

Expand Down
Loading
Loading