Skip to content

Make cuda version check dynamic#202

Open
casparvl wants to merge 4 commits intoEESSI:mainfrom
casparvl:make_cuda_version_check_dynamic
Open

Make cuda version check dynamic#202
casparvl wants to merge 4 commits intoEESSI:mainfrom
casparvl:make_cuda_version_check_dynamic

Conversation

@casparvl
Copy link
Copy Markdown
Contributor

@casparvl casparvl commented Apr 14, 2026

Fixes #189

First step to fixing #201

Unblocks #200 , which blocks EESSI/software-layer#1462 which blocks EESSI/software-layer#1453 ...

This PR can be modified by modifying the create_lmodsitepackage.py with something like:

                if not cudaVersion or cudaVersion == "" then
                    -- Hardcode for local testing
                    -- local eessi_prefix = os.getenv("EESSI_PREFIX")
                    local eessi_prefix = pathJoin('/home', 'casparl', 'EESSI', 'software-layer-scripts')
                    local script = pathJoin(eessi_prefix, 'scripts', 'gpu_support', 'nvidia', 'get_cuda_driver_version.sh')

Comment thread create_lmodsitepackage.py
-- Check return code first. We don't want source_sh to raise an LmodError, we just print
-- an LmodWarning stating we couldn't do a proper version compatibility check
local rc = os.execute("bash -c 'source " .. script .. "'")
if rc == 0 then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me this does not seem to work. Even though the script exists, the condition always evaluates to false. By adding some debugging statements, I found that rc is a boolean (or nil?), and if rc then works for me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.lua.org/pil/22.2.html is not really clear, but my AI friend told me:

In Lua, os.execute() returns different values depending on the Lua version.

✅ Lua 5.2 and newer (5.2, 5.3, 5.4)

os.execute(command) returns three values:
success, exit_type, code = os.execute("your_command")

Meaning:
success → true if the command terminated normally, nil otherwise
exit_type → string:
"exit" → program exited normally
"signal" → program was killed by a signal (Unix)
code → numeric:
exit status (if "exit")
signal number (if "signal")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lua 5.1 apparently does only return a number...

💡 Portable pattern

If you want code that works across versions:

local r1, r2, r3 = os.execute(cmd)

if type(r1) == "number" then
    -- Lua 5.1
    local exit_code = r1 / 256
else
    -- Lua 5.2+
    local success = r1
    local exit_code = r3
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file will have to be added to the following list to ensure that it gets deployed to cvmfs:
https://github.com/EESSI/software-layer-scripts/blob/main/install_scripts.sh#L210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get CUDA driver version dynamically

2 participants