def test_convolve(num_samps, num_taps, mode='same'): cpu_sig = np.random.rand(num_samps) cpu_win = signal.windows.hann(num_taps) gpu_sig = cp.asarray(cpu_sig) gpu_win = cusignal.windows.hann(num_taps) cpu_conv = signal.convolve(cpu_sig, cpu_win, mode=mode) gpu_conv = cp.asnumpy(cusignal.convolve(gpu_sig, gpu_win, mode=mode)) assert array_equal(cpu_conv, gpu_conv)
def conv(h,sample,device): if device =='cuda': from cusignal import convolve from cupy import array,vstack if device =='cpu': from numpy import convolve,vstack from numpy import array,atleast_2d res = [] for row_cnt,row in enumerate(sample): res.append(convolve(h[0],row)) if len(res) == 2: return vstack(res) else: return atleast_2d(array(res))
def gpu_version(self, sig, win, mode, method): with cp.cuda.Stream.null: out = cusignal.convolve(sig, win, mode=mode, method=method) cp.cuda.Stream.null.synchronize() return out