Skip to content

Commit

Permalink
Adding ability to reload system device and device descriptors and fix…
Browse files Browse the repository at this point in the history
… flaky test (#2259)

### Ticket
Closes #2258

### Problem description
Some people noticed failures of the following Silicon test:
test/ttmlir/Silicon/TTNN/n150/Transforms/DecomposeLayouts/decomposing_layouts_from_host.mlir

This test utilizes Python script to prepare the mlir for test execution,
hence on some dev machines it fails due to different environment
configurations.

### What's changed
Solved the test flakiness by adding the ability to reload the system and
device descriptors in passes:
- --ttir-load-system-desc
- --ttir-implicit-device

Utilized the new capability to fix the flaky test, using the MLIR pass
to prepare the MLIR for execution instead of relying on a Python script.

New test behavior:
- The test has default system and device descriptors present in their
MLIR files.
- --ttir-load-system-desc reloads a new system descriptor based on
machine setup
- --ttir-implicit-device reloads a new device descriptor based on a
newly loaded system descriptor

### Checklist
- [x] New/Existing tests provide coverage for changes
  • Loading branch information
sdjordjevicTT authored Feb 25, 2025
1 parent f15e704 commit b112dba
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 140 deletions.
3 changes: 3 additions & 0 deletions include/ttmlir/Dialect/TTIR/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def TTIRImplicitDevice: Pass<"ttir-implicit-device", "::mlir::ModuleOp"> {
let options = [
ListOption<"meshShape", "mesh-shape", "int64_t",
"Set the multi-device mesh shape.">,
Option<"forceReload", "force-reload", "bool",
/*default=*/"false",
"Force reload the system descriptor.">
];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/TTIR/Transforms/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TTIRImplicitDevice
void runOnOperation() final {
ModuleOp module = getOperation();

if (not module->hasAttr(tt::DeviceAttr::name)) {
if (not module->hasAttr(tt::DeviceAttr::name) || forceReload) {
assert(module->hasAttr(tt::SystemDescAttr::name));
auto systemDesc = module->getAttr(tt::SystemDescAttr::name);
auto finalMeshShape = tt::utils::determineMeshShape(module, *meshShape);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttnn-decompose-layouts %s | FileCheck %s
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device="force-reload=true" --ttnn-decompose-layouts %s | FileCheck %s
#device = #tt.device<workerGrid = #tt.grid<8x8, (d0, d1) -> (0, d0, d1)>, l1Map = (d0, d1)[s0, s1] -> (0, d0 floordiv s0, d1 floordiv s1, (d0 mod s0) * s1 + d1 mod s1), dramMap = (d0, d1)[s0, s1] -> (0, 0, ((((d0 floordiv s0) * 8 + d1 floordiv s1) * (s1 * s0) + (d0 mod s0) * s1 + d1 mod s1) floordiv 8192) mod 12, (((d0 floordiv s0) * 8 + d1 floordiv s1) * (s1 * s0) + (d0 mod s0) * s1 + d1 mod s1) floordiv 98304 + (((d0 floordiv s0) * 8 + d1 floordiv s1) * (s1 * s0) + (d0 mod s0) * s1 + d1 mod s1) mod 8192), meshShape = , chipIds = [0]>
#system_desc = #tt.system_desc<[{role = host, target_triple = "x86_64-pc-linux"}], [{arch = <wormhole_b0>, grid = 8x8, l1_size = 1499136, num_dram_channels = 12, dram_channel_size = 1073741824, noc_l1_address_align_bytes = 16, pcie_address_align_bytes = 32, noc_dram_address_align_bytes = 32, l1_unreserved_base = 99104, erisc_l1_unreserved_base = 104480, dram_unreserved_base = 32, dram_unreserved_end = 1073196736, physical_cores = {worker = [ 18x18, 18x19, 18x20, 18x21, 18x22, 18x23, 18x24, 18x25, 19x18, 19x19, 19x20, 19x21, 19x22, 19x23, 19x24, 19x25, 20x18, 20x19, 20x20, 20x21, 20x22, 20x23, 20x24, 20x25, 21x18, 21x19, 21x20, 21x21, 21x22, 21x23, 21x24, 21x25, 22x18, 22x19, 22x20, 22x21, 22x22, 22x23, 22x24, 22x25, 23x18, 23x19, 23x20, 23x21, 23x22, 23x23, 23x24, 23x25, 24x18, 24x19, 24x20, 24x21, 24x22, 24x23, 24x24, 24x25, 25x18, 25x19, 25x20, 25x21, 25x22, 25x23, 25x24, 25x25] dram = [ 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10, 0x11] eth = [ 17x25] eth_inactive = [ 16x18, 16x19, 16x20, 16x21, 16x22, 16x23, 16x24, 16x25, 17x19, 17x20, 17x22, 17x23, 17x24]}, supported_data_types = [<f32>, <f16>, <bf16>, <bfp_f8>, <bfp_bf8>, <bfp_f4>, <bfp_bf4>, <bfp_f2>, <bfp_bf2>, <u32>, <u16>, <u8>], supported_tile_sizes = [ 4x16, 16x16, 32x16, 4x32, 16x32, 32x32], num_cbs = 32}, {arch = <wormhole_b0>, grid = 8x8, l1_size = 1499136, num_dram_channels = 12, dram_channel_size = 1073741824, noc_l1_address_align_bytes = 16, pcie_address_align_bytes = 32, noc_dram_address_align_bytes = 32, l1_unreserved_base = 99104, erisc_l1_unreserved_base = 104480, dram_unreserved_base = 32, dram_unreserved_end = 1073196736, physical_cores = {worker = [ 18x18, 18x19, 18x20, 18x21, 18x22, 18x23, 18x24, 18x25, 19x18, 19x19, 19x20, 19x21, 19x22, 19x23, 19x24, 19x25, 20x18, 20x19, 20x20, 20x21, 20x22, 20x23, 20x24, 20x25, 21x18, 21x19, 21x20, 21x21, 21x22, 21x23, 21x24, 21x25, 22x18, 22x19, 22x20, 22x21, 22x22, 22x23, 22x24, 22x25, 23x18, 23x19, 23x20, 23x21, 23x22, 23x23, 23x24, 23x25, 24x18, 24x19, 24x20, 24x21, 24x22, 24x23, 24x24, 24x25, 25x18, 25x19, 25x20, 25x21, 25x22, 25x23, 25x24, 25x25] dram = [ 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10, 0x11] eth = [ 16x25] eth_inactive = [ 16x19, 16x20, 16x21, 16x22, 16x23, 16x24, 17x18, 17x19, 17x20, 17x21, 17x22, 17x23, 17x24, 17x25]}, supported_data_types = [<f32>, <f16>, <bf16>, <bfp_f8>, <bfp_bf8>, <bfp_f4>, <bfp_bf4>, <bfp_f2>, <bfp_bf2>, <u32>, <u16>, <u8>], supported_tile_sizes = [ 4x16, 16x16, 32x16, 4x32, 16x32, 32x32], num_cbs = 32}], [0, 1], [3 : i32, 0 : i32], [ 0x0x0x0], [<[0, 8, 0], [1, 0, 0]>]>
#dram = #ttnn.buffer_type<dram>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// RUN: python %ttmlir_scripts_root/extract-and-replace-system-desc-and-device.py --input-file %s --temp-dir %T --system-desc-path "%system_desc_path%" > %t.mlir
// RUN: ttmlir-opt --ttnn-decompose-layouts %t.mlir > %t_ttnn_mlir.mlir
// RUN: FileCheck %t.mlir --input-file=%t_ttnn_mlir.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t_ttnn_mlir.mlir > %t.ttnn
// UNSUPPORTED: true
#device = #tt.device<>
#system_desc = #tt.system_desc<>
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device="force-reload=true" --ttnn-decompose-layouts %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn
#device = #tt.device<workerGrid = #tt.grid<8x8, (d0, d1) -> (0, d0, d1)>, l1Map = (d0, d1)[s0, s1] -> (0, d0 floordiv s0, d1 floordiv s1, (d0 mod s0) * s1 + d1 mod s1), dramMap = (d0, d1)[s0, s1] -> (0, 0, ((((d0 floordiv s0) * 8 + d1 floordiv s1) * (s1 * s0) + (d0 mod s0) * s1 + d1 mod s1) floordiv 8192) mod 12, (((d0 floordiv s0) * 8 + d1 floordiv s1) * (s1 * s0) + (d0 mod s0) * s1 + d1 mod s1) floordiv 98304 + (((d0 floordiv s0) * 8 + d1 floordiv s1) * (s1 * s0) + (d0 mod s0) * s1 + d1 mod s1) mod 8192), meshShape = , chipIds = [0]>
#system_desc = #tt.system_desc<[{role = host, target_triple = "x86_64-pc-linux"}], [{arch = <wormhole_b0>, grid = 8x8, l1_size = 1499136, num_dram_channels = 12, dram_channel_size = 1073741824, noc_l1_address_align_bytes = 16, pcie_address_align_bytes = 32, noc_dram_address_align_bytes = 32, l1_unreserved_base = 99104, erisc_l1_unreserved_base = 104480, dram_unreserved_base = 32, dram_unreserved_end = 1073196736, physical_cores = {worker = [ 18x18, 18x19, 18x20, 18x21, 18x22, 18x23, 18x24, 18x25, 19x18, 19x19, 19x20, 19x21, 19x22, 19x23, 19x24, 19x25, 20x18, 20x19, 20x20, 20x21, 20x22, 20x23, 20x24, 20x25, 21x18, 21x19, 21x20, 21x21, 21x22, 21x23, 21x24, 21x25, 22x18, 22x19, 22x20, 22x21, 22x22, 22x23, 22x24, 22x25, 23x18, 23x19, 23x20, 23x21, 23x22, 23x23, 23x24, 23x25, 24x18, 24x19, 24x20, 24x21, 24x22, 24x23, 24x24, 24x25, 25x18, 25x19, 25x20, 25x21, 25x22, 25x23, 25x24, 25x25] dram = [ 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10, 0x11] eth = [ 17x25] eth_inactive = [ 16x18, 16x19, 16x20, 16x21, 16x22, 16x23, 16x24, 16x25, 17x19, 17x20, 17x22, 17x23, 17x24]}, supported_data_types = [<f32>, <f16>, <bf16>, <bfp_f8>, <bfp_bf8>, <bfp_f4>, <bfp_bf4>, <bfp_f2>, <bfp_bf2>, <u32>, <u16>, <u8>], supported_tile_sizes = [ 4x16, 16x16, 32x16, 4x32, 16x32, 32x32], num_cbs = 32}, {arch = <wormhole_b0>, grid = 8x8, l1_size = 1499136, num_dram_channels = 12, dram_channel_size = 1073741824, noc_l1_address_align_bytes = 16, pcie_address_align_bytes = 32, noc_dram_address_align_bytes = 32, l1_unreserved_base = 99104, erisc_l1_unreserved_base = 104480, dram_unreserved_base = 32, dram_unreserved_end = 1073196736, physical_cores = {worker = [ 18x18, 18x19, 18x20, 18x21, 18x22, 18x23, 18x24, 18x25, 19x18, 19x19, 19x20, 19x21, 19x22, 19x23, 19x24, 19x25, 20x18, 20x19, 20x20, 20x21, 20x22, 20x23, 20x24, 20x25, 21x18, 21x19, 21x20, 21x21, 21x22, 21x23, 21x24, 21x25, 22x18, 22x19, 22x20, 22x21, 22x22, 22x23, 22x24, 22x25, 23x18, 23x19, 23x20, 23x21, 23x22, 23x23, 23x24, 23x25, 24x18, 24x19, 24x20, 24x21, 24x22, 24x23, 24x24, 24x25, 25x18, 25x19, 25x20, 25x21, 25x22, 25x23, 25x24, 25x25] dram = [ 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10, 0x11] eth = [ 16x25] eth_inactive = [ 16x19, 16x20, 16x21, 16x22, 16x23, 16x24, 17x18, 17x19, 17x20, 17x21, 17x22, 17x23, 17x24, 17x25]}, supported_data_types = [<f32>, <f16>, <bf16>, <bfp_f8>, <bfp_bf8>, <bfp_f4>, <bfp_bf4>, <bfp_f2>, <bfp_bf2>, <u32>, <u16>, <u8>], supported_tile_sizes = [ 4x16, 16x16, 32x16, 4x32, 16x32, 32x32], num_cbs = 32}], [0, 1], [3 : i32, 0 : i32], [ 0x0x0x0], [<[0, 8, 0], [1, 0, 0]>]>
#dram = #ttnn.buffer_type<dram>
#system_memory = #ttnn.buffer_type<system_memory>
#ttnn_layout_host_rm = #ttnn.ttnn_layout<(d0, d1) -> (d0, d1), <1x1>, memref<64x128xf32, #system_memory>>
Expand Down
131 changes: 0 additions & 131 deletions tools/scripts/extract-and-replace-system-desc-and-device.py

This file was deleted.

0 comments on commit b112dba

Please sign in to comment.