Skip to content

Commit

Permalink
Fix for Nvidia Passthrough (#166)
Browse files Browse the repository at this point in the history
* Fix Nvidia Passthrough closing #127
* Mount libraries parent directory
* Use the dynamic library path from the existing code
  • Loading branch information
dalgibbard authored May 11, 2024
1 parent bc8284e commit 5259927
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions jlmkr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
with full access to all files via bind mounts, \
thanks to systemd-nspawn!"""

__version__ = "1.4.0"
__version__ = "1.4.1"

__disclaimer__ = """USE THIS SCRIPT AT YOUR OWN RISK!
IT COMES WITHOUT WARRANTY AND IS NOT SUPPORTED BY IXSYSTEMS."""
Expand Down Expand Up @@ -44,7 +44,7 @@
seccomp=1
# Below you may add additional systemd-nspawn flags behind systemd_nspawn_user_args=
# To mount host storage in the jail, you may add: --bind='/mnt/pool/dataset:/home'
# To mount host storage in the jail, you may add: --bind='/mnt/pool/dataset:/home'
# To readonly mount host storage, you may add: --bind-ro=/etc/certificates
# To use macvlan networking add: --network-macvlan=eno1 --resolv-conf=bind-host
# To use bridge networking add: --network-bridge=br1 --resolv-conf=bind-host
Expand Down Expand Up @@ -353,6 +353,17 @@ def passthrough_nvidia(
return

try:
# Get list of libraries
nvidia_libraries = set(
[
x
for x in subprocess.check_output(["nvidia-container-cli", "list", "--libraries"])
.decode()
.split("\n")
if x
]
)
# Get full list of files, but excluding library ones from above
nvidia_files = set(
(
[
Expand All @@ -361,6 +372,7 @@ def passthrough_nvidia(
.decode()
.split("\n")
if x
and x not in nvidia_libraries
]
)
)
Expand Down Expand Up @@ -393,16 +405,10 @@ def passthrough_nvidia(

# Check if the parent dir exists where we want to write our conf file
if ld_so_conf_path.parent.exists():
nvidia_libraries = set(
Path(x)
for x in subprocess.check_output(
["nvidia-container-cli", "list", "--libraries"]
)
.decode()
.split("\n")
if x
)
library_folders = set(str(x.parent) for x in nvidia_libraries)
library_folders = set(str(Path(x).parent) for x in nvidia_libraries)
# Add the library folders as mounts
for lf in library_folders:
nvidia_mounts.append(f"--bind-ro={lf}")

# Only write if the conf file doesn't yet exist or has different contents
existing_conf_libraries = set()
Expand Down

0 comments on commit 5259927

Please sign in to comment.