Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
MemorySpace.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 <cuda.h>
12
13 #if CUDA_VERSION >= 8000
14 // Whether or not we enable usage of CUDA Unified Memory
15 #define FAISS_UNIFIED_MEM 1
16 #endif
17
18 namespace faiss { namespace gpu {
19
20 enum MemorySpace {
21 /// Managed using cudaMalloc/cudaFree
22 Device = 1,
23 /// Managed using cudaMallocManaged/cudaFree
24 Unified = 2,
25 /// Managed using cudaHostAlloc/cudaFreeHost
26 HostPinned = 3,
27 };
28
29 /// All memory allocations and de-allocations come through these functions
30
31 /// Allocates CUDA memory for a given memory space (void pointer)
32 /// Throws a FaissException if we are unable to allocate the memory
33 void allocMemorySpaceV(MemorySpace space, void** p, size_t size);
34
35 template <typename T>
36 inline void allocMemorySpace(MemorySpace space, T** p, size_t size) {
37 allocMemorySpaceV(space, (void**)(void*) p, size);
38 }
39
40 /// Frees CUDA memory for a given memory space
41 /// Asserts if we are unable to free the region
42 void freeMemorySpace(MemorySpace space, void* p);
43
44 } }