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

BlobGetMutableTensor returns Tensor (#14136) #14424

Closed
wants to merge 1 commit into from

Conversation

jerryzh168
Copy link
Contributor

Summary:
Pull Request resolved: #14136

Since now Tensor is a shared_ptr, it doesn't make sense to have Tensor* around anymore,
this diff is changing Tensor* to Tensor in the interface.
We'll store pointer to intrusive_ptr to TensorImpl in Tensor and create Tensor object on the fly
when returning from BlobGetMutableTensor.
Another motivation is we want Blob to store intrusive_ptr of TensorImpl because IValue can store intrusive ptr. Without this change, IValue will have to store Blob which is an extra level of indirection.

To remove Tensor*, we'll do following

auto* Y = Ouptut(0);
Y->mutable_data...

-->

auto Y = Output(0);
Y.mutable_data...

But to run clangr codemod, we'll keep both APIs in different names, e.g. Output and XOutput, and do the refactor and then delete the old method and rename the new method into the old one.
For example for Output, we'll first codemod the callsites from Output to XOutput, then delete the old Output and rename XOutput to Output in the end.

This diff should be rebased on the diffs that removes Resize/ResizeLike+mutable_data

Differential Revision: D12934074

@@ -28,6 +28,7 @@ inline Tensor* BlobSetTensor(Blob* blob, const Tensor& tensor) {
return blob->Reset<Tensor>(new Tensor(tensor));
}

// need to keep both for clangr codemod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe specify what you mean by "both"

Summary:
Pull Request resolved: pytorch#14424

Pull Request resolved: pytorch#14136

Since now Tensor is a shared_ptr, it doesn't make sense to have Tensor* around anymore,
so we want to change Tensor* to Tensor in the interface.
We added functions that work with `Tensor` instead of `Tensor*` in this diff.

To remove Tensor*, we'll do following
```
auto* Y = Ouptut(0);
Y->mutable_data...
```
-->
```
auto Y = Output(0);
Y.mutable_data...
```

But to run clangr codemod, we'll keep both APIs in different names, e.g. `Output` and `XOutput`, and do the refactor and then delete the old method and rename the new method into the old one.
For example for `Output`, we'll first codemod the callsites from `Output` to `XOutput`, then delete the old `Output` and rename `XOutput` to `Output` in the end.

Reviewed By: smessmer

Differential Revision: D12934074

fbshipit-source-id: 120778830835fc4d90286cf2ed00b4994cf32737
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants