Skip to content

Commit 15edb3c

Browse files
committed
Arm backend: Test int64 under the int64 extension
1 parent d335ea8 commit 15edb3c

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,47 @@ 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, *args):
121+
return self.op(*args)
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+
_NARROW = torch.tensor([1, 2, 3, 4], dtype=torch.int32)
130+
_COND = torch.tensor([True, False, True, False])
131+
132+
# A matched int64 pair delegates; a pair mixing widths falls back instead.
133+
int64_extension_suite = {
134+
"add": (lambda x, y: x + y, (_WIDE, _WIDE_2), 1),
135+
"sub": (lambda x, y: x - y, (_WIDE, _WIDE_2), 1),
136+
"mul": (lambda x, y: x * y, (_WIDE, _WIDE_2), 1),
137+
"gt_scalar": (lambda x, y: x > 9007199254740993, (_NEAR_2_53, _WIDE), 1),
138+
"where_int64": (torch.where, (_COND, _WIDE, _WIDE_2), 1),
139+
"where_x_narrow": (torch.where, (_COND, _NARROW, _WIDE), 0),
140+
"where_y_narrow": (torch.where, (_COND, _WIDE, _NARROW), 0),
141+
}
142+
143+
144+
@common.parametrize("test_data", int64_extension_suite)
145+
def test_int64_extension_tosa_INT(test_data: Tuple):
146+
op, inputs, delegates = test_data
147+
(
148+
ArmTester(
149+
Int64Op(op),
150+
inputs,
151+
common.get_tosa_compile_spec("TOSA-1.1+INT+int64"),
152+
)
153+
.export()
154+
.to_edge_transform_and_lower()
155+
.check_count({"torch.ops.higher_order.executorch_call_delegate": delegates})
156+
)

0 commit comments

Comments
 (0)