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