Skip to content

Commit dd2c487

Browse files
ezyangfacebook-github-bot
authored andcommitted
Enforce invariant that storage_ is always non-null (pytorch#12328)
Summary: Pull Request resolved: pytorch#12328 - Delete reset() from Storage, as it makes it easy to accidentally create a null storage. - Immediately reject a storage if it is null when passed in Reviewed By: dzhulgakov Differential Revision: D10200448 fbshipit-source-id: 14bfa45f8f59859cc350bd9e20e3ef8692e3991d
1 parent 7788ec9 commit dd2c487

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

aten/src/ATen/core/Storage.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ struct CAFFE2_API Storage {
5151
allocator,
5252
resizable)) {}
5353

54-
void reset() {
55-
storage_impl_->reset();
56-
}
57-
5854
template <typename T>
5955
inline bool IsType() const {
6056
return storage_impl_->IsType<T>();

aten/src/ATen/core/TensorImpl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ struct CAFFE2_API TensorImpl : public c10::intrusive_ptr_target {
162162
TensorImpl(Storage&& storage, TensorTypeId type_id, bool is_variable);
163163

164164
explicit TensorImpl(at::Storage storage) : storage_(std::move(storage)), storage_offset_(0) {
165-
data_type_ = storage_ ? storage_.dtype() : caffe2::TypeMeta{};
165+
AT_ASSERT(storage_);
166+
data_type_ = storage_.dtype();
166167
}
167168

168169
TensorImpl(const TensorImpl&) = default;
@@ -442,7 +443,7 @@ struct CAFFE2_API TensorImpl : public c10::intrusive_ptr_target {
442443
numel_ = -1;
443444
strides_.reset();
444445
is_contiguous_ = true;
445-
storage_.reset();
446+
storage_ = at::Storage(device_type(), caffe2::TypeMeta());
446447
data_type_ = caffe2::TypeMeta();
447448
return;
448449
}

0 commit comments

Comments
 (0)