Skip to content

Commit

Permalink
Using MLIR/LLVM as a submodule.
Browse files Browse the repository at this point in the history
- It is important to stick to a certain version of MLIR/LLVM (see issue daphne-eu#1).
- Please see README.md for new instructions on cloning and pulling.
- This commit fixes daphne-eu#1.
  • Loading branch information
pdamme committed Feb 17, 2021
1 parent aa2ee33 commit 7839e5e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
thirdparty/
thirdparty/*
!thirdparty/llvm-project/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "thirdparty/llvm-project"]
path = thirdparty/llvm-project
url = https://github.com/llvm/llvm-project.git
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,42 @@ Please ensure that your system meets the following requirements before trying to
- hardware
- about 3.5 GB disk space (only for LLVM/MLIR)

## 1. Build
## 1. Obtain the source code

Simply build the prototype using `./build.sh`.
When you do this the *first* time, it will also download and build antlr4 as well as clone and build LLVM/MLIR.
The latter takes very long (can be about 30 minutes).
All *following* build should take only a few seconds.
To clean, simply delete the `build`-directory.
The prototype is based on MLIR, which is a part of the LLVM monorepo.
The LLVM monorepo is included in this repository as a submodule.
Thus, clone this repository as follows to also clone the submodule:

## 2. Run
```bash
git clone --recursive https://gitlab.know-center.tugraz.at/daphne/prototype.git
```

Upstream changes to this repository might contain changes to the submodule (we might have upgraded to a newer version of MLIR/LLVM).
Thus, please pull as follows:

```bash
# in git >= 2.14
git pull --recurse-submodules

# in git < 2.14
git pull && git submodule update --init --recursive

# or use this little convenience script
./pull.sh
```

## 2. Build

Simply build the prototype using the build-script without any arguments:

```bash
./build.sh
```

When you do this the first time, or when there were updates to the LLVM submodule, this will also download and build the third-party material, which might increase the build time significantly.
Subsequent builds, e.g., when you changed something in this repository, will be much faster.

## 3. Run

Write a little DaphneDSL script or use `example.daphne`...

Expand Down
57 changes: 36 additions & 21 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
#!/bin/bash

# This script builds the DAPHNE prototype.
#
# It also downloads and builds all required third-party material. Simply invoke
# it without any arguments.


# Stop immediately if any command fails.
set -e


#******************************************************************************
# Download thirdparty material
# Handle third-party material
#******************************************************************************

thirdpartyPath=thirdparty
mkdir --parents $thirdpartyPath
oldPwd=$(pwd)
cd $thirdpartyPath

#------------------------------------------------------------------------------
# Download third-party material if necessary
#------------------------------------------------------------------------------

# Download antlr4 jar if it does not exist yet.
antlrName=antlr-4.9.1-complete.jar
if [ ! -f $antlrName ]
then
wget https://www.antlr.org/download/$antlrName
fi

# Clone and build LLVM/MLIR if it does not exist yet.
#------------------------------------------------------------------------------
# Build MLIR
#------------------------------------------------------------------------------
# TODO Do this only when it is necessary, since cmake takes some time even if
# there is nothing to do.

llvmName=llvm-project
if [ ! -d $llvmName ]
then
git clone https://github.com/llvm/$llvmName.git
cd $llvmName
# We do not use the latest version of the MLIR/LLVM source code.
# See issue #1.
git checkout f1ff6d210a5fb45dc90d063d04b12b9da0ae4110
mkdir build
cd build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_BUILD_EXAMPLES=ON \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON
cmake --build . --target check-mlir
fi
cd $llvmName
mkdir --parents build
cd build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_BUILD_EXAMPLES=ON \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON
cmake --build . --target check-mlir

#------------------------------------------------------------------------------
# Go back
#------------------------------------------------------------------------------

cd $oldPwd


# *****************************************************************************
# Build the DAPHNE prototype.
# *****************************************************************************
Expand All @@ -50,4 +64,5 @@ cd build
cmake -G Ninja .. -DMLIR_DIR=$thirdpartyPath/$llvmName/build/lib/cmake/mlir/
cmake --build . --target daphnec


set +e
6 changes: 6 additions & 0 deletions pull.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# This script pulls upstream changes to this repository and handles all updates
# to the submodule(s).

git pull && git submodule update --init --recursive
1 change: 1 addition & 0 deletions thirdparty/llvm-project
Submodule llvm-project added at f1ff6d

0 comments on commit 7839e5e

Please sign in to comment.