-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50e15ff
commit d6cc624
Showing
5 changed files
with
137 additions
and
105 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,28 @@ uuid = "c3c07f87-98de-43f2-a76f-835b330b2cbb" | |
authors = ["CliMA Contributors <[email protected]>"] | ||
version = "0.3.1" | ||
|
||
[deps] | ||
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" | ||
|
||
[weakdeps] | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
|
||
[extensions] | ||
MultiBroadcastFusionCUDAExt = ["CUDA", "Adapt"] | ||
|
||
[compat] | ||
julia = "^1.9" | ||
Adapt = "3, 4" | ||
CUDA = "5" | ||
julia = "^1.9" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" | ||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | ||
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test", "CUDA", "Adapt", "SafeTestsets", "BenchmarkTools", "InteractiveUtils"] |
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 |
---|---|---|
@@ -1,55 +1,55 @@ | ||
module MultiBroadcastFusionCUDAExt | ||
|
||
import CUDA, Adapt | ||
import MultiBroadcastFusion as MBF | ||
import MultiBroadcastFusion: fused_copyto! | ||
|
||
MBF.device(x::CUDA.CuArray) = MBF.GPU() | ||
|
||
function fused_copyto!(fmb::MBF.FusedMultiBroadcast, ::MBF.GPU) | ||
(; pairs) = fmb | ||
dest = first(pairs).first | ||
nitems = length(parent(dest)) | ||
max_threads = 256 # can be higher if conditions permit | ||
nthreads = min(max_threads, nitems) | ||
nblocks = cld(nitems, nthreads) | ||
CUDA.@cuda threads = (nthreads) blocks = (nblocks) fused_copyto_kernel!(fmb) | ||
return nothing | ||
end | ||
function fused_copyto_kernel!(fmb::MBF.FusedMultiBroadcast) | ||
(; pairs) = fmb | ||
dest = first(pairs).first | ||
nitems = length(dest) | ||
idx = CUDA.threadIdx().x + (CUDA.blockIdx().x - 1) * CUDA.blockDim().x | ||
if idx ≤ nitems | ||
MBF.rcopyto_at!(pairs, idx) | ||
end | ||
return nothing | ||
end | ||
|
||
adapt_f(to, f::F) where {F} = Adapt.adapt(to, f) | ||
adapt_f(to, ::Type{F}) where {F} = (x...) -> F(x...) | ||
|
||
adapt_src(to, src::AbstractArray) = Adapt.adapt(to, src) | ||
|
||
function adapt_src(to, bc::Base.Broadcast.Broadcasted) | ||
Base.Broadcast.Broadcasted( | ||
bc.style, | ||
adapt_f(to, bc.f), | ||
Adapt.adapt(to, bc.args), | ||
Adapt.adapt(to, bc.axes), | ||
) | ||
end | ||
|
||
function Adapt.adapt_structure( | ||
to::CUDA.KernelAdaptor, | ||
fmbc::MBF.FusedMultiBroadcast, | ||
) | ||
MBF.FusedMultiBroadcast(map(fmbc.pairs) do pair | ||
dest = pair.first | ||
src = pair.second | ||
Pair(Adapt.adapt(to, dest), adapt_src(to, src)) | ||
end) | ||
end | ||
# import CUDA, Adapt | ||
# import MultiBroadcastFusion as MBF | ||
# import MultiBroadcastFusion: fused_copyto! | ||
|
||
# # MBF.device(x::CUDA.CuArray) = MBF.GPU() | ||
|
||
# function fused_copyto!(fmb::MBF.FusedMultiBroadcast, ::MBF.GPU) | ||
# (; pairs) = fmb | ||
# dest = first(pairs).first | ||
# nitems = length(parent(dest)) | ||
# max_threads = 256 # can be higher if conditions permit | ||
# nthreads = min(max_threads, nitems) | ||
# nblocks = cld(nitems, nthreads) | ||
# CUDA.@cuda threads = (nthreads) blocks = (nblocks) fused_copyto_kernel!(fmb) | ||
# return nothing | ||
# end | ||
# function fused_copyto_kernel!(fmb::MBF.FusedMultiBroadcast) | ||
# (; pairs) = fmb | ||
# dest = first(pairs).first | ||
# nitems = length(dest) | ||
# idx = CUDA.threadIdx().x + (CUDA.blockIdx().x - 1) * CUDA.blockDim().x | ||
# if idx ≤ nitems | ||
# MBF.rcopyto_at!(pairs, idx) | ||
# end | ||
# return nothing | ||
# end | ||
|
||
# adapt_f(to, f::F) where {F} = Adapt.adapt(to, f) | ||
# adapt_f(to, ::Type{F}) where {F} = (x...) -> F(x...) | ||
|
||
# adapt_src(to, src::AbstractArray) = Adapt.adapt(to, src) | ||
|
||
# function adapt_src(to, bc::Base.Broadcast.Broadcasted) | ||
# Base.Broadcast.Broadcasted( | ||
# bc.style, | ||
# adapt_f(to, bc.f), | ||
# Adapt.adapt(to, bc.args), | ||
# Adapt.adapt(to, bc.axes), | ||
# ) | ||
# end | ||
|
||
# function Adapt.adapt_structure( | ||
# to::CUDA.KernelAdaptor, | ||
# fmbc::MBF.FusedMultiBroadcast, | ||
# ) | ||
# MBF.FusedMultiBroadcast(map(fmbc.pairs) do pair | ||
# dest = pair.first | ||
# src = pair.second | ||
# Pair(Adapt.adapt(to, dest), adapt_src(to, src)) | ||
# 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
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