Skip to content

Commit

Permalink
Merge branch 'main' into array-part
Browse files Browse the repository at this point in the history
  • Loading branch information
kumasento authored Oct 9, 2021
2 parents 3203dd4 + 95bc22a commit 3f1d895
Show file tree
Hide file tree
Showing 28 changed files with 1,188 additions and 614 deletions.
77 changes: 49 additions & 28 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ jobs:
# Build Phism and run its tests.
build-phism:
name: Build and Test Phism
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
# - name: Configure Environment
# run: echo "${GITHUB_WORKSPACE}/llvm/install/bin" >> $GITHUB_PATH
# Disabled for self-hosted
# - name: Get dependences
# run: |
# sudo apt-get update -y
# sudo apt-get install -y build-essential libtool autoconf pkg-config flex bison libgmp-dev clang-9 libclang-9-dev texinfo python3
# - name: Update the LLVM/Clang version to 9
# run: |
# sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-9 100
# sudo update-alternatives --install /usr/bin/FileCheck FileCheck /usr/bin/FileCheck-9 100
- name: Configure Environment
run: echo "${GITHUB_WORKSPACE}/llvm/install/bin" >> $GITHUB_PATH
- name: Get dependences
run: |
sudo apt-get update -y
sudo apt-get install -y build-essential libtool autoconf pkg-config flex bison libgmp-dev clang-9 libclang-9-dev texinfo python3
- name: Update the LLVM/Clang version to 9
run: |
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-9 100
sudo update-alternatives --install /usr/bin/FileCheck FileCheck /usr/bin/FileCheck-9 100
# Clone the Phism repo and its submodules. Do shallow clone to save clone
Expand All @@ -29,21 +29,26 @@ jobs:
uses: actions/checkout@v2
with:
submodules: "true"

- name: Sync Polygeist submodule
run: |
cd polygeist
git submodule update --init --recursive
# --------
# Restore LLVM from cache and build if it's not in there.
# --------
# Extract the LLVM submodule hash for use in the cache key.
- name: Get LLVM Hash
id: get-llvm-hash
run: echo "::set-output name=hash::$(git rev-parse @:./llvm)"
run: echo "::set-output name=hash::$(git rev-parse @:./polygeist/llvm-project)"
shell: bash
# Try to fetch LLVM from the cache.
- name: Cache LLVM
id: cache-llvm
uses: actions/cache@v2
with:
path: llvm/build
path: ./polygeist/llvm-project/build
key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}
# Build LLVM if we didn't hit in the cache. Even though we build it in
# the previous job, there is a low chance that it'll have been evicted by
Expand All @@ -52,8 +57,24 @@ jobs:
- name: Rebuild and Install LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
./scripts/build-llvm.sh ci
./scripts/build-llvm.sh
rm -rf ./llvm/build/test
# --------
# Build and test Polygeist.
# --------
- name: Build and test Polygeist
run: |
./scripts/build-polygeist.sh
# --------
# Build and test Polymer.
# --------
- name: Build and test Polymer
run: |
./scripts/build-polymer.sh
# --------
# Build and test Phism in both debug and release mode.
# --------
Expand All @@ -71,19 +92,19 @@ jobs:
pytest pyphism/
# Build and test Phism with pb-flow.
- name: Build and Test Phism (pb-flow)
run: |
python3 -m venv env
source env/bin/activate
which python3
python3 -m pip install -r requirements.txt
python3 ./scripts/pb-flow.py ./example/polybench --dataset MINI --sanity-check
python3 ./scripts/pb-flow.py ./example/polybench --dataset MINI --polymer --sanity-check
python3 ./scripts/pb-flow.py ./example/polybench --dataset MINI --polymer --loop-transforms --sanity-check
python3 ./scripts/pb-flow.py ./example/polybench --dataset SMALL --skip-vitis
python3 ./scripts/pb-flow.py ./example/polybench --dataset SMALL --polymer --skip-vitis
python3 ./scripts/pb-flow.py ./example/polybench --dataset SMALL --polymer --loop-transforms --skip-vitis
python3 ./scripts/pb-flow.py ./example/polybench --dataset SMALL --polymer --loop-transforms --array-partition --skip-vitis
# - name: Build and Test Phism (pb-flow)
# run: |
# python3 -m venv env
# source env/bin/activate
# which python3
# python3 -m pip install -r requirements.txt
# python3 ./scripts/pb-flow.py ./example/polybench --dataset MINI --sanity-check
# python3 ./scripts/pb-flow.py ./example/polybench --dataset MINI --polymer --sanity-check
# python3 ./scripts/pb-flow.py ./example/polybench --dataset MINI --polymer --loop-transforms --sanity-check
# python3 ./scripts/pb-flow.py ./example/polybench --dataset SMALL --skip-vitis
# python3 ./scripts/pb-flow.py ./example/polybench --dataset SMALL --polymer --skip-vitis
# python3 ./scripts/pb-flow.py ./example/polybench --dataset SMALL --polymer --loop-transforms --skip-vitis
# python3 ./scripts/pb-flow.py ./example/polybench --dataset SMALL --polymer --loop-transforms --array-partition --skip-vitis



9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "llvm"]
path = llvm
url = https://github.com/kumasento/Polygeist
[submodule "example/polybench"]
path = example/polybench
url = [email protected]:MatthiasJReisinger/PolyBenchC-4.2.1.git
[submodule "polygeist"]
path = polygeist
url = https://github.com/wsmoses/Polygeist
[submodule "polymer"]
path = polymer
url = https://github.com/kumasento/polymer
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Phism: Polyhedral High-Level Synthesis in MLIR

[![Build and Test](https://github.com/kumasento/phism/actions/workflows/buildAndTest.yml/badge.svg)](https://github.com/kumasento/phism/actions/workflows/buildAndTest.yml)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/kumasento/phism)
![GitHub](https://img.shields.io/github/license/kumasento/phism)
![GitHub issues](https://img.shields.io/github/issues/kumasento/phism)
![GitHub pull requests](https://img.shields.io/github/issues-pr/kumasento/phism)


## What is Phism?

Expand All @@ -18,20 +23,40 @@ Please find how to setup the prerequisites [here](docs/PREREQUISITES.md).

### Build LLVM

After that, the first thing you need to do is building the [Polygeist](wsmoses/Polygeist) submodule (with name `llvm`). Make sure you have it cloned:
Phism uses [Polygeist](https://github.com/wsmoses/Polygeist) to process C/C++ code into MLIR. But before we built Polygeist, we need to build the LLVM package within Polygeist (`polygeist/llvm-project`). This LLVM package will be shared by Polygeist, Polymer (later), and Phism.

First of all, make sure you've initialized all the submodules.

```sh
git submodule update --init --update
git submodule update --init --recursive
```

You may see many submodules being synced -- don't worry, they are simply required by Pluto, the polyhedral optimizer that Phism uses.

To build Polygeist, Just run the following script. It should take care of everything you need.
To build LLVM, Just run the following script. It should take care of everything you need.

```sh
./scripts/build-llvm.sh
```

### Build Polygeist

It is another one-liner:

```sh
./script/build-polygeist.sh
```

### Build Polymer

[Polymer](https://github.com/kumasento/polymer) provides the functionality to interact MLIR code with polyhedral scheduler.

There is also a script for you -

```sh
./script/build-polymer.sh
```

### Build Phism

Finally, you're all prepared to build Phism! Just type in the following commands:
Expand All @@ -44,7 +69,6 @@ It should run the Phism regression test in the end. And if all the tests passed,

## Usage


### Using Docker

This [doc](docs/DOCKER.md) gives an introduction on how to run Phism with docker.
Expand Down
3 changes: 2 additions & 1 deletion include/phism/mlir/Transforms/PhismTransforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace phism {
void registerExtractTopFuncPass();
void registerLoopTransformPasses();
void registerArrayPartitionPasses();
void registerFoldIfPasses();
void registerAllPhismPasses();
void registerDependenceAnalysisPasses();
// void registerDependenceAnalysisPasses();
} // namespace phism

#endif
6 changes: 6 additions & 0 deletions include/phism/mlir/Transforms/Utils.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
//===- Utils.h - Utility functions ------------------ C++-===//

#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/OperationSupport.h"

namespace phism {

/// Get the top function for the hardware design.
mlir::FuncOp getTopFunction(mlir::ModuleOp m);
mlir::Value expandAffineExpr(mlir::OpBuilder &builder, mlir::Location loc,
mlir::AffineExpr expr, mlir::ValueRange dimValues,
mlir::ValueRange symbolValues);

} // namespace phism
6 changes: 3 additions & 3 deletions lib/llvm/Transforms/VhlsLLVMRewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1776,9 +1776,9 @@ struct ConfigMemoryInterfacePass : public ModulePass {
if (isPointerToArray(arg->getType())) {
// Set ap_memory interface to array arguments.
auto arrayName = arg->getName().str();
attributeList = attributeList.addAttribute(F->getContext(), i + 1,
"fpga.address.interface",
"ap_memory." + arrayName);
attributeList = attributeList.addAttributeAtIndex(
F->getContext(), i + 1, "fpga.address.interface",
"ap_memory." + arrayName);

// Set bram configuration to function metadata.
auto &C = F->getContext();
Expand Down
4 changes: 3 additions & 1 deletion lib/mlir/Transforms/ArrayPartition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringExtras.h"

#include <fstream>
#include <queue>
Expand Down Expand Up @@ -970,7 +971,8 @@ static void renameTiledFunctions(ModuleOp m, OpBuilder &b) {
m.walk([&](mlir::CallOp caller) {
if (newNames.count(caller.getCallee()))
caller->setAttr("callee",
b.getSymbolRefAttr(newNames[caller.getCallee()]));
SymbolRefAttr::get(caller.getContext(),
newNames[caller.getCallee()]));
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/mlir/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ add_mlir_library(PhismTransforms
LoopTransforms.cc
PhismTransforms.cc
ArrayPartition.cc
DependenceAnalysis.cc
FoldIf.cc
Utils.cc

ADDITIONAL_HEADER_DIRS
Expand Down
Loading

0 comments on commit 3f1d895

Please sign in to comment.