Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuResources_c.h
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 #ifndef FAISS_GPU_RESOURCES_C_H
13 #define FAISS_GPU_RESOURCES_C_H
14
15 #include <cuda_runtime_api.h>
16 #include <cublas.h>
17 #include "faiss_c.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /// Base class of GPU-side resource provider; hides provision of
24 /// cuBLAS handles, CUDA streams and a temporary memory manager
25 FAISS_DECLARE_CLASS(GpuResources)
26
27 FAISS_DECLARE_DESTRUCTOR(GpuResources)
28
29 /// Call to pre-allocate resources for a particular device. If this is
30 /// not called, then resources will be allocated at the first time
31 /// of demand
32 int faiss_GpuResources_initializeForDevice(FaissGpuResources*, int);
33
34 /// Returns the cuBLAS handle that we use for the given device
35 int faiss_GpuResources_getBlasHandle(FaissGpuResources*, int, cublasHandle_t*);
36
37 /// Returns the stream that we order all computation on for the
38 /// given device
39 int faiss_GpuResources_getDefaultStream(FaissGpuResources*, int, cudaStream_t*);
40
41 /// Returns the available CPU pinned memory buffer
42 int faiss_GpuResources_getPinnedMemory(FaissGpuResources*, void**, size_t*);
43
44 /// Returns the stream on which we perform async CPU <-> GPU copies
45 int faiss_GpuResources_getAsyncCopyStream(FaissGpuResources*, int, cudaStream_t*);
46
47 /// Calls getBlasHandle with the current device
48 int faiss_GpuResources_getBlasHandleCurrentDevice(FaissGpuResources*, cublasHandle_t*);
49
50 /// Calls getDefaultStream with the current device
51 int faiss_GpuResources_getDefaultStreamCurrentDevice(FaissGpuResources*, cudaStream_t*);
52
53 /// Synchronizes the CPU with respect to the default stream for the
54 /// given device
55 // equivalent to cudaDeviceSynchronize(getDefaultStream(device))
56 int faiss_GpuResources_syncDefaultStream(FaissGpuResources*, int);
57
58 /// Calls syncDefaultStream for the current device
59 int faiss_GpuResources_syncDefaultStreamCurrentDevice(FaissGpuResources*);
60
61 /// Calls getAsyncCopyStream for the current device
62 int faiss_GpuResources_getAsyncCopyStreamCurrentDevice(FaissGpuResources*, cudaStream_t*);
63
64 #ifdef __cplusplus
65 }
66 #endif
67 #endif