summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: d4bc73fb47a6279e2b1c55493b80dc8bdd93804b (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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# Maintainer: Jingbei Li <i@jingbei.li>
# Contributor: Carl Ă…kerlindh <carl.akerlindh at gmail dot com>
pkgbase=mxnet
pkgname=('mxnet' 'mxnet-cuda' 'mxnet-mkl' 'mxnet-mkl-cuda')
pkgver=1.7.0
pkgrel=2
pkgdesc="Flexible and Efficient Library for Deep Learning"
arch=('x86_64')
url="https://mxnet.apache.org/"
license=('Apache')
depends=(
	'double-conversion'
	'hdf5'
	'libjpeg-turbo'
	'python-numpy'
	'python-requests'
	'opencv'
)
makedepends=(
	'cblas'
	'ccache'
	'cmake'
	'cython'
	'doxygen'
	'git'
	'gtk3'
	'lapack'
	'ninja'
	'qt5-base'

	'cuda'
	'cudnn'
	'nccl'

	#'intel-compiler-base'
	'intel-mkl'
	#'intel-tbb'
	'onednn'
)
optdepends=('python-graphviz')
source=("${pkgbase}::git+https://github.com/apache/incubator-mxnet#tag=$pkgver"
	'git+https://github.com/dmlc/dlpack'
	'git+https://github.com/dmlc/dmlc-core'
	'git+https://github.com/google/googletest'
	'mkldnn::git+https://github.com/intel/mkl-dnn'
	#'git+https://github.com/dmlc/mshadow'
	'nvidia_cub::git+https://github.com/NVlabs/cub'
	'git+https://github.com/onnx/onnx-tensorrt'
	'git+https://github.com/llvm-mirror/openmp'
	'git+https://github.com/dmlc/ps-lite'
	'git+https://github.com/dmlc/tvm'
	'git+https://github.com/onnx/onnx'
	'git+https://github.com/google/benchmark.git'
	'git+https://github.com/pybind/pybind11.git'
	'git+https://github.com/wjakob/clang-cindex-python3'
	'git+https://github.com/agauniyal/rang'
)

md5sums=('SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP')

prepare() {
	cd "$srcdir/$pkgbase"
	for i in dlpack dmlc-core googletest mkldnn nvidia_cub onnx-tensorrt openmp ps-lite tvm
	do
		git config submodule.3rdparty/${i}.url "$srcdir/$i"
	done
	git submodule update --init

	cd "$srcdir/$pkgbase/3rdparty/onnx-tensorrt"
	git config submodule.third_party/onnx.url "$srcdir/onnx"
	git submodule update --init

	cd "$srcdir/$pkgbase/3rdparty/onnx-tensorrt/third_party/onnx"
	for i in benchmark pybind11
	do
		git config submodule.third_party/${i}.url "$srcdir/$i"
	done
	git submodule update --init

	cd "$srcdir/$pkgbase/3rdparty/onnx-tensorrt/third_party/onnx/third_party/pybind11"
	git config submodule.tools/clang.url "$srcdir/clang-cindex-python3"
	git submodule update --init

	cd "$srcdir/$pkgbase/3rdparty/tvm"
	for i in dlpack dmlc-core 3rdparty/rang
	do
		git config submodule.${i}.url "$srcdir/$(basename $i)"
	done
	git submodule update --init

	cd "$srcdir/$pkgbase"
	git submodule update --init --recursive
	rm -rf 3rdparty/nvidia_cub

	# https://github.com/apache/incubator-mxnet/pull/18357
	git checkout 78e31d6 src/operator/tensor/elemwise_binary_broadcast_op_basic.cc

	mkdir -p "$srcdir/$pkgbase/build"
	cp -r "$srcdir/$pkgbase" "$srcdir/$pkgbase-cuda"
	cp config/distribution/linux_cpu.cmake config.cmake

	cd "$srcdir/$pkgbase-cuda"
	cp config/distribution/linux_cu102.cmake config.cmake

	cp -r "$srcdir/$pkgbase" "$srcdir/$pkgbase-mkl"
	cp -r "$srcdir/$pkgbase-cuda" "$srcdir/$pkgbase-mkl-cuda"

	(
		echo "list(APPEND mshadow_LINKER_LIBS -lcblas -fopenmp)"
		echo 'add_definitions("-DMSHADOW_USE_MKL=0")'
		echo 'add_definitions("-DMSHADOW_USE_CBLAS=1")'
	) | tee -a \
		"$srcdir/$pkgbase"/config.cmake \
		"$srcdir/$pkgbase-cuda"/config.cmake

	#(
	#	echo "list(APPEND mshadow_LINKER_LIBS -lmkl_rt)"

	#	# https://github.com/apache/incubator-mxnet/issues/14086
	#	# https://github.com/apache/incubator-mxnet/compare/master...TaoLv:enable-icc?expand=1
	#	#echo 'add_definitions("-Qoption\,cpp\,--new_cilkfor")'
	#) | tee -a \
	#	"$srcdir/$pkgbase-mkl"/config.cmake \
	#	"$srcdir/$pkgbase-mkl-cuda"/config.cmake
}

build() {
	common_args=(
		-DCMAKE_INSTALL_PREFIX=/usr
		-G Ninja
	)

	cblas_args=(
		-DUSE_BLAS=blas
		-DUSE_MKLDNN:BOOL=OFF
	)

	cuda_args=(
		-DUSE_NCCL:BOOL=ON
		-DMXNET_CUDA_ARCH='5.0;6.0;7.0;7.5;8.0'
		-DCMAKE_C_COMPILER=/opt/cuda/bin/gcc
		-DCMAKE_CXX_COMPILER=/opt/cuda/bin/g++
	)

	mkl_args=(
		-DUSE_BLAS=mkl
		-DUSE_MKL_IF_AVAILABLE:BOOL=ON
		#-DDNNL_CPU_RUNTIME=TBB
		#-DCMAKE_C_COMPILER=icc
		#-DCMAKE_CXX_COMPILER=icpc
	)

	msg2 "Building $pkgbase"
	cd "$srcdir/$pkgbase/build"
	cmake ${common_args[@]} ${cblas_args[@]} ..
	cmake --build .
	cd ../python
	python setup.py build --with-cython

	msg2 "Building $pkgbase-cuda"
	cd "$srcdir/$pkgbase-cuda/build"
	cmake ${common_args[@]} ${cblas_args[@]} ${cuda_args[@]} ..
	cmake --build .
	cd ../python
	python setup.py build --with-cython

	msg2 "Building $pkgbase-mkl"
	cd "$srcdir/$pkgbase-mkl/build"
	cmake ${common_args[@]} ${mkl_args[@]} ..
	cmake --build .
	cd ../python
	python setup.py build --with-cython

	msg2 "Building $pkgbase-mkl-cuda"
	cd "$srcdir/$pkgbase-mkl-cuda/build"
	cmake ${common_args[@]} ${mkl_args[@]} ${cuda_args[@]} ..
	cmake --build .
	cd ../python
	python setup.py build --with-cython
}

_package() {
	cd "${srcdir}/${pkgname}/build"
	#make DESTDIR="${pkgdir}" install
	DESTDIR="${pkgdir}" ninja install
	install -Dm755 im2rec "${pkgdir}/usr/bin/im2rec" || :

	cd "$srcdir/$pkgname/python"
	python setup.py install --root="$pkgdir"/ --optimize=1 --with-cython --skip-build
	ln -sf '/usr/lib/libmxnet.so' "${pkgdir}/usr/lib/python3.9/site-packages/mxnet/libmxnet.so"

	rm -f ${pkgdir}/usr/lib/lib{gomp,iomp5,omp}.so
	rm -f ${pkgdir}/usr/include/{omp*,dnnl*,mkldnn*}
	rm -rf $pkgdir/usr/$pkgbase
	rm -rf $pkgdir/usr/lib/cmake
	rm -rf $pkgdir/usr/share/doc/dnnl
	find "${pkgdir}" -name '*.a' -delete

	install -Dm644 "$srcdir/$pkgname/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_mxnet() {
	depends+=(cblas lapack)
	_package
}

package_mxnet-cuda() {
	pkgdesc="$pkgdesc (with CUDA)"
	depends+=(cblas lapack cuda cudnn nccl)
	conflicts=(mxnet)
	provides=(mxnet)
	_package
}

package_mxnet-mkl() {
	pkgdesc="$pkgdesc (with MKL)"
	depends+=(intel-mkl onednn)
	conflicts=(mxnet)
	provides=(mxnet)
	_package
}

package_mxnet-mkl-cuda() {
	pkgdesc="$pkgdesc (with MKL and CUDA)"
	depends+=(intel-mkl onednn cuda cudnn nccl)
	conflicts=(mxnet)
	provides=(mxnet)
	_package
}