文件 GpuIndexFlat.h
-
namespace faiss
实现具有许多变体的 k-means 聚类。
版权所有 (c) Facebook, Inc. 及其关联公司。
此源代码根据 MIT 许可证获得许可,该许可证位于此源树根目录的 LICENSE 文件中。
IDSelector 旨在定义要处理的向量子集(用于删除或作为搜索的子集)
PQ4 SIMD 压缩和累积函数
基本内核将 nq 查询向量与 bbs = nb * 2 * 16 向量累积,并为此生成一个输出矩阵。 对于 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
-
struct GpuIndexFlatConfig : public faiss::gpu::GpuIndexConfig
公共函数
- bool ALIGNED (8) useFloat16
数据是否以 float16 形式存储。
公共成员
-
bool storeTransposed = false
已弃用:不再使用。 以前用于指示向量的内部存储是否已转置
-
class GpuIndexFlat : public faiss::gpu::GpuIndex
- #include <GpuIndexFlat.h>
GPU 实现的包装器,看起来像 faiss::IndexFlat;从给定的 faiss::IndexFlat 复制质心数据
子类包括 faiss::gpu::GpuIndexFlatIP, faiss::gpu::GpuIndexFlatL2
公共函数
-
GpuIndexFlat(GpuResourcesProvider *provider, const faiss::IndexFlat *index, GpuIndexFlatConfig config = GpuIndexFlatConfig())
从预先存在的 faiss::IndexFlat 实例构造,将数据复制到给定的 GPU
-
GpuIndexFlat(GpuResourcesProvider *provider, int dims, faiss::MetricType metric, GpuIndexFlatConfig config = GpuIndexFlatConfig())
构造一个可以添加到的空实例。
-
~GpuIndexFlat() override
-
size_t getNumVecs() const
返回我们包含的向量的数量。
-
virtual void reset() override
从该索引中清除所有向量。
-
virtual void train(idx_t n, const float *x) override
此索引未经训练,因此不执行任何操作。
-
virtual void add(idx_t, const float *x) override
覆盖以避免过多的副本。
-
virtual void reconstruct(idx_t key, float *out) const override
重建方法; 首选批量重建,因为它会更有效
-
virtual void compute_residual(const float *x, float *residual, idx_t key) const override
计算残差。
-
virtual void compute_residual_n(idx_t n, const float *xs, float *residuals, const idx_t *keys) const override
计算残差(批量模式)
-
inline FlatIndex *getGpuData()
用于内部访问。
保护函数
-
void resetIndex_(int dims)
-
virtual bool addImplRequiresIDs_() const override
Flat 索引不需要 ID,因为没有可用于存储它们的空间
-
virtual void searchImpl_(idx_t n, const float *x, int k, float *distances, idx_t *labels, const SearchParameters *params) const override
从 GpuIndex 中调用以进行搜索。
保护属性
-
const GpuIndexFlatConfig flatConfig_
我们的配置选项。
-
std::unique_ptr<FlatIndex> data_
保存包含向量列表的 GPU 数据。
-
GpuIndexFlat(GpuResourcesProvider *provider, const faiss::IndexFlat *index, GpuIndexFlatConfig config = GpuIndexFlatConfig())
-
class GpuIndexFlatL2 : public faiss::gpu::GpuIndexFlat
- #include <GpuIndexFlat.h>
GPU 实现的包装器,看起来像 faiss::IndexFlatL2;从给定的 faiss::IndexFlat 复制质心数据
公共函数
-
GpuIndexFlatL2(GpuResourcesProvider *provider, faiss::IndexFlatL2 *index, GpuIndexFlatConfig config = GpuIndexFlatConfig())
从预先存在的 faiss::IndexFlatL2 实例构造,并将数据复制到给定的 GPU
-
GpuIndexFlatL2(GpuResourcesProvider *provider, int dims, GpuIndexFlatConfig config = GpuIndexFlatConfig())
构造一个可以添加到的空实例。
-
size_t getNumVecs() const
返回我们包含的向量的数量。
-
virtual void reset() override
从该索引中清除所有向量。
-
virtual void train(idx_t n, const float *x) override
此索引未经训练,因此不执行任何操作。
-
virtual void add(idx_t, const float *x) override
覆盖以避免过多的副本。
-
virtual void reconstruct(idx_t key, float *out) const override
重建方法; 首选批量重建,因为它会更有效
-
重建一批(Reconstruct a batch)
批量重建方法。
-
计算残差(Compute residual)
计算残差。
-
计算n个残差(Compute n residuals)
计算残差(批量模式)
-
获取GPU数据(Get GPU data)
用于内部访问。
保护函数
-
重置索引(Reset index)
-
添加实现是否需要IDs(Whether addImpl requires IDs)
Flat 索引不需要 ID,因为没有可用于存储它们的空间
-
添加实现(Add implementation)
从 GpuIndex 中调用以进行添加。
-
搜索实现(Search implementation)
从 GpuIndex 中调用以进行搜索。
保护属性
-
Flat配置(Flat configuration)
我们的配置选项。
-
数据(Data)
保存包含向量列表的 GPU 数据。
-
GpuIndexFlatL2(GpuResourcesProvider *provider, faiss::IndexFlatL2 *index, GpuIndexFlatConfig config = GpuIndexFlatConfig())
-
类:GpuIndexFlatIP
- #include <GpuIndexFlat.h>
围绕GPU实现的包装器,看起来像 faiss::IndexFlatIP; 从给定的 faiss::IndexFlat 复制质心数据。
公共函数
-
构造函数:GpuIndexFlatIP,从预先存在的 faiss::IndexFlatIP 实例构造,将数据复制到给定的GPU。
从预先存在的 faiss::IndexFlatIP 实例构造,将数据复制到给定的GPU。
-
GpuIndexFlatIP(GpuResourcesProvider *provider, int dims, GpuIndexFlatConfig config = GpuIndexFlatConfig())
构造一个可以添加到的空实例。
-
void copyFrom(IndexFlat *index)
从给定的 CPU 索引初始化自身;将覆盖自身中的所有数据
-
void copyTo(IndexFlat *index)
将自身复制到给定的 CPU 索引;将覆盖索引实例中的所有数据
-
void copyFrom(const IndexFlat *index)
从给定的 CPU 索引初始化自身;将覆盖自身中的所有数据
-
void copyTo(IndexFlat *index) const
将自身复制到给定的 CPU 索引;将覆盖索引实例中的所有数据
-
size_t getNumVecs() const
返回我们包含的向量的数量。
-
virtual void reset() override
从该索引中清除所有向量。
-
virtual void train(idx_t n, const float *x) override
此索引未经训练,因此不执行任何操作。
-
virtual void add(idx_t, const float *x) override
覆盖以避免过多的副本。
-
virtual void reconstruct(idx_t key, float *out) const override
重建方法; 首选批量重建,因为它会更有效
-
virtual void compute_residual(const float *x, float *residual, idx_t key) const override
计算残差。
-
virtual void compute_residual_n(idx_t n, const float *xs, float *residuals, const idx_t *keys) const override
计算残差(批量模式)
-
inline FlatIndex *getGpuData()
用于内部访问。
保护函数
-
void resetIndex_(int dims)
-
virtual bool addImplRequiresIDs_() const override
Flat 索引不需要 ID,因为没有可用于存储它们的空间
-
virtual void searchImpl_(idx_t n, const float *x, int k, float *distances, idx_t *labels, const SearchParameters *params) const override
从 GpuIndex 中调用以进行搜索。
保护属性
-
const GpuIndexFlatConfig flatConfig_
我们的配置选项。
-
std::unique_ptr<FlatIndex> data_
保存包含向量列表的 GPU 数据。
-
构造函数:GpuIndexFlatIP,从预先存在的 faiss::IndexFlatIP 实例构造,将数据复制到给定的GPU。
-
struct GpuIndexFlatConfig : public faiss::gpu::GpuIndexConfig
-
namespace gpu