Trying to run that code gives me an error about the use_cuda flag (with version 0.3.1). For example:
import torch
from torch.autograd import Variable
x = Variable(torch.randn(5,5), requires_grad=True).cuda()
with torch.autograd.profiler.profile() as prof:
    y = x**2
    with torch.autograd.profiler.emit_nvtx():
        y = x**2
print(prof)

Gives:
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-18-c54fc33dff6e> in <module>()
      1 with torch.autograd.profiler.profile() as prof:
      2     y = x**2
----> 3     with torch.autograd.profiler.emit_nvtx():
      4         y = x**2
      5

~/.pyenv/versions/3.6.1/envs/phdnets2/lib/python3.6/site-packages/torch/autograd/profiler.py in __enter__(self)
    213         self.entered = True
    214         torch.cuda.synchronize()
--> 215         torch.autograd._enable_profiler(True)
    216         return self
    217