类 faiss::gpu::GpuIndexFlat
-
class GpuIndexFlat : public faiss::gpu::GpuIndex
围绕 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 compute_residual_n(idx_t n, const float *xs, float *residuals, const idx_t *keys) const override
计算残差(批量模式)
-
inline FlatIndex *getGpuData()
用于内部访问。
-
int getDevice() const
返回此索引所在的设备。
-
std::shared_ptr<GpuResources> getResources()
返回一个指向我们的 GpuResources 对象的引用,该对象管理 GPU 上的内存、流和句柄资源。
-
void setMinPagingSize(size_t size)
设置用于 CPU -> GPU 分页搜索的最小数据大小(以 MiB 为单位)
-
size_t getMinPagingSize() const
返回分页搜索的当前最小数据大小。
-
virtual void add_with_ids(idx_t n, const float *x, const idx_t *ids) override
x
和ids
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制。如果添加集太大,则处理分页添加;调用 addInternal_
-
virtual void assign(idx_t n, const float *x, idx_t *labels, idx_t k = 1) const override
x
和labels
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制
-
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, const SearchParameters *params = nullptr) const override
x
、distances
和labels
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制
-
virtual void search_and_reconstruct(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, float *recons, const SearchParameters *params = nullptr) const override
x
、distances
和labels
以及recons
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制
-
virtual void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result, const SearchParameters *params = nullptr) const
查询索引的 n 个维度为 d 的向量。
返回所有距离 < radius 的向量。请注意,许多索引不实现 range_search(只有 k-NN 搜索是强制性的)。
- 参数:
n – 向量数
x – 要搜索的输入向量,大小为 n * d
radius – 搜索半径
result – 结果表
-
virtual size_t remove_ids(const IDSelector &sel)
从索引中删除 ID。并非所有索引都支持。返回删除的元素数量。
-
virtual DistanceComputer *get_distance_computer() const
获取此类型索引的 DistanceComputer (在 AuxIndexStructures 中定义) 对象。
DistanceComputer 针对支持随机访问其向量的索引实现。
-
virtual size_t sa_code_size() const
以字节为单位的生成代码的大小
-
virtual void sa_encode(idx_t n, const float *x, uint8_t *bytes) const
编码一组向量
- 参数:
n – 向量数
x – 输入向量,大小为 n * d
bytes – 输出的编码向量,大小为 n * sa_code_size()
-
virtual void sa_decode(idx_t n, const uint8_t *bytes, float *x) const
解码一组向量
- 参数:
n – 向量数
bytes – 输入的编码向量,大小为 n * sa_code_size()
x – 输出向量,大小为 n * d
-
virtual void merge_from(Index &otherIndex, idx_t add_id = 0)
将条目从另一个数据集移动到自身。 在输出时,other 为空。 add_id 添加到所有移动的 id(对于序列 id,这将是 this->ntotal)
-
virtual void check_compatible_for_merge(const Index &otherIndex) const
检查两个索引是否兼容(即,它们以相同的方式训练并且具有相同的参数)。 否则抛出异常。
-
virtual void add_sa_codes(idx_t n, const uint8_t *codes, const idx_t *xids)
添加使用独立编解码器计算的向量
- 参数:
codes – 要添加的代码,大小为 n * sa_code_size()
xids – 对应的 id,大小为 n
保护函数
-
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::shared_ptr<GpuResources> resources_
管理设备的流、cuBLAS 句柄和暂存内存。
-
const GpuIndexConfig config_
我们的配置选项。
-
size_t minPagedSize_
大于此尺寸时,我们将从 CPU 到 GPU 分页复制。
-
GpuIndexFlat(GpuResourcesProvider *provider, const faiss::IndexFlat *index, GpuIndexFlatConfig config = GpuIndexFlatConfig())