Revert "Add UTs for accelerator device-agnostic runtime APIs (#133572)"

This reverts commit 952514f0c8d8ff2e1719e0ca82b0d178a5c5ff45.

Reverted https://github.com/pytorch/pytorch/pull/133572 on behalf of https://github.com/malfet due to Sorry for reverting your PR, but it segfaults on MacOS ([comment](https://github.com/pytorch/pytorch/pull/133572#issuecomment-2530354401))
This commit is contained in:
PyTorch MergeBot
2024-12-10 04:42:52 +00:00
parent adbfdbd6a0
commit a1c6cf7e9f
3 changed files with 0 additions and 89 deletions

View File

@ -1,73 +0,0 @@
# Owner(s): ["module: tests"]
import sys
import unittest
import torch
from torch.testing._internal.common_utils import NoTest, run_tests, TestCase
if not torch.accelerator.is_available():
print("No available accelerator detected, skipping tests", file=sys.stderr)
TestCase = NoTest # noqa: F811
TEST_MULTIACCELERATOR = torch.accelerator.device_count() > 1
class TestAccelerator(TestCase):
def test_current_accelerator(self):
self.assertTrue(torch.accelerator.is_available())
accelerators = ["cuda", "xpu", "mps"]
for accelerator in accelerators:
if torch.get_device_module(accelerator).is_available():
self.assertEqual(
torch.accelerator.current_accelerator().type, accelerator
)
self.assertIsNone(torch.accelerator.current_accelerator().index)
with self.assertRaisesRegex(
ValueError, "doesn't match the current accelerator"
):
torch.accelerator.set_device_idx("cpu")
@unittest.skipIf(not TEST_MULTIACCELERATOR, "only one accelerator detected")
def test_generic_multi_device_behavior(self):
orig_device = torch.accelerator.current_device_idx()
target_device = (orig_device + 1) % torch.accelerator.device_count()
torch.accelerator.set_device_idx(target_device)
self.assertEqual(target_device, torch.accelerator.current_device_idx())
torch.accelerator.set_device_idx(orig_device)
self.assertEqual(orig_device, torch.accelerator.current_device_idx())
s1 = torch.Stream(target_device)
torch.accelerator.set_stream(s1)
self.assertEqual(target_device, torch.accelerator.current_device_idx())
torch.accelerator.synchronize(orig_device)
self.assertEqual(target_device, torch.accelerator.current_device_idx())
def test_generic_stream_behavior(self):
s1 = torch.Stream()
s2 = torch.Stream()
torch.accelerator.set_stream(s1)
self.assertEqual(torch.accelerator.current_stream(), s1)
event = torch.Event()
a = torch.randn(100)
b = torch.randn(100)
c = a + b
torch.accelerator.set_stream(s2)
self.assertEqual(torch.accelerator.current_stream(), s2)
a_acc = a.to(torch.accelerator.current_accelerator(), non_blocking=True)
b_acc = b.to(torch.accelerator.current_accelerator(), non_blocking=True)
torch.accelerator.set_stream(s1)
self.assertEqual(torch.accelerator.current_stream(), s1)
event.record(s2)
event.synchronize()
c_acc = a_acc + b_acc
event.record(s2)
torch.accelerator.synchronize()
self.assertTrue(event.query())
self.assertEqual(c_acc.cpu(), c)
if __name__ == "__main__":
run_tests()

View File

@ -725,14 +725,6 @@ class TestCuda(TestCase):
self.assertTrue(issubclass(type(cuda_event), torch.Event))
self.assertTrue(torch.Event in type(cuda_event).mro())
def test_stream_compatibility(self):
s1 = torch.cuda.Stream()
s2 = torch.cuda.Stream()
torch.accelerator.set_stream(s1)
self.assertEqual(torch.accelerator.current_stream().stream_id, s1.stream_id)
torch.accelerator.set_stream(s2)
self.assertEqual(torch.accelerator.current_stream().stream_id, s2.stream_id)
def test_record_stream(self):
cycles_per_ms = get_cycles_per_ms()

View File

@ -299,14 +299,6 @@ print(torch.xpu.device_count())
self.assertTrue(issubclass(type(xpu_event), torch.Event))
self.assertTrue(torch.Event in type(xpu_event).mro())
def test_stream_compatibility(self):
s1 = torch.xpu.Stream()
s2 = torch.xpu.Stream()
torch.accelerator.set_stream(s1)
self.assertEqual(torch.accelerator.current_stream().stream_id, s1.stream_id)
torch.accelerator.set_stream(s2)
self.assertEqual(torch.accelerator.current_stream().stream_id, s2.stream_id)
def test_generator(self):
torch.manual_seed(2024)
g_state0 = torch.xpu.get_rng_state()