blob: 1859a1df1000069a67aeb72bfc78051aef64f00c (
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
DESCRIPTION="Manage installed BLAS implementations"
MAINTAINER="Danny van Dyk <kugelfang@gentoo.org>"
SVN_DATE='$Date$'
VERSION=$(svn_date_to_version "${SVN_DATE}")
BLAS_CONFIG="${ROOT}/etc/eselect/blas/blas.config"
BLAS_IMPLEMENTATIONS="ACML ATLAS threaded-ATLAS reference"
BLAS_PROFILES="C F77"
# TODO
# * make compatible with threaded-atlas target
# check_* $libdir
# implementation specific check functions
check_ACML() {
# libacml.so provides C/C++ and FORTRAN 77 support
[[ -f ${1}/libacml.so ]] && echo "C F77"
}
check_ATLAS() {
[[ -d ${1}/blas/atlas ]] || return
local ret
# libblas.so provides FORTRAN 77 support
[[ -f ${1}/blas/atlas/libblas.so ]] && ret="F77"
# libcblas.so provides C/C++ support
[[ -f ${1}/blas/atlas/libcblas.so ]] && ret="${ret} C"
echo "${ret}"
}
check_threaded-ATLAS() {
[[ -d ${1}/blas/threaded-atlas ]] || return
local ret
# libblas.so provides FORTRAN 77 support
[[ -f ${1}/blas/threaded-atlas/libblas.so ]] && ret="F77"
# libcblas.so provides C/C++ support
[[ -f ${1}/blas/threaded-atlas/libcblas.so ]] && ret="${ret} C"
echo "${ret}"
}
check_reference() {
[[ -d ${1}/blas/reference ]] || return
local ret
[[ -f ${1}/blas/reference/libblas.so ]] && ret="F77"
[[ -f ${1}/blas/reference/libcblas.so ]] && ret="${ret} C"
echo "${ret}"
}
# package $impl
# Prints the name of the package providing $impl
package() {
case ${1} in
ACML) echo "sci-libs/ACML";;
ATLAS) echo "sci-libs/blas-atlas";;
MKL) echo "sci-libs/mkl";;
reference) echo "sci-libs/blas-reference";;
*) ;;
esac
}
# is_active_* $lib
# return 0 if $lib points to an active BLAS implementation of profile *
is_active_ACML() {
[[ -L ${1} ]] || return 1
local lib=$(readlink -sn ${1})
[[ $(basename ${lib}) == libacml.so ]] \
&& return 0
return 1
}
is_active_ATLAS() {
[[ -L ${1} ]] || return 1
local lib=$(readlink -sn ${1})
local dir=${lib%/*}
[[ ${dir##*/} == atlas ]] \
&& return 0
return 1
}
is_active_threaded-ATLAS() {
[[ -L ${1} ]] || return 1
local lib=$(readlink -sn ${1})
local dir=${lib%/*}
[[ ${dir##*/} == threaded-atlas ]] \
&& return 0
return 1
}
#is_active_MKL() {
# [[ -L ${1} ]] || return 1
# local lib=$(readlink -sn ${1})
#}
is_active_reference() {
[[ -L ${1} ]] || return 1
local lib=$(readlink -sn ${1})
local dir=${lib%/*}
[[ ${dir##*/} == reference ]] \
&& return 0
return 1
}
# setup_* $libdir $profile
# Implementation specific activation/setup functions
setup_ACML() {
if [[ ${2} == C ]] ; then
ln -sf ${1}/libacml.so ${1}/libcblas.so
ln -sf ${1}/libacml.so ${1}/libcblas.so.0
ln -sf ${1}/libacml.a ${1}/libcblas.a
elif [[ ${2} == F77 ]] ; then
ln -sf ${1}/libacml.so ${1}/libblas.so
ln -sf ${1}/libacml.so ${1}/libblas.so.0
ln -sf ${1}/libacml.a ${1}/libblas.a
else
die "Illegal profile: ${2}"
fi
}
setup_ATLAS() {
if [[ ${2} == C ]] ; then
ln -sf ${1}/blas/atlas/libcblas.so ${1}/libcblas.so
ln -sf ${1}/blas/atlas/libcblas.so ${1}/libcblas.so.0
ln -sf ${1}/blas/atlas/libcblas.a ${1}/libcblas.a
elif [[ ${2} == F77 ]] ; then
ln -sf ${1}/blas/atlas/libblas.so ${1}/libblas.so
ln -sf ${1}/blas/atlas/libblas.so ${1}/libblas.so.0
ln -sf ${1}/blas/atlas/libblas.a ${1}/libblas.a
else
die "Illegal profile: ${2}"
fi
}
setup_threaded-ATLAS() {
if [[ ${2} == C ]] ; then
ln -sf ${1}/blas/threaded-atlas/libcblas.so ${1}/libcblas.so
ln -sf ${1}/blas/threaded-atlas/libcblas.so ${1}/libcblas.so.0
ln -sf ${1}/blas/threaded-atlas/libcblas.a ${1}/libcblas.a
elif [[ ${2} == F77 ]] ; then
ln -sf ${1}/blas/threaded-atlas/libblas.so ${1}/libblas.so
ln -sf ${1}/blas/threaded-atlas/libblas.so ${1}/libblas.so.0
ln -sf ${1}/blas/threaded-atlas/libblas.a ${1}/libblas.a
else
die "Illegal profile: ${2}"
fi
}
setup_reference() {
if [[ ${2} == F77 ]] ; then
ln -sf ${1}/blas/reference/libblas.so ${1}/libblas.so
ln -sf ${1}/blas/reference/libblas.so ${1}/libblas.so.0
ln -sf ${1}/blas/reference/libblas.a ${1}/libblas.a
elif [[ ${2} == C ]] ; then
return 1
else
die "Illegal profile: ${2}"
fi
}
### list action ###
describe_list() {
echo "List all installed BLAS implementations"
}
do_list() {
local libdirs libdir n
[[ -z "$@" ]] \
&& libdirs="$(list_libdirs)" \
|| libdirs="$@"
for libdir in ${libdirs} ; do
C_PROFILES=$(load_config ${BLAS_CONFIG} C_${libdir})
F77_PROFILES=$(load_config ${BLAS_CONFIG} F77_${libdir})
if [[ -n ${C_PROFILES} ]] || [[ -n ${F77_PROFILES} ]] ; then
if [[ -n ${C_PROFILES} ]] ; then
write_list_start "C/C++ profiles in ${ROOT}/usr/${libdir}"
n=1
for x in ${C_PROFILES} ; do
active=''
is_active_${x} ${ROOT}/usr/${libdir}/libcblas.so \
&& active=' *'
write_numbered_list_entry \
$n \
"${x}$(space $((12 - ${#x})))($(package ${x}))$(highlight "${active}")"
n=$(( n + 1))
done
echo
fi
if [[ -n ${F77_PROFILES} ]] ; then
write_list_start "FORTRAN 77 profiles in ${ROOT}/usr/${libdir}"
n=1
for x in ${F77_PROFILES} ; do
active=''
is_active_${x} ${ROOT}/usr/${libdir}/libblas.so \
&& active=' *'
write_numbered_list_entry \
$n \
"${x}$(space $((12 - ${#x})))($(package ${x}))$(highlight "${active}")"
n=$(( n + 1))
done
echo
fi
fi
done
}
### select action ###
describe_set() {
echo "Activate one of the installed BLAS implementations"
}
do_set() {
local libdirs=$(list_libdirs) profiles=${BLAS_PROFILES} impl libdir prof
[[ ${#1} == 0 ]] && die -q "Please specify the implementation to setup as active."
impl=${1}
shift
has ${impl} ${BLAS_IMPLEMENTATIONS} \
|| die -q "Illegal implementation: ${impl}"
for param in ${@} ; do
echo "param: ${param}"
if has ${param} ${libdirs} ; then
mylibdirs=(${mylibdirs[@]} ${param})
elif has ${param} ${BLAS_PROFILES} ; then
myprofiles=(${myprofiles[@]} ${param})
else
die -q "Illegal parameter: ${param}."
fi
done
[[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
[[ -n ${myprofiles[@]} ]] && profiles=${myprofiles[@]}
write_list_start "Changing BLAS implementation to $(highlight ${impl}) in"
echo " ${libdirs}"
write_list_start "Affected language interfaces"
for libdir in ${libdirs} ; do
for prof in ${profiles} ; do
if setup_${impl} ${ROOT}/usr/${libdir} ${prof} ; then
has ${prof} ${myprofiles} \
|| myprofiles=( ${myprofiles[@]} ${prof} )
store_config ${BLAS_CONFIG} "${prof}_${libdir}_CURRENT" ${impl}
fi
done
done
echo " ${myprofiles[@]}"
}
### show action ###
describe_show() {
echo "Show the currently active BLAS implementations"
}
do_show() {
local libdirs=$(list_libdirs) profiles=${BLAS_PROFILES} libdir lib prefix
[[ -n ${1} ]] && has ${1} ${libdirs} && libdirs=${1}
[[ -n ${2} ]] && has ${2} ${profiles} && profiles=${2}
write_list_start "Active BLAS implementations"
for libdir in ${libdirs} ; do
[[ ${#libdirs} -eq 1 ]] || prefix="${ROOT}/usr/${libdir}"
for prof in ${profiles} ; do
[[ ${prof} == C ]] && lib=libcblas.so
[[ ${prof} == F77 ]] && lib=libblas.so
impl=$(load_config ${BLAS_CONFIG} "${prof}_${libdir}_CURRENT")
if [[ -z ${impl} ]] ; then
[[ -n $(load_config ${BLAS_CONFIG} "${prof}_${libdir}") ]] \
&& die -q "Configuration file is broken. Please run scan."
else
if is_active_${impl} ${ROOT}/usr/${libdir}/${lib} ; then
write_kv_list_entry "${prefix} (${prof})" "${impl} ($(package ${impl}))"
else
die -q "Configuration file is out of date. Please run scan."
fi
fi
done
done
}
### update action ###
describe_scan() {
echo "Scans the system for data about all installed BLAS implementations"
}
do_scan() {
local lib libdir impl prof
[[ -e ${ROOT}/etc/eselect/blas/blas.config ]] \
&& rm ${ROOT}/etc/eselect/blas/blas.config
for libdir in $(list_libdirs) ; do
[[ -e ${ROOT}/usr/${libdir}/ ]] || continue
for impl in ${BLAS_IMPLEMENTATIONS} ; do
for prof in $(check_${impl} ${ROOT}/usr/${libdir}/) ; do
if has ${prof} ${BLAS_PROFILES} ; then
add_config ${BLAS_CONFIG} "${prof}_${libdir}" ${impl}
[[ ${prof} == C ]] && lib=${ROOT}/usr/${libdir}/libcblas.so
[[ ${prof} == F77 ]] && lib=${ROOT}/usr/${libdir}/libblas.so
is_active_${impl} ${lib} \
&& store_config ${BLAS_CONFIG} \
"${prof}_${libdir}_CURRENT" ${impl}
else
die -q "Unknown profile: \"${prof}\". Valid profiles: ${BLAS_PROFILES}"
fi
done
done
done
}
# vim: set ft=eselect
|