add batched fields for better GPU usage #11
Merged
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.
This adds "batched" Flat fields which behave just like normal fields but actually store several "batches" of fields at once. The motivation is to speed up GPU code, which is currently only using about 20% of a Tesla V100, due to having to wait on results of FFT kernels. Since we can't speed those up, the solution is to just do more of them in parallel. However, we only get the full speedup if we actually batch the field data together so kernels can efficiently go through it all at once, hence batched fields.
You can create batched fields in several ways:
All code pretty much works transparently on batched fields as it does on normal fields, but just does everything in batches. This includes everything up to posterior gradients, sampling, etc... The only difference is that operations that return a scalar now return a
BatchedReal
(which itself can be added, multiplied, etc... as if it were aReal
):On a Tesla V100, some timings for a 256×256 Float32 mixed posterior gradient:
Looks like the sweet-spot for per-gradient speed-up while not hurting overall sequential runtime is somewhere near batchsize of 10 and we get about a 5x speedup.