This commit is contained in:
Mario Fetka
2025-06-06 03:35:14 +02:00
parent b56141d74d
commit 0dba7be35f
91 changed files with 5377 additions and 809 deletions

View File

@@ -3,5 +3,8 @@ AUX nvidia-cuda-toolkit-glibc-2.41-r1.patch 3163 BLAKE2B a3d5dbc50898b1502a342c3
AUX parse_manifest.py 8488 BLAKE2B fe4748e41727e717d99b3b7f294d7c8e67b44e3f352f27a76c386502870e6134217ead3d93714755f50b0393d514b9e317748aed89637c660e354d53354d1485 SHA512 ab90e614bfd729a0a90a7373d58fcf2f6e7ba3beb8a00841b87e8240c9386a678daf551f4fcc89040f10d46d159e316442978c60b1a8960070576cfb7a11d52c
DIST cuda_12.8.1_570.124.06_linux.run 5382238770 BLAKE2B 6dff4eb32e97f960bdb2bd57d0dbf0920a9f85c19c26199adcac64eb9d30d7b6f6e2691c7a7a0b5b8249c7860cc685931080a3775c804f6e4e3294c43380e94f SHA512 2ac14ba054bf01924e1953053850f679ebdbc2b9150715398365464eae9d686cde2b82abb8f385b74e4eafa8d68421a9ea216c7647c08956ccba8b2299b50a6e
DIST cuda_12.8.1_570.124.06_linux_sbsa.run 4606631442 BLAKE2B 142c3a231f2a621c4d6a74059b72125baca83d2653ba95c726e3e3c12cf8a0a6b75ced7c0bdaa98450c3d2c2224e88886598191b594ac69be52ba5765bb30592 SHA512 108a75e0ca098b0fd514b3380d42b4752669201dcd68c41f2c1ecf9f29c216ac5937fa33d60e11be06e8a2ad8ae73aa49e6685a363ea77af943e1a1b936b8349
DIST cuda_12.9.0_575.51.03_linux.run 5839691742 BLAKE2B aead43ad3c127fcbe4e642ca3f82e46fe328aeb11d0b3b5abf2784948ce8b46dc703d959c9dd8dbe87697f52bc294636950129a60e2106d26e20e4eeb297c6f3 SHA512 92bef212ed5b5583ba1fdc12add2d7d9e8ced9abb48e336f5cd71bf507a841a855b0d7232d90d1c730ee21f5da2106c6f4acf8100852c1719e1a16715a665878
DIST cuda_12.9.0_575.51.03_linux_sbsa.run 5058547799 BLAKE2B c8b482fcd45529c2f810292be182cc6de703ab9e25018a220e18cb1b163e9bcb5c1648a898a658d678c5e229b83264b9b5a14309adca5c0de1189835e7d1fa18 SHA512 9d6d8b2e0529815eeb18aeefcf2e151c91960c0c7e29917b02d0e66cc68f396dda67fda24456031a94fb4d21348087428c26d18b25d891af621ede492a5d29cf
EBUILD nvidia-cuda-toolkit-12.8.1.ebuild 10532 BLAKE2B c40be32d8ec1da1ead0394212e632dc690c729ad7b0e7703f5cc1308ea8608a3de9f2cc9927ec8d47b430a1b0c1f7c456c558853b6c2e302522dd7941a9ed210 SHA512 05e6fa35eb4041e7cafb1c20efe314e997d025ca811690ba8efbad0a33f5eca4e6d08599cd1542cf1ed26f2ff94d69a65c3bb400ba117fc8493736c82da00451
EBUILD nvidia-cuda-toolkit-12.9.0.ebuild 10531 BLAKE2B 302f68260a7debd4cc0f2e46e00df71cc8ac1aa474aa061aa71321efc9d521470af938ffa3bca52a075d82a2e2d5f274843595968ffa8a229f8598a5c374f231 SHA512 34d56ed82cd35872b25c761eb5a3e79ba487dbdf97c3b3ad7dd8eba305a68dd4b0102d5d4394ead0b4ff656a94faaf71aec5e94691d21c4f705d313408c39b73
MISC metadata.xml 761 BLAKE2B a6ae653c6206cbc05349297499b6dde91bce6d543e10bd5ea915cfe9729dfa6f1eb954ae09c2e4d3997f51315ae090b38606c21b5099e750596ea66fdd93e817 SHA512 9133517d805201d25b651e48abed90394c88ef33a2571ab20b3b19d365f85a90478486c7c087c9150d7d9f6e4026873c5236c64ed649fd3bfc8f9b81479dcc59

View File

@@ -0,0 +1,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 toolchain-funcs
inherit python-r1
DRIVER_PV="575.51.03"
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#/}/*"
PATCHES=(
"${FILESDIR}/nvidia-cuda-toolkit-glibc-2.41-r1.patch"
)
python_check_deps() {
python_has_version "dev-python/defusedxml[${PYTHON_USEDEP}]"
}
cuda-toolkit_check_reqs() {
if use amd64; then
export CHECKREQS_DISK_BUILD="6645M"
elif use arm64; then
export CHECKREQS_DISK_BUILD="6412M"
fi
"check-reqs_pkg_${EBUILD_PHASE}"
}
cuda_verify() {
if has_version "sys-apps/grep[pcre]"; then
local DRIVER_PV_info
DRIVER_PV_info="$(bash "${DISTDIR}/${A}" --info | grep -oP "cuda_${PV}.*run" | cut -d '_' -f 3)"
if [[ "${DRIVER_PV}" != "${DRIVER_PV_info}" ]]; then
die "check DRIVER_PV is ${DRIVER_PV} and should be ${DRIVER_PV_info}"
fi
fi
# rest only works in 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
# 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"
)
bash "${DISTDIR}/${A}" --tar xf -X <(printf "%s\n" "${exclude[@]}") || die "failed to extract ${A}"
}
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 "targets/${narch}-linux/include" "${CUDA_PATH}/include"
dosym "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 "${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
}