@@ -8,38 +8,22 @@ struct C10_API Storage {
88 public:
99 Storage () {}
1010 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
1113 Storage (
1214 caffe2::TypeMeta data_type,
1315 size_t size,
1416 Allocator* allocator,
15- bool resizable = false )
17+ bool resizable)
1618 : storage_impl_(c10::make_intrusive<StorageImpl>(
1719 data_type,
1820 size,
1921 allocator,
2022 resizable)) {}
2123
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
4327 Storage (
4428 caffe2::TypeMeta data_type,
4529 int64_t numel,
@@ -53,6 +37,18 @@ struct C10_API Storage {
5337 allocator,
5438 resizable)) {}
5539
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+
5652 template <typename T>
5753 inline bool IsType () const {
5854 return storage_impl_->IsType <T>();
0 commit comments