Как новичок в Python и Cupy, я пытаюсь использовать AORUS RTX 2070 GAMING BOX в качестве внешнего графического процессора для обработки данных IQ Complex64 с радиочастотного приемника. Цель состоит в том, чтобы получить более быструю демодуляцию и просмотр, чем то, что я получаю от процессора.
Основные шаги для одной части скрипта:1- Получить массив сложных данных из файла с NumPy2- Разделите этот массив на более мелкие части в рамках подготовки к нескольким БПФ. 3- Выполнить FFT
Я хочу выполнить большинство операций с cupy для ускорения процесса, но кажется, что cupy.split () возвращает тип <class 'list'>
вместо типа <class cupy.core.core.ndarray'>
, что"остаться" в графическом процессоре.
Это нормально, что cupy.split () возвращает тип <class 'list'>
, когда я ожидаю тип <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'>
form 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'