summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: c27a9fe988f07df0b88489473c789308fe7c60ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Maintainer: Martin Chang <marty188586@gmail.com>

pkgname=python-ttnn-git
pkgver=0.62.0.dev20250919.r28.ga7ce66c29d4
pkgrel=3
pkgdesc='TT-NN operator and Tensor library for Tenstorrent hardware'
arch=('x86_64')
url='https://github.com/tenstorrent/tt-metal'
license=('Apache-2.0')
makedepends=(python-build python-installer python-wheel python-setuptools 'gcc>=12' 'cmake>=3.29' ninja wget pkg-config xz curl mold)
depends=('python>=3.10' hwloc numactl boost tbb capstone sfpi python python-loguru python-networkx python-graphviz python-numpy)
provides=("python-ttnn")
conflicts=("python-ttnn")
source=("tt-metal::git+https://github.com/tenstorrent/tt-metal")
sha256sums=('SKIP')
options=(!strip)

pkgver() {
    cd "$srcdir/tt-metal"
    git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g' | sed 's/^v//'
}


prepare() {
    cd "$srcdir/tt-metal"
    git submodule update --init --recursive

    # Dirty source patches (patching using the patch command is not stable enough)
    sed -i '/add_subdirectory(tools)/d' CMakeLists.txt # Does not build (most likely LTO)
    sed -i '/add_subdirectory(tools)/d' tt_metal/CMakeLists.txt # Does not build (most likely LTO)
    sed -i '/add_subdirectory(examples)/d' ttnn/CMakeLists.txt # Not used in output
    sed -i 's/#\(include(linking)\)/\1/' CMakeLists.txt # Arch is new enough that we can use the better linking parameters
    sed -i 's/\(setuptools.*\)==.*"/\1"/' pyproject.toml # Forced version but it doesn't really need it
    sed -i 's/\(numpy\)>.*"/\1"/' pyproject.toml # DITTO
    sed -i 's/--release"/--release", "--cxx-compiler-path=g++", "--c-compiler-path=gcc", "--without-distributed"/' setup.py # Need more flags but no palce to invoke from build() - hack script
    sed -i 's/"lib64" if/"lib" if/' setup.py # Bad assumption. Arch installs to lib even if lib64 exist
    sed -i '/copy_tree_with_patterns(build_dir \/ get_lib_dir(), self.build_lib + f"\/ttnn\/build\/lib", lib_patterns)/{p; s|get_lib_dir()|"ttnn"| }' setup.py # Additional install needed
}

build() {
    # patch deps
    cd "$srcdir/tt-metal"

    [[ -d dist ]] && (rm -r dist && mkdir dist)
    python -m build --wheel --no-isolation
}

package() {
    cd "$srcdir/tt-metal"
    python -m installer --destdir="$pkgdir" dist/*.whl

    rm -rf $pkgdir/usr/lib/python*/site-packages/debian/ || true

    strip --strip-unneeded "$pkgdir"/usr/lib/python*/site-packages/ttnn/*.so
    strip --strip-unneeded "$pkgdir"/usr/lib/python*/site-packages/ttnn/build/lib/*.so

    # Delete pyc
    find "$pkgdir" -name '*.pyc' -delete
    find "$pkgdir" -name '__pycache__' -type d -empty -delete
}