Skip to content

Commit b521a4d

Browse files
authored
Fix NVRTC behavior
1 parent a27b66d commit b521a4d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

selkies-gstreamer-entrypoint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ if [ -z "${SELKIES_TURN_REST_URI}" ] && { { [ -z "${SELKIES_TURN_USERNAME}" ] ||
4545
/etc/start-turnserver.sh &
4646
fi
4747

48+
# Extract NVRTC dependency, https://developer.download.nvidia.com/compute/cuda/redist/cuda_nvrtc/LICENSE.txt
49+
if command -v nvidia-smi &> /dev/null && nvidia-smi >/dev/null 2>&1; then
50+
CUDA_DRIVER_SYSTEM="$(nvidia-smi | sed -n 's/.*CUDA Version: \([0-9]\+\.[0-9]\+\).*/\1/p')"
51+
NVRTC_ARCH="${NVRTC_ARCH-$(dpkg --print-architecture | sed -e 's/arm64/sbsa/' -e 's/ppc64el/ppc64le/' -e 's/i.*86/x86/' -e 's/amd64/x86_64/' -e 's/unknown/x86_64/')}"
52+
NVRTC_URL="https://developer.download.nvidia.com/compute/cuda/redist/cuda_nvrtc/linux-${NVRTC_ARCH}/"
53+
NVRTC_ARCHIVE="$(curl -fsSL "${NVRTC_URL}" | grep -oP "(?<=href=')cuda_nvrtc-linux-${NVRTC_ARCH}-${CUDA_DRIVER_SYSTEM}\.[0-9]+-archive\.tar\.xz" | sort -V | tail -n 1)"
54+
if [ -z "${NVRTC_ARCHIVE}" ]; then
55+
FALLBACK_VERSION="${CUDA_DRIVER_SYSTEM}.0"
56+
NVRTC_ARCHIVE=$((curl -fsSL "${NVRTC_URL}" | grep -oP "(?<=href=')cuda_nvrtc-linux-${NVRTC_ARCH}-.*?\.tar\.xz" ; \
57+
echo "cuda_nvrtc-linux-${NVRTC_ARCH}-${FALLBACK_VERSION}-archive.tar.xz") | \
58+
sort -V | grep -B 1 --fixed-strings "${FALLBACK_VERSION}" | head -n 1)
59+
fi
60+
if [ -z "${NVRTC_ARCHIVE}" ]; then
61+
echo "ERROR: Could not find a compatible NVRTC archive." >&2
62+
fi
63+
echo "Selected NVRTC archive: ${NVRTC_ARCHIVE}"
64+
GST_ARCH="$(dpkg --print-architecture | sed -e 's/arm64/aarch64-linux-gnu/' -e 's/armhf/arm-linux-gnueabihf/' -e 's/riscv64/riscv64-linux-gnu/' -e 's/ppc64el/powerpc64le-linux-gnu/' -e 's/s390x/s390x-linux-gnu/' -e 's/i.*86/i386-linux-gnu/' -e 's/amd64/x86_64-linux-gnu/' -e 's/unknown/x86_64-linux-gnu/')"
65+
cd /tmp && curl -fsSL "${NVRTC_URL}${NVRTC_ARCHIVE}" | tar -xJf - -C /tmp && mv -f cuda_nvrtc* cuda_nvrtc && cd cuda_nvrtc/lib && chmod -f 755 libnvrtc* && rm -f "/opt/gstreamer/lib/${GST_ARCH}/"libnvrtc* && mv -f libnvrtc* "/opt/gstreamer/lib/${GST_ARCH}/" && cd /tmp && rm -rf /tmp/cuda_nvrtc
66+
fi
67+
4868
# Wait for X server to start
4969
echo 'Waiting for X Socket' && until [ -S "/tmp/.X11-unix/X${DISPLAY#*:}" ]; do sleep 0.5; done && echo 'X Server is ready'
5070

0 commit comments

Comments
 (0)