Skip to content

Commit 8ecf87e

Browse files
Jeff Johnsonfacebook-github-bot
authored andcommitted
faiss gpu: fix DeviceVector reallocations (facebookresearch#3256)
Summary: 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. Differential Revision: D53813207
1 parent 8400ece commit 8ecf87e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

faiss/gpu/utils/DeviceVector.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class DeviceVector {
132132
bool resize(size_t newSize, cudaStream_t stream) {
133133
bool mem = false;
134134

135-
if (num_ < newSize) {
135+
if (newSize > capacity_) {
136136
mem = reserve(getNewCapacity_(newSize), stream);
137137
}
138138

@@ -249,7 +249,7 @@ class DeviceVector {
249249
if (preferredSize <= kDeviceVector_2x_Limit) {
250250
return utils::nextHighestPowerOf2(preferredSize);
251251
} else if (preferredSize <= kDeviceVector_1_25x_Limit) {
252-
return preferredSize + (preferredSize << 2);
252+
return preferredSize + (preferredSize >> 2);
253253
} else {
254254
return preferredSize;
255255
}

0 commit comments

Comments
 (0)