Skip to content
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

Define device-flexible @sync #64

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaComms"
uuid = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
authors = ["CliMA Contributors <[email protected]>"]
version = "0.5.4"
version = "0.5.5"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ClimaComms.array_type
ClimaComms.@threaded
ClimaComms.@time
ClimaComms.@elapsed
ClimaComms.@sync
```

## Contexts
Expand Down
31 changes: 31 additions & 0 deletions src/devices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,34 @@ macro elapsed(device, expr)
end
end
end

"""
@sync device expr

Device-flexible `@sync`.

Lowers to
```julia
@sync expr
```
for CPU devices and
```julia
CUDA.@sync expr
```
for CUDA devices.
"""
macro sync(device, expr)
# https://github.com/JuliaLang/julia/issues/28979#issuecomment-1756145207
return esc(quote
if $(device) isa $CUDADevice
$CUDA.@sync begin
$(expr)
end
else
@assert $(device) isa $AbstractDevice
$Base.@sync begin
$(expr)
end
end
end)
end
4 changes: 4 additions & 0 deletions test/hygiene.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function test_macro_hyhiene(dev)
CC.@elapsed dev for i in 1:n
sin.(rand(10))
end

CC.@sync dev for i in 1:n
sin.(rand(10))
end
end
dev = CC.device()

Expand Down
Loading