numba / numba/pyculib

Cannot get correct FFT results

Open
#16 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
99
Forks
11
PR merge metrics
No merged PRs in 30d

Description

Hello,

I've been trying to batched FFT for a while and I can't get the correct result (but It works fine with skcuda). Could you tell me what is wrong with the way I am using pyculib. Or equivalently how to copy from pyculib to/from skcuda.

Here is a code example that does the same thing with numba, numpy and skcuda

```python
import numpy as np
from pyculib import fft
from scipy.io import loadmat
from scipy.fftpack import fft as cfft
import numba
from numba import cuda
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import numpy as np

import skcuda.fft as cu_fft

def test_skcuda():
print('Testing fft/ifft..')
x = INSERT_YOUR_OWN_SIGNAL

batch_size, N = x.shape

#numpy
xf = np.fft.fft(x, axis=1)
y = np.real(np.fft.ifft(xf))

#skcuda
x_gpu = gpuarray.to_gpu(x)
xf_gpu = gpuarray.empty((batch_size, N//2+1), np.complex64)
plan_forward = cu_fft.Plan(N, np.float32, np.complex64, batch_size)
cu_fft.fft(x_gpu, xf_gpu, plan_forward)

#numba
out = np.empty((batch_size, N//2 + 1), dtype=np.complex64)
gpu_temp = numba.cuda.to_device(out)
plan = fft.FFTPlan((N,), np.float32, np.complex64, batch_size)
fft.fft(x, gpu_temp)
result = gpu_temp.copy_to_host()

print(np.allclose(xf[:, :N//2+1], xf_gpu.get(), atol=1e-4)) #True
print(np.allclose(xf[:, :N//2+1], result, atol=1e-4)) #False

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Run the supplied comparison with a concrete signal and inspect the pyculib.fft.FFTPlan call alongside test_skcuda(). Compare the NumPy, skcuda, and pyculib outputs and determine why the batched result differs. Done means the discrepancy is explained and the example produces the expected comparison.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
hpc
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.