10 #include "MemorySpace.h"
11 #include <cuda_runtime.h>
13 namespace faiss {
namespace gpu {
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);
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);
28 FAISS_ASSERT_FMT(
false,
"Unknown MemorySpace %d", (
int) space);