Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
RemapIndices.cpp
1 /**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8
9 #include "RemapIndices.h"
10 #include "../../FaissAssert.h"
11
12 namespace faiss { namespace gpu {
13
14 // Utility function to translate (list id, offset) to a user index on
15 // the CPU. In a cpp in order to use OpenMP
16 void ivfOffsetToUserIndex(
17 long* indices,
18 int numLists,
19 int queries,
20 int k,
21 const std::vector<std::vector<long>>& listOffsetToUserIndex) {
22 FAISS_ASSERT(numLists == listOffsetToUserIndex.size());
23
24 #pragma omp parallel for
25 for (int q = 0; q < queries; ++q) {
26 for (int r = 0; r < k; ++r) {
27 long offsetIndex = indices[q * k + r];
28
29 if (offsetIndex < 0) continue;
30
31 int listId = (int) (offsetIndex >> 32);
32 int listOffset = (int) (offsetIndex & 0xffffffff);
33
34 FAISS_ASSERT(listId < numLists);
35 auto& listIndices = listOffsetToUserIndex[listId];
36
37 FAISS_ASSERT(listOffset < listIndices.size());
38 indices[q * k + r] = listIndices[listOffset];
39 }
40 }
41 }
42
43 } } // namespace