Skip to content

Commit 6760de9

Browse files
committed
Merge branch 'GodloveD-master'
2 parents 4d29381 + bc934e7 commit 6760de9

File tree

13 files changed

+156
-204
lines changed

13 files changed

+156
-204
lines changed

_posts/recipes/2017-05-09-hostlibs-gpus-and-mpi.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ category: recipes
44
permalink: tutorial-gpu-drivers-open-mpi-mtls
55
---
66

7+
**Note: _Much of the GPU portion of this tutorial is deprecated by the `--nv`
8+
option that automatically binds host system driver libraries into your
9+
container at runtime. See the [`exec`](/docs-exec#a-gpu-example) command for
10+
an example_**
11+
712
Singularity does a fantastic job of isolating you from the host so you don't
813
have to muck about with `LD_LIBRARY_PATH`, you just get exactly the library
914
versions you want. However, in some situations you need to use library

pages/docs/contributing/contributing-docs.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ title: Contributing to Documentation
33
sidebar: main_sidebar
44
permalink: contributing-docs
55
folder: releases
6+
toc: false
67
---
78

89
We (like almost all open source software providers) have a documentation dillemma... We tend to focus on the code features and functionality before working on documentation. And there is very good reason for this, we want to share the love so nobody feels left out!
910

1011
The following documentation page assumes one is running on OS X, but if you are not, you should be able to easily transpose the necessary commands to your operating system of choice.
1112

13+
{% include toc.html %}
1214

1315
## Setting Up Your Development Environment
1416

@@ -113,8 +115,16 @@ asciinema rec -w 1 demo-asciicast.js
113115
# To play
114116
asciinema play demo-asciicast.js
115117
```
118+
Make sure to resize your terminal to 25 rows x 115 columns or less before you
119+
begin your recording. Otherwise it will not display properly on the webpage. To get the size of your current terminal (in lines and columns) you can use `tput`:
116120

117-
Once you've generated an asciicast, you should drop the file (e.g., some `demo-asciicast.js`) into the `assets/asciicast` folder, and then include the following in the page or post:
121+
```
122+
echo -e "lines\ncols"|tput -S
123+
34
124+
80
125+
```
126+
127+
Once you've generated an asciicast, you should drop the file (e.g., `demo-asciicast.js`) into the `assets/asciicast` folder. Since we will have many asciicasts here, please name it meaningfully. Then include the following in the page or post:
118128

119129
```bash
120130
{{ "{% include asciicast.html source='demo-asciicast.js' title='How to make demos' author='[email protected]'" }}%}

pages/docs/overview/faq.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ See the Singularity on HPC page for more details.
213213

214214
### Does Singularity support containers that require GPUs?
215215

216-
Yes, Singularity has been tested to run some test and diagnostic code from within a container without modification. There are however potential issues that can come into play when using GPUs, for instance there are version API compatibilities between kernel and user land which will have to be considered.
216+
Yes. Many users run GPU dependant code within Singularity containers. The
217+
experimental `--nv` option allows you to leverage host GPUs without installing
218+
system level drivers into your container. See the [`exec`](/docs-exec#a-gpu-example) command for
219+
an example.
217220

218221
## Container portability
219222

pages/docs/user-docs/docs-bootstrap-image.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ title: Getting Started with Bootstrap
33
sidebar: user_docs
44
permalink: bootstrap-image
55
folder: docs
6+
toc: false
67
---
78

8-
## Bootstrapping a Container
99
Bootstrapping is the process where we install an operating system and then configure it appropriately for a specified need. To do this we use a bootstrap definition file (a text file called `Singularity`) which is a recipe of how to specifically build the container. Here we will overview the sections, best practices, and a quick example.
1010

1111
{% include toc.html %}
@@ -142,7 +142,17 @@ Version 2.0
142142
```
143143

144144
#### %environment
145-
Akin to labels, you can add pairs of `VARIABLE` and `VALUE` under environment to be sourced when the container is used as variables in the environment. The entire section is written to a file that gets sourced, so you should generally use the same conventions that you might use in a `bashrc` or `profile`. See <a href="/docs-environment-metadata">Environment and Metadata</a> for more information about these two sections.
145+
You can add environment variables to be sourced when the container is used in the `%environment` section. The entire section is written to a file that gets sourced, so you should generally use the same conventions that you might use in a `bashrc` or `profile`.
146+
147+
```
148+
%environment
149+
VADER=badguy
150+
LUKE=goodguy
151+
SOLO=someguy
152+
export VADER LUKE SOLO
153+
```
154+
155+
See <a href="/docs-environment-metadata">Environment and Metadata</a> for more information about the `%labels` and `%environment` sections.
146156

147157

148158
#### %post

pages/docs/user-docs/docs-bootstrap.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ toc: false
66
folder: docs
77
---
88

9-
{% include toc.html %}
10-
119
The process of *bootstrapping* a Singularity container is equivalent to describing a recipe for the container creation. There are several recipe formats that Singularity supports, but only the primary format of version 2.3 will be documented here. If you want a general overview with examples, see <a href="/bootstrap-image">Bootstrapping an Image</a>. The detailed options for each of the header and sections are provided here.
1210

11+
{% include toc.html %}
12+
1313
## The header fields:
1414

1515
### Bootstrap:
@@ -48,7 +48,7 @@ The Docker bootstrap module will create a core operating system image based on a
4848
Once the `Bootstrap` module has completed, the sections are identified and utilized if present. The following sections are supported in the bootstrap definition, and integrated during the bootstrap process:
4949

5050

51-
#### %setup
51+
### %setup
5252
This section blob is a Bourne shell scriptlet which will be executed on the host outside the container during bootstrap. The path to the container is accessible from within the running scriptlet environment via the variable `$SINGULARITY_ROOTFS`. For example, consider the following scriptlet:
5353

5454
```
@@ -65,8 +65,7 @@ As we investigate this example scriptlet, you will first see this is the outside
6565

6666
*note: Any uncaught command errors that occur within the scriptlet will cause the entire build process to halt!*
6767

68-
69-
#### %post
68+
### %post
7069
Similar to the `%setup` section, this section will be executed once during bootstrapping, but this scriptlet will be run from inside the container. This is where you should put additional installation commands, downloads, and configuration into your containers. Here is an example to consider:
7170

7271
```
@@ -94,8 +93,15 @@ The above example runs inside the container, so in this case we will first insta
9493

9594
*another note: This is not a good example of a reproducible definition because it is pulling Open MPI from a moving target. A better example, would be to pull a static released version, but this serves as a good example of building a `%post` scriptlet.*
9695

96+
### %environment
97+
Beginning with Singularity v2.3 you can set up your environment using the `%environment` section of the definition file. For example, if you wanted to add a directory to your search path, you could do so like this.
98+
99+
```
100+
%environment
101+
export PATH=/opt/good/stuff:$PATH
102+
```
97103

98-
#### %runscript
104+
### %runscript
99105
The `%runscript` is another scriptlet, but it does not get executed during bootstrapping. Instead it gets persisted within the container to a file called `/singularity` which is the execution driver when the container image is ***run*** (either via the `singularity run` command or via executing the container directly).
100106

101107
When the `%runscript` is executed, all options are passed along to the executing script at runtime, this means that you can (and should) manage argument processing from within your runscript. Here is an example of how to do that:
@@ -108,7 +114,7 @@ When the `%runscript` is executed, all options are passed along to the executing
108114

109115
In this particular runscript, the arguments are printed as a single string (`$*`) and then they are passed to `/usr/bin/python` via a quoted array (`$@`) which ensures that all of the arguments are properly parsed by the executed command. The `exec` command causes the given command to replace the current entry in the process table with the one that is to be called. This makes it so the runscript shell process ceases to exist, and the only process running inside this container is the called Python command.
110116

111-
#### %test
117+
### %test
112118
You may choose to add a `%test` section to your definition file. This section will be run at the very end of the boostrapping process and will give you a chance to validate the container during the bootstrap process. If you are building on Singularity Hub, [it is a good practice](https://github.com/singularityhub/singularityhub.github.io/wiki/Generate-Images#add-tests) to have this test section so you can be sure that your container works as expected. A non-zero status code indicates that one or more of your tests did not pass. You can also execute this scriptlet through the container itself, such that you can always test the validity of the container itself as you transport it to different hosts. Extending on the above Open MPI `%post`, consider this example:
113119

114120
```

pages/docs/user-docs/docs-environment-metadata.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
2-
title: Changing Existing Containers
2+
title: Environment and Metadata
33
sidebar: user_docs
44
permalink: docs-environment-metadata
55
folder: docs
6+
toc: false
67
---
78

8-
## Container Metadata
9+
Singularity containers support environment variables and labels that can be added by user during the bootstrap process.
910

10-
Singularity containers have two level of metadata - environment variables, and labels from the user and bootstrap process.
11+
{% include toc.html %}
1112

12-
### Environment
13+
## Environment
1314

1415
If you are importing a Docker container, the environment will be imported as well. If you want to define custom environment variables in your bootstrap recipe file `Singularity` you can do that like this
1516

@@ -18,8 +19,8 @@ Bootstrap:docker
1819
From: ubuntu:latest
1920

2021
%environment
21-
VARIABLE_NAME=VARIABLE_VALUE
22-
export VARIABLE_NAME
22+
VARIABLE_NAME=VARIABLE_VALUE
23+
export VARIABLE_NAME
2324
```
2425

2526
Forget something, or need a variable defined at runtime? You can set any variable you want inside the container by prefixing it with "SINGULARITYENV_". It will be transposed automatically and the prefix will be stripped. For example, let's say we want to set the variable `HELLO` to have value `WORLD`. We can do that as follows:
@@ -58,7 +59,7 @@ singularity exec centos7.img cat /.singularity.d/env/10-docker.sh
5859
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
5960
```
6061

61-
### Labels
62+
## Labels
6263
Your container stores metadata about it's build, along with Docker labels. You can see the data as follows:
6364

6465
```bash

pages/docs/user-docs/docs-exec.md

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,11 @@ toc: false
88

99
The `exec` Singularity sub-command allows you to spawn an arbitrary command within your container image as if it were running directly on the host system. All standard IO, pipes, and file systems are accessible via the command being exec'ed within the container. Note that this exec is different from the Docker exec, as it does not require a container to be "running" before using it.
1010

11-
## Usage
11+
{% include toc.html %}
1212

13-
The usage is as follows:
13+
## Examples
1414

15-
```bash
16-
USAGE: singularity [...] exec [exec options...] <container path> <command>
17-
18-
This command will allow you to execute any program within the given
19-
container image.
20-
21-
EXEC OPTIONS:
22-
-B/--bind <spec> A user-bind path specification. spec has the format
23-
src[:dest[:opts]], where src and dest are outside and
24-
inside paths. If dest is not given, it is set equal
25-
to src. Mount options ('opts') may be specified as
26-
'ro' (read-only) or 'rw' (read/write, which is the
27-
default). This option can be called multiple times.
28-
-c/--contain This option disables the automatic sharing of writable
29-
filesystems on your host (e.g. $HOME and /tmp).
30-
-C/--containall Contain not only file systems, but also PID and IPC
31-
-e/--cleanenv Clean environment before running container
32-
-H/--home <spec> A home directory specification. spec can either be a
33-
src path or src:dest pair. src is the source path
34-
of the home directory outside the container and dest
35-
overrides the home directory within the container
36-
-i/--ipc Run container in a new IPC namespace
37-
-p/--pid Run container in a new PID namespace
38-
--pwd Initial working directory for payload process inside
39-
the container
40-
-S/--scratch <path> Include a scratch directory within the container that
41-
is linked to a temporary dir (use -W to force location)
42-
-u/--user Try to run completely unprivileged (only works on very
43-
new kernels/distros)
44-
-W/--workdir Working directory to be used for /tmp, /var/tmp and
45-
$HOME (if -c/--contain was also used)
46-
-w/--writable By default all Singularity containers are available as
47-
read only. This option makes the file system accessible
48-
as read/write.
49-
50-
51-
CONTAINER FORMATS SUPPORTED:
52-
*.img This is the native Singularity image format for all
53-
Singularity versions 2.x.
54-
*.sqsh SquashFS format, note the suffix is required!
55-
*.tar* Tar archives are exploded to a temporary directory and
56-
run within that directory (and cleaned up after).
57-
Compression suffixes as '.gz' and 'bz2' are supported.
58-
directory/ Container directories that contain a valid root file
59-
system.
60-
61-
62-
EXAMPLES:
63-
64-
$ singularity exec /tmp/Debian.img cat /etc/debian_version
65-
$ singularity exec /tmp/Debian.img python ./hello_world.py
66-
$ cat hello_world.py | singularity exec /tmp/Debian.img python
67-
$ sudo singularity exec --writable /tmp/Debian.img apt-get update
68-
69-
```
70-
71-
### Examples
72-
73-
#### Printing the OS release inside the container:
15+
### Printing the OS release inside the container:
7416

7517
```bash
7618
$ singularity exec container.img cat /etc/os-release
@@ -85,7 +27,7 @@ BUG_REPORT_URL="https://bugs.debian.org/"
8527
$
8628
```
8729

88-
#### Special Characters
30+
### Special Characters
8931
And properly passing along special characters to the program within the container.
9032

9133
```bash
@@ -104,7 +46,7 @@ $
10446
```
10547

10648

107-
#### A Python example
49+
### A Python example
10850
Starting with the file `hello.py` in the current directory with the contents of:
10951

11052
```python
@@ -149,3 +91,54 @@ Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c
14991
Downloading layer: sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5bb
15092
Hello World: The Python version is 3.5.2
15193
```
94+
95+
### A GPU example
96+
If your host system has an NVIDIA GPU card and a driver installed you can
97+
leverage the card with the `--nv` option. (This example requires a fairly
98+
recent version of the NVIDIA driver on the host system to run the latest
99+
version of TensorFlow.
100+
101+
```
102+
$ git clone https://github.com/tensorflow/models.git
103+
$ singularity exec --nv docker://tensorflow/tensorflow:latest-gpu \
104+
python ./models/tutorials/image/mnist/convolutional.py
105+
Docker image path: index.docker.io/tensorflow/tensorflow:latest-gpu
106+
Cache folder set to /home/david/.singularity/docker
107+
[19/19] |===================================| 100.0%
108+
Creating container runtime...
109+
Extracting data/train-images-idx3-ubyte.gz
110+
Extracting data/train-labels-idx1-ubyte.gz
111+
Extracting data/t10k-images-idx3-ubyte.gz
112+
Extracting data/t10k-labels-idx1-ubyte.gz
113+
2017-08-18 20:33:59.677580: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
114+
2017-08-18 20:33:59.677620: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
115+
2017-08-18 20:34:00.148531: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:893] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
116+
2017-08-18 20:34:00.148926: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 0 with properties:
117+
name: GeForce GTX 760 (192-bit)
118+
major: 3 minor: 0 memoryClockRate (GHz) 0.8885
119+
pciBusID 0000:03:00.0
120+
Total memory: 2.95GiB
121+
Free memory: 2.92GiB
122+
2017-08-18 20:34:00.148954: I tensorflow/core/common_runtime/gpu/gpu_device.cc:976] DMA: 0
123+
2017-08-18 20:34:00.148965: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 0: Y
124+
2017-08-18 20:34:00.148979: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 760 (192-bit), pci bus id: 0000:03:00.0)
125+
Initialized!
126+
Step 0 (epoch 0.00), 21.7 ms
127+
Minibatch loss: 8.334, learning rate: 0.010000
128+
Minibatch error: 85.9%
129+
Validation error: 84.6%
130+
Step 100 (epoch 0.12), 20.9 ms
131+
Minibatch loss: 3.235, learning rate: 0.010000
132+
Minibatch error: 4.7%
133+
Validation error: 7.8%
134+
Step 200 (epoch 0.23), 20.5 ms
135+
Minibatch loss: 3.363, learning rate: 0.010000
136+
Minibatch error: 9.4%
137+
Validation error: 4.2%
138+
[...snip...]
139+
Step 8500 (epoch 9.89), 20.5 ms
140+
Minibatch loss: 1.602, learning rate: 0.006302
141+
Minibatch error: 0.0%
142+
Validation error: 0.9%
143+
Test error: 0.8%
144+
```

pages/docs/user-docs/docs-export.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,16 @@ toc: false
66
folder: docs
77
---
88

9-
Export is a way to dump the contents of your container into a .tar.gz, or a stream to put into some other place. For example, you could stream this into an in memory tar in python.
9+
Export is a way to dump the contents of your container into a .tar.gz, or a stream to put into some other place. For example, you could stream this into an in memory tar in python.
1010

11-
## Usage
11+
Here we export an image into a `.tar` file:
1212

13-
```bash
14-
USAGE: singularity [...] export [export options...] <container path>
15-
16-
Export will dump a tar stream of the container image contents to standard
17-
out (stdout).
18-
19-
EXPORT OPTIONS:
20-
-f/--file Output to a file instead of a pipe
21-
--command Replace the tar command (DEFAULT: 'tar cf - .')
22-
23-
EXAMPLES:
13+
```
14+
singularity export container.img > container.tar
15+
```
2416

25-
$ singularity export /tmp/Debian.img > /tmp/Debian.tar
26-
$ singularity export /tmp/Debian.img | gzip -9 > /tmp/Debian.tar.gz
27-
$ singularity export -f Debian.tar /tmp/Debian.img
17+
And here is the recommended way to compress your image:
2818

2919
```
20+
singularity export container.img | gzip -9 > container.img.gz
21+
```

0 commit comments

Comments
 (0)