Skip to content

Commit fc3a38d

Browse files
efaulhaberLasNikas
authored andcommitted
Add docs for GPU support (trixi-framework#660)
* Add docs for GPU support * Reformat code * Implement suggestions * Implement suggestions * Fix typo
1 parent fea431c commit fc3a38d

File tree

5 files changed

+83
-3
lines changed

5 files changed

+83
-3
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ makedocs(sitename="TrixiParticles.jl",
120120
"Preprocessing" => [
121121
"Sampling of Geometries" => joinpath("preprocessing", "preprocessing.md")
122122
],
123-
"Components" => [
123+
"GPU Support" => "gpu.md",
124+
"API Reference" => [
124125
"Overview" => "overview.md",
125126
"General" => [
126127
"Semidiscretization" => joinpath("general", "semidiscretization.md"),

docs/src/gpu.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# GPU Support
2+
3+
GPU support is still an experimental feature that is actively being worked on.
4+
As of now, the [`WeaklyCompressibleSPHSystem`](@ref) and the [`BoundarySPHSystem`](@ref)
5+
are supported on GPUs.
6+
We have tested this on GPUs by Nvidia and AMD.
7+
8+
To run a simulation on a GPU, we need to use the [`FullGridCellList`](@ref)
9+
as cell list for the [`GridNeighborhoodSearch`](@ref).
10+
This cell list requires a bounding box for the domain, unlike the default cell list, which
11+
uses an unbounded domain.
12+
For simulations that are bounded by a closed tank, we can use the boundary of the tank
13+
to obtain the bounding box as follows.
14+
```jldoctest gpu; output=false, setup=:(using TrixiParticles; trixi_include(@__MODULE__, joinpath(examples_dir(), "fluid", "hydrostatic_water_column_2d.jl"), sol=nothing))
15+
search_radius = TrixiParticles.compact_support(smoothing_kernel, smoothing_length)
16+
min_corner = minimum(tank.boundary.coordinates, dims=2) .- search_radius
17+
max_corner = maximum(tank.boundary.coordinates, dims=2) .+ search_radius
18+
cell_list = TrixiParticles.PointNeighbors.FullGridCellList(; min_corner, max_corner)
19+
20+
# output
21+
PointNeighbors.FullGridCellList{PointNeighbors.DynamicVectorOfVectors{Int32, Matrix{Int32}, Vector{Int32}, Base.RefValue{Int32}}, Nothing, SVector{2, Float64}, SVector{2, Float64}}(Vector{Int32}[], nothing, [-0.24500000000000002, -0.24500000000000002], [1.245, 1.245])
22+
```
23+
24+
We then need to pass this cell list to the neighborhood search and the neighborhood search
25+
to the [`Semidiscretization`](@ref).
26+
```jldoctest gpu; output=false
27+
semi = Semidiscretization(fluid_system, boundary_system,
28+
neighborhood_search=GridNeighborhoodSearch{2}(; cell_list))
29+
30+
# output
31+
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
32+
│ Semidiscretization │
33+
│ ══════════════════ │
34+
│ #spatial dimensions: ………………………… 2 │
35+
│ #systems: ……………………………………………………… 2 │
36+
│ neighborhood search: ………………………… GridNeighborhoodSearch │
37+
│ total #particles: ………………………………… 636 │
38+
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
39+
```
40+
41+
At this point, we should run the simulation and make sure that it still works and that
42+
the bounding box is large enough.
43+
For some simulations where particles move outside the initial tank coordinates,
44+
for example when the tank is not closed or when the tank is moving, an appropriate
45+
bounding box has to be specified.
46+
47+
Then, we only need to specify the data type that is used for the simulation.
48+
On an Nvidia GPU, we specify:
49+
```julia
50+
using CUDA
51+
ode = semidiscretize(semi, tspan, data_type=CuArray)
52+
```
53+
On an AMD GPU, we use:
54+
```julia
55+
using AMDGPU
56+
ode = semidiscretize(semi, tspan, data_type=ROCArray)
57+
```
58+
Then, we can run the simulation as usual.
59+
All data is transferred to the GPU during initialization and all loops over particles
60+
and their neighbors will be executed on the GPU as kernels generated by KernelAbstractions.jl.
61+
Data is only copied to the CPU for saving VTK files via the [`SolutionSavingCallback`](@ref).

docs/src/overview.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Overview
2+
The actual API reference is not listed on a single page, like in most Julia packages,
3+
but instead is split into multiple sections that follow a similar structure
4+
as the code files themselves.
5+
In these sections, API docs are combined with explanations of the theoretical background
6+
of these methods.
7+
28
The following page gives a rough overview of important parts of the code.
39

410
## Program flow
511

612
To initiate a simulation, the goal is to solve an ordinary differential equation, for example,
7-
by employing the time integration schemes provided by OrdinaryDiffEq.jl. These schemes are then
13+
by employing the time integration schemes provided by OrdinaryDiffEq.jl. These schemes are then
814
utilized to integrate ``\mathrm{d}u/\mathrm{d}t`` and ``\mathrm{d}v/\mathrm{d}t``, where ``u``
915
represents the particles' positions and ``v`` their properties such as velocity and density.
1016
During a single time step or an intermediate step of the time integration scheme, the functions

docs/src/reference-pointneighbors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PointNeighbors.jl API
1+
# [PointNeighbors.jl API](@id pointneighbors)
22

33
```@meta
44
CurrentModule = PointNeighbors

test/examples/examples.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@
99
"hydrostatic_water_column_2d.jl"),
1010
fluid_system=nothing, sol=nothing, semi=nothing, ode=nothing)
1111

12+
# Neighborhood search for `FullGridCellList` test below
13+
search_radius = TrixiParticles.compact_support(smoothing_kernel,
14+
smoothing_length)
15+
min_corner = minimum(tank.boundary.coordinates, dims=2) .- search_radius
16+
max_corner = maximum(tank.boundary.coordinates, dims=2) .+ search_radius
17+
cell_list = TrixiParticles.PointNeighbors.FullGridCellList(; min_corner,
18+
max_corner)
19+
semi_fullgrid = Semidiscretization(fluid_system, boundary_system,
20+
neighborhood_search=GridNeighborhoodSearch{2}(;
21+
cell_list))
22+
1223
hydrostatic_water_column_tests = Dict(
1324
"WCSPH default" => (),
25+
"WCSPH with FullGridCellList" => (semi=semi_fullgrid,),
1426
"WCSPH with source term damping" => (source_terms=SourceTermDamping(damping_coefficient=1e-4),),
1527
"WCSPH with SummationDensity" => (fluid_density_calculator=SummationDensity(),
1628
clip_negative_pressure=true),

0 commit comments

Comments
 (0)