Commit 481da8d
authored
[TOSA] : Fix float to integer cast for
The behavior of float -> integer cast in PyTorch (though I haven't found
the actual code implementing the cast) appears to be (based on the
results produced in PyTorch):
1. round the float nearest to zero (similar to `arith.fptosi/ui`)
2. then perform the conversion
Currently we only emit `tosa.cast` for this operation but as per the
spec https://www.mlplatform.org/tosa/tosa_spec.html#_cast the rounding
performed for float -> integer is round to nearest integer (not zero).
Hence, the current TOSA lowering for `torch.ops.aten.to` produces
incorrect answer.torch.ops.aten.to lowering. (llvm#3946)1 parent 9dd94fb commit 481da8d
File tree
4 files changed
+87
-11
lines changed- lib/Conversion/TorchToTosa
- projects/pt1
- e2e_testing
- python/torch_mlir_e2e_test/test_suite
- test/Conversion/TorchToTosa
4 files changed
+87
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
| 339 | + | |
| 340 | + | |
340 | 341 | | |
341 | 342 | | |
342 | 343 | | |
| |||
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
384 | 402 | | |
385 | 403 | | |
386 | 404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1720 | 1720 | | |
1721 | 1721 | | |
1722 | 1722 | | |
| 1723 | + | |
| 1724 | + | |
1723 | 1725 | | |
1724 | 1726 | | |
1725 | 1727 | | |
| |||
2627 | 2629 | | |
2628 | 2630 | | |
2629 | 2631 | | |
| 2632 | + | |
2630 | 2633 | | |
2631 | 2634 | | |
2632 | 2635 | | |
| |||
3333 | 3336 | | |
3334 | 3337 | | |
3335 | 3338 | | |
| 3339 | + | |
3336 | 3340 | | |
3337 | 3341 | | |
3338 | 3342 | | |
| |||
3444 | 3448 | | |
3445 | 3449 | | |
3446 | 3450 | | |
3447 | | - | |
3448 | 3451 | | |
3449 | 3452 | | |
3450 | 3453 | | |
| |||
3501 | 3504 | | |
3502 | 3505 | | |
3503 | 3506 | | |
3504 | | - | |
3505 | 3507 | | |
3506 | 3508 | | |
3507 | 3509 | | |
| |||
3544 | 3546 | | |
3545 | 3547 | | |
3546 | 3548 | | |
3547 | | - | |
3548 | 3549 | | |
3549 | 3550 | | |
3550 | 3551 | | |
| |||
3577 | 3578 | | |
3578 | 3579 | | |
3579 | 3580 | | |
3580 | | - | |
3581 | | - | |
3582 | 3581 | | |
3583 | 3582 | | |
3584 | 3583 | | |
3585 | 3584 | | |
3586 | 3585 | | |
3587 | 3586 | | |
3588 | 3587 | | |
3589 | | - | |
3590 | 3588 | | |
3591 | 3589 | | |
3592 | 3590 | | |
| |||
3649 | 3647 | | |
3650 | 3648 | | |
3651 | 3649 | | |
3652 | | - | |
3653 | 3650 | | |
3654 | 3651 | | |
3655 | 3652 | | |
| |||
3734 | 3731 | | |
3735 | 3732 | | |
3736 | 3733 | | |
3737 | | - | |
3738 | | - | |
3739 | 3734 | | |
3740 | 3735 | | |
3741 | 3736 | | |
| |||
4002 | 3997 | | |
4003 | 3998 | | |
4004 | 3999 | | |
4005 | | - | |
4006 | 4000 | | |
4007 | 4001 | | |
4008 | 4002 | | |
| |||
4717 | 4711 | | |
4718 | 4712 | | |
4719 | 4713 | | |
| 4714 | + | |
| 4715 | + | |
4720 | 4716 | | |
4721 | 4717 | | |
4722 | 4718 | | |
| |||
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
258 | 297 | | |
259 | 298 | | |
260 | 299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1022 | 1022 | | |
1023 | 1023 | | |
1024 | 1024 | | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
1025 | 1048 | | |
1026 | 1049 | | |
1027 | 1050 | | |
| |||
0 commit comments