1# Owner(s): ["module: inductor"] 2import importlib 3import os 4import sys 5import unittest 6 7import torch 8from torch.testing._internal.common_utils import IS_CI, IS_WINDOWS 9 10 11if IS_WINDOWS and IS_CI: 12 sys.stderr.write( 13 "Windows CI does not have necessary dependencies for test_xpu_basic yet\n" 14 ) 15 if __name__ == "__main__": 16 sys.exit(0) 17 raise unittest.SkipTest("requires sympy/functorch/filelock") 18 19importlib.import_module("filelock") 20 21pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 22sys.path.append(pytorch_test_dir) 23from inductor.test_torchinductor import check_model_gpu, TestCase 24 25 26# TODO: Remove this file. 27# This is a temporary test case to test the base functionality of first Intel GPU Inductor integration. 28# We are working on reuse and pass the test cases in test/inductor/* step by step. 29# Will remove this file when pass full test in test/inductor/*. 30 31 32class XpuBasicTests(TestCase): 33 common = check_model_gpu 34 device = "xpu" 35 36 def test_add(self): 37 def fn(a, b): 38 return a + b 39 40 self.common(fn, (torch.rand(2, 3, 16, 16), torch.rand(2, 3, 16, 16))) 41 42 def test_sub(self): 43 def fn(a, b): 44 return a - b 45 46 self.common(fn, (torch.rand(2, 3, 16, 16), torch.rand(2, 3, 16, 16))) 47 48 def test_mul(self): 49 def fn(a, b): 50 return a * b 51 52 self.common(fn, (torch.rand(2, 3, 16, 16), torch.rand(2, 3, 16, 16))) 53 54 def test_div(self): 55 def fn(a, b): 56 return a / b 57 58 self.common(fn, (torch.rand(2, 3, 16, 16), torch.rand(2, 3, 16, 16))) 59 60 61if __name__ == "__main__": 62 from torch._dynamo.test_case import run_tests 63 from torch.testing._internal.inductor_utils import HAS_XPU 64 65 if HAS_XPU: 66 run_tests(needs="filelock") 67