Skip to content

Commit

Permalink
faiss gpu: fix DeviceVector reallocations (facebookresearch#3256)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookresearch#3256

Per facebookresearch#3251 there are two problems with DeviceVector resizing and capacity growth. The first is that if you resize a vector with enough capacity available for the new size, it will go ahead and re-allocate memory anyways.

The second is that the calculation that was supposed to produce x + 0.25 * x was actually producing x + 4 * x for determining the new size of the allocated memory for a vector. This is also fixed.

Reviewed By: mdouze

Differential Revision: D53813207

fbshipit-source-id: 5aa67bc0a87c171a070645bdcc6bc5d22ba6b36b
  • Loading branch information
Jeff Johnson authored and facebook-github-bot committed Feb 21, 2024
1 parent b8d91d8 commit abff75e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions faiss/gpu/utils/DeviceVector.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class DeviceVector {
bool resize(size_t newSize, cudaStream_t stream) {
bool mem = false;

if (num_ < newSize) {
if (newSize > capacity_) {
mem = reserve(getNewCapacity_(newSize), stream);
}

Expand Down Expand Up @@ -249,7 +249,7 @@ class DeviceVector {
if (preferredSize <= kDeviceVector_2x_Limit) {
return utils::nextHighestPowerOf2(preferredSize);
} else if (preferredSize <= kDeviceVector_1_25x_Limit) {
return preferredSize + (preferredSize << 2);
return preferredSize + (preferredSize >> 2);
} else {
return preferredSize;
}
Expand Down

0 comments on commit abff75e

Please sign in to comment.