Skip to content

[PyTorch] RFC: optimize c10::optional<ArrayRef<T>>#59333

Closed
swolchok wants to merge 12 commits intogh/swolchok/252/basefrom
gh/swolchok/252/head
Closed

[PyTorch] RFC: optimize c10::optional<ArrayRef<T>>#59333
swolchok wants to merge 12 commits intogh/swolchok/252/basefrom
gh/swolchok/252/head

Conversation

@swolchok
Copy link
Copy Markdown
Contributor

@swolchok swolchok commented Jun 2, 2021

Stack from ghstack:

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

Differential Revision: D28843027

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jun 2, 2021

💊 CI failures summary and remediations

As of commit 2d02790 (more details on the Dr. CI page):


  • 1/1 failures introduced in this PR

🕵️ 1 new failure recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See CircleCI build pytorch_linux_xenial_cuda11_1_cudnn8_py3_gcc7_build (1/1)

Step: "Build" (full log | diagnosis details | 🔁 rerun)

Jun 04 20:05:58 rm: cannot remove '/var/lib/jenkins/sccache_error.log': No such file or directory
Jun 04 20:05:58 ++++ extract_trap_cmd
Jun 04 20:05:58 ++++ printf '%s\n' ''
Jun 04 20:05:58 +++ printf '%s\n' cleanup
Jun 04 20:05:58 ++ trap -- '
Jun 04 20:05:58 cleanup' EXIT
Jun 04 20:05:58 ++ [[ pytorch-linux-xenial-cuda11.1-cudnn8-py3-gcc7-build != *pytorch-win-* ]]
Jun 04 20:05:58 ++ which sccache
Jun 04 20:05:58 ++ sccache --stop-server
Jun 04 20:05:58 ++ true
Jun 04 20:05:58 ++ rm /var/lib/jenkins/sccache_error.log
Jun 04 20:05:58 rm: cannot remove '/var/lib/jenkins/sccache_error.log': No such file or directory
Jun 04 20:05:58 ++ true
Jun 04 20:05:58 ++ [[ -n '' ]]
Jun 04 20:05:58 ++ [[ pytorch-linux-xenial-cuda11.1-cudnn8-py3-gcc7-build == *rocm* ]]
Jun 04 20:05:58 ++ SCCACHE_ERROR_LOG=/var/lib/jenkins/sccache_error.log
Jun 04 20:05:58 ++ SCCACHE_IDLE_TIMEOUT=1200
Jun 04 20:05:58 ++ RUST_LOG=sccache::server=error
Jun 04 20:05:58 ++ sccache --start-server
Jun 04 20:05:58 sccache: Starting the server...
Jun 04 20:05:58 ++ sccache --zero-stats
Jun 04 20:05:58 Compile requests                      0

1 job timed out:

  • pytorch_linux_xenial_cuda11_1_cudnn8_py3_gcc7_build

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.

Click here to manually regenerate this comment.

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
swolchok added a commit that referenced this pull request Jun 2, 2021
Pull Request resolved: #59333

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.
ghstack-source-id: 130402821

Differential Revision: [D28843027](https://our.internmc.facebook.com/intern/diff/D28843027/)
@swolchok swolchok requested review from ezyang and samestep June 2, 2021 19:39
@swolchok
Copy link
Copy Markdown
Contributor Author

swolchok commented Jun 2, 2021

If and when this is committed, we should leave a breadcrumb somewhere indicating that this is a thing that will regress when we upgrade to std::optional, and we'll need to port this optimization over.

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
swolchok added a commit that referenced this pull request Jun 2, 2021
Pull Request resolved: #59333

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.
ghstack-source-id: 130427769

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D28843027/)!
@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Jun 3, 2021

Easy breadcrumb is add a static assert on c10::optional<ArrayRef<T>> size with a comment saying what to do when the static assert fails.

Comment thread c10/util/ArrayRef.h Outdated
size_type Length;

void debugCheckNullptrInvariant() {
TORCH_INTERNAL_ASSERT(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

DEBUG_ONLY assert?

Comment thread c10/util/Optional.cpp
"c10::optional<IntArrayRef> should be trivially copyable");
static_assert(
sizeof(c10::optional<c10::IntArrayRef>) == sizeof(c10::IntArrayRef),
"c10::optional<IntArrayRef> should be size-optimized");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is assert is good, just shouldn't be in this file (because it's likely to get deleted when we go to std::optional)

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.

if people are going to delete this file without looking at it, what's going to stop them from deleting the contents of Optional.h or Optional_test.cpp without looking? (and which one of those two did you want this moved to)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blugh, IDK, some random test file in ATen/test maybe. Or we can just trust in code review, I guess.

Comment thread c10/util/Optional.h Outdated
};

// HACK: Optimization for ArrayRef<T>. We take advantage of an unused
// bit pattern in ArrayRef (inspirted by Arthur O'Dwyer's
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: inspired

Copy link
Copy Markdown
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

okey dokey

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
…o on "[PyTorch] RFC: optimize c10::optional<ArrayRef<T>>"

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
swolchok added a commit that referenced this pull request Jun 3, 2021
Pull Request resolved: #59333

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.
ghstack-source-id: 130553181

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D28843027/)!
…ize c10::optional<ArrayRef<T>>"

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
…nal<ArrayRef<T>>"

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
swolchok added a commit that referenced this pull request Jun 4, 2021
Pull Request resolved: #59333

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.
ghstack-source-id: 130623937

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D28843027/)!
Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.

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

[ghstack-poisoned]
swolchok added a commit that referenced this pull request Jun 4, 2021
Pull Request resolved: #59333

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.
ghstack-source-id: 130631329

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D28843027/)!
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 1798ff0.

deniskokarev pushed a commit to deniskokarev/pytorch that referenced this pull request Jun 9, 2021
Summary:
Pull Request resolved: pytorch#59333

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.
ghstack-source-id: 130631329

Test Plan: Updated optional_test and added static_assert in Optional.cpp.

Reviewed By: ezyang

Differential Revision: D28843027

fbshipit-source-id: 3029f05e03a9f04ca7337962e7770cdeb9a608d9
@facebook-github-bot facebook-github-bot deleted the gh/swolchok/252/head branch June 11, 2021 14:17
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 25, 2026
Summary:
Pull Request resolved: pytorch#59333

Code comment should explain this in sufficient detail. In brief, making it 16 bytes should get it to be passed in registers.
ghstack-source-id: 130631329

Test Plan: Updated optional_test and added static_assert in Optional.cpp.

Reviewed By: ezyang

Differential Revision: D28843027

fbshipit-source-id: 3029f05e03a9f04ca7337962e7770cdeb9a608d9
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.

3 participants