Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuResources.h
1 /**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8
9 #pragma once
10
11 #include "utils/DeviceMemory.h"
12 #include <cuda_runtime.h>
13 #include <cublas_v2.h>
14 #include <utility>
15 #include <vector>
16
17 namespace faiss { namespace gpu {
18
19 /// Base class of GPU-side resource provider; hides provision of
20 /// cuBLAS handles, CUDA streams and a temporary memory manager
21 class GpuResources {
22 public:
23 virtual ~GpuResources();
24
25 /// Call to pre-allocate resources for a particular device. If this is
26 /// not called, then resources will be allocated at the first time
27 /// of demand
28 virtual void initializeForDevice(int device) = 0;
29
30 /// Returns the cuBLAS handle that we use for the given device
31 virtual cublasHandle_t getBlasHandle(int device) = 0;
32
33 /// Returns the stream that we order all computation on for the
34 /// given device
35 virtual cudaStream_t getDefaultStream(int device) = 0;
36
37 /// Returns the set of alternative streams that we use for the given device
38 virtual std::vector<cudaStream_t> getAlternateStreams(int device) = 0;
39
40 /// Returns the temporary memory manager for the given device
41 virtual DeviceMemory& getMemoryManager(int device) = 0;
42
43 /// Returns the available CPU pinned memory buffer
44 virtual std::pair<void*, size_t> getPinnedMemory() = 0;
45
46 /// Returns the stream on which we perform async CPU <-> GPU copies
47 virtual cudaStream_t getAsyncCopyStream(int device) = 0;
48
49 /// Calls getBlasHandle with the current device
50 cublasHandle_t getBlasHandleCurrentDevice();
51
52 /// Calls getDefaultStream with the current device
53 cudaStream_t getDefaultStreamCurrentDevice();
54
55 /// Synchronizes the CPU with respect to the default stream for the
56 /// given device
57 // equivalent to cudaDeviceSynchronize(getDefaultStream(device))
58 void syncDefaultStream(int device);
59
60 /// Calls syncDefaultStream for the current device
61 void syncDefaultStreamCurrentDevice();
62
63 /// Calls getAlternateStreams for the current device
64 std::vector<cudaStream_t> getAlternateStreamsCurrentDevice();
65
66 /// Calls getMemoryManager for the current device
67 DeviceMemory& getMemoryManagerCurrentDevice();
68
69 /// Calls getAsyncCopyStream for the current device
70 cudaStream_t getAsyncCopyStreamCurrentDevice();
71 };
72
73 } } // namespace
faiss::gpu::GpuResources::initializeForDevice
virtual void initializeForDevice(int device)=0
faiss::gpu::GpuResources::getDefaultStreamCurrentDevice
cudaStream_t getDefaultStreamCurrentDevice()
Calls getDefaultStream with the current device.
Definition: GpuResources.cpp:23
faiss::gpu::GpuResources::getBlasHandle
virtual cublasHandle_t getBlasHandle(int device)=0
Returns the cuBLAS handle that we use for the given device.
faiss::gpu::GpuResources
Definition: GpuResources.h:21
faiss::gpu::GpuResources::getDefaultStream
virtual cudaStream_t getDefaultStream(int device)=0
faiss::gpu::GpuResources::getBlasHandleCurrentDevice
cublasHandle_t getBlasHandleCurrentDevice()
Calls getBlasHandle with the current device.
Definition: GpuResources.cpp:18
faiss::gpu::GpuResources::getMemoryManagerCurrentDevice
DeviceMemory & getMemoryManagerCurrentDevice()
Calls getMemoryManager for the current device.
Definition: GpuResources.cpp:33
faiss::gpu::GpuResources::syncDefaultStreamCurrentDevice
void syncDefaultStreamCurrentDevice()
Calls syncDefaultStream for the current device.
Definition: GpuResources.cpp:48
faiss::gpu::GpuResources::getAsyncCopyStreamCurrentDevice
cudaStream_t getAsyncCopyStreamCurrentDevice()
Calls getAsyncCopyStream for the current device.
Definition: GpuResources.cpp:38
faiss::gpu::GpuResources::getAlternateStreamsCurrentDevice
std::vector< cudaStream_t > getAlternateStreamsCurrentDevice()
Calls getAlternateStreams for the current device.
Definition: GpuResources.cpp:28
faiss::gpu::GpuResources::getAsyncCopyStream
virtual cudaStream_t getAsyncCopyStream(int device)=0
Returns the stream on which we perform async CPU &lt;-&gt; GPU copies.
faiss::gpu::GpuResources::syncDefaultStream
void syncDefaultStream(int device)
Definition: GpuResources.cpp:43
faiss::gpu::GpuResources::getMemoryManager
virtual DeviceMemory & getMemoryManager(int device)=0
Returns the temporary memory manager for the given device.
faiss::gpu::DeviceMemory
Manages temporary memory allocations on a GPU device.
Definition: DeviceMemory.h:44
faiss::gpu::GpuResources::getPinnedMemory
virtual std::pair< void *, size_t > getPinnedMemory()=0
Returns the available CPU pinned memory buffer.
faiss::gpu::GpuResources::getAlternateStreams
virtual std::vector< cudaStream_t > getAlternateStreams(int device)=0
Returns the set of alternative streams that we use for the given device.