forked from facebookresearch/faiss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemorySpace.cpp
More file actions
33 lines (28 loc) · 940 Bytes
/
Copy pathMemorySpace.cpp
File metadata and controls
33 lines (28 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD+Patents license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
#include "MemorySpace.h"
#include <cuda_runtime.h>
namespace faiss { namespace gpu {
/// Allocates CUDA memory for a given memory space
void allocMemorySpace(MemorySpace space, void** p, size_t size) {
if (space == MemorySpace::Device) {
FAISS_ASSERT_FMT(cudaMalloc(p, size) == cudaSuccess,
"Failed to cudaMalloc %zu bytes", size);
}
#ifdef FAISS_UNIFIED_MEM
else if (space == MemorySpace::Unified) {
FAISS_ASSERT_FMT(cudaMallocManaged(p, size) == cudaSuccess,
"Failed to cudaMallocManaged %zu bytes", size);
}
#endif
else {
FAISS_ASSERT_FMT(false, "Unknown MemorySpace %d", (int) space);
}
}
} }