Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 135 additions & 17 deletions .github/workflows/ci-gpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ env:
LLVM_SHA_FILE: llvm-sha.txt
LLVM_CACHE_NUMBER: 1 # Increase to reset cache

# Git ref from https://github.com/ftynse/water to checkout
WATER_REF: a04ed201cbad8927d86749f386e03a1cc847c867

jobs:
# Water uses its own LLVM version independent of the one used by IREE and
# potentially can have different compilation flags/enabled features.
Expand All @@ -43,12 +40,9 @@ jobs:
runs-on: ${{matrix.runs-on}}
timeout-minutes: 240 # Building LLVM can take multiple hours on public GH runners
steps:
- name: Checkout Water
- name: Checkout repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
repository: ftynse/water
ref: ${{ env.WATER_REF }}
path: water
fetch-depth: 0

- name: Setup Cache Vars
Expand All @@ -67,7 +61,7 @@ jobs:
run: |
sudo apt update
sudo apt install -y ninja-build cmake clang lld

pip install -r water/requirements-dev.txt

- name: Checkout LLVM
if: steps.cache-llvm-mlir.outputs.cache-hit != 'true'
Expand All @@ -92,15 +86,16 @@ jobs:
cmake ../llvm-project/llvm \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="mlir" \
-DLLVM_ENABLE_PROJECTS="mlir;llvm" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_ZSTD=OFF \
-DMLIR_INCLUDE_TESTS=OFF \
-DLLVM_USE_LINKER=lld \
-DLLVM_DISTRIBUTION_COMPONENTS="llvm-headers;llvm-libraries;cmake-exports;FileCheck;count;not;mlir-headers;mlir-libraries;mlir-cmake-exports;mlir-tblgen" \
-DLLVM_DISTRIBUTION_COMPONENTS="llvm-headers;llvm-libraries;cmake-exports;FileCheck;count;not;mlir-headers;mlir-libraries;mlir-cmake-exports;mlir-tblgen;mlir-python-sources" \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/llvm-mlir/_mlir_install
ninja install-distribution-stripped
popd
Expand Down Expand Up @@ -136,15 +131,9 @@ jobs:
echo "HAS_NO_GPU=true" >> $GITHUB_ENV
fi

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Checkout Water
- name: Checkout repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
if: ${{ env.IS_MI325 == 'true' && !cancelled() }}
with:
repository: ftynse/water
ref: ${{ env.WATER_REF }}
path: water
fetch-depth: 0

- name: Setup Cache Vars
Expand Down Expand Up @@ -248,3 +237,132 @@ jobs:
if: ${{ !cancelled() }}
run: |
mypy


test_linux_water:
name: "${{ matrix.name }} :: SHARED_LIBS ${{ matrix.shared_libs }} :: Run water tests"
strategy:
fail-fast: false
matrix:
name: [linux-mi325-1gpu-ossci-iree-org]
shared_libs: ["ON", "OFF"]
runs-on: ${{ matrix.name }}
timeout-minutes: 60
needs: build_llvm_linux

steps:
- name: Checkout repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0

- name: Setup env
run: |
sudo apt update
sudo apt install -y ninja-build cmake clang lld
pip install -r water/requirements-dev.txt

- name: Setup Cache Vars
run: |
echo "LLVM_SHA=$(cat $GITHUB_WORKSPACE/water/$LLVM_SHA_FILE)" >> $GITHUB_ENV

- name: Cache LLVM-MLIR
id: cache-llvm-mlir
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: |
llvm-mlir/_mlir_install/**
key: ${{ runner.os }}-build-llvm-${{ env.LLVM_CACHE_NUMBER }}-${{ env.LLVM_SHA }}


- name: Build water
run: |
export EXTERNAL_LIT=${GITHUB_WORKSPACE}/water/scripts/runlit.py
export LLVM_DIR=${GITHUB_WORKSPACE}/llvm-mlir/_mlir_install
mkdir -p cmake_build
cd cmake_build
export CC=clang
export CXX=clang++
cmake ${GITHUB_WORKSPACE}/water \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_DIR=${LLVM_DIR}/lib/cmake/llvm \
-DMLIR_DIR=${LLVM_DIR}/lib/cmake/mlir \
-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} \
-DLLVM_EXTERNAL_LIT=${EXTERNAL_LIT} \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DWATER_ENABLE_PYTHON=ON
cmake --build .

- name: Test water
run: |
cd cmake_build
cmake --build . --target check-water


test_linux_water_python:
name: "${{ matrix.name }} :: ${{ matrix.version }} :: Test water python package"
strategy:
fail-fast: false
matrix:
name: [linux-mi325-1gpu-ossci-iree-org]
version: ["3.10", "3.11", "3.12"]
runs-on: ${{ matrix.name }}
timeout-minutes: 60
needs: build_llvm_linux
env:
VENV_DIR: ${{ github.workspace }}/water/.water-venv

steps:
- name: Checkout repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0

- name: "Setting up Python"
id: setup_python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: ${{matrix.version}}

- name: Create Python venv
run: |
python -m venv ${VENV_DIR}
source ${VENV_DIR}/bin/activate
echo VIRTUAL_ENV=$VIRTUAL_ENV >> "$GITHUB_ENV"
echo "$VENV_DIR/bin" >> "$GITHUB_PATH"

- name: Setup env
run: |
sudo apt update
sudo apt install -y ninja-build cmake clang lld
pip install -r water/requirements-dev.txt

- name: Setup Cache Vars
run: |
echo "LLVM_SHA=$(cat $GITHUB_WORKSPACE/water/$LLVM_SHA_FILE)" >> $GITHUB_ENV

- name: Cache LLVM-MLIR
id: cache-llvm-mlir
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: |
llvm-mlir/_mlir_install/**
key: ${{ runner.os }}-build-llvm-${{ env.LLVM_CACHE_NUMBER }}-${{ env.LLVM_SHA }}

- name: Install editable python package
run: |
cd ${GITHUB_WORKSPACE}/water/build_tools/wheel
export WATER_MLIR_DIR=${GITHUB_WORKSPACE}/llvm-mlir/_mlir_install/lib/cmake/mlir
pip install -e .

- name: Run python tests
run: |
cd ${GITHUB_WORKSPACE}/water/build_tools/wheel
pytest -n auto --capture=tee-sys -vv --durations=100 --timeout=300 tests/

- name: Build python package
run: |
cd ${GITHUB_WORKSPACE}/water/build_tools/wheel
export WATER_MLIR_DIR=${GITHUB_WORKSPACE}/llvm-mlir/_mlir_install/lib/cmake/mlir
pip wheel .
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Run unit tests
if: ${{ !cancelled() }}
run: |
pytest -n 4 --capture=tee-sys -vv .
pytest -n 4 --capture=tee-sys -vv ./tests

- name: Run LIT tests
if: ${{ !cancelled() }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ version_local.json

# Output files
out

# clangd
water/.cache
46 changes: 46 additions & 0 deletions water/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.20.0)
project(water LANGUAGES CXX C)

set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")

include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
else()
# Build via external projects mechanism
set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir)
set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include)
set(MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/mlir/include)
set(MLIR_INCLUDE_DIRS "${MLIR_INCLUDE_DIR};${MLIR_GENERATED_INCLUDE_DIR}")
endif()

set(WATER_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(WATER_BINARY_DIR ${PROJECT_BINARY_DIR})
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${WATER_SOURCE_DIR}/include)
include_directories(${WATER_BINARY_DIR}/include)
link_directories(${LLVM_BUILD_LIBRARY_DIR})
add_definitions(${LLVM_DEFINITIONS})

add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(test)
add_subdirectory(tools)
121 changes: 121 additions & 0 deletions water/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Water 💧

Water forms waves 🌊, and hosts sharks 🦈 and other eerie creatures 👻.

Water is a collection of [MLIR](https://mlir.llvm.org) components including
passes, dialects and interfaces usable in other projects.

## Building

### Component Build

This setup assumes that you have built LLVM and MLIR in `$BUILD_DIR`.

```sh
cmake -G Ninja \
-B build \
-DMLIR_DIR=$BUILD_DIR/lib/cmake/mlir \
-DBUILD_SHARED_LIBS=On
cmake --build build --target check-water
```

### Monolithic Build

This setup assumes that you build the project as part of a monolithic LLVM
build via the `LLVM_EXTERNAL_PROJECTS` mechanism. To build LLVM, MLIR, the
example and launch the tests run

```sh
cmake -G Ninja \
-B build \
$LLVM_SRC_DIR/llvm \
-DLLVM_TARGETS_TO_BUILD=host \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_EXTERNAL_PROJECTS=water \
-DLLVM_EXTERNAL_WATER_SOURCE_DIR=$PWD \
-DBUILD_SHARED_LIBS=On
cmake --build build --target check-water
```

Here, `$LLVM_SRC_DIR` needs to point to the root of the monorepo.

### Useful Cmake Flags

* `-DCMAKE_BUILD_TYPE=RelWithDebInfo` - build with optimizations but preserve
debug information.
* `-DBUILD_SHARED_LIBS=Off` - build static libraries, increases build time and
**may lead to missing library dependencies**, may be necessary to avoid LLVM
version conflicts in binary distributions.
* `-DCMAKE_C_COMPILER_LAUNCHER=ccache` - use ccache for C files.
* `-DCMAKE_CXX_COMPILER_LAUNCHER=ccache` - use ccache for C++ files.
* `-DLLVM_PARALLEL_LINK_JOBS=1` - disable parallel linking, helps with build
times and out-of-memory errors on low-memory machines.
* `-DCMAKE_EXPORT_COMPILE_COMMANDS=On` - generate `compile_commands.json` used
by IDEs to discover the source file tree.

### Python Wheel

A Python wheel containing the `water-opt` binary can be produced using the
following commands:

```sh
cd build_tools/wheel
WATER_MLIR_DIR=$BUILD_DIR/lib/cmake/mlir python -m pip wheel .
```

This will produce a `.whl` file containing the `water-opt` and metadata. It can
be installed using:

```sh
pip install --force-reinstall *.whl
```

Note that force-reinstallation flag without which the wheel may not be
reinstalled without bumping the version.

The package build can be configured to checkout and build LLVM from source by
setting the `WATER_BUILD_LLVM` environment variable to `1`:

```sh
cd build_tools/wheel
WATER_BUILD_LLVM=1 python -m pip wheel .
```

The build mode is controlled by the `WATER_BUILD_TYPE` environment variable
whose content is forward to cmake.

An editable build allows you to modify the python code and have the changes
immediately reflected without reinstalling the package. This is useful during
development. To install an editable build:

```sh
cd build_tools/wheel
WATER_MLIR_DIR=$BUILD_DIR/lib/cmake/mlir python -m pip install -e .
```

Note that editable builds still require rebuilding native parts when they are
modified.

## Developing

### Pre-commit

Please use pre-commit by installing it from
[pre-commit.com](https://pre-commit.com) or system repository and running

```sh
pre-commit install
pre-commit install --hook-type commit-msg
```

in the repository once. After that, every further commit will run through the
pre-commit checks such as formatters and linters. If any problems are found,
please fix them and amend the commit before pushing.

Pre-commit hooks require `black` and `gem` to be available on the system.

### Certificate of Origin

Please follow the [Developer Certificate of
Origin](https://wiki.linuxfoundation.org/dco) policy by signing off the
commits, e.g., use `git commit -s` to automatically add the required field.
1 change: 1 addition & 0 deletions water/build_tools/wheel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
water_mlir/bin/
8 changes: 8 additions & 0 deletions water/build_tools/wheel/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"cmake",
"ninja",
]
build-backend = "setuptools.build_meta"
Loading
Loading