From 7839e5e8a3c48b0dc2e1dc366ba45af09f857a4e Mon Sep 17 00:00:00 2001 From: Patrick Damme Date: Wed, 17 Feb 2021 16:42:54 +0100 Subject: [PATCH] Using MLIR/LLVM as a submodule. - It is important to stick to a certain version of MLIR/LLVM (see issue #1). - Please see README.md for new instructions on cloning and pulling. - This commit fixes #1. --- .gitignore | 3 ++- .gitmodules | 3 +++ README.md | 41 ++++++++++++++++++++++++----- build.sh | 57 ++++++++++++++++++++++++++--------------- pull.sh | 6 +++++ thirdparty/llvm-project | 1 + 6 files changed, 82 insertions(+), 29 deletions(-) create mode 100644 .gitmodules create mode 100755 pull.sh create mode 160000 thirdparty/llvm-project diff --git a/.gitignore b/.gitignore index 500e9d1fe..8d492b3d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ -thirdparty/ +thirdparty/* +!thirdparty/llvm-project/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..f5f664cdc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "thirdparty/llvm-project"] + path = thirdparty/llvm-project + url = https://github.com/llvm/llvm-project.git diff --git a/README.md b/README.md index 7df799d96..ca0407490 100644 --- a/README.md +++ b/README.md @@ -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`... diff --git a/build.sh b/build.sh index acb5ce058..9b63e8f5e 100755 --- a/build.sh +++ b/build.sh @@ -1,16 +1,27 @@ #!/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 ] @@ -18,29 +29,32 @@ 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. # ***************************************************************************** @@ -50,4 +64,5 @@ cd build cmake -G Ninja .. -DMLIR_DIR=$thirdpartyPath/$llvmName/build/lib/cmake/mlir/ cmake --build . --target daphnec + set +e \ No newline at end of file diff --git a/pull.sh b/pull.sh new file mode 100755 index 000000000..0fc401b40 --- /dev/null +++ b/pull.sh @@ -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 \ No newline at end of file diff --git a/thirdparty/llvm-project b/thirdparty/llvm-project new file mode 160000 index 000000000..f1ff6d210 --- /dev/null +++ b/thirdparty/llvm-project @@ -0,0 +1 @@ +Subproject commit f1ff6d210a5fb45dc90d063d04b12b9da0ae4110