Table of Contents

Class Fft

Namespace
NVMathNet.Fft
Assembly
NVMath.Net.dll

Stateful cuFFT wrapper. Mirrors the design of nvmath.fft.FFT:

  1. Construct with an input descriptor.
  2. Call NVMathNet.Fft.Fft.PlanAsync(System.Threading.CancellationToken) to build the cuFFT plan.
  3. Call NVMathNet.Fft.Fft.ExecuteAsync(NVMathNet.Fft.FftDirection,System.Threading.CancellationToken) (possibly multiple times with NVMathNet.Fft.Fft.ResetOperand(System.IntPtr,System.IntPtr)).
  4. Dispose (or use await using) to free all CUDA resources.
public sealed class Fft : IAsyncDisposable, IDisposable

Inheritance

Fft

Implements

Inherited Members

Constructors

Fft(long[], int[]?, FftOptions?, CudaStream?, bool)

Creates an FFT descriptor.

public Fft(long[] shape, int[]? axes = null, FftOptions? options = null, CudaStream? stream = null, bool doublePrecision = false)

Parameters

shape long[]

Full shape of the input tensor (all dimensions, including batch).

axes int[]?

The axes over which to perform the FFT. null means all axes. Negative values count from the end. Must be ascending, contiguous and include either the first or last dimension. Leading axes are supported through strided layouts. For R2C the shape is the real input; for C2R it is the real output.

options FftOptions?

FFT options; null uses defaults.

stream CudaStream?

Optional external stream to use. If null, a private stream is created.

doublePrecision bool

true for double / complex128 precision; false (default) for float / complex64.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

Execute(FftDirection)

Synchronously executes the FFT on device memory and returns when done. Prefer NVMathNet.Fft.Fft.ExecuteAsync(NVMathNet.Fft.FftDirection,System.Threading.CancellationToken) in async contexts.

public void Execute(FftDirection direction = FftDirection.Forward)

Parameters

direction FftDirection

ExecuteAsync(FftDirection, CancellationToken)

Executes the FFT on device pointers previously set with NVMathNet.Fft.Fft.ResetOperand(System.IntPtr,System.IntPtr). Returns a System.Threading.Tasks.Task that completes when the GPU kernel finishes.

public Task ExecuteAsync(FftDirection direction = FftDirection.Forward, CancellationToken ct = default)

Parameters

direction FftDirection
ct CancellationToken

Returns

Task

FftAsync(DeviceBuffer<Complex>, long[], int[]?, CudaStream?, FftOptions?, CancellationToken)

Performs a forward complex-to-complex FFT. Allocates and frees plan resources automatically.

public static Task<DeviceBuffer<Complex>> FftAsync(DeviceBuffer<Complex> input, long[] shape, int[]? axes = null, CudaStream? stream = null, FftOptions? options = null, CancellationToken ct = default)

Parameters

input DeviceBuffer<Complex>

Device buffer of complex64 (interleaved float pairs) elements.

shape long[]

Full tensor shape.

axes int[]?

FFT axes; null = all.

stream CudaStream?

Optional external stream.

options FftOptions?

Optional options.

ct CancellationToken

Cancellation token.

Returns

Task<DeviceBuffer<Complex>>

IFftAsync(DeviceBuffer<Complex>, long[], int[]?, CudaStream?, FftOptions?, CancellationToken)

Performs an inverse complex-to-complex FFT.

public static Task<DeviceBuffer<Complex>> IFftAsync(DeviceBuffer<Complex> input, long[] shape, int[]? axes = null, CudaStream? stream = null, FftOptions? options = null, CancellationToken ct = default)

Parameters

input DeviceBuffer<Complex>
shape long[]
axes int[]?
stream CudaStream?
options FftOptions?
ct CancellationToken

Returns

Task<DeviceBuffer<Complex>>

IRFftAsync(DeviceBuffer<Complex>, long[], int[]?, CudaStream?, FftOptions?, CancellationToken)

Performs a complex-to-real (inverse half-spectrum) FFT in double precision. The output contains the reconstructed real signal. The result is not scaled unless NVMathNet.Fft.FftOptions.Normalization says so.

public static Task<DeviceBuffer<double>> IRFftAsync(DeviceBuffer<Complex> input, long[] outputShape, int[]? axes = null, CudaStream? stream = null, FftOptions? options = null, CancellationToken ct = default)

Parameters

input DeviceBuffer<Complex>

Device buffer of System.Numerics.Complex half-spectrum elements.

outputShape long[]

Full shape of the desired real output tensor (all dimensions, including batch), row-major. The last transform-axis size n determines the half-spectrum length n/2+1 that input must hold.

axes int[]?

FFT axes; null = all axes.

stream CudaStream?

Optional external stream.

options FftOptions?

Optional options; NVMathNet.Fft.FftOptions.FftType is overridden to NVMathNet.Fft.FftType.C2R.

ct CancellationToken

Cancellation token.

Returns

Task<DeviceBuffer<double>>

Device buffer of System.Double reconstructed real elements.

IRFftAsync(DeviceBuffer<float>, long[], int[]?, CudaStream?, FftOptions?, CancellationToken)

Performs a complex-to-real (inverse half-spectrum) FFT in single precision. The half-spectrum is supplied as interleaved (re, im) floats (see NVMathNet.Fft.Fft.RFftAsync(NVMathNet.DeviceBuffer{System.Single},System.Int64[],System.Int32[],NVMathNet.CudaStream,NVMathNet.Fft.FftOptions,System.Threading.CancellationToken)).

public static Task<DeviceBuffer<float>> IRFftAsync(DeviceBuffer<float> input, long[] outputShape, int[]? axes = null, CudaStream? stream = null, FftOptions? options = null, CancellationToken ct = default)

Parameters

input DeviceBuffer<float>

Device buffer of interleaved single-precision complex half-spectrum values.

outputShape long[]

Full shape of the desired real output tensor, row-major.

axes int[]?

FFT axes; null = all axes.

stream CudaStream?

Optional external stream.

options FftOptions?

Optional options; NVMathNet.Fft.FftOptions.FftType is overridden to NVMathNet.Fft.FftType.C2R.

ct CancellationToken

Cancellation token.

Returns

Task<DeviceBuffer<float>>

Device buffer of System.Single reconstructed real elements.

Plan()

Synchronously builds the cuFFT plan.

public void Plan()

PlanAsync(CancellationToken)

Builds the cuFFT plan on the current stream.

public Task PlanAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task

RFftAsync(DeviceBuffer<double>, long[], int[]?, CudaStream?, FftOptions?, CancellationToken)

Performs a real-to-complex (forward half-spectrum) FFT in double precision. The output has n/2+1 complex elements along the last transform axis.

public static Task<DeviceBuffer<Complex>> RFftAsync(DeviceBuffer<double> input, long[] shape, int[]? axes = null, CudaStream? stream = null, FftOptions? options = null, CancellationToken ct = default)

Parameters

input DeviceBuffer<double>

Device buffer of System.Double real elements.

shape long[]

Full tensor shape of the real input (all dimensions, including batch), row-major.

axes int[]?

FFT axes; null = all axes.

stream CudaStream?

Optional external stream.

options FftOptions?

Optional options; NVMathNet.Fft.FftOptions.FftType is overridden to NVMathNet.Fft.FftType.R2C.

ct CancellationToken

Cancellation token.

Returns

Task<DeviceBuffer<Complex>>

Device buffer of System.Numerics.Complex elements (half-spectrum).

RFftAsync(DeviceBuffer<float>, long[], int[]?, CudaStream?, FftOptions?, CancellationToken)

Performs a real-to-complex (forward half-spectrum) FFT in single precision. .NET has no single-precision complex type, so the half-spectrum is returned as interleaved (re, im) floats: element k of the spectrum is output[2k] + i·output[2k+1], and the buffer holds 2 · (number of complex elements) floats.

public static Task<DeviceBuffer<float>> RFftAsync(DeviceBuffer<float> input, long[] shape, int[]? axes = null, CudaStream? stream = null, FftOptions? options = null, CancellationToken ct = default)

Parameters

input DeviceBuffer<float>

Device buffer of System.Single real elements.

shape long[]

Full tensor shape of the real input (all dimensions, including batch), row-major.

axes int[]?

FFT axes; null = all axes.

stream CudaStream?

Optional external stream.

options FftOptions?

Optional options; NVMathNet.Fft.FftOptions.FftType is overridden to NVMathNet.Fft.FftType.R2C.

ct CancellationToken

Cancellation token.

Returns

Task<DeviceBuffer<float>>

Device buffer of interleaved single-precision complex values.

ResetOperand(nint, nint)

Sets the device pointers for the current execution. Both inputPtr and outputPtr must remain valid until NVMathNet.Fft.Fft.SynchronizeAsync(System.Threading.CancellationToken) completes.

public void ResetOperand(nint inputPtr, nint outputPtr)

Parameters

inputPtr nint
outputPtr nint

SynchronizeAsync(CancellationToken)

Returns a System.Threading.Tasks.Task that completes once all work on the internal stream has finished.

public Task SynchronizeAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task