@@ -447,6 +447,179 @@ find_cuda_libraries_on_host() {
447447 fi
448448}
449449
450+ # Symlink structure changed from 2025.06 onwards. This function reflects the symlinking as it was done for EESSI 2023.06
451+ # Actually symlinks the Matched libraries to correct folders.
452+ # Then also creates "host" and "latest" folder symlinks
453+ symlink_mode_202306 () {
454+ # First let's make sure the driver libraries are not already in place
455+ # Have to link drivers = True
456+ link_drivers=1
457+
458+ # Make sure that target of host_injections variant symlink is an existing directory
459+ echo " Ensure host_injections directory"
460+ host_injections_target=$( realpath -m " ${EESSI_CVMFS_REPO} /host_injections" )
461+ log_verbose " host_injections_target: ${host_injections_target} "
462+ if [ ! -d " $host_injections_target " ]; then
463+ check_global_read
464+ create_directory_structure " $host_injections_target "
465+ fi
466+
467+ # Define proper nvidia directory structure for host_injections in EESSI
468+ host_injections_nvidia_dir=" ${EESSI_CVMFS_REPO} /host_injections/nvidia/${EESSI_CPU_FAMILY} "
469+ host_injection_driver_dir=" ${host_injections_nvidia_dir} /host"
470+ host_injection_driver_version_file=" ${host_injection_driver_dir} /driver_version.txt"
471+ log_verbose " host_injections_nvidia_dir: ${host_injections_nvidia_dir} "
472+ log_verbose " host_injection_driver_dir: ${host_injection_driver_dir} "
473+ log_verbose " host_injection_driver_version_file: ${host_injection_driver_version_file} "
474+
475+ # Check if drivers are already linked with correct version
476+ # This is done by comparing host_injection_driver_version_file (driver_version.txt)
477+ # This is needed when updating GPU drivers.
478+ if [ -e " $host_injection_driver_version_file " ]; then
479+ if grep -q " $HOST_GPU_DRIVER_VERSION " " $host_injection_driver_version_file " ; then
480+ echo_green " The host GPU driver libraries (v${HOST_GPU_DRIVER_VERSION} ) have already been linked! (based on ${host_injection_driver_version_file} )"
481+ # The GPU libraries were already linked for this version of CUDA driver
482+ # Have to link drivers = False
483+ link_drivers=0
484+ else
485+ # There's something there but it is out of date
486+ echo_yellow " The host GPU driver libraries version have changed. Now its: (v${HOST_GPU_DRIVER_VERSION} )"
487+ echo_yellow " Cleaning out outdated symlinks."
488+ rm " ${host_injection_driver_dir} " /* || fatal_error " Unable to remove files under '${host_injection_driver_dir} '."
489+ fi
490+ fi
491+
492+ # Link all matched_libraries from Nvidia to correct host_injection folder
493+ # This step is only run, when linking of drivers is needed (eg. link_drivers==1)
494+ # Setup variable to track if some drivers were actually linked this run.
495+ drivers_linked=0
496+
497+ # Have to link drivers
498+ if [ " $link_drivers " -eq 1 ]; then
499+ # Link the matched libraries
500+
501+ echo_green " Linking drivers to the host_injection folder"
502+ check_global_read
503+ if ! create_directory_structure " ${host_injection_driver_dir} " ; then
504+ fatal_error " No write permissions to directory ${host_injection_driver_dir} "
505+ fi
506+
507+ cd " ${host_injection_driver_dir} " || fatal_error " Failed to cd to ${host_injection_driver_dir} "
508+ log_verbose " Changed directory to: $PWD "
509+
510+ # Make symlinks to all the interesting libraries
511+ # Loop over each matched library
512+ for library in " ${MATCHED_LIBRARIES[@]} " ; do
513+ log_verbose " Linking library: ${library} "
514+
515+ # Get just the library filename
516+ lib_name=$( basename " $library " )
517+
518+ # Check if the symlink already exists
519+ if [ -L " $lib_name " ]; then
520+ # Check if it's pointing to the same target
521+ target=$( readlink " $lib_name " )
522+ if [ " $target " = " $library " ]; then
523+ log_verbose " Symlink for $lib_name already exists and points to correct target"
524+ continue
525+ else
526+ log_verbose " Symlink for $lib_name exists but points to wrong target: $target , updating..."
527+ rm " $lib_name "
528+ fi
529+ fi
530+
531+ # Create a symlink in the current directory
532+ # and check if the symlink was created successfully
533+ if ! ln -s " $library " .
534+ then
535+ fatal_error " Error: Failed to create symlink for library $library in $PWD "
536+ fi
537+ done
538+
539+ # Inject driver and CUDA versions into the directory
540+ echo " $HOST_GPU_DRIVER_VERSION " > driver_version.txt
541+ echo " $HOST_GPU_CUDA_VERSION " > cuda_version.txt
542+
543+ drivers_linked=1
544+ fi
545+
546+ # Make latest symlink for NVIDIA drivers
547+ cd " $host_injections_nvidia_dir " || fatal_error " Failed to cd to $host_injections_nvidia_dir "
548+ log_verbose " Changed directory to: $PWD "
549+ symlink=" latest"
550+
551+ # Check if the symlink exists
552+ if [ -L " $symlink " ]; then
553+ # If the drivers were linked this run - relink the symlink!
554+ if [ " $drivers_linked " -eq 1 ]; then
555+ # Force relinking the current link.
556+ # Need to remove the link first, otherwise this will follow existing symlink
557+ # and create host directory one level down !
558+ rm " $symlink " || fatal_error " Failed to remove symlink ${symlink} "
559+
560+ if ln -sf host " $symlink "
561+ then
562+ echo " Successfully force recreated symlink between $symlink and host in $PWD "
563+ else
564+ fatal_error " Failed to force recreate symlink between $symlink and host in $PWD "
565+ fi
566+ fi
567+ else
568+ # If the symlink doesn't exists, create normal one.
569+ if ln -s host " $symlink "
570+ then
571+ echo " Successfully created symlink between $symlink and host in $PWD "
572+ else
573+ fatal_error " Failed to create symlink between $symlink and host in $PWD "
574+ fi
575+ fi
576+
577+ # Make sure the libraries can be found by the EESSI linker
578+ host_injection_linker_dir=${EESSI_EPREFIX/ versions/ host_injections}
579+ if [ -L " $host_injection_linker_dir /lib" ]; then
580+ # Use readlink without -f to get direct symlink target
581+ # using -f option will create "lastest" symlink one dir deeper (inside host)
582+ target_path=$( readlink " $host_injection_linker_dir /lib" )
583+ expected_target=" $host_injections_nvidia_dir /latest"
584+
585+ log_verbose " Checking symlink target for EESSI linker:"
586+ log_verbose " Current target: $target_path "
587+ log_verbose " Expected target: $expected_target "
588+
589+ # Update symlink if needed
590+ if [ " $target_path " != " $expected_target " ]; then
591+ cd " $host_injection_linker_dir " || fatal_error " Failed to cd to $host_injection_linker_dir "
592+ log_verbose " Changed directory to: $PWD "
593+
594+
595+ if ln -sf " $expected_target " lib
596+ then
597+ echo " Successfully force created symlink between $expected_target and lib in $PWD "
598+ else
599+ fatal_error " Failed to force create symlink between $expected_target and lib in $PWD "
600+ fi
601+ else
602+ log_verbose " Symlink already points to correct target"
603+ fi
604+ else
605+ # Just start from scratch, symlink doesn't exists.
606+ check_global_read
607+ create_directory_structure " $host_injection_linker_dir "
608+ cd " $host_injection_linker_dir " || fatal_error " Failed to cd to $host_injection_linker_dir "
609+ log_verbose " Changed directory to: $PWD "
610+
611+ if ln -s " $host_injections_nvidia_dir /latest" lib
612+ then
613+ echo " Successfully created symlink between $host_injections_nvidia_dir /latest and lib in $PWD "
614+ else
615+ fatal_error " Failed to create symlink between $host_injections_nvidia_dir /latest and lib in $PWD "
616+ fi
617+ fi
618+
619+ }
620+
621+
622+ # Symlink structure changed from 2025.06 onwards. This function reflects the new symlinking
450623# Actually symlinks the Matched libraries to correct folders.
451624symlink_mode () {
452625 # First let's make sure the driver libraries are not already in place
639812
640813# === 5b. Symlink Mode ===
641814# If we haven't already exited, we may need to create the symlinks
642- symlink_mode
815+ if [ " $EESSI_VERSION " == ' 2023.06' ]; then
816+ symlink_mode_202306
817+ else
818+ symlink_mode
819+ fi
643820
644821# If everything went OK, show success message
645822echo_green " Host NVIDIA GPU drivers linked successfully for EESSI"
0 commit comments