Architecture agnostic singularity image files
Version of Singularity:
3.3.0
Expected behavior
When an sif or sandbox image is build on an architecture (say x86_64) it should run on arm/ppcle architecture without recompiling. This will help in maintaining one version of sif across all architecture rather then having platform/architecture dependent singularity image files
Actual behavior
Currently if we have to build or download image from docker repo for arm it has to be rebuild. https://github.com/sylabs/singularity/issues/2744
Docker have implemented a manifest file for multi-architecture build but they still have this open issue (https://github.com/docker/cli/issues/327)
This Feature will be helpful in heterogenous systems where the scheduler like slurm can use one sif file to run across different architecture
I'll defer to others who are working on this topic like @dctrud, but I don't think there is technically any way to do what you are asking. One thing that could be done is to create the container equivalent of a fat binary. And then put some logic into the Singularity runtime to understand what arch it is running on and select the appropriate bits out of the SIF. But this would really just mean putting multiple container images into a single SIF. There would still be multiple images with different bits in them that would not be guaranteed to run the same on different platforms.
Some one has tried to use binfmt_misc kernel module to create architecture emulation containers https://old.lwn.net/Articles/679308/ The solution they propose is to have architecture emulator outside the container and container run using the emulator. Not sure if this is an ideal solution or even secure one
Hello @Amjadhpc - this is an interesting and complicated topic. I'll try to address the few things you've mentioned here.
- The general issue of running on a different architecture without recompiling
This is not something we'd really expect people to want to do in production, though there might be a use case for development. The only way to run code on a completely different architecture is through emulation, such as via qemu. This tends to be extremely slow compared to hardware. I've actually played around with this, installing singularity inside a qemu arm VM on my desktop. With this setup my relatively fast Ryzen 5 2600 CPU is slower at running arm code than my Raspberry Pi 3b. There is also huge overhead for IO etc. as the kernel drivers etc are running emulated.
Even within a single architecture in performance sensitive environments, such as production HPC or large cloud service deployments, it's often a good idea to maintain different optimized images if you have varied systems. I come from a bioinformatics HPC background, where we routinely saw 15% performance improvement for software compiled specifically for the latest chips vs software compiled so it could run on our oldest (4-5 yo) systems.
- The docker issue 327
The docker issue you reference actually starts in a slightly different place. The original poster is talking about architecture pairings where newer CPUs are instruction set compatible with older ones. E.g. a recent amd64 CPU can run i386 code. An arm64 cpu can run older armv6 code. The thread then takes on a bit of a life of its own getting into making arm work on an amd64 CPU.
Behind the scenes, docker is maintaining completely separate container images for multi-architecture builds. If you pull ubuntu:latest on arm you get a completely different container from dockerhub than if you pull ubuntu:latest on amd64. The manifest list is just a 'wrapper' that links the different manifests/images for each architecture to the ubuntu:latest ref/tag. We have work ongoing to transparently support multiple architectures in the Sylabs Container Library, so you could push up mycontainer:latest for multiple architectures, and then hosts could pull the image appropriate for them. The build still needs to be done for the different host architectures though.
- binfmt_misc
Further to your lwn link, Docker does now provide experimental facilities for building containers across architectures. I understand that this is using qemu and some binfmt magic that the lwn link touches on: https://engineering.docker.com/2019/04/multi-arch-images/ - google search will find various blog posts about similar approaches.
This is certainly interesting for us to look at - but note here you are still doing builds for each architecture - not running an amd64 container on ppc64le in production. Builds can also be very slow.
Additionally, across these 3 points, a difficulty in following a similar path for Singularity is the nature of the container run time - we are closer to the host than docker, emphasizing integration such that you can very easily use exotic GPU, Infiniband etc. hardware that is common in HPC and EPC. Containers that require access to the hardware at software install/compile/run time couldn't use the qemu approach, as you are limited to the hardware qemu emulates. In general, qemu is emulating fairly simple, standard, low performance hardware. You may be familiar with passing in hardware to the VM - but this is only for qemu-kvm where the VM is the same architecture as the host system.
To summarize - there is definitely work to do to make things easier in multi-architecture environments, but we need to do it in a way which does preserve the advantages of Singularity and delivers containers which are viable to run in production. Emulation / binfmt_misc unfortunately does not do this.
I agree with the above comments that we do not want a single SIF image to span multiple architectures. I can only imagine this will be messy and lead to strenuous issues at runtime. I second @GodloveD 's comments about qemu being almost unsuitably slow, expect >50x performance degradation when emulating.
Instead, I'd like to perhaps turn this into a feature request, whereby we can somehow inspect the SIF image to determine the uarch type and/or embed this as Metadata. I believe the SIF image as a capability for this that could be leveraged? I also think it would be nice to have images pulled from OCI-compliant registries (say Gitlab or Dockerhub) to be inspected and have uarch information inserted into the SIF image. Currently, "singularity inspect mimg.simg" has no idea that I'm actually running on a aarch64 on a Marvell ThunderX2 processor!
[myuser@astra-login1 ~]$ singularity inspect myimg-0.0.9.simg ==labels== org.label-schema.usage.singularity.deffile.bootstrap: docker org.label-schema.usage.singularity.deffile.from: blah.sandia.gov:1234/myuser/myimg/myimg-astra:0.0.9 org.label-schema.usage.singularity.version: 3.2.1-2.1.atse.1.2.1 org.label-schema.build-date: Monday_22_July_2019_15:3:23_MDT org.label-schema.schema-version: 1.0 [ajyoung@astra-login1 ~]$ singularity inspect --environment myimg-0.0.9.simg ==environment== ==environment:90-environment.sh== #!/bin/sh #Custom environment shell code should follow
Instead, I'd like to perhaps turn this into a feature request, whereby we can somehow inspect the SIF image to determine the uarch type and/or embed this as Metadata.
Just noting here this is given by sif list, but we need to expose via inspect.
10:17 AM $ singularity sif list mpich_ofi.arm64.sif
Container id: efaa70e0-d57b-4ed7-9d8e-2403efb70478
Created on: 2020-02-10 18:08:51 -0600 CST
Modified on: 2020-02-10 18:08:51 -0600 CST
----------------------------------------------------
Descriptor list:
ID |GROUP |LINK |SIF POSITION (start-end) |TYPE
------------------------------------------------------------------------------
1 |1 |NONE |32768-35093 |Def.FILE
2 |1 |NONE |36864-37167 |JSON.Generic
3 |1 |NONE |40960-191684608 |FS (Squashfs/*System/arm64)
The specific request is actually made in issue #4310 so I'm going to close this one.