Skip to content

Commit

Permalink
#163: Added strict runtime checking for ttnn binary and system its ru…
Browse files Browse the repository at this point in the history
…nning on
  • Loading branch information
tapspatel committed Aug 5, 2024
1 parent 5dc6d82 commit 26cd00a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/src/ttmlir-opt.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The `ttmlir` optimizer driver. This tool is used to run the `ttmlir` compiler p
## Simple Test

```bash
./build/bin/ttmlir-opt --ttir-to-ttnn-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir
./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-to-ttnn-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir
# Or
./build/bin/ttmlir-opt --ttir-to-ttmetal-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir
./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-to-ttmetal-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir
```
6 changes: 3 additions & 3 deletions docs/src/ttmlir-translate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The `ttmlir-translate` translation utility. Unlike `ttmlir-opt` tool which is us

```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
./build/bin/ttmlir-opt --ttir-load-system-desc --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
Expand All @@ -14,13 +14,13 @@ The `ttmlir-translate` translation utility. Unlike `ttmlir-opt` tool which is us
## Generate flatbuffer file from MLIR
```bash
# First run `ttmlir-opt` to convert to proper dialect
./build/bin/ttmlir-opt --ttir-to-ttnn-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir -o ttnn.mlir
./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-to-ttnn-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir -o ttnn.mlir

# Now run `ttmlir-translate` to produce flatbuffer file
./build/bin/ttmlir-translate --ttnn-to-flatbuffer ttnn.mlir -o out.ttnn
```

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
./build/bin/ttmlir-opt --ttir-load-system-desc --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
```
6 changes: 5 additions & 1 deletion docs/src/ttrt.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ttrt run out.ttnn --clean-artifacts
ttrt run out.ttnn --save-artifacts
ttrt run out.ttnn --loops 10
ttrt run --program-index 0 out.ttnn
ttrt run --program-index all out.ttnn
ttrt run /dir/of/flatbuffers
ttrt run /dir/of/flatbuffers --loops 10
```
Expand All @@ -66,7 +67,7 @@ ttrt query --clean-artifacts

### perf
Note: It's required to be on a system with silicon and to have a runtime enabled
build `-DTTMLIR_ENABLE_RUNTIME=ON`. Also need perf enabled build `-DTT_RUNTIME_ENABLE_PERF_TRACE=ON`.
build `-DTTMLIR_ENABLE_RUNTIME=ON`. Also need perf enabled build `-DTT_RUNTIME_ENABLE_PERF_TRACE=ON` with `export ENABLE_TRACY=1`.

```bash
ttrt perf --help
Expand All @@ -89,3 +90,6 @@ import ttrt.binary
fbb = ttrt.binary.load_from_path("out.ttnn")
d = ttrt.binary.as_dict(fbb)
```

## bonus
artifacts are saved in ttrt-artifacts directory if the option `--save-artifacts` is provided
6 changes: 6 additions & 0 deletions runtime/tools/python/ttrt/common/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ def run(args):
fbb = ttrt.binary.load_binary_from_path(binary)
check_version(fbb.version)
fbb_dict = ttrt.binary.as_dict(fbb)
assert (
fbb_dict["system_desc"]
== system_desc_as_dict(ttrt.runtime.get_current_system_desc()[0])[
"system_desc"
]
), f"system descriptor for binary and system mismatch!"
fbb_list.append((os.path.splitext(os.path.basename(binary))[0], fbb, fbb_dict))
program_index = arg_program_index
assert program_index <= len(
Expand Down

0 comments on commit 26cd00a

Please sign in to comment.