13 #include "../FaissAssert.h"
14 #include "GpuResources.h"
15 #include "utils/DeviceUtils.h"
17 namespace faiss {
namespace gpu {
20 constexpr
size_t kAddPageSize = (size_t) 256 * 1024 * 1024;
21 constexpr
size_t kSearchPageSize = (size_t) 256 * 1024 * 1024;
23 GpuIndex::GpuIndex(GpuResources* resources,
28 resources_(resources),
30 FAISS_ASSERT(device_ < getNumDevices());
32 FAISS_ASSERT(resources_);
33 resources_->initializeForDevice(device_);
56 size_t totalSize = n * (size_t) this->
d *
sizeof(
float);
58 if (totalSize > kAddPageSize) {
60 size_t numVecsPerPage =
61 kAddPageSize / ((size_t) this->
d *
sizeof(
float));
64 numVecsPerPage = std::max(numVecsPerPage, (
size_t) 1);
66 for (
size_t i = 0; i < n; i += numVecsPerPage) {
67 size_t curNum = std::min(numVecsPerPage, n - i);
70 x + i * (
size_t) this->
d,
71 ids ? ids + i :
nullptr);
89 size_t totalSize = n * (size_t) this->
d *
sizeof(
float);
91 if (totalSize > kSearchPageSize) {
95 size_t numVecsPerPage =
96 kSearchPageSize / ((size_t) this->
d *
sizeof(
float));
99 numVecsPerPage = std::max(numVecsPerPage, (
size_t) 1);
101 for (
size_t i = 0; i < n; i += numVecsPerPage) {
102 size_t curNum = std::min(numVecsPerPage, n - i);
105 x + i * (
size_t) this->
d,
virtual void searchImpl_(faiss::Index::idx_t n, const float *x, faiss::Index::idx_t k, float *distances, faiss::Index::idx_t *labels) const =0
Overridden to actually perform the search.
void addInternal_(Index::idx_t n, const float *x, const Index::idx_t *ids)
int device_
The GPU device we are resident on.
long idx_t
all indices are this type
virtual void addImpl_(Index::idx_t n, const float *x, const Index::idx_t *ids)=0
Overridden to actually perform the add.
virtual void add(faiss::Index::idx_t, const float *x)
virtual void add_with_ids(Index::idx_t n, const float *x, const Index::idx_t *ids)
virtual void search(faiss::Index::idx_t n, const float *x, faiss::Index::idx_t k, float *distances, faiss::Index::idx_t *labels) const
bool is_trained
set if the Index does not require training, or if training is done already
MetricType
Some algorithms support both an inner product vetsion and a L2 search version.