-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CUDA support #172
Add CUDA support #172
Changes from 38 commits
065efd1
caa43bf
d7212a0
48f4455
c50daa2
d4e85cc
590e042
7b9bb49
01844c6
0e8861f
7d6af69
2cc5ce9
d53e80e
850c20e
9b2e72f
5f82658
16e87af
cf65a37
7319db2
6537725
2ba47e4
ac268b1
bb5301b
75ce850
17b7662
03b01f1
dadb170
0f5884f
5f2c1f6
efe5f88
ab95873
63fded6
d3cadb5
81e4135
ec9dd69
0c1004d
7a9827b
6e86649
e38391b
b2a4865
fb73d12
8c8a227
f90dd66
a24e09c
3d0ebad
fe1843f
70e5dec
1075d0b
d65fe30
2ac2671
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# How to add GPU support | ||
The collection of scripts in this directory enables you to add GPU support to your setup. | ||
Note that currently this means that CUDA support can be added for Nvidia GPUs. AMD GPUs are not yet supported (feel free to contribute that though!). | ||
To enable the usage of CUDA in your setup, simply run the following script: | ||
``` | ||
./add_nvidia_gpu_support.sh | ||
``` | ||
## Prerequisites and tips | ||
* You need write permissions to `/cvmfs/pilot.eessi-hpc.org/host_injections` (which by default is a symlink to `/opt/eessi` but can be configured in your CVMFS config file to point somewhere else). If you would like to make a system-wide installation you should change this in your configuration to point somewhere on a shared filesystem. | ||
* If you want to install CUDA on a node without GPUs (e.g. on a login node where you want to be able to compile your CUDA-enabled code), you should `export INSTALL_WO_GPU=true` in order to skip checks and tests that can only succeed if you have access to a GPU. This approach is not recommended as there is a chance the CUDA compatibility library installed is not compatible with the existing CUDA driver on GPU nodes (and this will not be detected). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
cat << EOF | ||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This is not implemented yet :( | ||
|
||
If you would like to contribute this support there are a few things you will | ||
need to consider: | ||
- We will need to change the Lmod property added to GPU software so we can | ||
distinguish AMD and Nvidia GPUs | ||
- Support should be implemented in user space, if this is not possible (e.g., | ||
requires a driver update) you need to tell the user what to do | ||
- Support needs to be _verified_ and a trigger put in place (like the existence | ||
of a particular path) so we can tell Lmod to display the associated modules | ||
EOF |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,204 @@ | ||||||||||||||||||||
#!/bin/bash | ||||||||||||||||||||
|
||||||||||||||||||||
# Drop into the prefix shell or pipe this script into a Prefix shell with | ||||||||||||||||||||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
# $EPREFIX/startprefix <<< /path/to/this_script.sh | ||||||||||||||||||||
|
||||||||||||||||||||
install_cuda_version="${INSTALL_CUDA_VERSION:=11.3.1}" | ||||||||||||||||||||
install_p7zip_version="${INSTALL_P7ZIP_VERSION:=17.04-GCCcore-10.3.0}" | ||||||||||||||||||||
|
||||||||||||||||||||
# If you want to install CUDA support on login nodes (typically without GPUs), | ||||||||||||||||||||
# set this variable to true. This will skip all GPU-dependent checks | ||||||||||||||||||||
install_wo_gpu=false | ||||||||||||||||||||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
[ "$INSTALL_WO_GPU" = true ] && install_wo_gpu=true | ||||||||||||||||||||
|
||||||||||||||||||||
# verify existence of nvidia-smi or this is a waste of time | ||||||||||||||||||||
# Check if nvidia-smi exists and can be executed without error | ||||||||||||||||||||
if [[ "${install_wo_gpu}" != "true" ]]; then | ||||||||||||||||||||
if command -v nvidia-smi > /dev/null 2>&1; then | ||||||||||||||||||||
nvidia-smi > /dev/null 2>&1 | ||||||||||||||||||||
if [ $? -ne 0 ]; then | ||||||||||||||||||||
echo "nvidia-smi was found but returned error code, exiting now..." >&2 | ||||||||||||||||||||
echo "If you do not have a GPU on this device but wish to force the installation," | ||||||||||||||||||||
echo "please set the environment variable INSTALL_WO_GPU=true" | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
fi | ||||||||||||||||||||
echo "nvidia-smi found, continue setup." | ||||||||||||||||||||
else | ||||||||||||||||||||
echo "nvidia-smi not found, exiting now..." >&2 | ||||||||||||||||||||
echo "If you do not have a GPU on this device but wish to force the installation," | ||||||||||||||||||||
echo "please set the environment variable INSTALL_WO_GPU=true" | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
fi | ||||||||||||||||||||
else | ||||||||||||||||||||
echo "You requested to install CUDA without GPUs present." | ||||||||||||||||||||
echo "This means that all GPU-dependent tests/checks will be skipped!" | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
EESSI_SILENT=1 source /cvmfs/pilot.eessi-hpc.org/latest/init/bash | ||||||||||||||||||||
|
||||||||||||||||||||
############################################################################################## | ||||||||||||||||||||
# Check that the CUDA driver version is adequate | ||||||||||||||||||||
# ( | ||||||||||||||||||||
# needs to be r450 or r470 which are LTS, other production branches are acceptable but not | ||||||||||||||||||||
# recommended, below r450 is not compatible [with an exception we will not explore,see | ||||||||||||||||||||
# https://docs.nvidia.com/datacenter/tesla/drivers/#cuda-drivers] | ||||||||||||||||||||
# ) | ||||||||||||||||||||
# only check first number in case of multiple GPUs | ||||||||||||||||||||
if [[ "${install_wo_gpu}" != "true" ]]; then | ||||||||||||||||||||
driver_major_version=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader | tail -n1) | ||||||||||||||||||||
driver_major_version="${driver_major_version%%.*}" | ||||||||||||||||||||
# Now check driver_version for compatability | ||||||||||||||||||||
# Check driver is at least LTS driver R450, see https://docs.nvidia.com/datacenter/tesla/drivers/#cuda-drivers | ||||||||||||||||||||
if (( $driver_major_version < 450 )); then | ||||||||||||||||||||
echo "Your NVIDIA driver version is too old, please update first.." | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
fi | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
############################################################################################### | ||||||||||||||||||||
############################################################################################### | ||||||||||||||||||||
# Install CUDA | ||||||||||||||||||||
# TODO: Can we do a trimmed install? | ||||||||||||||||||||
# if modules dir exists, load it for usage within Lmod | ||||||||||||||||||||
cuda_install_dir="${EESSI_SOFTWARE_PATH/versions/host_injections}" | ||||||||||||||||||||
mkdir -p ${cuda_install_dir} | ||||||||||||||||||||
# only install CUDA if specified version is not found | ||||||||||||||||||||
if [ -d ${cuda_install_dir}/software/CUDA/${install_cuda_version} ]; then | ||||||||||||||||||||
echo "CUDA module found! No need to install CUDA again, proceeding with tests" | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not quite accurate, you've tested for the software here, not the module |
||||||||||||||||||||
else | ||||||||||||||||||||
# - as an installation location just use $EESSI_SOFTWARE_PATH but replacing `versions` with `host_injections` | ||||||||||||||||||||
# (CUDA is a binary installation so no need to worry too much about this) | ||||||||||||||||||||
# TODO: The install is pretty fat, you need lots of space for download/unpack/install (~3*5GB), need to do a space check before we proceed | ||||||||||||||||||||
avail_space=$(df --output=avail ${cuda_install_dir}/ | tail -n 1 | awk '{print $1}') | ||||||||||||||||||||
if (( ${avail_space} < 16000000 )); then | ||||||||||||||||||||
echo "Need more disk space to install CUDA, exiting now..." | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
fi | ||||||||||||||||||||
# install cuda in host_injections | ||||||||||||||||||||
module load EasyBuild | ||||||||||||||||||||
# we need the --rebuild option, since the module file is shipped with EESSI | ||||||||||||||||||||
tmpdir=$(mktemp -d) | ||||||||||||||||||||
eb --rebuild --installpath-modules=${tmpdir} --installpath=${cuda_install_dir}/ CUDA-${install_cuda_version}.eb | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now this makes testing difficult as the actual CUDA module in EESSI is not available. You might be better off here checking if the CUDA module exists and if so prefixing this command with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
ret=$? | ||||||||||||||||||||
if [ $ret -ne 0 ]; then | ||||||||||||||||||||
echo "CUDA installation failed, please check EasyBuild logs..." | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
fi | ||||||||||||||||||||
rm -rf ${tmpdir} | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
# Install p7zip, this will be used to install the CUDA compat libraries from rpm. | ||||||||||||||||||||
# The rpm and deb files contain the same libraries, so we just stick to the rpm version. | ||||||||||||||||||||
# If p7zip is missing from the software layer (for whatever reason), we need to install it. | ||||||||||||||||||||
# This has to happen in host_injections, so we check first if it is already installed there. | ||||||||||||||||||||
module use ${cuda_install_dir}/modules/all/ | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe do this conditionally (i.e, only if this directory exists) |
||||||||||||||||||||
module avail 2>&1 | grep -i p7zip &> /dev/null | ||||||||||||||||||||
if [[ $? -eq 0 ]]; then | ||||||||||||||||||||
echo "p7zip module found! No need to install p7zip again, proceeding with installation of compat libraries" | ||||||||||||||||||||
else | ||||||||||||||||||||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
# install p7zip in host_injections | ||||||||||||||||||||
module load EasyBuild | ||||||||||||||||||||
eb --robot --installpath=${cuda_install_dir}/ p7zip-${install_p7zip_version}.eb | ||||||||||||||||||||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
ret=$? | ||||||||||||||||||||
if [ $ret -ne 0 ]; then | ||||||||||||||||||||
echo "p7zip installation failed, please check EasyBuild logs..." | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
fi | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
# Check if the CUDA compat libraries are installed and compatible with the target CUDA version | ||||||||||||||||||||
# if not find the latest version of the compatibility libraries and install them | ||||||||||||||||||||
|
||||||||||||||||||||
# get URL to latest CUDA compat libs, exit if URL is invalid | ||||||||||||||||||||
cuda_compat_urls="$($(dirname "$BASH_SOURCE")/get_cuda_compatlibs.sh)" | ||||||||||||||||||||
ret=$? | ||||||||||||||||||||
if [ $ret -ne 0 ]; then | ||||||||||||||||||||
echo $cuda_compat_urls | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
# loop over the compat library versions until we get one that works for us | ||||||||||||||||||||
keep_driver_check=1 | ||||||||||||||||||||
# Do a maximum of five attempts | ||||||||||||||||||||
for value in {1..5} | ||||||||||||||||||||
do | ||||||||||||||||||||
latest_cuda_compat_url=$(echo $cuda_compat_urls | cut -d " " -f1) | ||||||||||||||||||||
# Chomp that value out of the list | ||||||||||||||||||||
cuda_compat_urls=$(echo $cuda_compat_urls | cut -d " " -f2-) | ||||||||||||||||||||
latest_driver_version="${latest_cuda_compat_url%-*}" | ||||||||||||||||||||
latest_driver_version="${latest_driver_version##*-}" | ||||||||||||||||||||
# URLs differ for different OSes; check if we already have a number, if not remove string part that is not needed | ||||||||||||||||||||
if [[ ! $latest_driver_version =~ ^[0-9]+$ ]]; then | ||||||||||||||||||||
latest_driver_version="${latest_driver_version##*_}" | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
install_compat_libs=false | ||||||||||||||||||||
host_injections_dir="/cvmfs/pilot.eessi-hpc.org/host_injections/nvidia" | ||||||||||||||||||||
# libcuda.so points to actual cuda compat lib with driver version in its name | ||||||||||||||||||||
# if this file exists, cuda compat libs are installed and we can compare the version | ||||||||||||||||||||
if [ -e $host_injections_dir/latest/compat/libcuda.so ]; then | ||||||||||||||||||||
eessi_driver_version=$( realpath $host_injections_dir/latest/compat/libcuda.so) | ||||||||||||||||||||
eessi_driver_version="${eessi_driver_version##*so.}" | ||||||||||||||||||||
else | ||||||||||||||||||||
eessi_driver_version=0 | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
if [ $keep_driver_check -eq 1 ] | ||||||||||||||||||||
then | ||||||||||||||||||||
# only keep the driver check for the latest version | ||||||||||||||||||||
keep_driver_check=0 | ||||||||||||||||||||
else | ||||||||||||||||||||
eessi_driver_version=0 | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
if [ ${latest_driver_version//./} -gt ${eessi_driver_version//./} ]; then | ||||||||||||||||||||
install_compat_libs=true | ||||||||||||||||||||
else | ||||||||||||||||||||
echo "CUDA compat libs are up-to-date, skip installation." | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
if [ "${install_compat_libs}" == true ]; then | ||||||||||||||||||||
bash $(dirname "$BASH_SOURCE")/install_cuda_compatlibs.sh $latest_cuda_compat_url | ||||||||||||||||||||
fi | ||||||||||||||||||||
|
||||||||||||||||||||
if [[ "${install_wo_gpu}" != "true" ]]; then | ||||||||||||||||||||
bash $(dirname "$BASH_SOURCE")/test_cuda.sh | ||||||||||||||||||||
if [ $? -eq 0 ] | ||||||||||||||||||||
then | ||||||||||||||||||||
exit 0 | ||||||||||||||||||||
else | ||||||||||||||||||||
echo | ||||||||||||||||||||
echo "It looks like your driver is not recent enough to work with that release of CUDA, consider updating!" | ||||||||||||||||||||
echo "I'll try an older release to see if that will work..." | ||||||||||||||||||||
echo | ||||||||||||||||||||
fi | ||||||||||||||||||||
else | ||||||||||||||||||||
echo "Requested to install CUDA without GPUs present, so we skip final tests." | ||||||||||||||||||||
echo "Instead we test if module load CUDA works as expected..." | ||||||||||||||||||||
if [ -d ${cuda_install_dir}/modules/all ]; then | ||||||||||||||||||||
module use ${cuda_install_dir}/modules/all/ | ||||||||||||||||||||
else | ||||||||||||||||||||
echo "Cannot load CUDA, modules path does not exist, exiting now..." | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
fi | ||||||||||||||||||||
module load CUDA | ||||||||||||||||||||
ret=$? | ||||||||||||||||||||
if [ $ret -ne 0 ]; then | ||||||||||||||||||||
echo "Could not load CUDA even though modules path exists..." | ||||||||||||||||||||
exit 1 | ||||||||||||||||||||
else | ||||||||||||||||||||
echo "Successfully loaded CUDA, you are good to go! :)" | ||||||||||||||||||||
echo " - To build CUDA enabled modules use ${EESSI_SOFTWARE_PATH/versions/host_injections} as your EasyBuild prefix" | ||||||||||||||||||||
echo " - To use these modules:" | ||||||||||||||||||||
echo " module use ${EESSI_SOFTWARE_PATH/versions/host_injections}/modules/all/" | ||||||||||||||||||||
echo " - Please keep in mind that we just installed the latest CUDA compat libs." | ||||||||||||||||||||
echo " Since we have no GPU to test with, we cannot guarantee that it will work with the installed CUDA drivers on your GPU node(s)." | ||||||||||||||||||||
exit 0 | ||||||||||||||||||||
fi | ||||||||||||||||||||
break | ||||||||||||||||||||
fi | ||||||||||||||||||||
done | ||||||||||||||||||||
|
||||||||||||||||||||
echo "Tried to install 5 different generations of compat libraries and none worked," | ||||||||||||||||||||
echo "this usually means your driver is very out of date!" | ||||||||||||||||||||
exit 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
current_dir=$(dirname $(realpath $0)) | ||
|
||
# Get arch type from EESSI environment | ||
if [[ -z "${EESSI_CPU_FAMILY}" ]]; then | ||
# set up basic environment variables, EasyBuild and Lmod | ||
EESSI_SILENT=1 source /cvmfs/pilot.eessi-hpc.org/latest/init/bash | ||
fi | ||
eessi_cpu_family="${EESSI_CPU_FAMILY:-x86_64}" | ||
|
||
# build URL for CUDA libraries | ||
# take rpm file for compat libs from rhel8 folder, deb and rpm files contain the same libraries | ||
cuda_url="https://developer.download.nvidia.com/compute/cuda/repos/rhel8/"${eessi_cpu_family}"/" | ||
# get all versions in decending order | ||
files=$(curl -s "${cuda_url}" | grep 'cuda-compat' | sed 's/<\/\?[^>]\+>//g' | xargs -n1 | /cvmfs/pilot.eessi-hpc.org/latest/compat/linux/${eessi_cpu_family}/bin/sort -r --version-sort ) | ||
if [[ -z "${files// }" ]]; then | ||
echo "Could not find any compat lib files under" ${cuda_url} | ||
exit 1 | ||
fi | ||
for file in $files; do echo "${cuda_url}$file"; done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
gpu
is a recognised property in Lmod so a good choice for now. Once we add AMD support it will get more complicated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a new property by extending the property table
propT
. To do so, we could add a fileinit/lmodrc.lua
with a new property. This file can be loaded using the env var$LMOD_RC
. Unfortunately, we do not seem to be able to add entries toarch
but rather have to add a new property (or find a way to extendarch
that I'm missing).