blob: 46414fa97bec859e5884119ec5dea141bf107d89 (
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# shellcheck disable=SC2317
EAPI=8
PYTHON_COMPAT=( python3_{11..13} )
inherit check-reqs edo toolchain-funcs
inherit python-r1
DRIVER_PV="570.124.06"
GCC_MAX_VER="14"
CLANG_MAX_VER="19"
DESCRIPTION="NVIDIA CUDA Toolkit (compiler and friends)"
HOMEPAGE="https://developer.nvidia.com/cuda-zone"
SRC_URI="
amd64? (
https://developer.download.nvidia.com/compute/cuda/${PV}/local_installers/cuda_${PV}_${DRIVER_PV}_linux.run
)
arm64? (
https://developer.download.nvidia.com/compute/cuda/${PV}/local_installers/cuda_${PV}_${DRIVER_PV}_linux_sbsa.run
)
"
S="${WORKDIR}"
LICENSE="NVIDIA-CUDA"
SLOT="0/${PV}" # UNSLOTTED
# SLOT="${PV}" # SLOTTED
KEYWORDS="-* ~amd64 ~arm64 ~amd64-linux ~arm64-linux"
IUSE="debugger examples profiler rdma sanitizer"
RESTRICT="bindist mirror strip test"
REQUIRED_USE="${PYTHON_REQUIRED_USE}"
# since CUDA 11, the bundled toolkit driver (== ${DRIVER_PV}) and the
# actual required minimum driver version are different.
RDEPEND="
|| (
<sys-devel/gcc-$(( GCC_MAX_VER + 1 ))_pre[cxx]
<llvm-core/clang-$(( CLANG_MAX_VER + 1 ))_pre
)
sys-process/numactl
debugger? (
${PYTHON_DEPS}
)
examples? (
media-libs/freeglut
media-libs/glu
)
rdma? ( sys-cluster/rdma-core )
"
BDEPEND="
$(python_gen_any_dep '
dev-python/defusedxml[${PYTHON_USEDEP}]
')
"
# CUDA_PATH="/opt/cuda-${PV}" #950207
CUDA_PATH="/opt/cuda"
QA_PREBUILT="${CUDA_PATH#/}/*"
python_check_deps() {
python_has_version "dev-python/defusedxml[${PYTHON_USEDEP}]"
}
cuda-toolkit_check_reqs() {
if use amd64; then
export CHECKREQS_DISK_BUILD="6608M"
elif use arm64; then
export CHECKREQS_DISK_BUILD="6354M"
fi
"check-reqs_pkg_${EBUILD_PHASE}"
}
cuda_verify() {
# only works with unpacked sources
[[ "${EBUILD_PHASE}" != prepare ]] && return
# run self checks
local compiler_versions GCC_HAS_VER CLANG_HAS_VER
compiler_versions="$(
grep -oP "unsupported (GNU|clang) version.*(gcc versions later than|clang version must be less than) [0-9]*" \
"${S}"/builds/cuda_nvcc/targets/*/include/crt/host_config.h
)"
GCC_HAS_VER="$( echo "${compiler_versions}" | grep gcc | grep -oP "(?<=than )[0-9]*")"
if [[ "${GCC_MAX_VER}" -ne "${GCC_HAS_VER}" ]]; then
eqawarn "check GCC_MAX_VER is ${GCC_MAX_VER} and should be ${GCC_HAS_VER}"
fi
CLANG_HAS_VER="$(( $(echo "${compiler_versions}" | grep clang | grep -oP "(?<=than )[0-9]*") - 1 ))"
if [[ "${CLANG_MAX_VER}" -ne "${CLANG_HAS_VER}" ]]; then
eqawarn "check CLANG_MAX_VER is ${CLANG_MAX_VER} and should be ${CLANG_HAS_VER}"
fi
}
pkg_pretend() {
cuda-toolkit_check_reqs
}
pkg_setup() {
cuda-toolkit_check_reqs
if [[ "${MERGE_TYPE}" == binary ]]; then
return
fi
# we need python for manifest parsing and to determine the supported python versions for cuda-gdb
python_setup
if use amd64; then
narch=x86_64
elif use arm64; then
narch=sbsa
else
die "unknown arch ${ARCH}"
fi
export narch
}
src_unpack() {
cuda_verify
local exclude=(
"cuda-installer"
"*-uninstaller"
"NVIDIA-Linux-${narch}-${DRIVER_PV}.run"
"builds/cuda_documentation"
"builds/cuda_nsight"
"builds/cuda_nvvp"
"builds/nsight_compute"
"builds/nsight_systems"
"builds/nvidia_fs"
)
edob -m "Extracting ${A}" \
bash "${DISTDIR}/${A}" --tar xf -X <(printf "%s\n" "${exclude[@]}")
}
src_prepare() {
pushd "builds/cuda_nvcc/targets/${narch}-linux" >/dev/null || die
eapply -p5 "${FILESDIR}/nvidia-cuda-toolkit-glibc-2.41-r1.patch"
popd >/dev/null || die
default
}
src_configure() {
:
}
src_compile() {
:
}
src_install() {
local -x SKIP_COMPONENTS=(
"Kernel_Objects"
"Visual_Tools"
"Documentation" # obsolete
"cuda-gdb-src" # not used
)
! use debugger && SKIP_COMPONENTS+=( "cuda-gdb" )
! use examples && SKIP_COMPONENTS+=( "Demo_Suite" )
! use profiler && SKIP_COMPONENTS+=( "cuda-cupti" "cuda-profiler-api" "nvprof" )
! use sanitizer && SKIP_COMPONENTS+=( "compute-sanitizer" )
dodir "${CUDA_PATH}"
into "${CUDA_PATH}"
dofile() {
debug-print-function "${FUNCNAME[0]}" "$@"
if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
die "${FUNCNAME[0]} must receive one or two arguments"
fi
local _DESTDIR
_DESTDIR="$(dirname "${CUDA_PATH}/${1%/}")${2:+/${2%/}}"
mkdir -p "${ED}${_DESTDIR}" || die "mkdir ${_DESTDIR} failed"
local dir
dir="$(dirname "${1}")"
if test -z "$(find "${dir}" -maxdepth 1 -name "$(basename "$1")" -print -quit)"; then
if [[ -e "${ED}${_DESTDIR}/$(basename "${1}")" ]]; then
return
fi
if [[ "$1" == "targets/x86_64-linux/lib/stubs/libcusolverMg*" ]] ||
[[ "$1" == "targets/x86_64-linux/lib/libcusparse.so.*" ]]; then
return
fi
return
fi
if [[ -e "${ED}${_DESTDIR}/$(basename "${1}")" ]]; then
# skip noisy warnings
if [[ "$(basename "${1}")" == "include" ]] ||
[[ "$(basename "${1}")" == "lib64" ]]; then
return
fi
eqawarn "${ED}${_DESTDIR}/$(basename "${1}") exists"
return
fi
eval mv -i "${1}" "${ED}${_DESTDIR}" || die "mv failed ${PWD} / ${1} -> ${ED} ${_DESTDIR}"
}
dopcfile() {
[[ $# -eq 0 ]] && return
dodir "${CUDA_PATH}/pkgconfig"
cat > "${ED}${CUDA_PATH}/pkgconfig/${1}-${2}.pc" <<-EOF || die "dopcfile"
cudaroot=${EPREFIX}${CUDA_PATH}
libdir=\${cudaroot}/targets/${narch}-linux/lib${4}
includedir=\${cudaroot}/targets/${narch}-linux/include
Name: ${1}
Description: ${3}
Version: ${2}
Libs: -L\${libdir} -l${1}
Cflags: -I\${includedir}
EOF
}
pushd builds >/dev/null || die
fix_executable_bit=(
cuda_cupti/extras/CUPTI/samples/pc_sampling_utility/pc_sampling_utility_helper.h
cuda_cupti/extras/CUPTI/samples/pc_sampling_continuous/libpc_sampling_continuous.pl
libcufile/gds/tools/run_gdsio.cfg
)
if use amd64; then
fix_executable_bit+=(
cuda_opencl/targets/*/include/CL/cl.hpp
libcufile/targets/*/lib/libcufile_rdma_static.a
libcufile/targets/*/lib/libcufile_static.a
)
fi
chmod -x "${fix_executable_bit[@]}" || die "failed chmod"
popd >/dev/null || die
ebegin "parsing manifest" "${S}/manifests/cuda_"*.xml # {{{
"${EPYTHON}" "${FILESDIR}/parse_manifest.py" "${S}/manifests/cuda_"*".xml" &> "${T}/install.sh" \
|| die "failed to parse manifest"
# shellcheck disable=SC1091
source "${T}/install.sh" || die "failed to source install script"
eend $? # }}}
if use debugger; then
if [[ -d "${ED}/${CUDA_PATH}/extras/Debugger/lib64" ]]; then
rmdir "${ED}/${CUDA_PATH}/extras/Debugger/lib64" || die "remove debugger lib64"
fi
find "${ED}/${CUDA_PATH}/bin" -maxdepth 1 -name "cuda-gdb-*-tui" -print0 | while read -rd $'\0' tui_name; do
impl="$(basename "${tui_name}" | cut -d '-' -f 3 | tr '.' '_')"
if ! has "${impl}" "${PYTHON_COMPAT[@]}" || ! use "python_targets_${impl}"; then
rm "${tui_name}" || die "tui-name rm ${tui_name}"
sed -e "/$(basename "${tui_name}")\"/d" -i "${ED}/${CUDA_PATH}/bin/cuda-gdb" || die "tui_name sed"
fi
done
fi
# remove rdma libs (unless USE=rdma)
if ! use rdma; then
rm "${ED}/${CUDA_PATH}/targets/${narch}-linux/lib/libcufile_rdma"* || die "failed to remove rdma files"
fi
# Add include and lib symlinks
dosym -r "${CUDA_PATH}/targets/${narch}-linux/include" "${CUDA_PATH}/include"
dosym -r "${CUDA_PATH}/targets/${narch}-linux/lib" "${CUDA_PATH}/lib64"
find "${ED}/${CUDA_PATH}" -empty -delete || die
local ldpathextradirs pathextradirs
use debugger && ldpathextradirs+=":${EPREFIX}${CUDA_PATH}/extras/Debugger/lib64"
use profiler && ldpathextradirs+=":${EPREFIX}${CUDA_PATH}/extras/CUPTI/lib64"
local revord=$(( 999999 - $(printf "%02d%02d%02d" "$(ver_cut 1)" "$(ver_cut 2)" "$(ver_cut 3)") ))
newenvd - "99cuda${revord}" <<-EOF
PATH=${EPREFIX}${CUDA_PATH}/bin${pathextradirs}
PKG_CONFIG_PATH=${EPREFIX}${CUDA_PATH}/pkgconfig
LDPATH=${EPREFIX}${CUDA_PATH}/lib64:${EPREFIX}${CUDA_PATH}/nvvm/lib64${ldpathextradirs}
EOF
# CUDA prepackages libraries, don't revdep-build on them
insinto /etc/revdep-rebuild
newins - "80${PN}${revord}" <<-EOF
SEARCH_DIRS_MASK="${EPREFIX}${CUDA_PATH}"
EOF
# https://bugs.gentoo.org/926116
insinto /etc/sandbox.d
newins - "80${PN}" <<-EOF
SANDBOX_PREDICT="/proc/self/task"
EOF
# TODO drop and replace with runtime detection similar to what python does {{{
# ATTENTION: change requires revbump, see link below for supported GCC # versions
# https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements
local cuda_supported_gcc=( 8.5 9.5 10 11 12 13 "${GCC_MAX_VER}" )
sed \
-e "s:CUDA_SUPPORTED_GCC:${cuda_supported_gcc[*]}:g" \
"${FILESDIR}"/cuda-config.in > "${ED}/${CUDA_PATH}/bin/cuda-config" || die
fperms +x "${CUDA_PATH}/bin/cuda-config"
# }}}
# skip til cudnn has been changed #950207
# if [[ "${SLOT}" != "${PV}" ]]; then
# dosym -r "${CUDA_PATH}" "${CUDA_PATH%"-${PV}"}"
# fi
fowners -R root:root "${CUDA_PATH}"
}
pkg_postinst_check() {
if tc-is-gcc &&
ver_test "$(gcc-major-version)" -gt "${GCC_MAX_VER}"; then
ewarn
ewarn "gcc > ${GCC_MAX_VER} will not work with CUDA"
ewarn
ewarn "Append --ccbin= pointing to a gcc bindir to the nvcc compiler flags (NVCCFLAGS)"
ewarn "or set NVCC_CCBIN to the same bindir."
ewarn " NVCCFLAGS=\"--ccbin=$(eval echo "${EPREFIX}/usr/*-linux-gnu/gcc-bin/${GCC_MAX_VER}")\""
ewarn " NVCC_CCBIN=$(eval echo "${EPREFIX}/usr/*-linux-gnu/gcc-bin/${GCC_MAX_VER}")"
ewarn
fi
if tc-is-clang &&
ver_test "$(clang-major-version)" -gt "${CLANG_MAX_VER}"; then
ewarn
ewarn "clang > ${CLANG_MAX_VER} will not work with CUDA"
ewarn
ewarn "Append --ccbin= pointing to a clang bindir to the nvcc compiler flags (NVCCFLAGS)"
ewarn "or set NVCC_CCBIN to the same bindir."
ewarn " NVCCFLAGS=\"--ccbin=$(eval echo "${EPREFIX}/usr/lib/llvm/*/bin${CLANG_MAX_VER}")\""
ewarn " NVCC_CCBIN=$(eval echo "${EPREFIX}/usr/lib/llvm/*/bin${CLANG_MAX_VER}")"
ewarn
fi
}
pkg_postinst() {
if [[ ${MERGE_TYPE} != binary ]]; then
pkg_postinst_check
fi
if use profiler; then
einfo
einfo "nvidia-drivers restricts access to performance counters."
einfo "You'll need to run profiling tools (nvprof) "
einfo "using sudo (needs cap SYS_ADMIN) or add the following line to "
einfo "a modprobe configuration file "
einfo "(e.g. /etc/modprobe.d/nvidia-prof.conf): "
einfo
einfo "options nvidia NVreg_RestrictProfilingToAdminUsers=0"
einfo
fi
}
|