Skip to content

Commit d38aaab

Browse files
committed
Update documentation with backend token examples
1 parent 7b7f61e commit d38aaab

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

docs/src/abstract.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,27 @@ An overview about the current packages and their dependencies is shown in the fo
1313
## Implementations
1414

1515
Currently, there are four implementations of the `AbstractNFFTs` interface:
16-
1. **NFFT.jl**: This is the reference implementation running und the CPU.
17-
2. **CuNFFT.jl**: An implementation running on graphics hardware of Nvidia exploiting CUDA.jl
18-
3. **NFFT3.jl**: In the `Wrapper` directory of `NFFT.jl` there is a wrapper around the `NFFT3.jl` package following the `AbstractNFFTs` interface. `NFFT3.jl` is itself a wrapper around the high performance C library [NFFT3](http://www.nfft.org).
19-
4. **FINUFFT.jl**: In the `Wrapper` directory of `NFFT.jl` there is a wrapper around the `FINUFFT.jl` package. `FINUFFT.jl` is itself a wrapper around the high performance C++ library [FINUFFT](https://finufft.readthedocs.io).
16+
1. **NFFT.jl**: This is the reference implementation running on the CPU and with configurations on the GPU.
17+
2. **NFFT3.jl**: In the `Wrapper` directory of `NFFT.jl` there is a wrapper around the `NFFT3.jl` package following the `AbstractNFFTs` interface. `NFFT3.jl` is itself a wrapper around the high performance C library [NFFT3](http://www.nfft.org).
18+
3. **FINUFFT.jl**: In the `Wrapper` directory of `NFFT.jl` there is a wrapper around the `FINUFFT.jl` package. `FINUFFT.jl` is itself a wrapper around the high performance C++ library [FINUFFT](https://finufft.readthedocs.io).
19+
4. **NonuniformFFTs.jl**: Pure Julia package written with generic and fast GPU kernels written with KernelAbstractions.jl.
2020

2121
!!! note
2222
Right now one needs to install `NFFT.jl` and manually include the wrapper files. In the future we hope to integrate the wrappers in `NFFT3.jl` and `FINUFFT.jl` directly such that it is much more convenient to switch libraries.
2323

24+
It's possible to change between different implementation backends. Each backend has to implement a backend type, which by convention can be accessed via for example `NFFT.backend()`. There are several ways to activate a backend:
25+
```julia
26+
# Actively setting a backend:
27+
AbstractNFFTs.set_active_backend!(NFFT.backend())
28+
# Activating a backend:
29+
NFFT.activate!()
30+
# and creating a new dynamic scope which uses a different backend:
31+
with(nfft_backend => NonuniformFFTs.backend()) do
32+
# Uses NonuniformFFTs as implementation backend
33+
end
34+
# It's also possible to directly pass backends to functions:
35+
nfft(NonuniformFFTs.backend(), ...)
36+
```
2437

2538
## Interface
2639

@@ -30,14 +43,24 @@ Here
3043
* `D` is the size of the input vector
3144
* `R` is the size of the output vector. Usually this will be `R=1` unless a directional NFFT is implemented.
3245

33-
For instance the `CuNFFTPlan` is defined like this
46+
For instance the `NFFTPlan` is defined like this
3447
```julia
35-
mutable struct CuNFFTPlan{T,D} <: AbstractNFFTPlan{T,D,1}
48+
mutable struct NFFTPlan{T,D,R} <: AbstractNFFTPlan{T,D,R}
3649
...
3750
end
3851
```
3952

40-
In addition to the plan, the following functions need to be implemented:
53+
Furthermore, a package needs to implement its own backend type to dispatch on
54+
```julia
55+
struct MyBackend <: AbstractNFFTBackend
56+
```
57+
and it should allow a user to activate the package, which by convention can be done with (unexported) functions:
58+
```julia
59+
activate!() = AbstractNFFTs.set_active_backend!(MyBackend())
60+
backend() = MyBackend()
61+
```
62+
63+
In addition to the plan and backend, the following functions need to be implemented:
4164
```julia
4265
size_out(p)
4366
size_out(p)
@@ -99,20 +122,16 @@ All parameters are put into keyword arguments that have to match as well. We des
99122

100123
Additionally, to the type-specific constructor one can provide the factory
101124
```
102-
plan_nfft(Q::Type, k::Matrix{T}, N::NTuple{D,Int}; kargs...) where {D}
125+
plan_nfft(b::MyBackend, Q::Type, k::Matrix{T}, N::NTuple{D,Int}; kargs...) where {D}
103126
```
104127
where `Q` is the Array type, e.g. `Array`. The reason to require the array type is, that this allows for GPU implementations, which would use for instance `CuArray` here.
105128

106129
The package `AbstractNFFTs` provides a convenient constructor
107130
```
108-
plan_nfft(k::Matrix{T}, N::NTuple{D,Int}; kargs...) where {D}
131+
plan_nfft(b::MyBackend, k::Matrix{T}, N::NTuple{D,Int}; kargs...) where {D}
109132
```
110133
defaulting to the `Array` type.
111134

112-
!!! note
113-
Different packages implementing `plan_nfft` will conflict if the same `Q` is implemented. In case of `NFFT.jl` and `CuNFFT.jl` there is no conflict since the array type is different.
114-
115-
116135
## Derived Interface
117136

118137
Based on the core low-level interface that an `AbstractNFFTPlan` needs to provide, the package

docs/src/index.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## Introduction
66

77
This package provides a Julia implementation of the Non-equidistant Fast Fourier Transform (NFFT).
8-
For a detailed introduction into the NFFT and its application please have a look at the [software paper](https://arxiv.org/pdf/2208.00049.pdf) on the `NFFT.jl`. Further resources are [nfft.org](http://www.nfft.org) and [finufft.readthedocs.io](https://finufft.readthedocs.io). You
8+
For a detailed introduction into the NFFT and its application please have a look at the [software paper](https://arxiv.org/pdf/2208.00049.pdf) on the `NFFT.jl`. Further resources are [nfft.org](http://www.nfft.org) and [finufft.readthedocs.io](https://finufft.readthedocs.io).
99

1010
The NFFT is a fast implementation of the Non-equidistant Discrete Fourier Transform (NDFT) that is
1111
basically a Discrete Fourier Transform (DFT) with non-equidistant sampling nodes in either Fourier or time/space domain.
@@ -25,7 +25,7 @@ add NFFT
2525
```
2626
This will install the packages `NFFT.jl` and all its dependencies. Most importantly it installs the abstract interface package `AbstractNFFTs.jl`, which `NFFT.jl` implements.
2727

28-
Additional NFFT related tools can be obtained by adding the package `NFFTTools.jl`. If you need support for `CUDA` you also need to install the package `CuNFFT.jl`.
28+
Additional NFFT related tools can be obtained by adding the package `NFFTTools.jl`. If you need support for `CUDA` or other GPU backends, you only need to install the respective GPU backend and a GPU compatible plan will be available via a package extension.
2929

3030
In case you want to use an alternative NFFT implementation such as [NFFT3.jl](https://github.com/NFFT/NFFT3.jl) or [FINUFFT.jl](https://github.com/ludvigak/FINUFFT.jl) we provide wrapper types allowing to use them as `AbstractNFFTs` implementations. They can be used like this:
3131

@@ -34,7 +34,9 @@ julia> using AbstractNFFTs
3434
julia> include(joinpath(dirname(pathof(AbstractNFFTs)), "..", "..", "Wrappers", "FINUFFT.jl"))
3535
julia> include(joinpath(dirname(pathof(AbstractNFFTs)), "..", "..", "Wrappers", "NFFT3.jl"))
3636
```
37-
This requires that you first `add` the package you want to use.
37+
This requires that you first `add` the package you want to use.
38+
39+
A related package is [NonuniformFFTs.jl](https://github.com/jipolanco/NonuniformFFTs.jl) which provides a pure Julia implementation using KernelAbstractions.jl. It also features an implementation of the `AbstractNFFTs.jl` interface.
3840

3941
## Guide
4042

0 commit comments

Comments
 (0)