Skip to content
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][python] add pyproject.toml #124878

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

makslevental
Copy link
Contributor

@makslevental makslevental commented Jan 29, 2025

It frequently comes up that we don't describe/document how to distribute the python bindings (as a wheel or otherwise). There are lots of downstream examples but these are probably unknown/obscure to novices.

This PR introduces a relatively simple (and differing from the aforementioned examples) way to build and package the bindings as a wheel. It uses scikit-build-core to (effectively) drive cmake. It can be combined with cibuildwheel to produce manylinux wheels.

In principle it maybe belongs under mlir/examples/standalone/python because it's not comprehensive (and maybe I'll move there after strong protest) but that would make it specifically an example of how to build standalone bindings rather than upstream bindings.

Anyway the point of putting this up is so we can iterate so that we have something to point people at.

Also I'm not quite sure how to test this; build-dir = "../../build" is set such that it coincides (I believe?) with the typical build directory so the wheel can be built quickly after a full source build but it will take changing the CI scripts to actually do this (and then run a test).

@makslevental makslevental force-pushed the users/makslevental/pyprojecttoml branch 2 times, most recently from cc50efd to 3d49f32 Compare January 29, 2025 05:42
@makslevental makslevental marked this pull request as ready for review January 29, 2025 05:46
@makslevental makslevental requested a review from jpienaar January 29, 2025 05:46
@llvmbot llvmbot added mlir:python MLIR Python bindings mlir labels Jan 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2025

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

It frequently comes up that we don't describe/document how to distribute the python bindings (as a wheel or otherwise). There are lots of downstream examples but these are probably unknown/obscure to novices.

This PR introduces a relatively simple (and differing from the aforementioned examples) way to build and package the bindings as a wheel. It uses scikit-build-core to (effectively) drive cmake. It can be combined with cibuildwheel to produce manylinux wheels.

In principle it maybe belongs under mlir/examples/standalone/python because it's not comprehensive (and maybe I'll move there after strong protest) but that would make it specifically an example of how to build standalone bindings rather than upstream bindings.

Anyway the point of putting this up is so we can iterate so that we have something to point people at.

Also I'm not quite sure how to test this; build-dir = "../../build" is set such that it coincides (I believe?) with the typical build directory so the wheel can be built quickly after a full source build but it will take changing the CI scripts to actually do this (and then run a test).


Patch is 24.98 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/124878.diff

3 Files Affected:

  • (modified) mlir/CMakeLists.txt (+2)
  • (modified) mlir/python/CMakeLists.txt (+162-163)
  • (added) mlir/python/pyproject.toml (+40)
diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index 9e786154a2b405..3b04244d23d37f 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -178,6 +178,8 @@ set(MLIR_BINDINGS_PYTHON_NB_DOMAIN "mlir"
   CACHE STRING "nanobind domain for MLIR python bindings.")
 set(MLIR_ENABLE_BINDINGS_PYTHON 0 CACHE BOOL
        "Enables building of Python bindings.")
+set(MLIR_BINDINGS_PYTHON_INSTALL_PREFIX "python_packages/mlir_core/mlir" CACHE STRING
+       "Prefix under install directory to place python bindings")
 set(MLIR_DETECT_PYTHON_ENV_PRIME_SEARCH 1 CACHE BOOL
        "Prime the python detection by searching for a full 'Development' \
        component first (temporary while diagnosing environment specific Python \
diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index fb115a5f43423a..123ba3cdbea761 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -18,34 +18,34 @@ declare_mlir_python_sources(MLIRPythonSources.Core.Python
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   ADD_TO_PARENT MLIRPythonSources.Core
   SOURCES
-    _mlir_libs/__init__.py
-    ir.py
-    passmanager.py
-    rewrite.py
-    dialects/_ods_common.py
-
-    # The main _mlir module has submodules: include stubs from each.
-    _mlir_libs/_mlir/__init__.pyi
-    _mlir_libs/_mlir/ir.pyi
-    _mlir_libs/_mlir/passmanager.pyi
+  _mlir_libs/__init__.py
+  ir.py
+  passmanager.py
+  rewrite.py
+  dialects/_ods_common.py
+
+  # The main _mlir module has submodules: include stubs from each.
+  _mlir_libs/_mlir/__init__.pyi
+  _mlir_libs/_mlir/ir.pyi
+  _mlir_libs/_mlir/passmanager.pyi
 )
 
 declare_mlir_python_sources(MLIRPythonSources.Core.Python.Extras
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   ADD_TO_PARENT MLIRPythonSources.Core.Python
   SOURCES
-    extras/types.py
-    extras/meta.py
+  extras/types.py
+  extras/meta.py
 )
 
 declare_mlir_python_sources(MLIRPythonSources.ExecutionEngine
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   ADD_TO_PARENT MLIRPythonSources
   SOURCES
-    execution_engine.py
-    _mlir_libs/_mlirExecutionEngine.pyi
+  execution_engine.py
+  _mlir_libs/_mlirExecutionEngine.pyi
   SOURCES_GLOB
-    runtime/*.py
+  runtime/*.py
 )
 
 declare_mlir_python_sources(MLIRPythonCAPI.HeaderSources
@@ -62,7 +62,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/AffineOps.td
   SOURCES
-    dialects/affine.py
+  dialects/affine.py
   DIALECT_NAME affine
   GEN_ENUM_BINDINGS)
 
@@ -71,7 +71,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/AMDGPUOps.td
   SOURCES
-    dialects/amdgpu.py
+  dialects/amdgpu.py
   DIALECT_NAME amdgpu
   GEN_ENUM_BINDINGS)
 
@@ -87,10 +87,10 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/BufferizationOps.td
   SOURCES
-    dialects/bufferization.py
+  dialects/bufferization.py
   DIALECT_NAME bufferization
   GEN_ENUM_BINDINGS_TD_FILE
-    "../../include/mlir/Dialect/Bufferization/IR/BufferizationEnums.td"
+  "../../include/mlir/Dialect/Bufferization/IR/BufferizationEnums.td"
 )
 
 declare_mlir_dialect_python_bindings(
@@ -98,7 +98,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/BuiltinOps.td
   SOURCES
-    dialects/builtin.py
+  dialects/builtin.py
   DIALECT_NAME builtin)
 
 declare_mlir_dialect_python_bindings(
@@ -106,7 +106,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/ComplexOps.td
   SOURCES
-    dialects/complex.py
+  dialects/complex.py
   DIALECT_NAME complex)
 
 declare_mlir_dialect_python_bindings(
@@ -114,7 +114,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/IndexOps.td
   SOURCES
-    dialects/index.py
+  dialects/index.py
   DIALECT_NAME index
   GEN_ENUM_BINDINGS)
 
@@ -123,7 +123,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/ControlFlowOps.td
   SOURCES
-    dialects/cf.py
+  dialects/cf.py
   DIALECT_NAME cf)
 
 declare_mlir_dialect_python_bindings(
@@ -131,7 +131,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/FuncOps.td
   SOURCES
-    dialects/func.py
+  dialects/func.py
   DIALECT_NAME func)
 
 declare_mlir_dialect_python_bindings(
@@ -148,7 +148,7 @@ declare_mlir_dialect_python_bindings(
   TD_FILE dialects/LinalgOps.td
   SOURCES
   SOURCES_GLOB
-    dialects/linalg/*.py
+  dialects/linalg/*.py
   DIALECT_NAME linalg
   DEPENDS LinalgOdsGen
   GEN_ENUM_BINDINGS)
@@ -158,16 +158,16 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/LLVMOps.td
   SOURCES
-    dialects/llvm.py
+  dialects/llvm.py
   DIALECT_NAME llvm
   GEN_ENUM_BINDINGS)
 
 declare_mlir_dialect_extension_python_bindings(
-ADD_TO_PARENT MLIRPythonSources.Dialects
-ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+  ADD_TO_PARENT MLIRPythonSources.Dialects
+  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/TransformPDLExtensionOps.td
   SOURCES
-    dialects/transform/pdl.py
+  dialects/transform/pdl.py
   DIALECT_NAME transform
   EXTENSION_NAME transform_pdl_extension)
 
@@ -176,11 +176,11 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/TransformOps.td
   SOURCES
-    dialects/transform/__init__.py
-    _mlir_libs/_mlir/dialects/transform/__init__.pyi
+  dialects/transform/__init__.py
+  _mlir_libs/_mlir/dialects/transform/__init__.pyi
   DIALECT_NAME transform
   GEN_ENUM_BINDINGS_TD_FILE
-    "../../include/mlir/Dialect/Transform/IR/TransformAttrs.td"
+  "../../include/mlir/Dialect/Transform/IR/TransformAttrs.td"
 )
 
 declare_mlir_python_sources(
@@ -189,21 +189,21 @@ declare_mlir_python_sources(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   GEN_ENUM_BINDINGS
   SOURCES
-    dialects/transform/extras/__init__.py)
+  dialects/transform/extras/__init__.py)
 
 declare_mlir_python_sources(
   MLIRPythonSources.Dialects.transform.interpreter
   ADD_TO_PARENT MLIRPythonSources.Dialects
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   SOURCES
-    dialects/transform/interpreter/__init__.py)
+  dialects/transform/interpreter/__init__.py)
 
 declare_mlir_dialect_extension_python_bindings(
   ADD_TO_PARENT MLIRPythonSources.Dialects
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/BufferizationTransformOps.td
   SOURCES
-    dialects/transform/bufferization.py
+  dialects/transform/bufferization.py
   DIALECT_NAME transform
   EXTENSION_NAME bufferization_transform)
 
@@ -212,7 +212,7 @@ declare_mlir_dialect_extension_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/GPUTransformOps.td
   SOURCES
-    dialects/transform/gpu.py
+  dialects/transform/gpu.py
   DIALECT_NAME transform
   EXTENSION_NAME gpu_transform)
 
@@ -221,7 +221,7 @@ declare_mlir_dialect_extension_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/SCFLoopTransformOps.td
   SOURCES
-    dialects/transform/loop.py
+  dialects/transform/loop.py
   DIALECT_NAME transform
   EXTENSION_NAME loop_transform)
 
@@ -230,7 +230,7 @@ declare_mlir_dialect_extension_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/MemRefTransformOps.td
   SOURCES
-    dialects/transform/memref.py
+  dialects/transform/memref.py
   DIALECT_NAME transform
   EXTENSION_NAME memref_transform)
 
@@ -239,7 +239,7 @@ declare_mlir_dialect_extension_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/NVGPUTransformOps.td
   SOURCES
-    dialects/transform/nvgpu.py
+  dialects/transform/nvgpu.py
   DIALECT_NAME transform
   EXTENSION_NAME nvgpu_transform)
 
@@ -248,11 +248,11 @@ declare_mlir_dialect_extension_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/LinalgStructuredTransformOps.td
   SOURCES
-    dialects/transform/structured.py
+  dialects/transform/structured.py
   DIALECT_NAME transform
   EXTENSION_NAME structured_transform
   GEN_ENUM_BINDINGS_TD_FILE
-    "../../include/mlir/Dialect/Linalg/TransformOps/LinalgTransformEnums.td"
+  "../../include/mlir/Dialect/Linalg/TransformOps/LinalgTransformEnums.td"
 )
 
 declare_mlir_dialect_extension_python_bindings(
@@ -260,7 +260,7 @@ declare_mlir_dialect_extension_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/SparseTensorTransformOps.td
   SOURCES
-    dialects/transform/sparse_tensor.py
+  dialects/transform/sparse_tensor.py
   DIALECT_NAME transform
   EXTENSION_NAME sparse_tensor_transform)
 
@@ -269,7 +269,7 @@ declare_mlir_dialect_extension_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/TensorTransformOps.td
   SOURCES
-    dialects/transform/tensor.py
+  dialects/transform/tensor.py
   DIALECT_NAME transform
   EXTENSION_NAME tensor_transform)
 
@@ -278,11 +278,11 @@ declare_mlir_dialect_extension_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/VectorTransformOps.td
   SOURCES
-    dialects/transform/vector.py
+  dialects/transform/vector.py
   DIALECT_NAME transform
   EXTENSION_NAME vector_transform
   GEN_ENUM_BINDINGS_TD_FILE
-    "../../include/mlir/Dialect/Vector/Transforms/VectorTransformsBase.td"
+  "../../include/mlir/Dialect/Vector/Transforms/VectorTransformsBase.td"
 )
 
 declare_mlir_dialect_python_bindings(
@@ -297,7 +297,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/ArithOps.td
   SOURCES
-    dialects/arith.py
+  dialects/arith.py
   DIALECT_NAME arith
   GEN_ENUM_BINDINGS)
 
@@ -306,7 +306,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/MemRefOps.td
   SOURCES
-    dialects/memref.py
+  dialects/memref.py
   DIALECT_NAME memref)
 
 declare_mlir_dialect_python_bindings(
@@ -314,7 +314,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/MLProgramOps.td
   SOURCES
-    dialects/ml_program.py
+  dialects/ml_program.py
   DIALECT_NAME ml_program)
 
 declare_mlir_dialect_python_bindings(
@@ -322,7 +322,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/NVGPUOps.td
   SOURCES
-    dialects/nvgpu.py
+  dialects/nvgpu.py
   DIALECT_NAME nvgpu
   GEN_ENUM_BINDINGS)
 
@@ -331,7 +331,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/NVVMOps.td
   SOURCES
-    dialects/nvvm.py
+  dialects/nvvm.py
   DIALECT_NAME nvvm
   GEN_ENUM_BINDINGS)
 
@@ -340,7 +340,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/ROCDLOps.td
   SOURCES
-    dialects/rocdl.py
+  dialects/rocdl.py
   DIALECT_NAME rocdl)
 
 declare_mlir_python_sources(
@@ -349,15 +349,15 @@ declare_mlir_python_sources(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   GEN_ENUM_BINDINGS
   SOURCES
-    dialects/quant.py
-    _mlir_libs/_mlir/dialects/quant.pyi)
+  dialects/quant.py
+  _mlir_libs/_mlir/dialects/quant.pyi)
 
 declare_mlir_dialect_python_bindings(
   ADD_TO_PARENT MLIRPythonSources.Dialects
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/EmitC.td
-  SOURCES 
-    dialects/emitc.py
+  SOURCES
+  dialects/emitc.py
   DIALECT_NAME emitc)
 
 declare_mlir_dialect_python_bindings(
@@ -365,8 +365,8 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/PDLOps.td
   SOURCES
-    dialects/pdl.py
-    _mlir_libs/_mlir/dialects/pdl.pyi
+  dialects/pdl.py
+  _mlir_libs/_mlir/dialects/pdl.pyi
   DIALECT_NAME pdl)
 
 declare_mlir_dialect_python_bindings(
@@ -374,7 +374,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/OpenMPOps.td
   SOURCES
-    dialects/openmp.py
+  dialects/openmp.py
   DIALECT_NAME omp
   DEPENDS omp_common_td)
 
@@ -383,7 +383,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/SCFOps.td
   SOURCES
-    dialects/scf.py
+  dialects/scf.py
   DIALECT_NAME scf)
 
 declare_mlir_dialect_python_bindings(
@@ -400,22 +400,22 @@ declare_mlir_dialect_python_bindings(
   SOURCES dialects/sparse_tensor.py
   DIALECT_NAME sparse_tensor
   GEN_ENUM_BINDINGS_TD_FILE
-    "../../include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td"
+  "../../include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td"
 )
 
 declare_mlir_dialect_python_bindings(
-    ADD_TO_PARENT MLIRPythonSources.Dialects
-    ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
-    TD_FILE dialects/SPIRVOps.td
-    SOURCES dialects/spirv.py
-    DIALECT_NAME spirv)
+  ADD_TO_PARENT MLIRPythonSources.Dialects
+  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+  TD_FILE dialects/SPIRVOps.td
+  SOURCES dialects/spirv.py
+  DIALECT_NAME spirv)
 
 declare_mlir_dialect_python_bindings(
   ADD_TO_PARENT MLIRPythonSources.Dialects
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/TensorOps.td
   SOURCES
-    dialects/tensor.py
+  dialects/tensor.py
   DIALECT_NAME tensor)
 
 declare_mlir_dialect_python_bindings(
@@ -433,7 +433,7 @@ declare_mlir_dialect_python_bindings(
   SOURCES dialects/vector.py
   DIALECT_NAME vector
   GEN_ENUM_BINDINGS_TD_FILE
-    "dialects/VectorAttributes.td")
+  "dialects/VectorAttributes.td")
 
 ################################################################################
 # Python extensions.
@@ -450,31 +450,31 @@ declare_mlir_python_extension(MLIRPythonExtension.Core
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    MainModule.cpp
-    IRAffine.cpp
-    IRAttributes.cpp
-    IRCore.cpp
-    IRInterfaces.cpp
-    IRModule.cpp
-    IRTypes.cpp
-    Pass.cpp
-    Rewrite.cpp
-
-    # Headers must be included explicitly so they are installed.
-    Globals.h
-    IRModule.h
-    Pass.h
-    NanobindUtils.h
-    Rewrite.h
+  MainModule.cpp
+  IRAffine.cpp
+  IRAttributes.cpp
+  IRCore.cpp
+  IRInterfaces.cpp
+  IRModule.cpp
+  IRTypes.cpp
+  Pass.cpp
+  Rewrite.cpp
+
+  # Headers must be included explicitly so they are installed.
+  Globals.h
+  IRModule.h
+  Pass.h
+  NanobindUtils.h
+  Rewrite.h
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIDebug
-    MLIRCAPIIR
-    MLIRCAPIInterfaces
+  MLIRCAPIDebug
+  MLIRCAPIIR
+  MLIRCAPIInterfaces
 
-    # Dialects
-    MLIRCAPIFunc
+  # Dialects
+  MLIRCAPIFunc
 )
 
 # This extension exposes an API to register all dialects, extensions, and passes
@@ -489,13 +489,13 @@ declare_mlir_python_extension(MLIRPythonExtension.RegisterEverything
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    RegisterEverything.cpp
+  RegisterEverything.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIConversion
-    MLIRCAPITransforms
-    MLIRCAPIRegisterEverything
+  MLIRCAPIConversion
+  MLIRCAPITransforms
+  MLIRCAPIRegisterEverything
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.Dialects.Linalg.Pybind
@@ -504,12 +504,12 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.Linalg.Pybind
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    DialectLinalg.cpp
+  DialectLinalg.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIIR
-    MLIRCAPILinalg
+  MLIRCAPIIR
+  MLIRCAPILinalg
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.Dialects.GPU.Pybind
@@ -518,12 +518,12 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.GPU.Pybind
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    DialectGPU.cpp
+  DialectGPU.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIIR
-    MLIRCAPIGPU
+  MLIRCAPIIR
+  MLIRCAPIGPU
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.Dialects.LLVM.Pybind
@@ -532,12 +532,12 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.LLVM.Pybind
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    DialectLLVM.cpp
+  DialectLLVM.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIIR
-    MLIRCAPILLVM
+  MLIRCAPIIR
+  MLIRCAPILLVM
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.Dialects.Quant.Pybind
@@ -546,12 +546,12 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.Quant.Pybind
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    DialectQuant.cpp
+  DialectQuant.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIIR
-    MLIRCAPIQuant
+  MLIRCAPIIR
+  MLIRCAPIQuant
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.Dialects.NVGPU.Pybind
@@ -560,12 +560,12 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.NVGPU.Pybind
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    DialectNVGPU.cpp
+  DialectNVGPU.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIIR
-    MLIRCAPINVGPU
+  MLIRCAPIIR
+  MLIRCAPINVGPU
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.Dialects.PDL.Pybind
@@ -574,12 +574,12 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.PDL.Pybind
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    DialectPDL.cpp
+  DialectPDL.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIIR
-    MLIRCAPIPDL
+  MLIRCAPIIR
+  MLIRCAPIPDL
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.Dialects.SparseTensor.Pybind
@@ -588,12 +588,12 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.SparseTensor.Pybind
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    DialectSparseTensor.cpp
+  DialectSparseTensor.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIIR
-    MLIRCAPISparseTensor
+  MLIRCAPIIR
+  MLIRCAPISparseTensor
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.Dialects.Transform.Pybind
@@ -602,12 +602,12 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.Transform.Pybind
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    DialectTransform.cpp
+  DialectTransform.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIIR
-    MLIRCAPITransformDialect
+  MLIRCAPIIR
+  MLIRCAPITransformDialect
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses
@@ -616,11 +616,11 @@ declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    AsyncPasses.cpp
+  AsyncPasses.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIAsync
+  MLIRCAPIAsync
 )
 
 if(MLIR_ENABLE_EXECUTION_ENGINE)
@@ -628,13 +628,13 @@ if(MLIR_ENABLE_EXECUTION_ENGINE)
     MODULE_NAME _mlirExecutionEngine
     ADD_TO_PARENT MLIRPythonSources.ExecutionEngine
     ROOT_DIR "${PYTHON_SOURCE_DIR}"
-  PYTHON_BINDINGS_LIBRARY nanobind
+    PYTHON_BINDINGS_LIBRARY nanobind
     SOURCES
-      ExecutionEngineModule.cpp
+    ExecutionEngineModule.cpp
     PRIVATE_LINK_LIBS
-      LLVMSupport
+    LLVMSupport
     EMBED_CAPI_LINK_LIBS
-      MLIRCAPIExecutionEngine
+    MLIRCAPIExecutionEngine
   )
 endif()
 
@@ -644,11 +644,11 @@ declare_mlir_python_extension(MLIRPythonExtension.GPUDialectPasses
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    GPUPasses.cpp
+  GPUPasses.cpp
   PRIVATE_LINK_LIBS
-    LLVMSupport
+  LLVMSupport
   EMBED_CAPI_LINK_LIBS
-    MLIRCAPIGPU
+  MLIRCAPIGPU
 )
 
 declare_mlir_python_extension(MLIRPythonExtension.LinalgPasses
@@ -657,11 +657,11 @@ declare_mlir_python_extension(MLIRPythonExtension.LinalgPasses
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   PYTHON_BINDINGS_LIBRARY nanobind
   SOURCES
-    LinalgPasses.cpp
+  LinalgPasses.cpp
   PRIVATE_L...
[truncated]

@makslevental makslevental force-pushed the users/makslevental/pyprojecttoml branch from 3d49f32 to 5f9c0e7 Compare January 29, 2025 05:48
[project]
name = "mlir-python-bindings"
version = "0.0.1"
requires-python = ">=3.8,<=3.13"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything that prevents the mlir bindings from working with Python versions newer than 3.13?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no - this toml is copy-pasta from some downstream uses where I do have a hard upperbound but for upstream there's no blocker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove it then?

Copy link
Member

@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you perhaps update the python binding readme to mention this?

[project]
name = "mlir-python-bindings"
version = "0.0.1"
requires-python = ">=3.8,<=3.13"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove it then?


[project]
name = "mlir-python-bindings"
version = "0.0.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC, do you have any idea when we'd bump this? E.g., every new feature bump? (is there an option to just have sha attached or something, I see there is some support for dynamic version)

"numpy>=1.19.5, <=2.1.2",
"pybind11>=2.10.0, <=2.13.6",
"PyYAML>=5.4.0, <=6.0.1",
'ml_dtypes>=0.1.0, <=0.6.0; python_version<"3.13"',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is optional and so too numpy - both very useful and used by most, but optional.

"typing_extensions==4.12.2",
"nanobind>=2.4, <3.0",
"numpy>=1.19.5, <=2.1.2",
"pybind11>=2.10.0, <=2.13.6",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this due to some of the in repo dialects still using pybind? (downstream folks obviously weren't asked to switch etc)


[tool.scikit-build]
minimum-version = "0.10"
build-dir = "../../build"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use environment variables from/thread through to cmake here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:python MLIR Python bindings mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants