SingularityをGraviton2(Arm)インスタンスで実行する環境構築

HPC環境でGraviton2を積極的に使っていきたいので地道な検証から
2021.01.28

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

AWSが設計開発したGraviton2(Arm)のインスタンスでSingularity実行環境を構築します。

SingularityはHPC環境向けのコンテナ技術です。最終的にはHPC on AWS環境(AWS ParallelCluster)Graviton2インスタンスと、Singularityを利用した環境構築を目標に検証を進めます。

SingularityはArmでも動くイメージがあることは下記の記事を読んでわかりました。しかし、 Graviton2 でも実行できるのか、環境構築は容易なのか情報は見当たりませんでした。なので、やってみました。

Singularity in HPC - HPC blog - High Performance Computing - Arm Community

検証環境

項目
Architecture Arm(Graviton2)
InstanceType t4g.small
OS Ubuntu 20.04 LTS
AMI ubuntu-focal-20.04-arm64-server-20201026
Go version 1.15.7
Singularity version 3.7.1

まず必要なものをインストール

Singularityのドキュメントにそって進めていきます。

Quick Start — Singularity User Guide 3.7 documentation

sudo apt-get update && sudo apt-get install -y \
    build-essential \
    uuid-dev \
    libgpgme-dev \
    squashfs-tools \
    libseccomp-dev \
    wget \
    pkg-config \
    git \
    cryptsetup-bin

Goインストール

Singularityの実行にはGoが必要です。Arm版のGoをと思ったのですが2バージョンありました。

調べるとGraviton2は Arm v8.2準拠 していることがわかりました。

GoのDownloadページから ARMv8版 をダウンロードします。

wget https://golang.org/dl/go1.15.7.linux-arm64.tar.gz
sudo tar -C /usr/local/ -xzvf go1.15.7.linux-arm64.tar.gz
mkdir ~/go
echo 'export GOPATH=${HOME}/go' >> ~/.bashrc && \
    echo 'export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin' >> ~/.bashrc && \
    source ~/.bashrc

インストール結果

$ go version
go version go1.15.7 linux/arm64

$ env |grep GOPATH
GOPATH=/home/ubuntu/go

実行テスト

test.go

package main

import(
    "fmt"
)

func main(){
    fmt.Println("Hello, Abashiri")
}

実行できているのでARMv8版のファイルで間違いありませんでした。

$ go run test.go
Hello, Abashiri

Singularityインストール

Singularityの最新バージョンを確認します。現時点で最新のv3.7.1を利用します。

Releases · hpcng/singularity

Singularityのリポジトリをクローン。

git clone https://github.com/hpcng/singularity.git && \
    cd singularity && \
    git checkout v3.7.1

ビルドします。

./mconfig && \
    make -C ./builddir && \
    sudo make -C ./builddir install

bashの補完を効くようにしておきます。

. /usr/local/etc/bash_completion.d/singularity

インストール結果

$ singularity version
3.7.1

実行テスト

Cloud Libraryからalpineのイメージを利用できるかテストしてみます。

Sylabs Cloud

alpineのバージョンが表示されました。無事実行できていますね。

$ singularity exec library://alpine cat /etc/alpine-release
INFO:    Downloading library image
2.6MiB / 2.6MiB [==============================================================================] 100 % 142.3 MiB/s 0s
3.11.5

今度はDocker Hubのhello-worldイメージを実行してみます。

hello-world - Docker Hub

Docker Hubのイメージもpullして問題なく実行できています。Graviton2でもSingularityの動作確認はできました。

$ singularity run docker://hello-world
INFO:    Converting OCI blobs to SIF format
INFO:    Starting build...
Getting image source signatures
Copying blob 256ab8fe8778 done
Copying config 437ef303b8 done
Writing manifest to image destination
Storing signatures
2021/01/27 13:31:21  info unpack layer: sha256:256ab8fe877846964b72aa04e4c172a0de763addcb1c490c3fa1f7d56636cdb9
INFO:    Creating SIF file...
WARNING: passwd file doesn't exist in container, not updating
WARNING: group file doesn't exist in container, not updating

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

おわりに

Graviton2のインスタンスでも実行環境構築はすんなりできました。ソースからビルドできなくてハマるのだろうと思いながら始めたのですがつまづく箇所はありませんでした。それと、Armのバージョンを意識したことなかったのでよい学びの機会でした。次回の検証はコンテナ動かしてなにか演算させる予定です。

参考

Quick Start — Singularity User Guide 3.7 documentation