Skip to content

Commit

Permalink
nvidia: Introduce NVIDIA package
Browse files Browse the repository at this point in the history
This commit introduces the pkg/nvidia:

This package fetches the Jetson Linux (currently 35.5.0) and extracts all
.deb packages containing all relevant files (libraries, firmwares, etc)
needed to run specific NVIDIA GPU applications, such as CUDA applications.

Then, all provided CDI files are parsed by the process-cdi.sh script, which
will copy all files pointed in the CDI from the extracted .deb packages.

The output container will provide a directory /opt/nvidia, where:

- /opt/vendor/nvidia/dist: Contains all files pointed in all CDI files
- /opt/vendor/nvidia/bin/nvidia-ctk and
- /opt/vendor/nvidia/bin/nvidia-cdi-hook: applications needed to process
  libraries files from the CDI spec.
- /opt/vendor/nvidia/bin/ldconfig-glibc: ldconfig tool for GNU libc
- /opt/vendor/nvidia/init.d/nv-init.sh: Script to perform platform setup
  actions, to be executed during pillar's initialization

All supported CDI files will be available at /etc/cdi.

The following CDI files are provided:

- jetson-xavier-nx.yaml: For devices based on Jetson Xavier NX
- jetson-orin-nano.yaml: For devices based on Jetson Orin Nano

Signed-off-by: Renê de Souza Pinto <[email protected]>
  • Loading branch information
rene committed Aug 30, 2024
1 parent 3dd02da commit 3b25eb2
Show file tree
Hide file tree
Showing 8 changed files with 6,939 additions and 0 deletions.
102 changes: 102 additions & 0 deletions pkg/nvidia/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# syntax=docker/dockerfile-upstream:1.5.0-rc2-labs

# Copyright (c) 2024 Zededa, Inc.
# SPDX-License-Identifier: Apache-2.0

FROM lfedge/eve-alpine:82df60e43ab9f8c935584b8c7b4d0a4b0271d608 as build-base
ENV BUILD_PKGS="autoconf automake build-base coreutils gettext git glib-dev go libtool libmd-dev ncurses-dev tar xz-dev yq zstd-dev"

RUN eve-alpine-deploy.sh

# This is a arm64 (only) package, nothing to do for other architectures
FROM build-base as build-amd64
FROM build-base as build-riscv64

FROM build-base as build-arm64

# Setup git to apply patches
RUN git config --global user.email '[email protected]' && \
git config --global user.name 'Project EVE'

# Jetson Linux tarball
ENV JETSON_LINUX=https://developer.nvidia.com/downloads/embedded/l4t/r35_release_v5.0/release/jetson_linux_r35.5.0_aarch64.tbz2

ADD ${JETSON_LINUX} /jetson_linux.tbz2

# We need to build dpkg in order to get zstd compression support
ENV DPKG_REVISION=1.22.6
ADD --keep-git-dir=true https://salsa.debian.org/dpkg-team/dpkg.git#${DPKG_REVISION} /dpkg
WORKDIR /dpkg
RUN ./autogen && \
./configure --prefix=/ && \
make -j "$(nproc)" && \
make install

# CDI Files
COPY cdi /cdi

# Extract tarball
WORKDIR /
RUN tar -xjf /jetson_linux.tbz2

# Build nvidia-ctk
ENV NVIDIA_CONTAINER_TOOLKIT_REV=v1.16.0
ADD --keep-git-dir=true https://github.com/NVIDIA/nvidia-container-toolkit.git#${NVIDIA_CONTAINER_TOOLKIT_REV} /nvct

WORKDIR /nvct

COPY patches/* /nvct
RUN for x in /nvct/*.patch; do \
git am "$x" ; \
done

RUN mkdir -p dist
RUN make cmd-nvidia-ctk && cp nvidia-ctk dist/
RUN make cmd-nvidia-cdi-hook && cp nvidia-cdi-hook dist/

# Get and extract ldconfig for glibc
ADD http://ports.ubuntu.com/ubuntu-ports/pool/main/g/glibc/libc-bin_2.31-0ubuntu9.16_arm64.deb /
RUN mkdir -p /ldconfig-bin && \
dpkg -x /libc-bin_2.31-0ubuntu9.16_arm64.deb /ldconfig && \
cp /ldconfig/sbin/ldconfig.real /ldconfig-bin/ldconfig-glibc


FROM build-${TARGETARCH} as build

# Copy udev rules
COPY udev/rules.d/* /rules.d/

# Copy scripts to processing CDI files and initialization
COPY scripts/* /

# Process CDI files
WORKDIR /
RUN mkdir -p /ldconfig-bin /nvfanctrl/dist /nvct/dist /cdi /rootfs-dist /cdi-dist /rules.d && \
mkdir -p /rootfs && \
if [ -n "$(ls /cdi/* 2> /dev/null)" ]; then \
for x in /cdi/*.yaml; do \
OUTFILE=/cdi-dist/$(basename "$x") ; \
/process-cdi.sh "$x" /rootfs /rootfs-dist && \
yq '. | (.devices[].containerEdits.hooks[] | select(.path == "/usr/bin/nvidia-ctk")).path = "/opt/vendor/nvidia/bin/nvidia-ctk"' -i "$x" && \
yq '. | (.devices[].containerEdits.hooks[] | select(.path == "/usr/bin/nvidia-cdi-hook")).path = "/opt/vendor/nvidia/bin/nvidia-cdi-hook"' -i "$x" && \
/nvct/dist/nvidia-ctk cdi transform root --relative-to host \
--from /usr --to /opt/vendor/nvidia/dist/usr --input "$x" | \
/nvct/dist/nvidia-ctk cdi transform root --relative-to host \
--from /etc --to /opt/vendor/nvidia/dist/etc | \
/nvct/dist/nvidia-ctk cdi transform root --relative-to host \
--from /lib --to /opt/vendor/nvidia/dist/lib --output "$OUTFILE" && \
yq '. | (.devices[].containerEdits.hooks[] | select(.args[] == "update-ldcache")).args += ["--ldconfig-path", "/opt/vendor/nvidia/bin/ldconfig-glibc"]' -i "$OUTFILE" ; \
done ; \
fi && \
rm -rf /rootfs/*

FROM scratch
COPY --from=build /cdi-dist/*.yaml /etc/cdi/
COPY --from=build /rules.d/* /opt/vendor/nvidia/etc/udev/rules.d/
COPY --from=build /rootfs-dist/ /opt/vendor/nvidia/dist/
COPY --from=build /ldconfig-bin/* /opt/vendor/nvidia/bin/
COPY --from=build /nvct/dist/* /opt/vendor/nvidia/bin/
COPY --from=build /nv-init.sh /opt/vendor/nvidia/init.d/

ENTRYPOINT []
CMD []
7 changes: 7 additions & 0 deletions pkg/nvidia/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# linuxkit build template
#
# Copyright (c) 2024 Zededa, Inc.
# SPDX-License-Identifier: Apache-2.0
#
org: lfedge
image: eve-nvidia
Loading

0 comments on commit 3b25eb2

Please sign in to comment.