Blame

10d7dc Dave LeBlanc 2026-11-12 16:13:03
Singularity updated on Thu Nov 12 16:12:23 2026
1
# Singularity
2
3
---++ Intro
4
5
Since there is a pressing need for the use of containers in a specific way, this document will begin limited to that specific context, and then branch from there.
6
7
---++ Why Singularity and not Docker?
8
9
Docker is a fine virtual abstraction system, however it requires administrator privileges to run. Further, once an image is running, Docker's default preference is to have input and output resources relevant to the container _within_ the container itself. Singularity overcomes these two issues by running images as the user envoking them, and then exposing the local filesystem on the host from within the running container. More detailed information can be found [[https://sylabs.io/guides/3.3/user-guide/quick_start.html#overview-of-the-singularity-interface][here]].
10
11
---++ Build a container
12
13
In this contextual need, we would like to be able to run Tensorflow. Singularity will allow us to obtain an existing container from a Singularity Container Library, a Singularity Hub, or a Docker Hub. In this particular case of Tensorflow, we'll download one of NVidia's premade Docker containers, which Singularity will convert into its own format.
14
First, we need to obtain access to NVidia's library of Docker containers, located here:
15
[[https://ngc.nvidia.com/catalog/containers][Nvidia NGC]]
16
17
This is initially done by requesting access through the [[https://ngc.nvidia.com/signup][Create Account]] link. Once an account is granted, the [[https://ngc.nvidia.com/setup/api-key][API key]] is needed.
18
19
Once the API key is obtained, set it usable in the shell:
20
21
<verbatim>
22
export SINGULARITY_DOCKER_USERNAME=$oauthtoken
23
export SINGULARITY_DOCKER_PASSWORD=<API key></verbatim>
24
25
Now you may log into the Nvidia NGC and browse for containers. In this example, we'll download [[https://ngc.nvidia.com/catalog/containers/nvidia:tensorflow][Tensorflow]].
26
There, it lists the container as:
27
28
<verbatim>nvcr.io/nvidia/tensorflow:19.09-py3</verbatim>
29
30
By default, singularity will write the entire container into your home directory and then the container will be specific to your account, hidden, and available only to you. To avoid that, we'll write it to a file instead, in Singularity Image Format (SIF).
31
So, for singularity, we will *pull* the image as such:
32
33
<verbatim>>singularity pull tf-19.09-py3.sif docker://nvcr.io/nvidia/tensorflow:19.09-py3</verbatim>
34
35
Singularity will then download each blob-layer in the _tensorflow:19.09-py3_ tag, and cache it into your home directory.
36
37
<verbatim>INFO: Converting OCI blobs to SIF format
38
INFO: Starting build...
39
Getting image source signatures
40
Copying blob sha256:35c102085707f703de2d9eaad8752d6fe1b8f02b5d2149f1d8357c9cc7fb7d0a
41
25.45 MiB / 25.45 MiB [====================================================] 1s
42
Copying blob sha256:251f5509d51d9e4119d4ffb70d4820f8e2d7dc72ad15df3ebd7cd755539e40fd
43
34.54 KiB / 34.54 KiB [====================================================] 0s
44
Copying blob sha256:8e829fe70a46e3ac4334823560e98b257234c23629f19f05460e21a453091e6d
45
848 B / 848 B [============================================================] 0s
46
Copying blob sha256:6001e1789921cf851f6fb2e5fe05be70f482fe9c2286f66892fe5a3bc404569c
47
162 B / 162 B [============================================================] 0s
48
Copying blob sha256:109c7cec1178b6d77b59e8715fe1eae904b528bb9c4868519ff5435bae50c44c
49
8.63 MiB / 8.63 MiB [======================================================] 0s
50
<sniped for brevity>
51
Copying blob sha256:df0616c98153f10db5b05626f314000ced06fb127a6cfaac37ff325d11488327
52
452 B / 452 B [============================================================] 0s
53
Copying blob sha256:7828d14d7927458867242e0274e706b1c902eb6b1207e5a28337a7fbc6400e17
54
209.76 KiB / 209.76 KiB [==================================================] 0s
55
Copying blob sha256:ae4e96299b2fca5dc08edbde4061cfdf25c313954a7d46a32dfc701af4e0edf6
56
9.64 KiB / 9.64 KiB [======================================================] 0s
57
Copying config sha256:ad94fc3cd170246d925f8c5aa8000b3e6cbe645d30ff185bf87b40cee8f41d32
58
33.55 KiB / 33.55 KiB [====================================================] 0s
59
Writing manifest to image destination
60
Storing signatures
61
INFO: Creating SIF file...
62
INFO: Build complete: /home/leblancd/.singularity/cache/oci-tmp/52706b896af93123eb7f894f9671bbd31a1cabd15943aa3334eb7af3a710d262/tensorflow_19.09-py3.sif</verbatim>
63
64
Now our container file is complete:
65
66
<verbatim>-rwxrwxr-x 1 leblancd supergroup 3.3G Oct 4 18:39 tf-19.09-py3.sif</verbatim>
67
68
---+++ Cache
69
70
Before we move on, note that singularity also stored the SIF file in the user's cache, in the home directory (there is now a 3.3G file there, with overhead).
71
You can view what is stored in the cache:
72
73
<verbatim>>singularity cache list
74
NAME DATE CREATED SIZE TYPE
75
tensorflow_19.09-py3.s 2019-10-04 18:39:01 3.45 GB oci
76
77
There 1 containers using: 3.45 GB, 68 oci blob file(s) using 3.70 GB of space.
78
Total space used: 7.15 GB</verbatim>
79
80
Clearing the cache is equally simple.
81
82
<verbatim>
83
>singularity cache clean -a</verbatim>
84
85
Removes all images in the cache (with the -a parameter).
86
87
By default, Singularity caches pulled files in your homedirectory with a structure as:
88
89
<verbatim>
90
$HOME/.singularity/cache/library
91
$HOME/.singularity/cache/oci
92
$HOME/.singularity/cache/oci-tmp</verbatim>
93
94
One can change the default location of the cache by setting =SINGULARITY_CACHEDIR= to your desired location, for example (in bash shell):
95
96
<verbatim>
97
echo $SINGULARITY_CACHEDIR
98
99
export $SINGULARITY_CACHEDIR=/tmp/leblancd_sing_cache
100
101
echo $SINGULARITY_CACHEDIR
102
/tmp/leblancd_sing_cache</verbatim>
103
104
---+++ Build a container from scratch
105
106
Now lets say we built this image but discovered it is lacking software that we need.
107
We have a few options at this point, depending on how permanent we would like the software to be.
108
One solution would be to build a new image from the image we pulled and built locally (above).
109
110
Since creating an image from a definition requires root privelege, we cannot do this locally and need to
111
employ the [[https://cloud.sylabs.io/builder][Remote Builder]] service.
112
There, once we have an account created and retrieved an API code (good for 30 days), and saving it to =~/.singularity/sylabs-token=,
113
we can proceed to build our new image with a definition file.
114
115
Using our image from above, lets install 'astropy' into the image.
116
We create a file definition, named =tensorflow-astropy.def=
117
<verbatim>Bootstrap: docker
118
From: nvcr.io/nvidia/tensorflow:19.09-py3
119
120
%post
121
apt-get -y update
122
pip install astropy
123
124
%environment
125
export LC_ALL=C
126
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:$PATH</verbatim>
127
128
Without going too deep into technical details, our definition begins with =Bootstrap=, which every definition file requires and describes the bootstrap agent; =docker= for Docker Hub images (whether from the Docker registry or other), and =library= for [[https://cloud.sylabs.io/library][Container Library]] images.%BR%
129
=From:= describes where the Remote Builder will find the foundational image to build upon.%BR%
130
Anything in the =%post%= section will be performed after the initial image has been pulled and built locally, namely =apt-get -y update= updates the installed software in the container, and =pip install astropy= will install the Python module "astropy" in the container.%BR%
131
In the =%environment= we set the locale (LC_ALL=C), and the =$PATH= so that the system knows where =pip= is located.
132
133
For mor information about building images from scratch and definition files, seek [[https://sylabs.io/guides/3.3/user-guide/definition_files.html][this documentation]].
134
135
With our definition file, =tensorflow-astropy.def=, we can execute:
136
<verbatim>singularity build --remote tf-astropy.sif tensorflow-astropy.def</verbatim>
137
138
which will submit our definition file to the Remote Builder site and build our new image for us.
139
140
---++ Interacting with the Image
141
---+++ exec
142
143
To run the container we just built, we need to decide how we would like to execute it.
144
We can *exec* on the container, which will run a command inside the container:
145
146
<verbatim>>singularity exec tf-19.09-py3.sif cat /etc/os-release
147
NAME="Ubuntu"
148
VERSION="18.04.3 LTS (Bionic Beaver)"
149
ID=ubuntu
150
ID_LIKE=debian
151
PRETTY_NAME="Ubuntu 18.04.3 LTS"
152
VERSION_ID="18.04"
153
HOME_URL="https://www.ubuntu.com/"
154
SUPPORT_URL="https://help.ubuntu.com/"
155
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
156
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
157
VERSION_CODENAME=bionic
158
UBUNTU_CODENAME=bionic</verbatim>
159
160
This will execute any command from within the container, and then immediately exit.
161
162
---+++ shell
163
164
We can also obtain a *shell* within the container:
165
166
<verbatim>>singularity shell tf-19.09-py3.sif
167
Singularity tf-19.09-py3.sif:/tmp> ls -al
168
total 3366992
169
drwxrwxrwt 10 root root 4096 Oct 4 18:45 .
170
drwxr-xr-x 1 leblancd supergroup 80 Oct 4 18:51 ..
171
-rwxrwxr-x 1 leblancd supergroup 3447758848 Oct 4 18:39 tf-19.09-py3.sif</verbatim>
172
173
Notice that the current working directory is /tmp, which is not inside the container.
174
When Singularity executes, it attempts to make available all your existing filespaces, such as your homedirectory, and any common directories existing on the physical host (such as /tmp). Only the files and directories inside the container are exposed over the filespace of the physical host. This makes it rather easy to write any output from the container to the local filesystem, or to an NFS mounted homedirectory.
175
176
Now that we're interactively running the container, we can attempt to execute Tensorflow.
177
178
<verbatim>Singularity tf-19.09-py3.sif:/tmp> python
179
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
180
[GCC 8.3.0] on linux
181
Type "help", "copyright", "credits" or "license" for more information.
182
Could not open PYTHONSTARTUP
183
FileNotFoundError: [Errno 2] No such file or directory: '/etc/pythonstart'
184
>>> import tensorflow as tf
185
2019-10-04 18:57:01.232584: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
186
>>> hello = tf.constant('Testing TF')
187
>>> sess = tf.Session()
188
2019-10-04 18:57:40.770169: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Could not dlopen library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/compat/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/.singularity.d/libs
189
2019-10-04 18:57:40.770224: E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit: UNKNOWN ERROR (303)
190
2019-10-04 18:57:40.773897: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: ml-login3
191
2019-10-04 18:57:40.773919: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: ml-login3
192
2019-10-04 18:57:40.773959: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:200] libcuda reported version is: Not found: was unable to find libcuda.so DSO loaded into this program
193
2019-10-04 18:57:40.774016: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:204] kernel reported version is: 435.21.0
194
2019-10-04 18:57:40.789291: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2494100000 Hz
195
2019-10-04 18:57:40.794142: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4c48fa0 executing computations on platform Host. Devices:
196
2019-10-04 18:57:40.794172: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): <undefined>, <undefined>
197
>>></verbatim>
198
199
Uh oh. The container couldn't locate the CUDA library necessary to execute the Tensorflow Python module in the container.
200
201
---++++ nv
202
203
This is because when the singularity shell was launched, it was not made aware of any NVidia software, and did not map any NVidia drivers/devices into the container. This is easily remedied with the _--nv_ parameter.
204
205
<verbatim>>singularity shell --nv tf-19.09-py3.sif
206
Singularity tf-19.09-py3.sif:/tmp> python
207
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
208
[GCC 8.3.0] on linux
209
Type "help", "copyright", "credits" or "license" for more information.
210
>>> import tensorflow as tf
211
2019-10-04 19:00:12.417390: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
212
>>> hello = tf.constant('Testing TensorF')
213
>>> sess = tf.Session()
214
2019-10-04 19:00:38.980743: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1
215
2019-10-04 19:00:39.767134: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
216
name: TITAN RTX major: 7 minor: 5 memoryClockRate(GHz): 1.77
217
pciBusID: 0000:84:00.0
218
2019-10-04 19:00:39.767193: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
219
2019-10-04 19:00:39.825552: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10
220
2019-10-04 19:00:39.854719: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10
221
2019-10-04 19:00:39.868698: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10
222
2019-10-04 19:00:39.929108: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10
223
2019-10-04 19:00:39.944015: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10
224
2019-10-04 19:00:40.054598: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
225
2019-10-04 19:00:40.057032: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
226
2019-10-04 19:00:40.072683: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2494100000 Hz
227
2019-10-04 19:00:40.077704: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x50cd760 executing computations on platform Host. Devices:
228
2019-10-04 19:00:40.077723: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): <undefined>, <undefined>
229
2019-10-04 19:00:40.172994: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x50d0e80 executing computations on platform CUDA. Devices:
230
2019-10-04 19:00:40.173041: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): TITAN RTX, Compute Capability 7.5
231
2019-10-04 19:00:40.174405: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
232
name: TITAN RTX major: 7 minor: 5 memoryClockRate(GHz): 1.77 pciBusID: 0000:84:00.0
233
2019-10-04 19:00:40.174453: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
234
2019-10-04 19:00:40.174511: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10
235
2019-10-04 19:00:40.174548: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10
236
2019-10-04 19:00:40.174585: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10
237
2019-10-04 19:00:40.174619: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10
238
2019-10-04 19:00:40.174680: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10
239
2019-10-04 19:00:40.174719: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
240
2019-10-04 19:00:40.177149: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
241
2019-10-04 19:00:40.180107: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
242
2019-10-04 19:00:42.739483: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
243
2019-10-04 19:00:42.739536: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0
244
2019-10-04 19:00:42.739545: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N
245
2019-10-04 19:00:42.742016: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device
246
(/job:localhost/replica:0/task:0/device:GPU:0 with 22756 MB memory) -> physical GPU
247
(device: 0, name: TITAN RTX, pci bus id: 0000:84:00.0, compute capability: 7.5)
248
>>> a = tf.constant(10)
249
>>> b = tf.constant(25)
250
>>> sess.run(a+b)
251
35</verbatim>
252
253
---++ Container Reuse
254
255
Now, we have built a container from NVidia, and demonstrated it as working, *can someone else use our container*?%BR%
256
_Yes_, as long as you don't need to write anything into the container space, because the container will be mounted __read-only__ by default.
257
This is likely expected behavior, as it seems undesirable to create a container that allows anyone to write files, creating unforeseen entropy into the otherwise pristine container.%BR%
258
Regarding our example Tensorflow container above, it remains usable as __read-only__ since we are not modifying the binaries/scripts involved in running Tensorflow itself, and any data input or output can live safely and be accessed outside the container.%BR%
259
Consider the following example:
260
261
We have a very simple (example) Python script:%BR%
262
263
<verbatim>
264
>cat helloworld.py
265
266
import tensorflow as tf
267
hello = tf.constant('Hello, TF!')
268
sess = tf.Session()
269
print(sess.run(hello))</verbatim>
270
271
That is in the current directory with our Tensorflow container:%BR%
272
273
<verbatim>
274
-rw-rw-r-- 1 leblancd supergroup 101 Oct 4 19:30 helloworld.py
275
-rwxrwxr-x 1 leblancd supergroup 3.3G Oct 4 18:39 tf-19.09-py3.sif</verbatim>
276
277
We can use our =helloworld.py= script like so:%BR%
278
279
<verbatim>
280
>singularity exec --nv ./tf-19.09-py3.sif python ./helloworld.py
281
2019-10-09 17:34:30.078770: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
282
name: TITAN RTX major: 7 minor: 5 memoryClockRate(GHz): 1.77 pciBusID: 0000:84:00.0
283
...snip...
284
2019-10-09 17:34:30.373594: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
285
2019-10-09 17:34:30.388525: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2494100000 Hz
286
2019-10-09 17:34:30.393509: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x56378c0 executing computations on platform Host. Devices:
287
2019-10-09 17:34:30.393530: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): <undefined>, <undefined>
288
2019-10-09 17:34:30.488286: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5637f30 executing computations on platform CUDA. Devices:
289
2019-10-09 17:34:30.488342: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): TITAN RTX, Compute Capability 7.5
290
2019-10-09 17:34:30.489712: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
291
name: TITAN RTX major: 7 minor: 5 memoryClockRate(GHz): 1.77 pciBusID: 0000:84:00.0
292
...snip...
293
2019-10-09 17:34:30.492309: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
294
2019-10-09 17:34:30.495275: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
295
2019-10-09 17:34:33.013974: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
296
2019-10-09 17:34:33.014043: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0
297
2019-10-09 17:34:33.014054: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N
298
2019-10-09 17:34:33.016631: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device
299
(/job:localhost/replica:0/task:0/device:GPU:0 with 22756 MB memory) -> physical GPU
300
(device: 0, name: TITAN RTX, pci bus id: 0000:84:00.0, compute capability: 7.5)
301
b'Hello, TF!'</verbatim>
302
303
Likewise, redirecting output as:
304
305
<verbatim>
306
>singularity exec --nv ./tf-19.09-py3.sif python ./helloworld.py >> OUTPUT
307
...snip...
308
2019-10-09 17:59:52.089016: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326]
309
Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 22756 MB memory)
310
-> physical GPU (device: 0, name: TITAN RTX, pci bus id: 0000:84:00.0, compute capability: 7.5)
311
></verbatim>
312
313
Then our =OUTPUT= file will be:
314
315
<verbatim>
316
>ls -l
317
total 3367004
318
-rw-rw-r-- 1 leblancd supergroup 101 Oct 9 17:30 helloworld.py
319
-rw-rw-r-- 1 leblancd supergroup 14 Oct 9 17:59 OUTPUT
320
-rwxrwxr-x 1 leblancd supergroup 3447758848 Oct 9 17:09 tf-19.09-py3.sif*
321
322
>cat OUTPUT
323
b'Hello, TF!'</verbatim>
324
325
---++ Instances
326
327
So far, we have run our container with =shell= or =exec=, which runs the container in the foreground, meaning the running container terminates when we exit, either by quitting from the =shell= or by the end of execution from =exec=.%BR%
328
We can, however, _detach_ a container and run it as a "service". In Singularity terms, this is called an *instance*.%BR%
329
<verbatim>
330
>singularity instance start --nv ./tf-19.09-py3.sif Tensorflow
331
332
INFO: instance started successfully</verbatim>
333
334
Now the instance is running, and we can launch however many as we like, though each instance needs a unique name.%BR%
335
336
<verbatim>
337
>singularity instance start --nv ./tf-19.09-py3.sif tensorflow
338
INFO: instance started successfully
339
>singularity instance start --nv ./tf-19.09-py3.sif tensorflow2
340
INFO: instance started successfully</verbatim>
341
342
To review what instances we have running:%BR%
343
344
<verbatim>
345
>singularity instance list
346
INSTANCE NAME PID IMAGE
347
Tensorflow 52226 /tmp/tf-19.09-py3.sif
348
tensorflow 52358 /tmp/tf-19.09-py3.sif
349
tensorflow2 52407 /tmp/tf-19.09-py3.sif</verbatim>
350
351
__NOTE:__ we launched our instances with =--nv=, to expose the NVidia devices/drivers to the instances we launch (you cannot do this after the container instance is already running).
352
353
Now, to access (or "attach") to the running instances, we can use =exec= or =shell= as before, but target the _instance_ like so:%BR%
354
355
<verbatim>
356
>singularity shell instance://tensorflow2
357
Singularity tf-19.09-py3.sif:/tmp> nvidia-smi
358
Wed Oct 9 18:24:58 2019
359
+-----------------------------------------------------------------------------+
360
| NVIDIA-SMI 435.21 Driver Version: 435.21 CUDA Version: 10.1 |
361
|-------------------------------+----------------------+----------------------+
362
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
363
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
364
|===============================+======================+======================|
365
| 0 TITAN RTX Off | 00000000:84:00.0 Off | N/A |
366
| 21% 35C P0 N/A / N/A | 0MiB / 24220MiB | 0% Default |
367
+-------------------------------+----------------------+----------------------+
368
369
+-----------------------------------------------------------------------------+
370
| Processes: GPU Memory |
371
| GPU PID Type Process name Usage |
372
|=============================================================================|
373
| No running processes found |
374
+-----------------------------------------------------------------------------+</verbatim>
375
376
Finally, to terminate our instances:%BR%
377
378
<verbatim>
379
>singularity instance stop Tensorflow
380
Stopping Tensorflow instance of /tmp/tf-19.09-py3.sif (PID=52226)</verbatim>
381
382
Or:
383
384
<verbatim>
385
>singularity instance stop -a
386
Stopping tensorflow2 instance of /tmp/tf-19.09-py3.sif (PID=52407)
387
Stopping tensorflow instance of /tmp/tf-19.09-py3.sif (PID=52762)</verbatim>