From 3fa41d00c6907240ff857451886aea52c98b204e Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 29 Nov 2024 11:27:53 -0500 Subject: [PATCH 01/28] Begin scaffolding for libcustom_call in cmake --- CMakeLists.txt | 13 +++++++++++++ frontend/catalyst/utils/CMakeLists.txt | 11 +++++++++++ .../utils/jax_cpu_lapack_kernels/CMakeLists.txt | 13 +++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..4c3ad4afdd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.20) +project(catalyst) + +set(LOGO [=[ +░█▀▀░█▀█░▀█▀░█▀█░█░░░█░█░█▀▀░▀█▀ +░█░░░█▀█░░█░░█▀█░█░░░░█░░▀▀█░░█░ +░▀▀▀░▀░▀░░▀░░▀░▀░▀▀▀░░▀░░▀▀▀░░▀░ +]=]) +message(${LOGO}) + +add_subdirectory(frontend) +add_subdirectory(mlir) +add_subdirectory(runtime) diff --git a/frontend/catalyst/utils/CMakeLists.txt b/frontend/catalyst/utils/CMakeLists.txt index 5dd037086c..ebb62ce44a 100644 --- a/frontend/catalyst/utils/CMakeLists.txt +++ b/frontend/catalyst/utils/CMakeLists.txt @@ -1,3 +1,4 @@ +project(catalyst_frontend_utils) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -44,3 +45,13 @@ target_include_directories(wrapper PRIVATE ${NUMPY_INCLUDE_DIR}) # Use suffix ".so" rather than ".abi3.so" for library file using Stable ABI # This is necessary for compatibility with setuptools build extensions set_target_properties(wrapper PROPERTIES SUFFIX ".so") + + +add_subdirectory(jax_cpu_lapack_kernels) + +add_library(custom_calls SHARED + ${PROJECT_SOURCE_DIR}/libcustom_calls.cpp +) +target_link_libraries(custom_calls PRIVATE catalyst_lapack_kernels) +#target_include_directories(custom_calls PRIVATE ${NUMPY_INCLUDE_DIR}) + diff --git a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt new file mode 100644 index 0000000000..3122c5d801 --- /dev/null +++ b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt @@ -0,0 +1,13 @@ +project(catalyst_jax_lapack) + +add_library(catalyst_lapack_kernels STATIC + ${PROJECT_SOURCE_DIR}/lapack_kernels.cpp + ${PROJECT_SOURCE_DIR}/lapack_kernels_using_lapack.cpp +) + +set_property(TARGET catalyst_lapack_kernels PROPERTY POSITION_INDEPENDENT_CODE ON) + +target_include_directories(catalyst_lapack_kernels PRIVATE + $ + $ +) \ No newline at end of file From 969240de4c1697e90cce1b97008792683b6109ec Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 29 Nov 2024 11:30:11 -0500 Subject: [PATCH 02/28] Ensure nested cmakes use project scoping --- frontend/catalyst/CMakeLists.txt | 2 ++ frontend/catalyst/utils/CMakeLists.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/frontend/catalyst/CMakeLists.txt b/frontend/catalyst/CMakeLists.txt index 512d2b1553..0c4d566172 100644 --- a/frontend/catalyst/CMakeLists.txt +++ b/frontend/catalyst/CMakeLists.txt @@ -1 +1,3 @@ +project(catalyst_frontend) + add_subdirectory(utils) diff --git a/frontend/catalyst/utils/CMakeLists.txt b/frontend/catalyst/utils/CMakeLists.txt index ebb62ce44a..d87a448832 100644 --- a/frontend/catalyst/utils/CMakeLists.txt +++ b/frontend/catalyst/utils/CMakeLists.txt @@ -1,4 +1,5 @@ project(catalyst_frontend_utils) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) From 2a1b6cc04d4285f7c10b2e56fa3f98407d7c8d27 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 29 Nov 2024 11:57:07 -0500 Subject: [PATCH 03/28] Remove python driven build for libcustom_calls.so --- setup.py | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/setup.py b/setup.py index 7cf241d3cd..662cccebb4 100644 --- a/setup.py +++ b/setup.py @@ -268,43 +268,12 @@ def run(self): check=False, ) - -# Compile the library of custom calls in the frontend -if system_platform == "Linux": - custom_calls_extension = Extension( - "catalyst.utils.libcustom_calls", - sources=[ - "frontend/catalyst/utils/libcustom_calls.cpp", - "frontend/catalyst/utils/jax_cpu_lapack_kernels/lapack_kernels.cpp", - "frontend/catalyst/utils/jax_cpu_lapack_kernels/lapack_kernels_using_lapack.cpp", - ], - extra_compile_args=["-std=c++17"], - ) - cmdclass = {"build_ext": CustomBuildExtLinux} - -elif system_platform == "Darwin": - variables = sysconfig.get_config_vars() - # Here we need to switch the deault to MacOs dynamic lib - variables["LDSHARED"] = variables["LDSHARED"].replace("-bundle", "-dynamiclib") - if sysconfig.get_config_var("LDCXXSHARED"): - variables["LDCXXSHARED"] = variables["LDCXXSHARED"].replace("-bundle", "-dynamiclib") - custom_calls_extension = Extension( - "catalyst.utils.libcustom_calls", - sources=[ - "frontend/catalyst/utils/libcustom_calls.cpp", - "frontend/catalyst/utils/jax_cpu_lapack_kernels/lapack_kernels.cpp", - "frontend/catalyst/utils/jax_cpu_lapack_kernels/lapack_kernels_using_lapack.cpp", - ], - extra_compile_args=["-std=c++17"], - ) - cmdclass = {"build_ext": CustomBuildExtMacos} - - project_root_dir = os.path.abspath(os.path.dirname(__file__)) frontend_dir = os.path.join(project_root_dir, "frontend") ext_modules = [ - custom_calls_extension, + #custom_calls_extension, + CMakeExtension("catalyst.utils.libcustom_calls", sourcedir=frontend_dir), CMakeExtension("catalyst.utils.wrapper", sourcedir=frontend_dir), ] @@ -331,6 +300,6 @@ def run(self): package_dir={"": "frontend"}, include_package_data=True, ext_modules=ext_modules, - cmdclass=cmdclass, + #cmdclass=cmdclass, **description, ) From 58c27f7c0210b81307d42e82e6a1babd50eea2ab Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 29 Nov 2024 12:10:40 -0500 Subject: [PATCH 04/28] Fix frontend build structure --- setup.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 662cccebb4..751c2fc3d5 100644 --- a/setup.py +++ b/setup.py @@ -268,11 +268,23 @@ def run(self): check=False, ) + +# Compile the library of custom calls in the frontend +if system_platform == "Linux": + cmdclass = {"build_ext": CustomBuildExtLinux} + +elif system_platform == "Darwin": + variables = sysconfig.get_config_vars() + # Here we need to switch the deault to MacOs dynamic lib + variables["LDSHARED"] = variables["LDSHARED"].replace("-bundle", "-dynamiclib") + if sysconfig.get_config_var("LDCXXSHARED"): + variables["LDCXXSHARED"] = variables["LDCXXSHARED"].replace("-bundle", "-dynamiclib") + cmdclass = {"build_ext": CustomBuildExtMacos} + project_root_dir = os.path.abspath(os.path.dirname(__file__)) frontend_dir = os.path.join(project_root_dir, "frontend") ext_modules = [ - #custom_calls_extension, CMakeExtension("catalyst.utils.libcustom_calls", sourcedir=frontend_dir), CMakeExtension("catalyst.utils.wrapper", sourcedir=frontend_dir), ] @@ -300,6 +312,6 @@ def run(self): package_dir={"": "frontend"}, include_package_data=True, ext_modules=ext_modules, - #cmdclass=cmdclass, + # cmdclass=cmdclass, **description, ) From ed676eb2b5999df7e4ecf2f49ddfd45dc5baf191 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 29 Nov 2024 16:55:49 -0500 Subject: [PATCH 05/28] Update Lapack submodule build setup --- .../jax_cpu_lapack_kernels/CMakeLists.txt | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt index 3122c5d801..246b5e89cc 100644 --- a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt +++ b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt @@ -1,13 +1,36 @@ project(catalyst_jax_lapack) +# Create a static library for LAPACK kernels to be included into the +# custom_calls librar in the parent scope. + add_library(catalyst_lapack_kernels STATIC ${PROJECT_SOURCE_DIR}/lapack_kernels.cpp ${PROJECT_SOURCE_DIR}/lapack_kernels_using_lapack.cpp ) +# Ensure fPIC is set for static builds set_property(TARGET catalyst_lapack_kernels PROPERTY POSITION_INDEPENDENT_CODE ON) -target_include_directories(catalyst_lapack_kernels PRIVATE +# Headers are tracked into the target from the current project scope +target_include_directories(catalyst_lapack_kernels PUBLIC $ $ -) \ No newline at end of file +) + +# If the option is set, allow explicit linking of the CMake-found CBLAS/LAPACKE +# library. See https://cmake.org/cmake/help/latest/module/FindBLAS.html for info. +option(CATALYST_LINK_BLAS "Link the CMake-defined BLAS and LAPACK libraries as part of the extension module" OFF) + +if(CATALYST_LINK_BLAS) + find_package( BLAS REQUIRED ) + find_package( LAPACK REQUIRED) + target_link_libraries(catalyst_lapack_kernels PUBLIC BLAS::BLAS) + + # Ensure libraries are explicitly linked. + target_link_options(catalyst_lapack_kernels PUBLIC + $<$:-Wl,--no-as-needed> + ) +endif() + +# Ensure the availability of symbol exports. Only necessary with `SHARED` +set_property(TARGET catalyst_lapack_kernels PROPERTY ENABLE_EXPORTS ON) \ No newline at end of file From 0e1fb47691a2171c029f313361c2826772c9761c Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 29 Nov 2024 17:13:42 -0500 Subject: [PATCH 06/28] Build libcustom_calls as a standalone shared lib --- frontend/catalyst/utils/CMakeLists.txt | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/frontend/catalyst/utils/CMakeLists.txt b/frontend/catalyst/utils/CMakeLists.txt index d87a448832..8bd645737c 100644 --- a/frontend/catalyst/utils/CMakeLists.txt +++ b/frontend/catalyst/utils/CMakeLists.txt @@ -3,9 +3,25 @@ project(catalyst_frontend_utils) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Find the Python interpreter, development headers and NumPy headers find_package(Python 3 - REQUIRED COMPONENTS Interpreter Development.Module + REQUIRED COMPONENTS Interpreter Development.Module NumPy OPTIONAL_COMPONENTS Development.SABIModule) +include_directories(${PYTHON_INCLUDE_DIRS}) + +# Build the custom calls library and make `catalyst_jax_cpu_lapack_kernels` +# target visible in the current project directory. +add_subdirectory(jax_cpu_lapack_kernels) + +add_library(custom_calls SHARED + ${PROJECT_SOURCE_DIR}/libcustom_calls.cpp +) +target_link_libraries(custom_calls PUBLIC "$") +set_property(TARGET custom_calls PROPERTY ENABLE_EXPORTS OFF) + +# If aiming to build additional shared submodules, setting the RPATH $ORIGIN +# value may be useful to avoid explicit library paths. +set_target_properties(custom_calls PROPERTIES BUILD_RPATH "$ORIGIN/") # nanobind suggests including these lines to configure CMake to perform an optimized release build # by default unless another build type is specified. Without this addition, binding code may run @@ -23,13 +39,6 @@ execute_process( find_package(nanobind CONFIG REQUIRED) -# Get the NumPy include directory -execute_process( - COMMAND "${Python_EXECUTABLE}" -c "import numpy; print(numpy.get_include())" - OUTPUT_VARIABLE NUMPY_INCLUDE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE -) - # Source file list for `wrapper` module set(WRAPPER_SRC_FILES wrapper.cpp @@ -41,18 +50,12 @@ set(WRAPPER_SRC_FILES nanobind_add_module(wrapper STABLE_ABI ${WRAPPER_SRC_FILES}) # Add the NumPy include directory to the library's include paths -target_include_directories(wrapper PRIVATE ${NUMPY_INCLUDE_DIR}) +target_include_directories(wrapper PRIVATE ${Python_NumPy_INCLUDE_DIRS}) # Use suffix ".so" rather than ".abi3.so" for library file using Stable ABI # This is necessary for compatibility with setuptools build extensions set_target_properties(wrapper PROPERTIES SUFFIX ".so") - -add_subdirectory(jax_cpu_lapack_kernels) - -add_library(custom_calls SHARED - ${PROJECT_SOURCE_DIR}/libcustom_calls.cpp -) -target_link_libraries(custom_calls PRIVATE catalyst_lapack_kernels) -#target_include_directories(custom_calls PRIVATE ${NUMPY_INCLUDE_DIR}) - +# Allow custom calls to be loaded alongside wrapper +target_link_libraries(wrapper INTERFACE custom_calls) +set_target_properties(wrapper PROPERTIES BUILD_RPATH "$ORIGIN/") \ No newline at end of file From 1e55e5e03af7706d599be63a678af7928f5651bc Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 29 Nov 2024 17:14:13 -0500 Subject: [PATCH 07/28] Tidy lapack submodule --- .../utils/jax_cpu_lapack_kernels/CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt index 246b5e89cc..a536d3d30d 100644 --- a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt +++ b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt @@ -1,18 +1,18 @@ -project(catalyst_jax_lapack) +project(catalyst_jax_cpu_lapack_kernels) # Create a static library for LAPACK kernels to be included into the # custom_calls librar in the parent scope. -add_library(catalyst_lapack_kernels STATIC +add_library(catalyst_jax_cpu_lapack_kernels STATIC ${PROJECT_SOURCE_DIR}/lapack_kernels.cpp ${PROJECT_SOURCE_DIR}/lapack_kernels_using_lapack.cpp ) # Ensure fPIC is set for static builds -set_property(TARGET catalyst_lapack_kernels PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET catalyst_jax_cpu_lapack_kernels PROPERTY POSITION_INDEPENDENT_CODE ON) # Headers are tracked into the target from the current project scope -target_include_directories(catalyst_lapack_kernels PUBLIC +target_include_directories(catalyst_jax_cpu_lapack_kernels PUBLIC $ $ ) @@ -24,13 +24,13 @@ option(CATALYST_LINK_BLAS "Link the CMake-defined BLAS and LAPACK libraries as p if(CATALYST_LINK_BLAS) find_package( BLAS REQUIRED ) find_package( LAPACK REQUIRED) - target_link_libraries(catalyst_lapack_kernels PUBLIC BLAS::BLAS) + target_link_libraries(catalyst_jax_cpu_lapack_kernels PUBLIC BLAS::BLAS) # Ensure libraries are explicitly linked. - target_link_options(catalyst_lapack_kernels PUBLIC + target_link_options(catalyst_jax_cpu_lapack_kernels PUBLIC $<$:-Wl,--no-as-needed> ) endif() # Ensure the availability of symbol exports. Only necessary with `SHARED` -set_property(TARGET catalyst_lapack_kernels PROPERTY ENABLE_EXPORTS ON) \ No newline at end of file +set_property(TARGET catalyst_jax_cpu_lapack_kernels PROPERTY ENABLE_EXPORTS ON) \ No newline at end of file From 1af2b863ce816ce18fea28714d698015ca737613 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 29 Nov 2024 17:15:07 -0500 Subject: [PATCH 08/28] Remove libcustom_calls from setup.py and simplify --- setup.py | 76 ++++++++------------------------------------------------ 1 file changed, 11 insertions(+), 65 deletions(-) diff --git a/setup.py b/setup.py index 751c2fc3d5..9392cf0d27 100644 --- a/setup.py +++ b/setup.py @@ -126,14 +126,12 @@ class CMakeExtension(Extension): - """A setuptools Extension class for modules with a CMake configuration.""" - def __init__(self, name, sourcedir=""): - super().__init__(name, sources=[]) + Extension.__init__(self, name, sources=[]) self.sourcedir = os.path.abspath(sourcedir) -class UnifiedBuildExt(build_ext): +class CMakeBuild(build_ext): """Custom build extension class for the Catalyst Frontend. This class overrides a number of methods from its parent class @@ -141,15 +139,6 @@ class UnifiedBuildExt(build_ext): 1. `get_ext_filename`, in order to remove the architecture/python version suffix of the library name. - 2. `build_extension`, in order to handle the compilation of extensions - with CMake configurations, namely the catalyst.utils.wrapper module, - and of generic C/C++ extensions without a CMake configuration, namely - the catalyst.utils.libcustom_calls module, which is currently built - as a plain setuptools Extension. - - TODO: Eventually it would be better to build the utils.libcustom_calls - module using a CMake configuration as well, rather than as a setuptools - Extension. """ def initialize_options(self): @@ -175,12 +164,6 @@ def get_ext_filename(self, fullname): return filename.replace(suffix, "") + extension def build_extension(self, ext): - if isinstance(ext, CMakeExtension): - self.build_cmake_extension(ext) - else: - super().build_extension(ext) - - def build_cmake_extension(self, ext: CMakeExtension): """Configure and build CMake extension.""" cmake_path = "cmake" ninja_path = "ninja" @@ -230,56 +213,19 @@ def build_cmake_extension(self, ext: CMakeExtension): subprocess.check_call([cmake_path, "--build", "."] + build_args, cwd=build_temp) -class CustomBuildExtLinux(UnifiedBuildExt): - """Custom build extension class for Linux platforms - - Currently no extra work needs to be performed with respect to the base class - UnifiedBuildExt. - """ - - -class CustomBuildExtMacos(UnifiedBuildExt): - """Custom build extension class for macOS platforms - - In addition to the work performed by the base class UnifiedBuildExt, this - class also changes the LC_ID_DYLIB that is otherwise constant and equal to - where the shared library was created. - """ - - def run(self): - # Run the original build_ext command - super().run() - - # Construct library name based on ext suffix (contains python version, architecture and .so) - library_name = "libcustom_calls.so" - - package_root = os.path.dirname(__file__) - frontend_path = glob.glob( - os.path.join(package_root, "frontend", "**", library_name), recursive=True - ) - build_path = glob.glob(os.path.join("build", "**", library_name), recursive=True) - lib_with_r_path = "@rpath/libcustom_calls.so" - - original_path = frontend_path[0] if frontend_path else build_path[0] - - # Run install_name_tool to modify LC_ID_DYLIB(other the rpath stays in vars/folder) - subprocess.run( - ["/usr/bin/install_name_tool", "-id", lib_with_r_path, original_path], - check=False, - ) - - # Compile the library of custom calls in the frontend if system_platform == "Linux": - cmdclass = {"build_ext": CustomBuildExtLinux} + cmdclass = {"build_ext": CMakeExtension} elif system_platform == "Darwin": - variables = sysconfig.get_config_vars() + cmdclass = {"build_ext": CMakeExtension} + + # variables = sysconfig.get_config_vars() # Here we need to switch the deault to MacOs dynamic lib - variables["LDSHARED"] = variables["LDSHARED"].replace("-bundle", "-dynamiclib") - if sysconfig.get_config_var("LDCXXSHARED"): - variables["LDCXXSHARED"] = variables["LDCXXSHARED"].replace("-bundle", "-dynamiclib") - cmdclass = {"build_ext": CustomBuildExtMacos} + # variables["LDSHARED"] = variables["LDSHARED"].replace("-bundle", "-dynamiclib") + # if sysconfig.get_config_var("LDCXXSHARED"): + # variables["LDCXXSHARED"] = variables["LDCXXSHARED"].replace("-bundle", "-dynamiclib") + # cmdclass = {"build_ext": CustomBuildExtMacos} project_root_dir = os.path.abspath(os.path.dirname(__file__)) frontend_dir = os.path.join(project_root_dir, "frontend") @@ -312,6 +258,6 @@ def run(self): package_dir={"": "frontend"}, include_package_data=True, ext_modules=ext_modules, - # cmdclass=cmdclass, + cmdclass={"build_ext": CMakeBuild}, **description, ) From e3adebfec04ddad35fcf82901155af2eaa009173 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 6 Dec 2024 13:46:50 -0500 Subject: [PATCH 09/28] Update docstring for cmake builder --- setup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9392cf0d27..0e21be07b1 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,6 @@ # pylint: disable=wrong-import-order -import glob import os import platform import subprocess @@ -126,6 +125,15 @@ class CMakeExtension(Extension): + """setuptools Extension wrapper for CMake. + + Provides access to the source directories directly for modules to be compiled. + + For example, to build the `libcustom_calls` library, the direct module path can be provided as + ```python + CMakeExtension("catalyst.utils.libcustom_calls", sourcedir=frontend_dir) + ``` + """ def __init__(self, name, sourcedir=""): Extension.__init__(self, name, sources=[]) self.sourcedir = os.path.abspath(sourcedir) From 5df5dd9f32397465cdc8b9b8e8a4b2e66ac55417 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 6 Dec 2024 13:51:15 -0500 Subject: [PATCH 10/28] Fix black format --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0e21be07b1..6c2720938f 100644 --- a/setup.py +++ b/setup.py @@ -128,12 +128,13 @@ class CMakeExtension(Extension): """setuptools Extension wrapper for CMake. Provides access to the source directories directly for modules to be compiled. - + For example, to build the `libcustom_calls` library, the direct module path can be provided as ```python CMakeExtension("catalyst.utils.libcustom_calls", sourcedir=frontend_dir) ``` """ + def __init__(self, name, sourcedir=""): Extension.__init__(self, name, sources=[]) self.sourcedir = os.path.abspath(sourcedir) From 5f9c3acb31562f189708b0e982021039dedf394e Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 6 Dec 2024 13:57:31 -0500 Subject: [PATCH 11/28] Trigger wheel builds From 5aa20b06b129e9c447c41f6bd2baaa46acb6a244 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Mon, 9 Dec 2024 14:21:24 -0500 Subject: [PATCH 12/28] Ensure libcustom follows OS native library naming --- frontend/catalyst/utils/CMakeLists.txt | 8 +++++--- .../utils/jax_cpu_lapack_kernels/CMakeLists.txt | 10 ++++++++-- .../lapack_kernels_using_lapack.cpp | 1 - setup.py | 17 +++++++---------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/frontend/catalyst/utils/CMakeLists.txt b/frontend/catalyst/utils/CMakeLists.txt index 8bd645737c..05480e0303 100644 --- a/frontend/catalyst/utils/CMakeLists.txt +++ b/frontend/catalyst/utils/CMakeLists.txt @@ -56,6 +56,8 @@ target_include_directories(wrapper PRIVATE ${Python_NumPy_INCLUDE_DIRS}) # This is necessary for compatibility with setuptools build extensions set_target_properties(wrapper PROPERTIES SUFFIX ".so") -# Allow custom calls to be loaded alongside wrapper -target_link_libraries(wrapper INTERFACE custom_calls) -set_target_properties(wrapper PROPERTIES BUILD_RPATH "$ORIGIN/") \ No newline at end of file +# Allow custom calls to be built with explicit linkage against wrapper +add_dependencies(wrapper custom_calls) + +# Explicitly set RPATH to allow access to libraries within same directory +set_target_properties(wrapper PROPERTIES BUILD_RPATH "$ORIGIN") \ No newline at end of file diff --git a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt index a536d3d30d..5f42902ab4 100644 --- a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt +++ b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt @@ -1,7 +1,7 @@ project(catalyst_jax_cpu_lapack_kernels) # Create a static library for LAPACK kernels to be included into the -# custom_calls librar in the parent scope. +# custom_calls library in the parent scope. add_library(catalyst_jax_cpu_lapack_kernels STATIC ${PROJECT_SOURCE_DIR}/lapack_kernels.cpp @@ -21,6 +21,7 @@ target_include_directories(catalyst_jax_cpu_lapack_kernels PUBLIC # library. See https://cmake.org/cmake/help/latest/module/FindBLAS.html for info. option(CATALYST_LINK_BLAS "Link the CMake-defined BLAS and LAPACK libraries as part of the extension module" OFF) + if(CATALYST_LINK_BLAS) find_package( BLAS REQUIRED ) find_package( LAPACK REQUIRED) @@ -33,4 +34,9 @@ if(CATALYST_LINK_BLAS) endif() # Ensure the availability of symbol exports. Only necessary with `SHARED` -set_property(TARGET catalyst_jax_cpu_lapack_kernels PROPERTY ENABLE_EXPORTS ON) \ No newline at end of file +set_property(TARGET catalyst_jax_cpu_lapack_kernels PROPERTY ENABLE_EXPORTS ON) + +# If building on MacOS avoid the linker complaining about undefined symbols +if(APPLE) +target_link_options(catalyst_jax_cpu_lapack_kernels PUBLIC -undefined dynamic_lookup) +endif() \ No newline at end of file diff --git a/frontend/catalyst/utils/jax_cpu_lapack_kernels/lapack_kernels_using_lapack.cpp b/frontend/catalyst/utils/jax_cpu_lapack_kernels/lapack_kernels_using_lapack.cpp index fe98badc5e..e045d2272b 100644 --- a/frontend/catalyst/utils/jax_cpu_lapack_kernels/lapack_kernels_using_lapack.cpp +++ b/frontend/catalyst/utils/jax_cpu_lapack_kernels/lapack_kernels_using_lapack.cpp @@ -113,7 +113,6 @@ jax::Sytrd>::FnType GET_SYMBOL(LAPACKE_zhetrd); } // extern "C" namespace jax { - static auto init = []() -> int { RealTrsm::fn = GET_SYMBOL(cblas_strsm); RealTrsm::fn = GET_SYMBOL(cblas_dtrsm); diff --git a/setup.py b/setup.py index 388a6b62c6..aff6f3a655 100644 --- a/setup.py +++ b/setup.py @@ -153,7 +153,7 @@ class CMakeBuild(build_ext): def initialize_options(self): super().initialize_options() self.define = None - self.verbosity = "" + self.verbosity = "-VVV" def finalize_options(self): # Parse the custom CMake options and store them in a new attribute @@ -219,7 +219,9 @@ def build_extension(self, ext): subprocess.check_call( [cmake_path, "-G", "Ninja", ext.sourcedir] + configure_args, cwd=build_temp ) - subprocess.check_call([cmake_path, "--build", "."] + build_args, cwd=build_temp) + subprocess.check_call( + [cmake_path, "--build", ".", "--verbose"] + build_args, cwd=build_temp + ) # Compile the library of custom calls in the frontend @@ -229,18 +231,10 @@ def build_extension(self, ext): elif system_platform == "Darwin": cmdclass = {"build_ext": CMakeExtension} - # variables = sysconfig.get_config_vars() - # Here we need to switch the deault to MacOs dynamic lib - # variables["LDSHARED"] = variables["LDSHARED"].replace("-bundle", "-dynamiclib") - # if sysconfig.get_config_var("LDCXXSHARED"): - # variables["LDCXXSHARED"] = variables["LDCXXSHARED"].replace("-bundle", "-dynamiclib") - # cmdclass = {"build_ext": CustomBuildExtMacos} - project_root_dir = os.path.abspath(os.path.dirname(__file__)) frontend_dir = os.path.join(project_root_dir, "frontend") ext_modules = [ - CMakeExtension("catalyst.utils.libcustom_calls", sourcedir=frontend_dir), CMakeExtension("catalyst.utils.wrapper", sourcedir=frontend_dir), ] @@ -266,6 +260,9 @@ def build_extension(self, ext): exclude=["catalyst.third_party.oqc.*"], ), package_dir={"": "frontend"}, + package_data={ + "catalyst.utils": [os.path.join(frontend_dir, "catalyst", "utils", "libcustom_calls.*")] + }, include_package_data=True, ext_modules=ext_modules, cmdclass={"build_ext": CMakeBuild}, From d5b6e4b8297f7e2e684c29d12833bda6c731f497 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Tue, 10 Dec 2024 17:10:52 -0500 Subject: [PATCH 13/28] Fix missing path in setup --- setup.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index aff6f3a655..99ec5eb726 100644 --- a/setup.py +++ b/setup.py @@ -20,9 +20,9 @@ import platform import subprocess import sys -from typing import Optional +from typing import Optional, Sequence, Union -from setuptools import Extension, find_namespace_packages, setup +from setuptools import Extension, find_namespace_packages, find_packages, setup from setuptools._distutils import sysconfig from setuptools.command.build_ext import build_ext @@ -236,6 +236,7 @@ def build_extension(self, ext): ext_modules = [ CMakeExtension("catalyst.utils.wrapper", sourcedir=frontend_dir), + CMakeExtension("catalyst.utils.libcustom_calls", sourcedir=frontend_dir), ] options = {"bdist_wheel": {"py_limited_api": "cp312"}} if sys.hexversion >= 0x030C0000 else {} @@ -246,6 +247,7 @@ def build_extension(self, ext): # - `ops`: Path to the compiler operations module. # - `qjit`: Path to the JIT compiler decorator provided by the compiler. + setup( classifiers=classifiers, name="PennyLane-Catalyst", @@ -260,9 +262,6 @@ def build_extension(self, ext): exclude=["catalyst.third_party.oqc.*"], ), package_dir={"": "frontend"}, - package_data={ - "catalyst.utils": [os.path.join(frontend_dir, "catalyst", "utils", "libcustom_calls.*")] - }, include_package_data=True, ext_modules=ext_modules, cmdclass={"build_ext": CMakeBuild}, From 67874e7701bf5641d21d6eb0f0406a611d24e339 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Wed, 11 Dec 2024 10:47:42 -0500 Subject: [PATCH 14/28] Force macos wheel builds to ignore universal --- .github/workflows/build-wheel-macos-arm64.yaml | 2 ++ .github/workflows/build-wheel-macos-x86_64.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/build-wheel-macos-arm64.yaml b/.github/workflows/build-wheel-macos-arm64.yaml index ad7a8e910c..26cfd6fc75 100644 --- a/.github/workflows/build-wheel-macos-arm64.yaml +++ b/.github/workflows/build-wheel-macos-arm64.yaml @@ -15,6 +15,8 @@ on: env: MACOSX_DEPLOYMENT_TARGET: 14.0 + _PYTHON_HOST_PLATFORM: "macosx-14.0-arm64" + ARCHFLAGS: "-arch arm64" concurrency: group: Build Catalyst Wheel on macOS (arm64)-${{ github.ref }} diff --git a/.github/workflows/build-wheel-macos-x86_64.yaml b/.github/workflows/build-wheel-macos-x86_64.yaml index af7878a672..0ec7dbf55b 100644 --- a/.github/workflows/build-wheel-macos-x86_64.yaml +++ b/.github/workflows/build-wheel-macos-x86_64.yaml @@ -15,6 +15,8 @@ on: env: MACOSX_DEPLOYMENT_TARGET: 13 + _PYTHON_HOST_PLATFORM: "macosx-13.0-x86_64" + ARCHFLAGS: "-arch x86_64" concurrency: group: Build Catalyst Wheel on macOS (x86_64)-${{ github.ref }} From c68f23723d48549297b47b61ca1d50456b54fd1d Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Wed, 11 Dec 2024 12:44:43 -0500 Subject: [PATCH 15/28] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 42af590ca2..7abc3b80c4 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ import sys from typing import Optional, Sequence, Union -from setuptools import Extension, find_namespace_packages, find_packages, setup +from setuptools import Extension, find_namespace_packages, setup from setuptools._distutils import sysconfig from setuptools.command.build_ext import build_ext From bd3d195ebfc42326118167abe79e8b98e730a934 Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Wed, 11 Dec 2024 12:44:48 -0500 Subject: [PATCH 16/28] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7abc3b80c4..68546e9e40 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ import platform import subprocess import sys -from typing import Optional, Sequence, Union +from typing import Optional from setuptools import Extension, find_namespace_packages, setup from setuptools._distutils import sysconfig From 4557ed9c6828021971aa33318ccde994ebe86a41 Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Wed, 11 Dec 2024 12:44:56 -0500 Subject: [PATCH 17/28] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 68546e9e40..13786ab8f4 100644 --- a/setup.py +++ b/setup.py @@ -154,7 +154,7 @@ class CMakeBuild(build_ext): def initialize_options(self): super().initialize_options() self.define = None - self.verbosity = "-VVV" + self.verbosity = "" def finalize_options(self): # Parse the custom CMake options and store them in a new attribute From 33ea71e125433ad5b5d6d66b26bf6ef8727eddb7 Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Wed, 11 Dec 2024 14:34:22 -0500 Subject: [PATCH 18/28] Update frontend/catalyst/utils/CMakeLists.txt Co-authored-by: David Ittah --- frontend/catalyst/utils/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/catalyst/utils/CMakeLists.txt b/frontend/catalyst/utils/CMakeLists.txt index 05480e0303..78cc38914f 100644 --- a/frontend/catalyst/utils/CMakeLists.txt +++ b/frontend/catalyst/utils/CMakeLists.txt @@ -60,4 +60,4 @@ set_target_properties(wrapper PROPERTIES SUFFIX ".so") add_dependencies(wrapper custom_calls) # Explicitly set RPATH to allow access to libraries within same directory -set_target_properties(wrapper PROPERTIES BUILD_RPATH "$ORIGIN") \ No newline at end of file +set_target_properties(wrapper PROPERTIES BUILD_RPATH "$ORIGIN") From 7b4a034084e050565bfe6493d0ecead045b5e418 Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Wed, 11 Dec 2024 14:35:32 -0500 Subject: [PATCH 19/28] Update frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt Co-authored-by: David Ittah --- frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt index 5f42902ab4..3b577a572f 100644 --- a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt +++ b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt @@ -39,4 +39,4 @@ set_property(TARGET catalyst_jax_cpu_lapack_kernels PROPERTY ENABLE_EXPORTS ON) # If building on MacOS avoid the linker complaining about undefined symbols if(APPLE) target_link_options(catalyst_jax_cpu_lapack_kernels PUBLIC -undefined dynamic_lookup) -endif() \ No newline at end of file +endif() From 9aee105406cdd8b5134f1ea062f297f8d808aca3 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Wed, 11 Dec 2024 14:51:55 -0500 Subject: [PATCH 20/28] remove unneeded branching --- setup.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/setup.py b/setup.py index 13786ab8f4..5e3b1329e1 100644 --- a/setup.py +++ b/setup.py @@ -225,13 +225,6 @@ def build_extension(self, ext): ) -# Compile the library of custom calls in the frontend -if system_platform == "Linux": - cmdclass = {"build_ext": CMakeExtension} - -elif system_platform == "Darwin": - cmdclass = {"build_ext": CMakeExtension} - project_root_dir = os.path.abspath(os.path.dirname(__file__)) frontend_dir = os.path.join(project_root_dir, "frontend") From b73ffde602782dde9ba6530edff543eb66d29d37 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Wed, 11 Dec 2024 14:52:42 -0500 Subject: [PATCH 21/28] Remove shared-lib specifics from builder --- frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt index 3b577a572f..b0507e5753 100644 --- a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt +++ b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt @@ -33,9 +33,6 @@ if(CATALYST_LINK_BLAS) ) endif() -# Ensure the availability of symbol exports. Only necessary with `SHARED` -set_property(TARGET catalyst_jax_cpu_lapack_kernels PROPERTY ENABLE_EXPORTS ON) - # If building on MacOS avoid the linker complaining about undefined symbols if(APPLE) target_link_options(catalyst_jax_cpu_lapack_kernels PUBLIC -undefined dynamic_lookup) From 32ceb397b132ef72eed14ba7f743fb1ada6eb702 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Wed, 11 Dec 2024 14:55:54 -0500 Subject: [PATCH 22/28] Remove CMake BLAS override option for custom calls lib --- .../utils/jax_cpu_lapack_kernels/CMakeLists.txt | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt index b0507e5753..180406b2c8 100644 --- a/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt +++ b/frontend/catalyst/utils/jax_cpu_lapack_kernels/CMakeLists.txt @@ -17,22 +17,6 @@ target_include_directories(catalyst_jax_cpu_lapack_kernels PUBLIC $ ) -# If the option is set, allow explicit linking of the CMake-found CBLAS/LAPACKE -# library. See https://cmake.org/cmake/help/latest/module/FindBLAS.html for info. -option(CATALYST_LINK_BLAS "Link the CMake-defined BLAS and LAPACK libraries as part of the extension module" OFF) - - -if(CATALYST_LINK_BLAS) - find_package( BLAS REQUIRED ) - find_package( LAPACK REQUIRED) - target_link_libraries(catalyst_jax_cpu_lapack_kernels PUBLIC BLAS::BLAS) - - # Ensure libraries are explicitly linked. - target_link_options(catalyst_jax_cpu_lapack_kernels PUBLIC - $<$:-Wl,--no-as-needed> - ) -endif() - # If building on MacOS avoid the linker complaining about undefined symbols if(APPLE) target_link_options(catalyst_jax_cpu_lapack_kernels PUBLIC -undefined dynamic_lookup) From 3f2b6b9759a0a04fe57b62fe139b03bbb403804d Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Wed, 11 Dec 2024 17:31:05 -0500 Subject: [PATCH 23/28] Rename to .so for now --- frontend/catalyst/utils/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/catalyst/utils/CMakeLists.txt b/frontend/catalyst/utils/CMakeLists.txt index 78cc38914f..391bf26c4b 100644 --- a/frontend/catalyst/utils/CMakeLists.txt +++ b/frontend/catalyst/utils/CMakeLists.txt @@ -23,6 +23,10 @@ set_property(TARGET custom_calls PROPERTY ENABLE_EXPORTS OFF) # value may be useful to avoid explicit library paths. set_target_properties(custom_calls PROPERTIES BUILD_RPATH "$ORIGIN/") +# Editable installations do not respect `package_data` in setup.py so +# build to mimic extension module expectations from setuptools+distutils +set_target_properties(wrapper PROPERTIES SUFFIX ".so") + # nanobind suggests including these lines to configure CMake to perform an optimized release build # by default unless another build type is specified. Without this addition, binding code may run # slowly and produce large binaries. From cc3e77aafea7fc2f9d5374a48fda26dce4b1e058 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Wed, 11 Dec 2024 17:38:55 -0500 Subject: [PATCH 24/28] Fix cmake target name --- frontend/catalyst/utils/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/catalyst/utils/CMakeLists.txt b/frontend/catalyst/utils/CMakeLists.txt index 391bf26c4b..3b1b3c24ea 100644 --- a/frontend/catalyst/utils/CMakeLists.txt +++ b/frontend/catalyst/utils/CMakeLists.txt @@ -25,7 +25,7 @@ set_target_properties(custom_calls PROPERTIES BUILD_RPATH "$ORIGIN/") # Editable installations do not respect `package_data` in setup.py so # build to mimic extension module expectations from setuptools+distutils -set_target_properties(wrapper PROPERTIES SUFFIX ".so") +set_target_properties(custom_calls PROPERTIES SUFFIX ".so") # nanobind suggests including these lines to configure CMake to perform an optimized release build # by default unless another build type is specified. Without this addition, binding code may run From 9386d0770d914cdb40dd633a1a887e1e89326a8a Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 13 Dec 2024 10:05:04 -0500 Subject: [PATCH 25/28] Force builder to use MacOS 13 as min wheel version --- .github/workflows/build-wheel-macos-arm64.yaml | 4 ++-- setup.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-wheel-macos-arm64.yaml b/.github/workflows/build-wheel-macos-arm64.yaml index 7c882267a3..1470ea855b 100644 --- a/.github/workflows/build-wheel-macos-arm64.yaml +++ b/.github/workflows/build-wheel-macos-arm64.yaml @@ -14,8 +14,8 @@ on: workflow_call: env: - MACOSX_DEPLOYMENT_TARGET: 14.0 - _PYTHON_HOST_PLATFORM: "macosx-14.0-arm64" + MACOSX_DEPLOYMENT_TARGET: 13.0 + _PYTHON_HOST_PLATFORM: "macosx-13.0-arm64" ARCHFLAGS: "-arch arm64" concurrency: diff --git a/setup.py b/setup.py index 6379dc4bd6..e71a9d8ad7 100644 --- a/setup.py +++ b/setup.py @@ -68,6 +68,13 @@ lightning_dep = f"pennylane-lightning>={lq_min_release}" kokkos_dep = "" +# Ensure MacOS minimum version is set for CMake builder +if platform.system() == "Darwin": + if val := os.environ.get("MACOSX_DEPLOYMENT_TARGET"): + MacOS_SDK_version = val + else: + MacOS_SDK_version = "13.0" + requirements = [ pennylane_dep, lightning_dep, @@ -210,6 +217,8 @@ def build_extension(self, ext): ) configure_args += self.cmake_defines + if platform.system() == "Darwin": + configure_args += f"-DCMAKE_OSX_DEPLOYMENT_TARGET={MacOS_SDK_version}" if "CMAKE_ARGS" in os.environ: configure_args += os.environ["CMAKE_ARGS"].split(" ") From 8580971904608045584a21740bf9f4749462027f Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 13 Dec 2024 10:34:27 -0500 Subject: [PATCH 26/28] Fix missing list --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e71a9d8ad7..740408329e 100644 --- a/setup.py +++ b/setup.py @@ -218,7 +218,7 @@ def build_extension(self, ext): configure_args += self.cmake_defines if platform.system() == "Darwin": - configure_args += f"-DCMAKE_OSX_DEPLOYMENT_TARGET={MacOS_SDK_version}" + configure_args += [f"-DCMAKE_OSX_DEPLOYMENT_TARGET={MacOS_SDK_version}"] if "CMAKE_ARGS" in os.environ: configure_args += os.environ["CMAKE_ARGS"].split(" ") From 599d98760af7f7a5bb162d814ae2ae9ad0bee93a Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 13 Dec 2024 11:15:41 -0500 Subject: [PATCH 27/28] Force set min mac version for wheel naming --- setup.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 740408329e..20de5d9c37 100644 --- a/setup.py +++ b/setup.py @@ -68,12 +68,13 @@ lightning_dep = f"pennylane-lightning>={lq_min_release}" kokkos_dep = "" -# Ensure MacOS minimum version is set for CMake builder +# Ensure MacOS minimum version is set for wheel & CMake builder if platform.system() == "Darwin": if val := os.environ.get("MACOSX_DEPLOYMENT_TARGET"): - MacOS_SDK_version = val + MacOS_SDK_VERSION = val else: - MacOS_SDK_version = "13.0" + MacOS_SDK_VERSION = "13.0" + os.environ["_PYTHON_HOST_PLATFORM"] = f"macosx-{MacOS_SDK_VERSION}-arm64" requirements = [ pennylane_dep, @@ -217,8 +218,10 @@ def build_extension(self, ext): ) configure_args += self.cmake_defines + if platform.system() == "Darwin": - configure_args += [f"-DCMAKE_OSX_DEPLOYMENT_TARGET={MacOS_SDK_version}"] + # Ensure use of -mmacosx-version-min=X compiler argument + configure_args += [f"-DCMAKE_OSX_DEPLOYMENT_TARGET={MacOS_SDK_VERSION}"] if "CMAKE_ARGS" in os.environ: configure_args += os.environ["CMAKE_ARGS"].split(" ") From 10e33d3f8359056bdc532a7fd4b2617bf30de70c Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 13 Dec 2024 11:19:09 -0500 Subject: [PATCH 28/28] Add missing platform tag --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 20de5d9c37..b0df55042d 100644 --- a/setup.py +++ b/setup.py @@ -74,7 +74,7 @@ MacOS_SDK_VERSION = val else: MacOS_SDK_VERSION = "13.0" - os.environ["_PYTHON_HOST_PLATFORM"] = f"macosx-{MacOS_SDK_VERSION}-arm64" + os.environ["_PYTHON_HOST_PLATFORM"] = f"macosx-{MacOS_SDK_VERSION}-{platform.machine()}" requirements = [ pennylane_dep,