Skip to content
19 changes: 19 additions & 0 deletions test/visualize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# MLIR Code Visualization Guide

This guide explains how to visualize MLIR (Multi-Level Intermediate Representation) code using various tools and techniques.

## Usage

First, run `apt install graphviz` to install Graphviz. For an MLIR file, use the option `--view-op-graph` to generate a Graphviz visualization of a function. Then, use the `dot` command to create an image file from the visualization.

Example:

```bash
mlir-neura-opt --assign-accelerator --lower-arith-to-neura --fuse-patterns test.mlir > test_fused.mlir
mlir-opt --allow-unregistered-dialect --view-op-graph test_fused.mlir 2> test.dot
dot -Tpng test.dot -o test.png
```

It will generate a `test.png` file in the current directory, as shown below:

![test](test.png)
13 changes: 13 additions & 0 deletions test/visualize/test.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Test cases for FusePatternsPass

// Test 1: Verify dot generation for fused operations
// RUN: mlir-neura-opt --assign-accelerator --lower-arith-to-neura --fuse-patterns --generate-dot %s | FileCheck %s --check-prefix=CHECK-DOT-GENERATION

func.func @test_dot_generation(%a: f32, %b: f32, %c: f32) -> f32 {
%temp = arith.addf %a, %b : f32
%res = arith.addf %temp, %c : f32
// CHECK-DOT-GENERATION: // DOT: digraph
// CHECK-DOT-GENERATION: // DOT: "fadd_fadd"
return %res : f32
}

Binary file added test/visualize/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/visualize/visualize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mlir-neura-opt --assign-accelerator --lower-arith-to-neura --fuse-patterns test.mlir > test_fused.mlir
mlir-opt --allow-unregistered-dialect --view-op-graph test_fused.mlir 2> test.dot
dot -Tpng test.dot -o test.png
Loading