Heterogeneous computing
Support for heterogeneous computing is currently being worked on.
The use of Adapt.jl
Adapt.jl is a package in the JuliaGPU family that allows for the translation of nested data structures. The primary goal is to allow the substitution of Array
at the storage level with a GPU array like CuArray
from CUDA.jl.
To facilitate this, data structures must be parameterized, so instead of:
They must be written as:
furthermore, we need to define a function that allows for the conversion of storage of our types:
or simply
additionally, we must define Adapt.parent_type
.
All together we can use this machinery to perform conversions of a container.
Element-type conversion with Trixi.trixi_adapt
.
We can use Trixi.trixi_adapt
to perform both an element-type and a storage-type adoption:
!!! note adapt(Array{Float32}, C)
is tempting, but it will do the wrong thing in the presence of SVector
s and similar arrays from StaticArrays.jl.
Writing GPU kernels
Offloading computations to the GPU is done with KernelAbstractions.jl, allowing for vendor-agnostic GPU code.
Example
Given the following Trixi.jl code, which would typically be called from within rhs!
:
Put the inner code in a new function
rhs_fct_per_element
. Besides the indexelement
, pass all required fields as arguments, but make sure to@unpack
them from their structs in advance.Where
trixi_rhs_fct
is called, get the backend, i.e., the hardware we are currently running on viatrixi_backend(x)
. This will, e.g., work withu_ode
. Internally, KernelAbstractions.jl'sget_backend
will be called, i.e., KernelAbstractions.jl has to know the type ofx
.Add a new argument
backend
totrixi_rhs_fct
used for dispatch. Whenbackend
isnothing
, the legacy implementation should be used:When
backend
is aBackend
(a type defined by KernelAbstractions.jl), write a KernelAbstractions.jl kernel: