mark Storage functions as const (#12623)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12623
Mark Storage functions as const so that they they can be exposed outside of TensorImpl when calling storage()
Based on this discussion https://github.com/zdevito/ATen/issues/27#issuecomment-330717839
Also potentially useful in the effort to remove ShareExternalPointer
Reviewed By: ezyang
Differential Revision: D10370201
fbshipit-source-id: 43cf3803a4aa7b94fdf0c3a604d7db769ca0bdd5
diff --git a/aten/src/ATen/core/Storage.h b/aten/src/ATen/core/Storage.h
index cd2e3c7..9355b15 100644
--- a/aten/src/ATen/core/Storage.h
+++ b/aten/src/ATen/core/Storage.h
@@ -81,8 +81,8 @@
}
// TODO: remove later
- void set_numel(int64_t numel) {
- storage_impl_->set_numel(numel);
+ void set_numel(int64_t numel) const {
+ storage_impl_.get()->set_numel(numel);
}
bool resizable() const {
@@ -94,10 +94,6 @@
}
// get() use here is to get const-correctness
- void* data() {
- return storage_impl_->data();
- }
-
void* data() const {
return storage_impl_.get()->data();
}
@@ -115,12 +111,12 @@
}
// Returns the previous data_ptr
- at::DataPtr set_data_ptr(at::DataPtr&& data_ptr) {
- return storage_impl_->set_data_ptr(std::move(data_ptr));
+ at::DataPtr set_data_ptr(at::DataPtr&& data_ptr) const {
+ return storage_impl_.get()->set_data_ptr(std::move(data_ptr));
};
- void set_dtype(const caffe2::TypeMeta& data_type) {
- storage_impl_->set_dtype(data_type);
+ void set_dtype(const caffe2::TypeMeta& data_type) const {
+ storage_impl_.get()->set_dtype(data_type);
}
DeviceType device_type() const {