@@ -8,38 +8,22 @@ struct C10_API Storage {
8
8
public:
9
9
Storage () {}
10
10
Storage (c10::intrusive_ptr<StorageImpl> ptr) : storage_impl_(std::move(ptr)) {}
11
+
12
+ // Allocates memory buffer using given allocator and creates a storage with it
11
13
Storage (
12
14
caffe2::TypeMeta data_type,
13
15
size_t size,
14
16
Allocator* allocator,
15
- bool resizable = false )
17
+ bool resizable)
16
18
: storage_impl_(c10::make_intrusive<StorageImpl>(
17
19
data_type,
18
20
size,
19
21
allocator,
20
22
resizable)) {}
21
23
22
- Storage (
23
- caffe2::TypeMeta data_type,
24
- at::DataPtr data_ptr,
25
- size_t size,
26
- const std::function<void (void *)>& deleter,
27
- bool resizable = false )
28
- : storage_impl_(c10::make_intrusive<StorageImpl>(
29
- data_type,
30
- size,
31
- std::move (data_ptr),
32
- /* allocator */ nullptr,
33
- resizable)) {}
34
-
35
- Storage (at::DeviceType device_type)
36
- : storage_impl_(
37
- c10::make_intrusive<StorageImpl>(at::Device(device_type))) {}
38
- Storage (at::Device device)
39
- : storage_impl_(c10::make_intrusive<StorageImpl>(device)) {}
40
- Storage (at::Device device, caffe2::TypeMeta data_type)
41
- : storage_impl_(c10::make_intrusive<StorageImpl>(device, data_type)) {}
42
-
24
+ // Creates storage with pre-allocated memory buffer. Allocator is given for
25
+ // potential future reallocations, however it can be nullptr if the storage
26
+ // is non-resizable
43
27
Storage (
44
28
caffe2::TypeMeta data_type,
45
29
int64_t numel,
@@ -53,6 +37,18 @@ struct C10_API Storage {
53
37
allocator,
54
38
resizable)) {}
55
39
40
+ // Legacy constructor for partially initialized (dtype or memory) storages
41
+ // that can be temporarily created with Caffe2 APIs. See the note on top of
42
+ // TensorImpl.h for details.
43
+ static Storage create_legacy (at::Device device, caffe2::TypeMeta data_type) {
44
+ return Storage (c10::make_intrusive<StorageImpl>(
45
+ data_type,
46
+ 0 ,
47
+ at::DataPtr (nullptr , device),
48
+ GetAllocator (device.type ()),
49
+ true ));
50
+ }
51
+
56
52
template <typename T>
57
53
inline bool IsType () const {
58
54
return storage_impl_->IsType <T>();
0 commit comments