-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MLIR][Python] add Python wheel build demo/test #160388
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
Merged
+109
−2
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# Copyright (c) 2025. | ||
|
||
[project] | ||
name = "standalone-python-bindings" | ||
dynamic = ["version"] | ||
requires-python = ">=3.8,<=3.14" | ||
dependencies = [ | ||
"numpy>=1.19.5, <=2.1.2", | ||
"PyYAML>=5.4.0, <=6.0.1", | ||
"ml_dtypes>=0.1.0, <=0.6.0; python_version<'3.13'", | ||
"ml_dtypes>=0.5.0, <=0.6.0; python_version>='3.13'", | ||
] | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/llvm/llvm-project" | ||
Discussions = "https://discourse.llvm.org/" | ||
"Issue Tracker" = "https://github.com/llvm/llvm-project/issues?q=is%3Aissue%20state%3Aopen%20label%3Amlir%3Apython%20" | ||
"Source Code" = "https://github.com/llvm/llvm-project/tree/main/mlir/python" | ||
|
||
[build-system] | ||
requires = [ | ||
"scikit-build-core>=0.10.7", | ||
"typing_extensions>=4.12.2", | ||
"nanobind>=2.9, <3.0", | ||
"pybind11>=2.10.0, <=2.13.6", | ||
] | ||
build-backend = "scikit_build_core.build" | ||
|
||
[tool.scikit-build] | ||
# This is the minimum version of scikit-build-core. | ||
minimum-version = "0.10.7" | ||
# This pyproject.toml must be adjacent to the root CMakeLists.txt (wherever project(...) is specified). | ||
cmake.source-dir = "." | ||
# This is for installing/distributing the python bindings target and only the python bindings target. | ||
build.targets = ["StandalonePythonModules"] | ||
install.components = ["StandalonePythonModules"] | ||
|
||
[tool.scikit-build.cmake.define] | ||
# Optional | ||
CMAKE_C_COMPILER = { env = "CMAKE_C_COMPILER", default = "" } | ||
CMAKE_CXX_COMPILER = { env = "CMAKE_CXX_COMPILER", default = "" } | ||
CMAKE_C_COMPILER_LAUNCHER = { env = "CMAKE_C_COMPILER_LAUNCHER", default = "" } | ||
CMAKE_CXX_COMPILER_LAUNCHER = { env = "CMAKE_CXX_COMPILER_LAUNCHER", default = "" } | ||
CMAKE_GENERATOR = { env = "CMAKE_GENERATOR", default = "Ninja" } | ||
LLVM_USE_LINKER = { env = "LLVM_USE_LINKER", default = "" } | ||
# Optional but highly recommended (this makes the bindings compatible with other bindings packages | ||
# by preventing symbol collisions). | ||
CMAKE_VISIBILITY_INLINES_HIDDEN = "ON" | ||
CMAKE_C_VISIBILITY_PRESET = "hidden" | ||
CMAKE_CXX_VISIBILITY_PRESET = "hidden" | ||
|
||
# Non-optional (alternatively you could use CMAKE_PREFIX_PATH here). | ||
MLIR_DIR = { env = "MLIR_DIR", default = "" } | ||
# Non-optional | ||
CMAKE_BUILD_TYPE = { env = "CMAKE_BUILD_TYPE", default = "Release" } | ||
MLIR_ENABLE_BINDINGS_PYTHON = "ON" | ||
# Effectively non-optional (any downstream project should specify this). | ||
MLIR_PYTHON_PACKAGE_PREFIX = "mlir_standalone" | ||
# This specifies the directory in the install directory (i.e., /tmp/pip-wheel/platlib) where _mlir_libs, dialects, etc. | ||
# are installed. Thus, this will be the package location (and the name of the package) that pip assumes is | ||
# the root package. | ||
MLIR_BINDINGS_PYTHON_INSTALL_PREFIX = "mlir_standalone" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# There's no real issue with windows here, it's just that some CMake generated paths for targets end up being longer | ||
# than 255 chars when combined with the fact that pip wants to install into a tmp directory buried under | ||
# C/Users/ContainerAdministrator/AppData/Local/Temp. | ||
# UNSUPPORTED: target={{.*(windows).*}} | ||
|
||
# RUN: export CMAKE_BUILD_TYPE=%cmake_build_type | ||
# RUN: export CMAKE_CXX_COMPILER=%host_cxx | ||
# RUN: export CMAKE_CXX_COMPILER_LAUNCHER=%hostcxx_compiler_launcher | ||
# RUN: export CMAKE_C_COMPILER=%host_cc | ||
# RUN: export CMAKE_C_COMPILER_LAUNCHER=%hostc_compiler_launcher | ||
# RUN: export CMAKE_GENERATOR=%cmake_generator | ||
# RUN: export LLVM_USE_LINKER=%llvm_use_linker | ||
# RUN: export MLIR_DIR="%mlir_cmake_dir" | ||
|
||
# RUN: %python -m pip wheel "%mlir_src_root/examples/standalone" -w "%mlir_obj_root/wheelhouse" -v | tee %t | ||
|
||
# RUN: rm -rf "%mlir_obj_root/standalone-python-bindings-install" | ||
# RUN: %python -m pip install standalone_python_bindings -f "%mlir_obj_root/wheelhouse" --target "%mlir_obj_root/standalone-python-bindings-install" -v | tee -a %t | ||
|
||
# RUN: export PYTHONPATH="%mlir_obj_root/standalone-python-bindings-install" | ||
# RUN: %python "%mlir_src_root/examples/standalone/test/python/smoketest.py" nanobind | tee -a %t | ||
|
||
# RUN: FileCheck --input-file=%t %s | ||
|
||
# CHECK: Successfully built standalone-python-bindings | ||
|
||
# CHECK: module { | ||
# CHECK: %[[C2:.*]] = arith.constant 2 : i32 | ||
# CHECK: %[[V0:.*]] = standalone.foo %[[C2]] : i32 | ||
# CHECK: } | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So this becomes the slowest test in the test suite. But only enabled if example and python is?
Uh oh!
There was an error while loading. Please reload this page.
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.
Correct. Also it's important to note that this isn't wall-clock time - the tests run in parallel. So here (ie GH pre-merge CI) there's basically no difference.