作为 python 和 cupy 的初学者,我正在尝试使用 AORUS RTX 2070 GAMING BOX 作为外部 GPU 来处理来自 RF 接收器的 complex64 IQ 数据。目标是获得比我从 CPU 获得的更快的解调和视图。
脚本的一部分的一般步骤是:
1- 使用 numpy 从文件中获取一组复杂数据
2- 将该数组拆分为更小的部分,为多个 FFT 做准备。
3- 执行 FFT
我想用 cupy 做大部分操作来加速这个过程,但似乎 cupy.split() 返回一个 type<class 'list'>
而不是 type <class cupy.core.core.ndarray'>
,它会“留在”GPU中。
<class 'list'>
当我期望一个类型时, cupy.split() 返回一个类型是否正常<class 'cupy.core.core.ndarray'>
?
似乎 cupy.split() 使用了 cupy.array_split(),它使用了 cupy.core.array_split()。
import numpy
import cupy # Version cuda91-6.5.0
def numpy_split_version():
filepath = 'C:\\Users\\Public\\Documents\\BladeRf2_20191108_145919_97900000_20000000_30.float32'
grab_length = 500000000 #Quantity of complex sample to import
with open(filepath, 'rb') as fr:
data = numpy.fromfile( fr, dtype=(numpy.complex64), count=grab_length ) #import samples in numpy array
len_count = len(data) #Get the length of the numpy array
#Validate end of file or format smaller file data. Test version
if len_count != grab_length:
if int(len_count/100) == 0:
pass
else: #Format data for equal split
x = len_count%100
if x != 0:
data = data[:-x]
#Calculate split value to get parts of 100 samples
split_count = int(len(data)/100)
#split the numpy array in arrays of size of 100 samples. Numpy version on cpu
cpu_data = numpy.split(data, split_count)
#Create an array inside the GPU from numpy array
gpu_data = cupy.array(cpu_data)
print( "gpu_data type after numpy split:", type(gpu_data) ) # type( gpu_data ) = <class 'cupy.core.core.ndarray'>
#Perfom fft on each array of size 100 inside the GPU
gpu_fft = cupy.fft.fft(gpu_data, axis=1)
gpu_fft = cupy.fft.fftshift(gpu_fft)
def cupy_split_version():
filepath = 'C:\\Users\\Public\\Documents\\BladeRf2_20191108_145919_97900000_20000000_30.float32'
grab_length = 800000000 #Quantity of complex sample to import
with open(filepath, 'rb') as fr:
data = numpy.fromfile( fr, dtype=(numpy.complex64), count=grab_length ) #import samples in numpy array
len_count = len(data) #Get the length of the numpy array
#Validate end of file or format smaller file data. Test version
if len_count != grab_length:
if int(len_count/100) == 0:
pass
else: #Format data for equal split
x = len_count%100
if x != 0:
data = data[:-x]
#Calculate split value to get parts of 100 samples
split_count = int(len(data)/100)
#Create an array inside the GPU from numpy array
gpu_data = cupy.array(data)
print( "gpu_data type after cupy array:", type(gpu_data) ) # type( gpu_data ) = <class 'cupy.core.core.ndarray'>
#Split the cupy array in arrays of size of 100 samples. Cupy version on gpu
gpu_data = cupy.split(gpu_data, split_count)
print( "gpu_data type after cupy split:", type(gpu_data) ) # type( gpu_data ) = <class 'list'> ??? should be <class 'cupy.core.core.ndarray'>
#Perfom fft on each array of size 100 inside the GPU. not possible because of <class 'list'>
gpu_fft = cupy.fft.fft(gpu_data, axis=1)
gpu_fft = cupy.fft.fftshift(gpu_fft)
if __name__ == '__main__':
numpy_split_version()
cupy_split_version()
我希望得到类型<class 'cupy.core.core.ndarray'>
形式 cupy.split(),但得到了类型<class 'list'>.
gpu_data type after numpy split: <class 'cupy.core.core.ndarray'>
gpu_data type after cupy array: <class 'cupy.core.core.ndarray'>
gpu_data type after cupy split: <class 'list'>
Traceback (most recent call last):
File "C:/Users/Kaven/Desktop/cupy_split_web_help.py", line 70, in <module>
cupy_split_version()
File "C:/Users/Kaven/Desktop/cupy_split_web_help.py", line 64, in cupy_split_version
gpu_fft = cupy.fft.fft(gpu_data, axis=1)
File "C:\Users\Kaven\AppData\Local\Programs\Python\Python37\lib\site-packages\cupy\fft\fft.py", line 468, in fft
return _fft(a, (n,), (axis,), norm, cupy.cuda.cufft.CUFFT_FORWARD)
File "C:\Users\Kaven\AppData\Local\Programs\Python\Python37\lib\site-packages\cupy\fft\fft.py", line 145, in _fft
a = _convert_dtype(a, value_type)
File "C:\Users\Kaven\AppData\Local\Programs\Python\Python37\lib\site-packages\cupy\fft\fft.py", line 30, in _convert_dtype
out_dtype = _output_dtype(a, value_type)
File "C:\Users\Kaven\AppData\Local\Programs\Python\Python37\lib\site-packages\cupy\fft\fft.py", line 15, in _output_dtype
if a.dtype in [np.float16, np.float32]:
AttributeError: 'list' object has no attribute 'dtype'