summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: cd4a8173bd16eea1a6cc126a8a6340984f44beb1 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Maintainer : Daniel Bermond <dbermond@archlinux.org>

pkgbase=caffe2
pkgname=('caffe2' 'caffe2-cuda')
_pytorchver=1.1.0 # pytorch stable release version
pkgver="0.8.2_${_pytorchver}"
pkgrel=1
pkgdesc='A new lightweight, modular, and scalable deep learning framework'
arch=('x86_64')
url='https://caffe2.ai/'
license=('BSD')
depends=('google-glog' 'protobuf' 'python' 'python-numpy' 'python-protobuf'
         'python-yaml' 'blas' 'lapack' 'gflags')
optdepends=('python-flask' 'graphviz' 'python-hypothesis' 'python-matplotlib'
            'python-pydot' 'python-nvd3' 'python-yaml' 'python-requests'
            'python-scikit-image' 'python-scipy' 'python-setuptools'
            'python-future' 'python-tornado' 'python-six' 'python-lmdb')
makedepends=('git' 'cmake' 'gtest' 'snappy' 'cuda' 'cudnn' 'nccl')
options=('!emptydirs')
source=("git+https://github.com/pytorch/pytorch.git#tag=v${_pytorchver}"
        'git+https://github.com/pybind/pybind11'
        'git+https://github.com/NVlabs/cub'
        'git+https://github.com/eigenteam/eigen-git-mirror'
        'git+https://github.com/google/googletest'
        'git+https://github.com/google/benchmark'
        'git+https://github.com/google/protobuf'
        'git+https://github.com/Yangqing/ios-cmake'
        'git+https://github.com/Maratyszcza/NNPACK'
        'git+https://github.com/facebookincubator/gloo'
        'git+https://github.com/Maratyszcza/pthreadpool'
        'git+https://github.com/Maratyszcza/FXdiv'
        'git+https://github.com/Maratyszcza/FP16'
        'git+https://github.com/Maratyszcza/psimd'
        'git+https://github.com/facebook/zstd'
        'git+https://github.com/Maratyszcza/cpuinfo'
        'git+https://github.com/PeachPy/enum34'
        'git+https://github.com/Maratyszcza/PeachPy'
        'git+https://github.com/benjaminp/six'
        'git+https://github.com/onnx/onnx'
        'git+https://github.com/onnx/onnx-tensorrt'
        'sleef-zdevito'::'git+https://github.com/zdevito/sleef'
        'git+https://github.com/intel/ideep'
        'git+https://github.com/NVIDIA/nccl.git'
        'git+https://github.com/google/gemmlowp'
        'git+https://github.com/pytorch/QNNPACK'
        'git+https://github.com/intel/ARM_NEON_2_x86_SSE'
        'git+https://github.com/pytorch/fbgemm'
        'git+https://github.com/houseroad/foxi')
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP')

prepare() {
    mkdir -p pytorch/{build-cpu-only,build-cuda}
    
    cd pytorch
    
    # submodules which clone dir coincide with the submodule name
    local _submodule_list=('pybind11'
                           'cub'
                           'googletest'
                           'benchmark'
                           'protobuf'
                           'ios-cmake'
                           'NNPACK'
                           'gloo'
                           'zstd'
                           'onnx'
                           'onnx-tensorrt'
                           'sleef'
                           'ideep'
                           'QNNPACK'
                           'fbgemm'
                           'foxi')
    local _submodule
    for _submodule in "${_submodule_list[@]}"
    do
        git config --local "submodule.third_party/${_submodule}.url" "${srcdir}/${_submodule}"
    done
    
    # submodules which clone dir does not coincide with the submodule name
    git config --local "submodule.third_party/eigen.url" "${srcdir}/eigen-git-mirror"
    git config --local "submodule.third_party/NNPACK_deps/pthreadpool.url" "${srcdir}/pthreadpool"
    git config --local "submodule.third_party/NNPACK_deps/FXdiv.url" "${srcdir}/FXdiv"
    git config --local "submodule.third_party/NNPACK_deps/FP16.url" "${srcdir}/FP16"
    git config --local "submodule.third_party/NNPACK_deps/psimd.url" "${srcdir}/psimd"
    git config --local "submodule.third_party/python-enum.url" "${srcdir}/enum34"
    git config --local "submodule.third_party/python-peachpy.url" "${srcdir}/PeachPy"
    git config --local "submodule.third_party/python-six.url" "${srcdir}/six"
    git config --local "submodule.third_party/sleef.url" "${srcdir}/sleef-zdevito"
    git config --local "submodule.third_party/neon2sse.url" "${srcdir}/ARM_NEON_2_x86_SSE"
    git config --local "submodule.third_party/nccl/nccl.url" "${srcdir}/nccl"
    git config --local "submodule.third_party/gemmlowp/gemmlowp.url" "${srcdir}/gemmlowp"
    
    # special case (upstream uses third.party instead of third_party)
    git config --local 'submodule.third-party/cpuinfo.url' "${srcdir}/cpuinfo"
    
    git submodule update
}

build() {
    local _common_opts=('..'
                        '-DBLAS:STRING=Eigen'
                        '-DBUILD_BINARY:BOOL=ON'
                        '-DBUILD_CUSTOM_PROTOBUF:BOOL=OFF'
                        '-DBUILD_SHARED_LIBS:BOOL=ON'
                        '-DCMAKE_BUILD_TYPE:STRING=None'
                        '-DCMAKE_INSTALL_LIBDIR:PATH=lib'
                        '-DCMAKE_INSTALL_PREFIX:PATH=/usr'
                        '-DCMAKE_SKIP_INSTALL_RPATH:BOOL=YES'
                        '-DCXX_AVX2_FOUND:BOOL=FALSE'
                        '-DCXX_AVX_FOUND:BOOL=FALSE'
                        '-DC_AVX2_FOUND:BOOL=FALSE'
                        '-DC_AVX_FOUND:BOOL=FALSE'
                        '-DUSE_GFLAGS:BOOL=ON'
                        '-DUSE_GLOG:BOOL=ON'
                        '-DUSE_MPI:BOOL=OFF'
                        '-DUSE_NUMA:BOOL=OFF'
                        '-DUSE_OPENCV:BOOL=OFF'
                        '-Wno-dev')
    
    # caffe2-cuda
    cd pytorch/build-cuda
    cmake \
        "${_common_opts[@]}" \
        -DCMAKE_CXX_COMPILER:FILEPATH='/usr/bin/g++' \
        -DCMAKE_C_COMPILER:FILEPATH='/usr/bin/gcc' \
        -DCUDA_HOST_COMPILER:FILEPATH='/usr/bin/gcc' \
        -DCUDA_NVCC_FLAGS:STRING='-Xfatbin -compress-all' \
        -DTORCH_CUDA_ARCH_LIST='3.0;3.2;3.5;3.7;5.0;5.2;5.3;6.0;6.1;6.2;7.0;7.2;7.5' \
        -DUSE_CUDA:BOOL='ON' \
        -DUSE_CUDNN:BOOL='ON' \
        -DUSE_METAL:BOOL='OFF' \
        -DUSE_NCCL:BOOL='ON' \
        -DUSE_SYSTEM_NCCL:BOOL='ON'
    ## fix: avoid a second compilation in package()
    sed -i 's/^preinstall:[[:space:]]all/preinstall:/' Makefile
    make
    
    # caffe2 (cpu only, without cuda support)
    cd "${srcdir}/pytorch/build-cpu-only"
    cmake "${_common_opts[@]}" -DUSE_CUDA:BOOL='OFF' -DUSE_NCCL:BOOL='OFF'
    make
}

_package_common() {
    make DESTDIR="$pkgdir" install
    
    # remove unneeded files
    local _entry
    local _exclude_dirs
    rm    "$pkgdir"/usr/include/*.h
    rm    "$pkgdir"/usr/lib/{*.a,lib{foxi*,onnxifi*}.so*}
    rm -r "$pkgdir"/usr/share/{ATen,cmake/{ATen,Gloo,ONNX}}
    rm -r "$pkgdir"/torch
    mapfile -t -d '' _exclude_dirs < <(find "${pkgdir}/usr/include" -mindepth 1 -maxdepth 1 -type d ! -name 'caffe*' ! -name 'c10' -print0)
    for _entry in "${_exclude_dirs[@]}"
    do
        rm -rf "$_entry"
    done
    
    # license
    cd "${srcdir}/pytorch"
    install -D -m644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
    install -D -m644 NOTICE  -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

package_caffe2-cuda() {
    pkgdesc+=' (with cuda support)'
    depends+=('cuda' 'cudnn' 'nccl')
    provides=('caffe2')
    conflicts=('caffe2')
    
    cd pytorch/build-cuda
    
    _package_common
}

package_caffe2() {
    pkgdesc+=' (cpu only)'
    provides=('caffe2-cpu')
    conflicts=('caffe2-cpu')
    replaces=('caffe2-cpu')
    
    cd pytorch/build-cpu-only
    
    _package_common
}