|
| 1 | +# Copyright 1999-2019 Gentoo Authors |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +# TODO |
| 5 | +# 1. Open issue on science-overlay to add a possibility for installing |
| 6 | +# xlintstc and other test programs from lapack-reference! |
| 7 | +# 2. Keep an eye on the cmake implementation. Does not work currently, |
| 8 | +# check again on bumps. |
| 9 | + |
| 10 | +EAPI=7 |
| 11 | + |
| 12 | +PYTHON_COMPAT=( python2_7 ) |
| 13 | +FORTRAN_STANDARD="77 90" |
| 14 | + |
| 15 | +inherit cuda flag-o-matic fortran-2 multilib toolchain-funcs python-any-r1 |
| 16 | + |
| 17 | +MY_PV=$(ver_rs 3 '-') |
| 18 | + |
| 19 | +DESCRIPTION="Matrix Algebra on GPU and Multicore Architectures" |
| 20 | +HOMEPAGE="https://icl.cs.utk.edu/magma/" |
| 21 | +SRC_URI="https://icl.cs.utk.edu/projectsfiles/${PN}/downloads/${PN}-${MY_PV}.tar.gz -> ${P}.tar.gz" |
| 22 | + |
| 23 | +LICENSE="BSD" |
| 24 | +SLOT="0" |
| 25 | +KEYWORDS="~amd64" |
| 26 | +IUSE="doc kepler maxwell pascal sparse static-libs test volta" |
| 27 | + |
| 28 | +RDEPEND=" |
| 29 | + dev-util/nvidia-cuda-toolkit:= |
| 30 | + virtual/blas |
| 31 | + virtual/lapack |
| 32 | +" |
| 33 | +DEPEND=" |
| 34 | + ${RDEPEND} |
| 35 | + test? ( ${PYTHON_DEPS} ) |
| 36 | +" |
| 37 | +BDEPEND=" |
| 38 | + virtual/pkgconfig |
| 39 | + doc? ( >=app-doc/doxygen-1.8.14-r1[dot] ) |
| 40 | +" |
| 41 | + |
| 42 | +# We have to have write acccess /dev/nvidia0 and /dev/nvidiactl and the portage |
| 43 | +# user is (usually) not in the video group |
| 44 | +RESTRICT="!test? ( test )" |
| 45 | + |
| 46 | +pkg_setup() { |
| 47 | + fortran-2_pkg_setup |
| 48 | + use test && python-any-r1_pkg_setup |
| 49 | + tc-check-openmp || die "Need OpenMP to compile ${P}" |
| 50 | +} |
| 51 | + |
| 52 | +src_prepare() { |
| 53 | + # distributed pc file not so useful so replace it |
| 54 | + cat <<-EOF > ${PN}.pc |
| 55 | + prefix=${EPREFIX}/usr |
| 56 | + libdir=\${prefix}/$(get_libdir) |
| 57 | + includedir=\${prefix}/include/${PN} |
| 58 | + Name: ${PN} |
| 59 | + Description: ${DESCRIPTION} |
| 60 | + Version: ${PV} |
| 61 | + URL: ${HOMEPAGE} |
| 62 | + Libs: -L\${libdir} -lmagma |
| 63 | + Libs.private: -lm -lpthread -ldl -lcublas -lcudart -lcusparse |
| 64 | + Cflags: -I\${includedir} |
| 65 | + Requires: blas lapack |
| 66 | + EOF |
| 67 | + |
| 68 | + if [[ $(tc-getCC) =~ gcc ]]; then |
| 69 | + local eopenmp=-fopenmp |
| 70 | + elif [[ $(tc-getCC) =~ icc ]]; then |
| 71 | + local eopenmp=-openmp |
| 72 | + else |
| 73 | + elog "Cannot detect compiler type so not setting openmp support" |
| 74 | + fi |
| 75 | + append-flags -fPIC ${eopenmp} |
| 76 | + append-ldflags -Wl,-soname,lib${PN}.so.2.4 ${eopenmp} |
| 77 | + |
| 78 | + cuda_src_prepare |
| 79 | + default |
| 80 | +} |
| 81 | + |
| 82 | +src_configure() { |
| 83 | + cat <<-EOF > make.inc |
| 84 | + ARCH = $(tc-getAR) |
| 85 | + ARCHFLAGS = cr |
| 86 | + RANLIB = $(tc-getRANLIB) |
| 87 | + NVCC = nvcc |
| 88 | + CC = $(tc-getCXX) |
| 89 | + FORT = $(tc-getFC) |
| 90 | + INC = -I"${EPREFIX}/opt/cuda/include" -DADD_ -DCUBLAS_GFORTRAN |
| 91 | + CFLAGS = ${CFLAGS} -fPIC |
| 92 | + CXXFLAGS = ${CXXFLAGS} -fPIC |
| 93 | + F90FLAGS = ${FFLAGS} -fPIC -x f95-cpp-input |
| 94 | + FFLAGS = ${FFLAGS} -fPIC |
| 95 | + NVCCFLAGS = -DADD_ -DUNIX ${NVCCFLAGS} |
| 96 | + LDOPTS = ${LDFLAGS} |
| 97 | + LOADER = $(tc-getFC) |
| 98 | + LIBBLAS = $($(tc-getPKG_CONFIG) --libs blas) |
| 99 | + LIBLAPACK = $($(tc-getPKG_CONFIG) --libs lapack) |
| 100 | + CUDADIR = ${EPREFIX}/opt/cuda |
| 101 | + LIBCUDA = -L\$(CUDADIR)/$(get_libdir) -lcublas -lcudart -lcusparse |
| 102 | + LIB = -pthread -lm -ldl \$(LIBCUDA) \$(LIBBLAS) \$(LIBLAPACK) -lstdc++ |
| 103 | + EOF |
| 104 | + if use volta; then |
| 105 | + echo >> make.inc "GPU_TARGET = Volta" |
| 106 | + elif use pascal; then |
| 107 | + echo >> make.inc "GPU_TARGET = Pascal" |
| 108 | + elif use maxwell; then |
| 109 | + echo >> make.inc "GPU_TARGET = Maxwell" |
| 110 | + elif use kepler; then |
| 111 | + echo >> make.inc "GPU_TARGET = Kepler" |
| 112 | + else # See http://icl.cs.utk.edu/magma/forum/viewtopic.php?f=2&t=227 |
| 113 | + # Minimal arch supported is Fermi as of 2.4.0 |
| 114 | + echo >> make.inc "GPU_TARGET = Fermi" |
| 115 | + fi |
| 116 | +} |
| 117 | + |
| 118 | +src_compile() { |
| 119 | + emake lib |
| 120 | + use sparse && emake sparse-lib |
| 121 | + emake shared |
| 122 | + mv lib/lib${PN}.so{,.2.4} || die |
| 123 | + ln -sf lib${PN}.so.2.4 lib/lib${PN}.so.2 || die |
| 124 | + ln -sf lib${PN}.so.2.4 lib/lib${PN}.so || die |
| 125 | + if use sparse; then |
| 126 | + mv lib/lib${PN}_sparse.so{,.2.4} || die |
| 127 | + ln -sf lib${PN}_sparse.so.2.4 lib/lib${PN}_sparse.so.2 || die |
| 128 | + ln -sf lib${PN}_sparse.so.2.4 lib/lib${PN}_sparse.so || die |
| 129 | + fi |
| 130 | +} |
| 131 | + |
| 132 | +src_test() { |
| 133 | + emake test |
| 134 | + # FIXME: sparse-test currently fails |
| 135 | + use sparse && emake sparse-test |
| 136 | + cd testing/lin || die |
| 137 | + # we need to access this while running the tests |
| 138 | + cuda_add_sandbox -w # replaces addwrite /dev/nvidia{ctl,0} |
| 139 | + # FIXME: The python file needs the xlintstc program from |
| 140 | + # lapack-reference test suite, which is not installed, even |
| 141 | + # if lapack-reference is compiled with FEATURES="test". See TODO |
| 142 | + LD_LIBRARY_PATH="${S}"/lib ${EPYTHON} lapack_testing.py || die |
| 143 | +} |
| 144 | + |
| 145 | +src_install() { |
| 146 | + dolib.so lib/lib*$(get_libname)* |
| 147 | + use static-libs && dolib.a lib/lib*.a |
| 148 | + insinto /usr/include/${PN} |
| 149 | + doins include/*.h |
| 150 | + insinto /usr/$(get_libdir)/pkgconfig |
| 151 | + doins ${PN}.pc |
| 152 | + local DOCS=( README ReleaseNotes ) |
| 153 | + use doc && local HTML_DOCS=( docs/html/. ) |
| 154 | + einstalldocs |
| 155 | +} |
0 commit comments