lebedov / scikit-cuda

Python interface to GPU-powered libraries
http://scikit-cuda.readthedocs.org/
Other
986 stars 179 forks source link

Cleaned example #192

Closed elrama- closed 7 years ago

elrama- commented 7 years ago

Hello everybody, I started trying to perform FFTs in my GPU, so I worked out today the example with scikit-cuda

There are minor updates on http://scikit-cuda.readthedocs.io/en/latest/generated/skcuda.fft.fft.html

import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import numpy as np
from skcuda.fft import fft, Plan
N = 128
x = np.asarray(np.random.rand(N), np.float32)
xf = np.fft.fft(x)
x_gpu = gpuarray.to_gpu(x)
xf_gpu = gpuarray.empty((N//2)+1, np.complex64)
plan = Plan(x.shape, np.float32, np.complex64)
fft(x_gpu, xf_gpu, plan)
np.allclose(xf[0:N/2+1], xf_gpu.get(), atol=1e-6)

Also, I wanted to take the chance to say: Congratulations, INSTALLING scikit-cuda was JUST cloning+setup.py (of course with CUDA already working fine, but that is a pre-requisite). Although this should be obvious, not all package manage to do a clean easy installation nowadays, even more in young technologies such as GPU

lebedov commented 7 years ago

The various doctring examples in skcuda don't explicitly import dependencies from within their respective modules because they were originally written as doctests (which have access to other definitions within the source file). Given that most users seem to be cutting/pasting them and given that there are already separately defined unit tests, explicitly listing necessary skcuda imports in the examples seems like a good idea.

Glad that installing skcuda from source proved problem-free!