Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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