Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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