Docker 和 -march 本机 [英] Docker and -march native

查看:30
本文介绍了Docker 和 -march 本机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序从使用 -march native 运行时 gcc 可以访问的高级 CPU 功能中受益匪浅.Docker 可以平滑操作系统的差异,但它如何处理不同的 CPU?要构建一个可以在任何 CPU 上运行的应用程序,我必须为 amd64 构建,这会损失很多性能.当应用程序需要针对每个 CPU 架构单独编译时,有没有好的分发 Docker 镜像的方法?

My application benefits greatly from advanced CPU features that gcc can access when it is run with -march native. Docker can smooth over differences in OS, but how does it handle different CPUs? To build an application that can run on any CPU I would have to build for amd64, losing out on a lot of performance. Is there a good way to distribute Docker images when the application needs to be compiled separately for each CPU architecture?

推荐答案

Docker 根本不处理 CPU.它只是内核命名空间、FS系统分层(例如UnionFS) 和 过程引用.
当您在 docker 容器上运行某些东西时,它只是在您的操作系统上运行的可执行文件,没有虚拟化,它只能访问一组选定的内核对象(例如设备)并且它被 chroot 到一个 FS 层次结构,这是由于覆盖不同的 FS(包括 docker 容器中的一个)而产生的.

Docker doesn't handle CPU at all. It is just a composition of kernel namespacing, FS system layering (e.g. UnionFS) and process quoting.
When you run something on a docker container it is just an executable running on your OS, without virtualisation, it has access only to a selected set of kernel objects (e.g. devices) and it is chrooted to a FS hierarchy resulting from overlaying vary FSs (including the one in the docker container).

因此,Docker 根本不处理 CPU,它与您的问题完全正交.

Hence, Docker doesn't handle the CPU at all, it is completely orthogonal to your problem.

正如 Peter 评论的,基本上有两种 CPU 调度方式:>

As Peter commented there are essentially two ways to CPU-dispatch:

  1. 您加载了正确的动态库(但对库的每个函数调用都使用一个指针).
  2. 您构建同一个静态链接二进制文件的多个版本并运行正确的一个.

主要问题是有时 ISA 扩展是正交的,这使得组合(即库/二进制文件的数量)呈指数增长.因此,考虑到您正在处理 Docker 的用户群,您可以稍微简化一下方法(如果组合有问题):

The main issue is that sometime ISA extensions are orthogonal and this makes the combinations (i.e. the number of libraries/binaries) grow exponential. So, considering that you are dealing with the Docker's userbase you can simplify the approach a bit (if combinations are a problem):

  1. 或者做一些需要的 ISA 扩展(如果没有这样的扩展会大大降低性能).对于可选扩展,您可以使用上述方法之一.
  2. 仅创建几个基线容器.例如.一种用于通用 amd64,一种用于 amd64-avx,一种用于 amd64-avx2-aesni-tsx 等.想法是只创建几个容器来覆盖所有大多数少数用户.
  1. Either make some ISA extensions required (if the absence of such would degrade the performance too much). For the optional extensions you can use one of the approaches of a above.
  2. Create only a few baseline containers. E.g. One for the generic amd64, one for amd64-avx, one for amd64-avx2-aesni-tsx and similar. The idea being to create only a few containers that covers all, most and few of your users.

编辑
正如BeeOnRope 在评论中指出,Dockers 在 Windows 上运行的版本.它使用 Hyper-V 运行带有 Linux 版本 docker 的 Linux VM.
由于 Hyper-V 是本机 VMM,因此除了额外的层之外,同样的注意事项也适用.
同样,也有 macOS 版本.这次使用了基于xhyve的hypervisor框架.

EDIT
As BeeOnRope pointed in the comments, Dockers has a version running on Windows. It uses Hyper-V to run a Linux VM with the Linux version of docker.
As Hyper-V is a native VMM, apart from an extra layer, the same considerations apply.
Similarly, there is a macOS version too. This time it uses an hypervisor framework based on xhyve.

这篇关于Docker 和 -march 本机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆