-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generating build files with cmake #21
Changes from all commits
b4264ce
641f13e
e4b100f
43b8cec
e9afcd6
6a781af
10b074a
95316ed
7b7de0a
0b0f570
7a0c5b1
6564842
2b69d46
38b7102
c44cb50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Build and Test | ||
name: Build and Test w/Bazel | ||
permissions: read-all | ||
on: | ||
push: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Build and Test w/CMake | ||
permissions: read-all | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: seanmiddleditch/gha-setup-ninja@master | ||
|
||
- name: Install prerequisites | ||
run: | | ||
sudo apt update | ||
sudo apt install -y uuid-dev | ||
|
||
- name: Cache LLVM artifact | ||
id: cache-llvm | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
./externals/llvm-project | ||
key: ${{ runner.os }}-norm-${{ hashFiles('externals/llvm-project/llvm/CMakeLists.txt') }} | ||
|
||
- name: Build LLVM | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' | ||
run: | | ||
git submodule update --init --recursive | ||
cd externals/llvm-project | ||
mkdir build && cd build | ||
cmake -G Ninja ../llvm -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_BUILD_EXAMPLES=ON -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=ON -DLLVM_TARGETS_TO_BUILD="host" | ||
cmake --build . --target check-mlir | ||
|
||
- name: Build and test mlir-tutorial | ||
run: | | ||
mkdir build && cd build | ||
cmake -DLLVM_DIR=$PWD/../externals/llvm-project/build/lib/cmake/llvm -DMLIR_DIR=$PWD/../externals/llvm-project/build/lib/cmake/mlir .. | ||
cmake --build . --target MLIRAffineFullUnrollPasses | ||
cmake --build . --target MLIRMulToAddPasses | ||
cmake --build . --target mlir-headers | ||
cmake --build . --target tutorial-opt | ||
cmake --build . --target check-mlir-tutorial |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be worthwhile to have the git submodule sync with the commit in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be indeed nice to be able to keep in sync the llvm commit for both build systems, I guess a note as you propose would be enough as i dont think this will change often. As a side note, I remember using a llvm checkout from september when i started to do the Cmake work and there were already some build errors due to some changes in MLIR. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "externals/llvm-project"] | ||
path = externals/llvm-project | ||
url = https://github.com/llvm/llvm-project.git |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
project(mlir-tutorial LANGUAGES CXX C) | ||
|
||
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") | ||
|
||
find_package(MLIR REQUIRED CONFIG) | ||
|
||
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") | ||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") | ||
|
||
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) | ||
|
||
include(AddLLVM) | ||
include(TableGen) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") | ||
include(AddMLIR) | ||
include_directories(${LLVM_INCLUDE_DIRS}) | ||
include_directories(${MLIR_INCLUDE_DIRS}) | ||
include_directories(${PROJECT_SOURCE_DIR}) | ||
include_directories(${PROJECT_SOURCE_DIR}/externals/llvm-project) | ||
include_directories(${PROJECT_BINARY_DIR}) | ||
|
||
add_subdirectory(tests) | ||
add_subdirectory(tools) | ||
add_subdirectory(lib) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_subdirectory(Dialect) | ||
add_subdirectory(Transform) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(Poly) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Inlining `add_mlir_dialect(Poly poly)` commands so that | ||
# we can custom name `*.inc` generated files. | ||
set(LLVM_TARGET_DEFINITIONS PolyOps.td) | ||
mlir_tablegen(PolyOps.h.inc -gen-op-decls) | ||
mlir_tablegen(PolyOps.cpp.inc -gen-op-defs) | ||
mlir_tablegen(PolyTypes.h.inc -gen-typedef-decls -typedefs-dialect=poly) | ||
mlir_tablegen(PolyTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=poly) | ||
mlir_tablegen(PolyDialect.h.inc -gen-dialect-decls -dialect=poly) | ||
mlir_tablegen(PolyDialect.cpp.inc -gen-dialect-defs -dialect=poly) | ||
add_public_tablegen_target(MLIRPolyOpsIncGen) | ||
add_dependencies(mlir-headers MLIRPolyOpsIncGen) | ||
|
||
add_mlir_doc(PolyDialect PolyDialect Poly/ -gen-dialect-doc) | ||
|
||
set(LLVM_TARGET_DEFINITIONS PolyPatterns.td) | ||
mlir_tablegen(PolyCanonicalize.cpp.inc -gen-rewriters) | ||
add_public_tablegen_target(MLIRPolyCanonicalizationIncGen) | ||
|
||
add_mlir_dialect_library(MLIRPoly | ||
PolyDialect.cpp | ||
PolyOps.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
${PROJECT_SOURCE_DIR}/lib/Dialect/Poly | ||
|
||
LINK_LIBS PUBLIC | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
add_mlir_library(AffineFullUnroll | ||
AffineFullUnroll.cpp | ||
AffineFullUnrollPatternRewrite.cpp | ||
|
||
${PROJECT_SOURCE_DIR}/lib/Transform/Affine/ | ||
ADDITIONAL_HEADER_DIRS | ||
LINK_LIBS PUBLIC | ||
) | ||
|
||
set(LLVM_TARGET_DEFINITIONS Passes.td) | ||
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Affine) | ||
add_public_tablegen_target(MLIRAffineFullUnrollPasses) | ||
add_mlir_doc(Passes AffinePasses ./ -gen-pass-doc) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add_mlir_library(MulToAdd | ||
MulToAdd.cpp | ||
|
||
${PROJECT_SOURCE_DIR}/lib/Transform/Arith/ | ||
ADDITIONAL_HEADER_DIRS | ||
LINK_LIBS PUBLIC | ||
) | ||
|
||
set(LLVM_TARGET_DEFINITIONS Passes.td) | ||
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Arith) | ||
add_public_tablegen_target(MLIRMulToAddPasses) | ||
add_mlir_doc(Passes ArithPasses ./ -gen-pass-doc) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_subdirectory(Affine) | ||
add_subdirectory(Arith) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
configure_lit_site_cfg( | ||
${CMAKE_CURRENT_SOURCE_DIR}/lit.cmake.site.cfg.py.in | ||
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py | ||
MAIN_CONFIG | ||
${CMAKE_CURRENT_SOURCE_DIR}/lit.cmake.cfg.py | ||
) | ||
|
||
set (MLIR_TUTORIAL_TEST_DEPENDS | ||
FileCheck count not | ||
mlir-opt | ||
mlir-cpu-runner | ||
# tutorial-opt | ||
) | ||
|
||
add_lit_testsuite(check-mlir-tutorial "Running the MLIR tutorial regression tests" | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
DEPENDS ${MLIR_TUTORIAL_TEST_DEPENDS} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- Python -*- | ||
|
||
import os | ||
|
||
import lit.formats | ||
import lit.util | ||
|
||
from lit.llvm import llvm_config | ||
|
||
# Configuration file for the 'lit' test runner. | ||
|
||
# name: The name of this test suite. | ||
config.name = "MLIR_TUTORIAL" | ||
|
||
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) | ||
|
||
# suffixes: A list of file extensions to treat as test files. | ||
config.suffixes = [".mlir"] | ||
|
||
# test_source_root: The root path where tests are located. | ||
config.test_source_root = os.path.dirname(__file__) | ||
|
||
# test_exec_root: The root path where tests should be run. | ||
config.test_exec_root = os.path.join(config.project_binary_dir, "tests") | ||
|
||
config.substitutions.append(("%PATH%", config.environment["PATH"])) | ||
config.substitutions.append(("%shlibext", config.llvm_shlib_ext)) | ||
|
||
llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"]) | ||
|
||
llvm_config.use_default_substitutions() | ||
|
||
# excludes: A list of directories to exclude from the testsuite. The 'Inputs' | ||
# subdirectories contain auxiliary inputs for various tests in their parent | ||
# directories. | ||
config.excludes = ["Inputs", "Examples", "CMakeLists.txt", "README.txt", "LICENSE.txt"] | ||
|
||
# test_exec_root: The root path where tests should be run. | ||
config.test_exec_root = os.path.join(config.project_binary_dir, "test") | ||
config.project_tools_dir = os.path.join(config.project_binary_dir, "tools") | ||
|
||
# Tweak the PATH to include the tools dir. | ||
llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True) | ||
|
||
tool_dirs = [config.project_tools_dir, config.llvm_tools_dir] | ||
tools = [ | ||
"mlir-opt", | ||
"mlir-cpu-runner", | ||
"tutorial-opt" | ||
] | ||
|
||
llvm_config.add_tool_substitutions(tools, tool_dirs) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@LIT_SITE_CFG_IN_HEADER@ | ||
|
||
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@") | ||
config.mlir_obj_dir = "@MLIR_BINARY_DIR@" | ||
config.llvm_shlib_ext = "@SHLIBEXT@" | ||
config.project_binary_dir = "@PROJECT_BINARY_DIR@" | ||
config.project_source_dir = "@PROJECT_SOURCE_DIR@" | ||
|
||
import lit.llvm | ||
lit.llvm.initialize(lit_config, config) | ||
|
||
# Let the main config do the real work. | ||
lit_config.load_config(config, "@PROJECT_SOURCE_DIR@/tests/lit.cmake.cfg.py") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) | ||
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) | ||
|
||
set (LIBS | ||
${dialect_libs} | ||
${conversion_libs} | ||
MLIRPoly | ||
AffineFullUnroll | ||
MulToAdd | ||
MLIROptLib | ||
MLIRPass | ||
) | ||
|
||
add_llvm_executable(tutorial-opt tutorial-opt.cpp) | ||
|
||
llvm_update_compile_flags(tutorial-opt) | ||
target_link_libraries(tutorial-opt PRIVATE ${LIBS}) | ||
|
||
mlir_check_all_link_libraries(tutorial-opt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: might be better to use
$github_workspace/externals/...
instead of the relative versionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, will change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in #24