GPUs excel at doing the exact same thing to a lot of data items (like 512 or more) at once. Your 1-element input just doesn’t match what they’re good at. If you put in a large vector for which you each compute that, it will give you a speedup.
Some additional speed gain could be achieved by using the PyTorch fuser – it automatically is called when you add @torch.jit.script to your function (and add a type annotation n : int for n).
Best regards
Thomas