0

I am writing code which can compare between numpy.fft.fft2 and pycuda but the results are not matching. Additionally pycuda results are ambiguous every time.

data file : https://nofile.io/f/bjGRQGRVSCG/gauss.npy

from pyfft.cuda import Plan
import numpy as np
from pycuda.tools import make_default_context
import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda
import time
import matplotlib.pyplot as plt

cuda.init()
context = make_default_context()

data = np.load('gauss.npy')
data_complex = data.astype(np.complex64)


start_time = time.time()
plan = Plan((32,32))

gpu_data = gpuarray.to_gpu(data_complex)
plan.execute(gpu_data)
result = gpu_data.get()

print("--- %s seconds (FFT calculation pycuda)---" % (time.time() - start_time))

start_time_3 = time.time()

result_np = np.fft.fft2(data)
#print(result_np)

print("--- %s seconds (FFT calculation numpy.fft.fft)---" % (time.time() - start_time))

context.pop()

#plt.plot(result)
#plt.plot(result_np)

I'm starting to wonder whether we can even perform 2D FFT with pycuda?

Kasia Gogolek
  • 3,374
  • 4
  • 33
  • 50

1 Answers1

1

pyfft.cuda is almost assuredly using cufft, which does not compute FFTs in the same way as numpy's fft (IIRC, even scipy.fft and np.fft can produce different results). You should read the documentation for each library in order to understand the differences. You can definitely perform 2D FFTs with pycuda

Michael
  • 2,344
  • 6
  • 12