From 56da84f3ec14c71f804c3e593b556fa34c734e02 Mon Sep 17 00:00:00 2001 From: "James P. Ketrenos" Date: Thu, 15 Oct 2020 14:48:51 -0700 Subject: [PATCH] Updated to latest xe-solutions Signed-off-by: James P. Ketrenos --- scripts/intel-docker | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 scripts/intel-docker diff --git a/scripts/intel-docker b/scripts/intel-docker new file mode 100755 index 0000000..1769b65 --- /dev/null +++ b/scripts/intel-docker @@ -0,0 +1,95 @@ +#!/bin/bash + +function fail { + >&2 echo "$*" + exit -1 +} + +PRE_RUN=() +POST_RUN=() +RUN= +for arg in "${@}"; do + [[ "${arg}" == "run" ]] && { + RUN=1 + continue + } + (( ! RUN )) && { + PRE_RUN+=("${arg}") + } || { + POST_RUN+=("${arg}") + } +done + +function usage { + cat << EOF +usage: scripts/intel-docker [DOCKER-OPTIONS] + +intel-docker adds the following docker parameters to your +DOCKER-OPTIONS, based on the host configuration: + + --device=/dev/dri + --group-add \${VIDEO} + --group-add \${RENDER} + +The group id used for VIDEO and RENDER is +based on the 'video' and 'render' group definitions used +for ownership of /dev/dri/* entries. Typically card* is +owned by 'video' and render* is owned by 'render'. To +find the group id, 'stat' is used: + + VIDEO=\$(stat -c '%g' /dev/dri/card*) + RENDER=\$(stat -c '%g' /dev/dri/render*) + +If /dev/dri entries do not exist, no group add lines are added to +the docker option. +EOF +} + +if test -e /dev/dri/card*; then + VIDEO=$(stat -c '%g' /dev/dri/card*) +fi +if test -e /dev/dri/render*; then + RENDER=$(stat -c '%g' /dev/dri/render*) +fi +if [ "${RENDER}" == "${VIDEO}" ]; then + unset RENDER +fi +if [ "${RENDER}" == "" ] && [ "${VIDEO}" == "" ]; then + fail "No /dev/dri/* entries found on host. Does your kernel have the GPU driver loaded?" +fi + +cat << EOF +------------------------------------------------------------------------------- +Intel Xe graphics container script +EOF + +(( RUN )) && { + PRE_RUN+=("run") + POST_RUN=(--device=/dev/dri ${POST_RUN[@]}) + + [[ "${VIDEO}" != "" ]] || fail "No group ownership of /dev/dri/card* found." + POST_RUN=("--group-add ${VIDEO}" ${POST_RUN[@]}) + + [[ "${RENDER}" != "" ]] && POST_RUN=("--group-add ${RENDER}" ${POST_RUN[@]}) + true +} || { + cat << EOF + +NOTE: intel-docker is intended to be executed with the same arguments as you +would pass to docker, including the 'run' command. + +EOF +} + +cat << EOF +Adding the following options to the docker command line after 'run' and before +user options: + + --device=/dev/dri + --group-add ${VIDEO}$( [[ "${RENDER}" != "" ]] && echo -e "\n --group-add ${RENDER}\n" ) + +------------------------------------------------------------------------------- +EOF + +echo -e "Running:\ndocker ${PRE_RUN[@]} ${POST_RUN[@]}" +docker ${PRE_RUN[@]} ${POST_RUN[@]}