Ubuntu 18.04 LTSにSingularityをインストールして、NGCコンテナーのTensorFlowを使ってみるまでの手順を詳しく解説します。

  1. 準備
  2. NVIDIA Driverのインストール
  3. go 言語のインストール
  4. Singularity のインストール
  5. NGC コンテナーの TensorFlow を Singularity で pull する
  6. pull した NGC コンテナーを singularity で実行する

1.準備

Ubuntu 18.04 LTS Desktopはすでにインストールされているものとします。
最初にインターネットに接続できるようにネットワークを設定します。その後OSを最新の状態にアップデートします

sudo apt update
sudo apt upgrade -y 

sshで別のPCから作業する場合は、

sudo apt install -y openssh-server 

でsshサーバーをインストールします。
Desktopで作業している場合はTerminalを開き、他のPCで作業の場合はssh -Y ユーザーID@IPアドレス でログインします。
現在のOSの情報は cat /etc/os-release で表示することができます。

dl@dl-machine:~$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
dl@dl-machine:~$ 

2.NVIDIA Driverのインストール

NVIDIA Driverをインストールする方法はいろいろ紹介されていますが、runファイルでインストールする方法はお勧めできません。これからお勧めする方法に比べて不要な手順が必要で、ステップ数も大きいからです。最も簡単でアップデートも apt upgrade だけやれば完了するやり方は、CUDA の CUDA Driver だけをインストールする方法です。どなたでも間違い無く実行可能で失敗することはあり得ません。ここではそれを行います。
firefox & でfirefoxを立ち上げて cuda download を検索します。
cuda download search result
上図検索結果の 一番上の CUDA Toolkit 10.2 Download | NVIDIA Developer をクリックします。
cuda toolkit download
上図の Select Target Platform 中の Linux をクリックします。
cuda toolkit download linux
出てきた上図の Architecture の下の x86_64 をクリックします。
cuda toolkit download linux
その下に出てきた上図の Distribution の下の Ubuntu をクリックします。
cuda toolkit download linux
その下に出てきた Versionの下の 18.04 をクリックします。
cuda toolkit download linux
その下に出てきた Installer Type 下の deb (network) をクリックします。
cuda toolkit download linux
するとその下に Installation Instructions: が表示されますので、それを最後の行を除いて実行していきます。

dl@dl-machine:~$ dl@dl-machine:~$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
--2020-08-02 11:27:16--  https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
developer.download.nvidia.com (developer.download.nvidia.com) をDNSに問いあわせています... 152.199.39.144
developer.download.nvidia.com (developer.download.nvidia.com)|152.199.39.144|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 190 [application/octet-stream]
`cuda-ubuntu1804.pin' に保存中

cuda-ubuntu1804.pin                          100%[=============================================================================================>]     190  --.-KB/s    時間 0s    

2020-08-02 11:27:16 (1.76 MB/s) - `cuda-ubuntu1804.pin' へ保存完了 [190/190]

dl@dl-machine:~$ dl@dl-machine:~$ sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
[sudo] dl のパスワード: 
dl@dl-machine:~$ sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
無視:1 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  InRelease
取得:2 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  Release [697 B] 
取得:3 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  Release.gpg [836 B]                          
ヒット:4 http://jp.archive.ubuntu.com/ubuntu bionic InRelease                                                                      
取得:5 http://jp.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]                                                
取得:6 http://jp.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]                                                       
無視:7 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  Packages                                            
取得:7 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  Packages [232 kB]
取得:8 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [1,032 kB]   
取得:9 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                                               
取得:10 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [723 kB]                                 
取得:11 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 DEP-11 Metadata [295 kB]
取得:12 http://jp.archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,027 kB]        
取得:13 http://jp.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,097 kB]         
取得:14 http://jp.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [279 kB]
取得:15 http://jp.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
取得:16 http://jp.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 DEP-11 Metadata [9,292 B]
4,950 kB を 2秒 で取得しました (2,441 kB/s)                           
パッケージリストを読み込んでいます... 完了
dl@dl-machine:~$ sudo apt-get update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu bionic InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu bionic-updates InRelease                                                                                      
ヒット:3 http://jp.archive.ubuntu.com/ubuntu bionic-backports InRelease                                                                                    
無視:4 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  InRelease                                  
ヒット:5 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  Release                                  
取得:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                    
88.7 kB を 1秒 で取得しました (87.8 kB/s)                     
パッケージリストを読み込んでいます... 完了
dl@dl-machine:~$  

CUDA全部をインストールするのではなく、ドライバーだけをインストールします。

dl@dl-machine:~$ sudo apt install cuda-drivers
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  build-essential cuda-drivers-450 dkms dpkg-dev fakeroot g++ g++-7 gcc gcc-7 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1
  libc-dev-bin libc6-dev libcilkrts5 libfakeroot libgcc-7-dev libitm1 liblsan0 libmpx2 libnvidia-cfg1-450 libnvidia-common-450 libnvidia-compute-450 libnvidia-decode-450
  libnvidia-encode-450 libnvidia-extra-450 libnvidia-fbc1-450 libnvidia-gl-450 libnvidia-ifr1-450 libopengl0 libquadmath0 libstdc++-7-dev libtsan0 libubsan0 libvdpau1
  libxnvctrl0 linux-libc-dev make manpages-dev mesa-vdpau-drivers nvidia-compute-utils-450 nvidia-dkms-450 nvidia-driver-450 nvidia-kernel-common-450 nvidia-kernel-source-450
  nvidia-modprobe nvidia-prime nvidia-settings nvidia-utils-450 pkg-config screen-resolution-extra vdpau-driver-all xserver-xorg-video-nvidia-450
提案パッケージ:
  menu debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg gcc-multilib autoconf automake libtool flex bison gcc-doc gcc-7-multilib gcc-7-locales libgcc1-dbg
  libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg glibc-doc libstdc++-7-doc make-doc
  libvdpau-va-gl1 nvidia-vdpau-driver nvidia-legacy-340xx-vdpau-driver
推奨パッケージ:
  libnvidia-compute-450:i386 libnvidia-decode-450:i386 libnvidia-encode-450:i386 libnvidia-ifr1-450:i386 libnvidia-fbc1-450:i386 libnvidia-gl-450:i386
以下のパッケージが新たにインストールされます:
  build-essential cuda-drivers cuda-drivers-450 dkms dpkg-dev fakeroot g++ g++-7 gcc gcc-7 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4
  libatomic1 libc-dev-bin libc6-dev libcilkrts5 libfakeroot libgcc-7-dev libitm1 liblsan0 libmpx2 libnvidia-cfg1-450 libnvidia-common-450 libnvidia-compute-450
  libnvidia-decode-450 libnvidia-encode-450 libnvidia-extra-450 libnvidia-fbc1-450 libnvidia-gl-450 libnvidia-ifr1-450 libopengl0 libquadmath0 libstdc++-7-dev libtsan0 libubsan0
  libvdpau1 libxnvctrl0 linux-libc-dev make manpages-dev mesa-vdpau-drivers nvidia-compute-utils-450 nvidia-dkms-450 nvidia-driver-450 nvidia-kernel-common-450
  nvidia-kernel-source-450 nvidia-modprobe nvidia-prime nvidia-settings nvidia-utils-450 pkg-config screen-resolution-extra vdpau-driver-all xserver-xorg-video-nvidia-450
アップグレード: 0 個、新規インストール: 56 個、削除: 0 個、保留: 0 個。
132 MB のアーカイブを取得する必要があります。
この操作後に追加で 545 MB のディスク容量が消費されます。
続行しますか? [Y/n] y
 *** 以下省略 *** 
dl@dl-machine:~$ 

リブートしてドライバーを有効にします。 nvidia-smi を実行してGPUが認識されるか確認します。

dl@dl-machine:~$ nvidia-smi
Sun Aug  2 11:47:56 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.51.06    Driver Version: 450.51.06    CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    On   | 00000000:01:00.0  On |                  N/A |
| N/A   52C    P8    10W /  N/A |    186MiB /  8117MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1013      G   /usr/lib/xorg/Xorg                114MiB |
|    0   N/A  N/A      1256      G   /usr/bin/gnome-shell               68MiB |
+-----------------------------------------------------------------------------+
dl@dl-machine:~$ 

3.go 言語のインストール

firefox & で firefox を立ち上げて、https://golang.org/dl/ にアクセスします。
cuda toolkit download linux
表示された画面の Featured downloads の下の Linux をクリックします。
cuda toolkit download linux
小さなウインドウに「このファイルをどのように処理するか選んでください」と表示されますので「ファイルを保存する 」をクリックします。
cuda toolkit download linux
小さなウインドウ右下の「OK]をクリックします。
cuda toolkit download linux
小さなウインドウ右下の「OK]をクリックします。
少し待つとダウンロードが終わりますので、/usr/localの下に展開します。

dl@dl-machine:~$ sudo tar -C /usr/local -xzf ~/Downloads/go1.14.6.linux-amd64.tar.gz 
[sudo] dl のパスワード: 
dl@dl-machine:~$ ls /usr/local
bin  etc  games  go  include  lib  man  sbin  share  src
dl@dl-machine:~$ 

/usr/local の下に go というディレクトリができているのがわかります。
全てのユーザーが go を使えるように、/etc/profile の PATH に /usr/local/go/bin を加えます。

dl@dl-machine:~$ echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee -a /etc/profile
export PATH=$PATH:/usr/local/go/bin
dl@dl-machine:~$ cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "${PS1-}" ]; then
  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
export PATH=$PATH:/usr/local/go/bin
dl@dl-machine:~$ 

変更を有効にするために source コマンドで /etc/profile を読み込みます。

dl@dl-machine:~$ source /etc/profile
dl@dl-machine:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin
dl@dl-machine:~$ 

PATH に /usr/local/go/bin が加わっているのがわかります。go version とすると go のバージョンが表示されます。

dl@dl-machine:~$  go version
go version go1.14.6 linux/amd64
dl@dl-machine:~$ 

4.Singularity のインストール

必要なライブラリをインストールします。

dl@dl-machine:~$ sudo apt-get update && sudo apt-get install -y \
     build-essential \
     libssl-dev \
     uuid-dev \
     libgpgme11-dev \
     squashfs-tools \
     libseccomp-dev \
     pkg-config
ヒット:1 http://jp.archive.ubuntu.com/ubuntu bionic InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu bionic-updates InRelease                                                                                             
ヒット:3 http://jp.archive.ubuntu.com/ubuntu bionic-backports InRelease                                                                                           
無視:4 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  InRelease                                         
ヒット:5 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  Release               
取得:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                    
取得:8 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [46.0 kB]
取得:9 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 Metadata [49.2 kB]
取得:10 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B]
186 kB を 2秒 で取得しました (105 kB/s)        
パッケージリストを読み込んでいます... 完了
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
注意、'libgpgme11-dev' の代わりに 'libgpgme-dev' を選択します
build-essential はすでに最新バージョン (12.4ubuntu1) です。
build-essential は手動でインストールしたと設定されました。
pkg-config はすでに最新バージョン (0.29.1-0ubuntu2) です。
pkg-config は手動でインストールしたと設定されました。
squashfs-tools はすでに最新バージョン (1:4.3-6ubuntu0.18.04.1) です。
squashfs-tools は手動でインストールしたと設定されました。
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libegl1-mesa libfwup1 libllvm9 libwayland-egl1-mesa
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  libassuan-dev libgpg-error-dev
提案パッケージ:
  seccomp libssl-doc
以下のパッケージが新たにインストールされます:
  libassuan-dev libgpg-error-dev libgpgme-dev libseccomp-dev libssl-dev uuid-dev
アップグレード: 0 個、新規インストール: 6 個、削除: 0 個、保留: 0 個。
2,158 kB のアーカイブを取得する必要があります。
この操作後に追加で 10.3 MB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com/ubuntu bionic/main amd64 libassuan-dev amd64 2.5.1-2 [92.1 kB]
取得:2 http://jp.archive.ubuntu.com/ubuntu bionic/main amd64 libgpg-error-dev amd64 1.27-6 [94.8 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libseccomp-dev amd64 2.4.3-1ubuntu3.18.04.3 [65.7 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl-dev amd64 1.1.1-1ubuntu2.1~18.04.6 [1,566 kB]
取得:5 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libgpgme-dev amd64 1.10.0-1ubuntu2 [306 kB]
取得:6 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 uuid-dev amd64 2.31.1-0.4ubuntu3.6 [33.2 kB]
2,158 kB を 1秒 で取得しました (4,204 kB/s)
以前に未選択のパッケージ libassuan-dev を選択しています。
(データベースを読み込んでいます ... 現在 175195 個のファイルとディレクトリがインストールされています。)
.../0-libassuan-dev_2.5.1-2_amd64.deb を展開する準備をしています ...
libassuan-dev (2.5.1-2) を展開しています...
以前に未選択のパッケージ libgpg-error-dev を選択しています。
.../1-libgpg-error-dev_1.27-6_amd64.deb を展開する準備をしています ...
libgpg-error-dev (1.27-6) を展開しています...
以前に未選択のパッケージ libseccomp-dev:amd64 を選択しています。
.../2-libseccomp-dev_2.4.3-1ubuntu3.18.04.3_amd64.deb を展開する準備をしています ...
libseccomp-dev:amd64 (2.4.3-1ubuntu3.18.04.3) を展開しています...
以前に未選択のパッケージ libssl-dev:amd64 を選択しています。
.../3-libssl-dev_1.1.1-1ubuntu2.1~18.04.6_amd64.deb を展開する準備をしています ...
libssl-dev:amd64 (1.1.1-1ubuntu2.1~18.04.6) を展開しています...
以前に未選択のパッケージ libgpgme-dev を選択しています。
.../4-libgpgme-dev_1.10.0-1ubuntu2_amd64.deb を展開する準備をしています ...
libgpgme-dev (1.10.0-1ubuntu2) を展開しています...
以前に未選択のパッケージ uuid-dev:amd64 を選択しています。
.../5-uuid-dev_2.31.1-0.4ubuntu3.6_amd64.deb を展開する準備をしています ...
uuid-dev:amd64 (2.31.1-0.4ubuntu3.6) を展開しています...
libssl-dev:amd64 (1.1.1-1ubuntu2.1~18.04.6) を設定しています ...
libgpg-error-dev (1.27-6) を設定しています ...
libseccomp-dev:amd64 (2.4.3-1ubuntu3.18.04.3) を設定しています ...
uuid-dev:amd64 (2.31.1-0.4ubuntu3.6) を設定しています ...
libassuan-dev (2.5.1-2) を設定しています ...
libgpgme-dev (1.10.0-1ubuntu2) を設定しています ...
man-db (2.8.3-2ubuntu0.1) のトリガを処理しています ...
install-info (6.5.0.dfsg.1-2) のトリガを処理しています ...
dl@dl-machine:~$ 

~/Downloads の下に singularity を git clone して安定版の v3.6.0 に checkout します。

dl@dl-machine:~$ cd Downloads/ 
dl@dl-machine:~/Downloads$ git clone https://github.com/sylabs/singularity.git && \
     cd singularity && \
     git checkout v3.6.0
Cloning into 'singularity'...
remote: Enumerating objects: 66, done.
remote: Counting objects: 100% (66/66), done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 91480 (delta 22), reused 27 (delta 8), pack-reused 91414
Receiving objects: 100% (91480/91480), 29.24 MiB | 5.34 MiB/s, done.
Resolving deltas: 100% (58469/58469), done.
Note: checking out 'v3.6.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b 

HEAD is now at e45d2237b Merge pull request #5425 from dctrud/3.6.0-integrity-merge
dl@dl-machine:~/Downloads/singularity$ 

./mconfig を実行します。

dl@dl-machine:~/Downloads/singularity$ ./mconfig
Configuring for project `singularity' with languages: C, Golang
=> running pre-basechecks project specific checks ...
=> running base system checks ...
 checking: host C compiler... cc
 checking: host C++ compiler... c++
 checking: host Go compiler (at least version 1.13)... /usr/local/go/bin/go
 checking: host C compiler option -Wall... yes
 checking: host C compiler option -Werror... yes
 checking: host C compiler option -Wfatal-errors... yes
 checking: host C compiler option -Wno-unknown-warning-option... yes
 checking: host C compiler option -Wstrict-prototypes... yes
 checking: host C compiler option -Wpointer-arith... yes
 checking: host C compiler option -Wbad-function-cast... yes
 checking: host C compiler option -Woverlength-strings... yes
 checking: host C compiler option -Wframe-larger-than=2047... yes
 checking: host C compiler option -Wno-sign-compare... yes
 checking: host C compiler option -Wclobbered... yes
 checking: host C compiler option -Wempty-body... yes
 checking: host C compiler option -Wmissing-parameter-type... yes
 checking: host C compiler option -Wtype-limits... yes
 checking: host C compiler option -Wunused-parameter... yes
 checking: host C compiler option -Wunused-but-set-parameter... yes
 checking: host C compiler option -Wno-discarded-qualifiers... yes
 checking: host C compiler option -Wno-incompatible-pointer-types... yes
 checking: host C compiler option -pipe... yes
 checking: host C compiler option -fmessage-length=0... yes
 checking: host C compiler option -fPIC... yes
 checking: host `ar' path... ar
 checking: host `ld' path... ld
 checking: host `ranlib' path... ranlib
 checking: host `objcopy' path... objcopy
 checking: target C compiler... cc
 checking: target C++ compiler... c++
 checking: target `ar' path... ar
 checking: target `ld' path... ld
 checking: target `ranlib' path... ranlib
 checking: target `objcopy' path... objcopy
 checking: host compiles static binaries... yes
 checking: target compiles static binaries... yes
 checking: host os type... unix
 checking: host architecture... x86_64
 checking: target architecture... x86_64
 checking: host architecture word size... 64
 checking: target architecture word size... 64
 checking: project version... 3.6.0
 checking: project short version... 3.6.0
=> running post-basechecks project specific checks ...
 checking: namespace: CLONE_NEWPID... yes
 checking: namespace: CLONE_FS... yes
 checking: namespace: CLONE_NEWNS... yes
 checking: namespace: CLONE_NEWUSER... yes
 checking: namespace: CLONE_NEWIPC... yes
 checking: namespace: CLONE_NEWNET... yes
 checking: namespace: CLONE_NEWUTS... yes
 checking: namespace: CLONE_NEWCGROUP... yes
 checking: feature: NO_NEW_PRIVS... yes
 checking: feature: MS_SLAVE... yes
 checking: feature: MS_REC... yes
 checking: feature: MS_PRIVATE... yes
 checking: user capabilities... yes
 checking: header linux/securebits.h... yes
 checking: header linux/capability.h... yes
 checking: libseccomp+headers... yes
 checking: cryptsetup... no

unable to find the cryptsetup program, is the package cryptsetup-bin installed?

=> generating fragments ...
=> building Makefile ...
=> generating singularity.spec ...
=> project singularity setup with :
    - host arch: x86_64
    - host wordsize: 64-bit
    - host C compiler: cc
    - host Go compiler: /usr/local/go/bin/go
    - host system: unix
      ---
    - target arch: x86_64
    - target wordsize: 64-bit
    - target C compiler: cc
      ---
    - config profile: release
      ---
    - SUID install: yes
    - Network plugins: yes
      ---
    - verbose: no
      ---
    - cryptsetup: 
      ---
    - version: 3.6.0
=> /home/dl/Downloads/singularity/builddir/Makefile ready, try:
   $ cd /home/dl/Downloads/singularity/builddir
   $ make
dl@dl-machine:~/Downloads/singularity$  

cryptsetup がないと言われたのでインストールします。

dl@dl-machine:~/Downloads/singularity$ sudo apt install cryptsetup
[sudo] dl のパスワード: 
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libegl1-mesa libfwup1 libllvm9 libwayland-egl1-mesa
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  cryptsetup-bin
提案パッケージ:
  keyutils
以下のパッケージが新たにインストールされます:
  cryptsetup cryptsetup-bin
アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
244 kB のアーカイブを取得する必要があります。
この操作後に追加で 828 kB のディスク容量が消費されます。
続行しますか? [Y/n] y
取得:1 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 cryptsetup-bin amd64 2:2.0.2-1ubuntu1.1 [92.9 kB]
取得:2 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 cryptsetup amd64 2:2.0.2-1ubuntu1.1 [151 kB]
244 kB を 0秒 で取得しました (611 kB/s)
パッケージを事前設定しています ...
以前に未選択のパッケージ cryptsetup-bin を選択しています。
(データベースを読み込んでいます ... 現在 175418 個のファイルとディレクトリがインストールされています。)
.../cryptsetup-bin_2%3a2.0.2-1ubuntu1.1_amd64.deb を展開する準備をしています ...
cryptsetup-bin (2:2.0.2-1ubuntu1.1) を展開しています...
以前に未選択のパッケージ cryptsetup を選択しています。
.../cryptsetup_2%3a2.0.2-1ubuntu1.1_amd64.deb を展開する準備をしています ...
cryptsetup (2:2.0.2-1ubuntu1.1) を展開しています...
cryptsetup-bin (2:2.0.2-1ubuntu1.1) を設定しています ...
cryptsetup (2:2.0.2-1ubuntu1.1) を設定しています ...
update-initramfs: deferring update (trigger activated)
man-db (2.8.3-2ubuntu0.1) のトリガを処理しています ...
ureadahead (0.100.0-21) のトリガを処理しています ...
ureadahead will be reprofiled on next reboot
systemd (237-3ubuntu10.41) のトリガを処理しています ...
initramfs-tools (0.130ubuntu3.9) のトリガを処理しています ...
update-initramfs: Generating /boot/initrd.img-5.4.0-42-generic
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8125a-3.fw for module r8169
dl@dl-machine:~/Downloads/singularity$ 

再度 ./mconfig を実行します。

dl@dl-machine:~/Downloads/singularity$ ./mconfig
Configuring for project `singularity' with languages: C, Golang
=> running pre-basechecks project specific checks ...
=> running base system checks ...
 checking: host C compiler... cc
 checking: host C++ compiler... c++
 checking: host Go compiler (at least version 1.13)... /usr/local/go/bin/go
 checking: host C compiler option -Wall... yes
 checking: host C compiler option -Werror... yes
 checking: host C compiler option -Wfatal-errors... yes
 checking: host C compiler option -Wno-unknown-warning-option... yes
 checking: host C compiler option -Wstrict-prototypes... yes
 checking: host C compiler option -Wpointer-arith... yes
 checking: host C compiler option -Wbad-function-cast... yes
 checking: host C compiler option -Woverlength-strings... yes
 checking: host C compiler option -Wframe-larger-than=2047... yes
 checking: host C compiler option -Wno-sign-compare... yes
 checking: host C compiler option -Wclobbered... yes
 checking: host C compiler option -Wempty-body... yes
 checking: host C compiler option -Wmissing-parameter-type... yes
 checking: host C compiler option -Wtype-limits... yes
 checking: host C compiler option -Wunused-parameter... yes
 checking: host C compiler option -Wunused-but-set-parameter... yes
 checking: host C compiler option -Wno-discarded-qualifiers... yes
 checking: host C compiler option -Wno-incompatible-pointer-types... yes
 checking: host C compiler option -pipe... yes
 checking: host C compiler option -fmessage-length=0... yes
 checking: host C compiler option -fPIC... yes
 checking: host `ar' path... ar
 checking: host `ld' path... ld
 checking: host `ranlib' path... ranlib
 checking: host `objcopy' path... objcopy
 checking: target C compiler... cc
 checking: target C++ compiler... c++
 checking: target `ar' path... ar
 checking: target `ld' path... ld
 checking: target `ranlib' path... ranlib
 checking: target `objcopy' path... objcopy
 checking: host compiles static binaries... yes
 checking: target compiles static binaries... yes
 checking: host os type... unix
 checking: host architecture... x86_64
 checking: target architecture... x86_64
 checking: host architecture word size... 64
 checking: target architecture word size... 64
 checking: project version... 3.6.0
 checking: project short version... 3.6.0
=> running post-basechecks project specific checks ...
 checking: namespace: CLONE_NEWPID... yes
 checking: namespace: CLONE_FS... yes
 checking: namespace: CLONE_NEWNS... yes
 checking: namespace: CLONE_NEWUSER... yes
 checking: namespace: CLONE_NEWIPC... yes
 checking: namespace: CLONE_NEWNET... yes
 checking: namespace: CLONE_NEWUTS... yes
 checking: namespace: CLONE_NEWCGROUP... yes
 checking: feature: NO_NEW_PRIVS... yes
 checking: feature: MS_SLAVE... yes
 checking: feature: MS_REC... yes
 checking: feature: MS_PRIVATE... yes
 checking: user capabilities... yes
 checking: header linux/securebits.h... yes
 checking: header linux/capability.h... yes
 checking: libseccomp+headers... yes
 checking: cryptsetup... yes
=> generating fragments ...
=> building Makefile ...
=> generating singularity.spec ...
=> project singularity setup with :
    - host arch: x86_64
    - host wordsize: 64-bit
    - host C compiler: cc
    - host Go compiler: /usr/local/go/bin/go
    - host system: unix
      ---
    - target arch: x86_64
    - target wordsize: 64-bit
    - target C compiler: cc
      ---
    - config profile: release
      ---
    - SUID install: yes
    - Network plugins: yes
      ---
    - verbose: no
      ---
    - cryptsetup: /sbin/cryptsetup
      ---
    - version: 3.6.0
=> /home/dl/Downloads/singularity/builddir/Makefile ready, try:
   $ cd /home/dl/Downloads/singularity/builddir
   $ make
dl@dl-machine:~/Downloads/singularity$ 

./mconfig が正常終了したので make -C ./builddir を実行します。

dl@dl-machine:~/Downloads/singularity$ make -C ./builddir/
make: ディレクトリ '/home/dl/Downloads/singularity/builddir' に入ります
 GEN GO DEP /home/dl/Downloads/singularity/builddir/starter.d
 GEN GO DEP /home/dl/Downloads/singularity/builddir/singularity.d
 GEN /home/dl/Downloads/singularity/scripts/go-generate
 GO singularity
    [+] GO_TAGS "containers_image_openpgp sylog oci_engine singularity_engine fakeroot_engine apparmor selinux seccomp"
 GEN etc/bash_completion.d/singularity
 GEN singularity.conf from /usr/local/etc/singularity/singularity.conf
 CNI PLUGIN dhcp
 CNI PLUGIN host-local
 CNI PLUGIN static
 CNI PLUGIN bridge
 CNI PLUGIN host-device
 CNI PLUGIN ipvlan
 CNI PLUGIN loopback
 CNI PLUGIN macvlan
 CNI PLUGIN ptp
 CNI PLUGIN vlan
 CNI PLUGIN bandwidth
 CNI PLUGIN firewall
 CNI PLUGIN flannel
 CNI PLUGIN portmap
 CNI PLUGIN tuning
 GO clean -cache
 GO cmd/starter/c/starter
 GO cmd/starter/c/starter-suid
    [+] GO_TAGS "containers_image_openpgp sylog singularity_engine fakeroot_engine apparmor selinux seccomp"
 GEN /home/dl/Downloads/singularity/scripts/go-test
make: ディレクトリ '/home/dl/Downloads/singularity/builddir' から出ます
dl@dl-machine:~/Downloads/singularity$

正常終了したので sudo make -C ./builddir install を実行してインストールします。

dl@dl-machine:~/Downloads/singularity$ sudo make -C ./builddir/ install
[sudo] dl のパスワード: 
make: ディレクトリ '/home/dl/Downloads/singularity/builddir' に入ります
 INSTALL /usr/local/bin/singularity
 INSTALL /usr/local/etc/bash_completion.d/singularity
 INSTALL /usr/local/etc/singularity/singularity.conf
 INSTALL /usr/local/etc/singularity/remote.yaml
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/dhcp
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/host-local
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/static
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/bridge
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/host-device
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/ipvlan
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/loopback
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/macvlan
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/ptp
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/vlan
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/bandwidth
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/firewall
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/flannel
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/portmap
 INSTALL CNI PLUGIN /usr/local/libexec/singularity/cni/tuning
 INSTALL CNI CONFIGURATION FILES
 INSTALL /usr/local/libexec/singularity/bin/starter
 INSTALL /usr/local/var/singularity/mnt/session
 INSTALL /usr/local/bin/run-singularity
 INSTALL /usr/local/etc/singularity/capability.json
 INSTALL /usr/local/etc/singularity/ecl.toml
 INSTALL /usr/local/etc/singularity/seccomp-profiles/default.json
 INSTALL /usr/local/etc/singularity/nvliblist.conf
 INSTALL /usr/local/etc/singularity/rocmliblist.conf
 INSTALL /usr/local/etc/singularity/cgroups/cgroups.toml
 INSTALL SUID /usr/local/libexec/singularity/bin/starter-suid
 DONE
make: ディレクトリ '/home/dl/Downloads/singularity/builddir' から出ます
dl@dl-machine:~/Downloads/singularity$  

これで singularity がインストールされました。singularity version でバージョンを表示します。

dl@dl-machine:~/Downloads/singularity$ cd
dl@dl-machine:~$ singularity version
3.6.0
dl@dl-machine:~$  

5.NGC コンテナーの TensorFlow を Singularity で pull する

firefox を立ち上げて https://ngc.nvidia.com/catalog/containers/nvidia:tensorflow を表示させます。
cuda toolkit download
Pull Command の下の nvcr.io/nvidia/tensorflow:20.03-tf2-py3 から下記の singularity pull コマンドを実行します。

dl@dl-machine:~/singularity$ singularity pull docker://nvcr.io/nvidia/tensorflow:20.07-tf2-py3
INFO:    Converting OCI blobs to SIF format
INFO:    Starting build...
Getting image source signatures
Copying blob d7c3167c320d done  
Copying blob 131f805ec7fd done  
Copying blob 322ed380e680 done  
Copying blob 6ac240b13098 done  
Copying blob cad59db95b8e done  
Copying blob b367f8e513bc done  
Copying blob a1b269a23502 done  
Copying blob 467edc0fcc05 done  
Copying blob bedb81dc2c8c done  
Copying blob e1a915fe07b1 done  
Copying blob b96d0898b84a done  
Copying blob fe7b350f2d0e done  
Copying blob 305986deca84 done  
Copying blob aa98e1280eb7 done  
Copying blob 6ff3aa18e426 done  
Copying blob f046a125c279 done  
Copying blob b3e2aca49cf1 done  
Copying blob 82e2c3a9486b done  
Copying blob d8de35752e52 done  
Copying blob b6ed5eb0c9eb done  
Copying blob 0fef710f1eba done  
Copying blob 0da261e2cf7f done  
Copying blob bb42d29af85e done  
Copying blob 1d0bba0058e7 done  
Copying blob 9fc38200abab done  
Copying blob ee21729dc5f2 done  
Copying blob cc0370279fe0 done  
Copying blob c89fe6ab901b done  
Copying blob 59a22af69f1c done  
Copying blob f16a37308e9d done  
Copying blob 4d793692aeeb done  
Copying blob 49a44a4656f1 done  
Copying blob 26daa39fa1b6 done  
Copying blob a2dc24824bc8 done  
Copying blob b9938faad679 done  
Copying blob 19fc0f39d6e7 done  
Copying blob 66070365e0cc done  
Copying blob e4261136cb63 done  
Copying blob 1636f80974f4 done  
Copying blob d6488b05954a done  
Copying blob 3f2c80b2ea62 done  
Copying blob 5cb277230385 done  
Copying blob f2578e1cf703 done  
Copying blob 632ee0fa81b5 done  
Copying blob 50910439ce94 done  
Copying blob 305e649605cb done  
Copying blob 0e5d7314835d done  
Copying blob fbb827514f1d done  
Copying blob 874fae36f903 done  
Copying blob a65765e23da2 done  
Copying blob 93b452434014 done  
Copying blob 73a66fd786b4 done  
Copying blob a9986534c006 done  
Copying blob 866829b33d0b done  
Copying blob 4d801a17142b done  
Copying blob 052fed7172bc done  
Copying blob 98141c39ea15 done  
Copying blob 33302099a852 done  
Copying blob 0d7f42c058e0 done  
Copying blob 6873805da6f9 done  
Copying blob f2efc39c7835 done  
Copying blob f301aacefed0 done  
Copying config afe8cafe1e done  
Writing manifest to image destination
Storing signatures
2020/08/02 13:59:13  info unpack layer: sha256:d7c3167c320d7a820935f54cf4290890ea19567da496ecf774e8773b35d5f065
2020/08/02 13:59:13  info unpack layer: sha256:131f805ec7fd68d45a887e2ef82de61de0247b4eb934ab03b7c933650e854baa
2020/08/02 13:59:13  info unpack layer: sha256:322ed380e680a77f30528ba013e3a802a7b44948a0609c7d1d732dd46a9a310d
2020/08/02 13:59:13  info unpack layer: sha256:6ac240b130982ad1c3ba3188abbf18ba4e54bdd9e504ce2d5c2eff6d3e86b8dd
2020/08/02 13:59:13  info unpack layer: sha256:cad59db95b8e9a21af275b646b15b220341636871cb725456d1b0f4e4834f24d
2020/08/02 13:59:16  info unpack layer: sha256:b367f8e513bc588b5436bb6489da33270f0a5a0af0e4288826bae906e4605aad
2020/08/02 13:59:17  info unpack layer: sha256:a1b269a235020b83aeabaf22362fcb601947f0368e621e4a31e6632d77d19302
2020/08/02 13:59:17  info unpack layer: sha256:467edc0fcc05c018b173944439fbd445e74add9292ec9b2f5176f29975d9c098
2020/08/02 13:59:17  info unpack layer: sha256:bedb81dc2c8c32d1078cd70747a0f7fba16bf3e6e54dc23577894ca61ec2249e
2020/08/02 13:59:17  info unpack layer: sha256:e1a915fe07b16deb8e41508b45a0670ce1b90c4a23de156a2bfa47fd61b7deff
2020/08/02 13:59:17  info unpack layer: sha256:b96d0898b84ac8c25a0c7a128180e8be115880927b5eae85f9a75b062b2514dc
2020/08/02 13:59:17  info unpack layer: sha256:fe7b350f2d0ee446c5da9e6df9e2ed5c717829db6e934d8e72c689396ef6684f
2020/08/02 13:59:17  info unpack layer: sha256:305986deca842a853cf0c4329a092220b9c4919771ca7ec204565a711a9eca89
2020/08/02 13:59:17  info unpack layer: sha256:aa98e1280eb7c4a94135c12835184bd6b5e7668f71fc601057df8eeb026b0490
2020/08/02 13:59:17  info unpack layer: sha256:6ff3aa18e4263b736609f1edd91cddb8002c1a29dea2f3e0c63d3987bff7cfae
2020/08/02 13:59:55  info unpack layer: sha256:f046a125c2799550491184cc807914344c6c19bb6513a7122b88dc7eade18e8e
2020/08/02 13:59:55  info unpack layer: sha256:b3e2aca49cf1f6e4e609746ad00eddd92caed22658566c2adb84f5ca230e04d2
2020/08/02 13:59:55  info unpack layer: sha256:82e2c3a9486b157eae22c09c25b2d79476846b909cde8b3a37f7d0ea8abe33a4
2020/08/02 13:59:55  info unpack layer: sha256:d8de35752e524b1ca0635023e5e1a78aa7fee247729da1306a150832e1c38d37
2020/08/02 13:59:55  info unpack layer: sha256:b6ed5eb0c9eb418dd50b28ab16902c85d6def38ddd0d4b089a45b0828a517f59
2020/08/02 13:59:56  info unpack layer: sha256:0fef710f1eba13b58fae605bdd2e894bf38ede5384d00774ffb7b7ed9a51177e
2020/08/02 13:59:56  info unpack layer: sha256:0da261e2cf7f5de74435d9ee4273aaa5966e79968fe5cab3d57971d2ce2ff95c
2020/08/02 13:59:56  info unpack layer: sha256:bb42d29af85ef92824109d0055d97e54691de36ca8b037bf80f4252cd282fb66
2020/08/02 13:59:56  info unpack layer: sha256:1d0bba0058e7e23b6d4dde8c37f1cfba74b3fb27b5ff05118bb08c02297a5789
2020/08/02 13:59:57  info unpack layer: sha256:9fc38200abab06eca622d693b8cc5be78b25baa29fe31a1e73927998142a7ab1
2020/08/02 13:59:57  info unpack layer: sha256:ee21729dc5f22dfdf5a89066231e44555d52c30c4dc798a1ea080372d38ee9a3
2020/08/02 13:59:57  info unpack layer: sha256:cc0370279fe0f26e25f4fa0a08903dbcde8160a3950494bb8945789188fdd28a
2020/08/02 14:00:01  info unpack layer: sha256:c89fe6ab901bc06a0aa9148738a7f742d29ac94a4647c474d23188051bc4124b
2020/08/02 14:00:02  info unpack layer: sha256:59a22af69f1c2f3419f51ddfa95a2610a66a30acb5fbf3f3d9229d85840062a9
2020/08/02 14:00:02  info unpack layer: sha256:f16a37308e9d3f2586dccd936a9d11cebb8b3f7d57e62b795e5db94356495105
2020/08/02 14:00:02  info unpack layer: sha256:4d793692aeebbabd1f718f1db71cadb3736ae5119eb77b98ff09a04bb7acc267
2020/08/02 14:00:02  info unpack layer: sha256:49a44a4656f19f6168954f99a79ffa4a51cf34004d921e41d7e1b5b57aa090a7
2020/08/02 14:00:05  info unpack layer: sha256:26daa39fa1b6d85b92e199f4cfdc9bc4c80dbf29137ca48ba6e38b380bcbf181
2020/08/02 14:00:05  info unpack layer: sha256:a2dc24824bc8b3e060d18bee47b6e69b66fa9cddbf81e640258a3644d08c80d6
2020/08/02 14:00:06  info unpack layer: sha256:b9938faad6795bc1d386218c4004600703a0144314992e4413ed4ea2775fae18
2020/08/02 14:00:06  info unpack layer: sha256:19fc0f39d6e77e772866fedeb9383348c9804dd97dd42efc6532e6d73e5bedbf
2020/08/02 14:00:06  info unpack layer: sha256:66070365e0cc9e81738625d59481466dc61576a9afe2dbef5acba7a805ce2152
2020/08/02 14:00:06  info unpack layer: sha256:e4261136cb6331f1697e5800a7d04839e075c3368e7edfda2f3b23ab232e9c01
2020/08/02 14:00:06  info unpack layer: sha256:1636f80974f465fe0d93d57106a90714608adae36a6ad3eea2e0648e5e0ed6e9
2020/08/02 14:00:07  info unpack layer: sha256:d6488b05954a13006d2ea38cab1081a695adfd63297ecd644f3f03f0a7c62324
2020/08/02 14:00:08  warn rootless{usr/local/nvm/versions/node/v14.5.0/bin/npm} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:08  warn rootless{usr/local/nvm/versions/node/v14.5.0/bin/npx} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:08  warn rootless{usr/local/nvm/versions/node/v14.5.0/lib/node_modules/npm/node_modules/.bin/is-ci} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:08  warn rootless{usr/local/nvm/versions/node/v14.5.0/lib/node_modules/npm/node_modules/libnpx/node_modules/.bin/is-ci} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:08  warn rootless{usr/local/nvm/versions/node/v14.5.0/lib/node_modules/npm/node_modules/libnpx/node_modules/.bin/rc} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:08  warn rootless{usr/local/nvm/versions/node/v14.5.0/lib/node_modules/npm/node_modules/libnpx/node_modules/.bin/semver} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:09  warn rootless{usr/local/nvm/versions/node/v14.5.0/lib/node_modules/npm/node_modules/make-dir/node_modules/.bin/semver} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:09  warn rootless{usr/local/nvm/versions/node/v14.5.0/lib/node_modules/npm/node_modules/package-json/node_modules/.bin/semver} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:09  warn rootless{usr/local/nvm/versions/node/v14.5.0/lib/node_modules/npm/node_modules/semver-diff/node_modules/.bin/semver} ignoring (usually) harmless EPERM on setxattr "user.rootlesscontainers"
2020/08/02 14:00:11  info unpack layer: sha256:3f2c80b2ea62abd51eac2f456b24d2e4b04098da9b278e1f9b349309616283f2
2020/08/02 14:00:11  info unpack layer: sha256:5cb2772303854a5f8014aeb591d6bea46f22f2ff742e83cd1bcce81b0b72857c
2020/08/02 14:00:13  info unpack layer: sha256:f2578e1cf70305e34c81e96fd526c8104b7a70286d3a6940232c1e6c8cffdf97
2020/08/02 14:00:13  info unpack layer: sha256:632ee0fa81b5c0f1c6593731ede794b8c6cd322274828200c280d4b3eb5717e3
2020/08/02 14:00:13  info unpack layer: sha256:50910439ce942c7108e97c229204e727a3542c649317ad5b2fb26693a7e29ef6
2020/08/02 14:00:35  info unpack layer: sha256:305e649605cb80e29c19deb2700b18ed7c81c79245e380b239898f5feca2208d
2020/08/02 14:00:36  info unpack layer: sha256:0e5d7314835d75ee21f48f4bd18da4c62478d7bfc27d72e8c80a58c7d119de6f
2020/08/02 14:00:37  info unpack layer: sha256:fbb827514f1d052ac05e0600a59a49bf499c6d0423f342c25c502c1a98e7aec6
2020/08/02 14:00:44  info unpack layer: sha256:874fae36f903a6bd6a03d201adc23ade58bd0938951a68203d2d6bd5288da8f5
2020/08/02 14:00:45  info unpack layer: sha256:a65765e23da2a7395b7663498adce392fc885ccfd7d657efab85287a172d887d
2020/08/02 14:00:45  info unpack layer: sha256:93b4524340148950c70fc8d8b5eb2cf2f6166ed7268d18258b752b9ecf77543c
2020/08/02 14:00:45  info unpack layer: sha256:73a66fd786b49a70bc4767f78bf6f72c95708ed5e5124a272408a6a3f1064fc7
2020/08/02 14:00:46  info unpack layer: sha256:a9986534c0060ef688bb7510e1c969550954d57e0276d0515b0f74b70c02850e
2020/08/02 14:00:46  info unpack layer: sha256:866829b33d0bf3e2373ac9afff7ddae57613210adbd6bb3094fe695a434ffeb1
2020/08/02 14:00:46  info unpack layer: sha256:4d801a17142b0ffcc02cb230a76125afd5df68c66ef889027e1eda11a74f7be2
2020/08/02 14:00:46  info unpack layer: sha256:052fed7172bc7a0b1bd09566d409ff9209c3db32554c394567f3731fdd1c1a6b
2020/08/02 14:00:46  info unpack layer: sha256:98141c39ea1588ab6f7fde3a73c7aea4c9fd3e1abb1797015e8f25c692aa56c2
2020/08/02 14:00:46  info unpack layer: sha256:33302099a85220c4744a5fe9d9fe9c33f6dce6e07e5acf0cc5a17c8963a8adb8
2020/08/02 14:00:46  info unpack layer: sha256:0d7f42c058e0e30ef9fee4c164986f1f83f30f58ec694cf5064dab7793fccf1c
2020/08/02 14:00:46  info unpack layer: sha256:6873805da6f9443a74b1beacb44a45accdb2235ee57f33aaf499b48b8de671f4
2020/08/02 14:00:46  info unpack layer: sha256:f2efc39c7835c4902654c23294c91a7fd2ea50db194cb88e19399dc61535ab50
2020/08/02 14:00:46  info unpack layer: sha256:f301aacefed07b1f43617afd722472985882381be7d6280c17167a3e8530f2f3
INFO:    Creating SIF file...
dl@dl-machine:~/singularity$ 

すると singularity 用のコンテナーができます。

dl@dl-machine:~/singularity$ ls
tensorflow_20.07-tf2-py3.sif
dl@dl-machine:~/singularity$ 

6.pull した NGC コンテナーを singularity で実行する

firefox を立ち上げて https://www.tensorflow.org/tutorials/quickstart/beginner を表示させます。
cuda toolkit download
上記のサンプルコードを実行します。

dl@dl-machine:~/singularity$ singularity exec --nv tensorflow_20.07-tf2-py3.sif python
Usage example: change_mofed_version.sh 4.5-1.0.1
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import absolute_import, division, print_function, unicode_literals
>>> 
>>> # TensorFlow をインストール
... 
>>> import tensorflow as tf
2020-08-02 14:16:09.394253: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.11.0
>>> mnist = tf.keras.datasets.mnist
>>> 
>>> (x_train, y_train), (x_test, y_test) = mnist.load_data()
>>> x_train, x_test = x_train / 255.0, x_test / 255.0
>>> model = tf.keras.models.Sequential([
...   tf.keras.layers.Flatten(input_shape=(28, 28)),
...   tf.keras.layers.Dense(128, activation='relu'),
...   tf.keras.layers.Dropout(0.2),
...   tf.keras.layers.Dense(10, activation='softmax')
... ])
2020-08-02 14:16:30.154519: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcuda.so.1
2020-08-02 14:16:30.189731: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:30.190349: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1070 computeCapability: 6.1
coreClock: 1.645GHz coreCount: 16 deviceMemorySize: 7.93GiB deviceMemoryBandwidth: 238.66GiB/s
2020-08-02 14:16:30.190376: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.11.0
2020-08-02 14:16:30.222847: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.11
2020-08-02 14:16:30.239239: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcufft.so.10
2020-08-02 14:16:30.246858: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcurand.so.10
2020-08-02 14:16:30.276227: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusolver.so.10
2020-08-02 14:16:30.283660: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusparse.so.11
2020-08-02 14:16:30.285568: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.8
2020-08-02 14:16:30.285692: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:30.286509: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:30.287026: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-08-02 14:16:30.304719: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2599990000 Hz
2020-08-02 14:16:30.306197: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fbd90000b20 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-08-02 14:16:30.306219: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-08-02 14:16:30.404299: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:30.406203: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x57e1520 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-08-02 14:16:30.406222: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1070, Compute Capability 6.1
2020-08-02 14:16:30.408073: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:30.408488: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1070 computeCapability: 6.1
coreClock: 1.645GHz coreCount: 16 deviceMemorySize: 7.93GiB deviceMemoryBandwidth: 238.66GiB/s
2020-08-02 14:16:30.408516: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.11.0
2020-08-02 14:16:30.408536: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.11
2020-08-02 14:16:30.408550: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcufft.so.10
2020-08-02 14:16:30.408563: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcurand.so.10
2020-08-02 14:16:30.408575: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusolver.so.10
2020-08-02 14:16:30.408588: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusparse.so.11
2020-08-02 14:16:30.408600: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.8
2020-08-02 14:16:30.408660: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:30.409077: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:30.409445: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-08-02 14:16:30.411396: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.11.0
2020-08-02 14:16:33.109291: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-08-02 14:16:33.109324: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-08-02 14:16:33.109331: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-08-02 14:16:33.111843: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:33.112291: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-08-02 14:16:33.112741: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7268 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
>>> 
>>> model.compile(optimizer='adam',
...               loss='sparse_categorical_crossentropy',
...               metrics=['accuracy'])
>>> model.fit(x_train, y_train, epochs=5)
Epoch 1/5
2020-08-02 14:16:50.091115: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.11
1875/1875 [==============================] - 2s 1ms/step - loss: 0.2960 - accuracy: 0.9147
Epoch 2/5
1875/1875 [==============================] - 3s 1ms/step - loss: 0.1447 - accuracy: 0.9574
Epoch 3/5
1875/1875 [==============================] - 3s 1ms/step - loss: 0.1084 - accuracy: 0.9678
Epoch 4/5
1875/1875 [==============================] - 3s 1ms/step - loss: 0.0901 - accuracy: 0.9718
Epoch 5/5
1875/1875 [==============================] - 3s 1ms/step - loss: 0.0755 - accuracy: 0.9760

>>> 
>>> model.evaluate(x_test,  y_test, verbose=2)
313/313 - 0s - loss: 0.0795 - accuracy: 0.9753
[0.07946345955133438, 0.9753000140190125]
>>> exit()
dl@dl-machine:~/singularity$