[Python] Lowpass filter is slower on GPU than CPU in PyTorch

Discussão em 'Python' iniciado por Stack, Fevereiro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have been trying out some of the Torchaudio functionalities and I can't seem to figure out why lowpass_biquad is running slower on the GPU than on the CPU. And this is true for other effects like, phaser, flanger, overdrive, which are even slower. Here I am pasting the example for the lowpass filter, but I applay the other effectes the same way to obtain the measurements. The example code is taken from this issue, which seems to have been resolved, but it's still slower on the GPU.

    import time
    import torch
    from torchaudio.functional import lowpass_biquad

    gpu_device = torch.device('cuda:0')
    cpu_device = torch.device('cpu')

    seconds = 1000
    sample_rate = 44100
    cutoff_freq = 1000.
    Q = .7

    # Run in cpu
    x = torch.rand(sample_rate * seconds, device=cpu_device)
    begin = time.time()
    y = lowpass_biquad(x, sample_rate, cutoff_freq, Q)

    print(f'Run in cpu: {time.time() - begin}')

    # Run in gpu
    x = torch.rand(sample_rate * seconds, device=gpu_device)
    begin = time.time()
    y = lowpass_biquad(x, sample_rate, cutoff_freq, Q)
    torch.cuda.synchronize()
    print(f'Run in gpu: {time.time() - begin}')


    Run in cpu: 1.6084413528442383
    Run in gpu: 6.183292865753174


    For example for the overdrive effect, the GPU is more than 1000x slower. It would be understandable, if the Torchaudio doesn't have the GPU implementation of the said effects, but their documentation seems to suggest they do. Am I doing something wrong?

    Continue reading...

Compartilhe esta Página