[Mlir-commits] [mlir] [mlir][python][cmake] Allows for specifying `NB_DOMAIN` in `add_mlir_python_extension` (PR #122865)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jan 15 14:28:35 PST 2025
https://github.com/erwei-xilinx updated https://github.com/llvm/llvm-project/pull/122865
>From 09dc8ab793a93fffa1cae5a591abd2b0bf8227da Mon Sep 17 00:00:00 2001
From: erwei-xilinx <erwei.wang at amd.com>
Date: Mon, 13 Jan 2025 22:50:44 -0800
Subject: [PATCH 1/3] Avoids domain conflict with nanobind by specifying
NB_DOMAIN
---
mlir/cmake/modules/AddMLIRPython.cmake | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 0679db9cf93e19..82a93c1a3c78c9 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -658,6 +658,13 @@ function(add_mlir_python_extension libname extname)
set(eh_rtti_enable -frtti -fexceptions)
endif ()
+ # Avoids domain conflict with nanobind by specifying NB_DOMAIN.
+ if(NB_DOMAIN)
+ set(_nb_domain ${NB_DOMAIN})
+ else()
+ set(_nb_domain "mlir")
+ endif ()
+
# The actual extension library produces a shared-object or DLL and has
# sources that must be compiled in accordance with pybind11 needs (RTTI and
# exceptions).
@@ -667,7 +674,7 @@ function(add_mlir_python_extension libname extname)
)
elseif(ARG_PYTHON_BINDINGS_LIBRARY STREQUAL "nanobind")
nanobind_add_module(${libname}
- NB_DOMAIN mlir
+ NB_DOMAIN ${_nb_domain}
FREE_THREADED
${ARG_SOURCES}
)
>From 6c69f59700366c92873f500d32af64479ccda00b Mon Sep 17 00:00:00 2001
From: erwei-xilinx <erwei.wang at amd.com>
Date: Tue, 14 Jan 2025 17:21:10 -0800
Subject: [PATCH 2/3] Switch to using the global MLIR_BINDINGS_PYTHON_NB_DOMAIN
---
mlir/CMakeLists.txt | 2 ++
mlir/cmake/modules/AddMLIRPython.cmake | 6 +++---
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index a888ac243b044b..9e786154a2b405 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -174,6 +174,8 @@ configure_file(
# disable all package setup and control it themselves.
#-------------------------------------------------------------------------------
+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_DETECT_PYTHON_ENV_PRIME_SEARCH 1 CACHE BOOL
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 82a93c1a3c78c9..8d30e797bd23b6 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -659,11 +659,11 @@ function(add_mlir_python_extension libname extname)
endif ()
# Avoids domain conflict with nanobind by specifying NB_DOMAIN.
- if(NB_DOMAIN)
- set(_nb_domain ${NB_DOMAIN})
+ if(MLIR_BINDINGS_PYTHON_NB_DOMAIN)
+ set(_nb_domain ${MLIR_BINDINGS_PYTHON_NB_DOMAIN})
else()
set(_nb_domain "mlir")
- endif ()
+ endif()
# The actual extension library produces a shared-object or DLL and has
# sources that must be compiled in accordance with pybind11 needs (RTTI and
>From cf169a8fc7657053c3dca37e56d96e2615ce25a6 Mon Sep 17 00:00:00 2001
From: erwei-xilinx <erwei.wang at amd.com>
Date: Wed, 15 Jan 2025 14:28:10 -0800
Subject: [PATCH 3/3] Removed the if-else condition trying to enforce a default
for MLIR_BINDINGS_PYTHON_NB_DOMAIN
---
mlir/cmake/modules/AddMLIRPython.cmake | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 8d30e797bd23b6..815f65b106d945 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -658,13 +658,6 @@ function(add_mlir_python_extension libname extname)
set(eh_rtti_enable -frtti -fexceptions)
endif ()
- # Avoids domain conflict with nanobind by specifying NB_DOMAIN.
- if(MLIR_BINDINGS_PYTHON_NB_DOMAIN)
- set(_nb_domain ${MLIR_BINDINGS_PYTHON_NB_DOMAIN})
- else()
- set(_nb_domain "mlir")
- endif()
-
# The actual extension library produces a shared-object or DLL and has
# sources that must be compiled in accordance with pybind11 needs (RTTI and
# exceptions).
@@ -674,7 +667,7 @@ function(add_mlir_python_extension libname extname)
)
elseif(ARG_PYTHON_BINDINGS_LIBRARY STREQUAL "nanobind")
nanobind_add_module(${libname}
- NB_DOMAIN ${_nb_domain}
+ NB_DOMAIN ${MLIR_BINDINGS_PYTHON_NB_DOMAIN}
FREE_THREADED
${ARG_SOURCES}
)
More information about the Mlir-commits
mailing list