From 74624c736c01c03cf625d0ce5bd18d1eed7f1edc Mon Sep 17 00:00:00 2001 From: Mykhailo Moroz Date: Sun, 4 May 2025 21:45:40 +0200 Subject: [PATCH 1/8] update all build related stuff --- .github/workflows/build-macos.yml | 34 +- .idea/editor.xml | 815 ++++++++---------- .run/TensorFrost.run.xml | 2 +- CMakeLists.txt | 2 +- Python/pyproject.toml | 19 +- README.md | 19 +- TensorFrost/CMakeLists.txt | 14 +- TensorFrost/Compiler/KernelGen.cpp | 2 +- .../Frontend/Python/Definitions/PyTensor.cpp | 9 + build.sh | 3 - build_all.sh | 44 - build_all_python_versions.cmd | 12 - build_manylinux.sh | 40 +- build_windows.ps1 | 25 +- clean_rebuild.cmd | 6 +- examples/Algorithms/fft_group.ipynb | 30 +- requirements.txt | 1 - 17 files changed, 421 insertions(+), 656 deletions(-) delete mode 100644 build.sh delete mode 100644 build_all.sh delete mode 100644 build_all_python_versions.cmd delete mode 100644 requirements.txt diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index f753719f..129854ff 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -26,7 +26,7 @@ jobs: pip install -r requirements.txt pip install cmake build # or other tools you need - - name: Configure CMake + - name: Build wheel run: | # Grab the path to the "python" selected by setup-python export PYTHON_EXECUTABLE="$(which python)" @@ -36,40 +36,12 @@ jobs: echo "Python version: $PYTHON_VERSION" echo "Python executable: $PYTHON_EXECUTABLE" - - cmake \ - -DPYBIND11_PYTHON_VERSION="${PYTHON_VERSION}" \ - -DPython3_EXECUTABLE="${PYTHON_EXECUTABLE}" \ - -DPython_FIND_STRATEGY=LOCATION \ - -DPython_FIND_REGISTRY=NEVER \ - -DPython_FIND_FRAMEWORK=NEVER \ - -S . \ - -B build \ - -DCMAKE_BUILD_TYPE=Release - - - name: Build - run: cmake --build build --config Release - - - name: Fix library pathing - run: | - # Find the shared object file under the Python/TensorFrost folder. - # This command will locate any *.so file - SO_FILE=$(find Python/TensorFrost -type f -name "*.so") - if [ -z "$SO_FILE" ]; then - echo "No shared library found!" - exit 1 - fi - echo "Found shared library: $SO_FILE" - # Add the rpath relative to the shared library’s loader - install_name_tool -add_rpath @loader_path/. "$SO_FILE" + + ${PYTHON_EXECUTABLE} -m pip wheel /Python -w Python/dist --verbose - name: Check Folder run: ls -R ./Python - - name: Build wheel - run: | - python -m build -w ./Python - - name: Upload wheels as artifact uses: actions/upload-artifact@v4 with: diff --git a/.idea/editor.xml b/.idea/editor.xml index b0d69ef6..6692539a 100644 --- a/.idea/editor.xml +++ b/.idea/editor.xml @@ -1,483 +1,342 @@ - \ No newline at end of file diff --git a/.run/TensorFrost.run.xml b/.run/TensorFrost.run.xml index 966b7b84..ed008d4d 100644 --- a/.run/TensorFrost.run.xml +++ b/.run/TensorFrost.run.xml @@ -1,5 +1,5 @@ - + diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b49070b..3c927cf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.15) project(TensorFrost) if(NOT CMAKE_BUILD_TYPE) diff --git a/Python/pyproject.toml b/Python/pyproject.toml index 193ee228..ef6dcee6 100644 --- a/Python/pyproject.toml +++ b/Python/pyproject.toml @@ -1,6 +1,10 @@ [build-system] -requires = ["setuptools>=64", "wheel"] -build-backend = "setuptools.build_meta" +requires = [ + "scikit-build-core>=0.11", + "pybind11>=2.12", + "jinja2>=3.1" +] +build-backend = "scikit_build_core.build" [project] name = "TensorFrost" @@ -28,6 +32,15 @@ classifiers = [ "Environment :: X11 Applications", "Environment :: GPU", ] +readme = "../README.md" [tool.setuptools.package-data] -"TensorFrost" = ["*.so", "*.pyd", "*.dll", "*.dylib"] \ No newline at end of file +"TensorFrost" = ["*.so", "*.pyd", "*.dll", "*.dylib"] + +[tool.scikit-build] + +[tool.scikit-build.cmake] +source-dir = ".." + +[tool.scikit-build.logging] +level = "INFO" diff --git a/README.md b/README.md index b19fde8e..b71a4217 100644 --- a/README.md +++ b/README.md @@ -54,17 +54,17 @@ git clone --recurse-submodules https://github.com/MichaelMoroz/TensorFrost.git cd TensorFrost ``` -Then run cmake to build the library. +Then you can either install the library for development or build a wheel file for distribution. ```bash -cmake -S . -B build && cmake --build build +python -m pip install --upgrade pip setuptools wheel +python -m pip install -e Python/ -v # install the library for development +python -m pip wheel ./Python -w dist -v # build a wheel file ``` > [!TIP] > If you are using a Linux distribution that doesn't support installing packages through pip (e.g. Arch Linux), read **[Using a Virtual Environment](#using-a-virtual-environment)**. -The cmake script will automatically install the compiled python module into your python environment. - ### Using a Virtual Environment Certain Linux distributions (e.g. Arch Linux) want you to use their package manager to manage system-wide Python packages instead of pip. TensorFrost uses pip to install itself once built, so before running CMake you will need to activate a Virtual Environment. @@ -81,16 +81,13 @@ Certain Linux distributions (e.g. Arch Linux) want you to use their package mana source venv/bin/activate ``` -3. Install `jinja` (required for building) - - ```sh - pip install jinja - ``` -4. Now, you can use CMake as usual. +4. Now, you can use pip to install the library: ```bash - cmake -S . -B build && cmake --build build + python -m pip install --upgrade pip setuptools wheel + python -m pip install -e Python/ -v # install the library for development + python -m pip wheel ./Python -w dist -v # build a wheel file ``` > [!TIP] diff --git a/TensorFrost/CMakeLists.txt b/TensorFrost/CMakeLists.txt index 50a51762..db1ea482 100644 --- a/TensorFrost/CMakeLists.txt +++ b/TensorFrost/CMakeLists.txt @@ -3,6 +3,14 @@ file(GLOB_RECURSE TENSORFROST_HEADER_LIST CONFIGURE_DEPENDS *.h *.hpp) pybind11_add_module(TensorFrost ${TENSORFROST_SOURCE_LIST} ${TENSORFROST_HEADER_LIST}) +if(APPLE) + set(CMAKE_MACOSX_RPATH ON) + set_target_properties(TensorFrost PROPERTIES + BUILD_WITH_INSTALL_RPATH ON + INSTALL_RPATH "@loader_path/." + ) +endif() + # Add GLFW target_link_libraries(TensorFrost PRIVATE glfw) @@ -29,12 +37,6 @@ target_sources(TensorFrost PRIVATE ${IMGUI_SOURCE_LIST} ${IMGUI_BACKEND_SOURCE_L #add renderdoc headers target_include_directories(TensorFrost PRIVATE ${CMAKE_SOURCE_DIR}/external/renderdoc) -add_custom_command( - TARGET TensorFrost - POST_BUILD - COMMAND ${Python3_EXECUTABLE} -m pip install -e Python/ - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) add_custom_target(install_python_package ALL DEPENDS TensorFrost diff --git a/TensorFrost/Compiler/KernelGen.cpp b/TensorFrost/Compiler/KernelGen.cpp index 6d23e7f0..4c0cd3e1 100644 --- a/TensorFrost/Compiler/KernelGen.cpp +++ b/TensorFrost/Compiler/KernelGen.cpp @@ -4,7 +4,7 @@ namespace TensorFrost { Program* GenerateProgram(IR* ir) { - ir->CompileIR(); + ir->CompileIR(); auto* program = new Program(ir); diff --git a/TensorFrost/Frontend/Python/Definitions/PyTensor.cpp b/TensorFrost/Frontend/Python/Definitions/PyTensor.cpp index bb779c4c..750b8c02 100644 --- a/TensorFrost/Frontend/Python/Definitions/PyTensor.cpp +++ b/TensorFrost/Frontend/Python/Definitions/PyTensor.cpp @@ -88,6 +88,15 @@ void PyTensorDefinition(py::module& /*m*/, py::class_& py_tensor) { } return indices; }); + py_tensor.def_property_readonly("op_name", [](const PyTensor& t) { + return T(t).node_->name; + }); + py_tensor.def("try_get_constant", [](const PyTensor& t) { + if(T(t).node_->name != "const") { + throw std::runtime_error("Can not get constant from non-constant tensor"); + } + return T(t).TryGetConstant(); + }); py_tensor.def("index",[](const PyTensor& t, int dim) { int dims = T(t).GetDimension(); return PT(T(t).Index(dims - dim - 1)); diff --git a/build.sh b/build.sh deleted file mode 100644 index 7f7e615d..00000000 --- a/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -sudo apt-get install xorg-dev -pip install jinja2 -cmake -S . -B build && cmake --build build \ No newline at end of file diff --git a/build_all.sh b/build_all.sh deleted file mode 100644 index c3b11446..00000000 --- a/build_all.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -export PATH="$HOME/.pyenv/bin:$PATH" -eval "$(pyenv init --path)" -eval "$(pyenv init -)" - -# Define the list of Python versions -PYTHON_VERSIONS="3.7 3.8 3.9 3.10 3.11 3.12" - -# Function to check if a specific Python version is installed -check_python_version() { - if ! pyenv versions | grep -q "$1"; then - echo "Python $1 not found, attempting to install..." - pyenv install "$1" - fi -} - -clean_rebuild() { - # Set the Python version for pyenv - pyenv local "$1" - - # Reload the shell environment - eval "$(pyenv init -)" - - # Refresh the shell environment to ensure pyenv shims are used - export PATH="$(pyenv root)/shims:$PATH" - - # Get the path of the current Python interpreter - PYTHON_PATH=$(pyenv which python) - - # Rest of your build commands - git clean -d -x -f -e Python/dist - cmake -DPYBIND11_PYTHON_VERSION="$1" -DPYTHON_EXECUTABLE="$PYTHON_PATH" -S . -B build -DCMAKE_BUILD_TYPE=Release - cmake --build build - "$PYTHON_PATH" -m pip install build - "$PYTHON_PATH" -m build -w ./Python -} - -# Main loop -for VERSION in $PYTHON_VERSIONS; do - echo "Building for Python $VERSION" - check_python_version "$VERSION" - clean_rebuild "$VERSION" -done diff --git a/build_all_python_versions.cmd b/build_all_python_versions.cmd deleted file mode 100644 index d008ca7c..00000000 --- a/build_all_python_versions.cmd +++ /dev/null @@ -1,12 +0,0 @@ -@echo off -setlocal - -REM Define the list of Python versions -set PYTHON_VERSIONS=3.7 3.8 3.9 3.10 3.11 3.12 - -for %%v in (%PYTHON_VERSIONS%) do ( - echo Building for Python %%v - call clean_rebuild %%v -) - -endlocal \ No newline at end of file diff --git a/build_manylinux.sh b/build_manylinux.sh index a298a37f..1cd3ae9b 100644 --- a/build_manylinux.sh +++ b/build_manylinux.sh @@ -20,27 +20,27 @@ export PYTHON_ROOT=/opt/python/$PYTHON_VERSION export PATH=$PYTHON_ROOT/bin:$PATH export PYTHON_EXECUTABLE=$PYTHON_ROOT/bin/python -$PYTHON_EXECUTABLE -m pip install --upgrade pip -r requirements.txt cmake build auditwheel +#$PYTHON_EXECUTABLE -m pip install --upgrade pip -r requirements.txt cmake build auditwheel +# +## Extract Python version (e.g., 3.7, 3.8, etc.) +#PY_VERSION=$($PYTHON_EXECUTABLE -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') +# +#echo "Python version: $PY_VERSION" +#echo "Python executable: $PYTHON_EXECUTABLE" +# +#$PYTHON_EXECUTABLE -m cmake \ +# -DPython3_ROOT_DIR=$PYTHON_ROOT \ +# -DPython3_EXECUTABLE=$PYTHON_EXECUTABLE \ +# -DPython_FIND_STRATEGY=LOCATION \ +# -DPython_FIND_REGISTRY=NEVER \ +# -DPython_FIND_FRAMEWORK=NEVER \ +# -DPYBIND11_PYTHON_VERSION=$PY_VERSION \ +# -DCMAKE_C_FLAGS="-D_POSIX_C_SOURCE=200809L -Wno-deprecated-declarations" \ +# -DCMAKE_CXX_FLAGS="-D_POSIX_C_SOURCE=200809L -Wno-deprecated-declarations" \ +# -S . -B build -DCMAKE_BUILD_TYPE=Release + +$PYTHON_EXECUTABLE -m pip wheel ./Python -w Python/dist --verbose -# Extract Python version (e.g., 3.7, 3.8, etc.) -PY_VERSION=$($PYTHON_EXECUTABLE -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') - -echo "Python version: $PY_VERSION" -echo "Python executable: $PYTHON_EXECUTABLE" - -$PYTHON_EXECUTABLE -m cmake \ - -DPython3_ROOT_DIR=$PYTHON_ROOT \ - -DPython3_EXECUTABLE=$PYTHON_EXECUTABLE \ - -DPython_FIND_STRATEGY=LOCATION \ - -DPython_FIND_REGISTRY=NEVER \ - -DPython_FIND_FRAMEWORK=NEVER \ - -DPYBIND11_PYTHON_VERSION=$PY_VERSION \ - -DCMAKE_C_FLAGS="-D_POSIX_C_SOURCE=200809L -Wno-deprecated-declarations" \ - -DCMAKE_CXX_FLAGS="-D_POSIX_C_SOURCE=200809L -Wno-deprecated-declarations" \ - -S . -B build -DCMAKE_BUILD_TYPE=Release - -$PYTHON_EXECUTABLE -m cmake --build build --config Release -$PYTHON_EXECUTABLE -m build -w ./Python for whl in Python/dist/*.whl; do auditwheel repair "$whl" -w ./wheelhouse/ done \ No newline at end of file diff --git a/build_windows.ps1 b/build_windows.ps1 index 141047ec..f82aa9a9 100644 --- a/build_windows.ps1 +++ b/build_windows.ps1 @@ -1,25 +1,2 @@ -# Install dependencies python -m pip install --upgrade pip -pip install -r requirements.txt -pip install build twine - -# Configure CMake -$env:PYTHON_EXECUTABLE = (Get-Command python).Path -$env:PYTHON_VERSION = (python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") -echo "Python version: $env:PYTHON_VERSION" -echo "Python executable: $env:PYTHON_EXECUTABLE" - -cmake -DPYBIND11_PYTHON_VERSION="$env:PYTHON_VERSION" ` - -DPython3_ROOT_DIR="$env:PYTHONLOCATION" ` - -DPython3_EXECUTABLE="$env:PYTHON_EXECUTABLE" ` - -DPython_FIND_STRATEGY=LOCATION ` - -DPython_FIND_REGISTRY=NEVER ` - -DPython_FIND_FRAMEWORK=NEVER ` - -S . -B build -DCMAKE_BUILD_TYPE=Release - -# Build the project with parallel jobs -$env:NUMBER_OF_PROCESSORS = (Get-WmiObject -Class Win32_ComputerSystem).NumberOfLogicalProcessors -cmake --build build --config Release --parallel $env:NUMBER_OF_PROCESSORS - -# Build the wheel -python -m build -w ./Python \ No newline at end of file +python -m pip wheel ./Python -w dist --verbose diff --git a/clean_rebuild.cmd b/clean_rebuild.cmd index 56e837f0..b1ac24c3 100644 --- a/clean_rebuild.cmd +++ b/clean_rebuild.cmd @@ -3,8 +3,4 @@ set PYTHON_VERSION=%1 if "%PYTHON_VERSION%"=="" set PYTHON_VERSION=3.12 git clean -d -x -f -e Python/dist -py -%PYTHON_VERSION% -m pip install jinja2 -cmake -DPYBIND11_PYTHON_VERSION=%PYTHON_VERSION% -S . -B build -DCMAKE_BUILD_TYPE=Release -cmake --build build --config Release -py -%PYTHON_VERSION% -m pip install build -py -%PYTHON_VERSION% -m build -w ./Python \ No newline at end of file +py -%PYTHON_VERSION% -m pip install -e Python/ -v \ No newline at end of file diff --git a/examples/Algorithms/fft_group.ipynb b/examples/Algorithms/fft_group.ipynb index d8aac54b..33586f46 100644 --- a/examples/Algorithms/fft_group.ipynb +++ b/examples/Algorithms/fft_group.ipynb @@ -9,18 +9,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "TensorFrost module loaded!\n", - "FFT:\n", - " Kernel count: 1\n", - " Intermediate buffers: 0\n", - " Host readbacks: 0\n", - " Host writes: 0\n", - " Lines of generated code: 542\n", - " IR Compile time: 11.146700 ms\n", - " Codegen time: 1.679300 ms\n", - " Host Compile time: 1387.222168 ms\n", - " Shader Compile time: 44.394798 ms\n", - "\n" + "TensorFrost module loaded!\n" + ] + }, + { + "ename": "TypeError", + "evalue": "group_buffer(): incompatible function arguments. The following argument types are supported:\n 1. (size: int, type: TensorFrost.TensorFrost.TFDataFormat = ) -> TensorFrost.TensorFrost.Tensor\n\nInvoked with: int(32) (32) = mul(inputs=[(1024),(2)], ), ", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 70\u001b[0m\n\u001b[0;32m 66\u001b[0m A[rowIndex, \u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m=\u001b[39m temp[\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m*\u001b[39mrowIndex \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m/\u001b[39m \u001b[38;5;28mfloat\u001b[39m(N \u001b[38;5;28;01mif\u001b[39;00m inverse \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m 68\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m A\n\u001b[1;32m---> 70\u001b[0m fft \u001b[38;5;241m=\u001b[39m \u001b[43mtf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompile\u001b[49m\u001b[43m(\u001b[49m\u001b[43mFFT\u001b[49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[1;32mIn[1], line 42\u001b[0m, in \u001b[0;36mFFT\u001b[1;34m()\u001b[0m\n\u001b[0;32m 39\u001b[0m temp[\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m*\u001b[39mk2 \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m=\u001b[39m v1[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m-\u001b[39m v2[\u001b[38;5;241m1\u001b[39m]\n\u001b[0;32m 41\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m tf\u001b[38;5;241m.\u001b[39mkernel([N], group_size\u001b[38;5;241m=\u001b[39m[BK]) \u001b[38;5;28;01mas\u001b[39;00m group_index:\n\u001b[1;32m---> 42\u001b[0m temp \u001b[38;5;241m=\u001b[39m \u001b[43mtf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgroup_buffer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mN\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfloat32\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 43\u001b[0m tx \u001b[38;5;241m=\u001b[39m group_index\u001b[38;5;241m.\u001b[39mblock_thread_index(\u001b[38;5;241m0\u001b[39m)\n\u001b[0;32m 45\u001b[0m M \u001b[38;5;241m=\u001b[39m N \u001b[38;5;241m/\u001b[39m\u001b[38;5;241m/\u001b[39m BK\n", + "\u001b[1;31mTypeError\u001b[0m: group_buffer(): incompatible function arguments. The following argument types are supported:\n 1. (size: int, type: TensorFrost.TensorFrost.TFDataFormat = ) -> TensorFrost.TensorFrost.Tensor\n\nInvoked with: int(32) (32) = mul(inputs=[(1024),(2)], ), " ] } ], @@ -64,7 +65,6 @@ " temp[2*k2] = v1[0] - v2[0]\n", " temp[2*k2 + 1] = v1[1] - v2[1]\n", "\n", - " #2d local + group tiled version\n", " with tf.kernel([N], group_size=[BK]) as group_index:\n", " temp = tf.group_buffer(N*2, tf.float32)\n", " tx = group_index.block_thread_index(0)\n", @@ -99,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -339,7 +339,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [ { diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index fe8e6064..00000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -jinja2==3.1.4 \ No newline at end of file From 667aa4aa09c36c8e5419a1193546c33f9c234e10 Mon Sep 17 00:00:00 2001 From: Mykhailo Moroz Date: Sun, 4 May 2025 22:05:31 +0200 Subject: [PATCH 2/8] Update readme --- .run/TensorFrost.run.xml | 2 +- README.md | 13 +++++++++---- examples/Rendering/fft3d.py | 0 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 examples/Rendering/fft3d.py diff --git a/.run/TensorFrost.run.xml b/.run/TensorFrost.run.xml index ed008d4d..97e80504 100644 --- a/.run/TensorFrost.run.xml +++ b/.run/TensorFrost.run.xml @@ -1,5 +1,5 @@ - + diff --git a/README.md b/README.md index b71a4217..dd9a14a3 100644 --- a/README.md +++ b/README.md @@ -54,12 +54,17 @@ git clone --recurse-submodules https://github.com/MichaelMoroz/TensorFrost.git cd TensorFrost ``` -Then you can either install the library for development or build a wheel file for distribution. +Then you can either install the library for development. ```bash -python -m pip install --upgrade pip setuptools wheel -python -m pip install -e Python/ -v # install the library for development -python -m pip wheel ./Python -w dist -v # build a wheel file +py -$YOUR_PYTHON_VERSION$ -m pip install --upgrade pip setuptools wheel +py -$YOUR_PYTHON_VERSION$ -m pip install -e Python/ -v # install the library for development +``` +This will link the build folder to Python, so any changes you make to the source code will be reflected in the installed library, in case of changed CPP code you need to rebuild the file library files using `cmake --build . --config Release` command, or by using any IDE. + +You can also build a wheel file for distribution. This will create a wheel file in the `dist` folder. +```bash +py -$YOUR_PYTHON_VERSION$ -m pip wheel ./Python -w dist -v # build a wheel file ``` > [!TIP] diff --git a/examples/Rendering/fft3d.py b/examples/Rendering/fft3d.py new file mode 100644 index 00000000..e69de29b From c6e6b7bf3c0aed24382e18dd69777050da23f7f7 Mon Sep 17 00:00:00 2001 From: Mykhailo Moroz Date: Sun, 4 May 2025 22:11:06 +0200 Subject: [PATCH 3/8] Drop 3.7 support --- .github/workflows/build_manylinux.yml | 2 +- .github/workflows/build_windows.yaml | 2 +- examples/Algorithms/fft_group.ipynb | 29 +++++++++++++-------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build_manylinux.yml b/.github/workflows/build_manylinux.yml index 94c23018..1b63fe09 100644 --- a/.github/workflows/build_manylinux.yml +++ b/.github/workflows/build_manylinux.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['cp37-cp37m', 'cp38-cp38', 'cp39-cp39', 'cp310-cp310', 'cp311-cp311', 'cp312-cp312', 'cp313-cp313'] + python-version: ['cp38-cp38', 'cp39-cp39', 'cp310-cp310', 'cp311-cp311', 'cp312-cp312', 'cp313-cp313'] steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/build_windows.yaml b/.github/workflows/build_windows.yaml index 1b1db712..b1550316 100644 --- a/.github/workflows/build_windows.yaml +++ b/.github/workflows/build_windows.yaml @@ -11,7 +11,7 @@ jobs: runs-on: windows-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v4 with: diff --git a/examples/Algorithms/fft_group.ipynb b/examples/Algorithms/fft_group.ipynb index 33586f46..61472ada 100644 --- a/examples/Algorithms/fft_group.ipynb +++ b/examples/Algorithms/fft_group.ipynb @@ -9,19 +9,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "TensorFrost module loaded!\n" - ] - }, - { - "ename": "TypeError", - "evalue": "group_buffer(): incompatible function arguments. The following argument types are supported:\n 1. (size: int, type: TensorFrost.TensorFrost.TFDataFormat = ) -> TensorFrost.TensorFrost.Tensor\n\nInvoked with: int(32) (32) = mul(inputs=[(1024),(2)], ), ", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[1], line 70\u001b[0m\n\u001b[0;32m 66\u001b[0m A[rowIndex, \u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m=\u001b[39m temp[\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m*\u001b[39mrowIndex \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m/\u001b[39m \u001b[38;5;28mfloat\u001b[39m(N \u001b[38;5;28;01mif\u001b[39;00m inverse \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m 68\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m A\n\u001b[1;32m---> 70\u001b[0m fft \u001b[38;5;241m=\u001b[39m \u001b[43mtf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompile\u001b[49m\u001b[43m(\u001b[49m\u001b[43mFFT\u001b[49m\u001b[43m)\u001b[49m\n", - "Cell \u001b[1;32mIn[1], line 42\u001b[0m, in \u001b[0;36mFFT\u001b[1;34m()\u001b[0m\n\u001b[0;32m 39\u001b[0m temp[\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m*\u001b[39mk2 \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m=\u001b[39m v1[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m-\u001b[39m v2[\u001b[38;5;241m1\u001b[39m]\n\u001b[0;32m 41\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m tf\u001b[38;5;241m.\u001b[39mkernel([N], group_size\u001b[38;5;241m=\u001b[39m[BK]) \u001b[38;5;28;01mas\u001b[39;00m group_index:\n\u001b[1;32m---> 42\u001b[0m temp \u001b[38;5;241m=\u001b[39m \u001b[43mtf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgroup_buffer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mN\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfloat32\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 43\u001b[0m tx \u001b[38;5;241m=\u001b[39m group_index\u001b[38;5;241m.\u001b[39mblock_thread_index(\u001b[38;5;241m0\u001b[39m)\n\u001b[0;32m 45\u001b[0m M \u001b[38;5;241m=\u001b[39m N \u001b[38;5;241m/\u001b[39m\u001b[38;5;241m/\u001b[39m BK\n", - "\u001b[1;31mTypeError\u001b[0m: group_buffer(): incompatible function arguments. The following argument types are supported:\n 1. (size: int, type: TensorFrost.TensorFrost.TFDataFormat = ) -> TensorFrost.TensorFrost.Tensor\n\nInvoked with: int(32) (32) = mul(inputs=[(1024),(2)], ), " + "TensorFrost module loaded!\n", + "FFT:\n", + " Kernel count: 1\n", + " Intermediate buffers: 0\n", + " Host readbacks: 0\n", + " Host writes: 0\n", + " Lines of generated code: 542\n", + " IR Compile time: 11.621900 ms\n", + " Codegen time: 1.764100 ms\n", + " Host Compile time: 1346.780518 ms\n", + " Shader Compile time: 0.715000 ms\n", + "\n" ] } ], @@ -99,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -339,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [ { From 4156a1d5f90a59bf241e9e3070f6a8e74e0cb443 Mon Sep 17 00:00:00 2001 From: Mykhailo Moroz Date: Sun, 4 May 2025 22:16:37 +0200 Subject: [PATCH 4/8] Update build_windows.yaml --- .github/workflows/build_windows.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build_windows.yaml b/.github/workflows/build_windows.yaml index b1550316..9705a3c2 100644 --- a/.github/workflows/build_windows.yaml +++ b/.github/workflows/build_windows.yaml @@ -25,6 +25,13 @@ jobs: - name: Build and Package run: .\build_windows.ps1 + - name: Check Folder + run: | + echo "Contents of Python directory:" + ls -R ./Python + echo "Contents of dist directory:" + ls -R ./Python/dist + - name: Upload wheels as artifact uses: actions/upload-artifact@v4 with: From 506012c5051c82b6012bb9e3b85034e7d64e3daf Mon Sep 17 00:00:00 2001 From: Mykhailo Moroz Date: Sun, 4 May 2025 22:19:05 +0200 Subject: [PATCH 5/8] Update build-macos.yml --- .github/workflows/build-macos.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 129854ff..9169c48a 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -23,7 +23,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt pip install cmake build # or other tools you need - name: Build wheel From 61308d9f3ded1d98bcf744e01c7b0e1ad2546dd1 Mon Sep 17 00:00:00 2001 From: Mykhailo Moroz Date: Sun, 4 May 2025 22:22:25 +0200 Subject: [PATCH 6/8] Update scripts --- .github/workflows/build-macos.yml | 2 +- .github/workflows/build_manylinux.yml | 3 +++ build_manylinux.sh | 19 ------------------- build_windows.ps1 | 2 +- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 9169c48a..bd27af33 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -36,7 +36,7 @@ jobs: echo "Python version: $PYTHON_VERSION" echo "Python executable: $PYTHON_EXECUTABLE" - ${PYTHON_EXECUTABLE} -m pip wheel /Python -w Python/dist --verbose + ${PYTHON_EXECUTABLE} -m pip wheel ./Python -w Python/dist --verbose - name: Check Folder run: ls -R ./Python diff --git a/.github/workflows/build_manylinux.yml b/.github/workflows/build_manylinux.yml index 1b63fe09..c15ad372 100644 --- a/.github/workflows/build_manylinux.yml +++ b/.github/workflows/build_manylinux.yml @@ -22,6 +22,9 @@ jobs: docker build -t tensorfrost-manylinux . docker run --rm -e PYTHON_VERSION=${{ matrix.python-version }} -v $(pwd):/io tensorfrost-manylinux + - name: Check Folder + run: ls -R ./wheelhouse + - name: Upload wheels as artifact uses: actions/upload-artifact@v4 with: diff --git a/build_manylinux.sh b/build_manylinux.sh index 1cd3ae9b..a702aa76 100644 --- a/build_manylinux.sh +++ b/build_manylinux.sh @@ -20,25 +20,6 @@ export PYTHON_ROOT=/opt/python/$PYTHON_VERSION export PATH=$PYTHON_ROOT/bin:$PATH export PYTHON_EXECUTABLE=$PYTHON_ROOT/bin/python -#$PYTHON_EXECUTABLE -m pip install --upgrade pip -r requirements.txt cmake build auditwheel -# -## Extract Python version (e.g., 3.7, 3.8, etc.) -#PY_VERSION=$($PYTHON_EXECUTABLE -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') -# -#echo "Python version: $PY_VERSION" -#echo "Python executable: $PYTHON_EXECUTABLE" -# -#$PYTHON_EXECUTABLE -m cmake \ -# -DPython3_ROOT_DIR=$PYTHON_ROOT \ -# -DPython3_EXECUTABLE=$PYTHON_EXECUTABLE \ -# -DPython_FIND_STRATEGY=LOCATION \ -# -DPython_FIND_REGISTRY=NEVER \ -# -DPython_FIND_FRAMEWORK=NEVER \ -# -DPYBIND11_PYTHON_VERSION=$PY_VERSION \ -# -DCMAKE_C_FLAGS="-D_POSIX_C_SOURCE=200809L -Wno-deprecated-declarations" \ -# -DCMAKE_CXX_FLAGS="-D_POSIX_C_SOURCE=200809L -Wno-deprecated-declarations" \ -# -S . -B build -DCMAKE_BUILD_TYPE=Release - $PYTHON_EXECUTABLE -m pip wheel ./Python -w Python/dist --verbose for whl in Python/dist/*.whl; do diff --git a/build_windows.ps1 b/build_windows.ps1 index f82aa9a9..28efec29 100644 --- a/build_windows.ps1 +++ b/build_windows.ps1 @@ -1,2 +1,2 @@ python -m pip install --upgrade pip -python -m pip wheel ./Python -w dist --verbose +python -m pip wheel ./Python -w Python/dist --verbose From e5247fc451bec06fcac5d28de9714fa771b5c5ac Mon Sep 17 00:00:00 2001 From: Mykhailo Moroz Date: Sun, 4 May 2025 22:43:26 +0200 Subject: [PATCH 7/8] only get tensorfrost wheels --- .github/workflows/build-macos.yml | 2 +- .github/workflows/build_windows.yaml | 2 +- build_manylinux.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index bd27af33..b45633a2 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -45,4 +45,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: macos-wheels-py${{ matrix.python-version }} - path: Python/dist/*.whl + path: Python/dist/tensorfrost-*.whl diff --git a/.github/workflows/build_windows.yaml b/.github/workflows/build_windows.yaml index 9705a3c2..a2f881ad 100644 --- a/.github/workflows/build_windows.yaml +++ b/.github/workflows/build_windows.yaml @@ -36,4 +36,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: windows-wheels-py${{ matrix.python-version }} - path: Python/dist/*.whl + path: Python/dist/tensorfrost-*.whl diff --git a/build_manylinux.sh b/build_manylinux.sh index a702aa76..17f396ad 100644 --- a/build_manylinux.sh +++ b/build_manylinux.sh @@ -22,6 +22,6 @@ export PYTHON_EXECUTABLE=$PYTHON_ROOT/bin/python $PYTHON_EXECUTABLE -m pip wheel ./Python -w Python/dist --verbose -for whl in Python/dist/*.whl; do +for whl in Python/dist/tensorfrost-*.whl; do auditwheel repair "$whl" -w ./wheelhouse/ done \ No newline at end of file From b94c5bee8302699fcdc4764275c8f99283e183f9 Mon Sep 17 00:00:00 2001 From: Mykhailo Moroz Date: Sun, 4 May 2025 22:48:11 +0200 Subject: [PATCH 8/8] Update pyproject.toml --- Python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/pyproject.toml b/Python/pyproject.toml index ef6dcee6..bb45d3ca 100644 --- a/Python/pyproject.toml +++ b/Python/pyproject.toml @@ -8,7 +8,7 @@ build-backend = "scikit_build_core.build" [project] name = "TensorFrost" -version = "0.7.3" +version = "0.7.3dev1" description = "A static optimizing tensor compiler with a Python frontend…" authors = [{name = "Mykhailo Moroz", email = "michael08840884@gmail.com"}] requires-python = ">=3.7"