-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathgpu.jl
More file actions
53 lines (47 loc) · 2.19 KB
/
gpu.jl
File metadata and controls
53 lines (47 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Adapt.jl provides a function `adapt(to, x)`, which adapts a value `x` to `to`.
# In practice, this means that we can use `adapt(CuArray, system)` to adapt a system to
# the `CuArray` type.
# What this does is that it converts all `Array`s inside this system to `CuArray`s,
# therefore copying them to the GPU.
# In order to run a simulation on a GPU, we want to call `adapt(T, semi)` to adapt the
# `Semidiscretization` `semi` to the GPU array type `T` (e.g. `CuArray`).
#
# `Adapt.@adapt_structure` automatically generates the `adapt` function for our custom types.
Adapt.@adapt_structure Semidiscretization
Adapt.@adapt_structure InitialCondition
Adapt.@adapt_structure WeaklyCompressibleSPHSystem
Adapt.@adapt_structure DensityDiffusionAntuono
Adapt.@adapt_structure EntropicallyDampedSPHSystem
Adapt.@adapt_structure WallBoundarySystem
Adapt.@adapt_structure BoundaryModelDummyParticles
Adapt.@adapt_structure BoundaryModelMonaghanKajtar
Adapt.@adapt_structure PrescribedMotion
Adapt.@adapt_structure TotalLagrangianSPHSystem
Adapt.@adapt_structure BoundaryZone
Adapt.@adapt_structure SystemBuffer
Adapt.@adapt_structure OpenBoundarySystem
Adapt.@adapt_structure DEMSystem
Adapt.@adapt_structure BoundaryDEMSystem
Adapt.@adapt_structure RCRWindkesselModel
# This makes `@threaded semi for ...` use `semi.parallelization_backend` for parallelization
@inline function PointNeighbors.parallel_foreach(f, iterator, semi::Semidiscretization)
PointNeighbors.parallel_foreach(f, iterator, semi.parallelization_backend)
end
# Same with `@threaded_nosync`
@inline function PointNeighbors.parallel_foreach_nosync(f, iterator,
semi::Semidiscretization)
PointNeighbors.parallel_foreach_nosync(f, iterator, semi.parallelization_backend)
end
function allocate(backend::KernelAbstractions.GPU, ELTYPE, size)
return KernelAbstractions.allocate(backend, ELTYPE, size)
end
function allocate(backend, ELTYPE, size)
return Array{ELTYPE, length(size)}(undef, size)
end
@inline function synchronize_backend(backend::KernelAbstractions.GPU)
KernelAbstractions.synchronize(backend)
return nothing
end
@inline function synchronize_backend(backend)
return nothing
end