Commit a55906e
[TOSA] Refactor: Use tosaCastTensorToType() function to create tosa.cast
* Previously, in Torch to TOSA, there are 3 ways to create tosa.cast op:
- `rewriter.create<tosa::CastOp>()`
- `tosa::promoteType()`
- `tosa::tosaCastTensorToType()`
* This commit combines the three APIs above into
`tosa::tosaCastTensorToType()` with the following features:
- Checking whether source and destination element types are the same
before casting. If they are same, skip the cast.
- Custom float to integer cast behavior added from this PR:
#3946
TLDR: PyTorch's and TOSA's float to integer casting behaviors are
different (round to zero vs round to nearest, respectively), which
requires a custom casting here.
- Future `TODO`: add a --strict mode which includes
`checkValidityOfCast()` to ensure that the casting pairs follow TOSA
specifications.
* Update LIT tests.
Signed-off-by: Justin Ngo <[email protected]>
Change-Id: I2aef3c79d8f2d98b93e671d5b815b8eab33e697e1 parent d70e7b1 commit a55906e
File tree
6 files changed
+263
-267
lines changed- include/torch-mlir/Conversion/TorchToTosa
- lib/Conversion/TorchToTosa
- test/Conversion/TorchToTosa
6 files changed
+263
-267
lines changedLines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
36 | | - | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
0 commit comments