Class faiss::gpu::GpuIndexFlatL2¶
-
class GpuIndexFlatL2 : public faiss::gpu::GpuIndexFlat¶
Wrapper around the GPU implementation that looks like faiss::IndexFlatL2; copies over centroid data from a given faiss::IndexFlat
Public Functions
-
GpuIndexFlatL2(GpuResourcesProvider *provider, faiss::IndexFlatL2 *index, GpuIndexFlatConfig config = GpuIndexFlatConfig())¶
Construct from a pre-existing faiss::IndexFlatL2 instance, copying data over to the given GPU
-
GpuIndexFlatL2(GpuResourcesProvider *provider, int dims, GpuIndexFlatConfig config = GpuIndexFlatConfig())¶
Construct an empty instance that can be added to.
-
void copyFrom(faiss::IndexFlat *index)¶
Initialize ourselves from the given CPU index; will overwrite all data in ourselves
-
void copyTo(faiss::IndexFlat *index)¶
Copy ourselves to the given CPU index; will overwrite all data in the index instance
-
void copyFrom(const faiss::IndexFlat *index)¶
Initialize ourselves from the given CPU index; will overwrite all data in ourselves
-
void copyTo(faiss::IndexFlat *index) const¶
Copy ourselves to the given CPU index; will overwrite all data in the index instance
-
size_t getNumVecs() const¶
Returns the number of vectors we contain.
-
virtual void reset() override¶
Clears all vectors from this index.
-
virtual void train(idx_t n, const float *x) override¶
This index is not trained, so this does nothing.
-
virtual void reconstruct(idx_t key, float *out) const override¶
Reconstruction methods; prefer the batch reconstruct as it will be more efficient
-
virtual void reconstruct_n(idx_t i0, idx_t num, float *out) const override¶
Batch reconstruction method.
-
virtual void reconstruct_batch(idx_t n, const idx_t *keys, float *out) const override¶
Batch reconstruction method.
-
virtual void compute_residual(const float *x, float *residual, idx_t key) const override¶
Compute residual.
-
virtual void compute_residual_n(idx_t n, const float *xs, float *residuals, const idx_t *keys) const override¶
Compute residual (batch mode)
-
inline FlatIndex *getGpuData()¶
For internal access.
-
int getDevice() const¶
Returns the device that this index is resident on.
-
std::shared_ptr<GpuResources> getResources()¶
Returns a reference to our GpuResources object that manages memory, stream and handle resources on the GPU
-
void setMinPagingSize(size_t size)¶
Set the minimum data size for searches (in MiB) for which we use CPU -> GPU paging
-
size_t getMinPagingSize() const¶
Returns the current minimum data size for paged searches.
-
virtual void add_with_ids(idx_t n, const float *x, const idx_t *ids) override¶
x
andids
can be resident on the CPU or any GPU; copies are performed as needed Handles paged adds if the add set is too large; calls addInternal_
-
virtual void assign(idx_t n, const float *x, idx_t *labels, idx_t k = 1) const override¶
x
andlabels
can be resident on the CPU or any GPU; copies are performed as needed
-
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
andlabels
can be resident on the CPU or any GPU; copies are performed as needed
-
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
andlabels
andrecons
can be resident on the CPU or any GPU; copies are performed as needed
-
virtual void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result, const SearchParameters *params = nullptr) const¶
query n vectors of dimension d to the index.
return all vectors with distance < radius. Note that many indexes do not implement the range_search (only the k-NN search is mandatory).
- Parameters:
x – input vectors to search, size n * d
radius – search radius
result – result table
-
virtual size_t remove_ids(const IDSelector &sel)¶
removes IDs from the index. Not supported by all indexes. Returns the number of elements removed.
-
virtual DistanceComputer *get_distance_computer() const¶
Get a DistanceComputer (defined in AuxIndexStructures) object for this kind of index.
DistanceComputer is implemented for indexes that support random access of their vectors.
-
virtual size_t sa_code_size() const¶
size of the produced codes in bytes
-
virtual void sa_encode(idx_t n, const float *x, uint8_t *bytes) const¶
encode a set of vectors
- Parameters:
n – number of vectors
x – input vectors, size n * d
bytes – output encoded vectors, size n * sa_code_size()
-
virtual void sa_decode(idx_t n, const uint8_t *bytes, float *x) const¶
decode a set of vectors
- Parameters:
n – number of vectors
bytes – input encoded vectors, size n * sa_code_size()
x – output vectors, size n * d
Public Members
-
int d¶
vector dimension
-
bool verbose¶
verbosity level
-
MetricType metric_type¶
type of metric this index uses for search
-
float metric_arg¶
argument of the metric type
Protected Functions
-
virtual bool addImplRequiresIDs_() const override¶
Flat index does not require IDs as there is no storage available for them
-
virtual void addImpl_(int n, const float *x, const idx_t *ids) override¶
Called from GpuIndex for add.
-
virtual void searchImpl_(int n, const float *x, int k, float *distances, idx_t *labels, const SearchParameters *params) const override¶
Called from GpuIndex for search.
Protected Attributes
-
const GpuIndexFlatConfig flatConfig_¶
Our configuration options.
-
std::shared_ptr<GpuResources> resources_¶
Manages streams, cuBLAS handles and scratch memory for devices.
-
const GpuIndexConfig config_¶
Our configuration options.
-
size_t minPagedSize_¶
Size above which we page copies from the CPU to GPU.
-
GpuIndexFlatL2(GpuResourcesProvider *provider, faiss::IndexFlatL2 *index, GpuIndexFlatConfig config = GpuIndexFlatConfig())¶