Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuAutoTune_c.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 // -*- c++ -*-
11
12 #include "GpuAutoTune_c.h"
13 #include "macros_impl.h"
14 #include "Index.h"
15 #include "gpu/GpuAutoTune.h"
16 #include "gpu/GpuClonerOptions.h"
17
18 using faiss::Index;
19 using faiss::gpu::GpuResources;
20 using faiss::gpu::GpuClonerOptions;
21
22 int faiss_index_gpu_to_cpu(const FaissIndex* gpu_index, FaissIndex** p_out) {
23 try {
24 auto cpu_index = faiss::gpu::index_gpu_to_cpu(
25 reinterpret_cast<const Index*>(gpu_index)
26 );
27 *p_out = reinterpret_cast<FaissIndex*>(cpu_index);
28 } CATCH_AND_HANDLE
29 }
30
31 /// converts any CPU index that can be converted to GPU
32 int faiss_index_cpu_to_gpu(FaissGpuResources* resources, int device, const FaissIndex *index, FaissGpuIndex** p_out) {
33 try {
34 auto res = reinterpret_cast<GpuResources*>(resources);
35 auto gpu_index = faiss::gpu::index_cpu_to_gpu(
36 res, device, reinterpret_cast<const Index*>(index)
37 );
38 *p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
39 } CATCH_AND_HANDLE
40 }
41
42 int faiss_index_cpu_to_gpu_with_options(
43 FaissGpuResources* resources, int device,
44 const FaissIndex *index, const FaissGpuClonerOptions* options,
45 FaissGpuIndex** p_out)
46 {
47 try {
48 auto res = reinterpret_cast<GpuResources*>(resources);
49 auto gpu_index = faiss::gpu::index_cpu_to_gpu(
50 res, device, reinterpret_cast<const Index*>(index),
51 reinterpret_cast<const GpuClonerOptions*>(options));
52 *p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
53 } CATCH_AND_HANDLE
54 }
faiss::gpu::GpuClonerOptions
set some options on how to copy to GPU
Definition: GpuClonerOptions.h:16
faiss::gpu::GpuResources
Definition: GpuResources.h:22
faiss::Index
Definition: Index.h:62