GPU acceleration

If your computer includes a suitable GPU, the code can use it to speed-up certain operations, most notably linked to the computation of lens-mapping for a large number of directions (points). This is, for example, required for the inversion of the lens-map when using a fine grid (see Gravity.lensunmap), or for the analysis of extended image.

Gravity.has_processing_unitFunction
has_processing_unit(Val(:something))

Return true if the requested processing unit is available.

Without extensions, this function returns true only for Val(:CPU), and false in all other cases.

Extensions should overload this function by adding definitions such as

has_processing_unit(::Val{:CUDA}) = CUDA.funtional()
source

GPU accelerations are enabled by loading the associated package, as explained in the following pages.

CUDA

In order to use a CUDA-enabled GPU, the user should include the CUDA package in its environment. That can be just performed with the command

julia> using CUDA

which can executed either before or after the using Gravity command. This way one can use various CUDA-based versions of standard routines. Note that after this command, if a CUDA GPU is available, one has

Gravity.has_processing_unit(Val(:CUDA)) == true

Lens mapping

In order to perform a batch lens mapping on the GPU for an array of points, on calls

Gravity.lensmap(lenssys, ς, θs, Val(:CUDA); kw...)

The argument θs can be either an array (of any dimension), or a tuple (xrange, yrange), in which case the result will be a 2D array (matrix) of points.

Grid inversion

Grid inversion is necessary to find a starting point for iterative algorithms used to solve the lens equation. Internally, this task is carried out by computing the lens mapping at the corners of grid cells, and by finding all polygons that intercept a given source in the source-plane. This task is carried out by Gravity.inversegridpoints.

When this function is called with a CuArray as third argument (the mapped points), it triggers a call to a CUDA-based version.

Convolutions

CUDA-based convolutions are integrated in the Gravity convolution algorithms by registering them as convolution methods in the Gravity.convolution_direct_methods and Gravity.convolution_indirect_methods. The method implemented are

  • :cuda_direct, a CUDA implementation of the :binned convolution technique;

  • :cuda_fft, FFT based;

  • :cuda_fft2, FFT based, using power of two grid sizes.