How to lower the pattern `torch.aten.Int.Scalar(torch.aten.item(rank0_tensor))`?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 736
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 15
Description
I want to lower `torch.dialect` module something like the following:
```mlir
module {
func @main(%arg0: !torch.vtensor<[?,?,?,?],f32>, %arg1: !torch.vtensor<[],si64>) -> !torch.vtensor<[?,?,?,?],f32> {
%int1 = torch.constant.int 1
%int3 = torch.constant.int 3
%int2 = torch.constant.int 2
%int0 = torch.constant.int 0
%0 = torch.aten.item %arg1 : !torch.vtensor<[],si64> -> !torch.number
%1 = torch.aten.Int.Scalar %0 : !torch.number -> !torch.int
%2 = torch.aten.add.Scalar %arg0, %1, %int1 : !torch.vtensor<[?,?,?,?],f32>, !torch.int, !torch.int -> !torch.vtensor<[?,?,?,?],f32>
return %2 : !torch.vtensor<[?,?,?,?],f32>
}
}
```
But I can't add a per-Op converter to somewhere like [`lib/Conversion/TorchToTosa/TorchToTosa.cpp`](https://github.com/llvm/torch-mlir/blob/main/lib/Conversion/TorchToTosa/TorchToTosa.cpp), since there is no `TypeConverter` between `!torch.number` and `!torch.int`.
Is there anyone knows how to lower the IR module?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/Conversion/TorchToTosa/TorchToTosa.cpp and inspect how the shown torch.aten.item and torch.aten.Int.Scalar operations are handled. A resolution would need to establish a supported lowering for the sample IR and demonstrate that the resulting module can be lowered successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100