Skip to content

Commit 5cb3fbb

Browse files
committed
[Docs] Add guide for converting Polybench to MLIR.
1 parent 5093adf commit 5cb3fbb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/PolybenchToMlir.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Converting Polybench to MLIR
2+
3+
This guide demonstrates how to convert [Polybench](https://www.cs.colostate.edu/~pouchet/software/polybench/), the C language polyhedral benchmark suite, to MLIR arith, affine and memref dialects using [Polygeist](https://github.com/llvm/Polygeist). Some manual modifications to the source code may be required.
4+
5+
## Requirements: Prepare Polygeist
6+
7+
1. Clone the Polygeist repository:
8+
```bash
9+
$ git clone --recursive https://github.com/llvm/Polygeist
10+
$ cd Polygeist
11+
$ git checkout 77c04bb
12+
```
13+
2. Build the project according to the instructions in the `README` file.
14+
15+
## Example: Converting `mvt` in Polybench
16+
17+
Follow the steps below to convert the `mvt` kernel in Polybench to MLIR:
18+
19+
1. **Modify the Source Code.**
20+
Since some statements such as `printf` and `assert` will introduce Polygeist custom dialects like `polygeist.pointer2memref` in the convertion, these parts of the code should be manually removed.
21+
- Locate the file `./tools/cgeist/Test/polybench/linear-algebra/kernels/mvt/mvt.c`, delete or comment out the `polybench_prevent_dce` function.
22+
- Locate the file `./tools/cgeist/Test/polybench/utilities/polybench.c`, delete or comment out the `assert` statement (i.e., `assert (tmp <= 10.0);`) in the `polybench_flush_cache` function.
23+
24+
2. **Run the Conversion Command.**
25+
Run the following command from the root directory of the Polygeist repository:
26+
```bash
27+
$ ./build/bin/cgeist ./tools/cgeist/Test/polybench/linear-algebra/kernels/mvt/mvt.c \
28+
./tools/cgeist/Test/polybench/utilities/polybench.c \
29+
-resource-dir=./llvm-project/build/lib/clang/18 \
30+
-D POLYBENCH_NO_FLUSH_CACHE -D MINI_DATASET \
31+
-I ./tools/cgeist/Test/polybench/utilities -O3 -S -o mvt-polygeist.mlir
32+
```
33+
> Notes: Replace `MINI_DATASET` to `SMALL_DATASET`, `STANDARD_DATASET`, `LARGE_DATASET`, or `EXTRALARGE_DATASET` to set different dataset sizes.
34+
35+
3. **Verify the Generated MLIR.**
36+
After running the command, check the generated `mvt-polygeist.mlir` file. It should contain only the standard MLIR arith, affine and memref dialects, with no Polygeist custom dialects like `polygeist.pointer2memref`.

0 commit comments

Comments
 (0)