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 // Copyright 2004-present Facebook. All Rights Reserved.
10
11 #include "RemapIndices.h"
12 #include "../../FaissAssert.h"
13
14 namespace faiss { namespace gpu {
15
16 // Utility function to translate (list id, offset) to a user index on
17 // the CPU. In a cpp in order to use OpenMP
18 void ivfOffsetToUserIndex(
19 long* indices,
20 int numLists,
21 int queries,
22 int k,
23 const std::vector<std::vector<long>>& listOffsetToUserIndex) {
24 FAISS_ASSERT(numLists == listOffsetToUserIndex.size());
25
26 #pragma omp parallel for
27 for (int q = 0; q < queries; ++q) {
28 for (int r = 0; r < k; ++r) {
29 long offsetIndex = indices[q * k + r];
30
31 if (offsetIndex < 0) continue;
32
33 int listId = (int) (offsetIndex >> 32);
34 int listOffset = (int) (offsetIndex & 0xffffffff);
35
36 FAISS_ASSERT(listId < numLists);
37 auto& listIndices = listOffsetToUserIndex[listId];
38
39 FAISS_ASSERT(listOffset < listIndices.size());
40 indices[q * k + r] = listIndices[listOffset];
41 }
42 }
43 }
44
45 } } // namespace