Skip to content
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

[PyTorch] Devirtualize TensorImpl::sizes() with macro #50176

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions c10/core/TensorImpl.cpp
Expand Up @@ -94,9 +94,11 @@ TensorImpl::TensorImpl(Storage&& storage, DispatchKeySet key_set, const caffe2::
strides_.push_back(1);
}

#ifndef C10_DISABLE_TENSORIMPL_EXTENSIBILITY
IntArrayRef TensorImpl::sizes() const {
return sizes_;
}
#endif

IntArrayRef TensorImpl::strides() const {
return strides_;
Expand Down
9 changes: 8 additions & 1 deletion c10/core/TensorImpl.h
Expand Up @@ -390,7 +390,14 @@ struct C10_API TensorImpl : public c10::intrusive_ptr_target {
* Return a reference to the sizes of this tensor. This reference remains
* valid as long as the tensor is live and not resized.
*/
virtual IntArrayRef sizes() const;
TENSORIMPL_MAYBE_VIRTUAL IntArrayRef sizes() const
#ifdef C10_DISABLE_TENSORIMPL_EXTENSIBILITY
{
return sizes_;
}
#else
;
#endif

/**
* Return a reference to the strides of this tensor. This reference remains
Expand Down
4 changes: 0 additions & 4 deletions c10/core/UndefinedTensorImpl.cpp
Expand Up @@ -8,10 +8,6 @@ UndefinedTensorImpl::UndefinedTensorImpl()
: TensorImpl(DispatchKey::Undefined, caffe2::TypeMeta(), c10::nullopt) {
}

IntArrayRef UndefinedTensorImpl::sizes() const {
AT_ERROR("sizes() called on undefined Tensor");
}

int64_t UndefinedTensorImpl::size(int64_t d) const {
AT_ERROR("size(dim) called on an undefined Tensor");
}
Expand Down
1 change: 0 additions & 1 deletion c10/core/UndefinedTensorImpl.h
Expand Up @@ -17,7 +17,6 @@ struct C10_API UndefinedTensorImpl final : public TensorImpl {
#endif
return &_singleton;
}
IntArrayRef sizes() const override;
IntArrayRef strides() const override;
int64_t size(int64_t d) const override;
int64_t stride(int64_t d) const override;
Expand Down