summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 4b4ab3ef37c41edc8951ac64c0fcf3acb5725fa9 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
# Maintainer: Butui Hu <hot123tea123@gmail.com>

#_cudaarch="3.7;5.0;5.2;5.2+PTX;5.3;5.3+PTX;6.0;6.0+PTX;6.1;6.1+PTX;6.2;6.2+PTX;7.0;7.0+PTX;7.2;7.2+PTX;7.5;7.5+PTX"
_cudaarch="6.0;6.1;6.2;7.0;7.2;7.5"
_pkgname=mxnet
pkgname=('mxnet-git' 'mxnet-mkl-git' 'mxnet-cuda-git' 'mxnet-cuda-mkl-git')
_pkgver=1.5.1
pkgver=1.5.1.r10596.593d5b6a81
pkgrel=1
pkgdesc="A flexible and efficient library for deep learning"
arch=('x86_64')
url="http://mxnet.io/"
license=('Apache')
depends=(
  'cblas'
  'curl'
  'double-conversion'
  'hdf5'
  'intel-tbb'
  'lapack'
  'protobuf'
  'python-graphviz'
  'python-numpy'
  'python-requests'
  'zeromq'
)
makedepends=(
  'cmake'
  'cuda'
  'cudnn'
  'cython'
  'git'
  'gtk3'
  'nccl'
  'opencv'
  'qt5-base'
)
provides=(mxnet=${pkgver})
conflicts=(mxnet)
source=("${_pkgname}::git+https://github.com/apache/incubator-mxnet.git")
sha512sums=('SKIP')

get_pyver() {
  python -c 'import sys; print(str(sys.version_info[0]) + "." + str(sys.version_info[1]))'
}

pkgver() {
  cd "${srcdir}/${_pkgname}"
  ver=$(printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)")
  echo "${_pkgver}.${ver}"
}

prepare() {
  cd "${srcdir}/${_pkgname}"
  git submodule update --init --recursive

  # do not use 3rd party openmp
  rm -rfv "${srcdir}/${_pkgname}/3rdparty/openmp"
  # the latest cmake set OpenMP_FOUND instead of OPENMP_FOUND
  sed -i 's/OPENMP_FOUND/OpenMP_FOUND/g' "${srcdir}/${_pkgname}/CMakeLists.txt"

  # find blas automatically
  sed -i 's/find_package(OpenBLAS REQUIRED)/find_package(BLAS REQUIRED)/' "${srcdir}/${_pkgname}/cmake/ChooseBlas.cmake"
  sed -i 's/OpenBLAS_LIB/BLAS_LIBRARIES/' "${srcdir}/${_pkgname}/cmake/ChooseBlas.cmake"
  sed -i '/OpenBLAS_INCLUDE_DIR/d' "${srcdir}/${_pkgname}/cmake/ChooseBlas.cmake"

  rm -rf "${srcdir}/${_pkgname}/build"
  mkdir "${srcdir}/${_pkgname}/build"
  cp -a "${srcdir}/${_pkgname}" "${srcdir}/mxnet-git"
  cp -a "${srcdir}/${_pkgname}" "${srcdir}/mxnet-mkl-git"
  cp -a "${srcdir}/${_pkgname}" "${srcdir}/mxnet-cuda-git"
  cp -a "${srcdir}/${_pkgname}" "${srcdir}/mxnet-cuda-mkl-git"
}

build() {
  cmake_opts=(
    -DBUILD_CPP_EXAMPLES:BOOL=OFF
    -DBUILD_TESTING:BOOL=OFF
    -DCMAKE_EXE_LINKER_FLAGS="$(pkg-config --libs cblas)"
    -DCMAKE_INSTALL_LIBDIR:PATH=lib
    -DCMAKE_INSTALL_PREFIX:PATH=/usr
    -DCMAKE_SHARED_LINKER_FLAGS="$(pkg-config --libs cblas)"
    -DCMAKE_SKIP_INSTALL_RPATH:BOOL=ON
    -DINSTALL_DOCUMENTATION:BOOL=OFF
    -DUSE_BLAS=open
    -DUSE_CPP_PACKAGE:BOOL=ON
    -DUSE_DIST_KVSTORE:BOOL=ON
    -DUSE_GPERFTOOLS:BOOL=OFF
    -DUSE_JEMALLOC:BOOL=OFF
    -DUSE_LAPACK:BOOL=ON
    -DUSE_MKL_IF_AVAILABLE:BOOL=OFF
    -DUSE_OPENMP:BOOL=ON
    -DUSE_S3:BOOL=ON
)

  export CC=gcc
  export CXX=g++

  # building without CUDA and without MKL-DNN
  cd "${srcdir}/mxnet-git/build"
  cmake \
    ${cmake_opts[@]} \
    -DUSE_CUDA:BOOL=OFF \
    -DUSE_CUDNN:BOOL=OFF \
    -DUSE_MKLDNN:BOOL=OFF \
    -DUSE_NCCL:BOOL=OFF \
    -DUSE_OPENCV:BOOL=ON \
    ..
  make
  cd ../python
  python setup.py build --with-cython

  # building without CUDA and with MKL-DNN
  cd "${srcdir}/mxnet-mkl-git/build"
  cmake \
    ${cmake_opts[@]} \
    -DUSE_CUDA:BOOL=OFF \
    -DUSE_CUDNN:BOOL=OFF \
    -DUSE_MKLDNN:BOOL=ON \
    -DUSE_NCCL:BOOL=OFF \
    -DUSE_OPENCV:BOOL=ON \
    ..
  make
  cd ../python
  python setup.py build --with-cython

  # use gcc version compatible with CUDA
  export CC=/opt/cuda/bin/gcc
  export CXX=/opt/cuda/bin/g++

  # building with CUDA and without MKL-DNN
  cd "${srcdir}/mxnet-cuda-git/build"
  cmake \
    ${cmake_opts[@]} \
    -DMXNET_CUDA_ARCH=${_cudaarch} \
    -DUSE_CUDA:BOOL=ON \
    -DUSE_CUDNN:BOOL=ON \
    -DUSE_MKLDNN:BOOL=OFF \
    -DUSE_NCCL:BOOL=ON \
    -DUSE_OPENCV:BOOL=OFF \
    ..
  make
  cd ../python
  python setup.py build --with-cython

  # building with CUDA and with MKL-DNN
  cd "${srcdir}/mxnet-cuda-mkl-git/build"
  cmake \
    ${cmake_opts[@]} \
    -DMXNET_CUDA_ARCH=${_cudaarch} \
    -DUSE_CUDA:BOOL=ON \
    -DUSE_CUDNN:BOOL=ON \
    -DUSE_MKLDNN:BOOL=ON \
    -DUSE_NCCL:BOOL=ON \
    -DUSE_OPENCV:BOOL=OFF \
    ..
  make
  cd ../python
  python setup.py build --with-cython
}

_package() {
  cd "${srcdir}/${pkgname}/build"

  # install mxnet core component
  make DESTDIR="${pkgdir}" install

  if [ -f "${srcdir}/${pkgname}/build/im2rec" ]; then
    install -Dm755 "${srcdir}/${pkgname}/build/im2rec" "${pkgdir}/usr/bin/im2rec"
  fi

  # install python binding
  cd "${srcdir}/${pkgname}/python"
  python setup.py install --root="${pkgdir}" --optimize=1 --with-cython --skip-build
  install -Dm644 "${srcdir}/${pkgname}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

  # create neccesarry soft links
  ln -sf '/usr/lib/libmxnet.so' "${pkgdir}/usr/lib/python$(get_pyver)/site-packages/mxnet/libmxnet.so"
  ln -s "/usr/include" "${pkgdir}/usr/lib/python$(get_pyver)/site-packages/mxnet/include"

  # remove unwantted files
  rm -rfv "${pkgdir}/usr/mxnet"
  rm -rfv "${pkgdir}/usr/lib/cmake" "${pkgdir}/usr/share/doc"
  find "${pkgdir}" -type f -name '*dnn*' -delete
  find "${pkgdir}" -name '*.a' -delete
  find "${pkgdir}" -type d -empty -delete
}


package_mxnet-git() {
  depends+=(opencv)

  export CC=gcc
  export CXX=g++
  _package
}

package_mxnet-mkl-git() {
  pkgdesc="${pkgdesc} (with MKL-DNN)"
  depends+=(opencv)

  export CC=gcc
  export CXX=g++
  _package
}

package_mxnet-cuda-git() {
  pkgdesc="${pkgdesc} (with CUDA)"
  depends+=(cuda cudnn nccl)

  export CC=/opt/cuda/bin/gcc
  export CXX=/opt/cuda/bin/g++
  _package
}

package_mxnet-cuda-mkl-git() {
  pkgdesc="${pkgdesc} (with CUDA and MKL-DNN)"
  depends+=(cuda cudnn nccl)
  provides+=(mxnet-cuda=${pkgver} mxnet-mkl=${pkgver})
  conflicts+=(mxnet-cuda=${pkgver} mxnet-mkl=${pkgver})

  export CC=/opt/cuda/bin/gcc
  export CXX=/opt/cuda/bin/g++
  _package
}
# vim:set ts=2 sw=2 et: