已合并
add torch mlir ut case #31637
bigprestigee1创建于 3月11日
add torch mlir ut case #31637
已合并
bigprestigee1创建于 3月11日
1 个文件变更+33-0
@@ -0,0 +1,33 @@
1+import torch
2+from torch.testing._internal.common_utils import run_tests, parametrize, instantiate_parametrized_tests
3+from testutils import TestUtils
4+import torch_npu
5+ 
6+ 
7+class TestAdd(TestUtils):
8+ import os
9+ 
10+ os.environ['TORCHINDUCTOR_NPU_BACKEND'] = 'mlir'
11+ 
12+ def op_calc(self, first_element, second_element):
13+ result = first_element + second_element
14+ return result
15+ 
16+ @parametrize('shape', TestUtils._pointwise_demo_shapes)
17+ @parametrize('dtype', ['float32', 'int64'])
18+ def test_pointwise_cases(self, shape, dtype):
19+ first_element = self._generate_tensor(shape, dtype)
20+ second_element = self._generate_tensor(shape, dtype)
21+ 
22+ std_sum = self.op_calc(first_element, second_element)
23+ 
24+ compiled_op_calc = torch.compile(self.op_calc)
25+ inductor_sum = compiled_op_calc(first_element, second_element)
26+ 
27+ self.assertEqual(std_sum, inductor_sum)
28+ 
29+ 
30+instantiate_parametrized_tests(TestAdd)
31+ 
32+if __name__ == "__main__":
33+ run_tests()