-
-
Notifications
You must be signed in to change notification settings - Fork 59
MLIR Plugin #881
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
MLIR Plugin #881
Changes from all commits
2a04dd5
65f34e7
c2e0cda
203049f
270fd6d
74a7ce9
cec21b4
ffedad9
95b7951
8167e6f
35c01bf
c230d99
705ac5d
116bb7f
d5471b9
4bd1af9
8c42d30
2680a1e
ec8bedd
43f2bc2
294272f
9ab3ef4
c43b7cc
c0ee59f
388acf3
54d4dec
ea57507
7015cf3
745b26a
7dda34a
624b5fa
4b69fa2
cbc97e9
7a97880
fa3e096
9900215
77266d3
4d76e3b
3d082df
cd575bf
e3fe319
ad33833
8124ce3
70afd91
173e971
3feaa26
aaa2188
d7d1783
f1b333f
4b0d47e
e385ea5
a314f38
90dcb7b
e80f154
29b121d
8f804a2
962802b
e9a3b56
098c174
43333de
9179a40
d9957f0
989adfd
14e5732
106fa7d
68142d6
9255e49
f7dce4c
04a43f3
063b184
e7aed92
610a8d9
039cffc
337ed02
78e6291
7d874be
e178ed8
bec9939
e045f05
dd8cfb3
1afa51a
3b2c9dd
04f134d
7668673
60f7c22
e2fde36
3de0827
8686445
8fa8c0d
dfa1d9d
f80355e
a682d93
d641451
81b0e36
ea46083
810ad4b
48802d4
5532a39
6358288
5953de0
a83ecf6
163d7d1
0b0b6d8
fbfcf8c
41ad6a7
1667c4a
5b1f072
32c4fdf
48ea811
6a6c59f
ee084fd
f9b32a2
db60591
6e829f2
54859f9
d2c7fec
ee20add
aa6bce6
9daf5d3
87ab895
ed9a3f3
2374378
fec7946
d80d1e4
12c47bf
9a52a78
857b368
4a7bf6e
778ae8f
b053818
dbb2bb0
45ee5e1
11c308e
f4580a3
f84706e
df10af6
f8215ca
541c7ca
52023c1
5e46c40
5d3df91
be0ba8e
3f11c3c
1250676
b10f91b
fca7d10
a876914
108bb60
0fbdcfc
d48decf
8142c08
906ca09
e7d8109
ac126cd
b31f55e
00b2661
5e642d7
3bcc78a
bca11f7
7a4c649
a92555a
3110870
e1193f5
0acca05
23c1fd7
559648d
708f2c8
59bcd6e
fcf3f5d
81ee0af
1496eb8
c9e0c9f
bad986e
ef302a7
2e7dc88
cd7916c
ac029e8
2ea817b
dd33fbf
cec133f
2830e66
1a49e72
f273fa4
08a5565
0d79329
0755907
fd2c784
e3ef2e9
3fe4e05
70be761
54c1dd7
abc676d
1906761
fe20c95
54a4ec1
b50d557
7443c3a
c8af436
c789e97
443ea2f
349e952
e1e300c
8eec5c7
3721891
fd43fba
36a5d50
886e71d
2032b9e
b071000
3d44546
f518011
71065ab
d6fec59
36b52da
f7f806b
38c779c
d40fa29
f79d5a9
465242a
70c4596
cc88071
7b95c7b
90c25d1
3fe4813
2239690
153b6e6
d5e808f
6f64f36
d0da45f
df0cf97
1f8adb6
d7c44d2
c447429
f7276ee
250abd3
0d2faa7
5690729
7e01857
b1ad57a
3e21e5e
5153ce8
2dd0a1c
f3cd62b
53fb679
62dd819
f422efc
01c91f3
e2efc99
fc8a852
7f8dfb5
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,5 @@ | ||
| FormatStyle: file | ||
| HeaderFilterRegex: "^(?!.*plugins/).*" | ||
|
|
||
| Checks: | | ||
| bugprone-*, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -155,7 +155,7 @@ jobs: | |||||
| name: 🇨 Lint | ||||||
| needs: change-detection | ||||||
| if: fromJSON(needs.change-detection.outputs.run-cpp-linter) | ||||||
| uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-linter.yml@ea4fccbb432596cbb6840a9608d6376b6b2c8ff7 # v1.17.2 | ||||||
| uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-linter.yml@v1.17 | ||||||
|
Contributor
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. 🧩 Analysis chain🏁 Script executed: # First, let's read the ci.yml file to see the actual content around line 158
cat -n .github/workflows/ci.yml | sed -n '1,250p'Repository: munich-quantum-toolkit/core Length of output: 11093 Inconsistent workflow reference format and version mismatch on line 158. Line 158 uses - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-linter.yml@v1.17
+ uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-linter.yml@ea4fccbb432596cbb6840a9608d6376b6b2c8ff7 # v1.17.2📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| with: | ||||||
| cmake-args: -DBUILD_MQT_CORE_BENCHMARKS=ON -DBUILD_MQT_CORE_MLIR=ON -DBUILD_MQT_CORE_BINDINGS=ON | ||||||
| clang-version: 21 | ||||||
|
|
@@ -164,6 +164,7 @@ jobs: | |||||
| setup-python: true | ||||||
| install-pkgs: "pybind11==3.0.0" | ||||||
| cpp-linter-extra-args: "-std=c++20" | ||||||
| cpp-linter-ignore-extra: "plugins/**" | ||||||
|
|
||||||
| python-tests: | ||||||
| name: 🐍 Test | ||||||
|
|
@@ -243,6 +244,9 @@ jobs: | |||||
| mlir-tests: | ||||||
| name: 🐉 Test | ||||||
| needs: change-detection | ||||||
| permissions: | ||||||
| contents: read | ||||||
| id-token: write | ||||||
| if: fromJSON(needs.change-detection.outputs.run-mlir) | ||||||
| uses: ./.github/workflows/reusable-mlir-tests.yml | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| name: MLIR Plugin CI | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "plugins/**" | ||
| pull_request: | ||
| paths: | ||
| - "plugins/**" | ||
| - ".github/workflows/ci_mlir_plugin.yml" | ||
| merge_group: | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| cpp-test-mlir-catalyst-plugin-exact-mlir: | ||
| name: 🧩 Test MLIR Catalyst Plugin on ${{ matrix.runs-on }} from exact MLIR source | ||
| runs-on: ${{ matrix.runs-on }} | ||
| strategy: | ||
| matrix: | ||
| runs-on: [ubuntu-24.04, ubuntu-24.04-arm, macos-14] | ||
| fail-fast: false | ||
| env: | ||
| CMAKE_BUILD_PARALLEL_LEVEL: 4 | ||
| CTEST_PARALLEL_LEVEL: 4 | ||
| FORCE_COLOR: 3 | ||
| steps: | ||
| # Check out the repository | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| # set up gcc as compiler | ||
| - name: Set up GCC as compiler | ||
| if: runner.os == 'Linux' | ||
| run: | | ||
| echo "C_COMPILER=gcc-14" >> $GITHUB_ENV | ||
| echo "CXX_COMPILER=g++-14" >> $GITHUB_ENV | ||
| echo "CC=gcc-14" >> $GITHUB_ENV | ||
| echo "CXX=g++-14" >> $GITHUB_ENV | ||
|
|
||
| # set up ccache for faster C++ builds | ||
| - name: Setup ccache | ||
| uses: Chocobo1/setup-ccache-action@v1 | ||
| with: | ||
| prepend_symlinks_to_path: false | ||
| override_cache_key: mlir-plugin-${{ matrix.runs-on }}-exact-mlir | ||
|
|
||
|
flowerthrower marked this conversation as resolved.
|
||
| # Set up uv for faster Python package management | ||
| - name: Install the latest version of uv | ||
| uses: astral-sh/setup-uv@v6 | ||
| with: | ||
| python-version: 3.13 | ||
| activate-environment: true | ||
|
|
||
| # Check out the LLVM commit Catalyst is based on | ||
| - name: Checkout llvm | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: llvm/llvm-project | ||
| ref: f8cb7987c64dcffb72414a40560055cb717dbf74 | ||
| path: llvm-project | ||
|
|
||
| # Install LLVM | ||
| - name: Install LLVM | ||
| working-directory: llvm-project | ||
| run: | | ||
| cmake \ | ||
| -S llvm \ | ||
| -B build_llvm \ | ||
| -G Ninja \ | ||
| -DLLVM_ENABLE_PROJECTS=mlir \ | ||
| -DLLVM_BUILD_EXAMPLES=OFF \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DLLVM_BUILD_TESTS=OFF \ | ||
| -DLLVM_INCLUDE_TESTS=OFF \ | ||
| -DLLVM_INCLUDE_EXAMPLES=OFF \ | ||
| -DLLVM_ENABLE_ASSERTIONS=ON \ | ||
| -DLLVM_ENABLE_ZLIB=FORCE_ON \ | ||
| -DLLVM_ENABLE_ZSTD=OFF \ | ||
| -DCMAKE_CXX_VISIBILITY_PRESET=default | ||
| cmake --build build_llvm --config Release | ||
|
flowerthrower marked this conversation as resolved.
|
||
| echo "MLIR_DIR=$(pwd)/build_llvm/lib/cmake/mlir" >> $GITHUB_ENV | ||
| echo "LLVM_DIR=$(pwd)/build_llvm/lib/cmake/llvm" >> $GITHUB_ENV | ||
|
|
||
|
flowerthrower marked this conversation as resolved.
|
||
| # Build the plugin package | ||
| - name: Build mqt-core-catalyst-plugin | ||
| working-directory: plugins/catalyst | ||
| run: uv sync --verbose --active | ||
|
|
||
| # Print shared library dependencies for the plugin | ||
| - name: Print shared library dependencies for mqt-core-catalyst-plugin | ||
| run: | | ||
| if [ "$(uname)" = "Linux" ]; then | ||
| ldd .venv/lib/python3.13/site-packages/mqt/core/plugins/catalyst/mqt-core-catalyst-plugin.so || true | ||
| elif [ "$(uname)" = "Darwin" ]; then | ||
| otool -l .venv/lib/python3.13/site-packages/mqt/core/plugins/catalyst/mqt-core-catalyst-plugin.dylib || true | ||
| fi | ||
|
|
||
|
flowerthrower marked this conversation as resolved.
|
||
| # Print shared library dependencies for Catalyst | ||
| - name: Print shared library dependencies for Catalyst | ||
| run: | | ||
| if [ "$(uname)" = "Linux" ]; then | ||
| ldd $(which catalyst) || true | ||
| elif [ "$(uname)" = "Darwin" ]; then | ||
| otool -l $(which catalyst) || true | ||
| fi | ||
|
flowerthrower marked this conversation as resolved.
|
||
|
|
||
| # Reconfigure CMake for LIT | ||
| - name: Reconfigure CMake for LIT | ||
| working-directory: plugins/catalyst | ||
| run: | | ||
| BUILD_DIR=$(find build -type d -name Release | head -n1) | ||
| if [ -z "$BUILD_DIR" ]; then | ||
| BUILD_DIR="build" | ||
| fi | ||
|
Comment on lines
+117
to
+120
Contributor
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. 🧹 Nitpick | 🔵 Trivial BUILD_DIR detection logic is duplicated across three steps. The same BUILD_DIR detection pattern (find Release subdir, fallback to "build") appears in three places. This is a code smell that violates DRY and makes future maintenance harder. Consider extracting this to a reusable shell function or GitHub Actions composite action. For example, define a shell function early in the workflow: detect_build_dir() {
local dir=$(find build -type d -name Release | head -n1)
echo "${dir:-build}"
}Then call it in each step: - name: Reconfigure CMake for LIT
working-directory: plugins/catalyst
run: |
+ detect_build_dir() {
+ local dir=$(find build -type d -name Release | head -n1)
+ echo "${dir:-build}"
+ }
- BUILD_DIR=$(find build -type d -name Release | head -n1)
- if [ -z "$BUILD_DIR" ]; then
- BUILD_DIR="build"
- fi
+ BUILD_DIR=$(detect_build_dir)Repeat for the clang-tidy and LIT test steps. Also applies to: 138-141, 178-181 🤖 Prompt for AI Agents |
||
|
|
||
| # Verify lit is installed, install if missing | ||
| if ! command -v lit &> /dev/null; then | ||
| echo "lit not found, installing..." | ||
| python -m pip install lit | ||
| fi | ||
|
|
||
| cmake -S . \ | ||
| -B "$BUILD_DIR" \ | ||
| -DLLVM_EXTERNAL_LIT=$(which lit) \ | ||
| -DPython3_EXECUTABLE=$(which python) \ | ||
| -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | ||
|
|
||
|
flowerthrower marked this conversation as resolved.
|
||
| # Run clang-tidy on plugin code | ||
| - name: Run clang-tidy on plugin | ||
| working-directory: plugins/catalyst | ||
| run: | | ||
| BUILD_DIR=$(find build -type d -name Release | head -n1) | ||
| if [ -z "$BUILD_DIR" ]; then | ||
| BUILD_DIR="build" | ||
| fi | ||
|
|
||
| # Check if compilation database exists | ||
| if [ ! -f "$BUILD_DIR/compile_commands.json" ]; then | ||
| echo "No compilation database found, skipping clang-tidy" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Find all C++ source files in the plugin | ||
| FILES=$(find lib include -name "*.cpp" -o -name "*.h" 2>/dev/null || true) | ||
| if [ -z "$FILES" ]; then | ||
| echo "No C++ files found to analyze" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Find Catalyst include directory | ||
| CATALYST_INCLUDE=$(find .venv -path "*/catalyst/include" -type d | head -n1) | ||
| if [ -z "$CATALYST_INCLUDE" ]; then | ||
| echo "Catalyst include directory not found, running without extra includes" | ||
| EXTRA_ARGS="" | ||
| else | ||
| echo "Found Catalyst includes at: $CATALYST_INCLUDE" | ||
| EXTRA_ARGS="--extra-arg=-I$CATALYST_INCLUDE" | ||
| fi | ||
|
|
||
| echo "Running clang-tidy on plugin files..." | ||
| echo "$FILES" | xargs clang-tidy \ | ||
| -p="$BUILD_DIR" \ | ||
| --config-file=.clang-tidy \ | ||
| --format-style=file \ | ||
| $EXTRA_ARGS \ | ||
| || echo "clang-tidy completed with warnings" | ||
|
|
||
| # Run the MLIR LIT tests | ||
| - name: Run LIT tests | ||
| working-directory: plugins/catalyst | ||
| run: | | ||
| BUILD_DIR=$(find build -type d -name Release | head -n1) | ||
| if [ -z "$BUILD_DIR" ]; then | ||
| BUILD_DIR="build" | ||
| fi | ||
| ninja -C "$BUILD_DIR" check-mqt-core-catalyst-plugin | ||
|
|
||
|
flowerthrower marked this conversation as resolved.
|
||
| # Run the plugin Python tests | ||
| - name: Run pytest for mqt-core-catalyst-plugin | ||
| working-directory: plugins/catalyst | ||
| run: python -m pytest -s --verbose | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| BasedOnStyle: InheritParentConfig |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| InheritParentConfig: true | ||
| HeaderFilterRegex: ".*" | ||
|
flowerthrower marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Copyright (c) 2023 - 2025 Chair for Design Automation, TUM | ||
| # Copyright (c) 2025 Munich Quantum Software Company GmbH | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # Licensed under the MIT License | ||
|
|
||
| # set required cmake version | ||
| cmake_minimum_required(VERSION 3.24...4.0) | ||
|
|
||
| project( | ||
| mqt-core-catalyst-plugin | ||
| LANGUAGES C CXX | ||
| VERSION 0.1.0 | ||
| DESCRIPTION "MQT Core MLIR Plugin for Catalyst") | ||
|
|
||
| set(CMAKE_CXX_STANDARD | ||
| 20 | ||
| CACHE STRING "C++ standard to conform to") | ||
|
|
||
| if(ENABLE_COVERAGE) | ||
| add_compile_options(--coverage -O0) | ||
| add_link_options(--coverage) | ||
| endif() | ||
|
flowerthrower marked this conversation as resolved.
|
||
|
|
||
| include(cmake/ExternalDependencies.cmake) | ||
|
|
||
| set(MQT_MLIR_PLUGIN_SOURCE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") | ||
| set(MQT_MLIR_PLUGIN_BUILD_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include") | ||
|
|
||
| # MLIR must be installed on the system | ||
| find_package(MLIR REQUIRED CONFIG) | ||
|
|
||
| # Add the paths to the MLIR and LLVM CMake modules. | ||
| list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") | ||
| list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") | ||
|
|
||
| # Include the TableGen, LLVM and MLIR CMake modules. | ||
| include(TableGen) | ||
| include(AddLLVM) | ||
| include(AddMLIR) | ||
| include(HandleLLVMOptions) | ||
|
|
||
| include_directories(${LLVM_INCLUDE_DIRS}) | ||
| include_directories(${MLIR_INCLUDE_DIRS}) | ||
| include_directories(BEFORE ${MQT_MLIR_PLUGIN_SOURCE_INCLUDE_DIR}) | ||
| include_directories(BEFORE ${MQT_MLIR_PLUGIN_BUILD_INCLUDE_DIR}) | ||
| include_directories(${CATALYST_INCLUDE_DIRS}) | ||
|
|
||
|
burgholzer marked this conversation as resolved.
|
||
| link_directories(${LLVM_BUILD_LIBRARY_DIR}) | ||
| add_definitions(${LLVM_DEFINITIONS}) | ||
|
|
||
|
burgholzer marked this conversation as resolved.
|
||
| if(APPLE) | ||
| set(BASEPOINT @loader_path) | ||
| else() | ||
| set(BASEPOINT $ORIGIN) | ||
| endif() | ||
| set(CMAKE_INSTALL_RPATH ${BASEPOINT} ${BASEPOINT}/${CMAKE_INSTALL_LIBDIR}) | ||
| set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) | ||
| set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) | ||
|
|
||
|
burgholzer marked this conversation as resolved.
|
||
| add_subdirectory(include) | ||
| add_subdirectory(lib) | ||
| add_subdirectory(test) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| MIT License | ||
|
flowerthrower marked this conversation as resolved.
|
||
|
|
||
| Copyright (c) 2023 - 2025 Chair for Design Automation, TUM | ||
| Copyright (c) 2025 Munich Quantum Software Company GmbH | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
|
flowerthrower marked this conversation as resolved.
|
||
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.
The version reference format changed from a specific commit hash to a version tag (v1.17). While this is more readable, it's less deterministic than pinning to a specific commit. Consider documenting this change if intentional.