文件 GpuCloner.h

namespace faiss

k-means 聚类算法的多种变体的实现。

版权所有 (c) Facebook, Inc. 及其附属公司。

此源代码根据 MIT 许可证授权,该许可证位于此源树的根目录中的 LICENSE 文件中。

IDSelector 旨在定义要处理的向量子集(用于删除或作为搜索的子集)

PQ4 SIMD 打包和累积函数

基本内核使用 bbs = nb * 2 * 16 个向量累积 nq 查询向量,并生成该向量的输出矩阵。 对于 nq * nb <= 4 很有用,否则寄存器溢出会变得太大。

这些函数的实现分布在 3 个 cpp 文件中,以减少并行编译时间。 模板被显式实例化。

此文件包含计算距离的内核的回调。

在整个库中,向量以 float * 指针的形式提供。 当批量处理(添加/搜索)多个向量时,大多数算法都可以得到优化。 在这种情况下,它们作为矩阵传入。 当大小为 d 的 n 个向量以 float * x 的形式提供时,向量 i 的分量 j 是

x[ i * d + j ]

其中 0 <= i < n 且 0 <= j < d。 换句话说,矩阵始终是紧凑的。 指定矩阵的大小时,我们将其称为 n*d 矩阵,这意味着行优先存储。

I/O 函数可以读取/写入文件名、文件句柄或抽象介质的对象。

读取函数返回的对象应使用 delete 取消分配。 这些对象中的所有引用都归该对象所有。

倒排列表的定义 + 一些实现该接口的常见类。

由于 IVF(倒排文件)索引在大型用例中非常有用,因此我们将与它们相关的一些函数分组到这个小型库中。 大多数函数都适用于 IndexIVF 和嵌入在 IndexPreTransform 中的 IndexIVF。

在此文件中,实现了 L2 和内积之外的额外度量

实现了一些神经网络层,主要用于支持 QINCo

定义一些将转换应用于一组向量的对象,通常这些是预处理步骤。

namespace gpu

函数

faiss::Index *index_gpu_to_cpu(const faiss::Index *gpu_index)

将 gpu_index 内的任何 GPU 索引转换为 CPU 索引

faiss::Index *index_cpu_to_gpu(GpuResourcesProvider *provider, int device, const faiss::Index *index, const GpuClonerOptions *options = nullptr)

将任何可以转换为 GPU 的 CPU 索引进行转换

faiss::Index *index_cpu_to_gpu_multiple(std::vector<GpuResourcesProvider*> &provider, std::vector<int> &devices, const faiss::Index *index, const GpuMultipleClonerOptions *options = nullptr)
faiss::IndexBinary *index_binary_gpu_to_cpu(const faiss::IndexBinary *gpu_index)
faiss::IndexBinary *index_binary_cpu_to_gpu(GpuResourcesProvider *provider, int device, const faiss::IndexBinary *index, const GpuClonerOptions *options = nullptr)

将任何可以转换为 GPU 的 CPU 索引进行转换

faiss::IndexBinary *index_binary_cpu_to_gpu_multiple(std::vector<GpuResourcesProvider*> &provider, std::vector<int> &devices, const faiss::IndexBinary *index, const GpuMultipleClonerOptions *options = nullptr)
struct ToCPUCloner : public faiss::Cloner
#include <GpuCloner.h>

为 GPU -> CPU 专门设计的 Cloner

公共函数

void merge_index(Index *dst, Index *src, bool successive_ids)
virtual Index *clone_Index(const Index *index) override
struct ToGpuCloner : public faiss::Cloner, public faiss::gpu::GpuClonerOptions
#include <GpuCloner.h>

针对 CPU -> 1 GPU 专门设计的 Cloner

公共函数

ToGpuCloner(GpuResourcesProvider *prov, int device, const GpuClonerOptions &options)
virtual Index *clone_Index(const Index *index) override

公开成员

GpuResourcesProvider *provider
int device
struct ToGpuClonerMultiple : public faiss::Cloner, public faiss::gpu::GpuMultipleClonerOptions
#include <GpuCloner.h>

针对 CPU -> 多个 GPU 专门设计的 Cloner

公共函数

ToGpuClonerMultiple(std::vector<GpuResourcesProvider*> &provider, std::vector<int> &devices, const GpuMultipleClonerOptions &options)
ToGpuClonerMultiple(const std::vector<ToGpuCloner> &sub_cloners, const GpuMultipleClonerOptions &options)
void copy_ivf_shard(const IndexIVF *index_ivf, IndexIVF *idx2, idx_t n, idx_t i)
Index *clone_Index_to_shards(const Index *index)
virtual Index *clone_Index(const Index *index) override

主要函数

公开成员

std::vector<ToGpuCloner> sub_cloners
struct GpuProgressiveDimIndexFactory : public faiss::ProgressiveDimIndexFactory
#include <GpuCloner.h>

用于 ProgressiveDimClustering 对象的索引工厂

公共函数

explicit GpuProgressiveDimIndexFactory(int ngpu)
virtual Index *operator()(int dim) override

所有权转移给调用者

virtual ~GpuProgressiveDimIndexFactory() override

公开成员

GpuMultipleClonerOptions options
std::vector<GpuResourcesProvider*> vres
std::vector<int> devices
int ncall