Skip to content

Commit

Permalink
Merge pull request #744 from ocaisa/lmod_accel_fixes
Browse files Browse the repository at this point in the history
Make sure Lmod site package and RC file do not appear in accelerator subdir
  • Loading branch information
boegel authored Oct 3, 2024
2 parents c4e20c6 + 93dae0d commit e9754dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions create_lmodrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def error(msg):
error("Prefix directory %s does not exist!" % prefix)

lmodrc_path = os.path.join(prefix, DOT_LMOD, 'lmodrc.lua')
# Lmod itself doesn't care about the accelerator subdir so remove this duplication from
# the target path (if it exists)
accel_subdir = os.getenv("EESSI_ACCELERATOR_TARGET")
if accel_subdir:
lmodrc_path = lmodrc_path.replace("/accel/%s" % accel_subdir, '')

lmodrc_txt = TEMPLATE_LMOD_RC % {
'dot_lmod': DOT_LMOD,
'prefix': prefix,
Expand Down
17 changes: 12 additions & 5 deletions create_lmodsitepackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

DOT_LMOD = '.lmod'

hook_txt ="""require("strict")
hook_txt = """require("strict")
local hook = require("Hook")
local open = io.open
Expand Down Expand Up @@ -36,7 +36,7 @@
-- eessi_prefix_host_injections is the prefix with site-extensions (i.e. additional modules)
-- to the official EESSI modules, e.g. /cvmfs/software.eessi.io/host_injections/2023.06
local eessi_prefix_host_injections = string.gsub(eessi_prefix, 'versions', 'host_injections')
-- Check if the full modulepath starts with the eessi_prefix_*
return string.find(t.fn, "^" .. eessi_prefix) ~= nil or string.find(t.fn, "^" .. eessi_prefix_host_injections) ~= nil
end
Expand Down Expand Up @@ -103,15 +103,15 @@
if isFile(archSitePackage) then
dofile(archSitePackage)
end
end
local function eessi_cuda_enabled_load_hook(t)
local frameStk = require("FrameStk"):singleton()
local mt = frameStk:mt()
local simpleName = string.match(t.modFullName, "(.-)/")
-- If we try to load CUDA itself, check if the full CUDA SDK was installed on the host in host_injections.
-- If we try to load CUDA itself, check if the full CUDA SDK was installed on the host in host_injections.
-- This is required for end users to build additional CUDA software. If the full SDK isn't present, refuse
-- to load the CUDA module and print an informative message on how to set up GPU support for EESSI
local refer_to_docs = "For more information on how to do this, see https://www.eessi.io/docs/gpu/.\\n"
Expand Down Expand Up @@ -207,6 +207,7 @@
load_site_specific_hooks()
"""


def error(msg):
sys.stderr.write("ERROR: %s\n" % msg)
sys.exit(1)
Expand All @@ -221,12 +222,18 @@ def error(msg):
error("Prefix directory %s does not exist!" % prefix)

sitepackage_path = os.path.join(prefix, DOT_LMOD, 'SitePackage.lua')

# Lmod itself doesn't care about compute capability so remove this duplication from
# the install path (if it exists)
accel_subdir = os.getenv("EESSI_ACCELERATOR_TARGET")
if accel_subdir:
sitepackage_path = sitepackage_path.replace("/accel/%s" % accel_subdir, '')
try:
os.makedirs(os.path.dirname(sitepackage_path), exist_ok=True)
with open(sitepackage_path, 'w') as fp:
fp.write(hook_txt)
# Make sure that the created Lmod file has "read/write" for the user/group and "read" permissions for others
os.chmod(sitepackage_path, S_IREAD|S_IWRITE|S_IRGRP|S_IWGRP|S_IROTH)
os.chmod(sitepackage_path, S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP | S_IROTH)

except (IOError, OSError) as err:
error("Failed to create %s: %s" % (sitepackage_path, err))
Expand Down

0 comments on commit e9754dd

Please sign in to comment.