Skip to content

Commit

Permalink
Install CUDA and CUDA-Samples via the bot
Browse files Browse the repository at this point in the history
  • Loading branch information
ocaisa committed Nov 9, 2023
1 parent 60ccab9 commit 1848410
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
82 changes: 82 additions & 0 deletions eb_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def parse_hook(ec, *args, **kwargs):
if ec.name in PARSE_HOOKS:
PARSE_HOOKS[ec.name](ec, eprefix)

# inject the GPU property (if required)
ec = inject_gpu_property(ec)

def pre_prepare_hook(self, *args, **kwargs):
"""Main pre-prepare hook: trigger custom functions."""
Expand Down Expand Up @@ -209,6 +211,12 @@ def pre_configure_hook(self, *args, **kwargs):
PRE_CONFIGURE_HOOKS[self.name](self, *args, **kwargs)


def post_package_hook(self, *args, **kwargs):
"""Main post-package hook: trigger custom functions based on software name."""
if self.name in POST_PACKAGE_HOOKS:
PRE_CONFIGURE_HOOKS[self.name](self, *args, **kwargs)


def pre_configure_hook_openblas_optarch_generic(self, *args, **kwargs):
"""
Pre-configure hook for OpenBLAS: add DYNAMIC_ARCH=1 to build/test/install options when using --optarch=GENERIC
Expand Down Expand Up @@ -328,6 +336,76 @@ def pre_single_extension_isoband(ext, *args, **kwargs):
# cfr. https://github.com/r-lib/isoband/commit/6984e6ce8d977f06e0b5ff73f5d88e5c9a44c027
ext.cfg['preinstallopts'] = "sed -i 's/SIGSTKSZ/32768/g' src/testthat/vendor/catch.h && "

def post_package_cuda(self, *args, **kwargs):
"""Delete CUDA files we are not allowed to ship and replace them with a symlink to a possible installation under host_injections."""
print_msg("Replacing CUDA stuff we cannot ship with symlinks...")
# read CUDA EULA
eula_path = os.path.join(self.installdir, "EULA.txt")
tmp_buffer = []
with open(eula_path) as infile:
copy = False
for line in infile:
if line.strip() == "2.6. Attachment A":
copy = True
continue
elif line.strip() == "2.7. Attachment B":
copy = False
continue
elif copy:
tmp_buffer.append(line)
# create whitelist without file extensions, they're not really needed and they only complicate things
whitelist = ['EULA']
file_extensions = [".so", ".a", ".h", ".bc"]
for tmp in tmp_buffer:
for word in tmp.split():
if any(ext in word for ext in file_extensions):
whitelist.append(word.split(".")[0])
whitelist = list(set(whitelist))
# Do some quick checks for things we should or shouldn't have in the list
if "nvcc" in whitelist:
raise EasyBuildError("Found 'nvcc' in whitelist: %s" % whitelist)
if "libcudart" not in whitelist:
raise EasyBuildError("Did not find 'libcudart' in whitelist: %s" % whitelist)
# iterate over all files in the CUDA path
for root, dirs, files in os.walk(self.installdir):
for filename in files:
# we only really care about real files, i.e. not symlinks
if not os.path.islink(os.path.join(root, filename)):
# check if the current file is part of the whitelist
basename = filename.split(".")[0]
if basename not in whitelist:
# if it is not in the whitelist, delete the file and create a symlink to host_injections
source = os.path.join(root, filename)
target = source.replace("versions", "host_injections")
os.remove(source)
# Using os.symlink requires the existence of the target directory, so we use os.system
system_command="ln -s %s %s" % (target, source)
if os.system(system_command) != 0:
raise EasyBuildError("Failed to create symbolic link: %s" % system_command)


def inject_gpu_property(ec):
ec_dict = ec.asdict()
# Check if CUDA is in the dependencies, if so add the GPU Lmod tag
if ("CUDA" in [dep[0] for dep in iter(ec_dict["dependencies"])]):
ec.log.info("[parse hook] Injecting gpu as Lmod arch property and envvar with CUDA version")
key = "modluafooter"
value = 'add_property("arch","gpu")'
cuda_version = 0
for dep in iter(ec_dict["dependencies"]):
# Make CUDA a build dependency only (rpathing saves us from link errors)
if "CUDA" in dep[0]:
cuda_version = dep[1]
ec_dict["dependencies"].remove(dep)
ec_dict["builddependencies"].append(dep) if dep not in ec_dict["builddependencies"] else ec_dict["builddependencies"]
value = "\n".join([value, 'setenv("EESSICUDAVERSION","%s")' % cuda_version])
if key in ec_dict:
if not value in ec_dict[key]:
ec[key] = "\n".join([ec_dict[key], value])
else:
ec[key] = value
return ec


PARSE_HOOKS = {
'CGAL': parse_hook_cgal_toolchainopts_precise,
Expand Down Expand Up @@ -358,3 +436,7 @@ def pre_single_extension_isoband(ext, *args, **kwargs):
'isoband': pre_single_extension_isoband,
'testthat': pre_single_extension_testthat,
}

POST_PACKAGE_HOOKS = {
'cuda': post_package_cuda,
}
1 change: 1 addition & 0 deletions eessi-2023.06-eb-4.8.1-system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ easyconfigs:
- EasyBuild-4.8.2.eb:
options:
from-pr: 19105
- CUDA-12.1.1.eb
2 changes: 2 additions & 0 deletions eessi-2023.06-eb-4.8.2-2023a.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
easyconfigs:
- CUDA-Samples-12.1-GCC-12.3.0-CUDA-12.1.1.eb

0 comments on commit 1848410

Please sign in to comment.