Skip to content

Commit 0e39bc8

Browse files
committed
Arm backend: Test int64 under the int64 extension
1 parent 75d1782 commit 0e39bc8

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

‎backends/arm/test/misc/test_int64.py‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,80 @@ def test_int64_tosa_INT(test_data: Tuple):
110110
.to_executorch()
111111
.run_method_and_compare_outputs(inputs)
112112
)
113+
114+
115+
class Int64Op(torch.nn.Module):
116+
def __init__(self, op):
117+
super().__init__()
118+
self.op = op
119+
120+
def forward(self, x: torch.Tensor, y: torch.Tensor):
121+
return self.op(x, y)
122+
123+
124+
# Operands straddle the int32 range, so a narrowed lowering cannot reproduce
125+
# the reference result, and 2**53 + 1 is not representable as a double.
126+
_WIDE = torch.tensor([2**40, -(2**38), 2**31, -1], dtype=torch.int64)
127+
_WIDE_2 = torch.tensor([2**39, 2**37, 1, -(2**40)], dtype=torch.int64)
128+
_NEAR_2_53 = torch.tensor([2**53, 2**53 + 1, 2**53 + 2, -(2**53)], dtype=torch.int64)
129+
130+
int64_extension_suite = {
131+
"add": (lambda x, y: x + y, (_WIDE, _WIDE_2), "aten_add_tensor"),
132+
"sub": (lambda x, y: x - y, (_WIDE, _WIDE_2), "aten_sub_tensor"),
133+
"mul": (lambda x, y: x * y, (_WIDE, _WIDE_2), "aten_mul_tensor"),
134+
"gt_scalar": (
135+
lambda x, y: x > 9007199254740993,
136+
(_NEAR_2_53, _WIDE),
137+
"aten_gt_scalar",
138+
),
139+
}
140+
141+
142+
@common.parametrize("test_data", int64_extension_suite)
143+
def test_int64_extension_tosa_INT(test_data: Tuple):
144+
op, inputs, aten_op = test_data
145+
(
146+
ArmTester(
147+
Int64Op(op),
148+
inputs,
149+
common.get_tosa_compile_spec("TOSA-1.1+INT+int64"),
150+
)
151+
.export()
152+
.to_edge_transform_and_lower()
153+
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
154+
.check_not([aten_op])
155+
.to_executorch()
156+
)
157+
158+
159+
class Int64Where(torch.nn.Module):
160+
def forward(self, c: torch.Tensor, x: torch.Tensor, y: torch.Tensor):
161+
return torch.where(c, x, y)
162+
163+
164+
mixed_width_suite = {
165+
"x_int32_y_int64": (
166+
torch.tensor([1, 2, 3, 4], dtype=torch.int32),
167+
torch.tensor([2**40, 2**40 + 1, -(2**40), 7], dtype=torch.int64),
168+
),
169+
"x_int64_y_int32": (
170+
torch.tensor([2**40, 2**40 + 1, -(2**40), 7], dtype=torch.int64),
171+
torch.tensor([1, 2, 3, 4], dtype=torch.int32),
172+
),
173+
}
174+
175+
176+
@common.parametrize("test_data", mixed_width_suite)
177+
def test_int64_mixed_width_where_not_delegated(test_data: Tuple):
178+
x, y = test_data
179+
inputs = (torch.tensor([True, False, True, False]), x, y)
180+
(
181+
ArmTester(
182+
Int64Where(),
183+
inputs,
184+
common.get_tosa_compile_spec("TOSA-1.1+INT+int64"),
185+
)
186+
.export()
187+
.to_edge_transform_and_lower()
188+
.check_count({"torch.ops.higher_order.executorch_call_delegate": 0})
189+
)

0 commit comments

Comments
 (0)