Solved by tom in post #6 
              
              
                You probably want to 

use const torch::OptionalDeviceGuard device_guard(a.device()); or so. 
This is similar to with torch.cuda.device(...) in Python.
Check that a, b, c actually are on the same device.

Best regards 
Thomas 
P.S.: If you take inspiration from PyTorch internals: The reason you don’…