Skip to content

Instantly share code, notes, and snippets.

@imadelh
Last active June 19, 2022 15:28
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save imadelh/cf7b12c9cc81c3cb95ad2c6bc747ccd0 to your computer and use it in GitHub Desktop.
Nvidia Docker - Jetson Nano
#!/bin/bash
# Copied and modified from https://github.com/Technica-Corporation/Tegra-Docker
# Copyright (c) 2017, Technica Corporation. All rights reserved.
NV_LIBS="/usr/lib/aarch64-linux-gnu \
/usr/local/cuda/lib64 \
/usr/local/cuda \
/usr/src/tensorrt \
/usr/local/cuda-10.0 \
/usr/include \
/usr/src "
LD_PATH="/usr/lib/aarch64-linux-gnu \
/usr/lib/aarch64-linux-gnu/tegra \
/usr/local/cuda/lib64 \
/usr/src/tensorrt \
/usr/local/cuda \
/usr/local/cuda-10.0 \
/usr/include"
GPU_DEVICES="/dev/nvhost-ctrl \
/dev/nvhost-ctrl-gpu \
/dev/nvhost-prof-gpu \
/dev/nvmap \
/dev/nvhost-gpu \
/dev/nvhost-as-gpu"
NV_DOCKER_ARGS="--net=host"
build_docker_args() {
#set the required libraries as volumes on the docker container
LIB_ARGS=""
for lib in $NV_LIBS; do
LIB_ARGS="$LIB_ARGS -v $lib:$lib"
done
#set the required devices to be passed through to the container
DEV_ARGS=""
for dev in $GPU_DEVICES; do
DEV_ARGS="$DEV_ARGS --device=$dev"
done
NV_DOCKER_ARGS="$NV_DOCKER_ARGS $LIB_ARGS $DEV_ARGS"
}
build_env() {
#build the LD_LIBRARY_PATH
LD_LIBRARY_PATH=""
for lib in $LD_PATH; do
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$lib"
done
}
if [[ $# -ge 2 && $1 == "run" ]]; then
echo "Running an nvidia docker image"
build_docker_args
build_env
DOCKER_OPTS="-e LD_LIBRARY_PATH=$LD_LIBRARY_PATH $NV_DOCKER_ARGS ${@:2}"
echo "docker run $DOCKER_OPTS"
docker run $DOCKER_OPTS
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment