HIP (ROCm) semantics
ROCmâ¢ is AMDâs open source software platform for GPU-accelerated high
performance computing and machine learning. HIP is ROCm's C++ dialect
designed to ease conversion of CUDA applications to portable C++ code.
HIP is used when converting existing CUDA applications like PyTorch to
portable C++ and for new projects that require portability between AMD
and NVIDIA.
HIP Interfaces Reuse the CUDA Interfaces
PyTorch for HIP intentionally reuses the existing "torch.cuda"
interfaces. This helps to accelerate the porting of existing PyTorch
code and models because very few code changes are necessary, if any.
The example from CUDA semantics will work exactly the same for HIP:
cuda = torch.device('cuda')     # Default HIP device
   cuda0 = torch.device('cuda:0')  # 'rocm' or 'hip' are not valid, use 'cuda'
   cuda2 = torch.device('cuda:2')  # GPU 2 (these are 0-indexed)
x = torch.tensor([1., 2.], device=cuda0)