Skip to content

Commit

Permalink
update CMake build
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Nov 15, 2023
1 parent 76504e2 commit c579389
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 38 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/build_and_test_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ jobs:
./externals/llvm-project
key: ${{ runner.os }}-cmake-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }}

- name: Cache mlir-tutorial build
id: cache-mlir-tutorial
uses: actions/cache@v3
with:
path: |
./build
key: ${{ runner.os }}-cmake-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }}

- name: Git config
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
Expand All @@ -47,9 +55,10 @@ jobs:
- name: Build and test mlir-tutorial
run: |
mkdir build && cd build
cmake -DLLVM_DIR=${GITHUB_WORKSPACE}/externals/llvm-project/build/lib/cmake/llvm -DMLIR_DIR=${GITHUB_WORKSPACE}/externals/llvm-project/build/lib/cmake/mlir ..
cmake -DLLVM_DIR=${GITHUB_WORKSPACE}/externals/llvm-project/build/lib/cmake/llvm -DMLIR_DIR=${GITHUB_WORKSPACE}/externals/llvm-project/build/lib/cmake/mlir -DBUILD_DEPS="ON" ..
cmake --build . --target MLIRAffineFullUnrollPasses
cmake --build . --target MLIRMulToAddPasses
cmake --build . --target MLIRNoisyPasses
cmake --build . --target mlir-headers
cmake --build . --target tutorial-opt
cmake --build . --target check-mlir-tutorial
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ bazel-mlir-tutorial
bazel-out
bazel-testlogs

# git submodule
externals

# cmake related files
# ignore the user specified CMake presets in subproject directories.
/*/CMakeUserPresets.json
Expand Down
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/externals/llvm-project)
include_directories(${PROJECT_BINARY_DIR})

message(STATUS "Fetching or-tools...")
include(FetchContent)
FetchContent_Declare(
or-tools
GIT_REPOSITORY https://github.com/google/or-tools.git
GIT_TAG main
)
FetchContent_MakeAvailable(or-tools)
message(STATUS "Done fetching or-tools")

add_subdirectory(tests)
add_subdirectory(tools)
add_subdirectory(lib)
add_subdirectory(lib)
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
# MLIR For Beginners

This is the code repository for a series of articles
on the [MLIR framework](https://mlir.llvm.org/) for building compilers.
This is the code repository for a series of articles on the
[MLIR framework](https://mlir.llvm.org/) for building compilers.

## Articles

1. [Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/)
2. [Running and Testing a Lowering](https://jeremykun.com/2023/08/10/mlir-running-and-testing-a-lowering/)
3. [Writing Our First Pass](https://jeremykun.com/2023/08/10/mlir-writing-our-first-pass/)
4. [Using Tablegen for Passes](https://jeremykun.com/2023/08/10/mlir-using-tablegen-for-passes/)
5. [Defining a New Dialect](https://jeremykun.com/2023/08/21/mlir-defining-a-new-dialect/)
6. [Using Traits](https://jeremykun.com/2023/09/07/mlir-using-traits/)
7. [Folders and Constant Propagation](https://jeremykun.com/2023/09/11/mlir-folders/)
8. [Verifiers](https://jeremykun.com/2023/09/13/mlir-verifiers/)
9. [Canonicalizers and Declarative Rewrite Patterns](https://jeremykun.com/2023/09/20/mlir-canonicalizers-and-declarative-rewrite-patterns/)
1. [Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/)
2. [Running and Testing a Lowering](https://jeremykun.com/2023/08/10/mlir-running-and-testing-a-lowering/)
3. [Writing Our First Pass](https://jeremykun.com/2023/08/10/mlir-writing-our-first-pass/)
4. [Using Tablegen for Passes](https://jeremykun.com/2023/08/10/mlir-using-tablegen-for-passes/)
5. [Defining a New Dialect](https://jeremykun.com/2023/08/21/mlir-defining-a-new-dialect/)
6. [Using Traits](https://jeremykun.com/2023/09/07/mlir-using-traits/)
7. [Folders and Constant Propagation](https://jeremykun.com/2023/09/11/mlir-folders/)
8. [Verifiers](https://jeremykun.com/2023/09/13/mlir-verifiers/)
9. [Canonicalizers and Declarative Rewrite Patterns](https://jeremykun.com/2023/09/20/mlir-canonicalizers-and-declarative-rewrite-patterns/)
10. [Dialect Conversion](https://jeremykun.com/2023/10/23/mlir-dialect-conversion/)
11. [Lowering through LLVM](https://jeremykun.com/2023/11/01/mlir-lowering-through-llvm/)


## Bazel build

Bazel is one of two supported build systems for this tutorial. The other is
CMake. If you're unfamiliar with Bazel, you can read the tutorials at
[https://bazel.build/start](https://bazel.build/start). Familiarity with Bazel
is not required to build or test, but it is required to follow the articles in
the tutorial series and explained in the first article, [Build System (Getting
Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/). The CMake
build is maintained, but was added at article 10 (Dialect Conversion) and will
not be explained in the articles.
the tutorial series and explained in the first article,
[Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/).
The CMake build is maintained, but was added at article 10 (Dialect Conversion)
and will not be explained in the articles.

### Prerequisites

Expand All @@ -51,16 +50,16 @@ bazel test ...:all

CMake is one of two supported build systems for this tutorial. The other is
Bazel. If you're unfamiliar with CMake, you can read the tutorials at
[https://cmake.org/getting-started/](https://cmake.org/getting-started/).
The CMake build is maintained, but was added at article 10 (Dialect Conversion)
and will not be explained in the articles.
[https://cmake.org/getting-started/](https://cmake.org/getting-started/). The
CMake build is maintained, but was added at article 10 (Dialect Conversion) and
will not be explained in the articles.

### Prerequisites

* Make sure you have installed everything needed to build LLVM
https://llvm.org/docs/GettingStarted.html#software
* For this recipe Ninja is used so be sure to have it as well installed
https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages
* Make sure you have installed everything needed to build LLVM
https://llvm.org/docs/GettingStarted.html#software
* For this recipe Ninja is used so be sure to have it as well installed
https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages

### Checking out the code

Expand Down Expand Up @@ -128,15 +127,18 @@ mkdir $BUILD_DIR
pushd $BUILD_DIR

LLVM_BUILD_DIR=externals/llvm-project/build
ORTOOLS_BUILD_DIR=externals/llvm-project/build
cmake -G $BUILD_SYSTEM .. \
-DLLVM_DIR="$LLVM_BUILD_DIR/lib/cmake/llvm" \
-DMLIR_DIR="$LLVM_BUILD_DIR/lib/cmake/mlir" \
-DBUILD_DEPS="ON" \
-DCMAKE_BUILD_TYPE=Debug

popd

cmake --build $BUILD_DIR --target MLIRAffineFullUnrollPasses
cmake --build $BUILD_DIR --target MLIRMulToAddPasses
cmake --build $BUILD_DIR --target MLIRNoisyPasses
cmake --build $BUILD_DIR --target mlir-headers
cmake --build $BUILD_DIR --target mlir-doc
cmake --build $BUILD_DIR --target tutorial-opt
Expand Down
2 changes: 1 addition & 1 deletion externals/llvm-project
Submodule llvm-project updated 5579 files
1 change: 1 addition & 0 deletions lib/Analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(ReduceNoiseAnalysis)
7 changes: 7 additions & 0 deletions lib/Analysis/ReduceNoiseAnalysis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_mlir_library(ReduceNoiseAnalysis
ReduceNoiseAnalysis.cpp

${PROJECT_SOURCE_DIR}/lib/Analysis/ReduceNoiseAnalysis/
ADDITIONAL_HEADER_DIRS
LINK_LIBS PUBLIC
)
3 changes: 2 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(Dialect)
add_subdirectory(Analysis)
add_subdirectory(Conversion)
add_subdirectory(Dialect)
add_subdirectory(Transform)
3 changes: 2 additions & 1 deletion lib/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(Poly)
add_subdirectory(Noisy)
add_subdirectory(Poly)
4 changes: 0 additions & 4 deletions lib/Dialect/Noisy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ add_dependencies(mlir-headers MLIRNoisyOpsIncGen)

add_mlir_doc(NoisyDialect NoisyDialect Noisy/ -gen-dialect-doc)

set(LLVM_TARGET_DEFINITIONS NoisyPatterns.td)
mlir_tablegen(NoisyCanonicalize.cpp.inc -gen-rewriters)
add_public_tablegen_target(MLIRNoisyCanonicalizationIncGen)

add_mlir_dialect_library(MLIRNoisy
NoisyDialect.cpp
NoisyOps.cpp
Expand Down
3 changes: 2 additions & 1 deletion lib/Transform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(Affine)
add_subdirectory(Arith)
add_subdirectory(Arith)
add_subdirectory(Noisy)
14 changes: 14 additions & 0 deletions lib/Transform/Noisy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_mlir_library(NoisyPasses
ReduceNoiseOptimizer.cpp

${PROJECT_SOURCE_DIR}/lib/Transform/Noisy/
ADDITIONAL_HEADER_DIRS

LINK_LIBS PUBLIC
ReduceNoiseAnalysis
)

set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Noisy)
add_public_tablegen_target(MLIRNoisyPasses)
add_mlir_doc(Passes NoisyPasses ./ -gen-pass-doc)
7 changes: 5 additions & 2 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
set (LIBS
${dialect_libs}
${conversion_libs}
MLIRPoly
AffineFullUnroll
MulToAdd
MLIRNoisy
MLIROptLib
MLIRPass
MLIRPoly
MulToAdd
NoisyPasses
PolyToStandard
ortools::ortools
)

add_llvm_executable(tutorial-opt tutorial-opt.cpp)
Expand Down

0 comments on commit c579389

Please sign in to comment.