复杂pyopecl.array的scipy.fft.ifftn

时间:2019-09-05 10:37:58

标签: fft pyopencl

我正在尝试使用pyopencl在gpu上添加两个3D复杂数组,然后对其结果执行快速傅里叶逆变换。但是我有一个错误,我不太了解。关于提高代码性能的任何建议都很好。

import pyopencl as cl
import numpy as np
import os
from scipy.fftpack import fftn, ifftn
import pyopencl.array as cl_array
from pyopencl.elementwise import ElementwiseKernel
os.environ['PYOPENCL_COMPILER_OUTPUT'] = '1'

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

Lx = 50
Ly = 50
Lz = 1

M1f = np.ones((2 * Lx - 1, 2 * Ly - 1, 2 * Lz -                               1)).astype(np.float32)
M2f = np.ones((2 * Lx - 1, 2 * Ly - 1, 2 * Lz - 1)).astype(np.float32)

FM1 = fftn(M1f)
FM2 = fftn(M2f)

res_cpu = FM1 + FM2

print(ifftn(res_cpu))

FM1_gpu = cl_array.to_device(queue,np.reshape(FM1, (2*Lx-1)*(2*Ly-  1)*(2*Lz-1)).astype(np.complex64))
FM2_gpu = cl_array.to_device(queue,np.reshape(FM2, (2*Lx-1)*(2*Ly-1)*(2*Lz-1)).astype(np.complex64))

complex_add = ElementwiseKernel(ctx,
        "float *x, "
        "float *y, "
        "float *z",
        "z[i] = x[i] + y[i]",
        "complex_add")

add_gpu = cl_array.empty_like(FM1_gpu)
complex_add(FM1_gpu, FM2_gpu, add_gpu)

res_gpu = np.zeros((2*Lx-1, 2*Ly-1, 2*Lz-1)).astype(np.complex64)
res_gpu = np.reshape(add_gpu, (2*Lx-1, 2*Ly-1, 2*Lz-1))

print(ifftn(res_gpu))

我希望有2个复杂数组的ifft的真实值,它们是在gpu中添加的,但我得到的却是结果:

  

回溯(最近通话最近):文件   “/home/heisenberg/Desktop/НИР/FM/math/GPU/loopsum.py”,第43行,在          打印(ifftn(res_gpu))文件“ /home/heisenberg/.local/lib/python3.7/site-packages/scipy/fftpack/basic.py”,   670行,在ifftn中       返回_raw_fftn_dispatch(x,形状,轴,overwrite_x,-1)文件“ /home/heisenberg/.local/lib/python3.7/site-packages/scipy/fftpack/basic.py”,   _raw_fftn_dispatch中的第628行       tmp = _asfarray(x)文件“ /home/heisenberg/.local/lib/python3.7/site-packages/scipy/fftpack/basic.py”,   _asfarray中的第136行       返回numpy.asarray(x,dtype = x.dtype)文件“ /home/heisenberg/.local/lib/python3.7/site-packages/numpy/core/numeric.py”,   第538行,呈数组形式       返回array(a,dtype,copy = False,order = order)TypeError:必须为实数,而不是Array

     

以退出代码1完成的过程

0 个答案:

没有答案