Tune kernels for use with FastCartesianIndices #2296
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.
After reviewing performance in the land model, I've come to accept that performance characteristics using multi-dimensional launch configurations are quite sharp. For example, we see good performance with high resolution simulations, but excessively poor if the vertical resolution is low.
All three parts of the launch config and index management:
are entangled, and increasing complexity of the launch configuration requires increasing complexity of the other two.
So, I took a second look at the previous design that I had put in place: always use linear launch configurations and use
CartesianIndices
. The issue with that is thatCartesianIndices(...)[::Int]
results in integer division, which is slow and can hurt performance by as much as 2x.Fortunately, I managed to get something that seems to be working, and I started the registration process for ClimaCartesianIndices.jl, which defines
FastCartesianIndices
, a drop-in replacement forCartesianIndices
. The difference is thatFastCartesianIndices(...)[::Int]
avoids integer division by using bit tricks.See the ClimaCartesianIndices.jl documentation for more information. We could reach near linear indexing speeds by passing
FastCartesianIndices
through to kernels viaVal
, but that will allocate becauseNh
is not in the type domain (we removed it because it, for some unknown reason, spiked compilation times). For now, I think it's still a better trade-off to use CartesianIndices and have more robust performance.As a result, I'm going to revert most of our multi-dimensional launch configurations to linear ones, and start using
FastCartesianIndices
.For now, I'm going to skip the kernels that use shared memory (SEM and FD shmem), since we never had linear launch configurations for those to begin with, and I'm not yet sure how to make that work. That will likely be next on the ticket.
Overall, these changes should yield good performance improvements for the land model, and recover performance losses for our lower resolution experiments, across the board.