Skip to content

Commit

Permalink
Update pin_memory implementation follow stock pytorch change
Browse files Browse the repository at this point in the history
Signed-off-by: majing <[email protected]>
  • Loading branch information
majing921201 committed Jul 23, 2024
1 parent 5f4970b commit a6fb4b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 63 deletions.
39 changes: 0 additions & 39 deletions src/ATen/native/xpu/PinnedMemoryAllocator.cpp

This file was deleted.

30 changes: 8 additions & 22 deletions test/xpu/test_torch_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8572,31 +8572,17 @@ def test_new(self) -> None:
# TypeError would be better
self.assertRaises(RuntimeError, lambda: x.new(z.storage()))

@unittest.skipIf(PYTORCH_CUDA_MEMCHECK, "is_pinned uses failure to detect pointer property")
def test_pin_memory(self):
x = torch.randn(3, 5)
self.assertFalse(x.is_pinned())
if not torch.cuda.is_available() or not torch.xpu.is_available():
self.assertRaises(RuntimeError, lambda: x.pin_memory())
else:
if torch.xpu.is_available():
device = 'xpu'
self.assertFalse(x.is_pinned(device))
pinned = x.pin_memory(device)
self.assertTrue(pinned.is_pinned(device))
self.assertEqual(pinned, x)
self.assertNotEqual(pinned.data_ptr(), x.data_ptr())
# test that pin_memory on already pinned tensor has no effect
self.assertIs(pinned, pinned.pin_memory(device))
self.assertEqual(pinned.data_ptr(), pinned.pin_memory(device).data_ptr())
else:
pinned = x.pin_memory()
self.assertTrue(pinned.is_pinned())
self.assertEqual(pinned, x)
self.assertNotEqual(pinned.data_ptr(), x.data_ptr())
# test that pin_memory on already pinned tensor has no effect
self.assertIs(pinned, pinned.pin_memory())
self.assertEqual(pinned.data_ptr(), pinned.pin_memory().data_ptr())
if torch.cuda.is_available() or torch.xpu.is_available():
pinned = x.pin_memory()
self.assertTrue(pinned.is_pinned())
self.assertEqual(pinned, x)
self.assertNotEqual(pinned.data_ptr(), x.data_ptr())
# test that pin_memory on already pinned tensor has no effect
self.assertIs(pinned, pinned.pin_memory())
self.assertEqual(pinned.data_ptr(), pinned.pin_memory().data_ptr())



Expand Down
2 changes: 0 additions & 2 deletions yaml/xpu_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,6 @@ supported:
- sgn.out
- sgn_
- _cdist_forward
- _pin_memory
- is_pinned
- is_set_to
- bucketize.Tensor
- bucketize.Tensor_out
Expand Down

0 comments on commit a6fb4b7

Please sign in to comment.