Skip to content

Commit e03e677

Browse files
committed
Add GHA workflow for building MLIR Python bindings
1 parent 8a2fac8 commit e03e677

7 files changed

Lines changed: 299 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: mlir_bindings_conda_builder
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
paths:
9+
- .github/workflows/mlir_conda_builder.yml
10+
- conda-recipes/mlir-python-bindings/**
11+
workflow_dispatch:
12+
inputs:
13+
platform:
14+
description: Conda Platform
15+
default: linux-64
16+
required: true
17+
type: choice
18+
options:
19+
- all
20+
- linux-64
21+
22+
# Add concurrency control
23+
concurrency:
24+
group: >-
25+
${{ github.workflow }}-
26+
${{ (github.event_name == 'push' && github.ref)
27+
|| github.event.pull_request.number
28+
|| toJson(github.event.inputs)
29+
|| github.sha }}
30+
cancel-in-progress: true
31+
32+
env:
33+
ARTIFACT_RETENTION_DAYS: 7
34+
35+
jobs:
36+
build:
37+
name: ${{ matrix.platform }}-py${{ matrix.python-version }}-build
38+
runs-on: ${{ matrix.runner }}
39+
env:
40+
EXTRA_CHANNELS: ''
41+
defaults:
42+
run:
43+
shell: bash -elx {0}
44+
strategy:
45+
matrix: ${{fromJson(needs.check.outputs.matrix)}}
46+
fail-fast: false
47+
48+
steps:
49+
- name: Clone repository
50+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
51+
with:
52+
fetch-depth: 0
53+
54+
- name: Setup Miniconda
55+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
56+
with:
57+
auto-update-conda: true
58+
auto-activate-base: true
59+
60+
- name: Install conda-build
61+
run: conda install conda-build
62+
63+
- name: Build mlir-python-bindings conda package
64+
run: |
65+
if [ "${{ inputs.mlir_run_id }}" != "" ]; then
66+
MLIR_CHANNEL="file:///${{ github.workspace }}/mlir_conda_packages"
67+
else
68+
MLIR_CHANNEL="numba/label/dev"
69+
fi
70+
CONDA_CHANNEL_DIR="conda_channel_dir"
71+
mkdir $CONDA_CHANNEL_DIR
72+
if [ -n "${EXTRA_CHANNELS}" ]; then
73+
extra_args=(${EXTRA_CHANNELS})
74+
else
75+
extra_args=()
76+
fi
77+
conda build --debug -c "${MLIR_CHANNEL}" "${extra_args[@]}" -c defaults --python=${{ matrix.python-version }} conda-recipes/mlir-python-bindings --output-folder="${CONDA_CHANNEL_DIR}" --no-test
78+
79+
- name: Upload mlir-python-bindings conda package
80+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
81+
with:
82+
name: mlir-python-bindings-${{ matrix.platform }}-py${{ matrix.python-version }}
83+
path: conda_channel_dir
84+
compression-level: 0
85+
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
86+
if-no-files-found: error
87+
88+
- name: Show Workflow Run ID
89+
run: "echo \"Workflow Run ID: ${{ github.run_id }}\""

.gitignore

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
From a43d733a668d9cba02eeb79a49cbdaed17e3749a Mon Sep 17 00:00:00 2001
2+
From: Isuru Fernando <isuruf@gmail.com>
3+
Date: Tue, 6 Apr 2021 13:36:08 +0200
4+
Subject: [PATCH] Support cross compiling standalone MLIR
5+
6+
---
7+
mlir/CMakeLists.txt | 13 +++++++++++++
8+
1 file changed, 13 insertions(+)
9+
10+
diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
11+
index c9b0d53bc3e9..a7870efc68e5 100644
12+
--- a/mlir/CMakeLists.txt
13+
+++ b/mlir/CMakeLists.txt
14+
@@ -41,6 +41,7 @@ if(MLIR_STANDALONE_BUILD)
15+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
16+
"${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
17+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
18+
+ set(MLIR_BUILT_STANDALONE 1)
19+
20+
set(LLVM_LIT_ARGS "-sv" CACHE STRING "Default options for lit")
21+
endif()
22+
@@ -164,6 +165,18 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
23+
include_directories( "include")
24+
include_directories( ${MLIR_INCLUDE_DIR})
25+
26+
+if(CMAKE_CROSSCOMPILING AND MLIR_BUILT_STANDALONE)
27+
+ set(LLVM_USE_HOST_TOOLS ON)
28+
+ include(CrossCompile)
29+
+ if (NOT NATIVE_LLVM_DIR)
30+
+ message(FATAL_ERROR
31+
+ "Crosscompiling standalone requires the variables NATIVE_LLVM_DIR
32+
+ for building the native mlir-tblgen used during the build process.")
33+
+ endif()
34+
+ llvm_create_cross_target(mlir NATIVE "" Release
35+
+ -DLLVM_DIR=${NATIVE_LLVM_DIR})
36+
+endif()
37+
+
38+
# Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
39+
# MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
40+
# from another directory like tools
41+
--
42+
2.38.0
43+
44+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@echo on
2+
mkdir build
3+
cd build
4+
5+
cmake -GNinja ^
6+
-DCMAKE_BUILD_TYPE=Release ^
7+
-DPython_FIND_REGISTRY=NEVER ^
8+
-DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" ^
9+
-DCMAKE_PREFIX_PATH="%LIBRARY_PREFIX%" ^
10+
-DLLVM_USE_INTEL_JITEVENTS=1 ^
11+
-DLLVM_BUILD_TOOLS=ON ^
12+
-DLLVM_BUILD_UTILS=ON ^
13+
-DMLIR_ENABLE_BINDINGS_PYTHON=ON ^
14+
-DPython3_EXECUTABLE="%PYTHON%" ^
15+
..\mlir
16+
17+
if %ERRORLEVEL% neq 0 exit 1
18+
19+
ninja -j%CPU_COUNT%
20+
if %ERRORLEVEL% neq 0 exit 1
21+
22+
ninja install
23+
if not exist "%SP_DIR%" mkdir "%SP_DIR%"
24+
move "%PREFIX%"\Library\python_packages\mlir_core\mlir "%SP_DIR%"\
25+
26+
if exist "%PREFIX%"\Library\python_packages rmdir /s /q "%PREFIX%"\Library\python_packages
27+
if exist "%PREFIX%"\Library\src rmdir /s /q "%PREFIX%"\Library\src
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
if [[ "${target_platform}" == "linux-ppc64le" ]]; then
6+
export CFLAGS="${CFLAGS//-fno-plt/}"
7+
export CXXFLAGS="${CXXFLAGS//-fno-plt/}"
8+
fi
9+
10+
export BUILD_NUMPY_INCLUDE_DIRS=$( $PYTHON -c "import numpy; print (numpy.get_include())")
11+
export TARGET_NUMPY_INCLUDE_DIRS=$SP_DIR/numpy/core/include
12+
13+
echo $BUILD_NUMPY_INCLUDE_DIRS
14+
echo $TARGET_NUMPY_INCLUDE_DIRS
15+
16+
if [[ "${CONDA_BUILD_CROSS_COMPILATION:-0}" == "1" ]]; then
17+
echo "Copying files from $BUILD_NUMPY_INCLUDE_DIRS to $TARGET_NUMPY_INCLUDE_DIRS"
18+
mkdir -p $TARGET_NUMPY_INCLUDE_DIRS
19+
cp -r $BUILD_NUMPY_INCLUDE_DIRS/numpy $TARGET_NUMPY_INCLUDE_DIRS
20+
CMAKE_ARGS="${CMAKE_ARGS} -DPython3_NumPy_INCLUDE_DIR=${TARGET_NUMPY_INCLUDE_DIRS}"
21+
22+
# NATIVE_LLVM_DIR is used by what we patch in for cross-compilation
23+
CMAKE_ARGS="${CMAKE_ARGS} -DMLIR_TABLEGEN_EXE=$BUILD_PREFIX/bin/mlir-tblgen -DNATIVE_LLVM_DIR=$BUILD_PREFIX/lib/cmake/llvm"
24+
NATIVE_FLAGS="-DCMAKE_C_COMPILER=$CC_FOR_BUILD;-DCMAKE_CXX_COMPILER=$CXX_FOR_BUILD"
25+
NATIVE_FLAGS="${NATIVE_FLAGS};-DCMAKE_C_FLAGS=-O2;-DCMAKE_CXX_FLAGS=-O2"
26+
NATIVE_FLAGS="${NATIVE_FLAGS};-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,${BUILD_PREFIX}/lib"
27+
NATIVE_FLAGS="${NATIVE_FLAGS};-DCMAKE_MODULE_LINKER_FLAGS=;-DCMAKE_SHARED_LINKER_FLAGS="
28+
NATIVE_FLAGS="${NATIVE_FLAGS};-DCMAKE_STATIC_LINKER_FLAGS=;-DCMAKE_PREFIX_PATH=${BUILD_PREFIX}"
29+
CMAKE_ARGS="${CMAKE_ARGS} -DCROSS_TOOLCHAIN_FLAGS_NATIVE=${NATIVE_FLAGS}"
30+
else
31+
rm -rf $BUILD_PREFIX/bin/mlir-tblgen
32+
fi
33+
34+
mkdir -p build
35+
cd build
36+
37+
cmake ${CMAKE_ARGS} \
38+
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
39+
-DCMAKE_BUILD_TYPE=Release \
40+
-DLLVM_BUILD_LLVM_DYLIB=ON \
41+
-DLLVM_LINK_LLVM_DYLIB=ON \
42+
-DLLVM_BUILD_TOOLS=ON \
43+
-DLLVM_BUILD_UTILS=ON \
44+
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
45+
-DPython_EXECUTABLE="$PYTHON" \
46+
-DPython_INCLUDE_DIR="$PREFIX/include/python$PY_VER" \
47+
-DPython3_EXECUTABLE="$PYTHON" \
48+
-GNinja \
49+
../mlir
50+
51+
ninja
52+
ninja install
53+
54+
cd $PREFIX
55+
56+
mkdir -p $SP_DIR
57+
mv $PREFIX/python_packages/mlir_core/mlir $SP_DIR/
58+
59+
rm -rf $PREFIX/src $PREFIX/python_packages
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# we want to match compilers with mlir (since we're recompiling portions of that)
2+
c_compiler: # [osx]
3+
- clang_bootstrap # [osx]
4+
cxx_compiler: # [osx]
5+
- clang_bootstrap # [osx]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{% set version = "21.1.5" %}
2+
3+
package:
4+
name: mlir-python-bindings
5+
version: {{ version }}
6+
7+
source:
8+
- url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version.replace(".rc", "-rc") }}/llvm-project-{{ version.replace(".rc", "-rc") }}.src.tar.xz
9+
sha256: 1794be4bf974e99a3fe1da4b2b9b1456c02ae9479c942f365441d8d207bd650c
10+
patches:
11+
# https://reviews.llvm.org/D99470
12+
- 0001-Support-cross-compiling-standalone-MLIR.patch
13+
14+
build:
15+
number: 0
16+
always_include_files:
17+
# Must overwrite cmake metadata from mlir
18+
- lib/cmake/mlir/ # [unix]
19+
- Library/lib/cmake/mlir/ # [win]
20+
21+
requirements:
22+
build:
23+
- cmake
24+
- ninja
25+
- {{ compiler('cxx') }}
26+
- {{ stdlib('c') }}
27+
- llvmdev {{ version }} # [build_platform != target_platform]
28+
- cross-python_{{ target_platform }} # [build_platform != target_platform]
29+
- python # [build_platform != target_platform]
30+
- numpy # [build_platform != target_platform]
31+
- nanobind >=2.4.0 # [build_platform != target_platform]
32+
- pybind11 >=2.8.0 # [build_platform != target_platform]
33+
# for native mlir-tblgen
34+
- mlir # [build_platform != target_platform]
35+
- zlib # [build_platform != target_platform]
36+
- zstd # [build_platform != target_platform]
37+
host:
38+
- llvmdev {{ version }}
39+
- llvm {{ version }}
40+
- mlir {{ version }}
41+
- libmlir
42+
- zlib
43+
- zstd # [win]
44+
- python
45+
- numpy
46+
- nanobind >=2.4.0
47+
- pybind11 >=2.8.0
48+
run:
49+
- python
50+
- pyyaml
51+
- mlir {{ version }}
52+
# we need to do this manually because clang_bootstrap has no run-export
53+
- libcxx >={{ version }} # [osx]
54+
55+
test:
56+
imports:
57+
- mlir
58+
- mlir.ir
59+
commands:
60+
- test -f "$SP_DIR/mlir/ir.py" # [unix]
61+
- test -f "$SP_DIR/mlir/execution_engine.py" # [unix]
62+
- if not exist "%SP_DIR%"\\mlir\\ir.py exit 1 # [win]
63+
- if not exist "%SP_DIR%"\\mlir\\execution_engine.py exit 1 # [win]
64+
65+
about:
66+
home: https://mlir.llvm.org/docs/Bindings/Python/
67+
license: Apache-2.0 WITH LLVM-exception
68+
license_file: mlir/LICENSE.TXT
69+
license_family: Apache
70+
summary: Python Bindings for MLIR
71+
72+
extra:
73+
recipe-maintainers:
74+
- jim22k
75+
- conda-forge/mlir

0 commit comments

Comments
 (0)