-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for async f!
and j!
#229
Open
charleskawczynski
wants to merge
1
commit into
main
Choose a base branch
from
ck/async_support
base: main
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.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module CudaExt | ||
|
||
import CUDA | ||
import ClimaComms: SingletonCommsContext, CUDADevice | ||
import ClimaTimeSteppers: compute_fj! | ||
|
||
@inline function compute_fj!(f, j, U, f!, j!, ::SingletonCommsContext{CUDADevice}) | ||
# TODO: we should benchmark these two options to | ||
# see if one is preferrable over the other | ||
if Base.Threads.nthreads() > 1 | ||
compute_fj_spawn!(f, j, U, f!, j!) | ||
else | ||
compute_fj_streams!(f, j, U, f!, j!) | ||
end | ||
end | ||
|
||
@inline function compute_fj_streams!(f, j, U, f!, j!) | ||
event = CUDA.CuEvent(CUDA.EVENT_DISABLE_TIMING) | ||
CUDA.record(event, CUDA.stream()) # record event on main stream | ||
|
||
stream1 = CUDA.CuStream() # make a stream | ||
local event1 | ||
CUDA.stream!(stream1) do # work to be done by stream1 | ||
CUDA.wait(event, stream1) # make stream1 wait on event (host continues) | ||
f!(f, U) | ||
event1 = CUDA.CuEvent(CUDA.EVENT_DISABLE_TIMING) | ||
end | ||
CUDA.record(event1, stream1) # record event1 on stream1 | ||
|
||
stream2 = CUDA.CuStream() # make a stream | ||
local event2 | ||
CUDA.stream!(stream2) do # work to be done by stream2 | ||
CUDA.wait(event, stream2) # make stream2 wait on event (host continues) | ||
j!(j, U) | ||
event2 = CUDA.CuEvent(CUDA.EVENT_DISABLE_TIMING) | ||
end | ||
CUDA.record(event2, stream2) # record event2 on stream2 | ||
|
||
CUDA.wait(event1, CUDA.stream()) # make main stream wait on event1 | ||
CUDA.wait(event2, CUDA.stream()) # make main stream wait on event2 | ||
end | ||
|
||
@inline function compute_fj_spawn!(f, j, U, f!, j!) | ||
|
||
CUDA.synchronize() | ||
CUDA.@sync begin | ||
Base.Threads.@spawn begin | ||
f!(f, U) | ||
CUDA.synchronize() | ||
nothing | ||
end | ||
Base.Threads.@spawn begin | ||
j!(j, U) | ||
CUDA.synchronize() | ||
nothing | ||
end | ||
end | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@inline function compute_fj!(f, j, U, f!, j!, ::Union{Nothing, ClimaComms.AbstractCommsContext}) | ||
f!(f, U) | ||
j!(j, U) | ||
end | ||
|
||
@inline function compute_fj!(f, j, U, f!, j!, ::ClimaComms.SingletonCommsContext{ClimaComms.CPUMultiThreaded}) | ||
Base.@sync begin | ||
Base.Threads.@spawn begin | ||
f!(f, U) | ||
nothing | ||
end | ||
Base.Threads.@spawn begin | ||
j!(j, U) | ||
nothing | ||
end | ||
end | ||
end |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be that CUDA doesn't like making these streams at every RHS evaluation. Maybe we can try caching this in the timestepper?