Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 4 additions & 33 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ 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: Configure CMake
- name: Build wheel
run: |
# Grab the path to the "python" selected by setup-python
export PYTHON_EXECUTABLE="$(which python)"
Expand All @@ -36,42 +35,14 @@ 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:
name: macos-wheels-py${{ matrix.python-version }}
path: Python/dist/*.whl
path: Python/dist/tensorfrost-*.whl
5 changes: 4 additions & 1 deletion .github/workflows/build_manylinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/build_windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,8 +25,15 @@ 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:
name: windows-wheels-py${{ matrix.python-version }}
path: Python/dist/*.whl
path: Python/dist/tensorfrost-*.whl
815 changes: 337 additions & 478 deletions .idea/editor.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .run/TensorFrost.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="TensorFrost" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="H:\TensorFrost\examples\debug.py" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" WORKING_DIR="file://$PROJECT_DIR$" PASS_PARENT_ENVS_2="true" PROJECT_NAME="TensorFrost" TARGET_NAME="TensorFrost" CONFIG_NAME="RelWithDebInfo-Visual Studio" RUN_PATH="$USER_HOME$/AppData/Local/Programs/Python/Python312/python.exe">
<configuration default="false" name="TensorFrost" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="H:\TensorFrost\examples\debug.py" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" WORKING_DIR="file://$PROJECT_DIR$" PASS_PARENT_ENVS_2="true" PROJECT_NAME="TensorFrost" TARGET_NAME="TensorFrost" CONFIG_NAME="Debug-Visual Studio" RUN_PATH="$USER_HOME$/AppData/Local/Programs/Python/Python312/python.exe">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.15)
project(TensorFrost)

if(NOT CMAKE_BUILD_TYPE)
Expand Down
21 changes: 17 additions & 4 deletions Python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[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"
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"
Expand All @@ -28,6 +32,15 @@ classifiers = [
"Environment :: X11 Applications",
"Environment :: GPU",
]
readme = "../README.md"

[tool.setuptools.package-data]
"TensorFrost" = ["*.so", "*.pyd", "*.dll", "*.dylib"]
"TensorFrost" = ["*.so", "*.pyd", "*.dll", "*.dylib"]

[tool.scikit-build]

[tool.scikit-build.cmake]
source-dir = ".."

[tool.scikit-build.logging]
level = "INFO"
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,22 @@ 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.

```bash
cmake -S . -B build && cmake --build build
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]
> 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.
Expand All @@ -81,16 +86,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]
Expand Down
14 changes: 8 additions & 6 deletions TensorFrost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion TensorFrost/Compiler/KernelGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TensorFrost {

Program* GenerateProgram(IR* ir)
{
ir->CompileIR();
ir->CompileIR();

auto* program = new Program(ir);

Expand Down
9 changes: 9 additions & 0 deletions TensorFrost/Frontend/Python/Definitions/PyTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ void PyTensorDefinition(py::module& /*m*/, py::class_<PyTensor>& 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));
Expand Down
3 changes: 0 additions & 3 deletions build.sh

This file was deleted.

44 changes: 0 additions & 44 deletions build_all.sh

This file was deleted.

12 changes: 0 additions & 12 deletions build_all_python_versions.cmd

This file was deleted.

23 changes: 2 additions & 21 deletions build_manylinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,8 @@ 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 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
for whl in Python/dist/tensorfrost-*.whl; do
auditwheel repair "$whl" -w ./wheelhouse/
done
25 changes: 1 addition & 24 deletions build_windows.ps1
Original file line number Diff line number Diff line change
@@ -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
python -m pip wheel ./Python -w Python/dist --verbose
6 changes: 1 addition & 5 deletions clean_rebuild.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
py -%PYTHON_VERSION% -m pip install -e Python/ -v
Loading
Loading