Skip to content

Commit

Permalink
Add ttmlir-translate docs and cpp gen example (#152)
Browse files Browse the repository at this point in the history
* add `ttmlir-translate` docs and cpp gen example

* add piped version
  • Loading branch information
svuckovicTT authored Jul 17, 2024
1 parent 4da2db8 commit 732d081
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Internal Build Notes / IRD](./internal-build.md)
- [Tools](./tools.md)
- [ttmlir-opt](./ttmlir-opt.md)
- [ttmlir-translate](./ttmlir-translate.md)
- [ttrt](./ttrt.md)
- [Flatbuffers](./flatbuffers.md)
- [Additional Reading](./additional-reading.md)
Expand Down
17 changes: 17 additions & 0 deletions docs/src/ttmlir-translate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `ttmlir-translate`

The `ttmlir-translate` translation utility. Unlike `ttmlir-opt` tool which is used to run passes within the MLIR world, `ttmlir-translate` allows us to ingest something (e.g. code) into MLIR world, and also produce something (e.g. executable binary, or even code again) from MLIR.
## Generate C++ code from MLIR

```bash
# First, let's run `ttmlir-opt` to convert to proper dialect
./build/bin/ttmlir-opt --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn --convert-ttnn-to-emitc test/ttmlir/Dialect/TTNN/simple_multiply.mlir -o c.mlir

# Now run `ttmlir-translate` to produce C++ code
./build/bin/ttmlir-translate -mlir-to-cpp c.mlir -allow-unregistered-dialect
```

Bonus: These two commands can be piped, to avoid writing a `mlir` file to disk, like so:
```bash
./build/bin/ttmlir-opt --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn --convert-ttnn-to-emitc test/ttmlir/Dialect/TTNN/simple_multiply.mlir | ./build/bin/ttmlir-translate -mlir-to-cpp -allow-unregistered-dialect
```

0 comments on commit 732d081

Please sign in to comment.