def test_stft_complex(self, rand_complex_data_gen, num_samps, fs, nperseg): cpu_sig, gpu_sig = rand_complex_data_gen(num_samps) _, _, cpu_stft = signal.stft(cpu_sig, fs, nperseg=nperseg) _, _, gpu_stft = cusignal.stft(gpu_sig, fs, nperseg=nperseg) gpu_stft = cp.asnumpy(gpu_stft) assert array_equal(cpu_stft, gpu_stft)
def test_stft_complex(num_samps, fs, nperseg): cpu_sig = np.random.rand(num_samps) + 1j * np.random.rand(num_samps) gpu_sig = cp.asarray(cpu_sig) cf, ct, cpu_stft = signal.stft(cpu_sig, fs, nperseg=nperseg) gf, gt, gpu_stft = cusignal.stft(gpu_sig, fs, nperseg=nperseg) gpu_stft = cp.asnumpy(gpu_stft) assert array_equal(cpu_stft, gpu_stft)
def test_istft_gpu(self, rand_data_gen, gpubenchmark, dtype, num_samps, fs, nperseg): cpu_sig, gpu_sig = rand_data_gen(num_samps, 1, dtype) _, _, cpu_sig = signal.stft(cpu_sig, fs, nperseg=nperseg) _, _, gpu_sig = cusignal.stft(gpu_sig, fs, nperseg=nperseg) output = gpubenchmark(self.gpu_version, gpu_sig, fs, nperseg) key = self.cpu_version(cpu_sig, fs, nperseg) array_equal(output, key)
def gpu_version(self, sig, fs, nperseg): with cp.cuda.Stream.null: out = cusignal.stft(sig, fs, nperseg=nperseg) cp.cuda.Stream.null.synchronize() return out