Skip to content

[PyTorch] Save a refcount bump in make_variable#51180

Closed
swolchok wants to merge 1 commit intogh/swolchok/94/basefrom
gh/swolchok/94/head
Closed

[PyTorch] Save a refcount bump in make_variable#51180
swolchok wants to merge 1 commit intogh/swolchok/94/basefrom
gh/swolchok/94/head

Conversation

@swolchok
Copy link
Copy Markdown
Contributor

@swolchok swolchok commented Jan 27, 2021

Stack from ghstack:

This fast path still did a refcount bump because it copied the inner intrusive_ptr to the stack. Now it's moved.

Differential Revision: D26094951

This fast path still did a refcount bump because it copied the inner intrusive_ptr to the stack. Now it's moved.

Differential Revision: [D26094951](https://our.internmc.facebook.com/intern/diff/D26094951/)

[ghstack-poisoned]
@swolchok swolchok requested a review from albanD as a code owner January 27, 2021 04:12
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jan 27, 2021

💊 CI failures summary and remediations

As of commit 7e82d4c (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

swolchok added a commit that referenced this pull request Jan 27, 2021
This fast path still did a refcount bump because it copied the inner intrusive_ptr to the stack. Now it's moved.

Differential Revision: [D26094951](https://our.internmc.facebook.com/intern/diff/D26094951/)

ghstack-source-id: 120460258
Pull Request resolved: #51180
Copy link
Copy Markdown

@bhosmer bhosmer left a comment

Choose a reason for hiding this comment

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

so nice

return impl_;
}

c10::intrusive_ptr<TensorImpl, UndefinedTensorImpl> unsafeReleaseIntrusivePtr() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

have you considered instead calling it

c10::intrusive_ptr<TensorImpl, UndefinedTensorImpl> getIntrusivePtr() && {
  return std::move(impl_);
}

Then the call site can be std::move(data).getIntrusivePtr(). Not sure it's better but I've seen this pattern in other libraries (e.g. https://github.com/apache/arrow/blob/master/cpp/src/arrow/result.h#L84 )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would be inconsistent with unsafeReleaseTensorImpl(), above..

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 27, 2021

Codecov Report

Merging #51180 (7e82d4c) into gh/swolchok/94/base (6dda036) will decrease coverage by 0.00%.
The diff coverage is n/a.

@@                   Coverage Diff                   @@
##           gh/swolchok/94/base   #51180      +/-   ##
=======================================================
- Coverage                80.88%   80.88%   -0.01%     
=======================================================
  Files                     1929     1929              
  Lines                   210519   210519              
=======================================================
- Hits                    170287   170282       -5     
- Misses                   40232    40237       +5     

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 1c8d11c.

@facebook-github-bot facebook-github-bot deleted the gh/swolchok/94/head branch January 31, 2021 15:18
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#51180

This fast path still did a refcount bump because it copied the inner intrusive_ptr to the stack. Now it's moved.
ghstack-source-id: 120460258

Test Plan:
1) profile empty benchmark & inspect assembly to verify move
2) run framework overhead benchmarks

Reviewed By: bhosmer

Differential Revision: D26094951

fbshipit-source-id: b2e09f9ad885cb633402885ca1e61a370723f6b8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants