This repository has been archived by the owner on Apr 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
Register promotion: limit the number of elements promoted per thread #587
Open
ftynse
wants to merge
9
commits into
master
Choose a base branch
from
sort-register-promotion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The captured variable was not used inside the lambda since it was introduced in the prehistory.
This function will be reused in an upcoming commit to sort groups before register promotion.
This function will be reused in an upcoming commit.
Follow the same strategy as with shared memory promotion: first, sort tensors in decreasing order of the total number of references; then, for each tensor, sort groups based on the number of references in this group. Tensor groups with more references are expected to benefit more from promotion as more global memory accesses may be avoided thanks to explicit caching in faster layers of the memory hierarchy. Note that since there is no limit on the number of registers to use, all groups that can be promoted into registers are promoted, and the sorting has no effect on the outcome. Such limit will be introduced next.
Introduce the per-thread limit on the total number of registers to use during promotion. This limit does not differentiate between the data types because we cannot control the register allocation at CUDA level anyway. It rather serves as a controllable input to the promotion heuristic.
The limit applies per thread and is cumulated for all subtrees where promotion is performed. By default, it is set to SIZE_MAX, which ensures backwards-compatible behavior for all sensible cases (if something had required more than SIZE_MAX registers, it would have been spilled to global memory and still would not have fit). This limit will be exposed as a mapping option in an upcoming commit.
This will be used in computation of the default number of elements to promote to private.
This platform-neutral function to query the number of registers will be used in an upcoming commit.
@caffe2bot retest this, please |
This mapping option controls the maximum number of elements per thread that are promoted into the private memory (hopefully, registers, but we cannot guarantee this at the CUDA level). The value is optional in the protocol buffers. When not provided, query the maximum number of threads per block from CUDA device properties and divide it by the number of threads in the block to obtain the per-thread limitation. Note that using all registers in a single block will likely limit the occupancy of SMs, potentially degrading performance. Introducing the limiting factor is primarily motivated by this effect, and it lets the caller to require the mapper to use less registers, potentially increasing the occupancy. Since register allocation is performed by the downstream compiler, this option is a mere recommendation and is expressed in terms of (untyped) elements rather than actual registers. It would be impossible to account for all registers required by the main computation (that is, necessary to store the data loaded from memory during operations) at the CUDA level, that also contribute to the register pressure of the kernel. Although limiting the number of promoted elements number of registers available per thread may seem too constraining for occupancy, it is strictly better than the current approach where we may promote even more elements, which then get spilled into the slow local memory.
22b36e1
to
74d3e85
Compare
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
cuda::MappedScop: introduce maxPrivateElements mapping option
This mapping option controls the maximum number of elements per thread
that are promoted into the private memory (hopefully, registers, but we
cannot guarantee this at the CUDA level). The value is optional in the
protocol buffers. When not provided, query the maximum number of
threads per block from CUDA device properties and divide it by the
number of threads in the block to obtain the per-thread limitation.
Note that using all registers in a single block will likely limit the
occupancy of SMs, potentially degrading performance. Introducing the
limiting factor is primarily motivated by this effect, and it lets the
caller to require the mapper to use less registers, potentially
increasing the occupancy. Since register allocation is performed by the
downstream compiler, this option is a mere recommendation and is
expressed in terms of (untyped) elements rather than actual registers.
It would be impossible to account for all registers required by the main
computation (that is, necessary to store the data loaded from memory
during operations) at the CUDA level, that also contribute to the
register pressure of the kernel.
Although limiting the number of promoted elements number of registers
available per thread may seem too constraining for occupancy, it is
strictly better than the current approach where we may promote even more
elements, which then get spilled into the slow local memory.
Closes #556