{"id":797,"date":"2018-11-02T14:00:20","date_gmt":"2018-11-02T14:00:20","guid":{"rendered":"https:\/\/portal.supercomputing.wales\/?page_id=797"},"modified":"2018-11-02T14:00:45","modified_gmt":"2018-11-02T14:00:45","slug":"singularity","status":"publish","type":"page","link":"https:\/\/portal.supercomputing.wales\/index.php\/singularity\/","title":{"rendered":"Singularity"},"content":{"rendered":"<h2><span id=\"What_is_Singularity\" class=\"mw-headline\">What is Singularity <\/span><\/h2>\n<p>Singularity <a class=\"external autonumber\" href=\"https:\/\/www.sylabs.io\/\" rel=\"nofollow\">[1]<\/a> is a container system that doesn&#8217;t need root access. Containers are a set of applications and a minimal operating system bundled together in a single file. They are a good way to ensure that anyone running the software is using the exact same set of libraries and dependencies. This is helpful to reproducible science where we want somebody else to be able to recreate our results. They also allow us to run newer\/older\/different operating systems than the one installed on the host system.<\/p>\n<h2><span id=\"Loading_singularity\" class=\"mw-headline\"> Loading singularity <\/span><\/h2>\n<p>Run the command (or add it to your submission script):<br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp; module load singularity \n<\/pre><\/p>\n<h2><span id=\"Obtaining_Containers\" class=\"mw-headline\"> Obtaining Containers <\/span><\/h2>\n<p>Singularity Hub <a class=\"external autonumber\" href=\"https:\/\/singularity-hub.org\/collections\" rel=\"nofollow\">[2]<\/a> contains a number of pre-made containers which you can download and use. To download these run:<br \/>\n<code class=\"preserve-code-formatting\">singularity pull shub:\/\/\/:<\/code><br \/>\nThis will then download the file to &lt;username&gt;-singularity_hub-master-&lt;image name&gt;.simg<\/p>\n<p>&nbsp;<\/p>\n<p>The Super Computing Wales base container can be obtained by running:<br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp; singularity pull shub:\/\/SupercomputingWales\/singularity_hub:base_image \n<\/pre><\/p>\n<h2><\/h2>\n<h2><span id=\"Running_a_shell_in_a_container\" class=\"mw-headline\"> Running a shell in a container <\/span><\/h2>\n<p>The singularity shell command will run a shell inside the container. You can then execute any commands from software installed in the container. To do this run the command &#8220;singularity shell&#8221;.<br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp; singularity shell \n<\/pre><br \/>\nIf you downloaded the Super Computing Wales container, you can now get a shell inside it by running:<br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp; singularity shell SupercomputingWales-singularity_hub-master-base_image.simg \n<\/pre><\/p>\n<h2><span id=\"Running_the_container.27s_default_actions\" class=\"mw-headline\"> Running the container&#8217;s default actions <\/span><\/h2>\n<p>Most containers specify a default command which they will run. The &#8220;singularity run&#8221; command will execute this.<br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp; singularity run \n<\/pre><\/p>\n<h2><span id=\"Accessing_the_host_file_system_from_inside_the_container\" class=\"mw-headline\"> Accessing the host file system from inside the container <\/span><\/h2>\n<p>You can mount paths from outside the container inside it. \/tmp, \/home, \/scratch and \/apps are already mounted.<br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp; singularity shell -B \/:\/ \n<\/pre><br \/>\nThis will mount a directory from the host inside the container. The container will only be able to access any files which the user running it has permissions for.<\/p>\n<h2><span id=\"Writing_your_own_containers\" class=\"mw-headline\"> Writing your own containers <\/span><\/h2>\n<p>To make your own containers you&#8217;ll probably have to install singularity on your own computer, as building a container typically requires root access.<\/p>\n<p>This example takes an ubuntu 16.04 image as a base, then installs the program cowsay. This is done when the container is built. When the container is run it executes cowsay with the arguments given on the command line.<br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp; bootstrap: docker\n&nbsp;&nbsp; From:ubuntu:16.04\n<\/pre><br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp;\u00a0%help\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Example container for Cowsay\n<\/pre><br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp;\u00a0%labels\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAINTAINER Super Computing Wales\n<\/pre><br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp;\u00a0%environment\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #configure our locale, without this we&#039;ll get locale errors\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; export LC_ALL=C\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #cowsay installs to \/usr\/games, but this isn&#039;t in the path by default\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; export PATH=\/usr\/games:$PATH\n&nbsp;&nbsp; \n&nbsp;&nbsp;\u00a0%post&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; apt-get update\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; apt-get -y install cowsay\n<\/pre><br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp;\u00a0%runscript\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cowsay $@\n<\/pre><br \/>\nTo build the container save the above example in a file called Singularity and run:<br \/>\n<pre class=\"preserve-code-formatting\">&nbsp;&nbsp;&nbsp;&nbsp;sudo singularity build cowsay.simg Singularity\n<\/pre><br \/>\nThis will create an image file called cowsay.simg containing all the required software to run cowsay in an Ubuntu 16.04 operating system. You can now copy this image file to Super Computing Wales and run it on an HPC.<\/p>\n<h2><\/h2>\n<h2><span id=\"Publishing_a_Container\" class=\"mw-headline\"> Publishing a Container <\/span><\/h2>\n<ul>\n<li>Publish the Singularity file on Github.<\/li>\n<li>Create an account on Singularity Hub.<\/li>\n<li>Add this repository to Singularity Hub and it will be automatically built by singularity hub and made available for download using the singularity pull command.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Using Containers with GPU applications<\/h2>\n<p>Singularity can use the system&#8217;s NVidia libraries by running with the in &#8220;&#8211;nv&#8221; option, this means you don&#8217;t need to install the NVidia libraries inside the container.<\/p>\n<h3>Building GPU containers<\/h3>\n<p>In order to compile software when building the container you will need to install some libraries. We will need to know which hardware version we are going to target. On Super Computing Wales the GPU hardware is version 396.37, this can be found by running the command &#8220;nvidia-smi&#8221; on a GPU node. The system building the container does not need to have its own GPU.<br \/>\n<pre class=\"preserve-code-formatting\">$ nvidia-smi\n\n+-----------------------------------------------------------------------------+\n| NVIDIA-SMI 396.37 Driver Version: 396.37 |\n|-------------------------------+----------------------+----------------------+\n| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n| Fan Temp Perf Pwr:Usage\/Cap| Memory-Usage | GPU-Util Compute M. |\n|===============================+======================+======================|\n| 0 Tesla V100-PCIE... On | 00000000:3B:00.0 Off | 0 |\n| N\/A 35C P0 25W \/ 250W | 0MiB \/ 16160MiB | 0% Default |\n+-------------------------------+----------------------+----------------------+\n| 1 Tesla V100-PCIE... On | 00000000:D8:00.0 Off | 0 |\n| N\/A 37C P0 27W \/ 250W | 0MiB \/ 16160MiB | 0% Default |\n+-------------------------------+----------------------+----------------------+\n\n+-----------------------------------------------------------------------------+\n| Processes: GPU Memory |\n| GPU PID Type Process name Usage |\n|=============================================================================|\n| No running processes found |<\/pre><br \/>\nThe NVidia docker image (nvidia\/cuda:9.0-devel) pre-supplies the Cuda libraries, these will need to match what is installed on the host system. Super Computing Wales has Cuda versions 8.0, 9.0, 9.1 and 9.2 installed. We need to manually install the version of libcuda1 which matches our hardware version, in our case this will be libcuda1-396. We can build versions of our program for other hardware versions if we require portability to other systems with different GPU hardware. Unfortunately these complications do make GPU applications less portable than their CPU only counterparts.<br \/>\n<pre class=\"preserve-code-formatting\">Bootstrap: docker\nFrom: nvidia\/cuda:9.0-devel\n\n%post\n&nbsp;&nbsp;&nbsp;&nbsp;mkdir \/usr\/lib\/nvidia\n&nbsp;&nbsp;&nbsp;&nbsp;apt-get -y install libcuda1-396\n&nbsp;&nbsp;&nbsp;&nbsp;.\n&nbsp;&nbsp;&nbsp;&nbsp;.\n&nbsp;&nbsp;&nbsp;&nbsp;.\n&nbsp;&nbsp;&nbsp;&nbsp;apt-get -y purge libcuda1-396<\/pre><\/p>\n<h3>Running GPU containers<\/h3>\n<p>The container needs to be run with the &#8211;nv option, this will use the system&#8217;s Cuda libraries and GPU configuration.<br \/>\n<pre class=\"preserve-code-formatting\">singularity run --nv<\/pre><\/p>\n<h2><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>What is Singularity Singularity [1] is a container system that doesn&#8217;t need root access. Containers are a set of applications and a minimal operating system bundled together in a single file. They are a good way to ensure that anyone running the software is using the exact same set of libraries and dependencies. This is [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"class_list":["post-797","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/comments?post=797"}],"version-history":[{"count":15,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/797\/revisions"}],"predecessor-version":[{"id":898,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/797\/revisions\/898"}],"wp:attachment":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/media?parent=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}