Skip to content

Commit

Permalink
FFT-MKL: support for 2D FFT
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrnet committed Oct 26, 2016
1 parent 52a857f commit 31106ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/NativeProviders/MKL/fft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ inline MKL_LONG fft_create_1d(DFTI_DESCRIPTOR_HANDLE* handle, const MKL_LONG n,
return status;
}

template<typename Precision>
inline MKL_LONG fft_create_2d(DFTI_DESCRIPTOR_HANDLE* handle, const MKL_LONG m, const MKL_LONG n, const Precision forward_scale, const Precision backward_scale, const DFTI_CONFIG_VALUE precision, const DFTI_CONFIG_VALUE domain)
{
MKL_LONG sizes[2];
sizes[0] = m;
sizes[1] = n;
MKL_LONG status = DftiCreateDescriptor(handle, precision, domain, 2, sizes);
DFTI_DESCRIPTOR_HANDLE descriptor = *handle;
if (0 == status) status = DftiSetValue(descriptor, DFTI_FORWARD_SCALE, forward_scale);
if (0 == status) status = DftiSetValue(descriptor, DFTI_BACKWARD_SCALE, backward_scale);
if (0 == status) status = DftiCommitDescriptor(descriptor);
return status;
}

template<typename Data, typename FFT>
inline MKL_LONG fft_compute(const DFTI_DESCRIPTOR_HANDLE handle, Data x[], FFT fft)
{
Expand All @@ -45,6 +59,16 @@ extern "C" {
return fft_create_1d(handle, n, forward_scale, backward_scale, DFTI_SINGLE, DFTI_COMPLEX);
}

DLLEXPORT MKL_LONG z_fft_create_2d(DFTI_DESCRIPTOR_HANDLE* handle, const MKL_LONG m, const MKL_LONG n, const double forward_scale, const double backward_scale)
{
return fft_create_2d(handle, m, n, forward_scale, backward_scale, DFTI_DOUBLE, DFTI_COMPLEX);
}

DLLEXPORT MKL_LONG c_fft_create_2d(DFTI_DESCRIPTOR_HANDLE* handle, const MKL_LONG m, const MKL_LONG n, const float forward_scale, const float backward_scale)
{
return fft_create_2d(handle, m, n, forward_scale, backward_scale, DFTI_SINGLE, DFTI_COMPLEX);
}

DLLEXPORT MKL_LONG z_fft_forward(const DFTI_DESCRIPTOR_HANDLE handle, MKL_Complex16 x[])
{
return fft_compute(handle, x, DftiComputeForward);
Expand Down
6 changes: 6 additions & 0 deletions src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ internal static class SafeNativeMethods
[DllImport(_DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int c_fft_create([Out] out IntPtr handle, int n, float forward_scale, float backward_scale);

[DllImport(_DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int z_fft_create_2d([Out] out IntPtr handle, int m, int n, double forward_scale, double backward_scale);

[DllImport(_DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int c_fft_create_2d([Out] out IntPtr handle, int m, int n, float forward_scale, float backward_scale);

[DllImport(_DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int z_fft_forward([In] IntPtr handle, [In, Out] Complex[] x);

Expand Down

0 comments on commit 31106ef

Please sign in to comment.