pyfft

FFT library for PyCuda and PyOpenCL
Download

pyfft Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Publisher Name:
  • Bogdan Opanchuk
  • Publisher web site:
  • http://github.com/Manticore

pyfft Tags


pyfft Description

FFT library for PyCuda and PyOpenCL pyfft is a Python module that contains implementation of batched FFT, ported from Apple's OpenCL implementation. OpenCL's ideology of constructing kernel code on the fly maps perfectly on PyCuda/PyOpenCL, and variety of Python's templating engines makes code generation simpler. I used mako templating engine, simply because of the personal preference. The code can be easily changed to use any other engine.Warning: "Cuda" part of pyfft requires current development version of PyCuda (0.94).Quick StartThe usage is quite simple. First, import numpy and plan creation interface from pyfft (let us use cuda in this example): >>> from pyfft.cuda import Plan >>> import numpySince we are using Cuda, it must be initialized before any Cuda functions are called (by default, the plan will use existing context, but there are other possibilities; see reference entry for Plan for further information). In addition, we will need gpuarray module to pass data to and from GPU: >>> from pycuda.tools import make_default_context >>> import pycuda.gpuarray as gpuarray >>> import pycuda.driver as cuda >>> cuda.init() >>> context = make_default_context()Then the plan must be created. The creation is not very fast, mainly because of the compilation speed. But, fortunately, PyCuda and PyOpenCL cache compiled sources, so if you use the same plan for each run of your program, it will be created pretty fast. >>> plan = Plan((16, 16))Now, let's prepare simple test array and try to execute plan over it: >>> data = numpy.ones((16, 16), dtype=numpy.complex64) >>> gpu_data = gpuarray.to_gpu(data) >>> plan.execute(gpu_data) >>> result = gpu_data.get() >>> print result # doctest: +ELLIPSIS ... ]As expected, we got array with the first non-zero element, equal to array size. Let's now perform the inverse transform: >>> plan.execute(gpu_data, inverse=True) >>> result = gpu_data.get()Since data is non-integer, we cannot simply compare it. We will just calculate error instead. >>> error = numpy.abs(numpy.sum(numpy.abs(data) - numpy.abs(result)) / data.size) >>> error < 1e-6 TrueThat's good enough for single precision numbers.Last step is releasing Cuda context: >>> context.pop() Requirements: · Python


pyfft Related Software