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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "DeviceMemory.h"
#include "DeviceUtils.h"
#include "../../FaissAssert.h"
namespace faiss { namespace gpu {
DeviceMemoryReservation::DeviceMemoryReservation()
: state_(NULL),
device_(0),
data_(NULL),
size_(0),
stream_(0) {
}
DeviceMemoryReservation::DeviceMemoryReservation(DeviceMemory* state,
int device,
void* p,
size_t size,
cudaStream_t stream)
: state_(state),
device_(device),
data_(p),
size_(size),
stream_(stream) {
}
DeviceMemoryReservation::DeviceMemoryReservation(
DeviceMemoryReservation&& m) noexcept {
state_ = m.state_;
device_ = m.device_;
data_ = m.data_;
size_ = m.size_;
stream_ = m.stream_;
m.data_ = NULL;
}
DeviceMemoryReservation::~DeviceMemoryReservation() {
if (data_) {
FAISS_ASSERT(state_);
state_->returnAllocation(*this);
}
data_ = NULL;
}
DeviceMemoryReservation&
DeviceMemoryReservation::operator=(DeviceMemoryReservation&& m) {
if (data_) {
FAISS_ASSERT(state_);
state_->returnAllocation(*this);
}
state_ = m.state_;
device_ = m.device_;
data_ = m.data_;
size_ = m.size_;
stream_ = m.stream_;
m.data_ = NULL;
return *this;
}
DeviceMemory::~DeviceMemory() {
}
} } // namespace