title: CUDA Illegal Memory Access error when using torch.cat
body: <p>I was playing around with pytorch concatenate and wanted to see if I could use an output tensor that had a different device to the input tensors, here is the code:</p>
  <pre><code>import torch
  a = torch.ones(4)
  b = torch.ones(4) 
  c = torch.zeros(8).cuda()
  print(c)
  ab = torch.cat([a,b], out=c)
  print(c)
  </code></pre>
  <p>I am running this inside a jupyter notebook. pytorch version: 1.7.1</p>
  <p>I get the following error:</p>
  <pre><code>...
  \Anaconda3\envs\...\lib\site-packages\torch\_tensor_str.py in __init__(self, tensor)
       87 
       88         else:
  ---&gt; 89             nonzero_finite_vals = torch.masked_select(tensor_view, torch.isfinite(tensor_view) &amp; tensor_view.ne(0))
       90 
       91             if nonzero_finite_vals.numel() == 0:
  
  RuntimeError: CUDA error: an illegal memory access was encountered
  </code></pre>
  <p>It happens if you try to access the tensors <code>c</code> (in this case with a <code>print</code>).</p>
  <p>I couldnt find anything in the  <a href="https://pytorch.org/docs/stable/generated/torch.cat.html" rel="nofollow noreferrer">documentation</a> that said I <em>couldn't</em> do this, other than perhaps this line:</p>
  <p><em>&quot; ... any python sequence of tensors of the same type ... &quot;</em></p>
  <p>The error is kind of curious though... any ideas?</p>