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-agnostic fill #81

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ v0.6.2
-------

- We added a device-agnostic `allowscalar(f, ::AbstractDevice, args...; kwargs...)` to further assist in making CUDA an extension.
- We added a device-agnostic `fill(value, dims...)` to further assist in making CUDA an extension.

v0.6.1
-------
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
"Jake Bolewski <[email protected]>",
"Gabriele Bozzola <[email protected]>",
]
version = "0.6.1"
version = "0.6.2"

[weakdeps]
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 @@ -28,6 +28,7 @@ ClimaComms.device
ClimaComms.device_functional
ClimaComms.array_type
ClimaComms.allowscalar
ClimaComms.fill
ClimaComms.@threaded
ClimaComms.@time
ClimaComms.@elapsed
Expand Down
1 change: 1 addition & 0 deletions ext/ClimaCommsCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ end
ClimaComms.array_type(::ClimaComms.CUDADevice) = CUDA.CuArray
ClimaComms.allowscalar(f, ::ClimaComms.CUDADevice, args...; kwargs...) =
CUDA.@allowscalar f(args...; kwargs...)
ClimaComms.fill(::CUDADevice, value, dims...) = CUDA.fill(value, dims...)

# Extending ClimaComms methods that operate on expressions (cannot use dispatch here)
ClimaComms.cuda_sync(expr) = CUDA.@sync expr
Expand Down
9 changes: 9 additions & 0 deletions src/devices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,12 @@ end
```
"""
allowscalar(f, ::AbstractDevice, args...; kwargs...) = f(args...; kwargs...)

"""
fill(::AbstractDevice, value, dims...)

Device-flexible version of `fill`.

Calls `Base.fill` on `AbstractCPUDevice`s and `CUDA.fill` on `CUDADevice`s.
"""
ClimaComms.fill(::AbstractDevice, value, dims...) = Base.fill(value, dims...)
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,7 @@ end
device isa ClimaComms.CUDADevice && @test_throws ErrorException a[1]
@test x == Array(a)[1]
end

@testset "fill" begin
@test ClimaComms.fill(device, 3, (2, 2)) isa AT
end
Loading