Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev nvidia with nv #1358

Merged
merged 7 commits into from Mar 27, 2018
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ and changes prior to that are (unfortunately) done retrospectively. Critical ite
- Put /usr/local/{bin,sbin} in front of the default PATH
- Adjustments to SCIF (Scientific Filesystem) integration for broader use
- Fixed bug that did not export environment variables for apps with "-" in name
- Fix conflict between `--nv` and `--contain` options

## [v2.4.4](https://github.com/singularityware/singularity/tree/release-2.4)

Expand Down
4 changes: 3 additions & 1 deletion libexec/cli/action_argparser.sh
Expand Up @@ -123,6 +123,8 @@ while true; do
;;
--nv)
shift
SINGULARITY_NV=1
export SINGULARITY_NV
SINGULARITY_NVLIBLIST=`mktemp ${TMPDIR:-/tmp}/.singularity-nvliblist.XXXXXXXX`
cat $SINGULARITY_sysconfdir"/singularity/nvliblist.conf" | grep -Ev "^#|^\s*$" > $SINGULARITY_NVLIBLIST
for i in $(ldconfig -p | grep -f "${SINGULARITY_NVLIBLIST}"); do
Expand All @@ -141,7 +143,7 @@ while true; do
else
export SINGULARITY_CONTAINLIBS
fi
if NVIDIA_SMI=$(which nvidia-smi); then
if NVIDIA_SMI=$(which nvidia-smi 2>/dev/null); then
if [ -n "${SINGULARITY_BINDPATH:-}" ]; then
SINGULARITY_BINDPATH="${SINGULARITY_BINDPATH},${NVIDIA_SMI}"
else
Expand Down
23 changes: 23 additions & 0 deletions src/lib/runtime/mounts/dev/dev.c
Expand Up @@ -31,6 +31,8 @@
#include <unistd.h>
#include <stdlib.h>
#include <grp.h>
#include <string.h>
#include <dirent.h>

#include "config.h"
#include "util/file.h"
Expand All @@ -52,6 +54,7 @@ int _singularity_runtime_mount_dev(void) {
if ( ( singularity_registry_get("CONTAIN") != NULL ) || ( strcmp("minimal", singularity_config_get_value(MOUNT_DEV)) == 0 ) ) {
char *sessiondir = singularity_registry_get("SESSIONDIR");
char *devdir = joinpath(sessiondir, "/dev");
char *nvopt = singularity_registry_get("NV");

if ( is_dir(joinpath(container_dir, "/dev")) < 0 ) {
int ret;
Expand Down Expand Up @@ -103,6 +106,26 @@ int _singularity_runtime_mount_dev(void) {
bind_dev(sessiondir, "/dev/random");
bind_dev(sessiondir, "/dev/urandom");

/* if the user passed the --nv flag and the --contain flag, still bind
nvidia devices */
if ( nvopt != NULL ) {
DIR *dir;
struct dirent *dp;

if ( ( dir = opendir("/dev") ) == NULL ) {
singularity_message(ERROR, "Could not open /dev on host system");
ABORT(255);
}

while ( ( dp = readdir(dir) ) != NULL ) {
if ( strstr(dp->d_name, "nvidia") != NULL ) {
bind_dev(sessiondir, joinpath("/dev", dp->d_name) );
}
}

closedir(dir);
}

singularity_message(DEBUG, "Mounting tmpfs for staged /dev/shm\n");
if ( singularity_mount("/dev/shm", joinpath(devdir, "/shm"), "tmpfs", MS_NOSUID, "") < 0 ) {
singularity_message(ERROR, "Failed to mount %s: %s\n", joinpath(devdir, "/shm"), strerror(errno));
Expand Down