Skip to content

Commit

Permalink
mlir: Initial MLIR/RVSDG backend
Browse files Browse the repository at this point in the history
  • Loading branch information
sjalander committed Oct 6, 2023
1 parent d70a8b6 commit c96a863
Show file tree
Hide file tree
Showing 12 changed files with 608 additions and 25 deletions.
194 changes: 182 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,75 @@ jobs:
- name: Generate documentation
run: make docs

build-mlir:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'

# --------
# Restore MLIR RVSDG Dialect from cache and build if it's not in there
# --------

# Clone MLIR RVSDG Dialect
- name: Clone MLIR RVSDG dialect
run: git clone https://github.com/Riphiphip/mlir_rvsdg.git ${{ github.workspace }}/mlir-rvsdg

# Extract the hash for latest commit for use in the cache key
- name: Get hash
id: get-mlir-hash
run: |
cd ${{ github.workspace }}/mlir-rvsdg
echo "hash=$(git rev-parse main)" >> $GITHUB_OUTPUT
# Try to fetch Dialect from the cache
- name: Cache RVSDG Dialect
id: cache-mlir
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/lib/mlir-rvsdg
key: ${{ runner.os }}-mlir-${{ steps.get-mlir-hash.outputs.hash }}

# Install dependencies if we didn't hit in the cache
- name: Install dependencies
if: steps.cache-mlir.outputs.cache-hit != 'true'
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main
sudo apt-get install llvm-16-dev libmlir-16-dev mlir-16-tools clang-16 ninja-build
sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/ && sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/libMLIR.so
sudo python3 /usr/lib/llvm-16/build/utils/lit/setup.py install
# Build MLIR RVSDG Dialect if we didn't hit in the cache
- name: Rebuild and Install MLIR RVSDG Dialect
if: steps.cache-mlir.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/mlir-rvsdg
mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_C_COMPILER=clang-16 \
-DCMAKE_CXX_COMPILER=clang++-16 \
-DLLVM_DIR=/usr/lib/llvm-16/cmake/ \
-DMLIR_DIR=/usr/lib/llvm-16/lib/cmake/mlir \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/lib/mlir-rvsdg
cmake --build .
ninja install
build:
runs-on: ubuntu-22.04
needs: build-mlir
steps:
- uses: actions/checkout@v3
- name: Cache build
id: cache-bin
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/bin/*
path: |
${{ github.workspace }}/bin/*
${{ github.workspace }}/lib/*
key: ${{ runner.os }}-${{ github.sha }}-jlm-bin
- name: Cache build
id: cache-build
Expand All @@ -34,23 +94,120 @@ jobs:
run: wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
- name: Update apt sources
run: sudo add-apt-repository deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main
- name: Install dependencies (LLVM)
run: sudo apt-get update && sudo apt-get install llvm-16-dev clang-16
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install llvm-16-dev libmlir-16-dev mlir-16-tools clang-16 ninja-build
sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/ && sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/libMLIR.so
# --------
# Restore MLIR RVSDG Dialect from cache and build if it's not in there
# --------

# Clone MLIR RVSDG Dialect
- name: Clone MLIR RVSDG dialect
run: git clone https://github.com/Riphiphip/mlir_rvsdg.git ${{ github.workspace }}/mlir-rvsdg

# Extract the hash for latest commit for use in the cache key
- name: Get hash
id: get-mlir-hash
run: |
cd ${{ github.workspace }}/mlir-rvsdg
echo "hash=$(git rev-parse main)" >> $GITHUB_OUTPUT
# Try to fetch Dialect from the cache
- name: Cache RVSDG Dialect
id: cache-mlir
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/lib/mlir-rvsdg
key: ${{ runner.os }}-mlir-${{ steps.get-mlir-hash.outputs.hash }}

# Build MLIR RVSDG Dialect if we didn't hit in the cache
- name: Rebuild and Install MLIR RVSDG Dialect
if: steps.cache-mlir.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/mlir-rvsdg
mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_C_COMPILER=clang-16 \
-DCMAKE_CXX_COMPILER=clang++-16 \
-DLLVM_DIR=/usr/lib/llvm-16/cmake/ \
-DMLIR_DIR=/usr/lib/llvm-16/lib/cmake/mlir \
-DCMAKE_INSTALL_PREFIX=../../lib/mlir-rvsdg
cmake --build .
ninja install
# --------
# Compile jlm
# --------

- name: Compile jlm
run: make jlm-release -j `nproc`
- name: Run unit and C tests
run: make check -j `nproc`

gcc:
runs-on: ubuntu-22.04
needs: build-mlir
steps:
- uses: actions/checkout@v3
- name: Get LLVM apt key
run: wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
- name: Update apt sources
run: sudo add-apt-repository deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main
- name: Install dependencies (LLVM)
run: sudo apt-get update && sudo apt-get install llvm-16-dev clang-16
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install llvm-16-dev libmlir-16-dev mlir-16-tools clang-16 ninja-build
sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/ && sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/libMLIR.so
# --------
# Restore MLIR RVSDG Dialect from cache and build if it's not in there
# --------

# Clone MLIR RVSDG Dialect
- name: Clone MLIR RVSDG dialect
run: git clone https://github.com/Riphiphip/mlir_rvsdg.git ${{ github.workspace }}/mlir-rvsdg

# Extract the hash for latest commit for use in the cache key
- name: Get hash
id: ${{ github.workspace }}/get-mlir-hash
run: |
cd ${{ github.workspace }}/mlir-rvsdg
echo "hash=$(git rev-parse main)" >> $GITHUB_OUTPUT
# Try to fetch Dialect from the cache
- name: Cache RVSDG Dialect
id: cache-mlir
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/lib/mlir-rvsdg
key: ${{ runner.os }}-mlir-${{ steps.get-mlir-hash.outputs.hash }}

# Build MLIR RVSDG Dialect if we didn't hit in the cache
- name: Rebuild and Install MLIR RVSDG Dialect
if: steps.cache-mlir.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/mlir-rvsdg
mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_C_COMPILER=clang-16 \
-DCMAKE_CXX_COMPILER=clang++-16 \
-DLLVM_DIR=/usr/lib/llvm-16/cmake/ \
-DMLIR_DIR=/usr/lib/llvm-16/lib/cmake/mlir \
-DCMAKE_INSTALL_PREFIX=../../lib/mlir-rvsdg
cmake --build .
ninja install
# --------
# Compile jlm
# --------

- name: Compile jlm
run: make CXX=g++ jlm-release -j `nproc`
- name: Run unit and C tests
Expand All @@ -70,7 +227,10 @@ jobs:
- name: Update apt sources
run: sudo add-apt-repository deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main
- name: Install dependencies (LLVM)
run: sudo apt-get update && sudo apt-get install llvm-16-dev clang-16
run: |
sudo apt-get update
sudo apt-get install llvm-16-dev libmlir-16-dev mlir-16-tools clang-16 ninja-build
sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/ && sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/libMLIR.so
- name: Add jlc to PATH
run: echo '${{ github.workspace }}/bin' >> $GITHUB_PATH
- name: Install valgrind
Expand All @@ -85,16 +245,21 @@ jobs:
- name: Cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/bin/*
path: |
${{ github.workspace }}/bin/*
${{ github.workspace }}/lib/*
key: ${{ runner.os }}-${{ github.sha }}-jlm-bin
- name: Add jlc to PATH
run: echo '${{ github.workspace }}/bin' >> $GITHUB_PATH
- name: Get LLVM apt key
run: wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
- name: Update apt sources
run: sudo add-apt-repository deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main
- name: Install dependencies (LLVM)
run: sudo apt-get update && sudo apt-get install llvm-16-dev clang-16
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install llvm-16-dev libmlir-16-dev mlir-16-tools clang-16 ninja-build
sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/ && sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/libMLIR.so
- name: Clone polybench
run: git clone https://github.com/phate/polybench-jlm.git
- name: Check polybench
Expand All @@ -107,14 +272,19 @@ jobs:
- name: Cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/bin/*
path: |
${{ github.workspace }}/bin/*
${{ github.workspace }}/lib/*
key: ${{ runner.os }}-${{ github.sha }}-jlm-bin
- name: Get LLVM apt key
run: wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
- name: Update apt sources
run: sudo add-apt-repository deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main
- name: Install dependencies (LLVM)
run: sudo apt-get update && sudo apt-get install llvm-16-dev clang-16
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install llvm-16-dev libmlir-16-dev mlir-16-tools clang-16 ninja-build
sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/ && sudo ln -s /usr/lib/llvm-16/lib/libMLIR.so.16 /usr/lib/x86_64-linux-gnu/libMLIR.so
- name: Add jlc to PATH
run: echo '${{ github.workspace }}/bin' >> $GITHUB_PATH
- name: Clone jlm-test-suite
Expand Down
8 changes: 5 additions & 3 deletions Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ endif

JLM_BIN = $(JLM_ROOT)/bin
JLM_BUILD = $(JLM_ROOT)/build
MLIR_ROOT = $(JLM_ROOT)/lib/mlir-rvsdg/

# -gdwarf-4 is used since the valgrind version in Ubuntu 22.04 doesn't support dwarf-5,
# which is produced by default by clang-14
CXXFLAGS += --std=c++17 -Wall -Wpedantic -Wextra -Wno-unused-parameter -Werror -Wfatal-errors -gdwarf-4
CXXFLAGS += --std=c++17 -Wall -Wpedantic -Wextra -Wno-unused-parameter -Werror -Wfatal-errors -gdwarf-4 -I$(MLIR_ROOT)/include -I$(MLIR_ROOT)/include
CXXFLAGS_DEBUG += -g -DJLM_DEBUG -DJLM_ENABLE_ASSERTS

$(JLM_BUILD)/%.la: $(JLM_ROOT)/%.cpp
Expand All @@ -50,6 +51,7 @@ $(JLM_BUILD)/%.a:
ranlib $@

include $(JLM_ROOT)/jlm/hls/Makefile.sub
include $(JLM_ROOT)/jlm/mlir/Makefile.sub
include $(JLM_ROOT)/jlm/llvm/Makefile.sub
include $(JLM_ROOT)/jlm/rvsdg/Makefile.sub
include $(JLM_ROOT)/jlm/tooling/Makefile.sub
Expand All @@ -59,10 +61,10 @@ include $(JLM_ROOT)/docs/Makefile.sub
include $(JLM_ROOT)/tests/Makefile.sub

.PHONY: jlm-debug
jlm-debug: libutil-debug libhls-debug jlm-opt-debug jlm-hls-debug jlc-debug jhls-debug
jlm-debug: libutil-debug libhls-debug libmlir-debug jlm-opt-debug jlm-hls-debug jlc-debug jhls-debug

.PHONY: jlm-release
jlm-release: libutil-release libhls-release jlm-opt-release jlm-hls-release jlc-release jhls-release
jlm-release: libutil-release libhls-release libmlir-release jlm-opt-release jlm-hls-release jlc-release jhls-release

.PHONY: jlm-clean
jlm-clean:
Expand Down
20 changes: 20 additions & 0 deletions jlm/mlir/Makefile.sub
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Magnus Sjalander <[email protected]>
# See COPYING for terms of redistribution.

LIBMLIR_SRC = \
jlm/mlir/backend/*.cpp

.PHONY: libmlir-debug
libmlir-debug: CXXFLAGS += $(CXXFLAGS_DEBUG)
libmlir-debug: $(JLM_BUILD)/libmlir.a

.PHONY: libmlir-release
libmlir-release: CXXFLAGS += -O3
libmlir-release: $(JLM_BUILD)/libmlir.a

$(JLM_BUILD)/libmlir.a: CPPFLAGS += -I$(JLM_ROOT) -I$(shell $(LLVMCONFIG) --includedir)
$(JLM_BUILD)/libmlir.a: $(patsubst %.cpp, $(JLM_BUILD)/%.la, $(LIBMLIR_SRC))

.PHONY: libmlir-clean
libmlir-clean:
@rm -rf $(JLM_BUILD)/libmlir.a
Loading

0 comments on commit c96a863

Please sign in to comment.