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 CC-by-NC 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 virtual cublasHandle_t getBlasHandle(int device) = 0;
33
34 virtual cudaStream_t getDefaultStream(int device) = 0;
35
36 virtual std::vector<cudaStream_t> getAlternateStreams(int device) = 0;
37
38 virtual DeviceMemory& getMemoryManager(int device) = 0;
39
40 virtual std::pair<void*, size_t> getPinnedMemory() = 0;
41
42 virtual cudaStream_t getAsyncCopyStream(int device) = 0;
43
44 cublasHandle_t getBlasHandleCurrentDevice();
45
46 cudaStream_t getDefaultStreamCurrentDevice();
47
48 std::vector<cudaStream_t> getAlternateStreamsCurrentDevice();
49
50 DeviceMemory& getMemoryManagerCurrentDevice();
51
52 cudaStream_t getAsyncCopyStreamCurrentDevice();
53 };
54
55 } } // namespace
faiss::gpu::GpuResources::initializeForDevice
virtual void initializeForDevice(int device)=0
faiss::gpu::GpuResources
Definition: GpuResources.h:23
faiss::gpu::DeviceMemory
Manages temporary memory allocations on a GPU device.
Definition: DeviceMemory.h:46