Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
MemorySpace.cpp
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 #include "MemorySpace.h"
12 #include <cuda_runtime.h>
13
14 namespace faiss { namespace gpu {
15
16 /// Allocates CUDA memory for a given memory space
17 void allocMemorySpace(MemorySpace space, void** p, size_t size) {
18 if (space == MemorySpace::Device) {
19 FAISS_ASSERT_FMT(cudaMalloc(p, size) == cudaSuccess,
20 "Failed to cudaMalloc %zu bytes", size);
21 }
22 #ifdef FAISS_UNIFIED_MEM
23 else if (space == MemorySpace::Unified) {
24 FAISS_ASSERT_FMT(cudaMallocManaged(p, size) == cudaSuccess,
25 "Failed to cudaMallocManaged %zu bytes", size);
26 }
27 #endif
28 else {
29 FAISS_ASSERT_FMT(false, "Unknown MemorySpace %d", (int) space);
30 }
31 }
32
33 } }