def __init__(self, shape, in_dtype, out_dtype, batch=1, stream=None, mode=0x01): if np.isscalar(shape): self.shape = (shape, ) else: self.shape = shape self.in_dtype = in_dtype self.out_dtype = out_dtype if batch <= 0: raise ValueError('batch size must be greater than 0') self.batch = batch # Determine type of transformation: if in_dtype == np.float32 and out_dtype == np.complex64: self.fft_type = cufft.CUFFT_R2C self.fft_func = cufft.cufftExecR2C elif in_dtype == np.complex64 and out_dtype == np.float32: self.fft_type = cufft.CUFFT_C2R self.fft_func = cufft.cufftExecC2R elif in_dtype == np.complex64 and out_dtype == np.complex64: self.fft_type = cufft.CUFFT_C2C self.fft_func = cufft.cufftExecC2C elif in_dtype == np.float64 and out_dtype == np.complex128: self.fft_type = cufft.CUFFT_D2Z self.fft_func = cufft.cufftExecD2Z elif in_dtype == np.complex128 and out_dtype == np.float64: self.fft_type = cufft.CUFFT_Z2D self.fft_func = cufft.cufftExecZ2D elif in_dtype == np.complex128 and out_dtype == np.complex128: self.fft_type = cufft.CUFFT_Z2Z self.fft_func = cufft.cufftExecZ2Z else: raise ValueError('unsupported input/output type combination') # Check for double precision support: capability = misc.get_compute_capability(misc.get_current_device()) if capability < 1.3 and \ (misc.isdoubletype(in_dtype) or misc.isdoubletype(out_dtype)): raise RuntimeError('double precision requires compute capability ' '>= 1.3 (you have %g)' % capability) # Set up plan: if len(self.shape) > 0: n = np.asarray(self.shape, np.int32) self.handle = cufft.cufftPlanMany(len(self.shape), n.ctypes.data, None, 1, 0, None, 1, 0, self.fft_type, self.batch) else: raise ValueError('invalid transform size') # Set FFTW compatibility mode: cufft.cufftSetCompatibilityMode(self.handle, mode) # Associate stream with plan: if stream != None: cufft.cufftSetStream(self.handle, stream.handle)
def __init__(self, shape, in_dtype, out_dtype, batch=1, stream=None, mode=0x01): if np.isscalar(shape): self.shape = (shape, ) else: self.shape = shape self.in_dtype = in_dtype self.out_dtype = out_dtype if batch <= 0: raise ValueError('batch size must be greater than 0') self.batch = batch # Determine type of transformation: if in_dtype == np.float32 and out_dtype == np.complex64: self.fft_type = cufft.CUFFT_R2C self.fft_func = cufft.cufftExecR2C elif in_dtype == np.complex64 and out_dtype == np.float32: self.fft_type = cufft.CUFFT_C2R self.fft_func = cufft.cufftExecC2R elif in_dtype == np.complex64 and out_dtype == np.complex64: self.fft_type = cufft.CUFFT_C2C self.fft_func = cufft.cufftExecC2C elif in_dtype == np.float64 and out_dtype == np.complex128: self.fft_type = cufft.CUFFT_D2Z self.fft_func = cufft.cufftExecD2Z elif in_dtype == np.complex128 and out_dtype == np.float64: self.fft_type = cufft.CUFFT_Z2D self.fft_func = cufft.cufftExecZ2D elif in_dtype == np.complex128 and out_dtype == np.complex128: self.fft_type = cufft.CUFFT_Z2Z self.fft_func = cufft.cufftExecZ2Z else: raise ValueError('unsupported input/output type combination') # Set up plan: if len(self.shape) > 0: n = np.asarray(self.shape, np.int32) self.handle = cufft.cufftPlanMany(len(self.shape), n.ctypes.data, None, 1, 0, None, 1, 0, self.fft_type, self.batch) else: raise ValueError('invalid transform size') # Set FFTW compatibility mode: cufft.cufftSetCompatibilityMode(self.handle, mode) # Associate stream with plan: if stream != None: cufft.cufftSetStream(self.handle, stream.handle)