summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: aa5d6269eb627293a3981a1b88e17108e93a5dfb (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Maintainer: Konstantin Gizdov <arch at kge dot pw>
# Contributor: Butui Hu <hot123tea123@gmail.com>
# Contributor: Chih-Hsuan Yen <yan12125@archlinux.org>
# Contributor: Jean Lucas <jean@4ray.co>
# Based on python-torchvision-git; original contributors:
# Contributor: Stephen Zhang <zsrkmyn at gmail dot com>

# update when available in pytorch
_CUDA_ARCH_LIST="5.2;5.3;6.0;6.1;6.2;7.0;7.2"
_CUDA_ARCH_LIST_CMAKE="52;53;60;61;62;70;72"
_pkgname=vision
pkgbase='torchvision-cuda12.9'
pkgname=(torchvision-cuda12.9 python-torchvision-cuda12.9)
pkgver=0.27.1
pkgrel=1
pkgdesc='Datasets, transforms, and models specific to computer vision (Maxwell/Pascal/Volta support)'
arch=(x86_64)
url='https://github.com/pytorch/vision'
license=(BSD-3-Clause)
depends=(
  glibc
  libgcc
  libjpeg-turbo
  libpng
  libstdc++
  libwebp
)
makedepends=(
  cmake
  ninja
  cuda-12.9
  cudnn9.10-cuda12.9
  python-pytorch-opt-cuda12.9
  python-build
  python-installer
  python-setuptools
  python-wheel
)
source=("${_pkgname}-${pkgver}.tar.gz::https://github.com/pytorch/vision/archive/v${pkgver}.tar.gz"
        "fix-build.patch"
)
b2sums=('c9c126f163ec1ceb0113ce930034af3abc88c68aae1ffe37500bdfd05a6d9c137822a0431b96e63bd6cf833d4d4356195169d2e14a600bd455848dddcd0421a6'
        '30d09ff1511178e25c31c6ecee789c141179bb3cc34f37299d74891973a80a357a9f51a93cfa36834e29a0ba2a366b0974ee5cd88cb5f6a92f7553cd2cd80e98')

prepare() {
  cd "${srcdir}/${_pkgname}-${pkgver}"

  # https://github.com/pytorch/vision/issues/8307
  patch -p1 -i "${srcdir}"/fix-build.patch

  cp -a "${srcdir}/${_pkgname}-${pkgver}" "${srcdir}/${_pkgname}-cuda-${pkgver}"
  mv "${srcdir}/${_pkgname}-${pkgver}" "${srcdir}/python-${_pkgname}-cuda-${pkgver}"
}

build() {
  # Use GCC 14 for CUDA 12.9
  export CC=gcc-14
  export CXX=g++-14

  # We have pass the cuda archs to all builds as cmake files included by
  # python-pytorch-cuda process them.
  local _common_cmake=(
    -G Ninja
    -Wno-dev
    -B build
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_CXX_FLAGS="${CXXFLAGS} -O3"
    -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}"
    -DTORCH_CUDA_ARCH_LIST="${_CUDA_ARCH_LIST}"
    -DCUDA_ARCH_LIST="${_CUDA_ARCH_LIST}"
    -DCMAKE_CUDA_ARCHITECTURES="${_CUDA_ARCH_LIST_CMAKE}"
    # unlike other formats, libwebp is disabled by default
    -DWITH_WEBP=ON
  )

  echo "Building torchvision (GPU version with CUDA)"
  cd "${srcdir}/${_pkgname}-cuda-${pkgver}"
  local _gpu_args=("${_common_cmake[@]}" -DWITH_CUDA=ON)
  cmake "${_gpu_args[@]}"
  cmake --build build

  # build python-torchvision-cuda
  echo "Building torchvision python bindings (GPU version with CUDA)"
  cd "${srcdir}/python-${_pkgname}-cuda-${pkgver}"
  TORCHVISION_INCLUDE="${srcdir}" \
  TORCHVISION_LIBRARY=/usr/lib \
  FORCE_CUDA=1 \
  TORCH_CUDA_ARCH_LIST="${_CUDA_ARCH_LIST}" \
  python -m build --wheel --no-isolation
}

package_python-torchvision-cuda12.9() {
  pkgdesc='Datasets, transforms, and models specific to computer vision (with GPU support)'
  depends+=(
    python
    python-numpy
    python-pillow
    python-pytorch-cuda12.9
  )
  optdepends+=(
    'python-pycocotools: support for MS-COCO dataset'
    'python-scipy: for specific datasets'
  )
  provides+=(python-torchvision python-torchvision-cuda)
  conflicts+=(python-torchvision)

  cd python-$_pkgname-cuda-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}

package_torchvision-cuda12.9() {
  pkgdesc='Datasets, transforms, and models specific to computer vision (C++ library only with GPU support)'
  depends+=(python-pytorch-cuda12.9)
  provides+=(torchvision torchvision-cuda)
  conflicts+=(torchvision)

  cd $_pkgname-cuda-$pkgver
  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}

# vim:set ts=2 sw=2 et: