@@ -128,25 +128,30 @@ def forward(self, x: torch.Tensor, y: torch.Tensor):
128128
129129
130130class Int64GreaterScalar (torch .nn .Module ):
131+ """Compare against a scalar that a double cannot represent exactly."""
132+
131133 def forward (self , x : torch .Tensor , y : torch .Tensor ):
132- return x > 0
134+ return x > 9007199254740993
135+
133136
137+ # Operands straddle the int32 range, so a narrowed lowering cannot reproduce
138+ # the reference result.
139+ _WIDE = torch .tensor ([2 ** 40 , - (2 ** 38 ), 2 ** 31 , - 1 ], dtype = torch .int64 )
140+ _WIDE_2 = torch .tensor ([2 ** 39 , 2 ** 37 , 1 , - (2 ** 40 )], dtype = torch .int64 )
141+ _NEAR_2_53 = torch .tensor ([2 ** 53 , 2 ** 53 + 1 , 2 ** 53 + 2 , - (2 ** 53 )], dtype = torch .int64 )
134142
135143int64_extension_suite = {
136- "add" : (Int64Add (), (torch .arange (- 5 , 5 ), torch .arange (0 , 10 ))),
137- "gt_scalar" : (
138- Int64GreaterScalar (),
139- (torch .arange (- 5 , 5 ), torch .arange (0 , 10 )),
140- ),
141- "sub" : (Int64Sub (), (torch .arange (- 5 , 5 ), torch .arange (0 , 10 ))),
142- "mul" : (Int64Mul (), (torch .arange (- 5 , 5 ), torch .arange (0 , 10 ))),
144+ "add" : (Int64Add (), (_WIDE , _WIDE_2 ), "aten_add_tensor" ),
145+ "sub" : (Int64Sub (), (_WIDE , _WIDE_2 ), "aten_sub_tensor" ),
146+ "mul" : (Int64Mul (), (_WIDE , _WIDE_2 ), "aten_mul_tensor" ),
147+ "gt_scalar" : (Int64GreaterScalar (), (_NEAR_2_53 , _WIDE ), "aten_gt_scalar" ),
143148}
144149
145150
146151@common .parametrize ("test_data" , int64_extension_suite )
147152def test_int64_extension_tosa_INT (test_data : Tuple ):
148- """Lowering keeps int64 operands when the spec declares the extension."""
149- model , inputs = test_data
153+ """Int64 operands are delegated when the spec declares the extension."""
154+ model , inputs , aten_op = test_data
150155 (
151156 ArmTester (
152157 model ,
@@ -155,5 +160,7 @@ def test_int64_extension_tosa_INT(test_data: Tuple):
155160 )
156161 .export ()
157162 .to_edge_transform_and_lower ()
163+ .check_count ({"torch.ops.higher_order.executorch_call_delegate" : 1 })
164+ .check_not ([aten_op ])
158165 .to_executorch ()
159166 )
0 commit comments