-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Remove virtual keyword from most functions in TensorImpl #20909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
benchmark? |
gchanan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are a bunch of comments in TensorImpl.h about avoiding virtual dispatch for perf that aren't relevant anymore.
c10/core/TensorImpl.cpp
Outdated
| TensorImpl* TensorImpl::maybe_zero_dim(bool condition_when_zero_dim) { | ||
| // We only allow this operation on dense tensors | ||
| if (!(has_storage() && layout() == kStrided)) { | ||
| TORCH_CHECK(condition_when_zero_dim == (dim() == 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you just moved this, but I think this should be an INTERAL_CHECK; this isn't a public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
c10/core/UndefinedTensorImpl.h
Outdated
| int64_t size(int64_t d) const override; | ||
| int64_t stride(int64_t d) const override; | ||
| int64_t dim() const override; | ||
| bool has_storage() const override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is has_storage still virtual?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking whether the derived types of TensorImpl is responsible for telling whether it has storage. An alternative is to explicitly check whether the current tensor is sparse or MKLDNN tensor, and if so return false in has_storage().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to explicitly check whether the current tensor is sparse or MKLDNN tensor, and if so return false in has_storage().
| bool TensorImpl::has_storage() const { | ||
| return storage_; | ||
| TORCH_CHECK(type_id_ != UndefinedTensorId(), type_id_, " does not have has_storage"); | ||
| return !is_sparse() && !is_mkldnn() && storage_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this just strided? Do we ever have strided tensors where "storage_" is false?
|
|
||
| TensorImpl* TensorImpl::maybe_zero_dim(bool condition_when_zero_dim) { | ||
| // We only allow this operation on dense tensors | ||
| if (!(has_storage() && layout() == kStrided)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before, is there a difference between has_storage and the layout being strided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my main question is -- can we just has_storage -> storage_ != NULL as an equivalence for kStrided? I don't know if that works with C2 tensors or not, though.
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
As part of the Variable/Tensor merge, we want to de-virtualize TensorImpl as much as possible, to achieve performance gain for common Tensor functions such as
numel()/sizes()/dim().This supersedes #11259.