From 9eac8a7c2cb3d538c8272b5c045a8127765927f2 Mon Sep 17 00:00:00 2001 From: Ansha Yu Date: Mon, 15 Oct 2018 13:01:38 -0700 Subject: [PATCH] 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 --- aten/src/ATen/core/Storage.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/aten/src/ATen/core/Storage.h b/aten/src/ATen/core/Storage.h index cd2e3c7c7..9355b1581 100644 --- a/aten/src/ATen/core/Storage.h +++ b/aten/src/ATen/core/Storage.h @@ -81,8 +81,8 @@ struct CAFFE2_API Storage { } // 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 @@ struct CAFFE2_API Storage { } // 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 @@ struct CAFFE2_API Storage { } // 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 {