diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8f61a8e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# SCM syntax highlighting +pixi.lock linguist-language=YAML linguist-generated=true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25949f9..aa64204 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,9 @@ on: schedule: # At 09:00 on Monday. (see https://crontab.guru) - cron: '0 9 * * 1' + pull_request: + branches: + - main defaults: run: @@ -19,7 +22,6 @@ jobs: matrix: os: ['ubuntu-24.04', 'macos-13', 'macos-14', 'windows-2022'] arch: ['x86_64', 'aarch64'] - python: ['3.10'] exclude: - os: 'ubuntu-24.04' # TODO: needs qemu setup arch: 'aarch64' @@ -35,14 +37,7 @@ jobs: - name: Checkout Finch-mlir uses: actions/checkout@v4 with: - path: 'Finch-mlir' - - - name: Checkout LLVM - uses: actions/checkout@v4 - with: - repository: llvm/llvm-project - ref: 'bb59eb8ed534da2bd03117cfde594321add4d60c' # Latest commit as of 2025-01-22 - path: 'llvm-project' + submodules: 'recursive' - name: Setup Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.4.1 @@ -61,7 +56,7 @@ jobs: - name: Setup ccache uses: hendrikmuhs/ccache-action@v1 with: - key: ${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.python }} + key: ${{ matrix.os }}-${{ matrix.arch }} max-size: "1G" verbose: 2 variant: ccache @@ -92,7 +87,7 @@ jobs: - name: Set env variables run: | echo "HOST_CCACHE_DIR="$(ccache --get-config cache_dir)"" >> $GITHUB_ENV - + - name: set env variables - macos if: contains(matrix.os, 'macos') shell: bash @@ -101,10 +96,8 @@ jobs: - name: cibuildwheel run env: - SPARSE_BACKEND: MLIR + SPARSE_BACKEND: "MLIR" run: | - mv ./Finch-mlir/setup.py . - mv ./Finch-mlir/pyproject.toml . cibuildwheel --output-dir ./wheelhouse ccache -s @@ -119,10 +112,11 @@ jobs: uses: actions/upload-artifact@v4 with: path: wheelhouse/*.whl - name: artifact_finch_mlir-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.python }} + name: artifact_finch_mlir-${{ matrix.os }}-${{ matrix.arch }} release-wheel: runs-on: 'ubuntu-latest' + if: github.ref_name == 'main' needs: build-wheel permissions: id-token: write diff --git a/.gitignore b/.gitignore index e524d79..b4bfc9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,15 @@ .vscode/ build/ +*.egg-info +dist/ +finch_mlir-*/ + +# pixi environments +.pixi +*.egg-info + +# Log files +*.log + +/wheelhouse/ +**/*.whl diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e9ec63c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,5 @@ +[submodule "llvm-project"] + path = llvm-project + url = https://github.com/llvm/llvm-project.git + branch = bb59eb8ed534da2bd03117cfde594321add4d60c + shallow = true diff --git a/CMakeLists.txt b/CMakeLists.txt index d6f7800..dfe0e2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,20 @@ cmake_minimum_required(VERSION 3.20.0) -project(finch-dialect LANGUAGES CXX C) +project(finch LANGUAGES CXX C) + +set(FINCH_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(FINCH_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") # https://github.com/iree-org/iree/blob/c96372348654eea8548509d38df5c8e8b179aef3/CMakeLists.txt#L275-L280 -find_package(Python3 COMPONENTS Interpreter Development NumPy) -find_package(Python3 COMPONENTS Interpreter Development.Module NumPy REQUIRED) -# nanobind uses Python_EXECUTABLE -find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED) - +if(MLIR_ENABLE_BINDINGS_PYTHON) + find_package(Python3 COMPONENTS Interpreter Development) + find_package(Python3 COMPONENTS Interpreter Development.Module NumPy REQUIRED) + # nanobind uses Python_EXECUTABLE + find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED) +endif() if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) find_package(MLIR REQUIRED CONFIG) @@ -18,8 +22,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin) - set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib) + set(LLVM_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/bin") + set(LLVM_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/lib") set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") @@ -31,10 +35,13 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) include(HandleLLVMOptions) else() # Build via external projects mechanism - set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir) - set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include) - set(MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/mlir/include) + set(MLIR_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR}/../mlir") + set(MLIR_INCLUDE_DIR "${MLIR_MAIN_SRC_DIR}/include") + set(MLIR_BINARY_DIR "${CMAKE_BINARY_DIR}") + set(MLIR_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/tools/mlir/include") set(MLIR_INCLUDE_DIRS "${MLIR_INCLUDE_DIR};${MLIR_GENERATED_INCLUDE_DIR}") + list(APPEND CMAKE_MODULE_PATH "${MLIR_MAIN_SRC_DIR}/cmake/modules") + include_directories("${MLIR_INCLUDE_DIRS}") endif() if(MLIR_ENABLE_BINDINGS_PYTHON) @@ -42,14 +49,10 @@ if(MLIR_ENABLE_BINDINGS_PYTHON) mlir_configure_python_dev_packages() endif() -set(FINCH_SOURCE_DIR ${PROJECT_SOURCE_DIR}) -set(FINCH_BINARY_DIR ${PROJECT_BINARY_DIR}) -include_directories(${LLVM_INCLUDE_DIRS}) -include_directories(${MLIR_INCLUDE_DIRS}) -include_directories(${FINCH_SOURCE_DIR}/include) -include_directories(${FINCH_BINARY_DIR}/include) -link_directories(${LLVM_BUILD_LIBRARY_DIR}) -add_definitions(${LLVM_DEFINITIONS}) +include_directories("${FINCH_SOURCE_DIR}/include") +include_directories("${FINCH_BINARY_DIR}/include") +link_directories("${LLVM_BUILD_LIBRARY_DIR}") +add_definitions("${LLVM_DEFINITIONS}") add_subdirectory(include) add_subdirectory(lib) @@ -57,6 +60,7 @@ if(MLIR_ENABLE_BINDINGS_PYTHON) message(STATUS "Enabling Python API") add_subdirectory(python) endif() + if(UNIX) add_subdirectory(test) add_subdirectory(finch-opt) diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..d449899 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include llvm-project **/* +recursive-exclude llvm-project/.git **/* diff --git a/include/Finch/CMakeLists.txt b/include/Finch/CMakeLists.txt index d8add84..940149e 100644 --- a/include/Finch/CMakeLists.txt +++ b/include/Finch/CMakeLists.txt @@ -4,8 +4,8 @@ add_mlir_doc(FinchOps FinchOps Finch/ -gen-op-doc) set(LLVM_TARGET_DEFINITIONS FinchPasses.td) mlir_tablegen(FinchPasses.h.inc --gen-pass-decls) -#mlir_tablegen(FinchOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=finch) -#mlir_tablegen(FinchOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=finch) +# mlir_tablegen(FinchOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=finch) +# mlir_tablegen(FinchOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=finch) add_public_tablegen_target(MLIRFinchPassesIncGen) set(LLVM_TARGET_DEFINITIONS FinchTypes.td) diff --git a/llvm-project b/llvm-project new file mode 160000 index 0000000..bb59eb8 --- /dev/null +++ b/llvm-project @@ -0,0 +1 @@ +Subproject commit bb59eb8ed534da2bd03117cfde594321add4d60c diff --git a/pixi.lock b/pixi.lock new file mode 100644 index 0000000..c56bf38 --- /dev/null +++ b/pixi.lock @@ -0,0 +1,257 @@ +version: 6 +environments: + default: + channels: + - url: https://conda.anaconda.org/conda-forge/ + packages: + osx-arm64: + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/bzip2-1.0.8-h99b78c6_7.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ca-certificates-2025.1.31-hf0a4a13_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.6.1-pyha770c72_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libexpat-2.6.4-h286801f_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libffi-3.4.2-h3422bc3_5.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/liblzma-5.6.4-h39f12f2_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libmpdec-4.0.0-h99b78c6_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libsqlite-3.48.0-h3f77e49_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libzlib-1.3.1-h8359307_2.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ncurses-6.5-h5e97a16_3.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/openssl-3.4.0-h81ee809_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/packaging-24.2-pyhd8ed1ab_2.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pip-25.0-pyh145f28c_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pyproject_hooks-1.2.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python-3.13.1-h4f43103_105_cp313.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-build-1.2.2.post1-pyhff2d567_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python_abi-3.13-5_cp313.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/readline-8.2-h92ec313_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/tk-8.6.13-h5083fa2_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/tomli-2.2.1-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2025a-h78e105d_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/zipp-3.21.0-pyhd8ed1ab_1.conda +packages: +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/bzip2-1.0.8-h99b78c6_7.conda + sha256: adfa71f158cbd872a36394c56c3568e6034aa55c623634b37a4836bd036e6b91 + md5: fc6948412dbbbe9a4c9ddbbcfe0a79ab + depends: + - __osx >=11.0 + license: bzip2-1.0.6 + license_family: BSD + size: 122909 + timestamp: 1720974522888 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/ca-certificates-2025.1.31-hf0a4a13_0.conda + sha256: 7e12816618173fe70f5c638b72adf4bfd4ddabf27794369bb17871c5bb75b9f9 + md5: 3569d6a9141adc64d2fe4797f3289e06 + license: ISC + size: 158425 + timestamp: 1738298167688 +- conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda + sha256: ab29d57dc70786c1269633ba3dff20288b81664d3ff8d21af995742e2bb03287 + md5: 962b9857ee8e7018c22f2776ffa0b2d7 + depends: + - python >=3.9 + license: BSD-3-Clause + license_family: BSD + size: 27011 + timestamp: 1733218222191 +- conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.6.1-pyha770c72_0.conda + sha256: 598951ebdb23e25e4cec4bbff0ae369cec65ead80b50bc08b441d8e54de5cf03 + md5: f4b39bf00c69f56ac01e020ebfac066c + depends: + - python >=3.9 + - zipp >=0.5 + license: Apache-2.0 + license_family: APACHE + size: 29141 + timestamp: 1737420302391 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libexpat-2.6.4-h286801f_0.conda + sha256: e42ab5ace927ee7c84e3f0f7d813671e1cf3529f5f06ee5899606630498c2745 + md5: 38d2656dd914feb0cab8c629370768bf + depends: + - __osx >=11.0 + constrains: + - expat 2.6.4.* + license: MIT + license_family: MIT + size: 64693 + timestamp: 1730967175868 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libffi-3.4.2-h3422bc3_5.tar.bz2 + sha256: 41b3d13efb775e340e4dba549ab5c029611ea6918703096b2eaa9c015c0750ca + md5: 086914b672be056eb70fd4285b6783b6 + license: MIT + license_family: MIT + size: 39020 + timestamp: 1636488587153 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/liblzma-5.6.4-h39f12f2_0.conda + sha256: 560c59d3834cc652a84fb45531bd335ad06e271b34ebc216e380a89798fe8e2c + md5: e3fd1f8320a100f2b210e690a57cd615 + depends: + - __osx >=11.0 + license: 0BSD + size: 98945 + timestamp: 1738525462560 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libmpdec-4.0.0-h99b78c6_0.conda + sha256: f7917de9117d3a5fe12a39e185c7ce424f8d5010a6f97b4333e8a1dcb2889d16 + md5: 7476305c35dd9acef48da8f754eedb40 + depends: + - __osx >=11.0 + license: BSD-2-Clause + license_family: BSD + size: 69263 + timestamp: 1723817629767 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libsqlite-3.48.0-h3f77e49_1.conda + sha256: 17c06940cc2a13fd6a17effabd6881b1477db38b2cd3ee2571092d293d3fdd75 + md5: 4c55169502ecddf8077973a987d08f08 + depends: + - __osx >=11.0 + - libzlib >=1.3.1,<2.0a0 + license: Unlicense + size: 852831 + timestamp: 1737564996616 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libzlib-1.3.1-h8359307_2.conda + sha256: ce34669eadaba351cd54910743e6a2261b67009624dbc7daeeafdef93616711b + md5: 369964e85dc26bfe78f41399b366c435 + depends: + - __osx >=11.0 + constrains: + - zlib 1.3.1 *_2 + license: Zlib + license_family: Other + size: 46438 + timestamp: 1727963202283 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/ncurses-6.5-h5e97a16_3.conda + sha256: 2827ada40e8d9ca69a153a45f7fd14f32b2ead7045d3bbb5d10964898fe65733 + md5: 068d497125e4bf8a66bf707254fff5ae + depends: + - __osx >=11.0 + license: X11 AND BSD-3-Clause + size: 797030 + timestamp: 1738196177597 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/openssl-3.4.0-h81ee809_1.conda + sha256: 97772762abc70b3a537683ca9fc3ff3d6099eb64e4aba3b9c99e6fce48422d21 + md5: 22f971393637480bda8c679f374d8861 + depends: + - __osx >=11.0 + - ca-certificates + license: Apache-2.0 + license_family: Apache + size: 2936415 + timestamp: 1736086108693 +- conda: https://conda.anaconda.org/conda-forge/noarch/packaging-24.2-pyhd8ed1ab_2.conda + sha256: da157b19bcd398b9804c5c52fc000fcb8ab0525bdb9c70f95beaa0bb42f85af1 + md5: 3bfed7e6228ebf2f7b9eaa47f1b4e2aa + depends: + - python >=3.8 + license: Apache-2.0 + license_family: APACHE + size: 60164 + timestamp: 1733203368787 +- conda: https://conda.anaconda.org/conda-forge/noarch/pip-25.0-pyh145f28c_0.conda + sha256: 314cd7254071bca8c44d70a011836db4b3fba4adf9afbbfcd884a4541243196a + md5: ae7cd0a3b7dd6e2a9b4fbba353c58ac3 + depends: + - python >=3.13.0a0 + license: MIT + license_family: MIT + size: 1255850 + timestamp: 1737901900785 +- conda: https://conda.anaconda.org/conda-forge/noarch/pyproject_hooks-1.2.0-pyhd8ed1ab_1.conda + sha256: 065ac44591da9abf1ff740feb25929554b920b00d09287a551fcced2c9791092 + md5: d4582021af437c931d7d77ec39007845 + depends: + - python >=3.9 + - tomli >=1.1.0 + license: MIT + license_family: MIT + size: 15528 + timestamp: 1733710122949 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/python-3.13.1-h4f43103_105_cp313.conda + build_number: 105 + sha256: 7d27cc8ef214abbdf7dd8a5d473e744f4bd9beb7293214a73c58e4895c2830b8 + md5: 11d916b508764b7d881dd5c75d222d6e + depends: + - __osx >=11.0 + - bzip2 >=1.0.8,<2.0a0 + - libexpat >=2.6.4,<3.0a0 + - libffi >=3.4,<4.0a0 + - liblzma >=5.6.3,<6.0a0 + - libmpdec >=4.0.0,<5.0a0 + - libsqlite >=3.47.2,<4.0a0 + - libzlib >=1.3.1,<2.0a0 + - ncurses >=6.5,<7.0a0 + - openssl >=3.4.0,<4.0a0 + - python_abi 3.13.* *_cp313 + - readline >=8.2,<9.0a0 + - tk >=8.6.13,<8.7.0a0 + - tzdata + license: Python-2.0 + size: 12919840 + timestamp: 1736761931666 + python_site_packages_path: lib/python3.13/site-packages +- conda: https://conda.anaconda.org/conda-forge/noarch/python-build-1.2.2.post1-pyhff2d567_1.conda + sha256: da40ab7413029351852268ca479e5cc642011c72317bd02dba28235c5c5ec955 + md5: 0903621fe8a9f37286596529528f4f74 + depends: + - colorama + - importlib-metadata >=4.6 + - packaging >=19.0 + - pyproject_hooks + - python >=3.9 + - tomli >=1.1.0 + constrains: + - build <0 + license: MIT + license_family: MIT + size: 25108 + timestamp: 1733230700715 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/python_abi-3.13-5_cp313.conda + build_number: 5 + sha256: 4437198eae80310f40b23ae2f8a9e0a7e5c2b9ae411a8621eb03d87273666199 + md5: b8e82d0a5c1664638f87f63cc5d241fb + constrains: + - python 3.13.* *_cp313 + license: BSD-3-Clause + license_family: BSD + size: 6322 + timestamp: 1723823058879 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/readline-8.2-h92ec313_1.conda + sha256: a1dfa679ac3f6007362386576a704ad2d0d7a02e98f5d0b115f207a2da63e884 + md5: 8cbb776a2f641b943d413b3e19df71f4 + depends: + - ncurses >=6.3,<7.0a0 + license: GPL-3.0-only + license_family: GPL + size: 250351 + timestamp: 1679532511311 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/tk-8.6.13-h5083fa2_1.conda + sha256: 72457ad031b4c048e5891f3f6cb27a53cb479db68a52d965f796910e71a403a8 + md5: b50a57ba89c32b62428b71a875291c9b + depends: + - libzlib >=1.2.13,<2.0.0a0 + license: TCL + license_family: BSD + size: 3145523 + timestamp: 1699202432999 +- conda: https://conda.anaconda.org/conda-forge/noarch/tomli-2.2.1-pyhd8ed1ab_1.conda + sha256: 18636339a79656962723077df9a56c0ac7b8a864329eb8f847ee3d38495b863e + md5: ac944244f1fed2eb49bae07193ae8215 + depends: + - python >=3.9 + license: MIT + license_family: MIT + size: 19167 + timestamp: 1733256819729 +- conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2025a-h78e105d_0.conda + sha256: c4b1ae8a2931fe9b274c44af29c5475a85b37693999f8c792dad0f8c6734b1de + md5: dbcace4706afdfb7eb891f7b37d07c04 + license: LicenseRef-Public-Domain + size: 122921 + timestamp: 1737119101255 +- conda: https://conda.anaconda.org/conda-forge/noarch/zipp-3.21.0-pyhd8ed1ab_1.conda + sha256: 567c04f124525c97a096b65769834b7acb047db24b15a56888a322bf3966c3e1 + md5: 0c3cc595284c5e8f0f9900a9b228a332 + depends: + - python >=3.9 + license: MIT + license_family: MIT + size: 21809 + timestamp: 1732827613585 diff --git a/pixi.toml b/pixi.toml new file mode 100644 index 0000000..9a2370a --- /dev/null +++ b/pixi.toml @@ -0,0 +1,14 @@ +[project] +authors = ["Hameer Abbasi <2190658+hameerabbasi@users.noreply.github.com>"] +channels = ["conda-forge"] +description = "Add a short description here" +name = "Finch-mlir" +platforms = ["osx-arm64"] +version = "0.1.0" + +[tasks] + +[dependencies] +python = ">=3.10" +pip = ">=24" +python-build = "*" diff --git a/pyproject.toml b/pyproject.toml index 24f89fe..a3c89e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,43 +1,91 @@ [build-system] requires = [ - "setuptools>=42", "wheel", "ninja", - "cmake>=3.12", + "cmake>=3.20", "pybind11>=2.10.4", - "numpy", + "numpy>=2", "PyYAML", "nanobind", + "delvewheel; platform_system=='Windows'", + "setuptools-scm>=8", + "scikit-build-core>=0.10,<0.11" ] +build-backend = "scikit_build_core.build" + +[project] +name = "finch-mlir" +dynamic = ["version"] +description = "Finch MLIR distribution as wheel." +readme = "README.md" +dependencies = [ + "PyYAML>=6", + "numpy>=1.17", +] + +[tool.setuptools_scm] + +[tool.scikit-build] +cmake.source-dir = "llvm-project/llvm" +ninja.make-fallback = false +build-dir = "build" +cmake.args = ["-G Ninja", "-UNB_SUFFIX", "-UNB_SUFFIX_S"] +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +wheel.exclude = ["**/*", "!mlir_finch/**/*"] +wheel.packages = [] + +[tool.scikit-build.cmake.define] +LLVM_EXTERNAL_PROJECTS = "finch" +LLVM_EXTERNAL_FINCH_SOURCE_DIR= "." +MLIR_ENABLE_BINDINGS_PYTHON = true +LLVM_ENABLE_PROJECTS = "mlir" +LLVM_TARGETS_TO_BUILD = "Native" +LLVM_CCACHE_BUILD = true +LLVM_ENABLE_ZLIB = false +LLVM_ENABLE_ZSTD = false +CMAKE_PLATFORM_NO_VERSIONED_SONAME = true + +[[tool.scikit-build.overrides]] +if.platform-system = "^darwin" +inherit.cmake.define = "append" +cmake.define.CMAKE_OSX_DEPLOYMENT_TARGET = "11.0" + +[[tool.scikit-build.overrides]] +if.platform-system = "^win32" +inherit.cmake.define = "append" +cmake.define.CMAKE_C_COMPILER = "clang-cl" +cmake.define.CMAKE_CXX_COMPILER = "clang-cl" +cmake.define.CMAKE_MSVC_RUNTIME_LIBRARY = "MultiThreaded" +cmake.define.CMAKE_C_FLAGS = "/MT" +cmake.define.CMAKE_CXX_FLAGS = "/MT" [tool.cibuildwheel] build = "cp310-* cp311-* cp312-* cp313-*" +build-frontend = { name = "build", args = ["--no-isolation"] } build-verbosity = 1 test-requires = ["pytest", "pytest-cov", "PyYAML", "scipy"] +before-build = [ + # These two lines get the build requirements from `pyproject.toml` + "pip install pip-tools", + "pip-compile --all-build-deps -o \"{project}/build-reqs.txt\" \"{project}/pyproject.toml\"", + # We install them since we're building without isolation. + "pip install -r \"{project}/build-reqs.txt\"", + # We remove the residual *.so files specific to a CPython version from the last build. + "find \"{project}\" -name *.cpython-*.so -type f -delete" +] before-test = "pip install --no-deps sparse@git+https://github.com/pydata/sparse.git" test-command = "python -m pytest --pyargs sparse.mlir_backend" [tool.cibuildwheel.linux] skip = ["*-manylinux_i686", "*-musllinux*"] environment = { PATH = "/usr/lib/ccache:/usr/lib64/ccache:/usr/lib/ccache/bin:$PATH" } -before-build = [ - "pip install -r {project}/Finch-mlir/requirements/requirements.txt", - "{project}/Finch-mlir/scripts/docker_prepare_ccache.sh" -] environment-pass = ["HOST_CCACHE_DIR", "SPARSE_BACKEND"] +before-all = [ + "\"{project}/scripts/docker_prepare_ccache.sh\"" +] [tool.cibuildwheel.macos] environment = { PATH = "/usr/local/opt/ccache/libexec:$PATH" } -before-build = [ - "pip install -r {project}/Finch-mlir/requirements/requirements.txt", -] -repair-wheel-command = [ - "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} --ignore-missing-dependencies" -] [tool.cibuildwheel.windows] build = "cp310-win_amd64 cp311-win_amd64 cp312-win_amd64 cp313-win_amd64" -before-build = [ - "pip install delvewheel", - "pip install -r {project}\\Finch-mlir\\requirements\\requirements.txt", -] diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 7f9efae..7eec0ae 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -66,3 +66,7 @@ add_mlir_python_modules(FinchPythonModules COMMON_CAPI_LINK_LIBS FinchPythonCAPI ) + +if (DEFINED SKBUILD) + install(DIRECTORY "${MLIR_BINARY_DIR}/python_packages/finch/mlir_finch" DESTINATION "${SKBUILD_PLATLIB_DIR}" USE_SOURCE_PERMISSIONS) +endif() diff --git a/requirements/requirements.txt b/requirements/requirements.txt deleted file mode 100644 index d81173c..0000000 --- a/requirements/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -setuptools>=42 -wheel -ninja -cmake>=3.12 -pybind11>=2.10.4 -numpy -PyYAML -nanobind diff --git a/setup.py b/setup.py deleted file mode 100644 index ed087d9..0000000 --- a/setup.py +++ /dev/null @@ -1,174 +0,0 @@ -import os -import platform -import shutil -import sys -import subprocess -from pathlib import Path -from sysconfig import get_paths - -import ninja -from setuptools import Extension, setup -from setuptools.command.build_ext import build_ext - - -class CMakeExtension(Extension): - def __init__( - self, - name: str, - llvm_source_dir: str, - finch_source_dir: str, - ) -> None: - super().__init__(name, sources=[]) - self.llvm_source_dir = os.fspath(Path(llvm_source_dir).resolve()) - self.finch_source_dir = os.fspath(Path(finch_source_dir).resolve()) - - -class CMakeBuild(build_ext): - def build_extension(self, ext: CMakeExtension) -> None: - ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name) - extdir = ext_fullpath.parent.resolve() - install_dir = extdir - ninja_executable_path = Path(ninja.BIN_DIR) / "ninja" - PYTHON_EXECUTABLE = str(Path(sys.executable)) - include_path = get_paths()["include"] - - extra_flags = [ - # pybind11 and nanobind use different names - f"-DPython_INCLUDE_DIR={include_path}", - f"-DPython3_INCLUDE_DIR={include_path}", - f"-DPYTHON_INCLUDE_DIR={include_path}", - ] - if sys.platform.startswith("darwin"): - extra_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0") - elif platform.system() == "Windows": - extra_flags += [ - "-DCMAKE_C_COMPILER=cl", - "-DCMAKE_CXX_COMPILER=cl", - "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", - "-DCMAKE_C_FLAGS=/MT", - "-DCMAKE_CXX_FLAGS=/MT", - ] - libs_path = Path(include_path).parent / "libs" - library_path = libs_path / f"python3{sys.version_info.minor}.lib" - for python_name in ["Python", "Python3", "PYTHON"]: - extra_flags += [ - f"-D{python_name}_LIBRARY={library_path}", - f"-D{python_name}_LIBRARY_DIRS={libs_path}", - ] - - # BUILD LLVM - llvm_cmake_args = [ - "-G Ninja", - f"-B{llvm_build_dir}", - "-DLLVM_ENABLE_PROJECTS=mlir", - "-DLLVM_TARGETS_TO_BUILD=Native", - "-DMLIR_ENABLE_BINDINGS_PYTHON=ON", - f"-DPython3_EXECUTABLE={PYTHON_EXECUTABLE}", - f"-DPython_EXECUTABLE={PYTHON_EXECUTABLE}", - f"-DPYTHON_EXECUTABLE={PYTHON_EXECUTABLE}", - f"-UNB_SUFFIX", - f"-UNB_SUFFIX_S", - "-DLLVM_INSTALL_UTILS=ON", - "-DLLVM_CCACHE_BUILD=ON", - "-DCMAKE_BUILD_TYPE=Release", - "-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON", - f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}", - "-DLLVM_ENABLE_ZLIB=OFF", - "-DLLVM_ENABLE_ZSTD=OFF", - *extra_flags, - ] - - subprocess.run( - ["cmake", ext.llvm_source_dir, *llvm_cmake_args], cwd=llvm_build_dir, check=True, - ) - subprocess.run([ninja_executable_path], cwd=llvm_build_dir, check=True) - - # INSTALL LLVM - subprocess.run( - ["cmake", f"-DCMAKE_INSTALL_PREFIX={llvm_install_dir}", "-Pcmake_install.cmake"], - cwd=llvm_build_dir, - check=True, - ) - - llvm_lit = "llvm-lit.py" if platform.system() == "Windows" else "llvm-lit" - - # BUILD FINCH DIALECT - dialect_cmake_args = [ - "-G Ninja", - f"-B{finch_build_dir}", - f"-DMLIR_DIR={llvm_install_dir / 'lib' / 'cmake' / 'mlir'}", - f"-DLLVM_EXTERNAL_LIT={llvm_build_dir / 'bin' / llvm_lit}", - "-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON", - f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}", - "-DLLVM_ENABLE_ZLIB=OFF", - "-DLLVM_ENABLE_ZSTD=OFF", - f"-DPython3_EXECUTABLE={PYTHON_EXECUTABLE}", - f"-DPython_EXECUTABLE={PYTHON_EXECUTABLE}", - f"-DPYTHON_EXECUTABLE={PYTHON_EXECUTABLE}", - f"-UNB_SUFFIX", - f"-UNB_SUFFIX_S", - *extra_flags, - ] - - subprocess.run( - ["cmake", ext.finch_source_dir, *dialect_cmake_args], cwd=finch_build_dir, check=True, - ) - subprocess.run([ninja_executable_path], cwd=finch_build_dir, check=True) - - # INSTALL FINCH DIALECT - subprocess.run( - ["cmake", f"-DCMAKE_INSTALL_PREFIX={install_dir}", "-Pcmake_install.cmake"], - cwd=finch_build_dir, - check=True, - ) - - # Move Python package out of nested directories. - python_package_dir = install_dir / "python_packages" / "finch" / "mlir_finch" - shutil.copytree(python_package_dir, install_dir / "mlir_finch") - shutil.rmtree(install_dir / "python_packages") - - subprocess.run( - [ - "find", - ".", - "-exec", - "touch", - "-a", - "-m", - "-t", - "197001010000", - "{}", - ";", - ], - cwd=install_dir, - check=False, - ) - - -def create_dir(name: str) -> Path: - path = Path.cwd() / "build" / name - if not path.exists(): - path.mkdir(parents=True) - return path - - -llvm_build_dir = create_dir("llvm-build") -llvm_install_dir = create_dir("llvm-install") -finch_build_dir = create_dir("finch-build") - - -setup( - name="finch-mlir", - version="0.0.2", - include_package_data=True, - description="Finch MLIR distribution as wheel.", - long_description="Finch MLIR distribution as wheel.", - long_description_content_type="text/markdown", - ext_modules=[CMakeExtension( - "mlir_finch_ext", - llvm_source_dir=f"./llvm-project/llvm", - finch_source_dir="./Finch-mlir", - )], - cmdclass={"build_ext": CMakeBuild}, - zip_safe=False, -)