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