Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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