Skip to content

Commit e8ba0f3

Browse files
authored
Merge pull request #91 from miaulightouch/fix-nvidia-support
fix: nvidia-container-toolkit missing files when mounting to Docker
2 parents c6c9726 + 9abc8e1 commit e8ba0f3

File tree

1 file changed

+54
-0
lines changed
  • root/etc/s6-overlay/s6-rc.d/init-video

1 file changed

+54
-0
lines changed

root/etc/s6-overlay/s6-rc.d/init-video/run

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,57 @@ do
3333
fi
3434
fi
3535
done
36+
37+
# check if nvidia gpu is present
38+
if which nvidia-smi >/dev/null 2>&1; then
39+
# nvidia-container-toolkit may not place files correctly, so we set them up here
40+
echo "**** NVIDIA GPU detected ****"
41+
42+
OPENCL_ICDS=$(find /etc/OpenCL/vendors -name '*nvidia*.icd' 2>/dev/null)
43+
# if no opencl icd found
44+
if [ -z "${OPENCL_ICDS}" ]; then
45+
echo "**** Setting up OpenCL ICD for NVIDIA ****"
46+
mkdir -pm755 /etc/OpenCL/vendors/
47+
echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd
48+
fi
49+
50+
# find vulkan icds
51+
ICDS=$(find /usr/share/vulkan/icd.d /etc/vulkan/icd.d -name '*nvidia*.json' 2>/dev/null)
52+
# if no icd found
53+
if [ -z "${ICDS}" ]; then
54+
echo "**** Setting up Vulkan ICD for NVIDIA ****"
55+
# get vulkan api version
56+
VULKAN_API_VERSION=$(ldconfig -p | grep "libvulkan.so" | awk '{print $NF}' | xargs readlink | grep -oE "[0-9]+\.[0-9]+\.[0-9]+")
57+
# Fallback if pipeline fails
58+
if [ -z "${VULKAN_API_VERSION}" ]; then
59+
# version 1.1 or greater allows vulkan-loader to load the driver's dynamic library
60+
VULKAN_API_VERSION="1.1.0"
61+
fi
62+
mkdir -pm755 /etc/vulkan/icd.d/
63+
cat > /etc/vulkan/icd.d/nvidia_icd.json << EOF
64+
{
65+
"file_format_version" : "1.0.0",
66+
"ICD": {
67+
"library_path": "libGLX_nvidia.so.0",
68+
"api_version" : "${VULKAN_API_VERSION}"
69+
}
70+
}
71+
EOF
72+
fi
73+
74+
# find glvnd egl_vendor files
75+
EGLS=$(find /usr/share/glvnd/egl_vendor.d /etc/glvnd/egl_vendor.d -name '*nvidia*.json' 2>/dev/null)
76+
# if no egl_vendor file found
77+
if [ -z "${EGLS}" ]; then
78+
echo "**** Setting up EGL vendor file for NVIDIA ****"
79+
mkdir -pm755 /etc/glvnd/egl_vendor.d/
80+
cat > /etc/glvnd/egl_vendor.d/10_nvidia.json << EOF
81+
{
82+
"file_format_version" : "1.0.0",
83+
"ICD": {
84+
"library_path": "libEGL_nvidia.so.0"
85+
}
86+
}
87+
EOF
88+
fi
89+
fi

0 commit comments

Comments
 (0)