Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
DeviceMemory.cpp
1 /**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8
9 #include "DeviceMemory.h"
10 #include "DeviceUtils.h"
11 #include "../../FaissAssert.h"
12
13 namespace faiss { namespace gpu {
14
15 DeviceMemoryReservation::DeviceMemoryReservation()
16 : state_(NULL),
17 device_(0),
18 data_(NULL),
19 size_(0),
20 stream_(0) {
21 }
22
23 DeviceMemoryReservation::DeviceMemoryReservation(DeviceMemory* state,
24 int device,
25 void* p,
26 size_t size,
27 cudaStream_t stream)
28 : state_(state),
29 device_(device),
30 data_(p),
31 size_(size),
32 stream_(stream) {
33 }
34
35 DeviceMemoryReservation::DeviceMemoryReservation(
36 DeviceMemoryReservation&& m) noexcept {
37
38 state_ = m.state_;
39 device_ = m.device_;
40 data_ = m.data_;
41 size_ = m.size_;
42 stream_ = m.stream_;
43
44 m.data_ = NULL;
45 }
46
47 DeviceMemoryReservation::~DeviceMemoryReservation() {
48 if (data_) {
49 FAISS_ASSERT(state_);
50 state_->returnAllocation(*this);
51 }
52
53 data_ = NULL;
54 }
55
56 DeviceMemoryReservation&
57 DeviceMemoryReservation::operator=(DeviceMemoryReservation&& m) {
58 if (data_) {
59 FAISS_ASSERT(state_);
60 state_->returnAllocation(*this);
61 }
62
63 state_ = m.state_;
64 device_ = m.device_;
65 data_ = m.data_;
66 size_ = m.size_;
67 stream_ = m.stream_;
68
69 m.data_ = NULL;
70
71 return *this;
72 }
73
74 DeviceMemory::~DeviceMemory() {
75 }
76
77 } } // namespace