-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopencl.eselect
220 lines (188 loc) · 5 KB
/
opencl.eselect
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
# -*-eselect-*- vim: ft=eselect
# Copyright 2010 Pentoo
# Distributed under the terms of the GNU General Public License v2
# This version is somewhat quick and dirty, it has hardcoded path and whatnot
inherit multilib package-manager config
# Eselect data
DESCRIPTION="Manages different OpenCL implementation installations"
MAINTAINER="[email protected]"
VERSION=0.1.1
# Our data
ENV_FILE="${ROOT}/etc/env.d/03opencl"
PREFIX="${ROOT}/usr"
DST_PREFIX="${ROOT}/usr"
OCL_IMPLEMENTATIONS="/etc/OpenCL/vendors"
AMD_APP="/usr/lib/amd"
# NVIDIA_CUDA="/usr"
INTEL_OCL_SDK="/opt/intel/opencl-sdk"
get_current_implementation() {
local ret
local opencl_profile=$(load_config "${ENV_FILE}" OPENCL_PROFILE)
if [[ -n ${opencl_profile} ]] ; then
ret="${opencl_profile}"
fi
echo ${ret}
}
get_implementations() {
local ret implem
if [[ ! -e ${OCL_IMPLEMENTATIONS} ]] ; then
echo ""
exit
fi
for implem in "${OCL_IMPLEMENTATIONS}"/*; do
implem=${implem##*vendors/}
implem=${implem%%\.icd}
implem=${implem%%ocl*}
has ${implem} ${ret} && continue
ret=${ret:+${ret} }${implem}
done
echo ${ret}
}
set_new_implementation() {
local cl_implem=${1}
local avail_implems=$(get_implementations)
local libdir
local cl_local
local moduledir
# Set a sane umask... bug #83115
umask 022
if ! has ${cl_implem} ${avail_implems}; then
die -q "Invalid opencl implementation selected."
fi
[[ "${EUID}" != "0" ]] && die -q "Must be run as root!"
echo "Switching to \"${cl_implem}\" OpenCL interface..."
if [[ -f ${ENV_FILE} ]] ; then
rm -f "${ENV_FILE}" || die -q "Failed to remove ${ENV_FILE}"
fi
if has nvidia ${avail_implems}; then
echo "WARNING: x11-drivers/nvidia-drivers still owns /usr/lib*/libOpenCL.so*!!!"
fi
for x in $(list_libdirs) ; do
#echo "${ROOT}/usr/${x}/libOpenCL.so"
if [[ ${x} = "lib64" ]] ; then
libdir="x86_64"
else
libdir="x86"
fi
# Delete old file/link
rm -f ${ROOT}/usr/${x}/libOpenCL.so
# Create new symbolic link
case ${cl_implem} in
nvidia)
# FIXME: x11-drivers/nvidia-drivers owns libOpenCL.so, libOpenCL.so.1 and libOpenCL.so.1.0.0
linkfile=$(relative_name "/usr/${x}/libOpenCL.so.1" "/usr/${x}/")
ln -s "${linkfile}" "/usr/${x}/libOpenCL.so"
;;
amd)
ln -s "${AMD_APP}/libOpenCL.so" "/usr/${x}/"
;;
intel)
ln -s "${INTEL_OCL_SDK}/libOpenCL.so" "/usr/${x}/"
;;
esac
done
store_config ${ENV_FILE} OPENCL_PROFILE "${cl_implem}"
echo " done"
echo "Make sure to update the environment variables:"
echo " # env-update"
echo "and source /etc/profile in any open shells:"
echo " $ source /etc/profile && source ~/.bashrc"
}
### show action ###
describe_show() {
echo "Print the current OpenCL implementation."
}
do_show() {
local current=$(get_current_implementation)
if [[ -n ${current} ]] ; then
echo ${current}
return 0
else
echo "(none)"
return 2
fi
}
### list action ###
describe_list() {
echo "List the available OpenCL implementations."
}
do_list() {
local i targets=( $(get_implementations) )
write_list_start "Available OpenCL implementations:"
for (( i = 0; i < ${#targets[@]}; i++ )); do
[[ ${targets[i]} = $(get_current_implementation) ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###
describe_set() {
echo "Select the OpenCL implementation."
}
describe_set_parameters() {
echo "<target>"
}
describe_set_options() {
echo "<target> : The profile to activate"
echo "--use-old : If an implementation is already set, use that one instead"
echo "--prefix=<val> : Set the source prefix (default: /usr)"
echo "--dst-prefix=<val> : Set the destination prefix (default: /usr)"
}
do_set() {
local action="error"
local current=$(get_current_implementation)
local available=$(get_implementations)
local new
[[ "${EUID}" != "0" ]] && die -q "Must be run as root!"
while [[ ${#@} -gt 0 ]] ; do
local opt=${1}
shift
case ${opt} in
--use-old)
if [[ -n ${current} ]] && has ${current} ${available}; then
action="old-implementation"
fi
;;
--prefix=*)
PREFIX=${ROOT}${opt#*=}
available=$(get_implementations)
;;
--dst-prefix=*)
DST_PREFIX=${ROOT}${opt#*=}
;;
*)
if [[ ${action} != "old-implementation" ]] ; then
action="set-implementation"
fi
if is_number ${opt} ; then
targets=( $(get_implementations) )
new=${targets[$(( ${opt} - 1 ))]}
if [[ -z ${new} ]] ; then
die -q "Unrecognized option: ${opt}"
fi
elif has ${opt} ${available}; then
new="${opt}"
else
die -q "Unrecognized option: ${opt}"
fi
;;
esac
done
case ${action} in
old-implementation)
set_new_implementation ${current}
return $?
;;
set-implementation)
if [[ -n ${new} ]] ; then
set_new_implementation ${new}
return $?
else
die -q "Please specify an implementation to set"
fi
;;
*)
die -q "Invalid usage of set action."
;;
esac
}