summaryrefslogtreecommitdiff
blob: 6e560a86ac3a5e73649b90ffe466c273623958a2 (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
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=6

PYTHON_COMPAT=( python{2_7,3_4,3_5,3_6} )
DISTUTILS_OPTIONAL=1
inherit cmake-utils eutils distutils-r1 git-r3

DESCRIPTION="Flexible and Efficient Library for Deep Learning"
HOMEPAGE="http://mxnet.io/"
EGIT_REPO_URI="https://github.com/dmlc/mxnet"
#EGIT_SUBMODULES=( "*" "-dmlc-core" "-nnvm" "-ps-lite" )

LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="-* ~amd64 ~x86 ~amd64-linux ~x86-linux"
IUSE="cuda distributed opencv openmp python +mxnet_blas_mkl mxnet_blas_openblas mxnet_blas_atlas"

RDEPEND="
	sys-devel/gcc[cxx,openmp=]
	mxnet_blas_mkl? ( ~sci-libs/mkl-2017.3.196 )
	mxnet_blas_openblas? ( sci-libs/openblas )
	mxnet_blas_atlas? ( sci-libs/atlas )
	cuda? ( dev-util/nvidia-cuda-toolkit )
	distributed? ( sci-libs/ps-lite )
	opencv? ( media-libs/opencv )
	python? ( ${PYTHON_DEPS} dev-python/numpy[${PYTHON_USEDEP}] )"
DEPEND="${RDEPEND}
	python? ( dev-python/setuptools[${PYTHON_USEDEP}] )"
REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )
	^^ (
		mxnet_blas_mkl
		mxnet_blas_openblas
		mxnet_blas_atlas
	)"

#PATCHES=( "${FILESDIR}/${P}-build-fix.patch" "${FILESDIR}/${P}-fix-python-stupid.patch" )
#PATCHES=( "${FILESDIR}/${P}-fix-python-stupid.patch" )
PATCHES=( "${FILESDIR}/${P}-build-fix.patch" )

pkg_setup() {
	lsmod|grep -q '^nvidia_uvm'
	if [ $? -ne 0 ] || [ ! -c /dev/nvidia-uvm ]; then
		eerror "Please run: \"nvidia-modprobe -u -c 0\" before attempting to install ${PN}."
		eerror "Otherwise the hardware autodetect will fail and all architecture modules will be built."
	fi
}

src_prepare() {
	default
	if use python; then
		cd "${S}"/python
		distutils-r1_src_prepare
	fi
	if use cuda; then
		cd "${S}"/mshadow
		epatch "${FILESDIR}/${P}-fix-c++11.patch"
	fi
	if use distributed; then
		cd "${S}"
		epatch "${FILESDIR}/${P}-link-shared-zmq.patch"
	fi
}

src_configure() {
	local mycmakeargs=(
		#-DBUILD_SHARED_LIBS=ON
		-DUSE_CUDA=$(usex cuda)
		-DUSE_OPENCV=$(usex opencv)
		-DUSE_OPENMP=$(usex openmp)
		-DUSE_DIST_KVSTORE=$(usex distributed)
	)

	if use mxnet_blas_mkl; then
		einfo "BLAS provided by Intel Math Kernel Library"
		get_major_version 
		mycmakeargs+=(
			-DBLAS=MKL
			-DUSE_MKLML_MKL=OFF
		)
		export MKL_ROOT=$(find /opt/intel -xtype d -regextype posix-extended -regex '.*compilers_and_libraries_[[:digit:]\.]+/linux/mkl$')
		if [[ -z ${MKL_ROOT} ]]; then
			eerror "Cannot find intel library in /opt/intel."
			return 0
		fi
	elif use mxnet_blas_openblas; then
		einfo "BLAS provided by OpenBLAS"
		mycmakeargs+=( 
			-DBLAS=Open
		)
	elif use mxnet_blas_atlas; then
		einfo "BLAS provided by ATLAS"
		mycmakeargs+=( 
			-DBLAS=Atlas
		)
	fi
	
	addwrite /dev/nvidia-uvm
	addwrite /dev/nvidiactl
	addwrite /dev/nvidia0

	cmake-utils_src_configure

	if use python; then
		cd python;
		distutils-r1_src_configure
	fi
}

src_compile() {
	cmake-utils_src_compile

	if use python; then
		cd python
		export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${BUILD_DIR}"
		distutils-r1_src_compile
	fi
}

src_install() {
	doheader -r include/mxnet

	if use python; then
		cd python
		distutils-r1_src_install
	fi

	cd "${BUILD_DIR}"
	dolib.so libmxnet.so
}