From 9754f7f0b35335e70a59d83caa7c505472f8e8b7 Mon Sep 17 00:00:00 2001 From: "Andrew M. James" Date: Fri, 14 Feb 2025 22:18:25 +0000 Subject: [PATCH 1/3] Update [ghstack-poisoned] --- aten/src/ATen/native/cuda/Copy.cu | 4 ++-- test/test_complex.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/aten/src/ATen/native/cuda/Copy.cu b/aten/src/ATen/native/cuda/Copy.cu index 0113d9f0e33a6d..0d9d67db91195b 100644 --- a/aten/src/ATen/native/cuda/Copy.cu +++ b/aten/src/ATen/native/cuda/Copy.cu @@ -449,10 +449,10 @@ static void copy_kernel_cuda(TensorIterator& iter, bool non_blocking) { } if (iter.tensor(0).is_conj() != iter.tensor(1).is_conj()) { - iter.tensor(0).conj_physical_(); + iter.tensor(0)._set_conj(iter.tensor(1).is_conj()); } if (iter.tensor(0).is_neg() != iter.tensor(1).is_neg()) { - iter.tensor(0).neg_(); + iter.tensor(0)._set_neg(iter.tensor(1).is_neg()); } } diff --git a/test/test_complex.py b/test/test_complex.py index 159f3e18aaee5a..8685421e207c93 100644 --- a/test/test_complex.py +++ b/test/test_complex.py @@ -6,6 +6,7 @@ dtypes, instantiate_device_type_tests, onlyCPU, + onlyCUDA, ) from torch.testing._internal.common_dtype import complex_types from torch.testing._internal.common_utils import run_tests, set_default_dtype, TestCase @@ -44,6 +45,20 @@ def test_conj_copy(self, device, dtype): x1.copy_(xc1) self.assertEqual(x1, torch.tensor([5 - 1j, 2 - 2j], device=device, dtype=dtype)) + @onlyCUDA + @dtypes(*complex_types()) + def test_conj_copy_gpu_to_cpu(self, device, dtype): + # issue: https://github.com/pytorch/pytorch/issues/146286 + x1 = torch.tensor([5 + 1j, 2 + 2j], device=device, dtype=dtype).conj() + x2 = torch.zeros_like(x1, device="cpu").pin_memory() + x2.copy_(x1, non_blocking=True) + self.assertEqual(x1, x2) + + x3 = torch.tensor([5 + 1j, 2 + 2j], device=device, dtype=dtype).conj() + x4 = torch.zeros_like(x1, device="cpu").pin_memory() + x4.copy_(x3, non_blocking=False) + self.assertEqual(x1, x2) + @dtypes(*complex_types()) def test_all(self, device, dtype): # issue: https://github.com/pytorch/pytorch/issues/120875 From 8f8088322b68f33eb9fb332380d9d344d4b26b58 Mon Sep 17 00:00:00 2001 From: "Andrew M. James" Date: Fri, 14 Mar 2025 21:31:29 +0000 Subject: [PATCH 2/3] Update [ghstack-poisoned] --- test/test_complex.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/test_complex.py b/test/test_complex.py index e118fb40605e72..236d61cf66714e 100644 --- a/test/test_complex.py +++ b/test/test_complex.py @@ -69,9 +69,6 @@ def pin(d): src_ref = src.clone() - src_i = src.imag - src_block_i = src_block.imag - # The copy is cross device so parameterize on the source device and make sure the dst is the other one dst_device = "cuda:0" if device == "cpu" else "cpu" dst = torch.zeros_like(src, device=dst_device, pin_memory=pin(dst_device)) @@ -80,20 +77,12 @@ def pin(d): dst = dst.conj() dst_block = dst_block.conj() - dst_i = dst.imag - dst_block_i = dst_block.imag - dst.copy_(src, non_blocking=True) dst_block.copy_(src_block, non_blocking=False) - dst_i.copy_(src_i, non_blocking=True) - dst_block_i.copy_(src_block_i, non_blocking=False) self.assertTrue(dst.is_conj() == dst_conj) - self.assertTrue(dst_i.is_neg() == dst_conj) self.assertEqual(dst_block, dst) - self.assertEqual(dst_block_i, dst_i) self.assertEqual(src, src_ref) - self.assertEqual(src_i, src_ref.imag) @dtypes(*complex_types()) def test_all(self, device, dtype): From 5610b04e9037842ce9d40ca1823cd76a81d1bd02 Mon Sep 17 00:00:00 2001 From: "Andrew M. James" Date: Fri, 14 Mar 2025 22:41:12 +0000 Subject: [PATCH 3/3] Update [ghstack-poisoned] --- test/test_complex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_complex.py b/test/test_complex.py index 9b40ea0d764c65..71b9785809eca5 100644 --- a/test/test_complex.py +++ b/test/test_complex.py @@ -6,7 +6,7 @@ dtypes, instantiate_device_type_tests, onlyCPU, - skipIf + skipIf, ) from torch.testing._internal.common_dtype import complex_types from torch.testing._internal.common_utils import (