Class Fft
- Namespace
- NVMathNet.Fft
- Assembly
- NVMath.Net.dll
Stateful cuFFT wrapper. Mirrors the design of nvmath.fft.FFT:
- Construct with an input descriptor.
- Call NVMathNet.Fft.Fft.PlanAsync(System.Threading.CancellationToken) to build the cuFFT plan.
- Call NVMathNet.Fft.Fft.ExecuteAsync(NVMathNet.Fft.FftDirection,System.Threading.CancellationToken) (possibly multiple times with NVMathNet.Fft.Fft.ResetOperand(System.IntPtr,System.IntPtr)).
- Dispose (or use
await using) to free all CUDA resources.
public sealed class Fft : IAsyncDisposable, IDisposableInheritance
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
shapelong[]-
Full shape of the input tensor (all dimensions, including batch).
axesint[]?-
The axes over which to perform the FFT.
nullmeans 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. optionsFftOptions?-
FFT options;
nulluses defaults. streamCudaStream?-
Optional external stream to use. If
null, a private stream is created. doublePrecisionbool-
truefor 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
directionFftDirection
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
directionFftDirectionctCancellationToken
Returns
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
inputDeviceBuffer<Complex>-
Device buffer of complex64 (interleaved float pairs) elements.
shapelong[]-
Full tensor shape.
axesint[]?-
FFT axes;
null= all. streamCudaStream?-
Optional external stream.
optionsFftOptions?-
Optional options.
ctCancellationToken-
Cancellation token.
Returns
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
inputDeviceBuffer<Complex>shapelong[]axesint[]?streamCudaStream?optionsFftOptions?ctCancellationToken
Returns
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
inputDeviceBuffer<Complex>-
Device buffer of System.Numerics.Complex half-spectrum elements.
outputShapelong[]-
Full shape of the desired real output tensor (all dimensions, including batch), row-major. The last transform-axis size
ndetermines the half-spectrum lengthn/2+1thatinputmust hold. axesint[]?-
FFT axes;
null= all axes. streamCudaStream?-
Optional external stream.
optionsFftOptions?-
Optional options; NVMathNet.Fft.FftOptions.FftType is overridden to NVMathNet.Fft.FftType.C2R.
ctCancellationToken-
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
inputDeviceBuffer<float>-
Device buffer of interleaved single-precision complex half-spectrum values.
outputShapelong[]-
Full shape of the desired real output tensor, row-major.
axesint[]?-
FFT axes;
null= all axes. streamCudaStream?-
Optional external stream.
optionsFftOptions?-
Optional options; NVMathNet.Fft.FftOptions.FftType is overridden to NVMathNet.Fft.FftType.C2R.
ctCancellationToken-
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
Returns
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
inputDeviceBuffer<double>-
Device buffer of System.Double real elements.
shapelong[]-
Full tensor shape of the real input (all dimensions, including batch), row-major.
axesint[]?-
FFT axes;
null= all axes. streamCudaStream?-
Optional external stream.
optionsFftOptions?-
Optional options; NVMathNet.Fft.FftOptions.FftType is overridden to NVMathNet.Fft.FftType.R2C.
ctCancellationToken-
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
inputDeviceBuffer<float>-
Device buffer of System.Single real elements.
shapelong[]-
Full tensor shape of the real input (all dimensions, including batch), row-major.
axesint[]?-
FFT axes;
null= all axes. streamCudaStream?-
Optional external stream.
optionsFftOptions?-
Optional options; NVMathNet.Fft.FftOptions.FftType is overridden to NVMathNet.Fft.FftType.R2C.
ctCancellationToken-
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
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)