Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions faiss/gpu/GpuIcmEncoder.cu
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void GpuIcmEncoder::encode(
size_t n,
size_t ils_iters) const {
size_t nshards = shards->size();
size_t shard_size = (n + nshards - 1) / nshards;
size_t base_shard_size = n / nshards;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it (n / nshards) or (n - 1)/ nshards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integer computing, round down already. remain = n - nshards * base_shard_size, then 0 <= remain < nshards, so each shard takes at least base_shard_size vectors, and the first remain shards takes one extra vector each.


auto codebooks = lsq->codebooks.data();
auto M = lsq->M;
Expand All @@ -94,8 +94,14 @@ void GpuIcmEncoder::encode(

// split input data
auto fn = [=](int idx, IcmEncoderImpl* encoder) {
size_t i0 = idx * shard_size;
size_t ni = std::min(shard_size, n - i0);
size_t i0 = idx * base_shard_size + std::min(size_t(idx), n % nshards);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it std::min(size_t(idx), n % nshards)? Btw, should be (n-1) % nshards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as my previous comment, you can verify it over the case n % nshards == 0, then (n -1) % nshards is meaningless

size_t ni = base_shard_size;
if (ni < n % nshards) {
++ni;
}
if (ni <= 0) { // only if n < nshards
return;
}
auto xi = x + i0 * d;
auto ci = codes + i0 * M;
std::mt19937 geni(idx + seed); // different seed for each shard
Expand Down